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