Skip to content

Commit 0a65f8b

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 2e7441c commit 0a65f8b

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

app/aboot/aboot.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,56 @@ 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+
const 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+
bool partition_found = false;
1587+
boot_img_hdr *hdr = (void*) buf;
1588+
static bool detected = false, result = false;
1589+
1590+
if (detected)
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+
partition_found = true;
1601+
break;
1602+
}
1603+
dprintf(CRITICAL, "ERROR: No %s partition found\n", ptn_names[i]);
1604+
}
1605+
1606+
if (!partition_found) {
1607+
detected = true;
1608+
return result;
1609+
}
1610+
1611+
/* Set Lun for boot & recovery partitions */
1612+
mmc_set_lun(partition_get_lun(index));
1613+
1614+
if (mmc_read(ptn, (uint32_t *) buf, page_size)) {
1615+
dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
1616+
detected = true;
1617+
return result;
1618+
}
1619+
1620+
if (strstr((const char *)hdr->cmdline, "androidboot.")) {
1621+
dprintf(INFO, "Detected Android boot parameter\n");
1622+
result = true;
1623+
}
1624+
1625+
detected = true;
1626+
return result;
1627+
}
1628+
15791629
int boot_linux_from_mmc(void)
15801630
{
15811631
boot_img_hdr *hdr = (void*) buf;
@@ -1627,7 +1677,7 @@ int boot_linux_from_mmc(void)
16271677
int current_active_slot = INVALID;
16281678
bool try_alternate_partition = false;
16291679

1630-
if (!IS_ENABLED(ABOOT_STANDALONE) && check_format_bit())
1680+
if (detect_android_from_mmc() && check_format_bit())
16311681
boot_into_recovery = 1;
16321682

16331683
if (!IS_ENABLED(ABOOT_STANDALONE) && !boot_into_recovery) {
@@ -5673,7 +5723,7 @@ void aboot_init(const struct app_descriptor *app)
56735723

56745724
if (target_is_emmc_boot())
56755725
{
5676-
if(!IS_ENABLED(ABOOT_STANDALONE) && emmc_recovery_init())
5726+
if(detect_android_from_mmc() && emmc_recovery_init())
56775727
dprintf(ALWAYS,"error in emmc_recovery_init\n");
56785728
if(target_use_signed_kernel())
56795729
{

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 */
@@ -460,6 +461,7 @@ int _emmc_recovery_init(void)
460461
emmc_set_recovery_msg(msg); // send recovery message
461462

462463
out:
464+
#endif
463465
if(msg)
464466
free(msg);
465467
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)