diff options
-rw-r--r-- | app/aboot/aboot.c | 99 | ||||
-rw-r--r-- | lib/debug/debug.c | 8 | ||||
-rw-r--r-- | project/msm8916.mk | 4 |
3 files changed, 106 insertions, 5 deletions
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c index a9c508c8..0f3b6b60 100644 --- a/app/aboot/aboot.c +++ b/app/aboot/aboot.c @@ -162,6 +162,7 @@ static bool devinfo_present = true; static int auth_kernel_img = 0; static device_info device = {DEVICE_MAGIC, 0, 0, 0, 0, 0}; +static bool is_allow_unlock = 0; struct atag_ptbl_entry { @@ -1577,6 +1578,77 @@ void write_device_info_flash(device_info *dev) } } +static int read_allow_oem_unlock(device_info *dev) +{ + const char *ptn_name = "frp"; + unsigned offset; + int index; + unsigned long long ptn; + unsigned long long ptn_size; + unsigned blocksize = mmc_get_device_blocksize(); + char buf[blocksize]; + + index = partition_get_index(ptn_name); + if (index == INVALID_PTN) + { + dprintf(CRITICAL, "No '%s' partition found\n", ptn_name); + return -1; + } + + ptn = partition_get_offset(index); + ptn_size = partition_get_size(index); + offset = ptn_size - blocksize; + + if (mmc_read(ptn + offset, buf, sizeof(buf))) + { + dprintf(CRITICAL, "Reading MMC failed\n"); + return -1; + } + + /*is_allow_unlock is a bool value stored at the LSB of last byte*/ + is_allow_unlock = buf[blocksize-1] & 0x01; + return 0; +} + +static int write_allow_oem_unlock(bool allow_unlock) +{ + const char *ptn_name = "frp"; + unsigned offset; + + int index; + unsigned long long ptn; + unsigned long long ptn_size; + unsigned blocksize = mmc_get_device_blocksize(); + char buf[blocksize]; + + index = partition_get_index(ptn_name); + if (index == INVALID_PTN) + { + dprintf(CRITICAL, "No '%s' partition found\n", ptn_name); + return -1; + } + + ptn = partition_get_offset(index); + ptn_size = partition_get_size(index); + offset = ptn_size - blocksize; + + if (mmc_read(ptn + offset, buf, sizeof(buf))) + { + dprintf(CRITICAL, "Reading MMC failed\n"); + return -1; + } + + /*is_allow_unlock is a bool value stored at the LSB of last byte*/ + buf[blocksize-1] = allow_unlock; + if (mmc_write(ptn + offset, blocksize, buf)) + { + dprintf(CRITICAL, "Writing MMC failed\n"); + return -1; + } + + return 0; +} + void read_device_info_flash(device_info *dev) { struct device_info *info = (void*) info_buf; @@ -2317,7 +2389,7 @@ void cmd_flash_mmc(const char *arg, void *data, unsigned sz) #endif /* SSD_ENABLE */ #if VERIFIED_BOOT - if(!device.is_unlocked && !device.is_verified) + if(!device.is_unlocked) { fastboot_fail("device is locked. Cannot flash images"); return; @@ -2453,12 +2525,33 @@ void cmd_oem_select_display_panel(const char *arg, void *data, unsigned size) void cmd_oem_unlock(const char *arg, void *data, unsigned sz) { - /* TODO: Wipe user data */ + if(!is_allow_unlock) { + fastboot_fail("oem unlock is not allowed"); + return; + } + dputs(CRITICAL,"oem unlock is been issued\n"); + fastboot_fail("Need wipe userdata. Do 'fastboot oem unlock-go'"); +} + +void cmd_oem_unlock_go(const char *arg, void *data, unsigned sz) +{ if(!device.is_unlocked || device.is_verified) { + if(!is_allow_unlock) { + fastboot_fail("oem unlock is not allowed"); + return; + } + device.is_unlocked = 1; device.is_verified = 0; write_device_info(&device); + + struct recovery_message msg; + snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); + write_misc(0, &msg, sizeof(msg)); + + fastboot_okay(""); + reboot_device(RECOVERY_MODE); } fastboot_okay(""); } @@ -2706,6 +2799,7 @@ void aboot_fastboot_register_commands(void) {"reboot", cmd_reboot}, {"reboot-bootloader", cmd_reboot_bootloader}, {"oem unlock", cmd_oem_unlock}, + {"oem unlock-go", cmd_oem_unlock_go}, {"oem lock", cmd_oem_lock}, {"oem verified", cmd_oem_verified}, {"oem device-info", cmd_oem_devinfo}, @@ -2770,6 +2864,7 @@ void aboot_init(const struct app_descriptor *app) ASSERT((MEMBASE + MEMSIZE) > MEMBASE); read_device_info(&device); + read_allow_oem_unlock(&device); /* Display splash screen if enabled */ #if DISPLAY_SPLASH_SCREEN diff --git a/lib/debug/debug.c b/lib/debug/debug.c index 84d0678b..c07a1535 100644 --- a/lib/debug/debug.c +++ b/lib/debug/debug.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2008 Travis Geiselbrecht * - * Copyright (c) 2014, The Linux Foundation. All rights reserved. + * Copyright (c) 2014,2015 The Linux Foundation. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files @@ -86,13 +86,17 @@ int _dprintf(const char *fmt, ...) snprintf(ts_buf, sizeof(ts_buf), "[%u] ", current_time()); dputs(ALWAYS, ts_buf); +#if ENABLE_FBCON_LOGGING + dputs(ALWAYS, ts_buf); +#endif va_list ap; va_start(ap, fmt); err = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); +#if ENABLE_FBCON_LOGGING dputs(ALWAYS, buf); - +#endif return err; } diff --git a/project/msm8916.mk b/project/msm8916.mk index 5f51f80c..f4d2124b 100644 --- a/project/msm8916.mk +++ b/project/msm8916.mk @@ -17,7 +17,9 @@ EMMC_BOOT := 1 #DEFINES += WITH_DEBUG_DCC=1 DEFINES += WITH_DEBUG_LOG_BUF=1 DEFINES += WITH_DEBUG_UART=1 -#DEFINES += WITH_DEBUG_FBCON=1 +DEFINES += WITH_DEBUG_FBCON=1 +DEFINES += WITH_DEV_FBCON=1 +#DEFINES += ENABLE_FBCON_LOGGING=0 DEFINES += DEVICE_TREE=1 #DEFINES += MMC_BOOT_BAM=1 DEFINES += CRYPTO_BAM=1 |