diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 13 | ||||
-rw-r--r-- | cmd/Makefile | 1 | ||||
-rw-r--r-- | cmd/axi.c | 6 | ||||
-rw-r--r-- | cmd/button.c | 2 | ||||
-rw-r--r-- | cmd/cpu.c | 4 | ||||
-rw-r--r-- | cmd/demo.c | 4 | ||||
-rw-r--r-- | cmd/efidebug.c | 253 | ||||
-rw-r--r-- | cmd/host.c | 2 | ||||
-rw-r--r-- | cmd/i2c.c | 10 | ||||
-rw-r--r-- | cmd/itest.c | 4 | ||||
-rw-r--r-- | cmd/led.c | 2 | ||||
-rw-r--r-- | cmd/lsblk.c | 2 | ||||
-rw-r--r-- | cmd/mem.c | 2 | ||||
-rw-r--r-- | cmd/misc.c | 2 | ||||
-rw-r--r-- | cmd/nvedit.c | 6 | ||||
-rw-r--r-- | cmd/osd.c | 6 | ||||
-rw-r--r-- | cmd/pci.c | 11 | ||||
-rw-r--r-- | cmd/pmic.c | 4 | ||||
-rw-r--r-- | cmd/pxe_utils.c | 27 | ||||
-rw-r--r-- | cmd/regulator.c | 50 | ||||
-rw-r--r-- | cmd/remoteproc.c | 4 | ||||
-rw-r--r-- | cmd/sandbox/Makefile | 3 | ||||
-rw-r--r-- | cmd/sandbox/exception.c | 41 | ||||
-rw-r--r-- | cmd/setexpr.c | 336 | ||||
-rw-r--r-- | cmd/tpm-v2.c | 3 | ||||
-rw-r--r-- | cmd/w1.c | 4 |
26 files changed, 620 insertions, 182 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 1595de999b..da86a940ce 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -55,6 +55,15 @@ config SYS_PROMPT This string is displayed in the command line to the left of the cursor. +config SYS_PROMPT_HUSH_PS2 + string "Hush shell secondary prompt" + depends on HUSH_PARSER + default "> " + help + This defines the secondary prompt string, which is + printed when the command interpreter needs more input + to complete a command. Usually "> ". + config SYS_XTRACE string "Command execution tracer" depends on CMDLINE @@ -1682,7 +1691,7 @@ config CMD_EFIDEBUG config CMD_EXCEPTION bool "exception - raise exception" - depends on ARM || RISCV || X86 + depends on ARM || RISCV || SANDBOX || X86 help Enable the 'exception' command which allows to raise an exception. @@ -1908,7 +1917,7 @@ config CMD_REGULATOR The '-f' (force) option can be used for set the value which exceeds the limits, which are found in device-tree and are kept in regulator's - uclass platdata structure. + uclass plat structure. endmenu diff --git a/cmd/Makefile b/cmd/Makefile index dd86675bf2..5b3400a840 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -193,6 +193,7 @@ obj-$(CONFIG_CMD_AVB) += avb.o obj-$(CONFIG_ARM) += arm/ obj-$(CONFIG_RISCV) += riscv/ +obj-$(CONFIG_SANDBOX) += sandbox/ obj-$(CONFIG_X86) += x86/ obj-$(CONFIG_ARCH_MVEBU) += mvebu/ @@ -33,9 +33,9 @@ static void show_bus(struct udevice *bus) { struct udevice *dev; - printf("Bus %d:\t%s", bus->req_seq, bus->name); + printf("Bus %d:\t%s", dev_seq(bus), bus->name); if (device_active(bus)) - printf(" (active %d)", bus->seq); + printf(" (active)"); printf("\n"); for (device_find_first_child(bus, &dev); dev; @@ -147,7 +147,7 @@ static int do_axi_bus_num(struct cmd_tbl *cmdtp, int flag, int argc, struct udevice *bus; if (!axi_get_cur_bus(&bus)) - bus_no = bus->seq; + bus_no = dev_seq(bus); else bus_no = -1; diff --git a/cmd/button.c b/cmd/button.c index 64c5a8fa04..1b45d0a2a0 100644 --- a/cmd/button.c +++ b/cmd/button.c @@ -37,7 +37,7 @@ static int list_buttons(void) for (uclass_find_first_device(UCLASS_BUTTON, &dev); dev; uclass_find_next_device(&dev)) { - struct button_uc_plat *plat = dev_get_uclass_platdata(dev); + struct button_uc_plat *plat = dev_get_uclass_plat(dev); if (!plat->label) continue; @@ -26,13 +26,13 @@ static int print_cpu_list(bool detail) for (uclass_first_device(UCLASS_CPU, &dev); dev; uclass_next_device(&dev)) { - struct cpu_platdata *plat = dev_get_parent_platdata(dev); + struct cpu_plat *plat = dev_get_parent_plat(dev); struct cpu_info info; bool first = true; int ret, i; ret = cpu_get_desc(dev, buf, sizeof(buf)); - printf("%3d: %-10s %s\n", dev->seq, dev->name, + printf("%3d: %-10s %s\n", dev_seq(dev), dev->name, ret ? "<no description>" : buf); if (!detail) continue; diff --git a/cmd/demo.c b/cmd/demo.c index 7310aa2907..78a55f72b6 100644 --- a/cmd/demo.c +++ b/cmd/demo.c @@ -71,10 +71,10 @@ int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev); dev; ret = uclass_next_device(&dev)) { - printf("entry %d - instance %08x, ops %08x, platdata %08x\n", + printf("entry %d - instance %08x, ops %08x, plat %08x\n", i++, (uint)map_to_sysmem(dev), (uint)map_to_sysmem(dev->driver->ops), - (uint)map_to_sysmem(dev_get_platdata(dev))); + (uint)map_to_sysmem(dev_get_plat(dev))); } return cmd_process_error(cmdtp, ret); diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 5288b9920b..5fb7b1e3c6 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,240 @@ #include <linux/ctype.h> #define BS systab.boottime +#define RT systab.runtime + +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT +/** + * do_efi_capsule_update() - process a capsule update + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule update" sub-command. + * process a capsule update. + * + * efidebug capsule update [-v] <capsule address> + */ +static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct efi_capsule_header *capsule; + int verbose = 0; + char *endp; + efi_status_t ret; + + if (argc != 2 && argc != 3) + return CMD_RET_USAGE; + + if (argc == 3) { + if (strcmp(argv[1], "-v")) + return CMD_RET_USAGE; + + verbose = 1; + argc--; + argv++; + } + + capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16); + if (endp == argv[1]) { + printf("Invalid address: %s", argv[1]); + return CMD_RET_FAILURE; + } + + if (verbose) { + printf("Capsule guid: %pUl\n", &capsule->capsule_guid); + printf("Capsule flags: 0x%x\n", capsule->flags); + printf("Capsule header size: 0x%x\n", capsule->header_size); + printf("Capsule image size: 0x%x\n", + capsule->capsule_image_size); + } + + ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); + if (ret) { + printf("Cannot handle a capsule at %p", capsule); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + efi_status_t ret; + + ret = efi_launch_capsules(); + + return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE; +} + +/** + * do_efi_capsule_show() - show capsule information + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule show" sub-command. + * show capsule information. + * + * efidebug capsule show <capsule address> + */ +static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct efi_capsule_header *capsule; + char *endp; + + if (argc != 2) + return CMD_RET_USAGE; + + capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16); + if (endp == argv[1]) { + printf("Invalid address: %s", argv[1]); + return CMD_RET_FAILURE; + } + + printf("Capsule guid: %pUl\n", &capsule->capsule_guid); + printf("Capsule flags: 0x%x\n", capsule->flags); + printf("Capsule header size: 0x%x\n", capsule->header_size); + printf("Capsule image size: 0x%x\n", + capsule->capsule_image_size); + + return CMD_RET_SUCCESS; +} + +/** + * do_efi_capsule_res() - show a capsule update result + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule result" sub-command. + * show a capsule update result. + * If result number is not specified, CapsuleLast will be shown. + * + * efidebug capsule result [<capsule result number>] + */ +static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + int capsule_id; + char *endp; + char var_name[12]; + u16 var_name16[12], *p; + efi_guid_t guid; + struct efi_capsule_result_variable_header *result = NULL; + efi_uintn_t size; + efi_status_t ret; + + if (argc != 1 && argc != 2) + return CMD_RET_USAGE; + + guid = efi_guid_capsule_report; + if (argc == 1) { + size = sizeof(var_name16); + ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL, + &size, var_name16)); + if (ret != EFI_SUCCESS) { + if (ret == EFI_NOT_FOUND) + printf("CapsuleLast doesn't exist\n"); + else + printf("Failed to get CapsuleLast\n"); + + return CMD_RET_FAILURE; + } + printf("CapsuleLast is %ls\n", var_name16); + } else { + argc--; + argv++; + + capsule_id = simple_strtoul(argv[0], &endp, 16); + if (capsule_id < 0 || capsule_id > 0xffff) + return CMD_RET_USAGE; + + sprintf(var_name, "Capsule%04X", capsule_id); + p = var_name16; + utf8_utf16_strncpy(&p, var_name, 9); + } + + size = 0; + ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL)); + if (ret == EFI_BUFFER_TOO_SMALL) { + result = malloc(size); + ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, + result)); + if (ret != EFI_SUCCESS) { + free(result); + printf("Failed to get %ls\n", var_name16); + + return CMD_RET_FAILURE; + } + } + + printf("Result total size: 0x%x\n", result->variable_total_size); + printf("Capsule guid: %pUl\n", &result->capsule_guid); + printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n", + result->capsule_processed.year, result->capsule_processed.month, + result->capsule_processed.day, result->capsule_processed.hour, + result->capsule_processed.minute, + result->capsule_processed.second); + printf("Capsule status: 0x%lx\n", result->capsule_status); + + free(result); + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl cmd_efidebug_capsule_sub[] = { + U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update, + "", ""), + U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show, + "", ""), + U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update, + "", ""), + U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res, + "", ""), +}; + +/** + * do_efi_capsule() - manage UEFI capsules + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule" sub-command. + */ +static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct cmd_tbl *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; argv++; + + cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub, + ARRAY_SIZE(cmd_efidebug_capsule_sub)); + if (!cp) + return CMD_RET_USAGE; + + return cp->cmd(cmdtp, flag, argc, argv); +} +#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */ /** * efi_get_device_handle_info() - get information of UEFI device @@ -278,6 +512,10 @@ static const struct { "Runtime properties", EFI_RT_PROPERTIES_TABLE_GUID, }, + { + "TCG2 Final Events Table", + EFI_TCG2_FINAL_EVENTS_TABLE_GUID, + }, }; /** @@ -1237,6 +1475,10 @@ static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag, static struct cmd_tbl cmd_efidebug_sub[] = { U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""), +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT + U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule, + "", ""), +#endif U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices, "", ""), U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers, @@ -1311,6 +1553,17 @@ static char efidebug_help_text[] = "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n" " - set/show UEFI boot order\n" "\n" +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT + "efidebug capsule update [-v] <capsule address>\n" + " - process a capsule\n" + "efidebug capsule disk-update\n" + " - update a capsule from disk\n" + "efidebug capsule show <capsule address>\n" + " - show capsule information\n" + "efidebug capsule result [<capsule result var>]\n" + " - show a capsule update result\n" + "\n" +#endif "efidebug devices\n" " - show UEFI devices\n" "efidebug drivers\n" diff --git a/cmd/host.c b/cmd/host.c index ff119da738..1d21f796ac 100644 --- a/cmd/host.c +++ b/cmd/host.c @@ -91,7 +91,7 @@ static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc, struct host_block_dev *host_dev; #ifdef CONFIG_BLK - host_dev = dev_get_platdata(blk_dev->bdev); + host_dev = dev_get_plat(blk_dev->bdev); #else host_dev = blk_dev->priv; #endif @@ -390,7 +390,7 @@ static int do_i2c_write(struct cmd_tbl *cmdtp, int flag, int argc, ret = i2c_set_chip_offset_len(dev, alen); if (ret) return i2c_report_err(ret, I2C_ERR_WRITE); - i2c_chip = dev_get_parent_platdata(dev); + i2c_chip = dev_get_parent_plat(dev); if (!i2c_chip) return i2c_report_err(ret, I2C_ERR_WRITE); #endif @@ -1700,14 +1700,14 @@ static void show_bus(struct udevice *bus) { struct udevice *dev; - printf("Bus %d:\t%s", bus->req_seq, bus->name); + printf("Bus %d:\t%s", dev_seq(bus), bus->name); if (device_active(bus)) - printf(" (active %d)", bus->seq); + printf(" (active %d)", dev_seq(bus)); printf("\n"); for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { - struct dm_i2c_chip *chip = dev_get_parent_platdata(dev); + struct dm_i2c_chip *chip = dev_get_parent_plat(dev); printf(" %02x: %s, offset len %x, flags %x\n", chip->chip_addr, dev->name, chip->offset_len, @@ -1825,7 +1825,7 @@ static int do_i2c_bus_num(struct cmd_tbl *cmdtp, int flag, int argc, struct udevice *bus; if (!i2c_get_cur_bus(&bus)) - bus_no = bus->seq; + bus_no = dev_seq(bus); else bus_no = -1; #else diff --git a/cmd/itest.c b/cmd/itest.c index a0cf4bee04..9a441ce9b8 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -197,10 +197,10 @@ static int do_itest(struct cmd_tbl *cmdtp, int flag, int argc, #endif value = binary_test (argv[2], argv[1], argv[3], w); break; - case -2: + case CMD_DATA_SIZE_STR: value = binary_test (argv[2], argv[1], argv[3], 0); break; - case -1: + case CMD_DATA_SIZE_ERR: default: puts("Invalid data width specifier\n"); value = 0; @@ -54,7 +54,7 @@ static int list_leds(void) for (uclass_find_first_device(UCLASS_LED, &dev); dev; uclass_find_next_device(&dev)) { - struct led_uc_plat *plat = dev_get_uclass_platdata(dev); + struct led_uc_plat *plat = dev_get_uclass_plat(dev); if (!plat->label) continue; diff --git a/cmd/lsblk.c b/cmd/lsblk.c index 653dffce04..6a1c8f5ef4 100644 --- a/cmd/lsblk.c +++ b/cmd/lsblk.c @@ -34,7 +34,7 @@ static int do_lsblk(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv uclass_foreach_dev(udev, uc) { if (udev->driver != entry) continue; - desc = dev_get_uclass_platdata(udev); + desc = dev_get_uclass_plat(udev); printf("%c %s %u", i ? ',' : ':', blk_get_if_type_name(desc->if_type), desc->devnum); @@ -393,7 +393,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, * Defaults to long if no or incorrect specification. */ size = cmd_get_data_size(argv[0], 4); - if (size < 0 && size != -2 /* string */) + if (size < 0 && size != CMD_DATA_SIZE_STR) return 1; argc--; diff --git a/cmd/misc.c b/cmd/misc.c index 653deed7f5..ef540e836f 100644 --- a/cmd/misc.c +++ b/cmd/misc.c @@ -34,7 +34,7 @@ static int do_misc_list(struct cmd_tbl *cmdtp, int flag, for (uclass_first_device(UCLASS_MISC, &dev); dev; uclass_next_device(&dev)) { - printf("%-20s %5d %10s\n", dev->name, dev->seq, + printf("%-20s %5d %10s\n", dev->name, dev_seq(dev), dev->driver->name); } diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 7fce723800..d0d2eca904 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -266,7 +266,9 @@ static int _do_env_set(int flag, int argc, char *const argv[], int env_flag) /* Delete only ? */ if (argc < 3 || argv[2] == NULL) { int rc = hdelete_r(name, &env_htab, env_flag); - return !rc; + + /* If the variable didn't exist, don't report an error */ + return rc && rc != -ENOENT ? 1 : 0; } /* @@ -895,7 +897,7 @@ static int do_env_delete(struct cmd_tbl *cmdtp, int flag, while (--argc > 0) { char *name = *++argv; - if (!hdelete_r(name, &env_htab, env_flag)) + if (hdelete_r(name, &env_htab, env_flag)) ret = 1; } @@ -75,9 +75,9 @@ static int osd_get_osd_cur(struct udevice **osdp) */ static void show_osd(struct udevice *osd) { - printf("OSD %d:\t%s", osd->req_seq, osd->name); + printf("OSD %d:\t%s", dev_seq(osd), osd->name); if (device_active(osd)) - printf(" (active %d)", osd->seq); + printf(" (active)"); printf("\n"); } @@ -235,7 +235,7 @@ static int do_osd_num(struct cmd_tbl *cmdtp, int flag, int argc, struct udevice *osd; if (!osd_get_osd_cur(&osd)) - osd_no = osd->seq; + osd_no = dev_seq(osd); else osd_no = -1; printf("Current osd is %d\n", osd_no); @@ -334,20 +334,21 @@ static void pciinfo(struct udevice *bus, bool short_listing) { struct udevice *dev; - pciinfo_header(bus->seq, short_listing); + pciinfo_header(dev_seq(bus), short_listing); for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { - struct pci_child_platdata *pplat; + struct pci_child_plat *pplat; - pplat = dev_get_parent_platdata(dev); + pplat = dev_get_parent_plat(dev); if (short_listing) { - printf("%02x.%02x.%02x ", bus->seq, + printf("%02x.%02x.%02x ", dev_seq(bus), PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn)); pci_header_show_brief(dev); } else { - printf("\nFound PCI device %02x.%02x.%02x:\n", bus->seq, + printf("\nFound PCI device %02x.%02x.%02x:\n", + dev_seq(bus), PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn)); pci_header_show(dev); } diff --git a/cmd/pmic.c b/cmd/pmic.c index 3bda0534a3..0cb44d0740 100644 --- a/cmd/pmic.c +++ b/cmd/pmic.c @@ -41,7 +41,7 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; } - printf("dev: %d @ %s\n", currdev->seq, currdev->name); + printf("dev: %d @ %s\n", dev_seq(currdev), currdev->name); } return CMD_RET_SUCCESS; @@ -66,7 +66,7 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, printf("| %-*.*s| %-*.*s| %s @ %d\n", LIMIT_DEV, LIMIT_DEV, dev->name, LIMIT_PARENT, LIMIT_PARENT, dev->parent->name, - dev_get_uclass_name(dev->parent), dev->parent->seq); + dev_get_uclass_name(dev->parent), dev_seq(dev->parent)); } if (ret) diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c index 8716e782f6..b9d9a5786c 100644 --- a/cmd/pxe_utils.c +++ b/cmd/pxe_utils.c @@ -322,7 +322,8 @@ static int label_localboot(struct pxe_label *label) if (label->append) { char bootargs[CONFIG_SYS_CBSIZE]; - cli_simple_process_macros(label->append, bootargs); + cli_simple_process_macros(label->append, bootargs, + sizeof(bootargs)); env_set("bootargs", bootargs); } @@ -430,7 +431,8 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label) strcat(bootargs, ip_str); strcat(bootargs, mac_str); - cli_simple_process_macros(bootargs, finalbootargs); + cli_simple_process_macros(bootargs, finalbootargs, + sizeof(finalbootargs)); env_set("bootargs", finalbootargs); printf("append: %s\n", finalbootargs); } @@ -451,11 +453,14 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label) /* * fdt usage is optional: - * It handles the following scenarios. All scenarios are exclusive + * It handles the following scenarios. * - * Scenario 1: If fdt_addr_r specified and "fdt" label is defined in - * pxe file, retrieve fdt blob from server. Pass fdt_addr_r to bootm, - * and adjust argc appropriately. + * Scenario 1: If fdt_addr_r specified and "fdt" or "fdtdir" label is + * defined in pxe file, retrieve fdt blob from server. Pass fdt_addr_r to + * bootm, and adjust argc appropriately. + * + * If retrieve fails and no exact fdt blob is specified in pxe file with + * "fdt" label, try Scenario 2. * * Scenario 2: If there is an fdt_addr specified, pass it along to * bootm, and adjust argc appropriately. @@ -521,9 +526,13 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label) free(fdtfilefree); if (err < 0) { - printf("Skipping %s for failure retrieving fdt\n", - label->name); - goto cleanup; + bootm_argv[3] = NULL; + + if (label->fdt) { + printf("Skipping %s for failure retrieving FDT\n", + label->name); + goto cleanup; + } } } else { bootm_argv[3] = NULL; diff --git a/cmd/regulator.c b/cmd/regulator.c index aa06c9a9fc..60a70036d6 100644 --- a/cmd/regulator.c +++ b/cmd/regulator.c @@ -25,7 +25,7 @@ static int failure(int ret) static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; const char *name; int ret = -ENXIO; @@ -43,7 +43,7 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; } - uc_pdata = dev_get_uclass_platdata(currdev); + uc_pdata = dev_get_uclass_plat(currdev); if (!uc_pdata) { printf("%s: no regulator platform data!\n", currdev->name); return failure(ret); @@ -55,9 +55,9 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_SUCCESS; } -static int curr_dev_and_platdata(struct udevice **devp, - struct dm_regulator_uclass_platdata **uc_pdata, - bool allow_type_fixed) +static int curr_dev_and_plat(struct udevice **devp, + struct dm_regulator_uclass_plat **uc_pdata, + bool allow_type_fixed) { *devp = NULL; *uc_pdata = NULL; @@ -69,7 +69,7 @@ static int curr_dev_and_platdata(struct udevice **devp, *devp = currdev; - *uc_pdata = dev_get_uclass_platdata(*devp); + *uc_pdata = dev_get_uclass_plat(*devp); if (!*uc_pdata) { pr_err("Regulator: %s - missing platform data!\n", currdev->name); return CMD_RET_FAILURE; @@ -86,7 +86,7 @@ static int curr_dev_and_platdata(struct udevice **devp, static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; struct udevice *dev; int ret; @@ -100,7 +100,7 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, if (ret) continue; - uc_pdata = dev_get_uclass_platdata(dev); + uc_pdata = dev_get_uclass_plat(dev); printf("| %-*.*s| %-*.*s| %s\n", LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name, LIMIT_OFNAME, LIMIT_OFNAME, uc_pdata->name, @@ -143,14 +143,14 @@ static int do_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; struct dm_regulator_mode *modes; const char *parent_uc; int mode_count; int ret; int i; - ret = curr_dev_and_platdata(&dev, &uc_pdata, true); + ret = curr_dev_and_plat(&dev, &uc_pdata, true); if (ret) return ret; @@ -183,7 +183,7 @@ static int do_info(struct cmd_tbl *cmdtp, int flag, int argc, } static void do_status_detail(struct udevice *dev, - struct dm_regulator_uclass_platdata *uc_pdata) + struct dm_regulator_uclass_plat *uc_pdata) { int current, value, mode; const char *mode_name; @@ -207,12 +207,12 @@ static void do_status_detail(struct udevice *dev, static void do_status_line(struct udevice *dev) { - struct dm_regulator_uclass_platdata *pdata; + struct dm_regulator_uclass_plat *pdata; int current, value, mode; const char *mode_name; bool enabled; - pdata = dev_get_uclass_platdata(dev); + pdata = dev_get_uclass_plat(dev); enabled = regulator_get_enable(dev); value = regulator_get_value(dev); current = regulator_get_current(dev); @@ -237,12 +237,12 @@ static void do_status_line(struct udevice *dev) static int do_status(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; struct udevice *dev; int ret; if (currdev && (argc < 2 || strcmp(argv[1], "-a"))) { - ret = curr_dev_and_platdata(&dev, &uc_pdata, true); + ret = curr_dev_and_plat(&dev, &uc_pdata, true); if (ret) return CMD_RET_FAILURE; do_status_detail(dev, uc_pdata); @@ -263,12 +263,12 @@ static int do_value(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; int value; int force; int ret; - ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1); + ret = curr_dev_and_plat(&dev, &uc_pdata, argc == 1); if (ret) return ret; @@ -313,11 +313,11 @@ static int do_current(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; int current; int ret; - ret = curr_dev_and_platdata(&dev, &uc_pdata, argc == 1); + ret = curr_dev_and_plat(&dev, &uc_pdata, argc == 1); if (ret) return ret; @@ -353,11 +353,11 @@ static int do_mode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; int mode; int ret; - ret = curr_dev_and_platdata(&dev, &uc_pdata, false); + ret = curr_dev_and_plat(&dev, &uc_pdata, false); if (ret) return ret; @@ -389,10 +389,10 @@ static int do_enable(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; int ret; - ret = curr_dev_and_platdata(&dev, &uc_pdata, true); + ret = curr_dev_and_plat(&dev, &uc_pdata, true); if (ret) return ret; @@ -409,10 +409,10 @@ static int do_disable(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - struct dm_regulator_uclass_platdata *uc_pdata; + struct dm_regulator_uclass_plat *uc_pdata; int ret; - ret = curr_dev_and_platdata(&dev, &uc_pdata, true); + ret = curr_dev_and_plat(&dev, &uc_pdata, true); if (ret) return ret; diff --git a/cmd/remoteproc.c b/cmd/remoteproc.c index e8b9178e74..5f9ba92560 100644 --- a/cmd/remoteproc.c +++ b/cmd/remoteproc.c @@ -32,7 +32,7 @@ static int print_remoteproc_list(void) struct dm_rproc_uclass_pdata *uc_pdata; const struct dm_rproc_ops *ops = rproc_get_ops(dev); - uc_pdata = dev_get_uclass_platdata(dev); + uc_pdata = dev_get_uclass_plat(dev); /* Do not print if rproc is not probed */ if (!(dev->flags & DM_FLAG_ACTIVATED)) @@ -47,7 +47,7 @@ static int print_remoteproc_list(void) break; } printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n", - dev->seq, + dev_seq(dev), uc_pdata->name, type, ops->load ? "load " : "", diff --git a/cmd/sandbox/Makefile b/cmd/sandbox/Makefile new file mode 100644 index 0000000000..24df023ece --- /dev/null +++ b/cmd/sandbox/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_CMD_EXCEPTION) += exception.o diff --git a/cmd/sandbox/exception.c b/cmd/sandbox/exception.c new file mode 100644 index 0000000000..1aa1d673ae --- /dev/null +++ b/cmd/sandbox/exception.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * The 'exception' command can be used for testing exception handling. + * + * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de> + */ + +#include <common.h> +#include <command.h> + +static int do_sigsegv(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + u8 *ptr = NULL; + + *ptr = 0; + return CMD_RET_FAILURE; +} + +static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + asm volatile (".word 0xffff\n"); + return CMD_RET_FAILURE; +} + +static struct cmd_tbl cmd_sub[] = { + U_BOOT_CMD_MKENT(sigsegv, CONFIG_SYS_MAXARGS, 1, do_sigsegv, + "", ""), + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, + "", ""), +}; + +static char exception_help_text[] = + "<ex>\n" + " The following exceptions are available:\n" + " undefined - undefined instruction\n" + " sigsegv - illegal memory access\n" + ; + +#include <exception.h> diff --git a/cmd/setexpr.c b/cmd/setexpr.c index 770dc24d2b..e828be3970 100644 --- a/cmd/setexpr.c +++ b/cmd/setexpr.c @@ -13,10 +13,27 @@ #include <command.h> #include <env.h> #include <log.h> +#include <malloc.h> #include <mapmem.h> +#include <linux/sizes.h> -static ulong get_arg(char *s, int w) +/** + * struct expr_arg: Holds an argument to an expression + * + * @ival: Integer value (if width is not CMD_DATA_SIZE_STR) + * @sval: String value (if width is CMD_DATA_SIZE_STR) + */ +struct expr_arg { + union { + ulong ival; + char *sval; + }; +}; + +static int get_arg(char *s, int w, struct expr_arg *argp) { + struct expr_arg arg; + /* * If the parameter starts with a '*' then assume it is a pointer to * the value we want. @@ -25,6 +42,8 @@ static ulong get_arg(char *s, int w) ulong *p; ulong addr; ulong val; + int len; + char *str; addr = simple_strtoul(&s[1], NULL, 16); switch (w) { @@ -32,31 +51,56 @@ static ulong get_arg(char *s, int w) p = map_sysmem(addr, sizeof(uchar)); val = (ulong)*(uchar *)p; unmap_sysmem(p); - return val; + arg.ival = val; + break; case 2: p = map_sysmem(addr, sizeof(ushort)); val = (ulong)*(ushort *)p; unmap_sysmem(p); - return val; + arg.ival = val; + break; + case CMD_DATA_SIZE_STR: + p = map_sysmem(addr, SZ_64K); + + /* Maximum string length of 64KB plus terminator */ + len = strnlen((char *)p, SZ_64K) + 1; + str = malloc(len); + if (!str) { + printf("Out of memory\n"); + return -ENOMEM; + } + memcpy(str, p, len); + str[len - 1] = '\0'; + unmap_sysmem(p); + arg.sval = str; + break; case 4: + p = map_sysmem(addr, sizeof(u32)); + val = *(u32 *)p; + unmap_sysmem(p); + arg.ival = val; + break; default: p = map_sysmem(addr, sizeof(ulong)); val = *p; unmap_sysmem(p); - return val; + arg.ival = val; + break; } } else { - return simple_strtoul(s, NULL, 16); + if (w == CMD_DATA_SIZE_STR) + return -EINVAL; + arg.ival = simple_strtoul(s, NULL, 16); } + *argp = arg; + + return 0; } #ifdef CONFIG_REGEX #include <slre.h> -#define SLRE_BUFSZ 16384 -#define SLRE_PATSZ 4096 - /* * memstr - Find the first substring in memory * @s1: The string to be searched @@ -79,13 +123,24 @@ static char *memstr(const char *s1, int l1, const char *s2, int l2) return NULL; } -static char *substitute(char *string, /* string buffer */ - int *slen, /* current string length */ - int ssize, /* string bufer size */ - const char *old,/* old (replaced) string */ - int olen, /* length of old string */ - const char *new,/* new (replacement) string */ - int nlen) /* length of new string */ +/** + * substitute() - Substitute part of one string with another + * + * This updates @string so that the first occurrence of @old is replaced with + * @new + * + * @string: String buffer containing string to update at the start + * @slen: Pointer to current string length, updated on success + * @ssize: Size of string buffer + * @old: Old string to find in the buffer (no terminator needed) + * @olen: Length of @old excluding terminator + * @new: New string to replace @old with + * @nlen: Length of @new excluding terminator + * @return pointer to immediately after the copied @new in @string, or NULL if + * no replacement took place + */ +static char *substitute(char *string, int *slen, int ssize, + const char *old, int olen, const char *new, int nlen) { char *p = memstr(string, *slen, old, olen); @@ -114,7 +169,7 @@ static char *substitute(char *string, /* string buffer */ memmove(p + nlen, p + olen, tail); } - /* insert substitue */ + /* insert substitute */ memcpy(p, new, nlen); *slen += nlen - olen; @@ -122,71 +177,32 @@ static char *substitute(char *string, /* string buffer */ return p + nlen; } -/* - * Perform regex operations on a environment variable - * - * Returns 0 if OK, 1 in case of errors. - */ -static int regex_sub(const char *name, - const char *r, const char *s, const char *t, - int global) +int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, + const char *r, const char *s, bool global) { struct slre slre; - char data[SLRE_BUFSZ]; char *datap = data; - const char *value; int res, len, nlen, loop; - if (name == NULL) - return 1; - if (slre_compile(&slre, r) == 0) { printf("Error compiling regex: %s\n", slre.err_str); return 1; } - if (t == NULL) { - value = env_get(name); - - if (value == NULL) { - printf("## Error: variable \"%s\" not defined\n", name); - return 1; - } - t = value; - } - - debug("REGEX on %s=%s\n", name, t); - debug("REGEX=\"%s\", SUBST=\"%s\", GLOBAL=%d\n", - r, s ? s : "<NULL>", global); - - len = strlen(t); - if (len + 1 > SLRE_BUFSZ) { - printf("## error: subst buffer overflow: have %d, need %d\n", - SLRE_BUFSZ, len + 1); - return 1; - } - - strcpy(data, t); - - if (s == NULL) - nlen = 0; - else - nlen = strlen(s); - + len = strlen(data); for (loop = 0;; loop++) { struct cap caps[slre.num_caps + 2]; - char nbuf[SLRE_PATSZ]; const char *old; char *np; int i, olen; (void) memset(caps, 0, sizeof(caps)); - res = slre_match(&slre, datap, len, caps); + res = slre_match(&slre, datap, len - (datap - data), caps); debug("Result: %d\n", res); - for (i = 0; i < slre.num_caps; i++) { + for (i = 0; i <= slre.num_caps; i++) { if (caps[i].len > 0) { debug("Substring %d: [%.*s]\n", i, caps[i].len, caps[i].ptr); @@ -195,7 +211,7 @@ static int regex_sub(const char *name, if (res == 0) { if (loop == 0) { - printf("%s: No match\n", t); + printf("%s: No match\n", data); return 1; } else { break; @@ -204,17 +220,16 @@ static int regex_sub(const char *name, debug("## MATCH ## %s\n", data); - if (s == NULL) { - printf("%s=%s\n", name, t); + if (!s) return 1; - } old = caps[0].ptr; olen = caps[0].len; + nlen = strlen(s); - if (nlen + 1 >= SLRE_PATSZ) { + if (nlen + 1 >= nbuf_size) { printf("## error: pattern buffer overflow: have %d, need %d\n", - SLRE_BUFSZ, nlen + 1); + nbuf_size, nlen + 1); return 1; } strcpy(nbuf, s); @@ -259,7 +274,7 @@ static int regex_sub(const char *name, break; np = substitute(np, &nlen, - SLRE_PATSZ, + nbuf_size - (np - nbuf), backref, 2, caps[i].ptr, caps[i].len); @@ -269,9 +284,8 @@ static int regex_sub(const char *name, } debug("## SUBST(2) ## %s\n", nbuf); - datap = substitute(datap, &len, SLRE_BUFSZ, - old, olen, - nbuf, nlen); + datap = substitute(datap, &len, data_size - (datap - data), + old, olen, nbuf, nlen); if (datap == NULL) return 1; @@ -285,6 +299,62 @@ static int regex_sub(const char *name, } debug("## FINAL (now env_set()) : %s\n", data); + return 0; +} + +#define SLRE_BUFSZ 16384 +#define SLRE_PATSZ 4096 + +/* + * Perform regex operations on a environment variable + * + * Returns 0 if OK, 1 in case of errors. + */ +static int regex_sub_var(const char *name, const char *r, const char *s, + const char *t, int global) +{ + struct slre slre; + char data[SLRE_BUFSZ]; + char nbuf[SLRE_PATSZ]; + const char *value; + int len; + int ret; + + if (!name) + return 1; + + if (slre_compile(&slre, r) == 0) { + printf("Error compiling regex: %s\n", slre.err_str); + return 1; + } + + if (!t) { + value = env_get(name); + if (!value) { + printf("## Error: variable \"%s\" not defined\n", name); + return 1; + } + t = value; + } + + debug("REGEX on %s=%s\n", name, t); + debug("REGEX=\"%s\", SUBST=\"%s\", GLOBAL=%d\n", r, s ? s : "<NULL>", + global); + + len = strlen(t); + if (len + 1 > SLRE_BUFSZ) { + printf("## error: subst buffer overflow: have %d, need %d\n", + SLRE_BUFSZ, len + 1); + return 1; + } + + strcpy(data, t); + + ret = setexpr_regex_sub(data, SLRE_BUFSZ, nbuf, SLRE_PATSZ, r, s, + global); + if (ret) + return 1; + printf("%s=%s\n", name, data); return env_set(name, data); @@ -294,8 +364,9 @@ static int regex_sub(const char *name, static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - ulong a, b; + struct expr_arg aval, bval; ulong value; + int ret = 0; int w; /* @@ -312,12 +383,19 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, w = cmd_get_data_size(argv[0], 4); - a = get_arg(argv[2], w); + if (get_arg(argv[2], w, &aval)) + return CMD_RET_FAILURE; /* plain assignment: "setexpr name value" */ if (argc == 3) { - env_set_hex(argv[1], a); - return 0; + if (w == CMD_DATA_SIZE_STR) { + ret = env_set(argv[1], aval.sval); + free(aval.sval); + } else { + ret = env_set_hex(argv[1], aval.ival); + } + + return ret; } /* 5 or 6 args (6 args only with [g]sub) */ @@ -327,10 +405,10 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, * with 5 args, "t" will be NULL */ if (strcmp(argv[2], "gsub") == 0) - return regex_sub(argv[1], argv[3], argv[4], argv[5], 1); + return regex_sub_var(argv[1], argv[3], argv[4], argv[5], 1); if (strcmp(argv[2], "sub") == 0) - return regex_sub(argv[1], argv[3], argv[4], argv[5], 0); + return regex_sub_var(argv[1], argv[3], argv[4], argv[5], 0); #endif /* standard operators: "setexpr name val1 op val2" */ @@ -340,49 +418,89 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, if (strlen(argv[3]) != 1) return CMD_RET_USAGE; - b = get_arg(argv[4], w); - - switch (argv[3][0]) { - case '|': - value = a | b; - break; - case '&': - value = a & b; - break; - case '+': - value = a + b; - break; - case '^': - value = a ^ b; - break; - case '-': - value = a - b; - break; - case '*': - value = a * b; - break; - case '/': - value = a / b; - break; - case '%': - value = a % b; - break; - default: - printf("invalid op\n"); - return 1; + if (get_arg(argv[4], w, &bval)) { + if (w == CMD_DATA_SIZE_STR) + free(aval.sval); + return CMD_RET_FAILURE; } - env_set_hex(argv[1], value); + if (w == CMD_DATA_SIZE_STR) { + int len; + char *str; + + switch (argv[3][0]) { + case '+': + len = strlen(aval.sval) + strlen(bval.sval) + 1; + str = malloc(len); + if (!str) { + printf("Out of memory\n"); + ret = CMD_RET_FAILURE; + } else { + /* These were copied out and checked earlier */ + strcpy(str, aval.sval); + strcat(str, bval.sval); + ret = env_set(argv[1], str); + if (ret) + printf("Could not set var\n"); + free(str); + } + break; + default: + printf("invalid op\n"); + ret = 1; + } + } else { + ulong a = aval.ival; + ulong b = bval.ival; - return 0; + switch (argv[3][0]) { + case '|': + value = a | b; + break; + case '&': + value = a & b; + break; + case '+': + value = a + b; + break; + case '^': + value = a ^ b; + break; + case '-': + value = a - b; + break; + case '*': + value = a * b; + break; + case '/': + value = a / b; + break; + case '%': + value = a % b; + break; + default: + printf("invalid op\n"); + return 1; + } + + env_set_hex(argv[1], value); + } + + if (w == CMD_DATA_SIZE_STR) { + free(aval.sval); + free(bval.sval); + } + + return ret; } U_BOOT_CMD( setexpr, 6, 0, do_setexpr, "set environment variable as the result of eval expression", - "[.b, .w, .l] name [*]value1 <op> [*]value2\n" + "[.b, .w, .l, .s] name [*]value1 <op> [*]value2\n" " - set environment variable 'name' to the result of the evaluated\n" " expression specified by <op>. <op> can be &, |, ^, +, -, *, /, %\n" + " (for strings only + is supported)\n" " size argument is only meaningful if value1 and/or value2 are\n" " memory addresses (*)\n" "setexpr[.b, .w, .l] name [*]value\n" diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index 5fa4788a72..daae91100a 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -116,7 +116,8 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc, if (index >= priv->pcr_count) return -EINVAL; - rc = tpm2_pcr_extend(dev, index, digest); + rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest, + TPM2_DIGEST_LEN); unmap_sysmem(digest); @@ -21,7 +21,7 @@ static int w1_bus(void) printf("one wire interface not found\n"); return CMD_RET_FAILURE; } - printf("Bus %d:\t%s", bus->seq, bus->name); + printf("Bus %d:\t%s", dev_seq(bus), bus->name); if (device_active(bus)) printf(" (active)"); printf("\n"); @@ -31,7 +31,7 @@ static int w1_bus(void) device_find_next_child(&dev)) { ret = device_probe(dev); - printf("\t%s (%d) uclass %s : ", dev->name, dev->seq, + printf("\t%s (%d) uclass %s : ", dev->name, dev_seq(dev), dev->uclass->uc_drv->name); if (ret) |