[PATCH] arm/raspberry: Set the workspace based on the mailbox version.

chrisj at rtems.org chrisj at rtems.org
Tue Aug 6 21:40:29 UTC 2019


From: Chris Johns <chrisj at rtems.org>

- Update the linkcmd file to support configure settings

- Set the workspace size based on the revision value
---
 bsps/arm/raspberrypi/start/bspgetworkarea.c   | 34 +++++--
 bsps/arm/raspberrypi/start/bspstart.c         | 93 +++++++++++++++++++
 bsps/arm/raspberrypi/start/linkcmds.in        | 34 +++----
 c/src/lib/libbsp/arm/raspberrypi/configure.ac | 20 +++-
 4 files changed, 151 insertions(+), 30 deletions(-)

diff --git a/bsps/arm/raspberrypi/start/bspgetworkarea.c b/bsps/arm/raspberrypi/start/bspgetworkarea.c
index 4b2f440183..6521dcf352 100644
--- a/bsps/arm/raspberrypi/start/bspgetworkarea.c
+++ b/bsps/arm/raspberrypi/start/bspgetworkarea.c
@@ -47,12 +47,16 @@ extern char WorkAreaBase[];
 
 void bsp_work_area_initialize(void)
 {
-  uintptr_t work_base = (uintptr_t) WorkAreaBase;
-  uintptr_t ram_end;
-  bcm2835_get_vc_memory_entries vc_entry;
+  uintptr_t                      work_base;
+  uintptr_t                      ram_end;
+  bcm2835_get_board_spec_entries spec = { 0 };
+
+  work_base = (uintptr_t) WorkAreaBase;
+
   /*
-   * bcm2835_get_arm_memory_entries arm_entry;
-   * is another alternative how to obtain usable memory size
+   * Get the board revision and use it to determine the size of the
+   * SDRAM. Get the VC memory entry to determine the size of the VC
+   * memory needed.
    */
 
   #ifdef USE_UBOOT
@@ -62,10 +66,22 @@ void bsp_work_area_initialize(void)
     ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
   #endif
 
-  memset( &vc_entry, 0, sizeof(vc_entry) );
-  if (bcm2835_mailbox_get_vc_memory( &vc_entry ) >= 0) {
-    if (vc_entry.base > 10 * 1024 *1024)
-      ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
+  if (bcm2835_mailbox_get_board_revision( &spec ) >= 0) {
+    uint32_t mem = (spec.spec >> (4 + 4 + 8 + 4)) & 0xf;
+    if (mem < 5) {
+      bcm2835_get_vc_memory_entries vc = { 0 };
+      const uint32_t rpi_mem[5] = {
+        256 * 1024,
+        512 * 1024,
+        1 * 1024,
+        2 * 1024,
+        4 * 1024
+      };
+      ram_end = work_base + rpi_mem[mem];
+      if (bcm2835_mailbox_get_vc_memory( &vc ) >= 0)
+        ram_end -= vc.size;
+    }
   }
+
   bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
 }
diff --git a/bsps/arm/raspberrypi/start/bspstart.c b/bsps/arm/raspberrypi/start/bspstart.c
index c5786bfa4a..6ff286f840 100644
--- a/bsps/arm/raspberrypi/start/bspstart.c
+++ b/bsps/arm/raspberrypi/start/bspstart.c
@@ -22,8 +22,101 @@
 #include <bsp/linker-symbols.h>
 #include <bsp/stackalloc.h>
 #include <bsp/raspberrypi.h>
+#include <bsp/vc.h>
+
+static const struct {
+    uint32_t code;
+    const char* label;
+} rpi_codes[] =
+{
+    { 0x900021, "A+ 1.1 (512MB)" },
+    { 0x900032, "B+ 1.2 (512MB)" },
+    { 0x900092, "Zero 1.2 (512MB)" },
+    { 0x900093, "Zero 1.3 (512MB)" },
+    { 0x9000c1, "Zero W 1.1 (512MB)" },
+    { 0x9020e0, "3A+ 1.0 (512MB)" },
+    { 0x920092, "Zero 1.2 (512MB)" },
+    { 0x920093, "Zero 1.3 (512MB)" },
+    { 0x900061, "CM 1.1 (512MB)" },
+    { 0xa01040, "2B 1.0 (1GB)" },
+    { 0xa01041, "2B 1.1 (1GB)" },
+    { 0xa02082, "3B 1.2 (1GB)" },
+    { 0xa020a0, "CM3 1.0 (1GB)" },
+    { 0xa020d3, "3B+ 1.3 (1GB)" },
+    { 0xa21041, "2B 1.1 (1GB)" },
+    { 0xa22042, "2B 1,2 (with BCM2837) (1GB)" },
+    { 0xa22082, "3B 1.2 (1GB)" },
+    { 0xa220a0, "CM3 1.0 (1GB)" },
+    { 0xa32082, "3B 1.2 (1GB)" },
+    { 0xa52082, "3B 1.2 (1GB)" },
+    { 0xa22083, "3B 1.3 (1GB)" },
+    { 0xa02100, "CM3+ 1.0 (1GB)" },
+    { 0xa03111, "4B 1.1 (1GB)" },
+    { 0xb03111, "4B 1.1 (2GB)" },
+    { 0xc03111, "4B 1.1 (4GB)" },
+};
+
+static const char* rpi_types[] = {
+    "A",
+    "B",
+    "A+",
+    "B+",
+    "2B",
+    "Alpha (early prototype)",
+    "CM1",
+    "3B",
+    "Zero",
+    "CM3",
+    "Zero W",
+    "3B+",
+    "3A+",
+    "Internal use only",
+    "CM3+",
+    "4B",
+};
+
+static const char* rpi_mem[] =
+{
+    "256MB",
+    "512MB",
+    "1GB",
+    "2GB",
+    "4GB"
+};
+
+#define NUMOF(_s) (sizeof(_s) / sizeof(_s[0]))
 
 void bsp_start(void)
 {
+    bcm2835_get_board_spec_entries spec = { 0 };
+
+    printk("\nRTEMS RPi ");
+    if (bcm2835_mailbox_get_board_revision( &spec ) >= 0) {
+	size_t i;
+	for (i = 0; i < NUMOF(rpi_codes); ++i) {
+	    if (rpi_codes[i].code == spec.spec) {
+		printk("%s [%08x]", rpi_codes[i].label, spec.spec);
+		break;
+	    }
+	}
+	if (i >= NUMOF(rpi_codes)) {
+	    uint32_t type = (spec.spec >> 4) & 0xff;
+	    uint32_t mem = (spec.spec >> (4 + 4 + 8 + 4)) & 0xf;
+	    printk(" unknown code [%08x] ", spec.spec);
+	    if (type < NUMOF(rpi_types))
+		printk(rpi_types[type]);
+	    else
+		printk("type: %02x", type);
+	    if (mem < NUMOF(rpi_mem))
+		printk(" %s", rpi_mem[mem]);
+	    else
+		printk(" mem: %x", mem);
+	}
+	printk("\n");
+    }
+    else {
+	printk(": ERROR reading mailbox\n");
+    }
+
     bsp_interrupt_initialize();
 }
diff --git a/bsps/arm/raspberrypi/start/linkcmds.in b/bsps/arm/raspberrypi/start/linkcmds.in
index 7a1bcbac73..d99b4fe23e 100644
--- a/bsps/arm/raspberrypi/start/linkcmds.in
+++ b/bsps/arm/raspberrypi/start/linkcmds.in
@@ -15,27 +15,27 @@
  */
 
 MEMORY {
-        RAM_MMU        (AIW) : ORIGIN = 0x00100000, LENGTH = 16k
-        RAM            (AIW) : ORIGIN = 0x00200000, LENGTH = 128M - 2M
+  RAM_MMU (AIW) : ORIGIN = 0x00100000, LENGTH = @RPI_RAM_MMU_LENGTH@
+  RAM     (AIW) : ORIGIN = 0x00200000, LENGTH = @RPI_RAM_LENGTH_AVAILABLE@ - @RPI_RAM_NOCACHE_LENGTH@
 }
 
-REGION_ALIAS ("REGION_START", RAM);
-REGION_ALIAS ("REGION_VECTOR", RAM);
-REGION_ALIAS ("REGION_TEXT", RAM);
-REGION_ALIAS ("REGION_TEXT_LOAD", RAM);
-REGION_ALIAS ("REGION_RODATA", RAM);
-REGION_ALIAS ("REGION_RODATA_LOAD", RAM);
-REGION_ALIAS ("REGION_DATA", RAM);
-REGION_ALIAS ("REGION_DATA_LOAD", RAM);
-REGION_ALIAS ("REGION_FAST_TEXT", RAM);
+REGION_ALIAS ("REGION_START",          RAM);
+REGION_ALIAS ("REGION_VECTOR",         RAM);
+REGION_ALIAS ("REGION_TEXT",           RAM);
+REGION_ALIAS ("REGION_TEXT_LOAD",      RAM);
+REGION_ALIAS ("REGION_RODATA",         RAM);
+REGION_ALIAS ("REGION_RODATA_LOAD",    RAM);
+REGION_ALIAS ("REGION_DATA",           RAM);
+REGION_ALIAS ("REGION_DATA_LOAD",      RAM);
+REGION_ALIAS ("REGION_FAST_TEXT",      RAM);
 REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM);
