Skip to content

Commit 09e52b6

Browse files
committed
aboot: Enable recovery features if the OS is Android
Android could run on mainline kernel...
1 parent 6321fc3 commit 09e52b6

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

app/aboot/aboot.c

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
15791626
int 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))

app/aboot/recovery.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ int send_recovery_cmd(const char *command)
396396

397397
int _emmc_recovery_init(void)
398398
{
399-
int update_status = 0;
399+
int update_status __attribute__((unused)) = 0;
400400
struct recovery_message *msg;
401401
uint32_t block_size = 0;
402402

@@ -428,6 +428,7 @@ int _emmc_recovery_init(void)
428428
boot_into_recovery = 1;
429429
}
430430

431+
#if !ABOOT_STANDALONE
431432
if (!strcmp("update-radio",msg->command))
432433
{
433434
/* We're now here due to radio update, so check for update status */
@@ -453,6 +454,7 @@ int _emmc_recovery_init(void)
453454
{
454455
set_device_root();
455456
}
457+
#endif
456458
else
457459
goto out;// do nothing
458460

app/aboot/rules.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ OBJS += \
1313

1414
ifeq ($(ABOOT_STANDALONE), 1)
1515
DEFINES += ABOOT_STANDALONE=1
16-
OBJS := $(filter-out $(LOCAL_DIR)/recovery.o, $(OBJS))
1716
DEFINES := $(filter-out SSD_ENABLE TZ_SAVE_KERNEL_HASH TZ_TAMPER_FUSE, $(DEFINES))
1817
endif
1918

0 commit comments

Comments
 (0)