[PATCH 2/2] bsp/raspberrypi: Fix size of work area.
list at c-mauderer.de
list at c-mauderer.de
Fri Dec 27 21:08:12 UTC 2019
From: Christian Mauderer <oss at c-mauderer.de>
The BSP tried to get the size of the SDRAM based on the revision code.
Unfortunately the code had some bugs so that the default size has been
used. Beneath that the MMU table hasn't been adapted.
This patch queries the SDRAM size via a special VC Mailbox call instead.
For the MMU adaption a simmilar method to the one in the imx BSP is
used.
---
bsps/arm/raspberrypi/include/bsp/vc.h | 11 +++
bsps/arm/raspberrypi/start/bspgetworkarea.c | 87 ------------------
bsps/arm/raspberrypi/start/bspstarthooks.c | 71 ++++++++++++++-
bsps/arm/raspberrypi/start/mm_config_table.c | 96 --------------------
c/src/lib/libbsp/arm/raspberrypi/Makefile.am | 4 -
5 files changed, 80 insertions(+), 189 deletions(-)
delete mode 100644 bsps/arm/raspberrypi/start/bspgetworkarea.c
delete mode 100644 bsps/arm/raspberrypi/start/mm_config_table.c
diff --git a/bsps/arm/raspberrypi/include/bsp/vc.h b/bsps/arm/raspberrypi/include/bsp/vc.h
index 107b6acf0c..422d28cdd9 100644
--- a/bsps/arm/raspberrypi/include/bsp/vc.h
+++ b/bsps/arm/raspberrypi/include/bsp/vc.h
@@ -138,6 +138,17 @@ int bcm2835_mailbox_get_board_model( bcm2835_get_board_spec_entries *_entries );
int bcm2835_mailbox_get_board_revision(
bcm2835_get_board_spec_entries *_entries );
+/*
+ * See the official documentation for the format of the revision codes:
+ * https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
+ */
+#define BCM2835_REVISION_IS_NEW_STYLE(revision) ((revision & (1 << 23)) != 0)
+#define BCM2835_REVISION_MEMORY_SIZE(revision) ((revision >> 20) & 0x7)
+#define BCM2835_REVISION_MANUFACTURER(revision) ((revision >> 16) & 0xf)
+#define BCM2835_REVISION_PROCESSOR(revision) ((revision >> 12) & 0xf)
+#define BCM2835_REVISION_TYPE(revision) ((revision >> 4) & 0xff)
+#define BCM2835_REVISION_REVISION(revision) ((revision >> 0) & 0xf)
+
typedef struct {
uint64_t board_serial;
} bcm2835_get_board_serial_entries;
diff --git a/bsps/arm/raspberrypi/start/bspgetworkarea.c b/bsps/arm/raspberrypi/start/bspgetworkarea.c
deleted file mode 100644
index 6521dcf352..0000000000
--- a/bsps/arm/raspberrypi/start/bspgetworkarea.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * @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>
-
-#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 ram_end;
- bcm2835_get_board_spec_entries spec = { 0 };
-
- work_base = (uintptr_t) WorkAreaBase;
-
- /*
- * 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
- 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
-
- 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/bspstarthooks.c b/bsps/arm/raspberrypi/start/bspstarthooks.c
index 3f8c680bc0..c2a9707d71 100644
--- a/bsps/arm/raspberrypi/start/bspstarthooks.c
+++ b/bsps/arm/raspberrypi/start/bspstarthooks.c
@@ -27,6 +27,7 @@
#include <bsp/raspberrypi.h>
#include <libcpu/arm-cp15.h>
#include <bsp.h>
+#include <bsp/bootcard.h>
#include <bsp/linker-symbols.h>
#include <bsp/arm-cp15-start.h>
@@ -34,6 +35,34 @@
#include <rtems/score/smp.h>
#endif
+#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
+ #define USE_UBOOT
+#endif
+
+#ifdef USE_UBOOT
+ #include <bsp/u-boot.h>
+#else
+ #include <bsp/vc.h>
+#endif
+
+BSP_START_DATA_SECTION static arm_cp15_start_section_config
+raspberrypi_mmu_config_table[] = {
+ ARMV7_CP15_START_DEFAULT_SECTIONS,
+ {
+ .begin = RPI_PERIPHERAL_BASE,
+ .end = RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
+ .flags = ARMV7_MMU_DEVICE
+ }
+#if (BSP_IS_RPI2 == 1)
+ /* Core local peripherals area - timer, mailboxes */
+ , {
+ .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
+ .end = BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
+ .flags = ARMV7_MMU_DEVICE
+ }
+#endif
+};
+
void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
{
uint32_t sctlr_val;
@@ -98,18 +127,43 @@ void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
#endif
}
+BSP_START_TEXT_SECTION static uintptr_t raspberrypi_get_ram_end(void)
+{
+ uintptr_t ram_end;
+
+#ifdef USE_UBOOT
+ ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
+ bsp_uboot_board_info.bi_memsize;
+#else
+ bcm2835_get_arm_memory_entries spec;
+
+ if (bcm2835_mailbox_get_arm_memory( &spec ) >= 0) {
+ ram_end = spec.base + spec.size;
+ } else {
+ /* Use the workspace end from the linker command file for fallback. */
+ ram_end = (uintptr_t) bsp_section_work_end;
+ }
+#endif
+
+ return ram_end;
+}
+
BSP_START_TEXT_SECTION static void bsp_memory_management_initialize(void)
{
+ uintptr_t ram_end = raspberrypi_get_ram_end();
uint32_t ctrl = arm_cp15_get_control();
ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
+ raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end =
+ ram_end;
+
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
+ &raspberrypi_mmu_config_table[0],
+ RTEMS_ARRAY_SIZE(raspberrypi_mmu_config_table)
);
}
@@ -121,3 +175,16 @@ void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
rpi_video_init();
}
+
+void bsp_work_area_initialize(void)
+{
+ uintptr_t begin;
+ uintptr_t end;
+
+ begin = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
+ .begin;
+ end = raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX]
+ .end;
+
+ bsp_work_area_initialize_default((void *) begin, end - begin);
+}
diff --git a/bsps/arm/raspberrypi/start/mm_config_table.c b/bsps/arm/raspberrypi/start/mm_config_table.c
deleted file mode 100644
index 27fa76b355..0000000000
--- a/bsps/arm/raspberrypi/start/mm_config_table.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * @file
- *
- * @ingroup arm_start
- *
- * @brief Raspberry Pi low level start
- */
-
-/*
- * Copyright (c) 2013 embedded brains GmbH. All rights reserved.
- *
- * embedded brains GmbH
- * Dornierstr. 4
- * 82178 Puchheim
- * Germany
- * <info at embedded-brains.de>
- *
- * 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.
- */
-
-#include <bsp.h>
-#include <bsp/arm-cp15-start.h>
-
-/*
- * Pagetable initialization data
- *
- * Keep all read-only sections before read-write ones.
- * This ensures that write is allowed if one page/region
- * is partially filled by read-only section contentent
- * and rest is used for writeable section
- */
-
-const arm_cp15_start_section_config arm_cp15_start_mmu_config_table[] = {
- {
- .begin = (uint32_t) bsp_section_fast_text_begin,
- .end = (uint32_t) bsp_section_fast_text_end,
- .flags = ARMV7_MMU_CODE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_start_begin,
- .end = (uint32_t) bsp_section_start_end,
- .flags = ARMV7_MMU_CODE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_text_begin,
- .end = (uint32_t) bsp_section_text_end,
- .flags = ARMV7_MMU_CODE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_rodata_begin,
- .end = (uint32_t) bsp_section_rodata_end,
- .flags = ARMV7_MMU_DATA_READ_ONLY_CACHED
- }, {
- .begin = (uint32_t) bsp_translation_table_base,
- .end = (uint32_t) bsp_translation_table_base + 0x4000,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_fast_data_begin,
- .end = (uint32_t) bsp_section_fast_data_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_vector_begin,
- .end = (uint32_t) bsp_section_vector_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_data_begin,
- .end = (uint32_t) bsp_section_data_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_bss_begin,
- .end = (uint32_t) bsp_section_bss_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_work_begin,
- .end = (uint32_t) bsp_section_work_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = (uint32_t) bsp_section_stack_begin,
- .end = (uint32_t) bsp_section_stack_end,
- .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED
- }, {
- .begin = RPI_PERIPHERAL_BASE,
- .end = RPI_PERIPHERAL_BASE + RPI_PERIPHERAL_SIZE,
- .flags = ARMV7_MMU_DEVICE
- }
-#if (BSP_IS_RPI2 == 1)
- /* Core local peripherals area - timer, mailboxes */
- , {
- .begin = BCM2836_CORE_LOCAL_PERIPH_BASE,
- .end = BCM2836_CORE_LOCAL_PERIPH_BASE + BCM2836_CORE_LOCAL_PERIPH_SIZE,
- .flags = ARMV7_MMU_DEVICE
- }
-#endif
-};
-
-const size_t arm_cp15_start_mmu_config_table_size =
- RTEMS_ARRAY_SIZE(arm_cp15_start_mmu_config_table);
diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
index 11a22f89e3..5326deb8a3 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
+++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
@@ -49,7 +49,6 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/shared/cp15/arm-cp15-set-ttb
# Startup
librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/bspstart.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/cmdline.c
-librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/bspgetworkarea.c
if HAS_SMP
librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/bspsmp.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/bspsmp_init.c
@@ -105,9 +104,6 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/shared/cache/cache-v7ar-disa
# Start hooks
librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/bspstarthooks.c
-# LIBMM
-librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/start/mm_config_table.c
-
###############################################################################
# Special Rules #
###############################################################################
--
2.24.1
More information about the devel
mailing list