Skip to contentSkip to conversation

get sdm845 boards u-boot usable as a secondary bootloader

PATCH Superseded Dzmitry Sankouski 2 participants 5 messages Jan 11, 2022 – Jan 30, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover get sdm845 boards u-boot usable as a secondary bootloader

U-boot is intended to replace linux kernel in android boot image(ABL), and it's FIT payload to replace initramfs file. The boot process is similar to boot image with linux:
- android bootloader (ABL) unpacks android boot image
- ABL sets linux,initrd-start property in chosen node in unpacked FDT
- ABL sets x0 register to FDT address, and passes control to u-boot
- u-boot reads x0 register, and stores it in abl_fdt_addr env variable
- u-boot reads linux,initrd-start property,
and stores it in abl_initrd_start_addr

In this way, u-boot bootcmd relies on abl_initrd_start_addr env variable, and boils down to bootm $abl_initrd_start_addr. If more control on boot process is desired, pack a boot script in FIT image, and put it to default configuration

Dzmitry Sankouski (2):
soc: sdm845: implement ABL info collecting, add bootcommand and usage
doc
board: starqltechn: get board usable - fix defconfig and strip config
options

 arch/arm/mach-snapdragon/init_sdm845.c | 60 ++++++++++++++++++++----
 configs/starqltechn_defconfig          | 12 +++--
 doc/board/qualcomm/sdm845.rst          | 63 +++++++++++++++++++++++++-
 include/configs/sdm845.h               |  5 ++
 4 files changed, 124 insertions(+), 16 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 soc: sdm845: implement ABL info collecting, add bootcommand and usage doc

U-boot is intended to replace linux kernel in android boot image, and it's FIT payload to replace initramfs file. The boot process is similar to boot image with linux:
- android bootloader (ABL) unpacks android boot image
- ABL sets linux,initrd-start property in chosen node in unpacked FDT
- ABL sets x0 register to FDT address, and passes control to u-boot
- u-boot reads x0 register, and stores it in abl_fdt_addr env variable
- u-boot reads linux,initrd-start property,
and stores it in abl_initrd_start_addr

In this way, u-boot bootcmd relies on abl_initrd_start_addr env variable, and boils down to bootm $abl_initrd_start_addr. If more control on boot process is desired, pack a boot script in FIT image, and put it to default configuration

---
 arch/arm/mach-snapdragon/init_sdm845.c | 60 ++++++++++++++++++++----
 doc/board/qualcomm/sdm845.rst          | 63 +++++++++++++++++++++++++-
 include/configs/sdm845.h               |  5 ++
 3 files changed, 116 insertions(+), 12 deletions(-)
arch/arm/mach-snapdragon/init_sdm845.c +50 -10
index 5f53c21947..6aeaeeb53a 100644
@@ -7,6 +7,7 @@
 
 #include <init.h>
 #include <env.h>
+#include <fdtdec.h>
 #include <common.h>
 #include <asm/system.h>
 #include <asm/gpio.h>
@@ -14,6 +15,14 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static ulong fdt_addr __section(".data");
+
+void save_boot_params(ulong r0)
+{
+	fdt_addr = r0;
+	save_boot_params_ret();
+}
+
 int dram_init(void)
 {
 	return fdtdec_setup_mem_size_base();
@@ -29,8 +38,33 @@ __weak int board_init(void)
 	return 0;
 }
 
-/* Check for vol- and power buttons */
-__weak int misc_init_r(void)
+void set_abl_env(void)
+{
+	const void *fdt_blob;
+	int node, ret;
+	ulong initrd_start_prop;
+
+	ret = env_set_addr("abl_fdt_addr", fdt_addr);
+	if (ret < 0) {
+		printf("Failed to set abl device tree address\n");
+		return;
+	}
+
+	fdt_blob = (void *)fdt_addr;
+	node = fdt_path_offset(fdt_blob, "/chosen");
+	if (!node) {
+		printf("Chosen node not found in device tree at addr: 0x%ll\n", fdt_addr);
+		return;
+	}
+	initrd_start_prop = fdtdec_get_addr(fdt_blob, node, "linux,initrd-start");
+	if (!initrd_start_prop) {
+		printf("linux,initrd-start property is not set\n");
+		return;
+	}
+	env_set_addr("abl_initrd_start_addr", initrd_start_prop);
+}
+
+void read_pressed_keys(void)
 {
 	struct udevice *pon;
 	struct gpio_desc resin;
@@ -39,19 +73,19 @@ __weak int misc_init_r(void)
 	ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8998_pon@800", &pon);
 	if (ret < 0) {
 		printf("Failed to find PMIC pon node. Check device tree\n");
-		return 0;
+		return;
 	}
 
 	node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
-				  "key_vol_down");
+					  "key_vol_down");
 	if (node < 0) {
 		printf("Failed to find key_vol_down node. Check device tree\n");
-		return 0;
+		return;
 	}
 	if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
