Skip to contentSkip to conversation

get sdm845 boards u-boot usable as a secondary bootloader

PATCH New Dzmitry Sankouski 1 participant 3 messages Jan 11, 2022

Subsystems (2)
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 v2 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

---
Changes for v2:
- Fix compilation warnings

 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..417a928b50 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", (void *)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%lx\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", (void *)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 v2 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.

---
Changes for v2:
- replace 'n' options with 'is not set'
- remove comment from defconfig file

 configs/starqltechn_defconfig | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
configs/starqltechn_defconfig +7 -4
index f57bb859cc..fa2eebecd7 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,7 @@ CONFIG_PM8916_GPIO=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_PM8916=y
-CONFIG_MSM_GENI_SERIAL=y
+# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+# CONFIG_MSM_GENI_SERIAL is not set
 CONFIG_SPMI_MSM=y
+CONFIG_LINUX_KERNEL_IMAGE_HEADER=y
Signature · 1 line
2.20.1