Skip to content

Commit b9725f6

Browse files
committed
aboot: Enable recovery features if the OS is Android
Android could run on mainline kernel... Fix up some logic and code style in `_emmc_recovery_init()` while at it.
1 parent 82dae92 commit b9725f6

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
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) {
@@ -5676,7 +5723,7 @@ void aboot_init(const struct app_descriptor *app)
56765723

56775724
if (target_is_emmc_boot())
56785725
{
5679-
if(!IS_ENABLED(ABOOT_STANDALONE) && emmc_recovery_init())
5726+
if(detect_android_from_mmc() && emmc_recovery_init())
56805727
dprintf(ALWAYS,"error in emmc_recovery_init\n");
56815728
if(target_use_signed_kernel())
56825729
{
@@ -5726,7 +5773,7 @@ void aboot_init(const struct app_descriptor *app)
57265773
}
57275774
else
57285775
{
5729-
if (!IS_ENABLED(ABOOT_STANDALONE))
5776+
if (!IS_ENABLED(ABOOT_STANDALONE)) // TODO: detect_android_from_flash()
57305777
recovery_init();
57315778
#if USE_PCOM_SECBOOT
57325779
if((device.is_unlocked) || (device.is_tampered))

app/aboot/recovery.c

Lines changed: 7 additions & 11 deletions
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,8 +428,8 @@ int _emmc_recovery_init(void)
428428
boot_into_recovery = 1;
429429
}
430430

431-
if (!strcmp("update-radio",msg->command))
432-
{
431+
#if !ABOOT_STANDALONE
432+
if (!strcmp("update-radio",msg->command)) {
433433
/* We're now here due to radio update, so check for update status */
434434
int ret = get_boot_info_apps(UPDATE_STATUS, (unsigned int *) &update_status);
435435

@@ -444,22 +444,18 @@ int _emmc_recovery_init(void)
444444
strlcpy(msg->status, "failed-update", sizeof(msg->status));
445445
}
446446
boot_into_recovery = 1; // Boot in recovery mode
447-
}
448-
if (!strcmp("reset-device-info",msg->command))
449-
{
447+
} else if (!strcmp("reset-device-info",msg->command)) {
450448
reset_device_info();
451-
}
452-
if (!strcmp("root-detect",msg->command))
453-
{
449+
} else if (!strcmp("root-detect",msg->command)) {
454450
set_device_root();
455-
}
456-
else
451+
} else
457452
goto out;// do nothing
458453

459454
strlcpy(msg->command, "", sizeof(msg->command)); // clearing recovery command
460455
emmc_set_recovery_msg(msg); // send recovery message
461456

462457
out:
458+
#endif
463459
if(msg)
464460
free(msg);
465461
return 0;

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)