[PATCH] boot: android: Fix ramdisk loading for v2 header

Before commit da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+"), the ramdisk was loaded from img_data.ramdisk_ptr, ignoring offset provided via mkbootimg.
commit da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+") rightfully fixes this by switching to use img_data.ramdisk_addr instead.
However, it does not copy the ramdisk content to img_data.ramdisk_addr in case we use boot image v2.
Because of this, we can no longer boot Android on Khadas vim3 board:
[ 3.940361] RAMDISK: Couldn't find valid RAM disk image starting at 0.
Add the missing memcpy() to fix the issue.
Fixes: da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+") Signed-off-by: Mattijs Korpershoek mkorpershoek@baylibre.com --- Note that on default AOSP boot images, there is another bug: the ramdisk offset is wronly configured:
$ file boot.img boot.img: Android bootimg, kernel (0x11080000), ramdisk (0x11000000), page size: 2048
With this, we have a maximum ramdisk size of 0x80000 bytes (512KiB) which is not enough. The kernel would overlap on the ramdisk address.
This can be fixed by repacking the boot image: $ unpack_bootimg --boot_img boot.img --out out --format=mkbootimg | \ tee mkbootimg_args
$ vim mkbootimg_args # change --ramdisk_offset to 0x20000000
$ sh -c "mkbootimg $(cat mkbootimg_args) -o boot_repacked.img" --- boot/image-android.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/boot/image-android.c b/boot/image-android.c index 774565fd1fea..8934491c35f2 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -409,6 +409,10 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, (ramdisk_ptr), (void *)img_data.bootconfig_addr, img_data.bootconfig_size); } + } else { + ramdisk_ptr = img_data.ramdisk_addr; + memcpy((void *)(ramdisk_ptr), (void *)img_data.ramdisk_ptr, + img_data.ramdisk_size); }
printf("RAM disk load addr 0x%08lx size %u KiB\n",
--- base-commit: 9cfe0cab3bf135a505e1e163ca442a4e4064d58e change-id: 20241003-android-fix-boot-v2-ada82163bd05
Best regards,

On Thu, 03 Oct 2024 14:42:39 +0200, Mattijs Korpershoek wrote:
Before commit da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+"), the ramdisk was loaded from img_data.ramdisk_ptr, ignoring offset provided via mkbootimg.
commit da3447d09fa0 ("android: Fix ramdisk loading for bootimage v3+") rightfully fixes this by switching to use img_data.ramdisk_addr instead.
[...]
Applied to u-boot/master, thanks!
participants (2)
-
Mattijs Korpershoek
-
Tom Rini