summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/gadget/bootctrl.c25
-rw-r--r--drivers/usb/gadget/f_fastboot.c21
-rw-r--r--drivers/usb/gadget/fastboot_lock_unlock.c21
-rw-r--r--drivers/usb/gadget/fastboot_lock_unlock.h3
4 files changed, 57 insertions, 13 deletions
diff --git a/drivers/usb/gadget/bootctrl.c b/drivers/usb/gadget/bootctrl.c
index d4b89d2..5528179 100644
--- a/drivers/usb/gadget/bootctrl.c
+++ b/drivers/usb/gadget/bootctrl.c
@@ -300,13 +300,7 @@ void get_slotvar(char *cmd, char *response, size_t chars_left)
struct boot_ctl t_bootctl;
memset(&t_bootctl, 0, sizeof(t_bootctl));
- ret = read_bootctl(&t_bootctl);
- if (ret) {
- error("get_slotvar, read_bootctl failed\n");
- strcpy(response, "get_slotvar read_bootctl failed");
- return;
- }
-
+ /* these two var no need to read_bootctl */
if (!strcmp_l1("has-slot:", cmd)) {
char *ptnname = NULL;
ptnname = strchr(cmd, ':') + 1;
@@ -314,14 +308,25 @@ void get_slotvar(char *cmd, char *response, size_t chars_left)
strncat(response, "yes", chars_left);
else
strncat(response, "no", chars_left);
- } else if (!strcmp_l1("current-slot", cmd)) {
+ return;
+ } else if (!strcmp_l1("slot-suffixes", cmd)) {
+ strncat(response, "_a,_b", chars_left);
+ return;
+ }
+
+ ret = read_bootctl(&t_bootctl);
+ if (ret) {
+ error("get_slotvar, read_bootctl failed\n");
+ strcpy(response, "get_slotvar read_bootctl failed");
+ return;
+ }
+
+ if (!strcmp_l1("current-slot", cmd)) {
unsigned int slot = slot_find(&t_bootctl);
if (slot < SLOT_NUM)
strncat(response, g_slot_suffix[slot], chars_left);
else
strncat(response, "no valid slot", chars_left);
- } else if (!strcmp_l1("slot-suffixes", cmd)) {
- strncat(response, "_a,_b", chars_left);
} else if (!strcmp_l1("slot-successful:", cmd)) {
char *suffix = strchr(cmd, ':') + 1;
unsigned int slot = slotidx_from_suffix(suffix);
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 8e7425a..d986f82 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -979,6 +979,13 @@ static void process_flash_mmc(const char *cmdbuf, char *response)
printf("Writing '%s' DONE!\n", ptn->name);
sprintf(response, "OKAY");
}
+
+ if (strncmp(ptn->name, "gpt", 3) == 0) {
+ /* will force scan the device,
+ so dev_desc can be re-inited
+ with the latest data */
+ run_command(mmc_dev, 0);
+ }
}
}
} else {
@@ -2654,6 +2661,7 @@ static void cb_flashing(struct usb_ep *ep, struct usb_request *req)
#endif
+
#ifdef CONFIG_FASTBOOT_FLASH
static void cb_flash(struct usb_ep *ep, struct usb_request *req)
{
@@ -2689,7 +2697,20 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
strcpy(response, "FAILno flash device defined");
#ifdef CONFIG_FSL_FASTBOOT
+ int gpt_valid_pre = 0;
+ int gpt_valid_pst = 0;
+
+ if (strncmp(cmd, "gpt", 3) == 0)
+ gpt_valid_pre = partition_table_valid();
+
rx_process_flash(cmd, response);
+
+ /* If gpt invalid -> valid, write unlock status, also wipe data. */
+ if (strncmp(cmd, "gpt", 3) == 0) {
+ gpt_valid_pst = partition_table_valid();
+ if ((gpt_valid_pre == 0) && (gpt_valid_pst == 1))
+ do_fastboot_unlock();
+ }
#else
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR,
diff --git a/drivers/usb/gadget/fastboot_lock_unlock.c b/drivers/usb/gadget/fastboot_lock_unlock.c
index 89327fd..65184d9 100644
--- a/drivers/usb/gadget/fastboot_lock_unlock.c
+++ b/drivers/usb/gadget/fastboot_lock_unlock.c
@@ -193,6 +193,7 @@ inline unsigned char lock_enable_parse(unsigned char* bdata) {
return *(bdata + SECTOR_SIZE -1);
}
+static unsigned char g_lockstat = FASTBOOT_UNLOCK;
/*
* Set status of the lock&unlock to FSL_FASTBOOT_FB_PART
* Currently use the very first Byte of FSL_FASTBOOT_FB_PART
@@ -212,7 +213,8 @@ int fastboot_set_lock_stat(unsigned char lock) {
&fs_dev_desc, &fs_partition, 1);
if (status < 0) {
printf("%s:error in getdevice partition.\n", __FUNCTION__);
- return -1;
+ g_lockstat = lock;
+ return 0;
}
DEBUG("%s %s partition.start=%d, size=%d\n",FSL_FASTBOOT_FB_DEV,
get_mmc_part(FSL_FASTBOOT_FB_PART_NUM), fs_partition.start, fs_partition.size);
@@ -247,7 +249,7 @@ unsigned char fastboot_get_lock_stat(void)
if (status < 0) {
printf("%s:error in getdevice partition.\n", __FUNCTION__);
- return FASTBOOT_LOCK_ERROR;
+ return g_lockstat;
}
DEBUG("%s %s partition.start=%d, size=%d\n",FSL_FASTBOOT_FB_DEV,
get_mmc_part(FSL_FASTBOOT_FB_PART_NUM), fs_partition.start, fs_partition.size);
@@ -352,7 +354,7 @@ int fastboot_wipe_data_partition(void)
get_mmc_part(FSL_FASTBOOT_DATA_PART_NUM), &fs_dev_desc, &fs_partition, 1);
if (status < 0) {
printf("error in get device partition for wipe /data\n");
- return -1;
+ return 0;
}
DEBUG("fs->start=%x, size=%d\n", fs_partition.start, fs_partition.size);
status = fs_dev_desc->block_erase(fs_dev_desc->dev, fs_partition.start , fs_partition.size );
@@ -364,3 +366,16 @@ int fastboot_wipe_data_partition(void)
return 0;
}
+
+int partition_table_valid(void)
+{
+ int status;
+ block_dev_desc_t *fs_dev_desc;
+ disk_partition_t fs_partition;
+
+ status = get_device_and_partition(FSL_FASTBOOT_FB_DEV,
+ get_mmc_part(FSL_FASTBOOT_FB_PART_NUM),
+ &fs_dev_desc, &fs_partition, 1);
+
+ return (status < 0) ? 0 : 1;
+}
diff --git a/drivers/usb/gadget/fastboot_lock_unlock.h b/drivers/usb/gadget/fastboot_lock_unlock.h
index c4325f1..a75b440 100644
--- a/drivers/usb/gadget/fastboot_lock_unlock.h
+++ b/drivers/usb/gadget/fastboot_lock_unlock.h
@@ -64,4 +64,7 @@ int fastboot_wipe_data_partition(void);
unsigned char fastboot_lock_enable(void);
int display_lock(int lock, int verify);
+
+int partition_table_valid(void);
+
#endif