-				       &resin, 0)) {
+					   &resin, 0)) {
 		printf("Failed to request key_vol_down button.\n");
-		return 0;
+		return;
 	}
 	if (dm_gpio_get_value(&resin)) {
 		env_set("key_vol_down", "1");
@@ -64,12 +98,12 @@ __weak int misc_init_r(void)
 				  "key_power");
 	if (node < 0) {
 		printf("Failed to find key_power node. Check device tree\n");
-		return 0;
+		return;
 	}
 	if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
-				       &resin, 0)) {
+					   &resin, 0)) {
 		printf("Failed to request key_power button.\n");
-		return 0;
+		return;
 	}
 	if (dm_gpio_get_value(&resin)) {
 		env_set("key_power", "1");
@@ -77,6 +111,12 @@ __weak int misc_init_r(void)
 	} else {
 		env_set("key_power", "0");
 	}
+}
+
+__weak int misc_init_r(void)
+{
+	set_abl_env();
+	read_pressed_keys();
 
 	return 0;
 }
doc/board/qualcomm/sdm845.rst +61 -2

78 lines not on this page · raw message

include/configs/sdm845.h +5 -0
index af9ba197d4..cdf0f7e030 100644
@@ -16,6 +16,11 @@
 /* Generic Timer Definitions */
 #define COUNTER_FREQUENCY	19000000
 
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"bootm_size=0x4000000\0"	\
+	"bootcmd=bootm $abl_initrd_start_addr\0"	\
+	"bootm_low=0x80000000\0"
+
 /* Size of malloc() pool */
 #define CONFIG_SYS_BOOTM_LEN	SZ_64M
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 board: starqltechn: get board usable - fix defconfig and strip config options

In reply to Dzmitry Sankouski

- add FIT image support
- increase LMB_MAX_REGIONS, to store all linux dtb reserved memory regions
- add linux kernel image header

Uart driver causes hang, when u-boot is used in android boot image instead of linux. Temporary disable console driver, until investigated and fixed.

---
 configs/starqltechn_defconfig | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
configs/starqltechn_defconfig +8 -4
index f57bb859cc..987ce93a36 100644
@@ -2,13 +2,14 @@ CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
 CONFIG_POSITION_INDEPENDENT=y
 CONFIG_ARCH_SNAPDRAGON=y
-CONFIG_SYS_TEXT_BASE=0x80000000
-CONFIG_SYS_MALLOC_LEN=0x81f000
 CONFIG_DEFAULT_DEVICE_TREE="starqltechn"
+CONFIG_BOOTDELAY=0
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
 CONFIG_TARGET_STARQLTECHN=y
 CONFIG_IDENT_STRING="\nSamsung S9 SM-G9600"
 CONFIG_SYS_LOAD_ADDR=0x80000000
-CONFIG_USE_PREBOOT=y
+CONFIG_LMB_MAX_REGIONS=64
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y
@@ -20,5 +21,8 @@ CONFIG_PM8916_GPIO=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_PM8916=y
-CONFIG_MSM_GENI_SERIAL=y
+# todo: fix serial initialization hang, when assembled in android boot image.
+CONFIG_REQUIRE_SERIAL_CONSOLE=n
+CONFIG_MSM_GENI_SERIAL=n
 CONFIG_SPMI_MSM=y
+CONFIG_LINUX_KERNEL_IMAGE_HEADER=y
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH 2/2] board: starqltechn: get board usable - fix defconfig and strip config options

Quoted 37 lines · Dzmitry Sankouski

- add FIT image support
- increase LMB_MAX_REGIONS, to store all linux dtb reserved memory regions
- add linux kernel image header

Uart driver causes hang, when u-boot is used in android boot image instead of linux. Temporary disable console driver, until investigated and fixed.

