board: stemmy: Parse atags to get available memory
authorStephan Gerhold <stephan@gerhold.net>
Wed, 7 Jul 2021 10:58:54 +0000 (12:58 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 14 Jul 2021 20:48:11 +0000 (16:48 -0400)
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>
arch/arm/mach-u8500/Kconfig
board/ste/stemmy/README
board/ste/stemmy/stemmy.c
configs/stemmy_defconfig
include/configs/stemmy.h

index 7478deb..372fbeb 100644 (file)
@@ -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).
 
index 81f7242..1b83b83 100644 (file)
@@ -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).
 
index b9b2a6f..9e6c8e2 100644 (file)
@@ -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;
 }
index 79c05ac..f31960b 100644 (file)
@@ -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
index 922eec4..c446b09 100644 (file)
@@ -7,23 +7,20 @@
 
 #include <linux/sizes.h>
 
-#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