Skip to content

Commit 6c4e1dc

Browse files
committed
aboot: Fix booting boot image header v2 via fastboot boot
Code copied from boot_linux_from_mmc() Change-Id: I8c6dd64eabd264f42e13e443bceae6e5cc525a38
1 parent 7650e01 commit 6c4e1dc

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

app/aboot/aboot.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,9 @@ void cmd_boot(const char *arg, void *data, unsigned sz)
32333233
unsigned int kernel_size = 0;
32343234
enum boot_type boot_type = 0;
32353235
#if DEVICE_TREE
3236+
void * image_buf = NULL;
32363237
uint8_t dtb_copied = 0;
3238+
unsigned dtb_image_size = 0;
32373239
unsigned int scratch_offset = 0;
32383240
#endif
32393241
#if VERIFIED_BOOT_2
@@ -3249,6 +3251,9 @@ void cmd_boot(const char *arg, void *data, unsigned sz)
32493251
static bool is_mdtp_activated = 0;
32503252
#endif /* MDTP_SUPPORT */
32513253
#endif
3254+
#ifdef OSVERSION_IN_BOOTIMAGE
3255+
uint32_t dtb_image_offset = 0;
3256+
#endif
32523257

32533258
#if FBCON_DISPLAY_MSG
32543259
/* Exit keys' detection thread firstly */
@@ -3286,13 +3291,39 @@ void cmd_boot(const char *arg, void *data, unsigned sz)
32863291
dt_size = hdr->dt_size;
32873292
#endif
32883293
dt_actual = ROUND_TO_PAGE(dt_size, page_mask);
3294+
dtb_image_size = hdr->kernel_size;
32893295
#endif
32903296

32913297
image_actual = ADD_OF(page_size, kernel_actual);
32923298
image_actual = ADD_OF(image_actual, ramdisk_actual);
32933299
image_actual = ADD_OF(image_actual, second_actual);
32943300
image_actual = ADD_OF(image_actual, dt_actual);
32953301

3302+
#ifdef OSVERSION_IN_BOOTIMAGE
3303+
if (hdr->header_version == BOOT_HEADER_VERSION_TWO) {
3304+
struct boot_img_hdr_v1 *hdr1 =
3305+
(struct boot_img_hdr_v1 *) (data + sizeof(boot_img_hdr));
3306+
struct boot_img_hdr_v2 *hdr2 = (struct boot_img_hdr_v2 *)
3307+
(data + sizeof(boot_img_hdr) +
3308+
BOOT_IMAGE_HEADER_V2_OFFSET);
3309+
unsigned int recovery_dtbo_actual = 0;
3310+
3311+
recovery_dtbo_actual =
3312+
ROUND_TO_PAGE(hdr1->recovery_dtbo_size, page_mask);
3313+
image_actual += recovery_dtbo_actual;
3314+
3315+
image_actual += ROUND_TO_PAGE(hdr2->dtb_size, page_mask);
3316+
3317+
3318+
dtb_image_offset = page_size +/* patched_kernel_hdr_size +*/
3319+
kernel_actual + ramdisk_actual + second_actual +
3320+
recovery_dtbo_actual;
3321+
3322+
dprintf(SPEW, "Header version: %d\n", hdr->header_version);
3323+
dprintf(SPEW, "Dtb image offset 0x%x\n", dtb_image_offset);
3324+
}
3325+
#endif
3326+
32963327
/* Checking to prevent oob access in read_der_message_length */
32973328
if (image_actual > sz) {
32983329
fastboot_fail("bootimage header fields are invalid");
@@ -3504,10 +3535,20 @@ void cmd_boot(const char *arg, void *data, unsigned sz)
35043535
* memory address to the DTB appended location on RAM.
35053536
* Else update with the atags address in the kernel header
35063537
*/
3538+
image_buf = (void*)(ptr + page_size);
3539+
3540+
#ifdef OSVERSION_IN_BOOTIMAGE
3541+
if ( hdr->header_version == BOOT_HEADER_VERSION_TWO) {
3542+
image_buf = (void*)(ptr);
3543+
dtb_offset = dtb_image_offset;
3544+
dtb_image_size = image_actual;
3545+
}
3546+
#endif
3547+
35073548
if (!dtb_copied) {
35083549
void *dtb;
3509-
dtb = dev_tree_appended((void*)(ptr + page_size),
3510-
hdr->kernel_size, dtb_offset,
3550+
dtb = dev_tree_appended(image_buf,
3551+
dtb_image_size, dtb_offset,
35113552
(void *)hdr->tags_addr);
35123553
#if WITH_LK2ND_DEVICE_2ND
35133554
if (!dtb && lk2nd_device2nd_have_atags())

0 commit comments

Comments
 (0)