diff options
Diffstat (limited to 'cmd')
71 files changed, 1299 insertions, 995 deletions
diff --git a/cmd/2048.c b/cmd/2048.c index 42cd171b0e4..aa0f82721dc 100644 --- a/cmd/2048.c +++ b/cmd/2048.c @@ -8,6 +8,7 @@ #include <rand.h> #include <vsprintf.h> #include <linux/delay.h> +#include <linux/string.h> #define SIZE 4 static uint score; diff --git a/cmd/Kconfig b/cmd/Kconfig index 057f091bf3b..b3b5be1ea79 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -190,6 +190,12 @@ config CMD_FWU_METADATA help Command to read the metadata and dump it's contents +config CMD_HELP + bool "help" + default y + help + Command to show help information about other commands. + config CMD_HISTORY bool "history" depends on CMDLINE_EDITING @@ -408,7 +414,7 @@ config BOOTM_RTEMS config CMD_SEAMA bool "Support read SEAMA NAND images" - depends on MTD_RAW_NAND + depends on (TARGET_BCMNS || TARGET_BCMNS3) && MTD_RAW_NAND help Support reading NAND Seattle Image (SEAMA) images. @@ -1687,13 +1693,6 @@ config CMD_TEMPERATURE help Provides a way to list thermal sensors and to get their readings. -config CMD_TSI148 - bool "tsi148 - Command to access tsi148 device" - depends on DM_PCI_COMPAT - help - This provides various sub-commands to initialise and configure the - Turndra tsi148 device. See the command help for full details. - config CMD_UFS bool "ufs - Universal Flash Storage commands" depends on UFS @@ -1701,13 +1700,6 @@ config CMD_UFS "This provides commands to initialise and configure universal flash subsystem devices" -config CMD_UNIVERSE - bool "universe - Command to set up the Turndra Universe controller" - depends on DM_PCI_COMPAT - help - This allows setting up the VMEbus provided by this controller. - See the command help for full details. - config CMD_USB bool "usb" depends on USB_HOST @@ -1865,12 +1857,6 @@ config CMD_DHCP6 if CMD_DHCP6 -config DHCP6_PXE_CLIENTARCH - hex - default 0x16 if ARM64 - default 0x15 if ARM - default 0xFF - config DHCP6_PXE_DHCP_OPTION bool "Request & store 'pxe_configfile' from DHCP6 server" @@ -1978,15 +1964,26 @@ config BOOTP_PXE help Supported for ARM, ARM64, and x86 for now. -config BOOTP_PXE_CLIENTARCH - hex - depends on BOOTP_PXE - default 0x16 if ARM64 - default 0x15 if ARM - default 0x0 if X86 +config DHCP_PXE_CLIENTARCH + hex "DCHCP client system architecture type" + depends on BOOTP_PXE || CMD_DHCP6 + default 0x16 if ARM64 # arm 64 uboot + default 0x15 if ARM # arm 32 uboot + default 0x0 if X86 # x86 BIOS + default 0xFF # DHCP option not sent + help + DHCP option 93 (defined in RFC4578) or DHCPv6 option 61 (defined in + RFC 5970) is used to transmit the client system architecture type + to the DHCP server. The DHCP server may use this information to + choose the boot file. For a complete list of assigned values see + https://www.iana.org/assignments/dhcpv6-parameters#processor-architecture. + + If the value is set to the reserved value 0xFF, the DHCP option will + not be sent by U-Boot. config BOOTP_PXE_DHCP_OPTION bool "Request & store 'pxe_configfile' from BOOTP/DHCP server" + default y depends on BOOTP_PXE config BOOTP_VCI_STRING @@ -1997,6 +1994,13 @@ config BOOTP_VCI_STRING default "U-Boot.arm" if ARM default "U-Boot" +config BOOTP_RANDOM_XID + bool "Send random transaction ID to BOOTP/DHCP server" + depends on CMD_BOOTP && (LIB_RAND || LIB_HW_RAND) + help + Selecting this will allow for a random transaction ID to get + selected for each BOOTP/DHCPv4 exchange. + config CMD_TFTPPUT bool "tftp put" depends on CMD_TFTPBOOT @@ -2062,12 +2066,6 @@ config CMD_CDP and to retrieve configuration data including the VLAN id using the proprietary Cisco Discovery Protocol (CDP). -config CMD_SNTP - bool "sntp" - select PROT_UDP - help - Synchronize RTC via network - config CMD_LINK_LOCAL bool "linklocal" depends on (LIB_RAND || LIB_HW_RAND) @@ -2145,6 +2143,13 @@ config CMD_PING help Send ICMP ECHO_REQUEST to network host +config CMD_SNTP + bool "sntp" + select PROT_UDP if NET + select PROT_UDP_LWIP if NET_LWIP + help + Synchronize RTC via network + config CMD_TFTPBOOT bool "tftp" select PROT_UDP_LWIP if NET_LWIP @@ -2154,7 +2159,7 @@ config CMD_TFTPBOOT config CMD_WGET bool "wget" - default y if SANDBOX + default y if SANDBOX || ARCH_QEMU select WGET help wget is a simple command to download kernel, or other files, @@ -2624,6 +2629,7 @@ config CMD_AES config CMD_BLOB bool "Enable the 'blob' command" depends on !MX6ULL && !MX6SLL && !MX6SL + depends on SYS_FSL_SEC_COMPAT >= 4 select IMX_HAB if ARCH_MX6 || ARCH_MX7 || ARCH_MX7ULP || ARCH_IMX8M help This is used with the Freescale secure boot mechanism. diff --git a/cmd/Makefile b/cmd/Makefile index 80cf70b7fe8..e4ecf2e0493 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -7,7 +7,7 @@ ifndef CONFIG_XPL_BUILD # core command obj-y += boot.o obj-$(CONFIG_CMD_BOOTM) += bootm.o -obj-y += help.o +obj-$(CONFIG_CMD_HELP) += help.o obj-y += panic.o obj-y += version.o @@ -133,7 +133,8 @@ obj-$(CONFIG_CMD_NAND) += nand.o ifdef CONFIG_NET obj-$(CONFIG_CMD_NET) += net.o net-common.o else ifdef CONFIG_NET_LWIP -obj-$(CONFIG_CMD_NET) += net-lwip.o net-common.o +obj-$(CONFIG_CMD_NET) += net-common.o +obj-y += lwip/ endif obj-$(CONFIG_ENV_SUPPORT) += nvedit.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o @@ -190,10 +191,8 @@ obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o obj-$(CONFIG_CMD_TPM_V2) += tpm-v2.o obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o -obj-$(CONFIG_CMD_TSI148) += tsi148.o obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_UBIFS) += ubifs.o -obj-$(CONFIG_CMD_UNIVERSE) += universe.o obj-$(CONFIG_CMD_UNLZ4) += unlz4.o obj-$(CONFIG_CMD_UNZIP) += unzip.o obj-$(CONFIG_CMD_UPL) += upl.o diff --git a/cmd/abootimg.c b/cmd/abootimg.c index ae7a1a7c83b..6fb52153786 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -6,6 +6,7 @@ #include <android_image.h> #include <command.h> +#include <env.h> #include <image.h> #include <mapmem.h> @@ -95,7 +96,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) return CMD_RET_USAGE; struct andr_image_data img_data = {0}; const struct andr_boot_img_hdr_v0 *hdr; - const struct andr_vnd_boot_img_hdr *vhdr; + const struct andr_vnd_boot_img_hdr *vhdr = NULL; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); if (get_avendor_bootimg_addr() != -1) diff --git a/cmd/adc.c b/cmd/adc.c index 4d3b5b61f6f..334ba7fdeca 100644 --- a/cmd/adc.c +++ b/cmd/adc.c @@ -5,6 +5,7 @@ */ #include <command.h> #include <dm.h> +#include <env.h> #include <adc.h> #include <linux/printk.h> diff --git a/cmd/aes.c b/cmd/aes.c index 87ad1ab82b9..3fd83013ffe 100644 --- a/cmd/aes.c +++ b/cmd/aes.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2014 Marek Vasut <marex@denx.de> + * Copyright (C) 2025 Ion Agorria <ion@agorria.com> * - * Command for en/de-crypting block of memory with AES-[128/192/256]-CBC cipher. + * Command for AES-[128/192/256] operations. */ #include <command.h> @@ -12,6 +13,8 @@ #include <linux/compiler.h> #include <mapmem.h> #include <vsprintf.h> +#include <dm/uclass.h> +#include <dm/device.h> u32 aes_get_key_len(char *command) { @@ -25,29 +28,30 @@ u32 aes_get_key_len(char *command) return key_len; } -/** - * do_aes() - Handle the "aes" command-line command - * @cmdtp: Command data struct pointer - * @flag: Command flag - * @argc: Command-line argument count - * @argv: Array of command-line arguments - * - * Returns zero on success, CMD_RET_USAGE in case of misuse and negative - * on error. - */ -static int do_aes(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +int aes_get_driver(struct udevice **dev) +{ + int ret; + + ret = uclass_get_device(UCLASS_AES, 0, dev); + if (ret) { + printf("Failed to get AES driver: %d\n", ret); + return ret; + } + + return 0; +} + +int cmd_aes_cbc_simple(int argc, char *const argv[], u32 key_len) { uint32_t key_addr, iv_addr, src_addr, dst_addr, len; uint8_t *key_ptr, *iv_ptr, *src_ptr, *dst_ptr; u8 key_exp[AES256_EXPAND_KEY_LENGTH]; - u32 aes_blocks, key_len; + u32 aes_blocks; int enc; if (argc != 7) return CMD_RET_USAGE; - key_len = aes_get_key_len(argv[0]); - if (!strncmp(argv[1], "enc", 3)) enc = 1; else if (!strncmp(argv[1], "dec", 3)) @@ -84,26 +88,257 @@ static int do_aes(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) unmap_sysmem(src_ptr); unmap_sysmem(dst_ptr); - return 0; + return CMD_RET_SUCCESS; +} + +int cmd_aes_get_slots(void) +{ + struct udevice *dev; + u8 slots; + int ret; + + ret = aes_get_driver(&dev); + if (ret) + return ret; + + slots = dm_aes_get_available_key_slots(dev); + printf("Available slots: %d\n", slots); + + return CMD_RET_SUCCESS; +} + +int cmd_aes_set_key(int argc, char *const argv[], u32 key_len) +{ + struct udevice *dev; + u32 key_addr, slot; + u8 *key_ptr; + int ret; + + if (argc != 4) + return CMD_RET_USAGE; + + ret = aes_get_driver(&dev); + if (ret) + return ret; + + key_addr = hextoul(argv[2], NULL); + slot = hextoul(argv[3], NULL); + + key_ptr = (uint8_t *)map_sysmem(key_addr, key_len); + + ret = dm_aes_set_key_for_key_slot(dev, key_len * 8, key_ptr, slot); + unmap_sysmem(key_ptr); + if (ret) { + printf("Unable to set key at slot: %d\n", ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +int cmd_aes_select_slot(int argc, char *const argv[], u32 key_len) +{ + struct udevice *dev; + u32 slot; + int ret; + + if (argc != 3) + return CMD_RET_USAGE; + + ret = aes_get_driver(&dev); + if (ret) + return ret; + + slot = hextoul(argv[2], NULL); + + ret = dm_aes_select_key_slot(dev, key_len * 8, slot); + if (ret) { + printf("Unable to select key slot: %d\n", ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +int cmd_aes_ecb(int argc, char *const argv[], u32 key_len) +{ + struct udevice *dev; + u32 src_addr, dst_addr, len; + u8 *src_ptr, *dst_ptr; + u32 aes_blocks; + int enc, ret; + + if (argc != 6) + return CMD_RET_USAGE; + + ret = aes_get_driver(&dev); + if (ret) + return ret; + + if (!strncmp(argv[1], "enc", 3)) + enc = 1; + else if (!strncmp(argv[1], "dec", 3)) + enc = 0; + else + return CMD_RET_USAGE; + + src_addr = hextoul(argv[3], NULL); + dst_addr = hextoul(argv[4], NULL); + len = hextoul(argv[5], NULL); + + src_ptr = (uint8_t *)map_sysmem(src_addr, len); + dst_ptr = (uint8_t *)map_sysmem(dst_addr, len); + + /* Calculate the number of AES blocks to encrypt. */ + aes_blocks = DIV_ROUND_UP(len, AES_BLOCK_LENGTH); + + if (enc) + ret = dm_aes_ecb_encrypt(dev, src_ptr, dst_ptr, aes_blocks); + else + ret = dm_aes_ecb_decrypt(dev, src_ptr, dst_ptr, aes_blocks); + + unmap_sysmem(src_ptr); + unmap_sysmem(dst_ptr); + + if (ret) { + printf("Unable to do ecb operation: %d\n", ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +int cmd_aes_cbc(int argc, char *const argv[], u32 key_len) +{ + struct udevice *dev; + u32 iv_addr, src_addr, dst_addr, len; + u8 *iv_ptr, *src_ptr, *dst_ptr; + u32 aes_blocks; + int enc, ret; + + if (argc != 7) + return CMD_RET_USAGE; + + ret = aes_get_driver(&dev); + if (ret) + return ret; + + if (!strncmp(argv[1], "enc", 3)) + enc = 1; + else if (!strncmp(argv[1], "dec", 3)) + enc = 0; + else + return CMD_RET_USAGE; + + iv_addr = hextoul(argv[3], NULL); + src_addr = hextoul(argv[4], NULL); + dst_addr = hextoul(argv[5], NULL); + len = hextoul(argv[6], NULL); + + iv_ptr = (uint8_t *)map_sysmem(iv_addr, AES_BLOCK_LENGTH); + src_ptr = (uint8_t *)map_sysmem(src_addr, len); + dst_ptr = (uint8_t *)map_sysmem(dst_addr, len); + + /* Calculate the number of AES blocks to encrypt. */ + aes_blocks = DIV_ROUND_UP(len, AES_BLOCK_LENGTH); + + if (enc) + ret = dm_aes_cbc_encrypt(dev, iv_ptr, src_ptr, dst_ptr, aes_blocks); + else + ret = dm_aes_cbc_decrypt(dev, iv_ptr, src_ptr, dst_ptr, aes_blocks); + + unmap_sysmem(iv_ptr); + unmap_sysmem(src_ptr); + unmap_sysmem(dst_ptr); + + if (ret) { + printf("Unable to do cbc operation: %d\n", ret); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +/** + * do_aes() - Handle the "aes" command-line command + * @cmdtp: Command data struct pointer + * @flag: Command flag + * @argc: Command-line argument count + * @argv: Array of command-line arguments + * + * Returns zero on success, CMD_RET_USAGE in case of misuse and negative + * on error. + */ +static int do_aes(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + u32 key_len; + + if (argc < 2) + return CMD_RET_USAGE; + + key_len = aes_get_key_len(argv[0]); + + if (!strncmp(argv[1], "enc", 3) || !strncmp(argv[1], "dec", 3)) + return cmd_aes_cbc_simple(argc, argv, key_len); + else if (CONFIG_IS_ENABLED(DM_AES) && !strncmp(argv[1], "get_slots", 9)) + return cmd_aes_get_slots(); + else if (CONFIG_IS_ENABLED(DM_AES) && !strncmp(argv[1], "set_key", 7)) + return cmd_aes_set_key(argc, argv, key_len); + else if (CONFIG_IS_ENABLED(DM_AES) && !strncmp(argv[1], "select_slot", 11)) + return cmd_aes_select_slot(argc, argv, key_len); + else if (CONFIG_IS_ENABLED(DM_AES) && !strncmp(argv[1], "ecb", 3)) + return cmd_aes_ecb(argc, argv, key_len); + else if (CONFIG_IS_ENABLED(DM_AES) && !strncmp(argv[1], "cbc", 3)) + return cmd_aes_cbc(argc, argv, key_len); + else + return CMD_RET_USAGE; } /***************************************************/ U_BOOT_LONGHELP(aes, - "[.128,.192,.256] enc key iv src dst len - Encrypt block of data $len bytes long\n" + "[.128,.192,.256] enc key iv src dst len - CBC encrypt block of data $len bytes long\n" " at address $src using a key at address\n" " $key with initialization vector at address\n" " $iv. Store the result at address $dst.\n" " The $len size must be multiple of 16 bytes.\n" " The $key and $iv must be 16 bytes long.\n" - "aes [.128,.192,.256] dec key iv src dst len - Decrypt block of data $len bytes long\n" + "aes [.128,.192,.256] dec key iv src dst len - CBC decrypt block of data $len bytes long\n" " at address $src using a key at address\n" " $key with initialization vector at address\n" " $iv. Store the result at address $dst.\n" " The $len size must be multiple of 16 bytes.\n" - " The $key and $iv must be 16 bytes long."); + " The $key and $iv must be 16 bytes long." + +#if CONFIG_IS_ENABLED(DM_AES) + "\n" + "aes get_slots - Gives number of available key slots\n" + "aes [.128,.192,.256] set_key key slot - Load key at address $key into the slot $slot\n" + "aes [.128,.192,.256] select_slot slot - Select current active key slot\n" + "aes [.128,.192,.256] ecb enc src dst len - ECB encrypt block of data $len bytes long\n" + " at address $src using a key at current\n" + " slot. Store the result at address $dst.\n" + " The $len size must be multiple of 16 bytes.\n" + "aes [.128,.192,.256] ecb dec src dst len - ECB decrypt block of data $len bytes long\n" + " at address $src using a key at current\n" + " slot. Store the result at address $dst.\n" + " The $len size must be multiple of 16 bytes.\n" + "aes [.128,.192,.256] cbc enc iv src dst len - CBC encrypt block of data $len bytes long\n" + " at address $src using a key at current\n" + " slot with initialization vector at address\n" + " $iv. Store the result at address $dst.\n" + " The $len size must be multiple of 16 bytes.\n" + " The $iv must be 16 bytes long.\n" + "aes [.128,.192,.256] cbc dec iv src dst len - CBC decrypt block of data $len bytes long\n" + " at address $src using a key at current\n" + " slot with initialization vector at address\n" + " $iv. Store the result at address $dst.\n" + " The $len size must be multiple of 16 bytes.\n" + " The $iv must be 16 bytes long." +#endif +); U_BOOT_CMD( aes, 7, 1, do_aes, - "AES 128/192/256 CBC encryption", + "AES 128/192/256 operations", aes_help_text ); diff --git a/cmd/armflash.c b/cmd/armflash.c index e292cf85c45..cde275c881b 100644 --- a/cmd/armflash.c +++ b/cmd/armflash.c @@ -7,8 +7,10 @@ */ #include <command.h> #include <console.h> +#include <env.h> #include <flash.h> #include <vsprintf.h> +#include <linux/string.h> #include <asm/io.h> #define MAX_REGIONS 4 diff --git a/cmd/bcb.c b/cmd/bcb.c index 16eabfe00f5..d6d944bd6b3 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -8,6 +8,7 @@ #include <android_bootloader_message.h> #include <bcb.h> #include <command.h> +#include <env.h> #include <android_ab.h> #include <display_options.h> #include <log.h> diff --git a/cmd/blkmap.c b/cmd/blkmap.c index 86a123b1cd3..65edec899e2 100644 --- a/cmd/blkmap.c +++ b/cmd/blkmap.c @@ -7,6 +7,7 @@ #include <blk.h> #include <blkmap.h> #include <command.h> +#include <env.h> #include <malloc.h> #include <dm/device.h> diff --git a/cmd/bootflow.c b/cmd/bootflow.c index a1fd59a69f4..551dffbb8b8 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -13,6 +13,9 @@ #include <command.h> #include <console.h> #include <dm.h> +#include <env.h> +#include <expo.h> +#include <log.h> #include <mapmem.h> /** @@ -104,24 +107,39 @@ __maybe_unused static int bootflow_handle_menu(struct bootstd_priv *std, bool text_mode, struct bootflow **bflowp) { + struct expo *exp; struct bootflow *bflow; - int ret; + int ret, seq; - ret = bootflow_menu_run(std, text_mode, &bflow); - if (ret) { - if (ret == -EAGAIN) { - printf("Nothing chosen\n"); - std->cur_bootflow = NULL; - } else { - printf("Menu failed (err=%d)\n", ret); + ret = bootflow_menu_start(std, text_mode, &exp); + if (ret) + return log_msg_ret("bhs", ret); + + ret = -ERESTART; + do { + if (ret == -ERESTART) { + ret = expo_render(exp); + if (ret) + return log_msg_ret("bhr", ret); } + ret = bootflow_menu_poll(exp, &seq); + } while (ret == -EAGAIN || ret == -ERESTART); - return ret; + if (ret == -EPIPE) { + printf("Nothing chosen\n"); + std->cur_bootflow = NULL; + } else if (ret) { + printf("Menu failed (err=%d)\n", ret); + } else { + bflow = alist_getw(&std->bootflows, seq, struct bootflow); + printf("Selected: %s\n", bflow->os_name ? bflow->os_name : + bflow->name); + std->cur_bootflow = bflow; + *bflowp = bflow; } - - printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name); - std->cur_bootflow = bflow; - *bflowp = bflow; + expo_destroy(exp); + if (ret) + return ret; return 0; } diff --git a/cmd/booti.c b/cmd/booti.c index 1a57fe91397..e6f67d6e136 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -6,6 +6,7 @@ #include <bootm.h> #include <command.h> +#include <env.h> #include <image.h> #include <irq_func.h> #include <lmb.h> @@ -29,6 +30,7 @@ static int booti_start(struct bootm_info *bmi) uint8_t *temp; ulong dest; ulong dest_end; + phys_addr_t ep_addr; unsigned long comp_len; unsigned long decomp_len; int ctype; @@ -87,7 +89,14 @@ static int booti_start(struct bootm_info *bmi) images->os.start = relocated_addr; images->os.end = relocated_addr + image_size; - lmb_reserve(images->ep, le32_to_cpu(image_size), LMB_NONE); + ep_addr = (phys_addr_t)images->ep; + ret = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &ep_addr, + le32_to_cpu(image_size), LMB_NONE); + if (ret) { + printf("Failed to allocate memory for the image at %#llx\n", + (unsigned long long)images->ep); + return 1; + } /* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index a5c979079f4..d3108778c6f 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -114,6 +114,14 @@ static char *bootmenu_choice_entry(void *data) ++menu->active; /* no menu key selected, regenerate menu */ return NULL; + case BKEY_SHORTCUT: + /* invalid shortcut, regenerate menu */ + if (cch->shortcut_key >= menu->count - 1) + return NULL; + /* shortcut_key value for Exit is is -1 */ + menu->active = cch->shortcut_key < 0 ? menu->count - 1 : + cch->shortcut_key; + fallthrough; case BKEY_SELECT: iter = menu->first; for (i = 0; i < menu->active; ++i) @@ -161,6 +169,21 @@ static void bootmenu_destroy(struct bootmenu_data *menu) free(menu); } +static char bootmenu_entry_shortcut_key(int index) +{ + switch (index) { + /* 1-9 shortcut key (0 reserved) */ + case 0 ... 8: + return '1' + index; + /* a-z shortcut key */ + case 9 ... 34: + return 'a' + index - 9; + /* We support shortcut for up to 34 options (0 reserved) */ + default: + return -ENOENT; + } +} + /** * prepare_bootmenu_entry() - generate the bootmenu_xx entries * @@ -184,6 +207,8 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, struct bootmenu_entry *iter = *current; while ((option = bootmenu_getoption(i))) { + char shortcut_key; + int len; /* bootmenu_[num] format is "[title]=[commands]" */ sep = strchr(option, '='); @@ -196,12 +221,22 @@ static int prepare_bootmenu_entry(struct bootmenu_data *menu, if (!entry) return -ENOMEM; - entry->title = strndup(option, sep - option); + /* Add shotcut key option: %c. %s\0 */ + len = sep - option + 4; + + entry->title = malloc(len); if (!entry->title) { free(entry); return -ENOMEM; } + shortcut_key = bootmenu_entry_shortcut_key(i); + /* Use emtpy space if entry doesn't support shortcut key */ + snprintf(entry->title, len, "%c%c %s", + shortcut_key > 0 ? shortcut_key : ' ', + shortcut_key > 0 ? '.' : ' ', + option); + entry->command = strdup(sep + 1); if (!entry->command) { free(entry->title); @@ -388,9 +423,9 @@ static struct bootmenu_data *bootmenu_create(int uefi, int delay) /* Add Quit entry if exiting bootmenu is disabled */ if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE)) - entry->title = strdup("Exit"); + entry->title = strdup("0. Exit"); else - entry->title = strdup("Quit"); + entry->title = strdup("0. Quit"); if (!entry->title) { free(entry); diff --git a/cmd/bootmeth.c b/cmd/bootmeth.c index 2f41fa1bec6..ea4b3f47db8 100644 --- a/cmd/bootmeth.c +++ b/cmd/bootmeth.c @@ -11,6 +11,7 @@ #include <bootstd.h> #include <command.h> #include <dm.h> +#include <env.h> #include <malloc.h> #include <dm/uclass-internal.h> diff --git a/cmd/bootstage.c b/cmd/bootstage.c index 8248c41ca82..5c6d5a3ab45 100644 --- a/cmd/bootstage.c +++ b/cmd/bootstage.c @@ -6,6 +6,7 @@ #include <bootstage.h> #include <command.h> #include <vsprintf.h> +#include <linux/string.h> static int do_bootstage_report(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/bootz.c b/cmd/bootz.c index 99318ff213f..44af7d012aa 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -28,6 +28,7 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, { ulong zi_start, zi_end; struct bootm_info bmi; + phys_addr_t ep_addr; int ret; bootm_init(&bmi); @@ -56,7 +57,14 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, if (ret != 0) return 1; - lmb_reserve(images->ep, zi_end - zi_start, LMB_NONE); + ep_addr = (phys_addr_t)images->ep; + ret = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &ep_addr, zi_end - zi_start, + LMB_NONE); + if (ret) { + printf("Failed to allocate memory for the image at %#llx\n", + (unsigned long long)images->ep); + return 1; + } /* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not diff --git a/cmd/broadcom/nitro_image_load.c b/cmd/broadcom/nitro_image_load.c index 289b184e9af..fe08679840e 100644 --- a/cmd/broadcom/nitro_image_load.c +++ b/cmd/broadcom/nitro_image_load.c @@ -4,6 +4,7 @@ */ #include <command.h> +#include <env.h> #include <vsprintf.h> #define FW_IMAGE_SIG 0xff123456 diff --git a/cmd/cache.c b/cmd/cache.c index 3049f5c305f..b7007877ab0 100644 --- a/cmd/cache.c +++ b/cmd/cache.c @@ -10,6 +10,7 @@ #include <command.h> #include <cpu_func.h> #include <linux/compiler.h> +#include <linux/string.h> static int parse_argv(const char *); diff --git a/cmd/cat.c b/cmd/cat.c index 6828b7b364e..3167cda6032 100644 --- a/cmd/cat.c +++ b/cmd/cat.c @@ -8,6 +8,7 @@ #include <fs.h> #include <malloc.h> #include <mapmem.h> +#include <linux/errno.h> static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/cedit.c b/cmd/cedit.c index f696356419e..20f48ae0007 100644 --- a/cmd/cedit.c +++ b/cmd/cedit.c @@ -287,6 +287,8 @@ static int do_cedit_run(struct cmd_tbl *cmdtp, int flag, int argc, log_err("Failed (err=%dE)\n", ret); return CMD_RET_FAILURE; } + expo_destroy(cur_exp); + cur_exp = NULL; return 0; } diff --git a/cmd/diag.c b/cmd/diag.c index c6da5aae3fc..4a88ab00a07 100644 --- a/cmd/diag.c +++ b/cmd/diag.c @@ -9,6 +9,7 @@ */ #include <command.h> #include <post.h> +#include <linux/string.h> int do_diag(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -9,6 +9,7 @@ #include <command.h> #include <dm/root.h> #include <dm/util.h> +#include <linux/string.h> static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) diff --git a/cmd/echo.c b/cmd/echo.c index 973213a03a6..d1346504cfb 100644 --- a/cmd/echo.c +++ b/cmd/echo.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <linux/string.h> static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 6e14d34a6bd..8ac0fb98e02 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -35,6 +35,7 @@ static int avail_row; #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 +#define EFICONFIG_URI_MAX 512 #define EFICONFIG_MENU_HEADER_ROW_NUM 3 #define EFICONFIG_MENU_DESC_ROW_NUM 5 @@ -539,6 +540,40 @@ struct efi_device_path *eficonfig_create_device_path(struct efi_device_path *dp_ } /** + * eficonfig_create_uri_device_path() - Create an URI based device path + * @uri_str: URI string to be added to the device path + * + * Take the u16 string, convert it to a u8 string, and create a URI + * device path. This will be used for the EFI HTTP boot. + * + * Return: pointer to the URI device path on success, NULL on failure + */ +static struct efi_device_path *eficonfig_create_uri_device_path(u16 *uri_str) +{ + char *pos, *p; + u32 len = 0; + efi_uintn_t uridp_len; + struct efi_device_path_uri *uridp; + + len = utf16_utf8_strlen(uri_str); + + uridp_len = sizeof(struct efi_device_path) + len + 1; + uridp = efi_alloc(uridp_len + sizeof(EFI_DP_END)); + if (!uridp) + return NULL; + + uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; + uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; + uridp->dp.length = uridp_len; + p = (char *)&uridp->uri; + utf16_utf8_strcpy(&p, uri_str); + pos = (char *)uridp + uridp_len; + memcpy(pos, &EFI_DP_END, sizeof(EFI_DP_END)); + + return &uridp->dp; +} + +/** * eficonfig_file_selected() - handler of file selection * * @data: pointer to the data of selected entry @@ -984,6 +1019,22 @@ static efi_status_t eficonfig_boot_add_optional_data(void *data) } /** + * eficonfig_boot_add_uri() - handle user input for HTTP Boot URI + * + * @data: pointer to the internal boot option structure + * Return: status code + */ +static efi_status_t eficonfig_boot_add_uri(void *data) +{ + struct eficonfig_select_file_info *file_info = data; + + return handle_user_input(file_info->uri, EFICONFIG_URI_MAX, 24, + "\n ** Edit URI **\n" + "\n" + " enter HTTP Boot URI:"); +} + +/** * eficonfig_boot_edit_save() - handler to save the boot option * * @data: pointer to the internal boot option structure @@ -998,7 +1049,8 @@ static efi_status_t eficonfig_boot_edit_save(void *data) bo->edit_completed = false; return EFI_NOT_READY; } - if (u16_strlen(bo->file_info.current_path) == 0) { + if (u16_strlen(bo->file_info.current_path) == 0 && + u16_strlen(bo->file_info.uri) == 0) { eficonfig_print_msg("File is not selected!"); bo->edit_completed = false; return EFI_NOT_READY; @@ -1024,9 +1076,19 @@ efi_status_t eficonfig_process_clear_file_selection(void *data) file_info->current_path[0] = u'\0'; file_info->dp_volume = NULL; + if (file_info->uri) + file_info->uri[0] = u'\0'; + return EFI_ABORTED; } +static struct eficonfig_item select_boot_file_menu_items[] = { + {"Select File", eficonfig_process_select_file}, + {"Enter URI", eficonfig_boot_add_uri}, + {"Clear", eficonfig_process_clear_file_selection}, + {"Quit", eficonfig_process_quit}, +}; + static struct eficonfig_item select_file_menu_items[] = { {"Select File", eficonfig_process_select_file}, {"Clear", eficonfig_process_clear_file_selection}, @@ -1042,16 +1104,30 @@ static struct eficonfig_item select_file_menu_items[] = { efi_status_t eficonfig_process_show_file_option(void *data) { efi_status_t ret; + unsigned int menu_count; struct efimenu *efi_menu; + struct eficonfig_item *menu_items; + struct eficonfig_select_file_info *file_info = data; + + menu_items = file_info->uri ? select_boot_file_menu_items : + select_file_menu_items; + + menu_count = file_info->uri ? + ARRAY_SIZE(select_boot_file_menu_items) : + ARRAY_SIZE(select_file_menu_items); + + menu_items[0].data = data; + menu_items[1].data = data; + menu_items[2].data = data; - select_file_menu_items[0].data = data; - select_file_menu_items[1].data = data; - efi_menu = eficonfig_create_fixed_menu(select_file_menu_items, - ARRAY_SIZE(select_file_menu_items)); + efi_menu = eficonfig_create_fixed_menu(menu_items, menu_count); if (!efi_menu) return EFI_OUT_OF_RESOURCES; - ret = eficonfig_process_common(efi_menu, " ** Update File **", + ret = eficonfig_process_common(efi_menu, + file_info->uri ? + " ** Update File/URI **" : + " ** Update File **", eficonfig_menu_desc, eficonfig_display_statusline, eficonfig_print_entry, @@ -1121,6 +1197,14 @@ out: file_info->current_path[len] = u'\0'; file_info->current_volume = tmp->current_volume; file_info->dp_volume = tmp->dp_volume; + + /* + * File being selected, set the URI string to + * null so that the file gets picked as the + * boot image. + */ + if (file_info->uri) + file_info->uri[0] = u'\0'; } list_for_each_safe(pos, n, &tmp->filepath_list) { @@ -1224,6 +1308,12 @@ static efi_status_t prepare_file_selection_entry(struct efimenu *efi_menu, char efi_handle_t handle; char *devname; + /* Check for URI based boot file */ + if (file_info->uri && utf16_utf8_strlen(file_info->uri)) + return create_boot_option_entry(efi_menu, title, file_info->uri, + eficonfig_process_show_file_option, + file_info); + devname = calloc(1, EFICONFIG_VOLUME_PATH_MAX + 1); if (!devname) return EFI_OUT_OF_RESOURCES; @@ -1341,6 +1431,27 @@ out: } /** + * fill_dp_uri() - copy the URI string in the device path + * @dp: pointer to the URI device path + * @uri_str: URI string to be copied + * + * Copy the passed URI string to the URI device path. This + * requires utf8_utf16_strcpy() to copy the u16 string to + * the u8 array in the device path structure. + * + * Return: None + */ +static void fill_dp_uri(struct efi_device_path *dp, u16 **uri_str) +{ + u16 *p = *uri_str; + struct efi_device_path_uri *uridp; + + uridp = (struct efi_device_path_uri *)dp; + + utf8_utf16_strcpy(&p, uridp->uri); +} + +/** * fill_file_info() - fill the file info from efi_device_path structure * * @dp: pointer to the device path @@ -1392,10 +1503,13 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo size_t len; efi_status_t ret; char *tmp = NULL, *p; + u16 *current_path = NULL; struct efi_load_option lo = {0}; efi_uintn_t dp_size; struct efi_device_path *dp = NULL; efi_uintn_t size = load_option_size; + struct efi_device_path *dp_volume = NULL; + struct efi_device_path *uri_dp = NULL; struct efi_device_path *device_dp = NULL; struct efi_device_path *initrd_dp = NULL; struct efi_device_path *fdt_dp = NULL; @@ -1464,6 +1578,12 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo goto out; } + bo->file_info.uri = calloc(1, EFICONFIG_URI_MAX * sizeof(u16)); + if (!bo->file_info.uri) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + /* copy the preset value */ if (load_option) { ret = efi_deserialize_load_option(&lo, load_option, &size); @@ -1481,7 +1601,10 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo u16_strcpy(bo->description, lo.label); /* EFI image file path is a first instance */ - if (lo.file_path) + if (lo.file_path && EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, + MSG_URI)) + fill_dp_uri(lo.file_path, &bo->file_info.uri); + else if (lo.file_path) fill_file_info(lo.file_path, &bo->file_info, device_dp); /* Initrd file path (optional) is placed at second instance. */ @@ -1512,6 +1635,9 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo goto out; } + if (utf16_utf8_strlen(bo->file_info.uri)) + uri_dp = eficonfig_create_uri_device_path(bo->file_info.uri); + if (bo->initrd_info.dp_volume) { dp = eficonfig_create_device_path(bo->initrd_info.dp_volume, bo->initrd_info.current_path); @@ -1536,7 +1662,10 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo efi_free_pool(dp); } - dp = eficonfig_create_device_path(bo->file_info.dp_volume, bo->file_info.current_path); + dp_volume = bo->file_info.dp_volume; + current_path = bo->file_info.current_path; + dp = uri_dp ? + uri_dp : eficonfig_create_device_path(dp_volume, current_path); if (!dp) { ret = EFI_OUT_OF_RESOURCES; goto out; @@ -1560,6 +1689,7 @@ out: free(tmp); free(bo->optional_data); free(bo->description); + free(bo->file_info.uri); free(bo->file_info.current_path); free(bo->initrd_info.current_path); free(bo->fdt_info.current_path); diff --git a/cmd/elf.c b/cmd/elf.c index 6b49c613703..5e0ee30a7c8 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -247,7 +247,7 @@ int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) ptr += sprintf(build_buf + ptr, "e=%s", tmp); tmp = env_get("netmask"); if (tmp) { - u32 mask = env_get_ip("netmask").s_addr; + u32 mask = string_to_ip(tmp).s_addr; ptr += sprintf(build_buf + ptr, ":%08x ", ntohl(mask)); } else { diff --git a/cmd/extension_board.c b/cmd/extension_board.c index 6c14d0ddebd..317b260bf36 100644 --- a/cmd/extension_board.c +++ b/cmd/extension_board.c @@ -7,6 +7,7 @@ #include <bootdev.h> #include <command.h> #include <dm.h> +#include <env.h> #include <malloc.h> #include <extension_board.h> #include <mapmem.h> diff --git a/cmd/fdt.c b/cmd/fdt.c index d16b141ce32..a67c30b21d5 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -691,9 +691,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) fdt_strerror(err)); return CMD_RET_FAILURE; } -#ifdef CONFIG_ARCH_KEYSTONE - ft_board_setup_ex(working_fdt, gd->bd); -#endif + + if (IS_ENABLED(CONFIG_OF_BOARD_SETUP_EXTENDED)) + ft_board_setup_ex(working_fdt, gd->bd); } #endif /* Create a chosen node */ diff --git a/cmd/flash.c b/cmd/flash.c index fd660ec477c..76aa387ba59 100644 --- a/cmd/flash.c +++ b/cmd/flash.c @@ -10,6 +10,7 @@ #include <command.h> #include <log.h> #include <vsprintf.h> +#include <linux/string.h> #include <u-boot/uuid.h> #if defined(CONFIG_CMD_MTDPARTS) diff --git a/cmd/fuse.c b/cmd/fuse.c index 6c42c096809..e2206cdf0d5 100644 --- a/cmd/fuse.c +++ b/cmd/fuse.c @@ -14,6 +14,7 @@ #include <mapmem.h> #include <vsprintf.h> #include <linux/errno.h> +#include <linux/string.h> static int confirm_prog(void) { diff --git a/cmd/hash.c b/cmd/hash.c index 5b40982b098..96d0e443a5b 100644 --- a/cmd/hash.c +++ b/cmd/hash.c @@ -10,6 +10,7 @@ */ #include <command.h> +#include <env.h> #include <hash.h> #include <linux/ctype.h> diff --git a/cmd/help.c b/cmd/help.c index 56579e28d31..1be83ba607d 100644 --- a/cmd/help.c +++ b/cmd/help.c @@ -9,13 +9,9 @@ static int do_help(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { -#ifdef CONFIG_CMDLINE struct cmd_tbl *start = ll_entry_start(struct cmd_tbl, cmd); const int len = ll_entry_count(struct cmd_tbl, cmd); return _do_help(start, len, cmdtp, flag, argc, argv); -#else - return 0; -#endif } U_BOOT_CMD( @@ -27,7 +23,6 @@ U_BOOT_CMD( " - print detailed usage of 'command'" ); -#ifdef CONFIG_CMDLINE /* * This does not use the U_BOOT_CMD macro as ? can't be used in symbol names * nor can we rely on the CONFIG_SYS_LONGHELP helper macro @@ -39,4 +34,3 @@ ll_entry_declare(struct cmd_tbl, question_mark, cmd) = { "" #endif /* CONFIG_SYS_LONGHELP */ }; -#endif diff --git a/cmd/ide.c b/cmd/ide.c index 036489fda97..ed30f946866 100644 --- a/cmd/ide.c +++ b/cmd/ide.c @@ -19,7 +19,6 @@ #include <dm/device-internal.h> #include <dm/uclass-internal.h> -#include <ide.h> #include <ata.h> #ifdef CONFIG_LED_STATUS diff --git a/cmd/irq.c b/cmd/irq.c index da223b4b2cc..58483d04de8 100644 --- a/cmd/irq.c +++ b/cmd/irq.c @@ -6,6 +6,7 @@ #include <config.h> #include <command.h> #include <irq_func.h> +#include <linux/string.h> static int do_interrupts(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/legacy-mtd-utils.c b/cmd/legacy-mtd-utils.c index 1a5271000bf..34a6da01947 100644 --- a/cmd/legacy-mtd-utils.c +++ b/cmd/legacy-mtd-utils.c @@ -4,7 +4,6 @@ #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/string.h> -#include <mtd.h> static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size, loff_t *maxsize, int devtype) diff --git a/cmd/legacy_led.c b/cmd/legacy_led.c index 50de7e89d8f..db312ae6e2d 100644 --- a/cmd/legacy_led.c +++ b/cmd/legacy_led.c @@ -12,6 +12,7 @@ #include <command.h> #include <status_led.h> #include <vsprintf.h> +#include <linux/string.h> struct led_tbl_s { char *string; /* String for use in the command */ diff --git a/cmd/load.c b/cmd/load.c index 899bb4f598e..159767aa7f7 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -178,17 +178,20 @@ static ulong load_serial(long offset) #endif { void *dst; + phys_addr_t dst_addr; - ret = lmb_reserve(store_addr, binlen, LMB_NONE); + dst_addr = (phys_addr_t)store_addr; + ret = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &dst_addr, + binlen, LMB_NONE); if (ret) { printf("\nCannot overwrite reserved area (%08lx..%08lx)\n", store_addr, store_addr + binlen); return ret; } - dst = map_sysmem(store_addr, binlen); + dst = map_sysmem(dst_addr, binlen); memcpy(dst, binbuf, binlen); unmap_sysmem(dst); - lmb_free(store_addr, binlen); + lmb_free(dst_addr, binlen, LMB_NONE); } if ((store_addr) < start_addr) start_addr = store_addr; diff --git a/cmd/lwip/Makefile b/cmd/lwip/Makefile new file mode 100644 index 00000000000..a7f8976af3f --- /dev/null +++ b/cmd/lwip/Makefile @@ -0,0 +1,6 @@ +obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_DNS) += dns.o +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_SNTP) += sntp.o +obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o +obj-$(CONFIG_CMD_WGET) += wget.o diff --git a/cmd/lwip/dhcp.c b/cmd/lwip/dhcp.c new file mode 100644 index 00000000000..3894d71f654 --- /dev/null +++ b/cmd/lwip/dhcp.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024-2025 Linaro Ltd. */ + +#include <command.h> +#include <net.h> + +U_BOOT_CMD(dhcp, 3, 1, do_dhcp, + "boot image via network using DHCP/TFTP protocol", + "[loadAddress] [[hostIPaddr:]bootfilename]"); diff --git a/cmd/lwip/dns.c b/cmd/lwip/dns.c new file mode 100644 index 00000000000..b5fccc7433e --- /dev/null +++ b/cmd/lwip/dns.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include <command.h> +#include <console.h> +#include <env.h> +#include <lwip/dns.h> +#include <lwip/timeouts.h> +#include <net.h> +#include <time.h> + +U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname", + "hostname [envvar]"); + +#define DNS_RESEND_MS 1000 +#define DNS_TIMEOUT_MS 10000 + +struct dns_cb_arg { + ip_addr_t host_ipaddr; + const char *var; + bool done; +}; + +static void do_dns_tmr(void *arg) +{ + dns_tmr(); +} + +static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg) +{ + struct dns_cb_arg *dns_cb_arg = arg; + char *ipstr = ip4addr_ntoa(ipaddr); + + dns_cb_arg->done = true; + + if (!ipaddr) { + printf("DNS: host not found\n"); + dns_cb_arg->host_ipaddr.addr = 0; + return; + } + + dns_cb_arg->host_ipaddr.addr = ipaddr->addr; + + if (dns_cb_arg->var) + env_set(dns_cb_arg->var, ipstr); +} + +static int dns_loop(struct udevice *udev, const char *name, const char *var) +{ + struct dns_cb_arg dns_cb_arg = { }; + struct netif *netif; + ip_addr_t ipaddr; + ulong start; + int ret; + + dns_cb_arg.var = var; + + netif = net_lwip_new_netif(udev); + if (!netif) + return CMD_RET_FAILURE; + + if (net_lwip_dns_init()) { + net_lwip_remove_netif(netif); + return CMD_RET_FAILURE; + } + + dns_cb_arg.done = false; + + ret = dns_gethostbyname(name, &ipaddr, dns_cb, &dns_cb_arg); + + if (ret == ERR_OK) { + dns_cb(name, &ipaddr, &dns_cb_arg); + } else if (ret == ERR_INPROGRESS) { + start = get_timer(0); + sys_timeout(DNS_RESEND_MS, do_dns_tmr, NULL); + do { + net_lwip_rx(udev, netif); + if (dns_cb_arg.done) + break; + if (ctrlc()) { + printf("\nAbort\n"); + break; + } + } while (get_timer(start) < DNS_TIMEOUT_MS); + sys_untimeout(do_dns_tmr, NULL); + } + + net_lwip_remove_netif(netif); + + if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) { + if (!var) + printf("%s\n", ipaddr_ntoa(&ipaddr)); + return CMD_RET_SUCCESS; + } + + return CMD_RET_FAILURE; +} + +int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + char *name; + char *var = NULL; + + if (argc == 1 || argc > 3) + return CMD_RET_USAGE; + + name = argv[1]; + + if (argc == 3) + var = argv[2]; + + if (net_lwip_eth_start() < 0) + return CMD_RET_FAILURE; + + return dns_loop(eth_get_dev(), name, var); +} diff --git a/cmd/lwip/ping.c b/cmd/lwip/ping.c new file mode 100644 index 00000000000..87f8e958e48 --- /dev/null +++ b/cmd/lwip/ping.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include <command.h> +#include <console.h> +#include <dm/device.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <lwip/icmp.h> +#include <lwip/inet_chksum.h> +#include <lwip/raw.h> +#include <lwip/timeouts.h> +#include <net.h> +#include <time.h> + +U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host", + "pingAddressOrHostName"); + +#define PING_DELAY_MS 1000 +#define PING_COUNT 5 +/* Ping identifier - must fit on a u16_t */ +#define PING_ID 0xAFAF + +struct ping_ctx { + ip_addr_t target; + struct raw_pcb *pcb; + struct icmp_echo_hdr *iecho; + uint16_t seq_num; + bool alive; +}; + +static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, + const ip_addr_t *addr) +{ + struct ping_ctx *ctx = arg; + struct icmp_echo_hdr *iecho = ctx->iecho; + + if (addr->addr != ctx->target.addr) + return 0; + + if ((p->tot_len >= (IP_HLEN + sizeof(struct icmp_echo_hdr))) && + pbuf_remove_header(p, IP_HLEN) == 0) { + iecho = (struct icmp_echo_hdr *)p->payload; + + if (iecho->id == PING_ID && + iecho->seqno == lwip_htons(ctx->seq_num)) { + ctx->alive = true; + printf("host %s is alive\n", ipaddr_ntoa(addr)); + pbuf_free(p); + return 1; /* eat the packet */ + } + /* not eaten, restore original packet */ + pbuf_add_header(p, IP_HLEN); + } + + return 0; /* don't eat the packet */ +} + +static int ping_raw_init(struct ping_ctx *ctx) +{ + ctx->pcb = raw_new(IP_PROTO_ICMP); + if (!ctx->pcb) + return -ENOMEM; + + raw_recv(ctx->pcb, ping_recv, ctx); + raw_bind(ctx->pcb, IP_ADDR_ANY); + + return 0; +} + +static void ping_raw_stop(struct ping_ctx *ctx) +{ + if (ctx->pcb) + raw_remove(ctx->pcb); +} + +static void ping_prepare_echo(struct ping_ctx *ctx) +{ + struct icmp_echo_hdr *iecho = ctx->iecho; + + ICMPH_TYPE_SET(iecho, ICMP_ECHO); + ICMPH_CODE_SET(iecho, 0); + iecho->chksum = 0; + iecho->id = PING_ID; + iecho->seqno = lwip_htons(ctx->seq_num); + + iecho->chksum = inet_chksum(iecho, sizeof(*iecho)); +} + +static void ping_send_icmp(struct ping_ctx *ctx) +{ + struct pbuf *p; + size_t ping_size = sizeof(struct icmp_echo_hdr); + + p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM); + if (!p) + return; + + if (p->len == p->tot_len && !p->next) { + ctx->iecho = (struct icmp_echo_hdr *)p->payload; + ping_prepare_echo(ctx); + raw_sendto(ctx->pcb, p, &ctx->target); + } + + pbuf_free(p); +} + +static void ping_send(void *arg) +{ + struct ping_ctx *ctx = arg; + + ctx->seq_num++; + if (ctx->seq_num <= PING_COUNT) { + ping_send_icmp(ctx); + sys_timeout(PING_DELAY_MS, ping_send, ctx); + } +} + +static int ping_loop(struct udevice *udev, const ip_addr_t *addr) +{ + struct ping_ctx ctx = {}; + struct netif *netif; + int ret; + + netif = net_lwip_new_netif(udev); + if (!netif) + return -ENODEV; + + printf("Using %s device\n", udev->name); + + ret = ping_raw_init(&ctx); + if (ret < 0) { + net_lwip_remove_netif(netif); + return ret; + } + + ctx.target = *addr; + + ping_send(&ctx); + + do { + net_lwip_rx(udev, netif); + if (ctx.alive) + break; + if (ctrlc()) { + printf("\nAbort\n"); + break; + } + } while (ctx.seq_num <= PING_COUNT); + + sys_untimeout(ping_send, &ctx); + ping_raw_stop(&ctx); + + net_lwip_remove_netif(netif); + + if (ctx.alive) + return 0; + + printf("ping failed; host %s is not alive\n", ipaddr_ntoa(addr)); + return -1; +} + +int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + ip_addr_t addr; + + if (argc < 2) + return CMD_RET_USAGE; + + if (net_lwip_dns_resolve(argv[1], &addr)) + return CMD_RET_USAGE; + +restart: + if (net_lwip_eth_start() < 0 || ping_loop(eth_get_dev(), &addr) < 0) { + if (net_start_again() == 0) + goto restart; + else + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} diff --git a/cmd/lwip/sntp.c b/cmd/lwip/sntp.c new file mode 100644 index 00000000000..ae02bb11040 --- /dev/null +++ b/cmd/lwip/sntp.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2025 Linaro Ltd. */ + +#include <command.h> +#include <console.h> +#include <dm/device.h> +#include <env.h> +#include <lwip/apps/sntp.h> +#include <lwip/timeouts.h> +#include <net.h> + +U_BOOT_CMD(sntp, 2, 1, do_sntp, "synchronize RTC via network", + "[NTPServerNameOrIp]"); + +#define SNTP_TIMEOUT 10000 + +static enum done_state { + NOT_DONE = 0, + SUCCESS, + ABORTED, + TIMED_OUT +} sntp_state; + +static void no_response(void *arg) +{ + sntp_state = TIMED_OUT; +} + +/* Called by lwIP via the SNTP_SET_SYSTEM_TIME() macro */ +void sntp_set_system_time(uint32_t seconds) +{ + char *toff; + int net_ntp_time_offset = 0; + + toff = env_get("timeoffset"); + if (toff) + net_ntp_time_offset = simple_strtol(toff, NULL, 10); + + net_sntp_set_rtc(seconds + net_ntp_time_offset); + sntp_state = SUCCESS; +} + +static bool ntp_server_known(void) +{ + int i; + + for (i = 0; i < SNTP_MAX_SERVERS; i++) { + const ip_addr_t *ip = sntp_getserver(i); + + if (ip && ip->addr) + return true; + } + + return false; +} + +static int sntp_loop(struct udevice *udev, ip_addr_t *srvip) +{ + struct netif *netif; + + netif = net_lwip_new_netif(udev); + if (!netif) + return -1; + + sntp_state = NOT_DONE; + + sntp_setoperatingmode(SNTP_OPMODE_POLL); + sntp_servermode_dhcp(CONFIG_IS_ENABLED(CMD_DHCP)); + if (srvip) { + sntp_setserver(0, srvip); + } else { + if (!ntp_server_known()) { + log_err("error: ntpserverip not set\n"); + return -1; + } + } + sntp_init(); + + sys_timeout(SNTP_TIMEOUT, no_response, NULL); + while (sntp_state == NOT_DONE) { + net_lwip_rx(udev, netif); + sys_check_timeouts(); + if (ctrlc()) { + printf("\nAbort\n"); + sntp_state = ABORTED; + break; + } + } + sys_untimeout(no_response, NULL); + + sntp_stop(); + net_lwip_remove_netif(netif); + + if (sntp_state == SUCCESS) + return 0; + + return -1; +} + +int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + ip_addr_t *srvip; + char *server; + ip_addr_t ipaddr; + + switch (argc) { + case 1: + srvip = NULL; + server = env_get("ntpserverip"); + if (server) { + if (!ipaddr_aton(server, &ipaddr)) { + printf("ntpserverip is invalid\n"); + return CMD_RET_FAILURE; + } + srvip = &ipaddr; + } + break; + case 2: + if (net_lwip_dns_resolve(argv[1], &ipaddr)) + return CMD_RET_FAILURE; + srvip = &ipaddr; + break; + default: + return CMD_RET_USAGE; + } + + if (net_lwip_eth_start() < 0) + return CMD_RET_FAILURE; + + if (sntp_loop(eth_get_dev(), srvip) < 0) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} diff --git a/cmd/lwip/tftp.c b/cmd/lwip/tftp.c new file mode 100644 index 00000000000..6bb7a3733a2 --- /dev/null +++ b/cmd/lwip/tftp.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024-2025 Linaro Ltd. */ + +#include <command.h> +#include <net.h> + +U_BOOT_CMD(tftpboot, 3, 0, do_tftpb, + "boot image via network using TFTP protocol", + "[loadAddress] [[hostIPaddr:]bootfilename]"); diff --git a/cmd/lwip/wget.c b/cmd/lwip/wget.c new file mode 100644 index 00000000000..fc9bc11cd83 --- /dev/null +++ b/cmd/lwip/wget.c @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024-2025 Linaro Ltd. */ + +#include <command.h> +#include <env.h> +#include <image.h> +#include <net.h> +#include <lwip/altcp_tls.h> + +U_BOOT_CMD(wget, 4, 1, do_wget, + "boot image via network using HTTP/HTTPS protocol" +#if defined(CONFIG_WGET_CACERT) + "\nwget cacert - configure wget root certificates" +#endif + , + "[loadAddress] url\n" + "wget [loadAddress] [host:]path\n" + " - load file" +#if defined(CONFIG_WGET_CACERT) + "\nwget cacert <address> <length>\n" + " - provide CA certificates (0 0 to remove current)" + "\nwget cacert none|optional|required\n" + " - set server certificate verification mode (default: optional)" +#if defined(CONFIG_WGET_BUILTIN_CACERT) + "\nwget cacert builtin\n" + " - use the builtin CA certificates" +#endif +#endif +); + +#if CONFIG_IS_ENABLED(WGET_CACERT) || CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT) +char *cacert; +size_t cacert_size; +enum auth_mode cacert_auth_mode = AUTH_OPTIONAL; + +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT) +extern const char builtin_cacert[]; +extern const size_t builtin_cacert_size; +bool cacert_initialized; +#endif + +static int _set_cacert(const void *addr, size_t sz) +{ + mbedtls_x509_crt crt; + void *p; + int ret; + + if (cacert) + free(cacert); + + if (!addr) { + cacert = NULL; + cacert_size = 0; + return CMD_RET_SUCCESS; + } + + p = malloc(sz); + if (!p) + return CMD_RET_FAILURE; + cacert = p; + cacert_size = sz; + + memcpy(cacert, (void *)addr, sz); + + mbedtls_x509_crt_init(&crt); + ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size); + if (ret) { + if (!wget_info->silent) + printf("Could not parse certificates (%d)\n", ret); + free(cacert); + cacert = NULL; + cacert_size = 0; + return CMD_RET_FAILURE; + } + +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT) + cacert_initialized = true; +#endif + return CMD_RET_SUCCESS; +} + +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT) +int set_cacert_builtin(void) +{ + cacert_auth_mode = AUTH_REQUIRED; + return _set_cacert(builtin_cacert, builtin_cacert_size); +} +#endif +#endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */ + +#if CONFIG_IS_ENABLED(WGET_CACERT) +static int set_auth(enum auth_mode auth) +{ + cacert_auth_mode = auth; + + return CMD_RET_SUCCESS; +} + +static int set_cacert(char * const saddr, char * const ssz) +{ + ulong addr, sz; + + addr = hextoul(saddr, NULL); + sz = hextoul(ssz, NULL); + + return _set_cacert((void *)addr, sz); +} +#endif + +/* + * Legacy syntax support + * Convert [<server_name_or_ip>:]filename into a URL if needed + */ +static int parse_legacy_arg(char *arg, char *nurl, size_t rem) +{ + char *p = nurl; + size_t n; + char *col = strchr(arg, ':'); + char *env; + char *server; + char *path; + + if (strstr(arg, "http") == arg) { + n = snprintf(nurl, rem, "%s", arg); + if (n < 0 || n > rem) + return -1; + return 0; + } + + n = snprintf(p, rem, "%s", "http://"); + if (n < 0 || n > rem) + return -1; + p += n; + rem -= n; + + if (col) { + n = col - arg; + server = arg; + path = col + 1; + } else { + env = env_get("httpserverip"); + if (!env) + env = env_get("serverip"); + if (!env) { + log_err("error: httpserver/serverip has to be set\n"); + return -1; + } + n = strlen(env); + server = env; + path = arg; + } + + if (rem < n) + return -1; + strncpy(p, server, n); + p += n; + rem -= n; + if (rem < 1) + return -1; + *p = '/'; + p++; + rem--; + n = strlen(path); + if (rem < n) + return -1; + strncpy(p, path, n); + p += n; + rem -= n; + if (rem < 1) + return -1; + *p = '\0'; + + return 0; +} + +int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + char *end; + char *url; + ulong dst_addr; + char nurl[1024]; + +#if CONFIG_IS_ENABLED(WGET_CACERT) + if (argc == 4 && !strncmp(argv[1], "cacert", strlen("cacert"))) + return set_cacert(argv[2], argv[3]); + if (argc == 3 && !strncmp(argv[1], "cacert", strlen("cacert"))) { +#if CONFIG_IS_ENABLED(WGET_BUILTIN_CACERT) + if (!strncmp(argv[2], "builtin", strlen("builtin"))) + return set_cacert_builtin(); +#endif + if (!strncmp(argv[2], "none", strlen("none"))) + return set_auth(AUTH_NONE); + if (!strncmp(argv[2], "optional", strlen("optional"))) + return set_auth(AUTH_OPTIONAL); + if (!strncmp(argv[2], "required", strlen("required"))) + return set_auth(AUTH_REQUIRED); + return CMD_RET_USAGE; + } +#endif + + if (argc < 2 || argc > 3) + return CMD_RET_USAGE; + + dst_addr = hextoul(argv[1], &end); + if (end == (argv[1] + strlen(argv[1]))) { + if (argc < 3) + return CMD_RET_USAGE; + url = argv[2]; + } else { + dst_addr = image_load_addr; + url = argv[1]; + } + + if (parse_legacy_arg(url, nurl, sizeof(nurl))) + return CMD_RET_FAILURE; + + wget_info = &default_wget_info; + if (wget_do_request(dst_addr, nurl)) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} diff --git a/cmd/mbr.c b/cmd/mbr.c index 7e1f92a13bb..7fe6c9e103a 100644 --- a/cmd/mbr.c +++ b/cmd/mbr.c @@ -10,6 +10,7 @@ #include <blk.h> #include <command.h> +#include <env.h> #include <malloc.h> #include <part.h> #include <vsprintf.h> diff --git a/cmd/mem.c b/cmd/mem.c index 9e716776393..b8afe62e474 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -14,8 +14,10 @@ #include <bootretry.h> #include <cli.h> #include <command.h> +#include <compiler.h> #include <console.h> #include <display_options.h> +#include <env.h> #ifdef CONFIG_MTD_NOR_FLASH #include <flash.h> #endif diff --git a/cmd/mmc.c b/cmd/mmc.c index fe7899ec793..5340a58be8e 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -8,6 +8,7 @@ #include <command.h> #include <console.h> #include <display_options.h> +#include <env.h> #include <mapmem.h> #include <memalign.h> #include <mmc.h> @@ -6,6 +6,7 @@ #include <command.h> #include <cpu_func.h> #include <vsprintf.h> +#include <linux/string.h> static int cpu_status_all(void) { diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c index a021b2d198d..571b79f091d 100644 --- a/cmd/mtdparts.c +++ b/cmd/mtdparts.c @@ -74,6 +74,7 @@ #include <env.h> #include <log.h> #include <malloc.h> +#include <mtd.h> #include <asm/global_data.h> #include <jffs2/load_kernel.h> #include <linux/list.h> diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c index 6b7d9ee061d..2755c26cdf7 100644 --- a/cmd/mvebu/bubt.c +++ b/cmd/mvebu/bubt.c @@ -185,7 +185,7 @@ static int mmc_burn_image(size_t image_size) lbaint_t blk_count; ulong blk_written; int err; - const u8 mmc_dev_num = CONFIG_SYS_MMC_ENV_DEV; + const u8 mmc_dev_num = CONFIG_ENV_MMC_DEVICE_INDEX; #ifdef CONFIG_BLK struct blk_desc *blk_desc; #endif @@ -290,7 +290,7 @@ static size_t mmc_read_file(const char *file_name) loff_t act_read = 0; int rc; struct mmc *mmc; - const u8 mmc_dev_num = CONFIG_SYS_MMC_ENV_DEV; + const u8 mmc_dev_num = CONFIG_ENV_MMC_DEVICE_INDEX; mmc = find_mmc_device(mmc_dev_num); if (!mmc) { diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c deleted file mode 100644 index cecf8d02555..00000000000 --- a/cmd/net-lwip.c +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* Copyright (C) 2024 Linaro Ltd. */ - -#include <command.h> -#include <net.h> - -#if defined(CONFIG_CMD_DHCP) -U_BOOT_CMD(dhcp, 3, 1, do_dhcp, - "boot image via network using DHCP/TFTP protocol", - "[loadAddress] [[hostIPaddr:]bootfilename]"); -#endif - -#if defined(CONFIG_CMD_PING) -U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host", - "pingAddress"); -#endif - -#if defined(CONFIG_CMD_TFTPBOOT) -U_BOOT_CMD(tftpboot, 3, 0, do_tftpb, - "boot image via network using TFTP protocol", - "[loadAddress] [[hostIPaddr:]bootfilename]"); -#endif - -#if defined(CONFIG_CMD_DNS) -U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname", - "hostname [envvar]"); -#endif - -#if defined(CONFIG_CMD_WGET) -U_BOOT_CMD(wget, 4, 1, do_wget, - "boot image via network using HTTP/HTTPS protocol" -#if defined(CONFIG_WGET_CACERT) - "\nwget cacert - configure wget root certificates" -#endif - , - "[loadAddress] url\n" - "wget [loadAddress] [host:]path\n" - " - load file" -#if defined(CONFIG_WGET_CACERT) - "\nwget cacert <address> <length>\n" - " - provide CA certificates (0 0 to remove current)" - "\nwget cacert none|optional|required\n" - " - set server certificate verification mode (default: optional)" -#if defined(CONFIG_WGET_BUILTIN_CACERT) - "\nwget cacert builtin\n" - " - use the builtin CA certificates" -#endif -#endif -); -#endif diff --git a/cmd/net.c b/cmd/net.c index eaa1de5295f..886735ea14f 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -564,7 +564,7 @@ int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) char *toff; if (argc < 2) { - net_ntp_server = env_get_ip("ntpserverip"); + net_ntp_server = string_to_ip(env_get("ntpserverip")); if (net_ntp_server.s_addr == 0) { printf("ntpserverip not set\n"); return CMD_RET_FAILURE; diff --git a/cmd/optee.c b/cmd/optee.c index e3aae5e9f9b..155c9f1bb73 100644 --- a/cmd/optee.c +++ b/cmd/optee.c @@ -6,6 +6,7 @@ #include <errno.h> #include <tee.h> #include <vsprintf.h> +#include <linux/string.h> #define TA_HELLO_WORLD_CMD_INC_VALUE 0 /* This needs to match the UUID of the Hello World TA. */ diff --git a/cmd/pxe.c b/cmd/pxe.c index 0f26b3b4219..3deae5e6d47 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <env.h> #include <fs.h> #include <net.h> #include <net6.h> @@ -64,6 +65,8 @@ static int pxe_dhcp_option_path(struct pxe_context *ctx, unsigned long pxefile_a int ret = get_pxe_file(ctx, pxelinux_configfile, pxefile_addr_r); free(pxelinux_configfile); + /* set to NULL to avoid double-free if DHCP is tried again */ + pxelinux_configfile = NULL; return ret; } diff --git a/cmd/sandbox/exception.c b/cmd/sandbox/exception.c index f9c847d8ff2..e015acf60e2 100644 --- a/cmd/sandbox/exception.c +++ b/cmd/sandbox/exception.c @@ -6,6 +6,7 @@ */ #include <command.h> +#include <env.h> static int do_sigsegv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/seama.c b/cmd/seama.c index 3c8e8199234..d6287978090 100644 --- a/cmd/seama.c +++ b/cmd/seama.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <env.h> #include <nand.h> /* diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c index 52aa26c78d2..f2757146bba 100644 --- a/cmd/sha1sum.c +++ b/cmd/sha1sum.c @@ -9,6 +9,7 @@ #include <command.h> #include <hash.h> +#include <linux/string.h> #include <u-boot/sha1.h> int do_sha1sum(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/sleep.c b/cmd/sleep.c index 7616fed7556..a8c896e0c5e 100644 --- a/cmd/sleep.c +++ b/cmd/sleep.c @@ -9,6 +9,7 @@ #include <time.h> #include <vsprintf.h> #include <linux/delay.h> +#include <linux/string.h> static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/smbios.c b/cmd/smbios.c index 562dd7959be..ed419f19028 100644 --- a/cmd/smbios.c +++ b/cmd/smbios.c @@ -280,7 +280,7 @@ static void smbios_print_type3(struct smbios_type3 *table) int i; u8 *addr = (u8 *)table + offsetof(struct smbios_type3, sku_number); - printf("Baseboard Information\n"); + printf("Chassis Information\n"); smbios_print_str("Manufacturer", table, table->manufacturer); printf("\tType: 0x%02x\n", table->chassis_type); smbios_print_str("Version", table, table->version); diff --git a/cmd/smccc.c b/cmd/smccc.c index 3a4d885e37e..fa04bb05ca4 100644 --- a/cmd/smccc.c +++ b/cmd/smccc.c @@ -9,6 +9,7 @@ #include <linux/arm-smccc.h> #include <linux/compiler.h> #include <linux/psci.h> +#include <linux/string.h> static int do_call(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/spawn.c b/cmd/spawn.c index 37737b8627c..8829aa9728d 100644 --- a/cmd/spawn.c +++ b/cmd/spawn.c @@ -5,6 +5,7 @@ #include <command.h> #include <console.h> +#include <env.h> #include <malloc.h> #include <vsprintf.h> #include <uthread.h> diff --git a/cmd/stackprot_test.c b/cmd/stackprot_test.c index e7ff4a06158..78e9beba5bf 100644 --- a/cmd/stackprot_test.c +++ b/cmd/stackprot_test.c @@ -4,6 +4,7 @@ */ #include <command.h> +#include <linux/string.h> static int do_test_stackprot_fail(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/strings.c b/cmd/strings.c index 5bcb0f2b567..beac2a6e6b3 100644 --- a/cmd/strings.c +++ b/cmd/strings.c @@ -9,6 +9,7 @@ #include <config.h> #include <command.h> #include <vsprintf.h> +#include <linux/string.h> static char *start_addr, *last_addr; diff --git a/cmd/test.c b/cmd/test.c index b4c3eabf9f6..a9ac07e6143 100644 --- a/cmd/test.c +++ b/cmd/test.c @@ -7,7 +7,9 @@ #include <command.h> #include <fs.h> #include <log.h> +#include <slre.h> #include <vsprintf.h> +#include <linux/string.h> #define OP_INVALID 0 #define OP_NOT 1 @@ -26,6 +28,7 @@ #define OP_INT_GT 14 #define OP_INT_GE 15 #define OP_FILE_EXISTS 16 +#define OP_REGEX 17 const struct { int arg; @@ -49,6 +52,9 @@ const struct { {0, "-z", OP_STR_EMPTY, 2}, {0, "-n", OP_STR_NEMPTY, 2}, {0, "-e", OP_FILE_EXISTS, 4}, +#ifdef CONFIG_REGEX + {1, "=~", OP_REGEX, 3}, +#endif }; static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, @@ -141,6 +147,20 @@ static int do_test(struct cmd_tbl *cmdtp, int flag, int argc, case OP_FILE_EXISTS: expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY); break; +#ifdef CONFIG_REGEX + case OP_REGEX: { + struct slre slre; + + if (slre_compile(&slre, ap[2]) == 0) { + printf("Error compiling regex: %s\n", slre.err_str); + expr = 0; + break; + } + + expr = slre_match(&slre, ap[0], strlen(ap[0]), NULL); + break; + } +#endif } switch (op) { diff --git a/cmd/timer.c b/cmd/timer.c index 04fcd84ac6a..427309e108d 100644 --- a/cmd/timer.c +++ b/cmd/timer.c @@ -6,6 +6,7 @@ #include <command.h> #include <time.h> +#include <linux/string.h> static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index a62862e94f9..346e21d27bb 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -113,7 +113,7 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; if (argc == 4) { algo = tpm2_name_to_algorithm(argv[3]); - if (algo < 0) + if (algo == TPM2_ALG_INVAL) return CMD_RET_FAILURE; } algo_len = tpm2_algorithm_to_len(algo); @@ -157,7 +157,7 @@ static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; if (argc == 4) { algo = tpm2_name_to_algorithm(argv[3]); - if (algo < 0) + if (algo == TPM2_ALG_INVAL) return CMD_RET_FAILURE; } algo_len = tpm2_algorithm_to_len(algo); @@ -288,7 +288,7 @@ static int do_tpm2_pcrallocate(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; algo = tpm2_name_to_algorithm(argv[1]); - if (algo == -EINVAL) + if (algo == TPM2_ALG_INVAL) return CMD_RET_USAGE; ret = get_tpm(&dev); diff --git a/cmd/tsi148.c b/cmd/tsi148.c deleted file mode 100644 index 113b4e67330..00000000000 --- a/cmd/tsi148.c +++ /dev/null @@ -1,472 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2009 Reinhard Arlt, reinhard.arlt@esd-electronics.com - * - * base on universe.h by - * - * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com - */ - -#include <command.h> -#include <log.h> -#include <malloc.h> -#include <vsprintf.h> -#include <asm/io.h> -#include <pci.h> - -#include <tsi148.h> - -#define LPCI_VENDOR PCI_VENDOR_ID_TUNDRA -#define LPCI_DEVICE PCI_DEVICE_ID_TUNDRA_TSI148 - -typedef struct _TSI148_DEV TSI148_DEV; - -struct _TSI148_DEV { - int bus; - pci_dev_t busdevfn; - TSI148 *uregs; - unsigned int pci_bs; -}; - -static TSI148_DEV *dev; - -/* - * Most of the TSI148 register are BIGENDIAN - * This is the reason for the __raw_writel(htonl(x), x) usage! - */ - -int tsi148_init(void) -{ - int j, result; - pci_dev_t busdevfn; - unsigned int val; - - busdevfn = pci_find_device(LPCI_VENDOR, LPCI_DEVICE, 0); - if (busdevfn == -1) { - puts("Tsi148: No Tundra Tsi148 found!\n"); - return -1; - } - - /* Lets turn Latency off */ - pci_write_config_dword(busdevfn, 0x0c, 0); - - dev = malloc(sizeof(*dev)); - if (NULL == dev) { - puts("Tsi148: No memory!\n"); - return -1; - } - - memset(dev, 0, sizeof(*dev)); - dev->busdevfn = busdevfn; - - pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val); - val &= ~0xf; - dev->uregs = (TSI148 *)val; - - debug("Tsi148: Base : %p\n", dev->uregs); - - /* check mapping */ - debug("Tsi148: Read via mapping, PCI_ID = %08X\n", - readl(&dev->uregs->pci_id)); - if (((LPCI_DEVICE << 16) | LPCI_VENDOR) != readl(&dev->uregs->pci_id)) { - printf("Tsi148: Cannot read PCI-ID via Mapping: %08x\n", - readl(&dev->uregs->pci_id)); - result = -1; - goto break_30; - } - - debug("Tsi148: PCI_BS = %08X\n", readl(&dev->uregs->pci_mbarl)); - - dev->pci_bs = readl(&dev->uregs->pci_mbarl); - - /* turn off windows */ - for (j = 0; j < 8; j++) { - __raw_writel(htonl(0x00000000), &dev->uregs->outbound[j].otat); - __raw_writel(htonl(0x00000000), &dev->uregs->inbound[j].itat); - } - - /* Tsi148 VME timeout etc */ - __raw_writel(htonl(0x00000084), &dev->uregs->vctrl); - -#ifdef DEBUG - if ((__raw_readl(&dev->uregs->vstat) & 0x00000100) != 0) - printf("Tsi148: System Controller!\n"); - else - printf("Tsi148: Not System Controller!\n"); -#endif - - /* - * Lets turn off interrupts - */ - /* Disable interrupts in Tsi148 first */ - __raw_writel(htonl(0x00000000), &dev->uregs->inten); - /* Disable interrupt out */ - __raw_writel(htonl(0x00000000), &dev->uregs->inteo); - eieio(); - /* Reset all IRQ's */ - __raw_writel(htonl(0x03ff3f00), &dev->uregs->intc); - /* Map all ints to 0 */ - __raw_writel(htonl(0x00000000), &dev->uregs->intm1); - __raw_writel(htonl(0x00000000), &dev->uregs->intm2); - eieio(); - - val = __raw_readl(&dev->uregs->vstat); - val &= ~(0x00004000); - __raw_writel(val, &dev->uregs->vstat); - eieio(); - - debug("Tsi148: register struct size %08x\n", sizeof(TSI148)); - - return 0; - - break_30: - free(dev); - dev = NULL; - - return result; -} - -/* - * Create pci slave window (access: pci -> vme) - */ -int tsi148_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, - int size, int vam, int vdw) -{ - int result, i; - unsigned int ctl = 0; - - if (NULL == dev) { - result = -1; - goto exit_10; - } - - for (i = 0; i < 8; i++) { - if (0x00000000 == readl(&dev->uregs->outbound[i].otat)) - break; - } - - if (i > 7) { - printf("Tsi148: No Image available\n"); - result = -1; - goto exit_10; - } - - debug("Tsi148: Using image %d\n", i); - - printf("Tsi148: Pci addr %08x\n", pciAddr); - - __raw_writel(htonl(pciAddr), &dev->uregs->outbound[i].otsal); - __raw_writel(0x00000000, &dev->uregs->outbound[i].otsau); - __raw_writel(htonl(pciAddr + size), &dev->uregs->outbound[i].oteal); - __raw_writel(0x00000000, &dev->uregs->outbound[i].oteau); - __raw_writel(htonl(vmeAddr - pciAddr), &dev->uregs->outbound[i].otofl); - __raw_writel(0x00000000, &dev->uregs->outbound[i].otofu); - - switch (vam & VME_AM_Axx) { - case VME_AM_A16: - ctl = 0x00000000; - break; - case VME_AM_A24: - ctl = 0x00000001; - break; - case VME_AM_A32: - ctl = 0x00000002; - break; - } - - switch (vam & VME_AM_Mxx) { - case VME_AM_DATA: - ctl |= 0x00000000; - break; - case VME_AM_PROG: - ctl |= 0x00000010; - break; - } - - if (vam & VME_AM_SUP) - ctl |= 0x00000020; - - switch (vdw & VME_FLAG_Dxx) { - case VME_FLAG_D16: - ctl |= 0x00000000; - break; - case VME_FLAG_D32: - ctl |= 0x00000040; - break; - } - - ctl |= 0x80040000; /* enable, no prefetch */ - - __raw_writel(htonl(ctl), &dev->uregs->outbound[i].otat); - - debug("Tsi148: window-addr =%p\n", - &dev->uregs->outbound[i].otsau); - debug("Tsi148: pci slave window[%d] attr =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->outbound[i].otat))); - debug("Tsi148: pci slave window[%d] start =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->outbound[i].otsal))); - debug("Tsi148: pci slave window[%d] end =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->outbound[i].oteal))); - debug("Tsi148: pci slave window[%d] offset=%08x\n", - i, ntohl(__raw_readl(&dev->uregs->outbound[i].otofl))); - - return 0; - - exit_10: - return -result; -} - -unsigned int tsi148_eval_vam(int vam) -{ - unsigned int ctl = 0; - - switch (vam & VME_AM_Axx) { - case VME_AM_A16: - ctl = 0x00000000; - break; - case VME_AM_A24: - ctl = 0x00000010; - break; - case VME_AM_A32: - ctl = 0x00000020; - break; - } - switch (vam & VME_AM_Mxx) { - case VME_AM_DATA: - ctl |= 0x00000001; - break; - case VME_AM_PROG: - ctl |= 0x00000002; - break; - case (VME_AM_PROG | VME_AM_DATA): - ctl |= 0x00000003; - break; - } - - if (vam & VME_AM_SUP) - ctl |= 0x00000008; - if (vam & VME_AM_USR) - ctl |= 0x00000004; - - return ctl; -} - -/* - * Create vme slave window (access: vme -> pci) - */ -int tsi148_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, - int size, int vam) -{ - int result, i; - unsigned int ctl = 0; - - if (NULL == dev) { - result = -1; - goto exit_10; - } - - for (i = 0; i < 8; i++) { - if (0x00000000 == readl(&dev->uregs->inbound[i].itat)) - break; - } - - if (i > 7) { - printf("Tsi148: No Image available\n"); - result = -1; - goto exit_10; - } - - debug("Tsi148: Using image %d\n", i); - - __raw_writel(htonl(vmeAddr), &dev->uregs->inbound[i].itsal); - __raw_writel(0x00000000, &dev->uregs->inbound[i].itsau); - __raw_writel(htonl(vmeAddr + size), &dev->uregs->inbound[i].iteal); - __raw_writel(0x00000000, &dev->uregs->inbound[i].iteau); - __raw_writel(htonl(pciAddr - vmeAddr), &dev->uregs->inbound[i].itofl); - if (vmeAddr > pciAddr) - __raw_writel(0xffffffff, &dev->uregs->inbound[i].itofu); - else - __raw_writel(0x00000000, &dev->uregs->inbound[i].itofu); - - ctl = tsi148_eval_vam(vam); - ctl |= 0x80000000; /* enable */ - __raw_writel(htonl(ctl), &dev->uregs->inbound[i].itat); - - debug("Tsi148: window-addr =%p\n", - &dev->uregs->inbound[i].itsau); - debug("Tsi148: vme slave window[%d] attr =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->inbound[i].itat))); - debug("Tsi148: vme slave window[%d] start =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->inbound[i].itsal))); - debug("Tsi148: vme slave window[%d] end =%08x\n", - i, ntohl(__raw_readl(&dev->uregs->inbound[i].iteal))); - debug("Tsi148: vme slave window[%d] offset=%08x\n", - i, ntohl(__raw_readl(&dev->uregs->inbound[i].itofl))); - - return 0; - - exit_10: - return -result; -} - -/* - * Create vme slave window (access: vme -> gcsr) - */ -int tsi148_vme_gcsr_window(unsigned int vmeAddr, int vam) -{ - int result; - unsigned int ctl; - - result = 0; - - if (NULL == dev) { - result = 1; - } else { - __raw_writel(htonl(vmeAddr), &dev->uregs->gbal); - __raw_writel(0x00000000, &dev->uregs->gbau); - - ctl = tsi148_eval_vam(vam); - ctl |= 0x00000080; /* enable */ - __raw_writel(htonl(ctl), &dev->uregs->gcsrat); - } - - return result; -} - -/* - * Create vme slave window (access: vme -> crcsr) - */ -int tsi148_vme_crcsr_window(unsigned int vmeAddr) -{ - int result; - unsigned int ctl; - - result = 0; - - if (NULL == dev) { - result = 1; - } else { - __raw_writel(htonl(vmeAddr), &dev->uregs->crol); - __raw_writel(0x00000000, &dev->uregs->crou); - - ctl = 0x00000080; /* enable */ - __raw_writel(htonl(ctl), &dev->uregs->crat); - } - - return result; -} - -/* - * Create vme slave window (access: vme -> crg) - */ -int tsi148_vme_crg_window(unsigned int vmeAddr, int vam) -{ - int result; - unsigned int ctl; - - result = 0; - - if (NULL == dev) { - result = 1; - } else { - __raw_writel(htonl(vmeAddr), &dev->uregs->cbal); - __raw_writel(0x00000000, &dev->uregs->cbau); - - ctl = tsi148_eval_vam(vam); - ctl |= 0x00000080; /* enable */ - __raw_writel(htonl(ctl), &dev->uregs->crgat); - } - - return result; -} - -/* - * Tundra Tsi148 configuration - */ -int do_tsi148(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, vdw = 0; - char cmd = 'x'; - - /* get parameter */ - if (argc > 1) - cmd = argv[1][0]; - if (argc > 2) - addr1 = hextoul(argv[2], NULL); - if (argc > 3) - addr2 = hextoul(argv[3], NULL); - if (argc > 4) - size = hextoul(argv[4], NULL); - if (argc > 5) - vam = hextoul(argv[5], NULL); - if (argc > 6) - vdw = hextoul(argv[6], NULL); - - switch (cmd) { - case 'c': - if (strcmp(argv[1], "crg") == 0) { - vam = addr2; - printf("Tsi148: Configuring VME CRG Window " - "(VME->CRG):\n"); - printf(" vme=%08lx vam=%02lx\n", addr1, vam); - tsi148_vme_crg_window(addr1, vam); - } else { - printf("Tsi148: Configuring VME CR/CSR Window " - "(VME->CR/CSR):\n"); - printf(" pci=%08lx\n", addr1); - tsi148_vme_crcsr_window(addr1); - } - break; - case 'i': /* init */ - tsi148_init(); - break; - case 'g': - vam = addr2; - printf("Tsi148: Configuring VME GCSR Window (VME->GCSR):\n"); - printf(" vme=%08lx vam=%02lx\n", addr1, vam); - tsi148_vme_gcsr_window(addr1, vam); - break; - case 'v': /* vme */ - printf("Tsi148: Configuring VME Slave Window (VME->PCI):\n"); - printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx\n", - addr1, addr2, size, vam); - tsi148_vme_slave_window(addr1, addr2, size, vam); - break; - case 'p': /* pci */ - printf("Tsi148: Configuring PCI Slave Window (PCI->VME):\n"); - printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx vdw=%02lx\n", - addr1, addr2, size, vam, vdw); - tsi148_pci_slave_window(addr1, addr2, size, vam, vdw); - break; - default: - printf("Tsi148: Command %s not supported!\n", argv[1]); - } - - return 0; -} - -U_BOOT_CMD( - tsi148, 7, 1, do_tsi148, - "initialize and configure Turndra Tsi148\n", - "init\n" - " - initialize tsi148\n" - "tsi148 vme [vme_addr] [pci_addr] [size] [vam]\n" - " - create vme slave window (access: vme->pci)\n" - "tsi148 pci [pci_addr] [vme_addr] [size] [vam] [vdw]\n" - " - create pci slave window (access: pci->vme)\n" - "tsi148 crg [vme_addr] [vam]\n" - " - create vme slave window: (access vme->CRG\n" - "tsi148 crcsr [pci_addr]\n" - " - create vme slave window: (access vme->CR/CSR\n" - "tsi148 gcsr [vme_addr] [vam]\n" - " - create vme slave window: (access vme->GCSR\n" - " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n" - " 02 -> A24 Address Space\n" - " 03 -> A32 Address Space\n" - " 04 -> Usr AM Code\n" - " 08 -> Supervisor AM Code\n" - " 10 -> Data AM Code\n" - " 20 -> Program AM Code\n" - " [vdw] = VMEbus Maximum Datawidth: 02 -> D16 Data Width\n" - " 03 -> D32 Data Width\n" -); diff --git a/cmd/ufs.c b/cmd/ufs.c index 6e21fbb1685..790dab50f18 100644 --- a/cmd/ufs.c +++ b/cmd/ufs.c @@ -8,6 +8,7 @@ #include <command.h> #include <ufs.h> #include <vsprintf.h> +#include <linux/string.h> static int do_ufs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { diff --git a/cmd/universe.c b/cmd/universe.c deleted file mode 100644 index 1445d5301f2..00000000000 --- a/cmd/universe.c +++ /dev/null @@ -1,361 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2003 Stefan Roese, stefan.roese@esd-electronics.com - */ - -#include <command.h> -#include <malloc.h> -#include <vsprintf.h> -#include <asm/io.h> -#include <pci.h> - -#include <universe.h> - -#define PCI_VENDOR PCI_VENDOR_ID_TUNDRA -#define PCI_DEVICE PCI_DEVICE_ID_TUNDRA_CA91C042 - -typedef struct _UNI_DEV UNI_DEV; - -struct _UNI_DEV { - int bus; - pci_dev_t busdevfn; - UNIVERSE *uregs; - unsigned int pci_bs; -}; - -static UNI_DEV *dev; - -int universe_init(void) -{ - int j, result; - pci_dev_t busdevfn; - unsigned int val; - - busdevfn = pci_find_device(PCI_VENDOR, PCI_DEVICE, 0); - if (busdevfn == -1) { - puts("No Tundra Universe found!\n"); - return -1; - } - - /* Lets turn Latency off */ - pci_write_config_dword(busdevfn, 0x0c, 0); - - dev = malloc(sizeof(*dev)); - if (NULL == dev) { - puts("UNIVERSE: No memory!\n"); - result = -1; - goto break_20; - } - - memset(dev, 0, sizeof(*dev)); - dev->busdevfn = busdevfn; - - pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_1, &val); - if (val & 1) { - pci_read_config_dword(busdevfn, PCI_BASE_ADDRESS_0, &val); - } - val &= ~0xf; - dev->uregs = (UNIVERSE *)val; - - debug ("UNIVERSE-Base : %p\n", dev->uregs); - - /* check mapping */ - debug (" Read via mapping, PCI_ID = %08X\n", readl(&dev->uregs->pci_id)); - if (((PCI_DEVICE <<16) | PCI_VENDOR) != readl(&dev->uregs->pci_id)) { - printf ("UNIVERSE: Cannot read PCI-ID via Mapping: %08x\n", - readl(&dev->uregs->pci_id)); - result = -1; - goto break_30; - } - - debug ("PCI_BS = %08X\n", readl(&dev->uregs->pci_bs)); - - dev->pci_bs = readl(&dev->uregs->pci_bs); - - /* turn off windows */ - for (j=0; j <4; j ++) { - writel(0x00800000, &dev->uregs->lsi[j].ctl); - writel(0x00800000, &dev->uregs->vsi[j].ctl); - } - - /* - * Write to Misc Register - * Set VME Bus Time-out - * Arbitration Mode - * DTACK Enable - */ - writel(0x15040000 | (readl(&dev->uregs->misc_ctl) & 0x00020000), &dev->uregs->misc_ctl); - - if (readl(&dev->uregs->misc_ctl) & 0x00020000) { - debug ("System Controller!\n"); /* test-only */ - } else { - debug ("Not System Controller!\n"); /* test-only */ - } - - /* - * Lets turn off interrupts - */ - writel(0x00000000,&dev->uregs->lint_en); /* Disable interrupts in the Universe first */ - writel(0x0000FFFF,&dev->uregs->lint_stat); /* Clear Any Pending Interrupts */ - eieio(); - writel(0x0000, &dev->uregs->lint_map0); /* Map all ints to 0 */ - writel(0x0000, &dev->uregs->lint_map1); /* Map all ints to 0 */ - eieio(); - - return 0; - - break_30: - free(dev); - break_20: - return result; -} - -/* - * Create pci slave window (access: pci -> vme) - */ -int universe_pci_slave_window(unsigned int pciAddr, unsigned int vmeAddr, int size, int vam, int pms, int vdw) -{ - int result, i; - unsigned int ctl = 0; - - if (NULL == dev) { - result = -1; - goto exit_10; - } - - for (i = 0; i < 4; i++) { - if (0x00800000 == readl(&dev->uregs->lsi[i].ctl)) - break; - } - - if (i == 4) { - printf ("universe: No Image available\n"); - result = -1; - goto exit_10; - } - - debug ("universe: Using image %d\n", i); - - writel(pciAddr , &dev->uregs->lsi[i].bs); - writel((pciAddr + size), &dev->uregs->lsi[i].bd); - writel((vmeAddr - pciAddr), &dev->uregs->lsi[i].to); - - switch (vam & VME_AM_Axx) { - case VME_AM_A16: - ctl = 0x00000000; - break; - case VME_AM_A24: - ctl = 0x00010000; - break; - case VME_AM_A32: - ctl = 0x00020000; - break; - } - - switch (vam & VME_AM_Mxx) { - case VME_AM_DATA: - ctl |= 0x00000000; - break; - case VME_AM_PROG: - ctl |= 0x00008000; - break; - } - - if (vam & VME_AM_SUP) { - ctl |= 0x00001000; - - } - - switch (vdw & VME_FLAG_Dxx) { - case VME_FLAG_D8: - ctl |= 0x00000000; - break; - case VME_FLAG_D16: - ctl |= 0x00400000; - break; - case VME_FLAG_D32: - ctl |= 0x00800000; - break; - } - - switch (pms & PCI_MS_Mxx) { - case PCI_MS_MEM: - ctl |= 0x00000000; - break; - case PCI_MS_IO: - ctl |= 0x00000001; - break; - case PCI_MS_CONFIG: - ctl |= 0x00000002; - break; - } - - ctl |= 0x80000000; /* enable */ - - writel(ctl, &dev->uregs->lsi[i].ctl); - - debug ("universe: window-addr=%p\n", &dev->uregs->lsi[i].ctl); - debug ("universe: pci slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->lsi[i].ctl)); - debug ("universe: pci slave window[%d] bs=%08x\n", i, readl(&dev->uregs->lsi[i].bs)); - debug ("universe: pci slave window[%d] bd=%08x\n", i, readl(&dev->uregs->lsi[i].bd)); - debug ("universe: pci slave window[%d] to=%08x\n", i, readl(&dev->uregs->lsi[i].to)); - - return 0; - - exit_10: - return -result; -} - -/* - * Create vme slave window (access: vme -> pci) - */ -int universe_vme_slave_window(unsigned int vmeAddr, unsigned int pciAddr, int size, int vam, int pms) -{ - int result, i; - unsigned int ctl = 0; - - if (NULL == dev) { - result = -1; - goto exit_10; - } - - for (i = 0; i < 4; i++) { - if (0x00800000 == readl(&dev->uregs->vsi[i].ctl)) - break; - } - - if (i == 4) { - printf ("universe: No Image available\n"); - result = -1; - goto exit_10; - } - - debug ("universe: Using image %d\n", i); - - writel(vmeAddr , &dev->uregs->vsi[i].bs); - writel((vmeAddr + size), &dev->uregs->vsi[i].bd); - writel((pciAddr - vmeAddr), &dev->uregs->vsi[i].to); - - switch (vam & VME_AM_Axx) { - case VME_AM_A16: - ctl = 0x00000000; - break; - case VME_AM_A24: - ctl = 0x00010000; - break; - case VME_AM_A32: - ctl = 0x00020000; - break; - } - - switch (vam & VME_AM_Mxx) { - case VME_AM_DATA: - ctl |= 0x00000000; - break; - case VME_AM_PROG: - ctl |= 0x00800000; - break; - } - - if (vam & VME_AM_SUP) { - ctl |= 0x00100000; - - } - - switch (pms & PCI_MS_Mxx) { - case PCI_MS_MEM: - ctl |= 0x00000000; - break; - case PCI_MS_IO: - ctl |= 0x00000001; - break; - case PCI_MS_CONFIG: - ctl |= 0x00000002; - break; - } - - ctl |= 0x80f00000; /* enable */ - - writel(ctl, &dev->uregs->vsi[i].ctl); - - debug ("universe: window-addr=%p\n", &dev->uregs->vsi[i].ctl); - debug ("universe: vme slave window[%d] ctl=%08x\n", i, readl(&dev->uregs->vsi[i].ctl)); - debug ("universe: vme slave window[%d] bs=%08x\n", i, readl(&dev->uregs->vsi[i].bs)); - debug ("universe: vme slave window[%d] bd=%08x\n", i, readl(&dev->uregs->vsi[i].bd)); - debug ("universe: vme slave window[%d] to=%08x\n", i, readl(&dev->uregs->vsi[i].to)); - - return 0; - - exit_10: - return -result; -} - -/* - * Tundra Universe configuration - */ -int do_universe(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - ulong addr1 = 0, addr2 = 0, size = 0, vam = 0, pms = 0, vdw = 0; - char cmd = 'x'; - - /* get parameter */ - if (argc > 1) - cmd = argv[1][0]; - if (argc > 2) - addr1 = hextoul(argv[2], NULL); - if (argc > 3) - addr2 = hextoul(argv[3], NULL); - if (argc > 4) - size = hextoul(argv[4], NULL); - if (argc > 5) - vam = hextoul(argv[5], NULL); - if (argc > 6) - pms = hextoul(argv[6], NULL); - if (argc > 7) - vdw = hextoul(argv[7], NULL); - - switch (cmd) { - case 'i': /* init */ - universe_init(); - break; - case 'v': /* vme */ - printf("Configuring Universe VME Slave Window (VME->PCI):\n"); - printf(" vme=%08lx pci=%08lx size=%08lx vam=%02lx pms=%02lx\n", - addr1, addr2, size, vam, pms); - universe_vme_slave_window(addr1, addr2, size, vam, pms); - break; - case 'p': /* pci */ - printf("Configuring Universe PCI Slave Window (PCI->VME):\n"); - printf(" pci=%08lx vme=%08lx size=%08lx vam=%02lx pms=%02lx vdw=%02lx\n", - addr1, addr2, size, vam, pms, vdw); - universe_pci_slave_window(addr1, addr2, size, vam, pms, vdw); - break; - default: - printf("Universe command %s not supported!\n", argv[1]); - } - - return 0; -} - -U_BOOT_CMD( - universe, 8, 1, do_universe, - "initialize and configure Turndra Universe", - "init\n" - " - initialize universe\n" - "universe vme [vme_addr] [pci_addr] [size] [vam] [pms]\n" - " - create vme slave window (access: vme->pci)\n" - "universe pci [pci_addr] [vme_addr] [size] [vam] [pms] [vdw]\n" - " - create pci slave window (access: pci->vme)\n" - " [vam] = VMEbus Address-Modifier: 01 -> A16 Address Space\n" - " 02 -> A24 Address Space\n" - " 03 -> A32 Address Space\n" - " 04 -> Supervisor AM Code\n" - " 10 -> Data AM Code\n" - " 20 -> Program AM Code\n" - " [pms] = PCI Memory Space: 01 -> Memory Space\n" - " 02 -> I/O Space\n" - " 03 -> Configuration Space\n" - " [vdw] = VMEbus Maximum Datawidth: 01 -> D8 Data Width\n" - " 02 -> D16 Data Width\n" - " 03 -> D32 Data Width" -); diff --git a/cmd/upl.c b/cmd/upl.c index c9a823bbc06..ef2183d8528 100644 --- a/cmd/upl.c +++ b/cmd/upl.c @@ -12,6 +12,7 @@ #include <alist.h> #include <command.h> #include <display_options.h> +#include <env.h> #include <mapmem.h> #include <string.h> #include <upl.h> diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c index 289865515ef..91130453039 100644 --- a/cmd/x86/mtrr.c +++ b/cmd/x86/mtrr.c @@ -6,6 +6,7 @@ #include <command.h> #include <log.h> #include <vsprintf.h> +#include <linux/string.h> #include <asm/msr.h> #include <asm/mp.h> #include <asm/mtrr.h> diff --git a/cmd/x86/zboot.c b/cmd/x86/zboot.c index 94e602b8a5b..3876d163236 100644 --- a/cmd/x86/zboot.c +++ b/cmd/x86/zboot.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY LOGC_BOOT #include <command.h> +#include <env.h> #include <mapmem.h> #include <vsprintf.h> #include <asm/zimage.h> diff --git a/cmd/ximg.c b/cmd/ximg.c index 29d7c3279b3..e97167a79cc 100644 --- a/cmd/ximg.c +++ b/cmd/ximg.c @@ -27,6 +27,7 @@ #include <asm/byteorder.h> #include <asm/cache.h> #include <asm/io.h> +#include <u-boot/zlib.h> static int do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -206,11 +207,18 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) break; #ifdef CONFIG_GZIP case IH_COMP_GZIP: - printf(" Uncompressing part %d ... ", part); - if (gunzip((void *) dest, unc_len, - (uchar *) data, &len) != 0) { - puts("GUNZIP ERROR - image not loaded\n"); - return 1; + { + int ret = 0; + printf(" Uncompressing part %d ... ", part); + ret = gunzip((void *)dest, unc_len, + (uchar *)data, &len); + if (ret == Z_BUF_ERROR) { + puts("Image too large: increase CONFIG_SYS_XIMG_LEN\n"); + return 1; + } else if (ret != 0) { + puts("GUNZIP ERROR - image not loaded\n"); + return 1; + } } break; #endif |