summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShohei Sakamoto <sakamotos@casio.co.jp>2016-01-14 14:51:06 +0900
committerShohei Sakamoto <sakamotos@casio.co.jp>2016-01-14 21:04:18 +0900
commite30cbbc481a30dc741765ef296f4b36704836549 (patch)
tree91b56829e9d20a1e101c7a9ddcd184e55526fa53
parentc4d26d10b391ec6ba9ff1ec65cef8ade7788bcd0 (diff)
downloadkoi-uboot-e30cbbc481a30dc741765ef296f4b36704836549.tar.gz
Fix lock/unlock command
Fixed that partition was erased even when bootloader is locked. Changed command name from 'oem' to 'flashing'. Modified string for prompt. Bug:26523025 Change-Id: I519a746ffb6e619ae77eb7ce8f4d26d972a4ae25 Signed-off-by: Shohei Sakamoto <sakamotos@casio.co.jp>
-rw-r--r--board/samsung/koi/koi.c7
-rw-r--r--common/cmd_fastboot.c158
-rw-r--r--common/cmd_nvedit.c12
-rw-r--r--common/env_mmc.c19
-rw-r--r--include/common.h2
5 files changed, 103 insertions, 95 deletions
diff --git a/board/samsung/koi/koi.c b/board/samsung/koi/koi.c
index c1a1c0aab..5290e9fea 100644
--- a/board/samsung/koi/koi.c
+++ b/board/samsung/koi/koi.c
@@ -669,6 +669,13 @@ int board_late_init(void)
char *reason;
int mode;
int ret;
+ char *bootdelay;
+
+ bootdelay = getenv("bootdelay");
+ if (!(bootdelay && *bootdelay == '0')) {
+ setenv("bootdelay", "0");
+ saveenv_one_variable("bootdelay", "0");
+ }
rst_stat = readl(&pmu->rst_stat);
printf("rst_stat : 0x%x\n", rst_stat);
diff --git a/common/cmd_fastboot.c b/common/cmd_fastboot.c
index d7dc19756..70b38043b 100644
--- a/common/cmd_fastboot.c
+++ b/common/cmd_fastboot.c
@@ -80,6 +80,7 @@
#endif
#include <decompress_ext4.h>
#include <version.h>
+#include <malloc.h>
#if defined(CONFIG_S5P6450)
DECLARE_GLOBAL_DATA_PTR;
@@ -97,10 +98,6 @@ DECLARE_GLOBAL_DATA_PTR;
#define OmPin readl(EXYNOS5_POWER_BASE + INFORM3_OFFSET)
#endif
-#ifdef CONFIG_LOCKING
-#define FASTBOOT_UNLOCKED_ENV_NAME "fastboot_locked"
-#endif
-
#define BASEBAND_VERSION "N/A"
#if defined(CONFIG_FASTBOOT)
@@ -539,7 +536,7 @@ static int write_to_ptn_sdmmc(struct fastboot_ptentry *ptn, unsigned int addr, u
if (ptn->flags & FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD)
{
- if (check_compress_ext4((char*)addr,ptn->length) != 0) {
+ if (addr && check_compress_ext4((char*)addr,ptn->length) != 0) {
argv[2] = device;
argv[3] = buffer;
argv[4] = start;
@@ -620,6 +617,9 @@ static int write_to_ptn_sdmmc(struct fastboot_ptentry *ptn, unsigned int addr, u
{
printf("*** erase block length too small ***\n");
}
+ if (addr == 0)
+ return 0;
+
ret = write_compressed_ext4((char*)addr,
ptn->start / CFG_FASTBOOT_SDMMC_BLOCKSIZE);
}
@@ -757,6 +757,28 @@ static void start_ramdump(void *buf)
}
#endif
+static int get_lock_state(void)
+{
+ char *fastboot_locked_env;
+ unsigned long lock = 0;
+
+ fastboot_locked_env = getenv("fastboot_locked");
+
+ if (fastboot_locked_env)
+ lock = simple_strtoul(fastboot_locked_env, NULL, 10);
+
+ return lock;
+}
+
+static void put_lock_state(int lock)
+{
+ char *str[] = { "0", "1" };
+
+ setenv("fastboot_locked", str[lock]);
+ saveenv_one_variable("fastboot_locked", str[lock]);
+}
+
+
static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
{
struct exynos4_power *pmu = (struct exynos4_power *)EXYNOS4_POWER_BASE;
@@ -766,8 +788,6 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
strcpy's need the extra byte */
char response[256] __attribute__ ((aligned(8)));
char response_tmp[256] __attribute__ ((aligned(8)));
- char *fastboot_unlocked_env;
- unsigned long lock =0;
int is_all = 0;
if (download_size)
@@ -965,14 +985,7 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
#ifdef CONFIG_LOCKING
if (is_all || !strcmp(cmdbuf + 7, "secure"))
{
- fastboot_unlocked_env = getenv(FASTBOOT_UNLOCKED_ENV_NAME);
-
- if (fastboot_unlocked_env)
- lock = simple_strtoul(fastboot_unlocked_env, NULL, 10);
- else
- lock = 0;
-
- if (lock) {
+ if (get_lock_state()) {
if (is_all)
sprintf(response,"INFOsecure: yes");
else
@@ -988,14 +1001,7 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
}
if (is_all || !strcmp(cmdbuf + 7, "unlocked"))
{
- fastboot_unlocked_env = getenv(FASTBOOT_UNLOCKED_ENV_NAME);
-
- if (fastboot_unlocked_env)
- lock = simple_strtoul(fastboot_unlocked_env, NULL, 10);
- else
- lock = 0;
-
- if (!lock) {
+ if (!get_lock_state()) {
if (is_all)
sprintf(response,"INFOunlocked: yes");
else
@@ -1393,6 +1399,7 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
}
#endif
} else if(OmPin == BOOT_EMMC_4_4 || OmPin == BOOT_EMMC) {
+ #if 0
char run_cmd[80];
status = 1;
if (!strcmp(ptn->name, "system")) {
@@ -1420,6 +1427,9 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
status = run_command(run_cmd, 0);
#endif
}
+ #else
+ status = get_lock_state();
+ #endif
}
//#else
else if(OmPin == BOOT_ONENAND) {
@@ -1488,7 +1498,7 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
ret = 0;
goto send_tx_status;
}
-
+#if 0
/* boot
boot what was downloaded
@@ -1593,20 +1603,13 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
sprintf(response, "FAILinvalid boot image");
ret = 0;
}
-
+#endif
/* flash
Flash what was downloaded */
if (memcmp(cmdbuf, "flash:", 6) == 0)
{
#ifdef CONFIG_LOCKING
- fastboot_unlocked_env = getenv(FASTBOOT_UNLOCKED_ENV_NAME);
-
- if (fastboot_unlocked_env)
- lock = simple_strtoul(fastboot_unlocked_env, NULL, 10);
- else
- lock = 0;
-
- if(!lock)
+ if(!get_lock_state())
{
#endif
if (download_bytes == 0)
@@ -1732,91 +1735,56 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)
/* oem
oem command. */
#ifdef CONFIG_LOCKING
- if (memcmp(cmdbuf, "oem ", 4) == 0) {
+ if (memcmp(cmdbuf, "flashing ", 9) == 0) {
static int unlock_accept = 0;
- if (memcmp(cmdbuf + 4, "unlock", 6) == 0)
+ if (memcmp(cmdbuf + 9, "unlock", 6) == 0)
{
+ if (unlock_accept) {
+ sprintf(response, "INFOErasing userdata and unlocking the device");
+ fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
- fastboot_unlocked_env = getenv(FASTBOOT_UNLOCKED_ENV_NAME);
- if (fastboot_unlocked_env)
- lock = simple_strtoul(fastboot_unlocked_env, NULL, 10);
- else
- lock = 0;
-
- if (strcmp(cmdbuf + 10, " accept") == 0) {
+ // run_command("ext4format mmc 0:3;ext4format mmc 0:4;", 0);
+ write_to_ptn_sdmmc(fastboot_flash_find_ptn("userdata"), 0, 0);
+ write_to_ptn_sdmmc(fastboot_flash_find_ptn("cache"), 0, 0);
- if (!lock)
- sprintf(response, "FAIL Already unlocked");
- else if (!unlock_accept)
- sprintf(response, "FAIL Unlock command is not given");
- else if (unlock_accept && lock) {
+ put_lock_state(0);
+ sprintf(response, "INFORun \"fastboot -w\" to make valid filesystem.");
+ fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
- sprintf(response, "INFO Doing factory reset and unlocking the device");
+ unlock_accept = 0;
+ sprintf(response, "OKAY");
+ } else {
+ if (!get_lock_state()) {
+ sprintf(response, "FAILDevice is already unlocked");
+ } else {
+ sprintf(response, "INFOUnlock requested.");
fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
-
- run_command("ext4format mmc 0:3;ext4format mmc 0:4;", 0);
-
- setenv(FASTBOOT_UNLOCKED_ENV_NAME, "0");
- saveenv_one_variable(FASTBOOT_UNLOCKED_ENV_NAME, "0");
-
- unlock_accept = 0;
- sprintf(response, "OKAY");
- }
- }
- else {
-
- if (!lock)
- sprintf(response, "FAIL Device is already unlocked");
- else {
-
- sprintf(response, "INFO Unlock requested, enter oem unlock accept\n");
+ sprintf(response, "INFODevice may encounter problem with unofficial images.");
+ fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
+ sprintf(response, "INFOTo confirm, run \"fastboot flashing unlock\" again.");
fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
- printf("Device may encounter problem with unofficial images\n");
- printf("If sure to continue, enter oem unlock accept command\n");
unlock_accept = 1;
sprintf(response, "OKAY");
}
}
}
- else if (strcmp(cmdbuf + 4, "lock") == 0) {
-
- fastboot_unlocked_env = getenv(FASTBOOT_UNLOCKED_ENV_NAME);
- if (fastboot_unlocked_env)
- lock = simple_strtoul(fastboot_unlocked_env, NULL, 10);
- else
- lock = 0;
-
- if (lock)
- sprintf(response, "FAIL Device is already locked");
+ else if (strcmp(cmdbuf + 9, "lock") == 0) {
+ if (get_lock_state())
+ sprintf(response, "FAILDevice is already locked");
else {
- setenv(FASTBOOT_UNLOCKED_ENV_NAME, "1");
- saveenv_one_variable(FASTBOOT_UNLOCKED_ENV_NAME, "1");
+ put_lock_state(1);
- sprintf(response, "INFO Locking the device, can't flash images");
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
+ sprintf(response, "INFODevice has been locked");
+ fastboot_tx_status(response, strlen(response), FASTBOOT_TX_SYNC);
sprintf(response, "OKAY");
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
-
- return 0;
}
}
ret = 0;
goto send_tx_status;
}
-#else
- if (memcmp(cmdbuf, "oem", 3) == 0)
- {
- sprintf(response,"INFOunknown OEM command");
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
-
- sprintf(response,"OKAY");
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
-
- return 0;
- }
#endif
#if defined(CONFIG_RAMDUMP_MODE)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index dddc7cc68..1b7f8adef 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -593,6 +593,18 @@ U_BOOT_CMD(
);
#endif
+int do_env_erase(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ printf("Erasing Environment to %s...\n", env_name_spec);
+
+ return eraseenv() ? 1 : 0;
+}
+
+U_BOOT_CMD(
+ eraseenv, 1, 0, do_env_erase,
+ "erase environment variables",
+ ""
+);
/*
* Match a name / name=value pair
diff --git a/common/env_mmc.c b/common/env_mmc.c
index a183e9368..3227a31d9 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -123,6 +123,25 @@ int saveenv(void)
}
#endif /* CONFIG_CMD_SAVEENV */
+int eraseenv(void)
+{
+ struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
+ u32 offset;
+
+ if (init_mmc_for_env(mmc) || mmc_get_env_addr(mmc, &offset))
+ return 1;
+
+ memset((void *)0x48000000, 0xff, CONFIG_ENV_SIZE);
+
+ if (write_env(mmc, CONFIG_ENV_SIZE, offset, (u_char *)0x48000000)) {
+ puts("failed\n");
+ return 1;
+ }
+
+ puts("done\n");
+ return 0;
+}
+
static inline int read_env(struct mmc *mmc, unsigned long size,
unsigned long offset, const void *buffer)
{
diff --git a/include/common.h b/include/common.h
index 83f2ec982..0a2d86f84 100644
--- a/include/common.h
+++ b/include/common.h
@@ -339,6 +339,8 @@ char *getenv (const char *);
int getenv_f (const char *name, char *buf, unsigned len);
ulong getenv_ulong(const char *name, int base, ulong default_val);
int saveenv (void);
+int saveenv_one_variable(const char *env_name, const char *env_data);
+int eraseenv(void);
#ifdef CONFIG_PPC /* ARM version to be fixed! */
int inline setenv (const char *, const char *);
#else