@@ -1576,6 +1576,53 @@ void get_recovery_dtbo_info(uint32_t *dtbo_size, void **dtbo_buf)
15761576 return ;
15771577}
15781578
1579+ bool detect_android_from_mmc (void )
1580+ {
1581+ char * ptn_names [] = {"boot" , "real_boot" };
1582+ unsigned int i ;
1583+ int index = INVALID_PTN ;
1584+ unsigned long long ptn = 0 ;
1585+ uint64_t image_size = 0 ;
1586+ unsigned offset = 0 ;
1587+ boot_img_hdr * hdr = (void * ) buf ;
1588+ static bool finish = false, result = false;
1589+
1590+ if (finish )
1591+ return result ;
1592+
1593+ for (i = 0 ; i < ARRAY_SIZE (ptn_names ); i ++ ) {
1594+ index = partition_get_index (ptn_names [i ]);
1595+ if (index != INVALID_PTN ) {
1596+ ptn = partition_get_offset (index );
1597+ image_size = partition_get_size (index );
1598+ }
1599+ if (index == INVALID_PTN || ptn == 0 || image_size == 0 ) {
1600+ dprintf (CRITICAL , "ERROR: No %s partition found\n" , ptn_names [i ]);
1601+ continue ;
1602+ }
1603+ goto detect ;
1604+ }
1605+ goto out ;
1606+
1607+ detect :
1608+ /* Set Lun for boot & recovery partitions */
1609+ mmc_set_lun (partition_get_lun (index ));
1610+
1611+ if (mmc_read (ptn + offset , (uint32_t * ) buf , page_size )) {
1612+ dprintf (CRITICAL , "ERROR: Cannot read boot image header\n" );
1613+ goto out ;
1614+ }
1615+
1616+ if (strstr ((const char * )hdr -> cmdline , "androidboot." )) {
1617+ dprintf (INFO , "Detected Android boot parameter\n" );
1618+ result = true;
1619+ }
1620+
1621+ out :
1622+ finish = true;
1623+ return result ;
1624+ }
1625+
15791626int boot_linux_from_mmc (void )
15801627{
15811628 boot_img_hdr * hdr = (void * ) buf ;
@@ -1627,7 +1674,7 @@ int boot_linux_from_mmc(void)
16271674 int current_active_slot = INVALID ;
16281675 bool try_alternate_partition = false;
16291676
1630- if (! IS_ENABLED ( ABOOT_STANDALONE ) && check_format_bit ())
1677+ if (detect_android_from_mmc ( ) && check_format_bit ())
16311678 boot_into_recovery = 1 ;
16321679
16331680 if (!IS_ENABLED (ABOOT_STANDALONE ) && !boot_into_recovery ) {
@@ -5686,7 +5733,7 @@ void aboot_init(const struct app_descriptor *app)
56865733
56875734 if (target_is_emmc_boot ())
56885735 {
5689- if (! IS_ENABLED ( ABOOT_STANDALONE ) && emmc_recovery_init ())
5736+ if (detect_android_from_mmc ( ) && emmc_recovery_init ())
56905737 dprintf (ALWAYS ,"error in emmc_recovery_init\n" );
56915738 if (target_use_signed_kernel ())
56925739 {
@@ -5737,7 +5784,7 @@ void aboot_init(const struct app_descriptor *app)
57375784 }
57385785 else
57395786 {
5740- if (!IS_ENABLED (ABOOT_STANDALONE ))
5787+ if (!IS_ENABLED (ABOOT_STANDALONE )) // TODO: detect_android_from_flash()
57415788 recovery_init ();
57425789 #if USE_PCOM_SECBOOT
57435790 if ((device .is_unlocked ) || (device .is_tampered ))
0 commit comments