@@ -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 ;
@@ -1653,6 +1654,7 @@ int boot_linux_from_mmc(void)
16531654 }
16541655 }
16551656
1657+ retry_boot :
16561658 index = partition_get_index (ptn_name );
16571659 ptn = partition_get_offset (index );
16581660 image_size = partition_get_size (index );
@@ -1670,8 +1672,21 @@ int boot_linux_from_mmc(void)
16701672 }
16711673
16721674 if (memcmp (hdr -> magic , BOOT_MAGIC , BOOT_MAGIC_SIZE )) {
1673- dprintf (CRITICAL , "ERROR: Invalid boot image header\n" );
1674- return ERR_INVALID_BOOT_MAGIC ;
1675+ dprintf (CRITICAL , "ERROR: Invalid boot image header on partition %s\n" , ptn_name );
1676+ if (IS_ENABLED (WITH_LK2ND_DEVICE_2ND ) && !try_alternate_partition ) {
1677+ try_alternate_partition = true;
1678+ if (strcmp (ptn_name , "boot" ) == 0 ) {
1679+ ptn_name = "real_boot" ;
1680+ } else if (strcmp (ptn_name , "recovery" ) == 0 ) {
1681+ ptn_name = "real_recovery" ;
1682+ } else {
1683+ dprintf (CRITICAL , "No alternate partition for %s, Abort.\n" , ptn_name );
1684+ return ERR_INVALID_BOOT_MAGIC ;
1685+ }
1686+ dprintf (CRITICAL , "Retrying boot with %s partition\n" , ptn_name );
1687+ goto retry_boot ;
1688+ }
1689+ return ERR_INVALID_BOOT_MAGIC ;
16751690 }
16761691
16771692 if (hdr -> page_size && (hdr -> page_size != page_size )) {
0 commit comments