@@ -1576,6 +1576,50 @@ 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+ goto out ;
1602+ }
1603+ }
1604+
1605+ /* Set Lun for boot & recovery partitions */
1606+ mmc_set_lun (partition_get_lun (index ));
1607+
1608+ if (mmc_read (ptn + offset , (uint32_t * ) buf , page_size )) {
1609+ dprintf (CRITICAL , "ERROR: Cannot read boot image header\n" );
1610+ goto out ;
1611+ }
1612+
1613+ if (strstr ((const char * )hdr -> cmdline , "androidboot." )) {
1614+ dprintf (INFO , "Detected Android boot parameter\n" );
1615+ result = true;
1616+ }
1617+
1618+ out :
1619+ finish = true;
1620+ return result ;
1621+ }
1622+
15791623int boot_linux_from_mmc (void )
15801624{
15811625 boot_img_hdr * hdr = (void * ) buf ;
@@ -1627,7 +1671,7 @@ int boot_linux_from_mmc(void)
16271671 int current_active_slot = INVALID ;
16281672 bool try_alternate_partition = false;
16291673
1630- if (! IS_ENABLED ( ABOOT_STANDALONE ) && check_format_bit ())
1674+ if (detect_android_from_mmc ( ) && check_format_bit ())
16311675 boot_into_recovery = 1 ;
16321676
16331677 if (!IS_ENABLED (ABOOT_STANDALONE ) && !boot_into_recovery ) {
@@ -5686,7 +5730,7 @@ void aboot_init(const struct app_descriptor *app)
56865730
56875731 if (target_is_emmc_boot ())
56885732 {
5689- if (! IS_ENABLED ( ABOOT_STANDALONE ) && emmc_recovery_init ())
5733+ if (detect_android_from_mmc ( ) && emmc_recovery_init ())
56905734 dprintf (ALWAYS ,"error in emmc_recovery_init\n" );
56915735 if (target_use_signed_kernel ())
56925736 {
@@ -5737,7 +5781,7 @@ void aboot_init(const struct app_descriptor *app)
57375781 }
57385782 else
57395783 {
5740- if (!IS_ENABLED (ABOOT_STANDALONE ))
5784+ if (!IS_ENABLED (ABOOT_STANDALONE )) // TODO: detect_android_from_flash()
57415785 recovery_init ();
57425786 #if USE_PCOM_SECBOOT
57435787 if ((device .is_unlocked ) || (device .is_tampered ))
0 commit comments