A series of patch for enable sc7180 android boot
Subsystems (3)
v3 cover A series of patch for enable sc7180 android boot
Since attempt[1] to embed android specific boot param into fdt bootargs, a new idea is formed as to make use of env file to contain default param value. Current code logic is already working fine, unless the priority of param at begining is higher than at tail. From env file, bootargs is treated important, and prepend at begining. So there is a need to reverse the logic, and make sure default bootargs value at the end, and let androidboot img bootargs value sit at begining.
So a new kconfig item is introduced. Once enabled, the bootargs strcat param will get reversed.
A similar logic is needed for fastboot->bootm glue function, so split function of patch #1 into 2 functions as #2, fixed some issues #3, and apply #4 with same trick to glue function too.
Some one-liners patch is included to enable device driver for sc7180 soc. It is about iommu for usb, usb gadget vendor/product id.
Reduce dependency on abootimg when androidboot v3 or greater is not needed. Since Tom suggested to reduce __maybe_unused directive and use IS_ENABLE() instead; two __weak func proto need to add into image.h
[1]https://lists.denx.de/pipermail/u-boot/2025-May/588828.html [2]https://lists.denx.de/pipermail/u-boot/2025-May/589926.html
---
Changes in v3:
- Collect acks-by and review-by.
- Split function and replace old #2 into #2-#4, code reuse in #4
- Modify changelog and Kconfig description of #1, suggested by Mattijs
- Slightly modify #5, add back line break.
- Rebase to latest next
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Add new patch #2 that is same trick as #1 to fastboot->bootm glue layer.
- Remove default n to patch #1, suggested by Tom.
- Use IS_ENABLE() instead, suggested by Tom.
- Collect review-by from Casey and Neil.
- Rebase to u-boot/next branch.
- CCing myself too.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
George Chan (7):
image-android: Prepend/postpend default bootargs value with given bootcmd boot/image-android.c: Split android_image_get_kernel into two functions image-android.c: Add null check to bootargs and cmdline
bootm: Append bootargs value when bootmeth_android provide cmdline
boot: bootmeth_android: Conditionally dependent on abootimg
iommu: qcom-smmu: Introduce sc7180 compatible string
usb: gadget: Introduce usb gadget vendor/product default id for ARCH_QCOM
boot/Kconfig | 9 ++++ boot/bootm.c | 2 +- boot/bootmeth_android.c | 2 +- boot/image-android.c | 107 +++++++++++++++++++++++++++++------------- drivers/iommu/qcom-hyp-smmu.c | 1 + drivers/usb/gadget/Kconfig | 2 + include/image.h | 14 ++++++ 7 files changed, 102 insertions(+), 35 deletions(-)
---
base-commit: 490ae8ceae2d5999c9de863e014e463f5c1495a6
change-id: 20250520-sc7180-android-boot-a845ecf48a48
Best regards,
Signature · 1 line
George Chan <[email protected]>
PATCH v3 1/7 image-android: Prepend/postpend default bootargs value with given bootcmd
By default, the boot.img's cmdline are appended to the bootargs environment.
If we take a cmdline example of:
* androidboot.hardware=warm (in U-Boot environment)
* androidboot.hardware=chilly (in boot.img's cmdline)
The resulting commandline will be:
androidboot.hardware=warm [...] androidboot.hardware=chilly.
Because of this, the U-Boot environment always take priority on the boot.img.
If we want to have a single U-Boot binary that support multiple board variants, we can't override androidboot.hardware via the boot.img.
Add a new Kconfig option, ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS that reverse the logic.
Above detail is suggested from Mattijs Korpershoek <[email protected]>
--- boot/Kconfig | 9 +++++++++ boot/image-android.c | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
boot/Kconfig +9 -0
@@ -22,6 +22,15 @@ config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR addr by repacking the boot.img (mainly due to AVB signature mismatch), we need a way to use kernel_addr_r and ramdisk_addr_r. +config ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS + bool "Android Boot Image boot cmd param will prepend to env bootargs" + help + This controls how Android boot image embedded cmdline integrates + with U-Boot bootargs environment. + + By enabling this, the boot.img's cmdline is prepended to the bootargs + environment. By default, when disabled, the cmdline is appended. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATE
boot/image-android.c +8 -2
@@ -348,14 +348,14 @@ int android_image_get_kernel(const void *hdr, len +=strlen (img_data.kcmdline_extra) + (len ?1 :0 );/* +1 for extra space */ } -char *newbootargs =malloc (len +1 );/* +1 for the '\0' */ +char *newbootargs =malloc (len +2 );/* +2 for 2x '\0' */ if (!newbootargs) {puts ("Error: malloc in android_image_get_kernel failed!\n" );return -ENOMEM ; } *newbootargs ='\0' ;/* set to Null in case no components below are present */ -if (bootargs) +if (bootargs && !IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS ))strcpy (newbootargs, bootargs);if (img_data.kcmdline && *img_data.kcmdline) {
@@ -370,6 +370,12 @@ int android_image_get_kernel(const void *hdr,strcat (newbootargs, img_data.kcmdline_extra); } +if (bootargs &&IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) { +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, bootargs); + } +env_set ("bootargs" , newbootargs);free (newbootargs);
Signature · 1 line
2.43.0
PATCH v3 2/7 boot/image-android.c: Split android_image_get_kernel into two functions
In reply to George ChanSince fastboot->bootm glue layer also need to cater with bootargs environment, so move common logic from android_image_get_kernel into a new function to avoid some degree of code duplication.
This new function is android_image_modify_bootargs_env to specially cater bootargs env value with boot image provided cmdline.
--- boot/image-android.c | 106 ++++++++++++++++++++++++++++++++------------------- include/image.h | 12 ++++++ 2 files changed, 79 insertions(+), 39 deletions(-)
boot/image-android.c +67 -39
@@ -285,6 +285,65 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,return img_data->kernel_addr; } +/** +* android_image_modify_bootargs_env() - helper to set new bootargs +* +* set boot based on provided cmdline and u-boot pre-set value +* +* @cmd: usually contain kernel boot command line string +* @cmd_extra: usually contain kernel boot command line string from vendor img +* return: 0, success; otherwise fail in various problem. +*/ +int android_image_modify_bootargs_env (const char *cmd,const char *cmd_extra) { +char *bootargs =env_get ("bootargs" ); +char *newbootargs; +int len =0 ; + +if (bootargs) + len +=strlen (bootargs); + +if (cmd && *cmd) + len +=strlen (cmd) + (len ?1 :0 );/* +1 for extra space */ + +if (cmd_extra && *cmd_extra) + len +=strlen (cmd_extra) + (len ?1 :0 );/* +1 for extra space */ + + newbootargs =malloc (len +2 );/* +2 for 2x '\0' */ + +if (!newbootargs) { +puts ("Error: malloc in android_image_get_kernel failed!\n" ); +return -ENOMEM ; + } + + *newbootargs ='\0' ;/* set to Null in case no components below are present */ + +if (bootargs && !IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) +strcpy (newbootargs, bootargs); + +if (cmd && *cmd) { +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, cmd); + } + +if (cmd_extra && *cmd_extra) { +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, cmd_extra); + } + +if (bootargs &&IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) { +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, bootargs); + } + +env_set ("bootargs" , newbootargs); +free (newbootargs); + +return 0 ; +} +/** * android_image_get_kernel() - processes kernel part of Android boot images * @hdr: Pointer to boot image header, which is at the start
@@ -310,6 +369,8 @@ int android_image_get_kernel(const void *hdr,ulong kernel_addr;const struct legacy_img_hdr *ihdr;ulong comp; +const char *cmd, *cmd_extra; +int ret;if (!android_image_get_data (hdr, vendor_boot_img, &img_data))return -EINVAL ;
@@ -330,54 +391,21 @@ int android_image_get_kernel(const void *hdr,printf ("Android's image name: %s\n" , andr_tmp_str);printf ("Kernel load addr 0x%08lx size %u KiB\n" , - kernel_addr,DIV_ROUND_UP (img_data.kernel_size,1024 )); - -int len =0 ; -char *bootargs =env_get ("bootargs" ); - -if (bootargs) - len +=strlen (bootargs); + kernel_addr,DIV_ROUND_UP (img_data.kernel_size,1024 ));if (img_data.kcmdline && *img_data.kcmdline) {printf ("Kernel command line: %s\n" , img_data.kcmdline); - len +=strlen (img_data.kcmdline) + (len ?1 :0 );/* +1 for extra space */ + cmd = img_data.kcmdline; }if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {printf ("Kernel extra command line: %s\n" , img_data.kcmdline_extra); - len +=strlen (img_data.kcmdline_extra) + (len ?1 :0 );/* +1 for extra space */ - } - -char *newbootargs =malloc (len +2 );/* +2 for 2x '\0' */ -if (!newbootargs) { -puts ("Error: malloc in android_image_get_kernel failed!\n" ); -return -ENOMEM ; - } - *newbootargs ='\0' ;/* set to Null in case no components below are present */ - -if (bootargs && !IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) -strcpy (newbootargs, bootargs); - -if (img_data.kcmdline && *img_data.kcmdline) { -if (*newbootargs)/* If there is something in newbootargs, a space is needed */ -strcat (newbootargs," " ); -strcat (newbootargs, img_data.kcmdline); + cmd_extra = img_data.kcmdline_extra; } -if (img_data.kcmdline_extra && *img_data.kcmdline_extra) { -if (*newbootargs)/* If there is something in newbootargs, a space is needed */ -strcat (newbootargs," " ); -strcat (newbootargs, img_data.kcmdline_extra); - } - -if (bootargs &&IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) { -if (*newbootargs)/* If there is something in newbootargs, a space is needed */ -strcat (newbootargs," " ); -strcat (newbootargs, bootargs); - } - -env_set ("bootargs" , newbootargs); -free (newbootargs); + ret =android_image_modify_bootargs_env (cmd, cmd_extra); +if (ret) +return ret;if (os_data) {if (image_get_magic (ihdr) ==IH_MAGIC ) {
include/image.h +12 -0
@@ -1890,6 +1890,18 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,struct andr_boot_img_hdr_v0 ; +/** +* android_image_modify_bootargs_env() - helper to set new bootargs +* +* set boot based on provided cmdline and u-boot pre-set value +* +* @cmd: usually contain kernel boot command line string +* @cmd_extra: usually contain kernel boot command line string from vendor img +* return: 0, success; otherwise fail in various problem. +*/ +int android_image_modify_bootargs_env (const char *cmd, +const char *cmd_extra); +/** * android_image_get_kernel() - Processes kernel part of Android boot images *
Signature · 1 line
2.43.0
PATCH v3 3/7 image-android.c: Add null check to bootargs and cmdline
In reply to George ChanWith some manual testing, when bootargs and/or cmdline from android boot image is absent there will be some unhandled behavior happened.
So add null check to all these const char values.
--- boot/image-android.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
boot/image-android.c +17 -10
@@ -299,15 +299,20 @@ int android_image_modify_bootargs_env(const char *cmd, const char *cmd_extra) {char *newbootargs;int len =0 ; -if (bootargs) - len +=strlen (bootargs); - -if (cmd && *cmd) +if (cmd !=NULL && cmd && *cmd) len +=strlen (cmd) + (len ?1 :0 );/* +1 for extra space */ -if (cmd_extra && *cmd_extra) +if (cmd_extra !=NULL && cmd_extra && *cmd_extra) len +=strlen (cmd_extra) + (len ?1 :0 );/* +1 for extra space */ +if (len <=2 ) { +puts ("Error: neither bootargs, ccmdline or cmdline_extra found!\n" ); +return 0 ; + } + +if (bootargs !=NULL && bootargs && *bootargs) + len +=strlen (bootargs); + newbootargs =malloc (len +2 );/* +2 for 2x '\0' */ if (!newbootargs) {
@@ -317,22 +322,24 @@ int android_image_modify_bootargs_env(const char *cmd, const char *cmd_extra) { *newbootargs ='\0' ;/* set to Null in case no components below are present */ -if (bootargs && !IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) -strcpy (newbootargs, bootargs); +if (bootargs !=NULL && bootargs && *bootargs + && !IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) +strcat (newbootargs, bootargs); -if (cmd && *cmd) { +if (cmd !=NULL && cmd && *cmd) {if (*newbootargs)/* If there is something in newbootargs, a space is needed */ strcat (newbootargs," " );strcat (newbootargs, cmd); } -if (cmd_extra && *cmd_extra) { +if (cmd_extra !=NULL && cmd_extra && *cmd_extra) {if (*newbootargs)/* If there is something in newbootargs, a space is needed */ strcat (newbootargs," " );strcat (newbootargs, cmd_extra); } -if (bootargs &&IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) { +if (bootargs !=NULL && bootargs && *bootargs + &&IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) {if (*newbootargs)/* If there is something in newbootargs, a space is needed */ strcat (newbootargs," " );strcat (newbootargs, bootargs);
Signature · 1 line
2.43.0
PATCH v3 4/7 bootm: Append bootargs value when bootmeth_android provide cmdline
In reply to George ChanOld logic wipe bootargs env with cmdline, new logic cater the value by prepending cmdline value to bootargs.
--- boot/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
boot/bootm.c +1 -1
@@ -1165,7 +1165,7 @@ int bootm_boot_start(ulong addr, const char *cmdline)snprintf (addr_str,sizeof (addr_str),"%lx" , addr); - ret =env_set ("bootargs" , cmdline); + ret =android_image_modify_bootargs_env (cmdline,NULL );if (ret) {printf ("Failed to set cmdline\n" );return ret;
Signature · 1 line
2.43.0
PATCH v3 5/7 boot: bootmeth_android: Conditionally dependent on abootimg
In reply to George ChanIf target u-boot img do not support androidboot v3 or greater, abootimg might not be necessary.
aarch64-linux-gnu-ld.bfd: boot/bootmeth_android.o: in function `boot_android_normal':
/home/user/sources/u-boot-next/boot/bootmeth_android.c:541:(.text.boot_android_normal+0xd0): undefined reference to set_avendor_bootimg_addr' aarch64-linux-gnu-ld.bfd: /home/user/sources/u-boot-next/boot/bootmeth_android.c:543:(.text.boot_android_normal+0xd8): undefined reference to set_abootimg_addr' Segmentation fault (core dumped)
--- boot/bootmeth_android.c | 2 +- include/image.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
boot/bootmeth_android.c +1 -1
@@ -534,7 +534,7 @@ static int boot_android_normal(struct bootflow *bflow)if (ret <0 )return log_msg_ret ("read boot" , ret); -if (priv->header_version >=3 ) { +if (IS_ENABLED (CONFIG_CMD_ABOOTIMG ) && priv->header_version >=3 ) { ret =read_slotted_partition (desc,"vendor_boot" , priv->slot, priv->vendor_boot_img_size, vloadaddr);if (ret <0 )
include/image.h +2 -0
@@ -2050,6 +2050,7 @@ ulong get_abootimg_addr(void);* Return: no returned results */ void set_abootimg_addr (ulong addr); +void __weak set_abootimg_addr (ulong addr) {}/** * get_ainit_bootimg_addr() - Get Android init boot image address
@@ -2071,6 +2072,7 @@ ulong get_avendor_bootimg_addr(void);* Return: no returned results */ void set_avendor_bootimg_addr (ulong addr); +void __weak set_avendor_bootimg_addr (ulong addr) {}/** * board_fit_config_name_match() - Check for a matching board name
Signature · 1 line
2.43.0
PATCH v3 6/7 iommu: qcom-smmu: Introduce sc7180 compatible string
In reply to George ChanAdd basic compatible string for sc7180 family soc.
--- drivers/iommu/qcom-hyp-smmu.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/qcom-hyp-smmu.c +1 -0
@@ -389,6 +389,7 @@ static struct iommu_ops qcom_smmu_ops = {static const struct udevice_id qcom_smmu500_ids[] = { { .compatible ="qcom,sdm845-smmu-500" }, + { .compatible ="qcom,sc7180-smmu-500" }, { .compatible ="qcom,sc7280-smmu-500" }, { .compatible ="qcom,smmu-500" , }, {/* sentinel */ }
Signature · 1 line
2.43.0
PATCH v3 7/7 usb: gadget: Introduce usb gadget vendor/product default id for ARCH_QCOM
In reply to George ChanCurrently vendor/product id are both 0, and that might not as we want. Set to some arbitary known value that we can make it work more smoothly.
--- drivers/usb/gadget/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/gadget/Kconfig +2 -0
@@ -60,6 +60,7 @@ config USB_GADGET_VENDOR_NUM default 0x0955 if ARCH_TEGRA default 0x1f3a if ARCH_SUNXI default 0x2207 if ARCH_ROCKCHIP + default 0x18d1 if ARCH_QCOM default 0x0 help Vendor ID of the USB device emulated, reported to the host device.
@@ -86,6 +87,7 @@ config USB_GADGET_PRODUCT_NUM default 0x350a if ROCKCHIP_RK3568 default 0x350b if ROCKCHIP_RK3588 default 0x350c if ROCKCHIP_RK3528 + default 0x4ee0 if ARCH_QCOM default 0x0 help Product ID of the USB device emulated, reported to the host device.
Signature · 1 line
2.43.0