Skip to contentSkip to conversation

boot: android: fix booting without a ramdisk

PATCH Superseded Michael Walle 2 participants 2 messages Jul 26, 2024 – Jul 28, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot: android: fix booting without a ramdisk

android_image_get_ramdisk() will return an error if there is no ramdisk. Using the android image without a ramdisk worked until commit 1ce8e10f3b4b ("image: Fix up ANDROID_BOOT_IMAGE ramdisk code") because that return code wasn't checked. Now that it is checked, don't return an error in the (valid) case that there is no ramdisk in the image.

With this, I'm able to boot a linux kernel using fastboot again:

  fastboot --base 0x41000000 --header-version 2 --dtb /path/to/dtb \
  --cmdline "root=/dev/mmcblk0p1 rootwait" boot path/to/Image
---
 boot/image-android.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/image-android.c +1 -1
index 09c7a44e058..0900579ee8c 100644
@@ -395,7 +395,7 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
 
 	if (!img_data.ramdisk_size) {
 		*rd_data = *rd_len = 0;
-		return -1;
+		return 0;
 	}
 	if (img_data.header_version > 2) {
 		ramdisk_ptr = img_data.ramdisk_addr;
Signature · 1 line
2.39.2
#1 lore raw

Hi Michael,

Quoted 31 lines · Michael Walle

android_image_get_ramdisk() will return an error if there is no ramdisk. Using the android image without a ramdisk worked until commit 1ce8e10f3b4b ("image: Fix up ANDROID_BOOT_IMAGE ramdisk code") because that return code wasn't checked. Now that it is checked, don't return an error in the (valid) case that there is no ramdisk in the image.

With this, I'm able to boot a linux kernel using fastboot again:

  fastboot --base 0x41000000 --header-version 2 --dtb /path/to/dtb \
  --cmdline "root=/dev/mmcblk0p1 rootwait" boot path/to/Image
---
 boot/image-android.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/image-android.c +1 -2
index 09c7a44e058..0900579ee8c 100644
@@ -395,7 +395,7 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
 
        if (!img_data.ramdisk_size) {
                *rd_data = *rd_len = 0;
-               return -1;
+               return 0;
        }
        if (img_data.header_version > 2) {
                ramdisk_ptr = img_data.ramdisk_addr;
--
Quoted 2 lines

2.39.2

Rather than squashing the information here, you should return a value that indicates there is no ramdisk. Normally in U-Boot this is -ENOENT. Then the caller can check it. Also please update the function docs in the header.

I see that -EINVAL is returned for some other error, so the caller should be careful to just allow -ENOENT.

Regards,
Simon