A series of patch for enable sc7180 android boot
Subsystems (3)
v2 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 apply 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
This series is independent, but modified boot/Kconfig that roughly same location to another patch series[2], so directly apply both would fail. Please let me know if maintainer wanna to let the one gets applied first and rebase _OR_ combine two series as one.
[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 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 (5):
image-android: Prepend/postpend default bootargs value with given bootcmd
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 | 7 +++++++ boot/bootm.c | 29 ++++++++++++++++++++++++++++- boot/bootmeth_android.c | 2 +- boot/image-android.c | 10 ++++++++-- drivers/iommu/qcom-hyp-smmu.c | 1 + drivers/usb/gadget/Kconfig | 2 ++ include/image.h | 3 ++- 7 files changed, 49 insertions(+), 5 deletions(-)
---
base-commit: a822b95da4b799bdc2a42c06923af4359238dc9e
change-id: 20250520-sc7180-android-boot-a845ecf48a48
Best regards,
Signature · 1 line
George Chan <[email protected]>
PATCH v2 1/5 image-android: Prepend/postpend default bootargs value with given bootcmd
Control how default bootargs is prepended or postpended to boot param found from androidboot img.
--- boot/Kconfig | 7 +++++++ boot/image-android.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
boot/Kconfig +7 -0
@@ -11,6 +11,13 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS + bool "Android Boot Image boot cmd param will prepend to env bootargs" + help + This control how androidboot img with bootcmd param integrate with u-boot + env bootargs. By enable this, androidboot boot param will prepend to + head of bootargs env. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATE
boot/image-android.c +8 -2
@@ -347,14 +347,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) {
@@ -369,6 +369,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
Re: [PATCH v2 1/5] image-android: Prepend/postpend default bootargs value with given bootcmd
Hi George,
Thank you for the patch.
I have a couple of small remarks on wording/spelling but the code change looks good already.
Quoted 4 lines · On Sat, Jun 07, 2025 at 13:24, George Chan via B4 Relay…
From: George Chan <[email protected]>
Control how default bootargs is prepended or postpended to boot param found from androidboot img.
Let's rephrase to be slightly more accurate, and add a problem statement first:
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.
with ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS=y, the resulting commandline would be:
androidboot.hardware=chilly [...] androidboot.hardware=warm.
(feel free to rephrase some parts to your liking)
Quoted 12 lines
Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 7 +++++++ boot/image-android.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)boot/Kconfig +0
-0
boot/Kconfig config ANDROID_BOOT_IMAGE · line 17
Quoted 7 lines
boot/Kconfig +4
-0@@ -11,6 +11,13 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS + bool "Android Boot Image boot cmd param will prepend to env bootargs" + help + This control how androidboot img with bootcmd param integrate with u-boot
Please, no abbreviations and some minor spelling tweaks:
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.
(Note: We use cmdline here since that's the terminology used by Android's mkbootimg tool [1])
[1] https://android.googlesource.com/platform/system/tools/mkbootimg/+/refs/heads/main/mkbootimg.py#511
With the wording fixed, please add
Also, Casey, feel free to pick of the reworded version through your tree !
Quoted 43 lines
boot/Kconfig +3
-0+ env bootargs. By enable this, androidboot boot param will prepend to + head of bootargs env. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +8
-2@@ -347,14 +347,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) {@@ -369,6 +369,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 · 2 lines
-- 2.43.0
PATCH v2 2/5 bootm: Append bootargs value when bootmeth_android provide cmdline
In reply to George ChanOld logic wipe bootargs env with cmdline, new logic maintain the value by prepending cmdline value to bootargs.
--- boot/bootm.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
boot/bootm.c +28 -1
@@ -1152,11 +1152,38 @@ int bootm_boot_start(ulong addr, const char *cmdline)snprintf (addr_str,sizeof (addr_str),"%lx" , addr); - ret =env_set ("bootargs" , cmdline); +if (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_PREPEND_ENV_BOOTARGS )) { +char *bootargs; +char *newbootargs; + bootargs =env_get ("bootargs" ); + ret =strlen (bootargs) +strlen (cmdline) +2 ; + + newbootargs =malloc (ret); + + *newbootargs ='\0' ; + +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, cmdline); + +if (*newbootargs)/* If there is something in newbootargs, a space is needed */ +strcat (newbootargs," " ); +strcat (newbootargs, bootargs); + +/* force to terminate the string */ +memset (newbootargs +MAX_CMDLINE_SIZE -2 ,'\0' ,1 ); + + ret =env_set ("bootargs" , newbootargs); + +free (newbootargs); + }else + ret =env_set ("bootargs" , cmdline); +if (ret) {printf ("Failed to set cmdline\n" );return ret; } +bootm_init (&bmi); bmi.addr_img = addr_str; bmi.cmd_name ="bootm" ;
Signature · 1 line
2.43.0
PATCH v2 3/5 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 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
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 -1
@@ -2038,7 +2038,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 *
@@ -2059,6 +2059,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
Re: [PATCH v2 3/5] boot: bootmeth_android: Conditionally dependent on abootimg
Hi George,
Thank you for the patch.
Quoted 4 lines · On Sat, Jun 07, 2025 at 13:24, George Chan via B4 Relay…
From: George Chan <[email protected]>
If target u-boot img do not support androidboot v3 or greater, abootimg might not be necessary.
Indeed, and this is already handled properly in ./boot/bootm.c and ./boot/image-board.c.
Quoted 7 lines
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 toset_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 toset_abootimg_addr' Segmentation fault (core dumped)Signed-off-by George Chan <[email protected]>
Casey, feel free to pick this up through your tree.
Quoted 42 lines
--- boot/bootmeth_android.c | 2 +- include/image.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)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
-1@@ -2038,7 +2038,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 * @@ -2059,6 +2059,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 · 2 lines
-- 2.43.0
PATCH v2 4/5 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
@@ -388,6 +388,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 v2 5/5 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
Re: [PATCH v2 5/5] usb: gadget: Introduce usb gadget vendor/product default id for ARCH_QCOM
Hi George,
Thank you for the patch.
Quoted 7 lines · On Sat, Jun 07, 2025 at 13:25, George Chan via B4 Relay…
From: George Chan <[email protected]>
Currently 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.
Signed-off-by George Chan <[email protected]>Reviewed-by Neil Armstrong <[email protected]>
Casey, even if this is usb gadget, feel free to pick this up in your tree.
Thanks,
Mattijs
Quoted 27 lines
--- 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 · 2 lines
-- 2.43.0