Skip to contentSkip to conversation

board: stemmy: Parse atags to get available memory

PATCH In review Stephan Gerhold 3 participants 6 messages Jul 7, 2021 – Jul 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 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.

---

 arch/arm/mach-u8500/Kconfig |  1 +
 board/ste/stemmy/README     |  1 +
 board/ste/stemmy/stemmy.c   | 62 ++++++++++++++++++++++++++++++++++++-
 configs/stemmy_defconfig    |  2 +-
 include/configs/stemmy.h    | 23 ++++++--------
 5 files changed, 74 insertions(+), 15 deletions(-)
arch/arm/mach-u8500/Kconfig +1 -0
index 7478deb25f..372fbeb80f 100644
@@ -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).
 
board/ste/stemmy/README +1 -0
index 81f72426f2..1b83b833c0 100644
@@ -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).
 
board/ste/stemmy/stemmy.c +61 -1

78 lines not on this page · raw message

configs/stemmy_defconfig +1 -1
index 79c05acc6a..f31960b814 100644
@@ -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
include/configs/stemmy.h +10 -13
index 922eec43ee..c446b09270 100644
@@ -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
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 board: stemmy: Copy atags for booting downstream/vendor kernel

The U-Boot "stemmy" board is mainly intended to simplify booting mainline Linux on various smartphones from Samsung based on ST-Ericsson Ux500. While the mainline kernel is working great, there are still some features missing there. In particular, it is currently not possible to charge the battery when using the mainline kernel.

This means that it is still necessary to boot the downstream/vendor kernel from Samsung sometimes to charge the device. That kernel is ancient, still uses board files + ATAGS instead of device trees and relies on a strange very long kernel command line hardcoded in the Samsung bootloader.

Actually, since mainline is booted with device trees there is a very simple way to make the old downstream kernel work as well: We can simply take most of the ATAGS passed to U-Boot from the Samsung bootloader and copy them as-is when booting a kernel without device tree. That way the long command line and other needed ATAGS are copied as-is without having to bother with them.

The only exception is the ATAG_INITRD - since the initrd is loaded by U-Boot, the atag for that should be generated in U-Boot so it points to the correct address. All other ATAGS are copied as-is and not generated in U-Boot.

Also use the chance and provide a serial# for U-Boot by parsing the ATAG_SERIAL that is also passed by the Samsung bootloader.

---

 arch/arm/mach-u8500/Kconfig |  1 +
 board/ste/stemmy/stemmy.c   | 87 +++++++++++++++++++++++++++++++++++++
 include/configs/stemmy.h    |  3 ++
 3 files changed, 91 insertions(+)
arch/arm/mach-u8500/Kconfig +1 -0
index 372fbeb80f..db7a29a54c 100644
@@ -8,6 +8,7 @@ choice
 
 config TARGET_STEMMY
 	bool "Samsung (stemmy) board"
+	select MISC_INIT_R
 	help
 	  The Samsung "stemmy" board supports Samsung smartphones released with
 	  the ST-Ericsson NovaThor U8500 SoC, e.g.
board/ste/stemmy/stemmy.c +87 -0

104 lines not on this page · raw message

include/configs/stemmy.h +3 -0
index c446b09270..b94ef91c2b 100644
@@ -23,4 +23,7 @@
 #define CONFIG_SYS_L2_PL310
 #define CONFIG_SYS_PL310_BASE		0xa0412000
 
+/* Generate initrd atag for downstream kernel (others are copied in stemmy.c) */
+#define CONFIG_INITRD_TAG
+
 #endif
Signature · 1 line
2.32.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] board: stemmy: Copy atags for booting downstream/vendor kernel

Quoted 24 lines · Stephan Gerhold

The U-Boot "stemmy" board is mainly intended to simplify booting mainline Linux on various smartphones from Samsung based on ST-Ericsson Ux500. While the mainline kernel is working great, there are still some features missing there. In particular, it is currently not possible to charge the battery when using the mainline kernel.

This means that it is still necessary to boot the downstream/vendor kernel from Samsung sometimes to charge the device. That kernel is ancient, still uses board files + ATAGS instead of device trees and relies on a strange very long kernel command line hardcoded in the Samsung bootloader.

Actually, since mainline is booted with device trees there is a very simple way to make the old downstream kernel work as well: We can simply take most of the ATAGS passed to U-Boot from the Samsung bootloader and copy them as-is when booting a kernel without device tree. That way the long command line and other needed ATAGS are copied as-is without having to bother with them.

The only exception is the ATAG_INITRD - since the initrd is loaded by U-Boot, the atag for that should be generated in U-Boot so it points to the correct address. All other ATAGS are copied as-is and not generated in U-Boot.

Quoted 4 lines

Also use the chance and provide a serial# for U-Boot by parsing the ATAG_SERIAL that is also passed by the Samsung bootloader.

Yours,
Linus Walleij

#3 lore raw

Re: [PATCH 2/2] board: stemmy: Copy atags for booting downstream/vendor kernel

In reply to Stephan Gerhold
Quoted 24 lines · Stephan Gerhold

The U-Boot "stemmy" board is mainly intended to simplify booting mainline Linux on various smartphones from Samsung based on ST-Ericsson Ux500. While the mainline kernel is working great, there are still some features missing there. In particular, it is currently not possible to charge the battery when using the mainline kernel.

This means that it is still necessary to boot the downstream/vendor kernel from Samsung sometimes to charge the device. That kernel is ancient, still uses board files + ATAGS instead of device trees and relies on a strange very long kernel command line hardcoded in the Samsung bootloader.

Actually, since mainline is booted with device trees there is a very simple way to make the old downstream kernel work as well: We can simply take most of the ATAGS passed to U-Boot from the Samsung bootloader and copy them as-is when booting a kernel without device tree. That way the long command line and other needed ATAGS are copied as-is without having to bother with them.

The only exception is the ATAG_INITRD - since the initrd is loaded by U-Boot, the atag for that should be generated in U-Boot so it points to the correct address. All other ATAGS are copied as-is and not generated in U-Boot.

Quoted 5 lines

Also use the chance and provide a serial# for U-Boot by parsing the ATAG_SERIAL that is also passed by the Samsung bootloader.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
Reviewed-by on v1 1/2
#4 lore raw
In reply to Stephan Gerhold
Quoted 16 lines · Stephan Gerhold

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.

Quoted 4 lines

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.

Quoted 4 lines
              - 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"

I have also used Stemmy U-boot successfully on
Samsung Galaxy Beam (GT-I8530) "gavini"
Samsung Galaxy Amp (SGH-I407) "kyle"

Yours,
Linus Walleij

#5 lore raw
In reply to Stephan Gerhold
Quoted 16 lines · Stephan Gerhold

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.

Quoted 5 lines

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom