summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorWinter Wang <wente.wang@nxp.com>2016-11-18 18:11:32 +0800
committerWinter Wang <wente.wang@nxp.com>2016-11-21 13:46:28 +0800
commit3197bfd7b43e6eda70116f6439cb0f1e346cf2d1 (patch)
treee41a5e4213dc78b1f2d7a2e0e0797579cc1793e4 /drivers
parent64cb24c2497a9ba28e41979e0c3d5deb387767f9 (diff)
downloadu-boot-imx-3197bfd7b43e6eda70116f6439cb0f1e346cf2d1.zip
u-boot-imx-3197bfd7b43e6eda70116f6439cb0f1e346cf2d1.tar.gz
u-boot-imx-3197bfd7b43e6eda70116f6439cb0f1e346cf2d1.tar.bz2
MA-9030 fastboot: getvar return FAIL if var not defined
modify get_slotvar in bootctl, buffer contains error string if fails; add FAIL to cb_getvar's response buffer if the input var is not defined. Change-Id: I91d60a434b654030457f1e6e7f3d067bfb179297 Signed-off-by: Winter Wang <wente.wang@nxp.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/bootctrl.c52
-rw-r--r--drivers/usb/gadget/bootctrl.h2
-rw-r--r--drivers/usb/gadget/f_fastboot.c96
3 files changed, 82 insertions, 68 deletions
diff --git a/drivers/usb/gadget/bootctrl.c b/drivers/usb/gadget/bootctrl.c
index 6f19418..9bc9db6 100644
--- a/drivers/usb/gadget/bootctrl.c
+++ b/drivers/usb/gadget/bootctrl.c
@@ -296,7 +296,7 @@ bool is_sotvar(char *cmd)
return false;
}
-void get_slotvar(char *cmd, char *response, size_t chars_left)
+int get_slotvar(char *cmd, char *buffer, size_t size)
{
int ret;
struct boot_ctl t_bootctl;
@@ -307,59 +307,69 @@ void get_slotvar(char *cmd, char *response, size_t chars_left)
char *ptnname = NULL;
ptnname = strchr(cmd, ':') + 1;
if (!strcmp(ptnname, "system") || !strcmp(ptnname, "boot"))
- strncat(response, "yes", chars_left);
+ strlcpy(buffer, "yes", size);
else
- strncat(response, "no", chars_left);
- return;
+ strlcpy(buffer, "no", size);
+ return 0;
} else if (!strcmp_l1("slot-suffixes", cmd)) {
- strncat(response, "_a,_b", chars_left);
- return;
+ strlcpy(buffer, "_a,_b", size);
+ return 0;
}
ret = read_bootctl(&t_bootctl);
if (ret) {
error("get_slotvar, read_bootctl failed\n");
- strcpy(response, "get_slotvar read_bootctl failed");
- return;
+ strlcpy(buffer, "get_slotvar read_bootctl failed", size);
+ return -1;
}
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);
+ strlcpy(buffer, g_slot_suffix[slot], size);
+ else {
+ strlcpy(buffer, "no valid slot", size);
+ return -1;
+ }
} else if (!strcmp_l1("slot-successful:", cmd)) {
char *suffix = strchr(cmd, ':') + 1;
unsigned int slot = slotidx_from_suffix(suffix);
if (slot >= SLOT_NUM) {
- strncat(response, "no such slot", chars_left);
+ strlcpy(buffer, "no such slot", size);
+ return -1;
} else {
bool suc = t_bootctl.a_slot_meta[slot].bootsuc;
- strncat(response, suc ? "yes" : "no", chars_left);
+ strlcpy(buffer, suc ? "yes" : "no", size);
}
} else if (!strcmp_l1("slot-unbootable:", cmd)) {
char *suffix = strchr(cmd, ':') + 1;
unsigned int slot = slotidx_from_suffix(suffix);
if (slot >= SLOT_NUM) {
- strncat(response, "no such slot", chars_left);
+ strlcpy(buffer, "no such slot", size);
+ return -1;
} else {
unsigned int pri = t_bootctl.a_slot_meta[slot].priority;
- strncat(response, pri ? "no" : "yes", chars_left);
+ strlcpy(buffer, pri ? "no" : "yes", size);
}
} else if (!strcmp_l1("slot-retry-count:", cmd)) {
char *suffix = strchr(cmd, ':') + 1;
unsigned int slot = slotidx_from_suffix(suffix);
- if (slot >= SLOT_NUM)
- strncat(response, "no such slot", chars_left);
- else
- sprintf(response, "OKAY%d",
+ if (slot >= SLOT_NUM) {
+ strlcpy(buffer, "no such slot", size);
+ return -1;
+ }
+ else {
+ char str_num[7];
+ sprintf(str_num, "%d",
t_bootctl.a_slot_meta[slot].tryremain);
+ strlcpy(buffer, str_num, size);
+ }
} else {
- strncat(response, "no such slot command", chars_left);
+ strlcpy(buffer, "no such slot command", size);
+ return -1;
}
- return;
+ return 0;
}
diff --git a/drivers/usb/gadget/bootctrl.h b/drivers/usb/gadget/bootctrl.h
index 9ec0bcd..b42aeb1 100644
--- a/drivers/usb/gadget/bootctrl.h
+++ b/drivers/usb/gadget/bootctrl.h
@@ -32,7 +32,7 @@ struct boot_ctl {
char *select_slot(void);
int invalid_curslot(void);
bool is_sotvar(char *cmd);
-void get_slotvar(char *cmd, char *response, size_t chars_left);
+int get_slotvar(char *cmd, char *buffer, size_t size);
void cb_set_active(struct usb_ep *ep, struct usb_request *req);
const char *get_slot_suffix(void);
#endif
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 0a685d2..586e38a 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -2615,66 +2615,49 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
return;
}
-#ifdef CONFIG_AVB_SUPPORT
- if (is_slotvar_avb(cmd)) {
- get_slotvar_avb(&fsl_avb_ops, cmd, response, chars_left);
- fastboot_tx_write_str(response);
- return;
- }
-#elif CONFIG_FSL_BOOTCTL
- if (is_sotvar(cmd)) {
- get_slotvar(cmd, response, chars_left);
- fastboot_tx_write_str(response);
- return;
- }
-#endif
- char *str;
- str = strstr(cmd, "partition-size:");
- if (str) {
- str+=strlen("partition-size:");
+ char *str = cmd;
+ if (!strcmp_l1("partition-size:", cmd)) {
+ str += strlen("partition-size:");
struct fastboot_ptentry* fb_part;
fb_part = fastboot_flash_find_ptn(str);
- if (!fb_part)
- strcpy(response, "FAILWrong partition name.");
+ if (!fb_part) {
+ strncat(response, "Wrong partition name.", chars_left);
+ goto fail;
+ }
else {
- char var[32] = {0};
- sprintf(var, "OKAY0x%016x", fb_part->length * get_block_size());
- strcpy(response, var);
+ char str_num[20];
+
+ sprintf(str_num, "0x%016x", fb_part->length * get_block_size());
+ strncat(response, str_num, chars_left);
}
- } else if (strstr(cmd, "partition-type:")) {
- str = strstr(cmd, "partition-type:");
- str+=strlen("partition-type:");
+ } else if (!strcmp_l1("partition-type:", cmd)) {
+ str += strlen("partition-type:");
struct fastboot_ptentry* fb_part;
fb_part = fastboot_flash_find_ptn(str);
- if (!fb_part)
- strcpy(response, "FAILWrong partition name.");
+ if (!fb_part) {
+ strncat(response, "Wrong partition name.", chars_left);
+ goto fail;
+ }
else {
- char var[32] = {0};
- sprintf(var, "OKAY%s", fb_part->fstype);
- strcpy(response, var);
+ strncat(response, fb_part->fstype, chars_left);
}
} else if (!strcmp_l1("all", cmd)) {
- strcpy(response, "OKAY");
+ /* FIXME need to return all vars here */
} else if (!strcmp_l1("version-baseband", cmd)) {
- strcpy(response, "OKAYN/A");
- } else if (!strcmp_l1("version-bootloader", cmd)) {
- char var[512] = {0};
- sprintf(var, "OKAY%s", U_BOOT_VERSION);
- strcpy(response, var);
+ strncat(response, "N/A", chars_left);
+ } else if (!strcmp_l1("version-bootloader", cmd) ||
+ !strcmp_l1("bootloader-version", cmd)) {
+ strncat(response, U_BOOT_VERSION, chars_left);
} else if (!strcmp_l1("version", cmd)) {
strncat(response, FASTBOOT_VERSION, chars_left);
} else if (!strcmp_l1("battery-voltage", cmd)) {
- strcpy(response, "OKAY0mV");
+ strncat(response, "0mV", chars_left);
} else if (!strcmp_l1("battery-soc-ok", cmd)) {
- strcpy(response, "OKAYyes");
+ strncat(response, "yes", chars_left);
} else if (!strcmp_l1("variant", cmd)) {
- strcpy(response, "OKAY");
+ /* just OKAY here */
} else if (!strcmp_l1("off-mode-charge", cmd)) {
- strcpy(response, "OKAY1");
- } else if (!strcmp_l1("bootloader-version", cmd)) {
- char var[512] = {0};
- sprintf(var, "OKAY%s", U_BOOT_VERSION);
- strcpy(response, var);
+ strncat(response, "1", chars_left);
} else if (!strcmp_l1("downloadsize", cmd) ||
!strcmp_l1("max-download-size", cmd)) {
char str_num[12];
@@ -2685,8 +2668,10 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
s = get_serial();
if (s)
strncat(response, s, chars_left);
- else
- strcpy(response, "FAILValue not set");
+ else {
+ strncat(response, "Value not set", chars_left);
+ goto fail;
+ }
} else if (!strcmp_l1("product", cmd)) {
strncat(response, PRODUCT_NAME, chars_left);
}
@@ -2701,10 +2686,29 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
}
}
#endif
+#ifdef CONFIG_AVB_SUPPORT
+ else if (is_slotvar_avb(cmd)) {
+ if (get_slotvar_avb(&fsl_avb_ops, cmd,
+ response + strlen(response), chars_left + 1) < 0)
+ goto fail;
+ }
+#elif CONFIG_FSL_BOOTCTL
+ else if (is_sotvar(cmd)) {
+ if (get_slotvar(cmd, response + strlen(response), chars_left + 1) < 0)
+ goto fail;
+ }
+#endif
else {
+ strncat(response, "No such var", chars_left);
error("unknown variable: %s\n", cmd);
+ goto fail;
}
fastboot_tx_write_str(response);
+ return;
+fail:
+ strncpy(response, "FAIL", 4);
+ fastboot_tx_write_str(response);
+ return;
}
static unsigned int rx_bytes_expected(unsigned int maxpacket)