[PATCH v2 5/7] arm/raspberrypi: move MMU in front of application image to respect variable memory size.

ppisa4lists at pikron.com ppisa4lists at pikron.com
Sun May 22 00:13:08 UTC 2016


From: Pavel Pisa <ppisa at pikron.com>

The page table is placed at address 0x00004000 which provides
required 16 kB space till the start of application image.

The RAM size specified in a linker script is upper limit
address of RAM utilized for the work area initialization.

If VideoCore reports to use lower address than expected
then work area size is adjusted (shrinked) appropriately.
---
 c/src/lib/libbsp/arm/raspberrypi/Makefile.am       |  4 +-
 c/src/lib/libbsp/arm/raspberrypi/include/bsp.h     |  2 +
 .../arm/raspberrypi/startup/bspgetworkarea.c       | 77 ++++++++++++++++++++++
 c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds  |  6 +-
 c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c  | 31 +++++++++
 5 files changed, 115 insertions(+), 5 deletions(-)
 create mode 100644 c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
 create mode 100644 c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c

diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
index 285da4f..3373d08 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
+++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
@@ -83,7 +83,6 @@ libbsp_a_LIBADD =
 # Shared
 libbsp_a_SOURCES += ../../shared/bootcard.c
 libbsp_a_SOURCES += ../../shared/bspclean.c
-libbsp_a_SOURCES += ../../shared/bspgetworkarea.c
 libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
 libbsp_a_SOURCES += ../../shared/cpucounterread.c
 libbsp_a_SOURCES += ../../shared/cpucounterdiff.c
@@ -97,6 +96,7 @@ libbsp_a_SOURCES += ../shared/arm-cp15-set-ttb-entries.c
 libbsp_a_SOURCES += ../../shared/bspreset_loop.c
 libbsp_a_SOURCES += startup/bspstart.c
 libbsp_a_SOURCES += startup/cmdline.c
+libbsp_a_SOURCES += startup/bspgetworkarea.c
 
 # IRQ
 libbsp_a_SOURCES += ../shared/arm-cp15-set-exception-handler.c
@@ -153,7 +153,7 @@ libbsp_a_SOURCES += startup/bspstarthooks.c
 
 # LIBMM
 libbsp_a_SOURCES += startup/mm_config_table.c
-libbsp_a_SOURCES += ../shared/mminit.c
+libbsp_a_SOURCES += startup/mminit.c
 
 ###############################################################################
 # Network                                                    #
diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
index 18a94ea..c6cd571 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
@@ -32,6 +32,8 @@ extern "C" {
 
 #define BSP_FEATURE_IRQ_EXTENSION
 
+#define RPI_L2_CACHE_ENABLE 1
+
 #define BSP_GPIO_PIN_COUNT 32
 #define BSP_GPIO_PINS_PER_BANK 32
 #define BSP_GPIO_PINS_PER_SELECT_BANK 10
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
new file mode 100644
index 0000000..9dc7e02
--- /dev/null
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
@@ -0,0 +1,77 @@
+/**
+ * @file
+ *
+ * @ingroup arm_start
+ *
+ * @brief Raspberry pi workarea initialization.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Copyright (c) 2011-2012 embedded brains GmbH.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ *
+ * Copyright (c) 2015 YANG Qiao
+ *
+ * Code is based on c/src/lib/libbsp/shared/bspgetworkarea.c
+ */
+
+#include <string.h>
+#include <bsp.h>
+#include <bsp/bootcard.h>
+#include <bsp/vc.h>
+#ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN
+  #include <rtems/config.h>
+#endif
+
+#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
+  #define USE_UBOOT
+#endif
+
+/*
+ *  These are provided by the linkcmds for ALL of the BSPs which use this file.
+ */
+extern char WorkAreaBase[];
+
+/*
+ *  We may get the size information from U-Boot or the linker scripts.
+ */
+#ifdef USE_UBOOT
+  #include <bsp/u-boot.h>
+#else
+  extern char RamBase[];
+  extern char RamSize[];
+#endif
+
+void bsp_work_area_initialize(void)
+{
+  uintptr_t work_base = (uintptr_t) WorkAreaBase;
+  uintptr_t ram_end;
+  bcm2835_get_vc_memory_entries vc_entry;
+  /*
+   * bcm2835_get_arm_memory_entries arm_entry;
+   * is another alternative how to obtain usable memory size
+   */
+
+  #ifdef USE_UBOOT
+    ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
+                          bsp_uboot_board_info.bi_memsize;
+  #else
+    ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
+  #endif
+
+  #ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN
+    work_base += rtems_configuration_get_interrupt_stack_size();
+  #endif
+
+  memset( &vc_entry, 0, sizeof(vc_entry) );
+  bcm2835_mailbox_get_vc_memory( &vc_entry );
+  if (vc_entry.base != 0)
+    ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
+  bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
+}
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds b/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
index f1ad11c..fc72b5c 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
@@ -36,9 +36,9 @@
  */
 
 MEMORY {
-        VECTOR_RAM     (AIW) : ORIGIN = 0x0       , LENGTH = 0x8000
-        RAM            (AIW) : ORIGIN = 0x00008000, LENGTH = 128M - 48K
-	RAM_MMU        (AIW) : ORIGIN = 128M - 16k, LENGTH = 16k
+        VECTOR_RAM     (AIW) : ORIGIN = 0x0       , LENGTH = 16k
+	RAM_MMU        (AIW) : ORIGIN = 0x00004000, LENGTH = 16k
+        RAM            (AIW) : ORIGIN = 0x00008000, LENGTH = 128M - 32k
 }
 
 REGION_ALIAS ("REGION_START", RAM);
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c b/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c
new file mode 100644
index 0000000..c1071a8
--- /dev/null
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015 Yang Qiao
+ * based on work by:
+ * Copyright (c) 2013 Hesham AL-Matary.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#define ARM_CP15_TEXT_SECTION BSP_START_TEXT_SECTION
+
+#include <bsp/start.h>
+#include <bsp/arm-cp15-start.h>
+#include <bsp/linker-symbols.h>
+#include <bsp/mm.h>
+
+BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)
+{
+  uint32_t ctrl = arm_cp15_get_control();
+
+  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
+
+  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
+    ctrl,
+    (uint32_t *) bsp_translation_table_base,
+    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
+    &arm_cp15_start_mmu_config_table[0],
+    arm_cp15_start_mmu_config_table_size
+  );
+}
-- 
1.9.1




More information about the devel mailing list