summaryrefslogtreecommitdiff
path: root/board/ste
diff options
context:
space:
mode:
authorStephan Gerhold <stephan@gerhold.net>2021-07-07 13:58:54 +0300
committerTom Rini <trini@konsulko.com>2021-07-14 23:48:11 +0300
commit03585d52fcb7c4f769b9af32085dcc365f39edbc (patch)
tree72feb4d627eab2165a55b4247e5d59f8a2b8f583 /board/ste
parent9e9074bcdd52e0e898c668eaac9555504370cc92 (diff)
downloadu-boot-03585d52fcb7c4f769b9af32085dcc365f39edbc.tar.xz
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 <stephan@gerhold.net> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'board/ste')
-rw-r--r--board/ste/stemmy/README1
-rw-r--r--board/ste/stemmy/stemmy.c62
2 files changed, 62 insertions, 1 deletions
diff --git a/board/ste/stemmy/README b/board/ste/stemmy/README
index 81f72426f2..1b83b833c0 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 b9b2a6fddc..9e6c8e208e 100644
--- a/board/ste/stemmy/stemmy.c
+++ b/board/ste/stemmy/stemmy.c
@@ -4,17 +4,77 @@
*/
#include <common.h>
#include <init.h>
+#include <log.h>
#include <asm/global_data.h>
+#include <asm/setup.h>
+#include <asm/system.h>
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;
}