Skip to content

Commit cf2e595

Browse files
committed
aboot: Try booting from real_{boot,recovery} partition as fallback
If it's not detecting boot image header at 512 KiB offset, try booting from 0 offset. Useful when lk2nd boots the recovery partition, at least.
1 parent 002c06e commit cf2e595

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

app/aboot/aboot.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ int boot_linux_from_mmc(void)
16251625
#endif
16261626
struct kernel64_hdr *kptr = NULL;
16271627
int current_active_slot = INVALID;
1628+
bool try_alternate_partition = false;
16281629

16291630
if (!IS_ENABLED(ABOOT_STANDALONE) && check_format_bit())
16301631
boot_into_recovery = 1;
@@ -1656,6 +1657,7 @@ int boot_linux_from_mmc(void)
16561657
else
16571658
ptn_name = "boot";
16581659

1660+
retry_boot:
16591661
index = partition_get_index(ptn_name);
16601662
ptn = partition_get_offset(index);
16611663
image_size = partition_get_size(index);
@@ -1673,8 +1675,21 @@ int boot_linux_from_mmc(void)
16731675
}
16741676

16751677
if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
1676-
dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
1677-
return ERR_INVALID_BOOT_MAGIC;
1678+
dprintf(CRITICAL, "ERROR: Invalid boot image header on partition %s\n", ptn_name);
1679+
if (!try_alternate_partition) {
1680+
try_alternate_partition = true;
1681+
if (strcmp(ptn_name, "boot") == 0) {
1682+
ptn_name = "real_boot";
1683+
} else if (strcmp(ptn_name, "recovery") == 0) {
1684+
ptn_name = "real_recovery";
1685+
} else {
1686+
dprintf(CRITICAL, "No alternate partition for %s, Abort.\n", ptn_name);
1687+
return ERR_INVALID_BOOT_MAGIC;
1688+
}
1689+
dprintf(CRITICAL, "Retrying boot with %s partition\n", ptn_name);
1690+
goto retry_boot;
1691+
}
1692+
return ERR_INVALID_BOOT_MAGIC;
16781693
}
16791694

16801695
if (hdr->page_size && (hdr->page_size != page_size)) {

0 commit comments

Comments
 (0)