summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bcb.c88
-rw-r--r--cmd/dfu.c13
-rw-r--r--cmd/thordown.c19
-rw-r--r--cmd/usb_mass_storage.c4
4 files changed, 95 insertions, 29 deletions
diff --git a/cmd/bcb.c b/cmd/bcb.c
index e03218066b..6b6f1e9a2f 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -6,10 +6,12 @@
*/
#include <android_bootloader_message.h>
+#include <bcb.h>
#include <command.h>
#include <common.h>
#include <log.h>
#include <part.h>
+#include <malloc.h>
enum bcb_cmd {
BCB_CMD_LOAD,
@@ -110,8 +112,7 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep)
return 0;
}
-static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int __bcb_load(int devnum, const char *partp)
{
struct blk_desc *desc;
struct disk_partition info;
@@ -119,17 +120,19 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
char *endp;
int part, ret;
- ret = blk_get_device_by_str("mmc", argv[1], &desc);
- if (ret < 0)
+ desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum);
+ if (!desc) {
+ ret = -ENODEV;
goto err_read_fail;
+ }
- part = simple_strtoul(argv[2], &endp, 0);
+ part = simple_strtoul(partp, &endp, 0);
if (*endp == '\0') {
ret = part_get_info(desc, part, &info);
if (ret)
goto err_read_fail;
} else {
- part = part_get_info_by_name(desc, argv[2], &info);
+ part = part_get_info_by_name(desc, partp, &info);
if (part < 0) {
ret = part;
goto err_read_fail;
@@ -151,10 +154,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_SUCCESS;
err_read_fail:
- printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret);
+ printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret);
goto err;
err_too_small:
- printf("Error: mmc %s:%s too small!", argv[1], argv[2]);
+ printf("Error: mmc %d:%s too small!", devnum, partp);
goto err;
err:
bcb_dev = -1;
@@ -163,33 +166,58 @@ err:
return CMD_RET_FAILURE;
}
-static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ char *endp;
+ int devnum = simple_strtoul(argv[1], &endp, 0);
+
+ if (*endp != '\0') {
+ printf("Error: Device id '%s' not a number\n", argv[1]);
+ return CMD_RET_FAILURE;
+ }
+
+ return __bcb_load(devnum, argv[2]);
+}
+
+static int __bcb_set(char *fieldp, const char *valp)
{
int size, len;
- char *field, *str, *found;
+ char *field, *str, *found, *tmp;
- if (bcb_field_get(argv[1], &field, &size))
+ if (bcb_field_get(fieldp, &field, &size))
return CMD_RET_FAILURE;
- len = strlen(argv[2]);
+ len = strlen(valp);
if (len >= size) {
printf("Error: sizeof('%s') = %d >= %d = sizeof(bcb.%s)\n",
- argv[2], len, size, argv[1]);
+ valp, len, size, fieldp);
+ return CMD_RET_FAILURE;
+ }
+ str = strdup(valp);
+ if (!str) {
+ printf("Error: Out of memory while strdup\n");
return CMD_RET_FAILURE;
}
- str = argv[2];
+ tmp = str;
field[0] = '\0';
- while ((found = strsep(&str, ":"))) {
+ while ((found = strsep(&tmp, ":"))) {
if (field[0] != '\0')
strcat(field, "\n");
strcat(field, found);
}
+ free(str);
return CMD_RET_SUCCESS;
}
+static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ return __bcb_set(argv[1], argv[2]);
+}
+
static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
@@ -250,8 +278,7 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_SUCCESS;
}
-static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int __bcb_store(void)
{
struct blk_desc *desc;
struct disk_partition info;
@@ -282,6 +309,31 @@ err:
return CMD_RET_FAILURE;
}
+static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ return __bcb_store();
+}
+
+int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp)
+{
+ int ret;
+
+ ret = __bcb_load(devnum, partp);
+ if (ret != CMD_RET_SUCCESS)
+ return ret;
+
+ ret = __bcb_set("command", reasonp);
+ if (ret != CMD_RET_SUCCESS)
+ return ret;
+
+ ret = __bcb_store();
+ if (ret != CMD_RET_SUCCESS)
+ return ret;
+
+ return 0;
+}
+
static struct cmd_tbl cmd_bcb_sub[] = {
U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""),
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""),
diff --git a/cmd/dfu.c b/cmd/dfu.c
index 7310595a02..ef4f897ce0 100644
--- a/cmd/dfu.c
+++ b/cmd/dfu.c
@@ -34,7 +34,6 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
#if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
unsigned long value = 0;
#endif
-
if (argc >= 4) {
interface = argv[2];
devstring = argv[3];
@@ -67,8 +66,18 @@ static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
}
int controller_index = simple_strtoul(usb_controller, NULL, 0);
+ bool retry = false;
+ do {
+ run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
- run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
+ if (dfu_reinit_needed) {
+ dfu_free_entities();
+ ret = dfu_init_env_entities(interface, devstring);
+ if (ret)
+ goto done;
+ retry = true;
+ }
+ } while (retry);
done:
dfu_free_entities();
diff --git a/cmd/thordown.c b/cmd/thordown.c
index ae20dddfdd..838764ccef 100644
--- a/cmd/thordown.c
+++ b/cmd/thordown.c
@@ -52,13 +52,18 @@ int do_thor_down(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
goto exit;
}
- ret = thor_handle();
- if (ret) {
- pr_err("THOR failed: %d\n", ret);
- ret = CMD_RET_FAILURE;
- goto exit;
- }
-
+ do {
+ ret = thor_handle();
+ if (ret == THOR_DFU_REINIT_NEEDED) {
+ dfu_free_entities();
+ ret = dfu_init_env_entities(interface, devstring);
+ }
+ if (ret) {
+ pr_err("THOR failed: %d\n", ret);
+ ret = CMD_RET_FAILURE;
+ goto exit;
+ }
+ } while (ret == 0);
exit:
g_dnl_unregister();
usb_gadget_release(controller_index);
diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c
index cf2f55994e..14fa7233c7 100644
--- a/cmd/usb_mass_storage.c
+++ b/cmd/usb_mass_storage.c
@@ -115,8 +115,8 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
ums[ums_count].name = name;
ums[ums_count].block_dev = *block_dev;
- printf("UMS: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n",
- ums_count, ums[ums_count].block_dev.devnum,
+ printf("UMS: LUN %d, dev %s %d, hwpart %d, sector %#x, count %#x\n",
+ ums_count, devtype, ums[ums_count].block_dev.devnum,
ums[ums_count].block_dev.hwpart,
ums[ums_count].start_sector,
ums[ums_count].num_sectors);