@@ -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 );
@@ -1683,8 +1685,21 @@ int boot_linux_from_mmc(void)
16831685 }
16841686
16851687 if (memcmp (hdr -> magic , BOOT_MAGIC , BOOT_MAGIC_SIZE )) {
1686- dprintf (CRITICAL , "ERROR: Invalid boot image header\n" );
1687- return ERR_INVALID_BOOT_MAGIC ;
1688+ dprintf (CRITICAL , "ERROR: Invalid boot image header on partition %s\n" , ptn_name );
1689+ if (!try_alternate_partition ) {
1690+ try_alternate_partition = true;
1691+ if (strcmp (ptn_name , "boot" ) == 0 ) {
1692+ ptn_name = "real_boot" ;
1693+ } else if (strcmp (ptn_name , "recovery" ) == 0 ) {
1694+ ptn_name = "real_recovery" ;
1695+ } else {
1696+ dprintf (CRITICAL , "No alternate partition for %s, Abort.\n" , ptn_name );
1697+ return ERR_INVALID_BOOT_MAGIC ;
1698+ }
1699+ dprintf (CRITICAL , "Retrying boot with %s partition\n" , ptn_name );
1700+ goto retry_boot ;
1701+ }
1702+ return ERR_INVALID_BOOT_MAGIC ;
16881703 }
16891704
16901705 if (hdr -> page_size && (hdr -> page_size != page_size )) {
0 commit comments