Skip to content

Commit 7943d1c

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

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

app/aboot/aboot.c

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

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)