---
 configs/starqltechn_defconfig | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
configs/starqltechn_defconfig +4 -3
index f57bb859cc..987ce93a36 100644
@@ -2,13 +2,14 @@ CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
 CONFIG_POSITION_INDEPENDENT=y
 CONFIG_ARCH_SNAPDRAGON=y
-CONFIG_SYS_TEXT_BASE=0x80000000
-CONFIG_SYS_MALLOC_LEN=0x81f000
 CONFIG_DEFAULT_DEVICE_TREE="starqltechn"
+CONFIG_BOOTDELAY=0
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
 CONFIG_TARGET_STARQLTECHN=y
 CONFIG_IDENT_STRING="\nSamsung S9 SM-G9600"
 CONFIG_SYS_LOAD_ADDR=0x80000000
-CONFIG_USE_PREBOOT=y
+CONFIG_LMB_MAX_REGIONS=64
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y

configs/starqltechn_defconfig CONFIG_PM8916_GPIO=y · line 28

Quoted 9 lines
configs/starqltechn_defconfig +4 -1
@@ -20,5 +21,8 @@ CONFIG_PM8916_GPIO=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_PM8916=y
-CONFIG_MSM_GENI_SERIAL=y
+# todo: fix serial initialization hang, when assembled in android boot image.
+CONFIG_REQUIRE_SERIAL_CONSOLE=n
+CONFIG_MSM_GENI_SERIAL=n
 CONFIG_SPMI_MSM=y
+CONFIG_LINUX_KERNEL_IMAGE_HEADER=y

As the defconfig files are (re)generated by 'savedefconfig' that comment will be lost quickly. And it needs to be "# CONFIG_FOO is not set" as well.

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH 2/2] board: starqltechn: get board usable - fix defconfig and strip config options

This patch series reimplemented in more generic way in save prev bootloader data, when u-boot chainloaded patch series

вт, 11 янв. 2022 г. в 19:19, Tom Rini <[email protected]>:

Quoted 60 lines · Dzmitry Sankouski
Quoted 3 lines

- add FIT image support
- increase LMB_MAX_REGIONS, to store all linux dtb reserved memory

regions

Quoted 3 lines

- add linux kernel image header

Uart driver causes hang, when u-boot is used in android boot image

instead

Review

Quoted 10 lines

of linux. Temporary disable console driver, until investigated and fixed.

---
 configs/starqltechn_defconfig | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/configs/starqltechn_defconfig

Quoted 22 lines

index f57bb859cc..987ce93a36 100644

configs/starqltechn_defconfig +4 -3
@@ -2,13 +2,14 @@ CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
 CONFIG_POSITION_INDEPENDENT=y
 CONFIG_ARCH_SNAPDRAGON=y
-CONFIG_SYS_TEXT_BASE=0x80000000
-CONFIG_SYS_MALLOC_LEN=0x81f000
 CONFIG_DEFAULT_DEVICE_TREE="starqltechn"
+CONFIG_BOOTDELAY=0
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
 CONFIG_TARGET_STARQLTECHN=y
 CONFIG_IDENT_STRING="\nSamsung S9 SM-G9600"
 CONFIG_SYS_LOAD_ADDR=0x80000000
-CONFIG_USE_PREBOOT=y
+CONFIG_LMB_MAX_REGIONS=64
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_GPIO=y

configs/starqltechn_defconfig CONFIG_PM8916_GPIO=y · line 24

Quoted 5 lines
configs/starqltechn_defconfig +1 -1
@@ -20,5 +21,8 @@ CONFIG_PM8916_GPIO=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_PM8916=y
-CONFIG_MSM_GENI_SERIAL=y
+# todo: fix serial initialization hang, when assembled in android boot

image.

configs/starqltechn_defconfig CONFIG_PM8916_GPIO=y · line 28

Quoted 4 lines
configs/starqltechn_defconfig +3 -0
+CONFIG_REQUIRE_SERIAL_CONSOLE=n
+CONFIG_MSM_GENI_SERIAL=n
 CONFIG_SPMI_MSM=y
+CONFIG_LINUX_KERNEL_IMAGE_HEADER=y

As the defconfig files are (re)generated by 'savedefconfig' that comment will be lost quickly. And it needs to be "# CONFIG_FOO is not set" as well.

--
Tom