-REGION_ALIAS ("REGION_FAST_DATA", RAM);
+REGION_ALIAS ("REGION_FAST_DATA",      RAM);
 REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM);
-REGION_ALIAS ("REGION_BSS", RAM);
-REGION_ALIAS ("REGION_WORK", RAM);
-REGION_ALIAS ("REGION_STACK", RAM);
-REGION_ALIAS ("REGION_NOCACHE", RAM);
-REGION_ALIAS ("REGION_NOCACHE_LOAD", RAM);
+REGION_ALIAS ("REGION_BSS",            RAM);
+REGION_ALIAS ("REGION_WORK",           RAM);
+REGION_ALIAS ("REGION_STACK",          RAM);
+REGION_ALIAS ("REGION_NOCACHE",        RAM);
+REGION_ALIAS ("REGION_NOCACHE_LOAD",   RAM);
 
 bsp_stack_abt_size = DEFINED (bsp_stack_abt_size) ? bsp_stack_abt_size : 1024;
 
diff --git a/c/src/lib/libbsp/arm/raspberrypi/configure.ac b/c/src/lib/libbsp/arm/raspberrypi/configure.ac
index 0f3a399877..452aa4d029 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/configure.ac
+++ b/c/src/lib/libbsp/arm/raspberrypi/configure.ac
@@ -10,14 +10,11 @@ AC_INIT([rtems-c-src-lib-libbsp-arm-raspberrypi],[_RTEMS_VERSION],[https://devel
 RTEMS_TOP(../../../../../..)
 RTEMS_SOURCE_TOP
 RTEMS_BUILD_TOP
-RTEMS_BSP_LINKCMDS
 
 RTEMS_CANONICAL_TARGET_CPU
 AM_INIT_AUTOMAKE([no-define nostdinc foreign 1.12.2])
 RTEMS_BSP_CONFIGURE
 
-
-
 RTEMS_BSPOPTS_SET([BSP_START_RESET_VECTOR],[*],[])
 RTEMS_BSPOPTS_HELP([BSP_START_RESET_VECTOR],[reset vector address for BSP start])
 
@@ -37,7 +34,22 @@ RTEMS_BSPOPTS_SET([BSP_IS_RPI2],[*],[0])
 RTEMS_BSPOPTS_HELP([BSP_IS_RPI2],[Set if the BSP variant is Raspberry Pi 2.])
 AM_CONDITIONAL(RTEMS_RPI2,[test "$BSP_IS_RPI2" = "1"])
 
+RPI_RAM_MMU_LENGTH="16k"
+RPI_RAM_LENGTH_AVAILABLE="256M"
+RPI_RAM_NOCACHE_LENGTH="2M"
+
+AC_DEFUN([RPI_LINKCMD],[
+AC_ARG_VAR([$1],[$2; default $3])dnl
+[$1]=[$]{[$1]:-[$3]}
+])
+
+RPI_LINKCMD([RPI_RAM_MMU_LENGTH],[MMU region length],[${BSP_RPI_RAM_MMU_LENGTH}])
+RPI_LINKCMD([RPI_RAM_LENGTH_AVAILABLE],[RAM region length],[${BSP_RPI_RAM_LENGTH_AVAILABLE}])
+RPI_LINKCMD([RPI_RAM_NOCACHE_LENGTH],[No-cache region length],[${BSP_RPI_RAM_NOCACHE_LENGTH}])
+
 RTEMS_BSP_CLEANUP_OPTIONS
 
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([
+Makefile
+linkcmds:../../../../../../bsps/arm/raspberrypi/start/linkcmds.in])
 AC_OUTPUT
-- 
2.19.1



More information about the devel mailing list