u-boot chain-loading LineageOS bootimg
Subsystems (2)
v2 cover u-boot chain-loading LineageOS bootimg
This is a series of patches to enable chainloading LineageOS on qcom SOC.
Patch #1 introduce kconfig to ignore those default value and use loadaddr instead. That workaround some androidboot image have invalid kernel/ramdisk loadaddr.
Patch #2 override qcom soc loadaddr with fastboot_addr_r as a band-aid. Casey confirmed loadaddr and kernel_addr_r are purposely set to same address for memory-constrain case. A proper fix is far from get ready so this patch can work as a band-aid for maintainer atm.
Patch #3 optionally introduce new kconfig and env_var to get hold of legacy OS boot param for boot compatibility. It is designed initially for booting legacy Android, but newer AOSP greatly dependent on kernel bootconfig feature with vendor_boot partition so not very useful for new AOSP based OS.
Patch #4 is an example for #3 with snapdragon soc env file
Patch #5 is oprtional to default enable #1 for snapdragon machine.
Worth mentioning a patch[1] to enable EL1 chainloading kernel is needed.
[1] https://lists.denx.de/pipermail/u-boot/2025-April/585995.html
To: Tom Rini <[email protected]>
To: Mattijs Korpershoek <[email protected]>
To: Simon Glass <[email protected]>
To: Casey Connolly <[email protected]>
To: Neil Armstrong <[email protected]>
To: Sumit Garg <[email protected]>
To: Rayagonda Kokatanur <[email protected]>
Changes in v2:
- Revised patch #1 to control by kconfig, suggested by Casey
- Split old #1 into new #1 and #5 for maintainer to choose.
- Revised Casey's approach for #2 and make it as band-aid atm.
- Revised Casey's approach for #3 and leave user to bake their own param set.
- Introduce example for #1
- Introduce kconfig default for #1 with snapdragon soc, suggested by Casey
- Link to v1: https://lore.kernel.org/r/[email protected]
---
George Chan (5):
boot/image-android: Workaround kernel/ramdisk invalid addr
mach-snapdragon: Enhance android image handling memory footprint
fdt_support: Add support for extra var for bootargs qcom-phone.env: Example of new env var legacy_os_boot_param
mach-snapdragon: Enable workaround of ignoring androidboot addr
arch/arm/Kconfig | 1 + arch/arm/mach-snapdragon/board.c | 8 ++++++-- board/qualcomm/qcom-phone.env | 4 ++++ boot/Kconfig | 15 +++++++++++++++ boot/fdt_support.c | 20 +++++++++++++++++++- boot/image-android.c | 9 ++++++--- 6 files changed, 51 insertions(+), 6 deletions(-)
---
base-commit: 5a0a93a768487e55ebe50a34cc90d751bf99cc56
change-id: 20250427-android-boot-ecbb768cda72
Best regards,
Signature · 1 line
George Chan <[email protected]>
PATCH v2 1/5 boot/image-android: Workaround kernel/ramdisk invalid addr
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
boot/Kconfig +6 -0
@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidboot header. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATE
boot/image-android.c +6 -3
@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );
@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to ramdisk_addr_r */ -if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { +if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { ramdisk_ptr =env_get_ulong ("ramdisk_addr_r" ,16 ,0 );if (!ramdisk_ptr) {printf ("Invalid ramdisk_addr_r to copy ramdisk into\n" );
@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, }else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr ==0 || - img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { + img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { *rd_data = img_data.ramdisk_ptr; }else { ramdisk_ptr = img_data.ramdisk_addr;
Signature · 1 line
2.43.0
PATCH v2 2/5 mach-snapdragon: Enhance android image handling memory footprint
In reply to George ChanIn order to unzipped kernel from androidboot img, extra memory for loadaddr is needed. So once fastboot is enabled fastboot memory also share with loadaddr.
That can balance with memory constrain soc and android usecase.
--- arch/arm/mach-snapdragon/board.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm/mach-snapdragon/board.c +6 -2
@@ -500,8 +500,12 @@ int board_late_init(void) status |=env_set_hex ("ramdisk_addr_r" ,addr_alloc (SZ_128M )); status |=env_set_hex ("kernel_comp_addr_r" ,addr_alloc (KERNEL_COMP_SIZE )); status |=env_set_hex ("kernel_comp_size" ,KERNEL_COMP_SIZE ); -if (IS_ENABLED (CONFIG_FASTBOOT )) - status |=env_set_hex ("fastboot_addr_r" ,addr_alloc (FASTBOOT_BUF_SIZE )); +if (IS_ENABLED (CONFIG_FASTBOOT )) { + addr =addr_alloc (FASTBOOT_BUF_SIZE ); + status |=env_set_hex ("fastboot_addr_r" , addr); +/* override loadaddr for memory rich soc */ + status |=env_set_hex ("loadaddr" , addr); + } status |=env_set_hex ("scriptaddr" ,addr_alloc (SZ_4M )); status |=env_set_hex ("pxefile_addr_r" ,addr_alloc (SZ_4M )); addr =addr_alloc (SZ_2M );
Signature · 1 line
2.43.0
PATCH v2 3/5 fdt_support: Add support for extra var for bootargs
In reply to George ChanIntroduce a new env var 'legacy_os_boot_param' to hold legacy OS dependent boot param.
--- boot/Kconfig | 9 +++++++++ boot/fdt_support.c | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-)
boot/Kconfig +9 -0
@@ -17,6 +17,15 @@ config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR help This ignore kernel/ramdisk load addr specified in androidboot header. +config SUPPORT_LEGACY_OS_BOOTPARAM + bool "Extra var to append bootargs" + default n + help + This introduce env_var 'legacy_os_boot_param' to hold extra OS + dependent kernel boot param, and append to fdt bootargs when bootm + execute. The value is supposed to obtain from env file at compile time. + Board dependent callback will override it completely. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATE
boot/fdt_support.c +19 -1
@@ -322,9 +322,27 @@ int fdt_kaslrseed(void *fdt, bool overwrite)* board_fdt_chosen_bootargs - boards may override this function to use * alternative kernel command line arguments */ +#define COMMAND_LINE_SIZE 1024 +static char bootargs[COMMAND_LINE_SIZE ] = {0 };__weak const char *board_fdt_chosen_bootargs (const struct fdt_property *fdt_ba) { -return env_get ("bootargs" ); +if (IS_ENABLED (CONFIG_SUPPORT_LEGACY_OS_BOOTPARAM )) { +int j; +snprintf (bootargs,COMMAND_LINE_SIZE -2 ,"%s %s" , +env_get ("bootargs" ), +env_get ("legacy_os_boot_param" )); + +/* remove all carriage return */ +for (j =0 ; j <COMMAND_LINE_SIZE ; j++) { +if (bootargs[j] =='\0' ) +break ; + +if ((bootargs[j] =='\n' ) || (bootargs[j] =='\r' )) + bootargs[j] =' ' ; + } +return bootargs; + }else +return env_get ("bootargs" ); }int fdt_chosen (void *fdt)
Signature · 1 line
2.43.0
PATCH v2 4/5 qcom-phone.env: Example of new env var legacy_os_boot_param
In reply to George ChanThis is an example for newly introduced env_var legacy_os_boot_param that will append 'console=ramoops' to fdt bootargs.
--- board/qualcomm/qcom-phone.env | 4 ++++ 1 file changed, 4 insertions(+)
board/qualcomm/qcom-phone.env +4 -0
@@ -4,6 +4,10 @@ stdin=serial,button-kbd stdout=serial,vidconsole stderr=serial,vidconsole +# Introduce var to hold legacy boot param, it will be append +# to bootargs automatically +legacy_os_boot_param=console=ramoops + # Fastboot is keen to use the address from kconfig, but we # allocate its buffer at runtime. fastboot=fastboot -l $fastboot_addr_r usb 0
Signature · 1 line
2.43.0
PATCH v2 5/5 mach-snapdragon: Enable workaround of ignoring androidboot addr
In reply to George ChanEnable the workaround for whole snapdragon family.
--- arch/arm/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/Kconfig +1 -0
@@ -1124,6 +1124,7 @@ config ARCH_SNAPDRAGON select LINUX_KERNEL_IMAGE_HEADER if !ENABLE_ARM_SOC_BOOT0_HOOK select SYSRESET select SYSRESET_PSCI + select ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR imply OF_UPSTREAM imply CMD_DM imply DM_USB_GADGET
Signature · 1 line
2.43.0
Re: [PATCH v2 1/5] boot/image-android: Workaround kernel/ramdisk invalid addr
In reply to George ChanQuoted 55 lines · On 05/05/2025 11:17, George Chan via B4 Relay wrote:
From: George Chan <[email protected]>
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)boot/Kconfig +6
-0@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidboot header. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +4
-2@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to ramdisk_addr_r */ -if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { +if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { ramdisk_ptr =env_get_ulong ("ramdisk_addr_r" ,16 ,0 );if (!ramdisk_ptr) {printf ("Invalid ramdisk_addr_r to copy ramdisk into\n" );
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, · line 497
Quoted 9 lines
boot/image-android.c +2
-1@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, }else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr ==0 || - img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { + img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { *rd_data = img_data.ramdisk_ptr; }else { ramdisk_ptr = img_data.ramdisk_addr;
I like this and should be the default except rare cases, exposing the whole memory to image loading sound really dangerous..
@Mattijs would this still work on Amlogic board if we set loadaddr to the address curently used in the boot images ?
Neil
Re: [PATCH v2 2/5] mach-snapdragon: Enhance android image handling memory footprint
In reply to George ChanQuoted 18 lines · On 05/05/2025 11:17, George Chan via B4 Relay wrote:
From: George Chan <[email protected]>
In order to unzipped kernel from androidboot img, extra memory for loadaddr is needed. So once fastboot is enabled fastboot memory also share with loadaddr.
That can balance with memory constrain soc and android usecase.
Signed-off-by George Chan <[email protected]>--- arch/arm/mach-snapdragon/board.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)arch/arm/mach-snapdragon/board.c +0
-0
arch/arm/mach-snapdragon/board.c int board_late_init(void) · line 507
Quoted 10 lines
arch/arm/mach-snapdragon/board.c +5
-2@@ -500,8 +500,12 @@ int board_late_init(void) status |=env_set_hex ("ramdisk_addr_r" ,addr_alloc (SZ_128M )); status |=env_set_hex ("kernel_comp_addr_r" ,addr_alloc (KERNEL_COMP_SIZE )); status |=env_set_hex ("kernel_comp_size" ,KERNEL_COMP_SIZE ); -if (IS_ENABLED (CONFIG_FASTBOOT )) - status |=env_set_hex ("fastboot_addr_r" ,addr_alloc (FASTBOOT_BUF_SIZE )); +if (IS_ENABLED (CONFIG_FASTBOOT )) { + addr =addr_alloc (FASTBOOT_BUF_SIZE ); + status |=env_set_hex ("fastboot_addr_r" , addr); +/* override loadaddr for memory rich soc */ + status |=env_set_hex ("loadaddr" , addr);
I wouldn't make it conditional on fastboot
arch/arm/mach-snapdragon/board.c int board_late_init(void) · line 511
Quoted 5 lines
arch/arm/mach-snapdragon/board.c +1
-0+ } status |=env_set_hex ("scriptaddr" ,addr_alloc (SZ_4M )); status |=env_set_hex ("pxefile_addr_r" ,addr_alloc (SZ_4M )); addr =addr_alloc (SZ_2M );
Anyway
Re: [PATCH v2 5/5] mach-snapdragon: Enable workaround of ignoring androidboot addr
In reply to George ChanQuoted 16 lines · On 05/05/2025 11:17, George Chan via B4 Relay wrote:
From: George Chan <[email protected]>
Enable the workaround for whole snapdragon family.
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- arch/arm/Kconfig | 1 + 1 file changed, 1 insertion(+)arch/arm/Kconfig +0
-0
arch/arm/Kconfig config ARCH_SNAPDRAGON · line 1130
Quoted 7 lines
arch/arm/Kconfig +1
-0@@ -1124,6 +1124,7 @@ config ARCH_SNAPDRAGON select LINUX_KERNEL_IMAGE_HEADER if !ENABLE_ARM_SOC_BOOT0_HOOK select SYSRESET select SYSRESET_PSCI + select ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR imply OF_UPSTREAM imply CMD_DM imply DM_USB_GADGET
Re: [PATCH v2 1/5] boot/image-android: Workaround kernel/ramdisk invalid addr
In reply to George ChanHi George,
Thank you for the patch.
I really prefer this solution to the one proposed in v1.
I have tested this on Khadas VIM3 board (using khadas-vim3_android_defconfig)
I have a couple of small remarks below.
Quoted 4 lines · On lun., mai 05, 2025 at 17:17, George Chan via B4 Relay…
From: George Chan <[email protected]>
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
Can we please elaborate a bit more in the commit message? We have not explained/justified why repacking a boot image with proper kernel ramdisk/load addr is not possible.
Is the following an acceptable justification for you?
"""
Since it's not always possible to change the load addr by repacking the boot.img (due to AVB signature mismatch/<or_another_justification>), we need a way to use kernel_addr_r and ramdisk_addr_r.
"""
Feel free to reformulate the above.
Quoted 13 lines
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)boot/Kconfig +0
-0
boot/Kconfig config ANDROID_BOOT_IMAGE · line 18
Quoted 8 lines
boot/Kconfig +5
-0@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidboot header.
Please add a bit more context here, checkpatch.pl reports issues:
$ ./scripts/checkpatch.pl --u-boot --git master..HEAD
WARNING: please write a paragraph that describes the config symbol fully #27: FILE: boot/Kconfig:14:
+config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR
Quoted 9 lines
boot/Kconfig +1
-0+ config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +0
-0
boot/image-android.c static ulong android_image_get_kernel_addr(struct andr_image_data *img_data, · line 272
Quoted 6 lines
boot/image-android.c +2
-1@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {
Please fix indentation, should be:
+ if (img_data->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ||
+ IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR)) {
(checkpatch.pl reports this)
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, · line 469
Quoted 10 lines
boot/image-android.c +2
-1if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to ramdisk_addr_r */ -if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { +if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) {
Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, · line 494
Quoted 10 lines
boot/image-android.c +2
-1ramdisk_ptr =env_get_ulong ("ramdisk_addr_r" ,16 ,0 );if (!ramdisk_ptr) {printf ("Invalid ramdisk_addr_r to copy ramdisk into\n" );@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, }else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr ==0 || - img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { + img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) {
Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
Quoted 6 lines
boot/image-android.c +0
-0*rd_data = img_data.ramdisk_ptr; }else { ramdisk_ptr = img_data.ramdisk_addr;Signature · 2 lines
-- 2.43.0
Mattijs Korpershoek
Tested-byRe: [PATCH v2 1/5] boot/image-android: Workaround kernel/ramdisk invalid addr
In reply to Neil ArmstrongHi Neil,
Quoted 69 lines · Neil Armstrong
Quoted 55 lines · On 05/05/2025 11:17, George Chan via B4 Relay wrote:
From: George Chan <[email protected]>
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)boot/Kconfig +6
-0@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidboot header. + config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +4
-2@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to ramdisk_addr_r */ -if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { +if (img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { ramdisk_ptr =env_get_ulong ("ramdisk_addr_r" ,16 ,0 );if (!ramdisk_ptr) {printf ("Invalid ramdisk_addr_r to copy ramdisk into\n" );boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, · line 497
Quoted 9 lines
boot/image-android.c +2
-1@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, }else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr ==0 || - img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR ) { + img_data.ramdisk_addr ==ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR || + (IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR ))) { *rd_data = img_data.ramdisk_ptr; }else { ramdisk_ptr = img_data.ramdisk_addr;I like this and should be the default except rare cases, exposing the whole memory to image loading sound really dangerous..
Quoted 4 lines
Reviewed-by Neil Armstrong <[email protected]>@Mattijs would this still work on Amlogic board if we set loadaddr to the address curently used in the boot images ?
TLDR, yes, it would still work on Amlogic if we:
- Set CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR=y
- setenv kernel_addr_r 0x11080000
- setenv ramdisk_addr_r 0x11000000
I've experimented a bit with an old boot.img.
Some details below
NOTE: newer boot.img have different addresses, see:
https://android-review.googlesource.com/c/device/amlogic/yukawa/+/3290364
Before sending a patch for this, make sure to use the latest ramdisk_addr_r variable
This is the original boot.img I have:
$ unpack_bootimg --format info --boot_img boot.img boot magic: ANDROID! kernel_size: 19022293 kernel load address: 0x11080000 ramdisk size: 1751539 ramdisk load address: 0x11000000 second bootloader size: 0 second bootloader load address: 0x00000000 kernel tags load address: 0x10000100 page size: 2048 os version: 13.0.0 os patch level: 2023-05 boot image header version: 2 product name: command line args: no_console_suspend console=ttyAML0,115200 earlycon printk.devkmsg=on androidboot.boot_devices=soc/ffe07000.mmc init=/init firmware_class.path=/vendor/firmware androidboot.hardware=yukawa androidboot.selinux=permissive additional command line args: recovery dtbo size: 0 recovery dtbo offset: 0x0000000000000000 boot header size: 1660 dtb size: 295778 dtb address: 0x0000000011f00000
I can unpack/repack it to change "kernel load address" and "ramdisk load address" with:
$ unpack_bootimg --boot_img boot.img --out out --format=mkbootimg | tee mkbootimg_args # edit mkbootimg_args to change both --kernel_offset and --ramdisk_offset to 0x0 $ sh -c "mkbootimg $(cat mkbootimg_args) --output boot_repacked.img"
$ unpack_bootimg --format info --boot_img boot_repacked.img | grep 'load address' kernel load address: 0x00000000 ramdisk load address: 0x00000000
Reflashing the boot partition with:
$ fastboot flash boot boot_repacked.img
Without modification, this does not boot, as expected:
U-Boot 2025.07-rc1-g8ea79fc630ac (May 07 2025 - 09:30:45 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (total 3.8 GiB) Core: 407 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2
Loading Environment from MMC... MMC Device -1 not found *** Warning - No MMC card found, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0
Card did not respond to voltage select! : -110
fs uses incompatible features: 00020000, ignoring
** Booting bootflow '[email protected]' with android
avb_slot_verify.c:428: ERROR: boot: Hash of data does not match digest in descriptor.
## Booting Android Image at 0x01080000 ...
Kernel load addr 0x01080000 size 18577 KiB
Kernel command line: no_console_suspend console=ttyAML0,115200 earlycon printk.devkmsg=on androidboot.boot_devices=soc/ffe07000.mmc init=/init firmware_class.path=/vendor/firmware androidboot.hardware=yukawa androidboot.selinux=permissive RAM disk load addr 0x022a5000 size 1711 KiB
Working FDT set to 2486baf
Uncompressing Kernel Image to 1080000
lz4 compressed: uncompress error -71
Must RESET board to recover
Resetting the board...
bl31 reboot reason: 0xd
bl31 reboot reason: 0x0
system cmd 1.
With the environment variables updated, it boots fine:
U-Boot 2025.07-rc1-g31837b1f1d1d (May 07 2025 - 11:25:40 +0200) khadas-vim3
Model: Khadas VIM3 SoC: Amlogic Meson G12B (A311D) Revision 29:b (10:2) DRAM: 2 GiB (total 3.8 GiB) Core: 407 devices, 36 uclasses, devicetree: separate MMC: mmc@ffe03000: 0, mmc@ffe05000: 1, mmc@ffe07000: 2
Loading Environment from MMC... MMC Device -1 not found *** Warning - No MMC card found, using default environment
In: usbkbd,serial Out: vidconsole,serial Err: vidconsole,serial Net: eth0: ethernet@ff3f0000
Hit any key to stop autoboot: 0
=> setenv kernel_addr_r 0x11080000
=> setenv ramdisk_addr_r 0x11000000
=> run bootcmd
Card did not respond to voltage select! : -110
fs uses incompatible features: 00020000, ignoring
** Booting bootflow '[email protected]' with android
avb_slot_verify.c:428: ERROR: boot: Hash of data does not match digest in descriptor.
## Booting Android Image at 0x01080000 ...
Kernel load addr 0x11080000 size 18577 KiB
Kernel command line: no_console_suspend console=ttyAML0,115200 earlycon printk.devkmsg=on androidboot.boot_devices=soc/ffe07000.mmc init=/init firmware_class.path=/vendor/firmware androidboot.hardware=yukawa androidboot.selinux=permissive RAM disk load addr 0x022a5000 size 1711 KiB
Working FDT set to 2486baf
Uncompressing Kernel Image to 11080000
Loading Ramdisk to 7fe54000, end 7ffff9f3 ... OK
Loading Device Tree to 000000007fe3e000, end 000000007fe537b2 ... OK
Working FDT set to 7fe3e000
Thanks,
Mattijs
Quoted 5 lines
Neil
Reviewed-by Neil Armstrong <[email protected]>
Re: [PATCH v2 1/5] boot/image-android: Workaround kernel/ramdisk invalid addr
In reply to Mattijs KorpershoekHi Mattijs,
Thx for feedback.
在 2025年5月7日週三 15:47,Mattijs Korpershoek <[email protected]> 寫道:
Quoted 22 lines
Hi George,
Thank you for the patch.
I really prefer this solution to the one proposed in v1.I have tested this on Khadas VIM3 board (using
khadas-vim3_android_defconfig)I have a couple of small remarks below.
Quoted 4 lines · On lun., mai 05, 2025 at 17:17, George Chan via B4 Relay <…
From: George Chan <[email protected]>
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
Can we please elaborate a bit more in the commit message? We have not explained/justified why repacking a boot image with proper kernel ramdisk/load addr is not possible.
Quoted 9 lines
Is the following an acceptable justification for you?
"""
Since it's not always possible to change the load addr by repacking the boot.img (due to AVB signature mismatch/<or_another_justification>), we need a way to usekernel_addr_randramdisk_addr_r.
"""Feel free to reformulate the above.
Thx. let me sum up as below 2 reasons.
1. there is a concern on exposing the whole memory to image loading is dangerous
2. Since it's not always possible to change the load 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.
Quoted 23 lines
Quoted 13 lines
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)boot/Kconfig +0
-0boot/Kconfig config ANDROID_BOOT_IMAGE · line 18
Quoted 8 lines
boot/Kconfig +5
-0@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidbootheader.
Quoted 7 lines
Please add a bit more context here, checkpatch.pl reports issues:
$ ./scripts/checkpatch.pl --u-boot --git master..HEADWARNING: please write a paragraph that describes the config symbol fully #27: FILE: boot/Kconfig:14:
+configANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR
same as above.
Quoted 23 lines
boot/image-android.c static ulong android_image_get_kernel_addr(struct
Quoted 10 lines
boot/Kconfig +1
-0+ config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +0
-0@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct
andr_image_data*img_data,boot/image-android.c static ulong android_image_get_kernel_addr(struct andr_image_data *img_data, · line 272
Quoted 6 lines
boot/image-android.c +2
-1* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {Please fix indentation, should be:
boot/image-android.c +2
-0+if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {
Quoted 2 lines
(checkpatch.pl reports this)
ack.
Quoted 10 lines
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const
Quoted 4 lines
boot/image-android.c +0
-0if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, constvoid
*vendor_boot_img,boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
Quoted 3 lines
boot/image-android.c +0
-0*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to
ramdisk_addr_r*/boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 467
Quoted 1 line
boot/image-android.c +0
-1- if (img_data.ramdisk_addr ==
Quoted 9 lines
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 468
Quoted 1 line
boot/image-android.c +1
-0+ if (img_data.ramdisk_addr ==
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR||boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 469
Quoted 1 line
boot/image-android.c +1
-0+(
IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR))) {Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
ack.
Quoted 11 lines
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 470
Quoted 1 line
boot/image-android.c +0
-0ramdisk_ptr = env_get_ulong("ramdisk_addr_r", 16,0);
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 472
Quoted 2 lines
boot/image-android.c +0
-0if (!ramdisk_ptr) { printf("Invalid ramdisk_addr_r to copyramdisk into\n");
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const
Quoted 1 line
boot/image-android.c +0
-0@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, constvoid
*vendor_boot_img,boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
Quoted 4 lines
boot/image-android.c +0
-1}else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr == 0 || - img_data.ramdisk_addr ==
Quoted 9 lines
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 493
Quoted 1 line
boot/image-android.c +1
-0+ img_data.ramdisk_addr ==
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR||boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 494
Quoted 1 line
boot/image-android.c +1
-0+(
IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR))) {Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
ack.
l planed to release v3 later around end of next week and contain only patch #1 #2 and #5 to ease maintainer processing. please feel free to comment on any idea, i will include into next version.
regards,
George
Quoted 1 line
Re: [PATCH v2 1/5] boot/image-android: Workaround kernel/ramdisk invalid addr
Hi George,
Quoted 38 lines · george chan
Hi Mattijs,
Thx for feedback.
在 2025年5月7日週三 15:47,Mattijs Korpershoek <[email protected]> 寫道:
Quoted 22 lines
Hi George,
Thank you for the patch.
I really prefer this solution to the one proposed in v1.I have tested this on Khadas VIM3 board (using
khadas-vim3_android_defconfig)I have a couple of small remarks below.
Quoted 4 lines · On lun., mai 05, 2025 at 17:17, George Chan via B4 Relay <…
From: George Chan <[email protected]>
Some androidboot image have invalid kernel/ramdisk load addr, force to ignore those value and use loadaddr instead.
Can we please elaborate a bit more in the commit message? We have not explained/justified why repacking a boot image with proper kernel ramdisk/load addr is not possible.
Quoted 9 lines
Is the following an acceptable justification for you?
"""
Since it's not always possible to change the load addr by repacking the boot.img (due to AVB signature mismatch/<or_another_justification>), we need a way to usekernel_addr_randramdisk_addr_r.
"""Feel free to reformulate the above.
Quoted 8 lines
Thx. let me sum up as below 2 reasons.
1. there is a concern on exposing the whole memory to image loading is dangerous
2. Since it's not always possible to change the load addr by repacking the boot.img (mainly due to AVB signature mismatch),
we need a way to usekernel_addr_randramdisk_addr_r.
That's good summary. Please include it in the commit message for v3.
Quoted 118 lines
Quoted 25 lines
Quoted 15 lines
Suggested-by Casey Connolly <[email protected]>Signed-off-by George Chan <[email protected]>--- boot/Kconfig | 6 ++++++ boot/image-android.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)boot/Kconfig +0
-0boot/Kconfig config ANDROID_BOOT_IMAGE · line 18
Quoted 8 lines
boot/Kconfig +5
-0@@ -11,6 +11,12 @@ config ANDROID_BOOT_IMAGE This enables support for booting images which use the Android image format header. +config ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR + bool "Android Boot Image ignore addr" + default n + help + This ignore kernel/ramdisk load addr specified in androidbootheader.
Quoted 7 lines
Please add a bit more context here, checkpatch.pl reports issues:
$ ./scripts/checkpatch.pl --u-boot --git master..HEADWARNING: please write a paragraph that describes the config symbol fully #27: FILE: boot/Kconfig:14:
+configANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDRsame as above.
Quoted 23 lines
boot/image-android.c static ulong android_image_get_kernel_addr(struct
Quoted 10 lines
boot/Kconfig +1
-0+ config TIMESTAMP bool "Show image date and time when displaying image information" default y if CMD_DATEboot/image-android.c +0
-0@@ -268,7 +268,8 @@ static ulong android_image_get_kernel_addr(struct
andr_image_data*img_data,boot/image-android.c static ulong android_image_get_kernel_addr(struct andr_image_data *img_data, · line 272
Quoted 6 lines
boot/image-android.c +2
-1* * Otherwise, we will return the actual value set by the user. */ -if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR ) { +if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {Please fix indentation, should be:
boot/image-android.c +2
-0+if (img_data->kernel_addr ==ANDROID_IMAGE_DEFAULT_KERNEL_ADDR || +IS_ENABLED (CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR )) {Quoted 2 lines
(checkpatch.pl reports this)
ack.
Quoted 10 lines
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const
Quoted 4 lines
boot/image-android.c +0
-0if (comp ==IH_COMP_NONE )return img_data->kernel_ptr;return env_get_ulong ("kernel_addr_r" ,16 ,0 );@@ -464,7 +465,8 @@ int android_image_get_ramdisk(const void *hdr, constvoid
*vendor_boot_img,boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
Quoted 3 lines
boot/image-android.c +0
-0*/ if (img_data.header_version >2 ) {/* Ramdisk can't be used in-place, copy it to
ramdisk_addr_r*/boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 467
Quoted 1 line
boot/image-android.c +0
-1- if (img_data.ramdisk_addr ==Quoted 9 lines
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 468
Quoted 1 line
boot/image-android.c +1
-0+ if (img_data.ramdisk_addr ==
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR||boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 469
Quoted 1 line
boot/image-android.c +1
-0+(
IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR))) {Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
ack.
Quoted 11 lines
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 470
Quoted 1 line
boot/image-android.c +0
-0ramdisk_ptr = env_get_ulong("ramdisk_addr_r", 16,0);
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 472
Quoted 2 lines
boot/image-android.c +0
-0if (!ramdisk_ptr) { printf("Invalid ramdisk_addr_r to copyramdisk into\n");
boot/image-android.c int android_image_get_ramdisk(const void *hdr, const
Quoted 1 line
boot/image-android.c +0
-0@@ -488,7 +490,8 @@ int android_image_get_ramdisk(const void *hdr, constvoid
*vendor_boot_img,boot/image-android.c int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
Quoted 4 lines
boot/image-android.c +0
-1}else {/* Ramdisk can be used in-place, use current ptr */ if (img_data.ramdisk_addr == 0 || - img_data.ramdisk_addr ==Quoted 9 lines
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 493
Quoted 1 line
boot/image-android.c +1
-0+ img_data.ramdisk_addr ==
ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR||boot/image-android.c int android_image_get_ramdisk(const void *hdr, const · line 494
Quoted 1 line
boot/image-android.c +1
-0+(
IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_IGNORE_BLOB_ADDR))) {Same here. Also, can we please drop the leading parenthesis (IS_ENABLED( -> IS_ENABLED( to be consistent with the previous code change?
ack.
l planed to release v3 later around end of next week and contain only patch #1 #2 and #5 to ease maintainer processing. please feel free to comment on any idea, i will include into next version.
regards,
GeorgeQuoted 1 line