aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bcb.c88
-rw-r--r--cmd/cros_ec.c195
-rw-r--r--cmd/dfu.c13
-rw-r--r--cmd/thordown.c19
-rw-r--r--cmd/usb_mass_storage.c4
5 files changed, 284 insertions, 35 deletions
diff --git a/cmd/bcb.c b/cmd/bcb.c
index e03218066bf..6b6f1e9a2f1 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/cros_ec.c b/cmd/cros_ec.c
index ce1f59a740c..eb5053d6424 100644
--- a/cmd/cros_ec.c
+++ b/cmd/cros_ec.c
@@ -94,6 +94,169 @@ static int do_read_write(struct udevice *dev, int is_write, int argc,
return 0;
}
+static const char *const feat_name[64] = {
+ "limited",
+ "flash",
+ "pwm_fan",
+ "pwm_keyb",
+ "lightbar",
+ "led",
+ "motion_sense",
+ "keyb",
+ "pstore",
+ "port80",
+ "thermal",
+ "bklight_switch",
+ "wifi_switch",
+ "host_events",
+ "gpio",
+ "i2c",
+ "charger",
+ "battery",
+ "smart_battery",
+ "hang_detect",
+ "pmu",
+ "sub_mcu",
+ "usb_pd",
+ "usb_mux",
+ "motion_sense_fifo",
+ "vstore",
+ "usbc_ss_mux_virtual",
+ "rtc",
+ "fingerprint",
+ "touchpad",
+ "rwsig",
+ "device_event",
+ "unified_wake_masks",
+ "host_event64",
+ "exec_in_ram",
+ "cec",
+ "motion_sense_tight_timestamps",
+ "refined_tablet_mode_hysteresis",
+ "efs2",
+ "scp",
+ "ish",
+ "typec_cmd",
+ "typec_require_ap_mode_entry",
+ "typec_mux_require_ap_ack",
+};
+
+static int do_show_features(struct udevice *dev)
+{
+ u64 feat;
+ int ret;
+ uint i;
+
+ ret = cros_ec_get_features(dev, &feat);
+ if (ret)
+ return ret;
+ for (i = 0; i < ARRAY_SIZE(feat_name); i++) {
+ if (feat & (1ULL << i)) {
+ if (feat_name[i])
+ printf("%s\n", feat_name[i]);
+ else
+ printf("unknown %d\n", i);
+ }
+ }
+
+ return 0;
+}
+
+static const char *const switch_name[8] = {
+ "lid open",
+ "power button pressed",
+ "write-protect disabled",
+ NULL,
+ "dedicated recovery",
+ NULL,
+ NULL,
+ NULL,
+};
+
+static int do_show_switches(struct udevice *dev)
+{
+ uint switches;
+ int ret;
+ uint i;
+
+ ret = cros_ec_get_switches(dev);
+ if (ret < 0)
+ return log_msg_ret("get", ret);
+ switches = ret;
+ for (i = 0; i < ARRAY_SIZE(switch_name); i++) {
+ uint mask = 1 << i;
+
+ if (switches & mask) {
+ if (switch_name[i])
+ printf("%s\n", switch_name[i]);
+ else
+ printf("unknown %02x\n", mask);
+ }
+ }
+
+ return 0;
+}
+
+static const char *const event_name[] = {
+ "lid_closed",
+ "lid_open",
+ "power_button",
+ "ac_connected",
+ "ac_disconnected",
+ "battery_low",
+ "battery_critical",
+ "battery",
+ "thermal_threshold",
+ "device",
+ "thermal",
+ "usb_charger",
+ "key_pressed",
+ "interface_ready",
+ "keyboard_recovery",
+ "thermal_shutdown",
+ "battery_shutdown",
+ "throttle_start",
+ "throttle_stop",
+ "hang_detect",
+ "hang_reboot",
+ "pd_mcu",
+ "battery_status",
+ "panic",
+ "keyboard_fastboot",
+ "rtc",
+ "mkbp",
+ "usb_mux",
+ "mode_change",
+ "keyboard_recovery_hw_reinit",
+ "extended",
+ "invalid",
+};
+
+static int do_show_events(struct udevice *dev)
+{
+ u32 events;
+ int ret;
+ uint i;
+
+ ret = cros_ec_get_host_events(dev, &events);
+ if (ret)
+ return ret;
+ printf("%08x\n", events);
+ for (i = 0; i < ARRAY_SIZE(event_name); i++) {
+ enum host_event_code code = i + 1;
+ u64 mask = EC_HOST_EVENT_MASK(code);
+
+ if (events & mask) {
+ if (event_name[i])
+ printf("%s\n", event_name[i]);
+ else
+ printf("unknown code %#x\n", code);
+ }
+ }
+
+ return 0;
+}
+
static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
@@ -140,6 +303,16 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
}
printf("rows = %u\n", info.rows);
printf("cols = %u\n", info.cols);
+ } else if (!strcmp("features", cmd)) {
+ ret = do_show_features(dev);
+
+ if (ret)
+ printf("Error: %d\n", ret);
+ } else if (!strcmp("switches", cmd)) {
+ ret = do_show_switches(dev);
+
+ if (ret)
+ printf("Error: %d\n", ret);
} else if (0 == strcmp("curimage", cmd)) {
enum ec_current_image image;
@@ -190,13 +363,10 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
return 1;
}
} else if (0 == strcmp("events", cmd)) {
- uint32_t events;
+ ret = do_show_events(dev);
- if (cros_ec_get_host_events(dev, &events)) {
- debug("%s: Could not read host events\n", __func__);
- return 1;
- }
- printf("0x%08x\n", events);
+ if (ret)
+ printf("Error: %d\n", ret);
} else if (0 == strcmp("clrevents", cmd)) {
uint32_t events = 0x7fffffff;
@@ -352,6 +522,15 @@ static int do_cros_ec(struct cmd_tbl *cmdtp, int flag, int argc,
debug("%s: Could not access LDO%d\n", __func__, index);
return ret;
}
+ } else if (!strcmp("sku", cmd)) {
+ ret = cros_ec_get_sku_id(dev);
+
+ if (ret >= 0) {
+ printf("%d\n", ret);
+ ret = 0;
+ } else {
+ printf("Error: %d\n", ret);
+ }
} else {
return CMD_RET_USAGE;
}
@@ -370,10 +549,13 @@ U_BOOT_CMD(
"init Re-init CROS-EC (done on startup automatically)\n"
"crosec id Read CROS-EC ID\n"
"crosec info Read CROS-EC info\n"
+ "crosec features Read CROS-EC features\n"
+ "crosec switches Read CROS-EC switches\n"
"crosec curimage Read CROS-EC current image\n"
"crosec hash Read CROS-EC hash\n"
"crosec reboot [rw | ro | cold] Reboot CROS-EC\n"
"crosec events Read CROS-EC host events\n"
+ "crosec eventsb Read CROS-EC host events_b\n"
"crosec clrevents [mask] Clear CROS-EC host events\n"
"crosec regioninfo <ro|rw> Read image info\n"
"crosec flashinfo Read flash info\n"
@@ -382,6 +564,7 @@ U_BOOT_CMD(
"crosec write <ro|rw> <addr> [<size>] Write EC image\n"
"crosec vbnvcontext [hexstring] Read [write] VbNvContext from EC\n"
"crosec ldo <idx> [<state>] Switch/Read LDO state\n"
+ "crosec sku Read board SKU ID\n"
"crosec test run tests on cros_ec\n"
"crosec version Read CROS-EC version"
);
diff --git a/cmd/dfu.c b/cmd/dfu.c
index 7310595a027..ef4f897ce07 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 ae20dddfddb..838764ccef7 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 cf2f55994e0..14fa7233c71 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);