From: Stephan Gerhold Date: Wed, 7 Jul 2021 10:58:54 +0000 (+0200) Subject: board: stemmy: Parse atags to get available memory X-Git-Tag: v2021.10~107^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03585d52fcb7c4f769b9af32085dcc365f39edbc;p=platform%2Fkernel%2Fu-boot.git board: stemmy: Parse atags to get available memory At the moment the "stemmy" board attempts to detect the RAM size with a simple memory test (get_ram_size()). Unfortunately, this does not work correctly for devices with 768 MiB RAM (e.g. Samsung Galaxy Ace 2 (GT-I8160), "codina"). Reading/writing memory after the 768 MiB RAM succeeds but actually overwrites some earlier parts of the memory. For U-Boot this does not result in any major problems, but on Linux this will eventually lead to strange crashes because of the memory corruption. Since the "stemmy" U-Boot port is designed to be chainloaded from the original Samsung bootloader, the most reliable way to get the available amount of RAM is to look at the ATAGS passed by the Samsung bootloader. Fortunately, the header used to generate ATAGS in U-Boot (asm/setup.h) can also be easily used to parse them. Also clarify and simplify stemmy.h a bit to make it more clear where some of the magic values in there are actually coming from. Signed-off-by: Stephan Gerhold Reviewed-by: Linus Walleij --- diff --git a/arch/arm/mach-u8500/Kconfig b/arch/arm/mach-u8500/Kconfig index 7478deb..372fbeb 100644 --- a/arch/arm/mach-u8500/Kconfig +++ b/arch/arm/mach-u8500/Kconfig @@ -15,6 +15,7 @@ config TARGET_STEMMY - Samsung Galaxy S III mini (GT-I8190) "golden" - Samsung Galaxy S Advance (GT-I9070) "janice" - Samsung Galaxy Xcover 2 (GT-S7710) "skomer" + - Samsung Galaxy Ace 2 (GT-I8160) "codina" and likely others as well (untested). diff --git a/board/ste/stemmy/README b/board/ste/stemmy/README index 81f7242..1b83b83 100644 --- a/board/ste/stemmy/README +++ b/board/ste/stemmy/README @@ -7,6 +7,7 @@ the ST-Ericsson NovaThor U8500 SoC, e.g. - Samsung Galaxy S III mini (GT-I8190) "golden" - Samsung Galaxy S Advance (GT-I9070) "janice" - Samsung Galaxy Xcover 2 (GT-S7710) "skomer" + - Samsung Galaxy Ace 2 (GT-I8160) "codina" and likely others as well (untested). diff --git a/board/ste/stemmy/stemmy.c b/board/ste/stemmy/stemmy.c index b9b2a6f..9e6c8e2 100644 --- a/board/ste/stemmy/stemmy.c +++ b/board/ste/stemmy/stemmy.c @@ -4,17 +4,77 @@ */ #include #include +#include #include +#include +#include DECLARE_GLOBAL_DATA_PTR; +/* Parse atags provided by Samsung bootloader to get available memory */ +static ulong fw_mach __section(".data"); +static ulong fw_atags __section(".data"); + +void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3) +{ + fw_mach = r1; + fw_atags = r2; + save_boot_params_ret(); +} + +static const struct tag *fw_atags_get(void) +{ + const struct tag *tags = (const struct tag *)fw_atags; + + if (tags->hdr.tag != ATAG_CORE) { + log_err("Invalid atags: tag 0x%x at %p\n", tags->hdr.tag, tags); + return NULL; + } + + return tags; +} + int dram_init(void) { - gd->ram_size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_SDRAM_SIZE); + const struct tag *t, *tags = fw_atags_get(); + + if (!tags) + return -EINVAL; + + for_each_tag(t, tags) { + if (t->hdr.tag != ATAG_MEM) + continue; + + debug("Memory: %#x-%#x (size %#x)\n", t->u.mem.start, + t->u.mem.start + t->u.mem.size, t->u.mem.size); + gd->ram_size += t->u.mem.size; + } + return 0; +} + +int dram_init_banksize(void) +{ + const struct tag *t, *tags = fw_atags_get(); + unsigned int bank = 0; + + if (!tags) + return -EINVAL; + + for_each_tag(t, tags) { + if (t->hdr.tag != ATAG_MEM) + continue; + + gd->bd->bi_dram[bank].start = t->u.mem.start; + gd->bd->bi_dram[bank].size = t->u.mem.size; + if (++bank == CONFIG_NR_DRAM_BANKS) + break; + } return 0; } int board_init(void) { + gd->bd->bi_arch_number = fw_mach; + gd->bd->bi_boot_params = fw_atags; return 0; } diff --git a/configs/stemmy_defconfig b/configs/stemmy_defconfig index 79c05ac..f31960b 100644 --- a/configs/stemmy_defconfig +++ b/configs/stemmy_defconfig @@ -1,7 +1,7 @@ CONFIG_ARM=y CONFIG_ARCH_U8500=y CONFIG_SYS_TEXT_BASE=0x100000 -CONFIG_NR_DRAM_BANKS=1 +CONFIG_NR_DRAM_BANKS=2 CONFIG_DEFAULT_DEVICE_TREE="ste-ux500-samsung-stemmy" CONFIG_SYS_CONSOLE_INFO_QUIET=y CONFIG_HUSH_PARSER=y diff --git a/include/configs/stemmy.h b/include/configs/stemmy.h index 922eec4..c446b09 100644 --- a/include/configs/stemmy.h +++ b/include/configs/stemmy.h @@ -7,23 +7,20 @@ #include -#define CONFIG_SKIP_LOWLEVEL_INIT /* Loaded by another bootloader */ -#define CONFIG_SYS_MALLOC_LEN SZ_2M +/* + * The "stemmy" U-Boot port is designed to be chainloaded by the Samsung + * bootloader on devices based on ST-Ericsson Ux500. Therefore, we skip most + * low-level initialization and rely on configuration provided by the Samsung + * bootloader. New images are loaded at the same address for compatibility. + */ +#define CONFIG_SKIP_LOWLEVEL_INIT +#define CONFIG_SYS_INIT_SP_ADDR CONFIG_SYS_TEXT_BASE +#define CONFIG_SYS_LOAD_ADDR CONFIG_SYS_TEXT_BASE -/* Physical Memory Map */ -#define PHYS_SDRAM_1 0x00000000 /* DDR-SDRAM Bank #1 */ -#define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1 -#define CONFIG_SYS_SDRAM_SIZE SZ_1G -#define CONFIG_SYS_INIT_RAM_SIZE 0x00100000 -#define CONFIG_SYS_GBL_DATA_OFFSET (CONFIG_SYS_SDRAM_BASE + \ - CONFIG_SYS_INIT_RAM_SIZE - \ - GENERATED_GBL_DATA_SIZE) -#define CONFIG_SYS_INIT_SP_ADDR CONFIG_SYS_GBL_DATA_OFFSET +#define CONFIG_SYS_MALLOC_LEN SZ_2M /* FIXME: This should be loaded from device tree... */ #define CONFIG_SYS_L2_PL310 #define CONFIG_SYS_PL310_BASE 0xa0412000 -#define CONFIG_SYS_LOAD_ADDR 0x00100000 - #endif