diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 517 | ||||
-rw-r--r-- | cmd/Makefile | 6 | ||||
-rw-r--r-- | cmd/bdinfo.c | 12 | ||||
-rw-r--r-- | cmd/bootefi.c | 135 | ||||
-rw-r--r-- | cmd/bootm.c | 4 | ||||
-rw-r--r-- | cmd/bootmenu.c | 4 | ||||
-rw-r--r-- | cmd/cbfs.c | 2 | ||||
-rw-r--r-- | cmd/cramfs.c | 10 | ||||
-rw-r--r-- | cmd/elf.c | 32 | ||||
-rw-r--r-- | cmd/fastboot/Kconfig | 2 | ||||
-rw-r--r-- | cmd/fdt.c | 31 | ||||
-rw-r--r-- | cmd/fpga.c | 4 | ||||
-rw-r--r-- | cmd/gpt.c | 411 | ||||
-rw-r--r-- | cmd/ini.c | 6 | ||||
-rw-r--r-- | cmd/itest.c | 2 | ||||
-rw-r--r-- | cmd/jffs2.c | 6 | ||||
-rw-r--r-- | cmd/load.c | 16 | ||||
-rw-r--r-- | cmd/log.c | 6 | ||||
-rw-r--r-- | cmd/lzmadec.c | 2 | ||||
-rw-r--r-- | cmd/md5sum.c | 4 | ||||
-rw-r--r-- | cmd/mtdparts.c | 44 | ||||
-rw-r--r-- | cmd/mvebu/bubt.c | 2 | ||||
-rw-r--r-- | cmd/nand.c | 12 | ||||
-rw-r--r-- | cmd/net.c | 42 | ||||
-rw-r--r-- | cmd/nvedit.c | 38 | ||||
-rw-r--r-- | cmd/nvme.c | 197 | ||||
-rw-r--r-- | cmd/part.c | 8 | ||||
-rw-r--r-- | cmd/pci.c | 4 | ||||
-rw-r--r-- | cmd/portio.c | 145 | ||||
-rw-r--r-- | cmd/pxe.c | 39 | ||||
-rw-r--r-- | cmd/qfw.c | 6 | ||||
-rw-r--r-- | cmd/read.c | 2 | ||||
-rw-r--r-- | cmd/reiser.c | 8 | ||||
-rw-r--r-- | cmd/scsi.c | 2 | ||||
-rw-r--r-- | cmd/setexpr.c | 10 | ||||
-rw-r--r-- | cmd/source.c | 2 | ||||
-rw-r--r-- | cmd/tpm.c | 4 | ||||
-rw-r--r-- | cmd/trace.c | 18 | ||||
-rw-r--r-- | cmd/unzip.c | 2 | ||||
-rw-r--r-- | cmd/usb.c | 7 | ||||
-rw-r--r-- | cmd/ximg.c | 6 | ||||
-rw-r--r-- | cmd/zfs.c | 6 | ||||
-rw-r--r-- | cmd/zip.c | 2 |
43 files changed, 1265 insertions, 553 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index f18efc1e88..42d955c96a 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -158,6 +158,12 @@ config CMD_LICENSE help Print GPL license text +config CMD_REGINFO + bool "reginfo" + depends on PPC + help + Register dump + endmenu menu "Boot commands" @@ -270,6 +276,54 @@ config CMD_POWEROFF help Poweroff/Shutdown the system +config CMD_SPL + bool "spl export - Export boot information for Falcon boot" + depends on SPL + help + Falcon mode allows booting directly from SPL into an Operating + System such as Linux, thus skipping U-Boot proper. See + doc/README.falcon for full information about how to use this + command. + +config CMD_SPL_NAND_OFS + hex "Offset of OS command line args for Falcon-mode NAND boot" + depends on CMD_SPL + default 0 + help + This provides the offset of the command line arguments for Linux + when booting from NAND in Falcon mode. See doc/README.falcon + for full information about how to use this option (and also see + board/gateworks/gw_ventana/README for an example). + +config CMD_SPL_WRITE_SIZE + hex "Size of argument area" + depends on CMD_SPL + default 0x2000 + help + This provides the size of the command-line argument area in NAND + flash used by Falcon-mode boot. See the documentation until CMD_SPL + for detail. + +config CMD_THOR_DOWNLOAD + bool "thor - TIZEN 'thor' download" + help + Implements the 'thor' download protocol. This is a way of + downloading a software update over USB from an attached host. + There is no documentation about this within the U-Boot source code + but you should be able to find something on the interwebs. + +config CMD_ZBOOT + bool "zboot - x86 boot command" + help + With x86 machines it is common to boot a bzImage file which + contains both a kernel and a setup.bin file. The latter includes + configuration information from the dark ages which x86 boards still + need to pick things out of. + + Consider using FIT in preference to this since it supports directly + booting both 32- and 64-bit kernels, as well as secure boot. + Documentation is available in doc/uImage.FIT/x86-fit-boot.txt + endmenu menu "Environment commands" @@ -336,20 +390,6 @@ endmenu menu "Memory commands" -config CMD_MEMORY - bool "md, mm, nm, mw, cp, cmp, base, loop" - default y - help - Memory commands. - md - memory display - mm - memory modify (auto-incrementing address) - nm - memory modify (constant address) - mw - memory write (fill) - cp - memory copy - cmp - memory compare - base - print or set address offset - loop - initialize loop on address range - config CMD_CRC32 bool "crc32" select HASH @@ -411,6 +451,11 @@ config EEPROM_LAYOUT_HELP_STRING Help printed with the LAYOUT VERSIONS part of the 'eeprom' command's help. +config LOOPW + bool "loopw" + help + Infinite write loop on address range + config CMD_MD5SUM bool "md5sum" default n @@ -425,22 +470,24 @@ config MD5SUM_VERIFY help Add -v option to verify data against an MD5 checksum. -config CMD_SHA1SUM - bool "sha1sum" - select SHA1 - help - Compute SHA1 checksum. - -config SHA1SUM_VERIFY - bool "sha1sum -v" - depends on CMD_SHA1SUM +config CMD_MEMINFO + bool "meminfo" help - Add -v option to verify data against a SHA1 checksum. + Display memory information. -config LOOPW - bool "loopw" +config CMD_MEMORY + bool "md, mm, nm, mw, cp, cmp, base, loop" + default y help - Infinite write loop on address range + Memory commands. + md - memory display + mm - memory modify (auto-incrementing address) + nm - memory modify (constant address) + mw - memory write (fill) + cp - memory copy + cmp - memory compare + base - print or set address offset + loop - initialize loop on address range config CMD_MEMTEST bool "memtest" @@ -453,10 +500,25 @@ config CMD_MX_CYCLIC mdc - memory display cyclic mwc - memory write cyclic -config CMD_MEMINFO - bool "meminfo" +config CMD_SHA1SUM + bool "sha1sum" + select SHA1 help - Display memory information. + Compute SHA1 checksum. + +config SHA1SUM_VERIFY + bool "sha1sum -v" + depends on CMD_SHA1SUM + help + Add -v option to verify data against a SHA1 checksum. + +config CMD_STRINGS + bool "strings - display strings in memory" + help + This works similarly to the Unix 'strings' command except that it + works with a memory range. String of printable characters found + within the range are displayed. The minimum number of characters + for a sequence to be considered a string can be provided. endmenu @@ -483,6 +545,12 @@ endmenu menu "Device access commands" +config CMD_ARMFLASH + #depends on FLASH_CFI_DRIVER + bool "armflash" + help + ARM Ltd reference designs flash partition access + config CMD_CLK bool "clk - Show clock frequencies" help @@ -492,6 +560,27 @@ config CMD_CLK clock values from associated drivers. However currently no command exists for this. +config CMD_DEMO + bool "demo - Demonstration commands for driver model" + depends on DM + help + Provides a 'demo' command which can be used to play around with + driver model. To use this properly you will need to enable one or + both of the demo devices (DM_DEMO_SHAPE and DM_DEMO_SIMPLE). + Otherwise you will always get an empty list of devices. The demo + devices are defined in the sandbox device tree, so the easiest + option is to use sandbox and pass the -d point to sandbox's + u-boot.dtb file. + +config CMD_DFU + bool "dfu" + select USB_FUNCTION_DFU + help + Enables the command "dfu" which is used to have U-Boot create a DFU + class device via USB. This command requires that the "dfu_alt_info" + environment variable be set and define the alt settings to expose to + the host. + config CMD_DM bool "dm - Access to driver model information" depends on DM @@ -503,17 +592,88 @@ config CMD_DM can be useful to see the state of driver model for debugging or interest. -config CMD_DEMO - bool "demo - Demonstration commands for driver model" - depends on DM +config CMD_FDC + bool "fdcboot - Boot from floppy device" help - Provides a 'demo' command which can be used to play around with - driver model. To use this properly you will need to enable one or - both of the demo devices (DM_DEMO_SHAPE and DM_DEMO_SIMPLE). - Otherwise you will always get an empty list of devices. The demo - devices are defined in the sandbox device tree, so the easiest - option is to use sandbox and pass the -d point to sandbox's - u-boot.dtb file. + The 'fdtboot' command allows booting an image from a floppy disk. + +config CMD_FLASH + bool "flinfo, erase, protect" + default y + help + NOR flash support. + flinfo - print FLASH memory information + erase - FLASH memory + protect - enable or disable FLASH write protection + +config CMD_FPGA + bool "fpga" + default y + help + FPGA support. + +config CMD_FPGA_LOADBP + bool "fpga loadbp - load partial bitstream (Xilinx only)" + depends on CMD_FPGA + help + Supports loading an FPGA device from a bitstream buffer containing + a partial bitstream. + +config CMD_FPGA_LOADFS + bool "fpga loadfs - load bitstream from FAT filesystem (Xilinx only)" + depends on CMD_FPGA + help + Supports loading an FPGA device from a FAT filesystem. + +config CMD_FPGA_LOADMK + bool "fpga loadmk - load bitstream from image" + depends on CMD_FPGA + help + Supports loading an FPGA device from a image generated by mkimage. + +config CMD_FPGA_LOADP + bool "fpga loadp - load partial bitstream" + depends on CMD_FPGA + help + Supports loading an FPGA device from a bitstream buffer containing + a partial bitstream. + +config CMD_FPGAD + bool "fpgad - dump FPGA registers" + help + (legacy, needs conversion to driver model) + Provides a way to dump FPGA registers by calling the board-specific + fpga_get_reg() function. This functions similarly to the 'md' + command. + +config CMD_FUSE + bool "fuse - support for the fuse subssystem" + help + (deprecated - needs conversion to driver model) + This allows reading, sensing, programming or overriding fuses + which control the behaviour of the device. The command uses the + fuse_...() API. + +config CMD_GPIO + bool "gpio" + help + GPIO support. + +config CMD_GPT + bool "GPT (GUID Partition Table) command" + select PARTITION_UUIDS + select EFI_PARTITION + help + Enable the 'gpt' command to ready and write GPT style partition + tables. + +config CMD_GPT_RENAME + bool "GPT partition renaming commands" + depends on CMD_GPT + help + Enables the 'gpt' command to interchange names on two GPT + partitions via the 'gpt swap' command or to rename single + partitions via the 'rename' command. config CMD_IDE bool "ide - Support for IDE drivers" @@ -566,6 +726,11 @@ config CMD_IOTRACE might be useful to enhance tracing to only checksum the accesses and not the data read/written. +config CMD_I2C + bool "i2c" + help + I2C support. + config CMD_LOADB bool "loadb" default y @@ -578,29 +743,6 @@ config CMD_LOADS help Load an S-Record file over serial line -config CMD_FLASH - bool "flinfo, erase, protect" - default y - help - NOR flash support. - flinfo - print FLASH memory information - erase - FLASH memory - protect - enable or disable FLASH write protection - -config CMD_GPT - bool "GPT (GUID Partition Table) command" - select PARTITION_UUIDS - select EFI_PARTITION - help - Enable the 'gpt' command to ready and write GPT style partition - tables. - -config CMD_ARMFLASH - #depends on FLASH_CFI_DRIVER - bool "armflash" - help - ARM Ltd reference designs flash partition access - config CMD_MMC bool "mmc" help @@ -631,121 +773,132 @@ config CMD_NAND_TORTURE endif # CMD_NAND -config CMD_PART - bool "part" - select PARTITION_UUIDS +config CMD_NVME + bool "nvme" + depends on NVME + default y if NVME help - Read and display information about the partition table on - various media. + NVM Express device support -config CMD_SF - bool "sf" +config CMD_MMC_SPI + bool "mmc_spi - Set up MMC SPI device" help - SPI Flash support + Provides a way to set up an MMC (Multimedia Card) SPI (Serial + Peripheral Interface) device. The device provides a means of + accessing an MMC device via SPI using a single data line, limited + to 20MHz. It is useful since it reduces the amount of protocol code + required. -config CMD_SPI - bool "sspi" +config CMD_ONENAND + bool "onenand - access to onenand device" help - SPI utility command. + OneNAND is a brand of NAND ('Not AND' gate) flash which provides + various useful features. This command allows reading, writing, + and erasing blocks. It allso provides a way to show and change + bad blocks, and test the device. -config CMD_I2C - bool "i2c" +config CMD_PART + bool "part" + select PARTITION_UUIDS help - I2C support. + Read and display information about the partition table on + various media. -config CMD_USB - bool "usb" +config CMD_PCI + bool "pci - Access PCI devices" help - USB support. + Provide access to PCI (Peripheral Interconnect Bus), a type of bus + used on some devices to allow the CPU to communicate with its + peripherals. Sub-commands allow bus enumeration, displaying and + changing configuration space and a few other features. -config CMD_DFU - bool "dfu" - select USB_FUNCTION_DFU +config CMD_PCMCIA + bool "pinit - Set up PCMCIA device" help - Enables the command "dfu" which is used to have U-Boot create a DFU - class device via USB. + Provides a means to initialise a PCMCIA (Personal Computer Memory + Card International Association) device. This is an old standard from + about 1990. These devices are typically removable memory or network + cards using a standard 68-pin connector. -config CMD_USB_MASS_STORAGE - bool "UMS usb mass storage" +config CMD_READ + bool "read - Read binary data from a partition" help - USB mass storage support + Provides low-level access to the data in a partition. -config CMD_FPGA - bool "fpga" - default y +config CMD_REMOTEPROC + bool "remoteproc" + depends on REMOTEPROC help - FPGA support. + Support for Remote Processor control -config CMD_FPGA_LOADBP - bool "fpga loadbp - load partial bitstream (Xilinx only)" - depends on CMD_FPGA +config CMD_SATA + bool "sata - Access SATA subsystem" + select SATA help - Supports loading an FPGA device from a bitstream buffer containing - a partial bitstream. + SATA (Serial Advanced Technology Attachment) is a serial bus + standard for connecting to hard drives and other storage devices. + This command provides information about attached devices and allows + reading, writing and other operations. -config CMD_FPGA_LOADFS - bool "fpga loadfs - load bitstream from FAT filesystem (Xilinx only)" - depends on CMD_FPGA - help - Supports loading an FPGA device from a FAT filesystem. + SATA replaces PATA (originally just ATA), which stands for Parallel AT + Attachment, where AT refers to an IBM AT (Advanced Technology) + computer released in 1984. -config CMD_FPGA_LOADMK - bool "fpga loadmk - load bitstream from image" - depends on CMD_FPGA +config CMD_SAVES + bool "saves - Save a file over serial in S-Record format" help - Supports loading an FPGA device from a image generated by mkimage. + Provides a way to save a binary file using the Motorola S-Record + format over the serial line. -config CMD_FPGA_LOADP - bool "fpga loadp - load partial bitstream" - depends on CMD_FPGA +config CMD_SDRAM + bool "sdram - Print SDRAM configuration information" help - Supports loading an FPGA device from a bitstream buffer containing - a partial bitstream. + Provides information about attached SDRAM. This assumed that the + SDRAM has an EEPROM with information that can be read using the + I2C bus. This is only available on some boards. -config CMD_FPGAD - bool "fpgad - dump FPGA registers" +config CMD_SF + bool "sf" help - (legacy, needs conversion to driver model) - Provides a way to dump FPGA registers by calling the board-specific - fpga_get_reg() function. This functions similarly to the 'md' - command. + SPI Flash support -config CMD_FUSE - bool "fuse - support for the fuse subssystem" +config CMD_SF_TEST + bool "sf test - Allow testing of SPI flash" help - (deprecated - needs conversion to driver model) - This allows reading, sensing, programming or overriding fuses - which control the behaviour of the device. The command uses the - fuse_...() API. + Provides a way to test that SPI flash is working correctly. The + test is destructive, in that an area of SPI flash must be provided + for the test to use. Performance information is also provided, + measuring the performance of reading, writing and erasing in + Mbps (Million Bits Per Second). This value should approximately + equal the SPI bus speed for a single-bit-wide SPI bus, assuming + everything is working properly. -config CMD_REMOTEPROC - bool "remoteproc" - depends on REMOTEPROC +config CMD_SPI + bool "sspi" help - Support for Remote Processor control + SPI utility command. -config CMD_GPIO - bool "gpio" +config CMD_TSI148 + bool "tsi148 - Command to access tsi148 device" help - GPIO support. + This provides various sub-commands to initialise and configure the + Turndra tsi148 device. See the command help for full details. -config CMD_FDC - bool "fdcboot - Boot from floppy device" +config CMD_UNIVERSE + bool "universe - Command to set up the Turndra Universe controller" help - The 'fdtboot' command allows booting an image from a floppy disk. + This allows setting up the VMEbus provided by this controller. + See the command help for full details. -config CMD_SATA - bool "sata - Access SATA subsystem" - select SATA +config CMD_USB + bool "usb" help - SATA (Serial Advanced Technology Attachment) is a serial bus - standard for connecting to hard drives and other storage devices. - This command provides information about attached devices and allows - reading, writing and other operations. + USB support. - SATA replaces PATA (originally just ATA), which stands for Parallel AT - Attachment, where AT refers to an IBM AT (Advanced Technology) - computer released in 1984. +config CMD_USB_MASS_STORAGE + bool "UMS usb mass storage" + help + USB mass storage support endmenu @@ -982,6 +1135,25 @@ config CMD_QFW source "cmd/mvebu/Kconfig" +config CMD_TERMINAL + bool "terminal - provides a way to attach a serial terminal" + help + Provides a 'cu'-like serial terminal command. This can be used to + access other serial ports from the system console. The terminal + is very simple with no special processing of characters. As with + cu, you can press ~. (tilde followed by period) to exit. + +config CMD_UUID + bool "uuid, guid - generation of unique IDs" + help + This enables two commands: + + uuid - generate random Universally Unique Identifier + guid - generate Globally Unique Identifier based on random UUID + + The two commands are very similar except for the endianness of the + output. + endmenu config CMD_BOOTSTAGE @@ -1213,6 +1385,56 @@ config MTDPARTS_DEFAULT Defines a default MTD partitioning scheme in the Linux MTD command line partitions format +config CMD_MTDPARTS_SPREAD + bool "Padd partition size to take account of bad blocks" + depends on CMD_MTDPARTS + help + This enables the 'spread' sub-command of the mtdparts command. + This command will modify the existing mtdparts variable by increasing + the size of the partitions such that 1) each partition's net size is + at least as large as the size specified in the mtdparts variable and + 2) each partition starts on a good block. + +config CMD_REISER + bool "reiser - Access to reiserfs filesystems" + help + This provides two commands which operate on a resierfs filesystem, + commonly used some years ago: + + reiserls - list files + reiserload - load a file + +config CMD_SCSI + bool "scsi - Access to SCSI devices" + default y if SCSI + help + This provides a 'scsi' command which provides access to SCSI (Small + Computer System Interface) devices. The command provides a way to + scan the bus, reset the bus, read and write data and get information + about devices. + +config CMD_YAFFS2 + bool "yaffs2 - Access of YAFFS2 filesystem" + depends on YAFFS2 + default y + help + This provides commands for accessing a YAFFS2 filesystem. Yet + Another Flash Filesystem 2 is a filesystem designed specifically + for NAND flash. It incorporates bad-block management and ensures + that device writes are sequential regardless of filesystem + activity. + +config CMD_ZFS + bool "zfs - Access of ZFS filesystem" + help + This provides commands to accessing a ZFS filesystem, commonly used + on Solaris systems. Two sub-commands are provided: + + zfsls - list files in a directory + zfsload - load a file + + See doc/README.zfs for more details. + endmenu menu "Debug commands" @@ -1249,6 +1471,15 @@ config CMD_KGDB single-stepping, inspecting variables, etc. This is supported only on PowerPC at present. +config CMD_TRACE + bool "trace - Support tracing of function calls and timing" + help + Enables a command to control using of function tracing within + U-Boot. This allows recording of call traces including timing + information. The command can write data to memory for exporting + for analsys (e.g. using bootchart). See doc/README.trace for full + details. + endmenu config CMD_UBI diff --git a/cmd/Makefile b/cmd/Makefile index bd231f24d8..13c86f8fcc 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -97,7 +97,6 @@ ifdef CONFIG_PCI obj-$(CONFIG_CMD_PCI) += pci.o endif obj-y += pcmcia.o -obj-$(CONFIG_CMD_PORTIO) += portio.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_QFW) += qfw.o obj-$(CONFIG_CMD_READ) += read.o @@ -106,8 +105,9 @@ obj-$(CONFIG_CMD_REISER) += reiser.o obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o obj-$(CONFIG_SANDBOX) += host.o obj-$(CONFIG_CMD_SATA) += sata.o +obj-$(CONFIG_CMD_NVME) += nvme.o obj-$(CONFIG_CMD_SF) += sf.o -obj-$(CONFIG_SCSI) += scsi.o disk.o +obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o obj-$(CONFIG_CMD_SPI) += spi.o @@ -133,7 +133,7 @@ obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o obj-$(CONFIG_CMD_USB_MASS_STORAGE) += usb_mass_storage.o obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_XIMG) += ximg.o -obj-$(CONFIG_YAFFS2) += yaffs2.o +obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o obj-$(CONFIG_CMD_ZIP) += zip.o obj-$(CONFIG_CMD_ZFS) += zfs.o diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c index 8971697e60..27ffcd55bc 100644 --- a/cmd/bdinfo.c +++ b/cmd/bdinfo.c @@ -28,7 +28,7 @@ static void print_eth(int idx) sprintf(name, "eth%iaddr", idx); else strcpy(name, "ethaddr"); - val = getenv(name); + val = env_get(name); if (!val) val = "(not set)"; printf("%-12s= %s\n", name, val); @@ -51,7 +51,7 @@ static void print_eths(void) } while (dev); printf("current eth = %s\n", eth_get_name()); - printf("ip_addr = %s\n", getenv("ipaddr")); + printf("ip_addr = %s\n", env_get("ipaddr")); } #endif @@ -141,7 +141,7 @@ static inline void print_eth_ip_addr(void) #if defined(CONFIG_HAS_ETH5) print_eth(5); #endif - printf("IP addr = %s\n", getenv("ipaddr")); + printf("IP addr = %s\n", env_get("ipaddr")); #endif } @@ -166,7 +166,7 @@ static inline void __maybe_unused print_std_bdinfo(const bd_t *bd) #if defined(CONFIG_PPC) void __weak board_detail(void) { - /* Please define boot_detail() for your platform */ + /* Please define board_detail() for your platform */ } int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -344,9 +344,9 @@ static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, #ifdef CONFIG_BOARD_TYPES printf("Board Type = %ld\n", gd->board_type); #endif -#ifdef CONFIG_SYS_MALLOC_F +#if CONFIG_VAL(SYS_MALLOC_F_LEN) printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr, - CONFIG_SYS_MALLOC_F_LEN); + CONFIG_VAL(SYS_MALLOC_F_LEN)); #endif if (gd->fdt_blob) printf("fdt_blob = %p\n", gd->fdt_blob); diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 771300ee94..d20775eccd 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -20,6 +20,8 @@ DECLARE_GLOBAL_DATA_PTR; +static uint8_t efi_obj_list_initalized; + /* * When booting using the "bootefi" command, we don't know which * physical device the file came from. So we create a pseudo-device @@ -54,14 +56,6 @@ static struct efi_device_path_file_path bootefi_device_path[] = { } }; -static efi_status_t EFIAPI bootefi_open_dp(void *handle, efi_guid_t *protocol, - void **protocol_interface, void *agent_handle, - void *controller_handle, uint32_t attributes) -{ - *protocol_interface = bootefi_device_path; - return EFI_SUCCESS; -} - /* The EFI loaded_image interface for the image executed via "bootefi" */ static struct efi_loaded_image loaded_image_info = { .device_handle = bootefi_device_path, @@ -78,7 +72,7 @@ static struct efi_object loaded_image_info_obj = { * return handle which points to loaded_image_info */ .guid = &efi_guid_loaded_image, - .open = &efi_return_handle, + .protocol_interface = &loaded_image_info, }, { /* @@ -86,7 +80,15 @@ static struct efi_object loaded_image_info_obj = { * bootefi_device_path */ .guid = &efi_guid_device_path, - .open = &bootefi_open_dp, + .protocol_interface = bootefi_device_path, + }, + { + .guid = &efi_guid_console_control, + .protocol_interface = (void *) &efi_console_control + }, + { + .guid = &efi_guid_device_path_to_text_protocol, + .protocol_interface = (void *) &efi_device_path_to_text }, }, }; @@ -99,11 +101,43 @@ static struct efi_object bootefi_device_obj = { /* When asking for the device path interface, return * bootefi_device_path */ .guid = &efi_guid_device_path, - .open = &bootefi_open_dp, + .protocol_interface = bootefi_device_path } }, }; +/* Initialize and populate EFI object list */ +static void efi_init_obj_list(void) +{ + efi_obj_list_initalized = 1; + + list_add_tail(&loaded_image_info_obj.link, &efi_obj_list); + list_add_tail(&bootefi_device_obj.link, &efi_obj_list); + efi_console_register(); +#ifdef CONFIG_PARTITIONS + efi_disk_register(); +#endif +#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) + efi_gop_register(); +#endif +#ifdef CONFIG_NET + void *nethandle = loaded_image_info.device_handle; + efi_net_register(&nethandle); + + if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6)) + loaded_image_info.device_handle = nethandle; + else + loaded_image_info.device_handle = bootefi_device_path; +#endif +#ifdef CONFIG_GENERATE_SMBIOS_TABLE + efi_smbios_register(); +#endif + + /* Initialize EFI runtime services */ + efi_reset_system_init(); + efi_get_time_init(); +} + static void *copy_fdt(void *fdt) { u64 fdt_size = fdt_totalsize(fdt); @@ -147,15 +181,28 @@ static void *copy_fdt(void *fdt) return new_fdt; } +static ulong efi_do_enter(void *image_handle, + struct efi_system_table *st, + asmlinkage ulong (*entry)(void *image_handle, + struct efi_system_table *st)) +{ + efi_status_t ret = EFI_LOAD_ERROR; + + if (entry) + ret = entry(image_handle, st); + st->boottime->exit(image_handle, ret, 0, NULL); + return ret; +} + #ifdef CONFIG_ARM64 -static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle, - struct efi_system_table *st), void *image_handle, - struct efi_system_table *st) +static unsigned long efi_run_in_el2(asmlinkage ulong (*entry)( + void *image_handle, struct efi_system_table *st), + void *image_handle, struct efi_system_table *st) { /* Enable caches again */ dcache_enable(); - return entry(image_handle, st); + return efi_do_enter(image_handle, st, entry); } #endif @@ -168,6 +215,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) ulong (*entry)(void *image_handle, struct efi_system_table *st) asmlinkage; ulong fdt_pages, fdt_size, fdt_start, fdt_end; + const efi_guid_t fdt_guid = EFI_FDT_GUID; bootm_headers_t img = { 0 }; /* @@ -186,9 +234,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) } /* Link to it in the efi tables */ - systab.tables[0].guid = EFI_FDT_GUID; - systab.tables[0].table = fdt; - systab.nr_tables = 1; + efi_install_configuration_table(&fdt_guid, fdt); /* And reserve the space in the memory map */ fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK; @@ -201,7 +247,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) EFI_BOOT_SERVICES_DATA, true); } else { printf("WARNING: Invalid device tree, expect boot to fail\n"); - systab.nr_tables = 0; + efi_install_configuration_table(&fdt_guid, NULL); } /* Load the EFI payload */ @@ -210,38 +256,14 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) return -ENOENT; /* Initialize and populate EFI object list */ - INIT_LIST_HEAD(&efi_obj_list); - list_add_tail(&loaded_image_info_obj.link, &efi_obj_list); - list_add_tail(&bootefi_device_obj.link, &efi_obj_list); -#ifdef CONFIG_PARTITIONS - efi_disk_register(); -#endif -#ifdef CONFIG_LCD - efi_gop_register(); -#endif -#ifdef CONFIG_NET - void *nethandle = loaded_image_info.device_handle; - efi_net_register(&nethandle); - - if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6)) - loaded_image_info.device_handle = nethandle; - else - loaded_image_info.device_handle = bootefi_device_path; -#endif -#ifdef CONFIG_GENERATE_SMBIOS_TABLE - efi_smbios_register(); -#endif - - /* Initialize EFI runtime services */ - efi_reset_system_init(); - efi_get_time_init(); + if (!efi_obj_list_initalized) + efi_init_obj_list(); /* Call our payload! */ debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry); if (setjmp(&loaded_image_info.exit_jmp)) { - efi_status_t status = loaded_image_info.exit_status; - return status == EFI_SUCCESS ? 0 : -EINVAL; + return loaded_image_info.exit_status; } #ifdef CONFIG_ARM64 @@ -260,7 +282,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) } #endif - return entry(&loaded_image_info, &systab); + return efi_do_enter(&loaded_image_info, &systab, entry); } @@ -269,7 +291,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *saddr, *sfdt; unsigned long addr, fdt_addr = 0; - int r = 0; + unsigned long r; if (argc < 2) return CMD_RET_USAGE; @@ -294,12 +316,13 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf("## Starting EFI application at %08lx ...\n", addr); r = do_bootefi_exec((void *)addr, (void*)fdt_addr); - printf("## Application terminated, r = %d\n", r); + printf("## Application terminated, r = %lu\n", + r & ~EFI_ERROR_MASK); - if (r != 0) - r = 1; - - return r; + if (r != EFI_SUCCESS) + return 1; + else + return 0; } #ifdef CONFIG_SYS_LONGHELP @@ -325,7 +348,7 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { __maybe_unused struct blk_desc *desc; char devname[32] = { 0 }; /* dp->str is u16[32] long */ - char *colon; + char *colon, *s; #if defined(CONFIG_BLK) || CONFIG_IS_ENABLED(ISO_PARTITION) desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10)); @@ -370,5 +393,9 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) } else { snprintf(devname, sizeof(devname), "%s", path); } + /* DOS style file path: */ + s = devname; + while ((s = strchr(s, '/'))) + *s++ = '\\'; ascii2unicode(bootefi_image_path[0].str, devname); } diff --git a/cmd/bootm.c b/cmd/bootm.c index daf15d9e80..df0bbe19ca 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -138,7 +138,7 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) { - const char *ep = getenv("autostart"); + const char *ep = env_get("autostart"); if (ep && !strcmp(ep, "yes")) { char *local_args[2]; @@ -202,7 +202,7 @@ U_BOOT_CMD( #if defined(CONFIG_CMD_BOOTD) int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - return run_command(getenv("bootcmd"), flag); + return run_command(env_get("bootcmd"), flag); } U_BOOT_CMD( diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 5879065c2e..870db7c1de 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -53,7 +53,7 @@ static char *bootmenu_getoption(unsigned short int n) return NULL; sprintf(name, "bootmenu_%d", n); - return getenv(name); + return env_get(name); } static void bootmenu_print_entry(void *data) @@ -483,7 +483,7 @@ int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) delay_str = argv[1]; if (!delay_str) - delay_str = getenv("bootmenu_delay"); + delay_str = env_get("bootmenu_delay"); if (delay_str) delay = (int)simple_strtol(delay_str, NULL, 10); diff --git a/cmd/cbfs.c b/cmd/cbfs.c index 95a11a3616..799ba01fcc 100644 --- a/cmd/cbfs.c +++ b/cmd/cbfs.c @@ -80,7 +80,7 @@ static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, printf("\n%ld bytes read\n", size); - setenv_hex("filesize", size); + env_set_hex("filesize", size); return 0; } diff --git a/cmd/cramfs.c b/cmd/cramfs.c index 49ee36c74a..86f1bac272 100644 --- a/cmd/cramfs.c +++ b/cmd/cramfs.c @@ -104,7 +104,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) struct mtdids id; ulong addr; - addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16); + addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16); /* hack! */ /* cramfs_* only supports NOR flash chips */ @@ -117,9 +117,9 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) part.offset = (u64)(uintptr_t) map_sysmem(addr - OFFSET_ADJUSTMENT, 0); /* pre-set Boot file name */ - if ((filename = getenv("bootfile")) == NULL) { + filename = env_get("bootfile"); + if (!filename) filename = "uImage"; - } if (argc == 2) { filename = argv[1]; @@ -138,7 +138,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (size > 0) { printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n", size, offset); - setenv_hex("filesize", size); + env_set_hex("filesize", size); } else { printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename); } @@ -169,7 +169,7 @@ int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) struct mtdids id; ulong addr; - addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16); + addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16); /* hack! */ /* cramfs_* only supports NOR flash chips */ @@ -148,7 +148,7 @@ int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) unsigned long addr; /* Address of the ELF image */ unsigned long rc; /* Return value from user code */ char *sload = NULL; - const char *ep = getenv("autostart"); + const char *ep = env_get("autostart"); int rcode = 0; /* Consume 'bootelf' */ @@ -242,11 +242,11 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) */ #if defined(CONFIG_WALNUT) tmp = (char *)CONFIG_SYS_NVRAM_BASE_ADDR + 0x500; - eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); + eth_env_get_enetaddr("ethaddr", (uchar *)build_buf); memcpy(tmp, &build_buf[3], 3); #elif defined(CONFIG_SYS_VXWORKS_MAC_PTR) tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR; - eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); + eth_env_get_enetaddr("ethaddr", (uchar *)build_buf); memcpy(tmp, build_buf, 6); #else puts("## Ethernet MAC address not copied to NV RAM\n"); @@ -258,7 +258,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by * VxWorks BSP. For example, on PowerPC it defaults to 0x4200. */ - tmp = getenv("bootaddr"); + tmp = env_get("bootaddr"); if (!tmp) { printf("## VxWorks bootline address not specified\n"); } else { @@ -269,21 +269,21 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * parameter. If it is not defined, we may be able to * construct the info. */ - bootline = getenv("bootargs"); + bootline = env_get("bootargs"); if (bootline) { memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255)); flush_cache(bootaddr, max(strlen(bootline), (size_t)255)); } else { - tmp = getenv("bootdev"); + tmp = env_get("bootdev"); if (tmp) { strcpy(build_buf, tmp); ptr = strlen(tmp); } else printf("## VxWorks boot device not specified\n"); - tmp = getenv("bootfile"); + tmp = env_get("bootfile"); if (tmp) ptr += sprintf(build_buf + ptr, "host:%s ", tmp); @@ -295,12 +295,12 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * The following parameters are only needed if 'bootdev' * is an ethernet device, otherwise they are optional. */ - tmp = getenv("ipaddr"); + tmp = env_get("ipaddr"); if (tmp) { ptr += sprintf(build_buf + ptr, "e=%s", tmp); - tmp = getenv("netmask"); + tmp = env_get("netmask"); if (tmp) { - u32 mask = getenv_ip("netmask").s_addr; + u32 mask = env_get_ip("netmask").s_addr; ptr += sprintf(build_buf + ptr, ":%08x ", ntohl(mask)); } else { @@ -308,19 +308,19 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } } - tmp = getenv("serverip"); + tmp = env_get("serverip"); if (tmp) ptr += sprintf(build_buf + ptr, "h=%s ", tmp); - tmp = getenv("gatewayip"); + tmp = env_get("gatewayip"); if (tmp) ptr += sprintf(build_buf + ptr, "g=%s ", tmp); - tmp = getenv("hostname"); + tmp = env_get("hostname"); if (tmp) ptr += sprintf(build_buf + ptr, "tn=%s ", tmp); - tmp = getenv("othbootargs"); + tmp = env_get("othbootargs"); if (tmp) { strcpy(build_buf + ptr, tmp); ptr += strlen(tmp); @@ -341,12 +341,12 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Since E820 information is critical to the kernel, if we don't * specify these in the environments, use a default one. */ - tmp = getenv("e820data"); + tmp = env_get("e820data"); if (tmp) data = (struct e820entry *)simple_strtoul(tmp, NULL, 16); else data = (struct e820entry *)VXWORKS_E820_DATA_ADDR; - tmp = getenv("e820info"); + tmp = env_get("e820info"); if (tmp) info = (struct e820info *)simple_strtoul(tmp, NULL, 16); else diff --git a/cmd/fastboot/Kconfig b/cmd/fastboot/Kconfig index 89b9e73440..b84529a374 100644 --- a/cmd/fastboot/Kconfig +++ b/cmd/fastboot/Kconfig @@ -18,6 +18,8 @@ config CMD_FASTBOOT protocol for downloading images, flashing and device control used on Android devices. + See doc/README.android-fastboot for more information. + config ANDROID_BOOT_IMAGE bool "Enable support for Android Boot Images" help @@ -43,21 +43,21 @@ void set_working_fdt_addr(ulong addr) buf = map_sysmem(addr, 0); working_fdt = buf; - setenv_hex("fdtaddr", addr); + env_set_hex("fdtaddr", addr); } /* * Get a value from the fdt and format it to be set in the environment */ -static int fdt_value_setenv(const void *nodep, int len, const char *var) +static int fdt_value_env_set(const void *nodep, int len, const char *var) { if (is_printable_string(nodep, len)) - setenv(var, (void *)nodep); + env_set(var, (void *)nodep); else if (len == 4) { char buf[11]; sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep)); - setenv(var, buf); + env_set(var, buf); } else if (len%4 == 0 && len <= 20) { /* Needed to print things like sha1 hashes. */ char buf[41]; @@ -66,7 +66,7 @@ static int fdt_value_setenv(const void *nodep, int len, const char *var) for (i = 0; i < len; i += sizeof(unsigned int)) sprintf(buf + (i * 2), "%08x", *(unsigned int *)(nodep + i)); - setenv(var, buf); + env_set(var, buf); } else { printf("error: unprintable value\n"); return 1; @@ -111,7 +111,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; printf("The address of the fdt is %#08lx\n", control ? (ulong)map_to_sysmem(blob) : - getenv_hex("fdtaddr", 0)); + env_get_hex("fdtaddr", 0)); return 0; } @@ -358,10 +358,12 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (curDepth == startDepth + 1) curIndex++; if (subcmd[0] == 'n' && curIndex == reqIndex) { - const char *nodeName = fdt_get_name( - working_fdt, nextNodeOffset, NULL); + const char *node_name; - setenv(var, (char *)nodeName); + node_name = fdt_get_name(working_fdt, + nextNodeOffset, + NULL); + env_set(var, node_name); return 0; } nextNodeOffset = fdt_next_node( @@ -371,7 +373,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } if (subcmd[0] == 's') { /* get the num nodes at this level */ - setenv_ulong(var, curIndex + 1); + env_set_ulong(var, curIndex + 1); } else { /* node index not found */ printf("libfdt node not found\n"); @@ -382,13 +384,14 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) working_fdt, nodeoffset, prop, &len); if (len == 0) { /* no property value */ - setenv(var, ""); + env_set(var, ""); return 0; } else if (nodep && len > 0) { if (subcmd[0] == 'v') { int ret; - ret = fdt_value_setenv(nodep, len, var); + ret = fdt_value_env_set(nodep, len, + var); if (ret != 0) return ret; } else if (subcmd[0] == 'a') { @@ -396,13 +399,13 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char buf[11]; sprintf(buf, "0x%p", nodep); - setenv(var, buf); + env_set(var, buf); } else if (subcmd[0] == 's') { /* Get size */ char buf[11]; sprintf(buf, "0x%08X", len); - setenv(var, buf); + env_set(var, buf); } else return CMD_RET_USAGE; return 0; diff --git a/cmd/fpga.c b/cmd/fpga.c index 016349f560..ac6f504140 100644 --- a/cmd/fpga.c +++ b/cmd/fpga.c @@ -43,8 +43,8 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) int op, dev = FPGA_INVALID_DEVICE; size_t data_size = 0; void *fpga_data = NULL; - char *devstr = getenv("fpga"); - char *datastr = getenv("fpgadata"); + char *devstr = env_get("fpga"); + char *datastr = env_get("fpgadata"); int rc = FPGA_FAIL; int wrong_parms = 0; #if defined(CONFIG_FIT) @@ -19,6 +19,11 @@ #include <linux/ctype.h> #include <div64.h> #include <memalign.h> +#include <linux/compat.h> +#include <linux/sizes.h> +#include <stdlib.h> + +static LIST_HEAD(disk_partitions); /** * extract_env(): Expand env name from string format '&{env_name}' @@ -50,14 +55,14 @@ static int extract_env(const char *str, char **env) memset(s + strlen(s) - 1, '\0', 1); memmove(s, s + 2, strlen(s) - 1); - e = getenv(s); + e = env_get(s); if (e == NULL) { #ifdef CONFIG_RANDOM_UUID debug("%s unset. ", str); gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_GUID); - setenv(s, uuid_str); + env_set(s, uuid_str); - e = getenv(s); + e = env_get(s); if (e) { debug("Set to random.\n"); ret = 0; @@ -151,6 +156,208 @@ static bool found_key(const char *str, const char *key) return result; } +static int calc_parts_list_len(int numparts) +{ + int partlistlen = UUID_STR_LEN + 1 + strlen("uuid_disk="); + /* for the comma */ + partlistlen++; + + /* per-partition additions; numparts starts at 1, so this should be correct */ + partlistlen += numparts * (strlen("name=,") + PART_NAME_LEN + 1); + /* see part.h for definition of struct disk_partition */ + partlistlen += numparts * (strlen("start=MiB,") + sizeof(lbaint_t) + 1); + partlistlen += numparts * (strlen("size=MiB,") + sizeof(lbaint_t) + 1); + partlistlen += numparts * (strlen("uuid=;") + UUID_STR_LEN + 1); + /* for the terminating null */ + partlistlen++; + debug("Length of partitions_list is %d for %d partitions\n", partlistlen, + numparts); + return partlistlen; +} + +#ifdef CONFIG_CMD_GPT_RENAME +static void del_gpt_info(void) +{ + struct list_head *pos = &disk_partitions; + struct disk_part *curr; + while (!list_empty(pos)) { + curr = list_entry(pos->next, struct disk_part, list); + list_del(pos->next); + free(curr); + } +} + +static struct disk_part *allocate_disk_part(disk_partition_t *info, int partnum) +{ + struct disk_part *newpart; + newpart = malloc(sizeof(*newpart)); + if (!newpart) + return ERR_PTR(-ENOMEM); + memset(newpart, '\0', sizeof(newpart)); + + newpart->gpt_part_info.start = info->start; + newpart->gpt_part_info.size = info->size; + newpart->gpt_part_info.blksz = info->blksz; + strncpy((char *)newpart->gpt_part_info.name, (const char *)info->name, + PART_NAME_LEN); + newpart->gpt_part_info.name[PART_NAME_LEN - 1] = '\0'; + strncpy((char *)newpart->gpt_part_info.type, (const char *)info->type, + PART_TYPE_LEN); + newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0'; + newpart->gpt_part_info.bootable = info->bootable; +#ifdef CONFIG_PARTITION_UUIDS + strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid, + UUID_STR_LEN); + /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */ + newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0'; +#endif + newpart->partnum = partnum; + + return newpart; +} + +static void prettyprint_part_size(char *sizestr, lbaint_t partsize, + lbaint_t blksize) +{ + unsigned long long partbytes, partmegabytes; + + partbytes = partsize * blksize; + partmegabytes = lldiv(partbytes, SZ_1M); + snprintf(sizestr, 16, "%lluMiB", partmegabytes); +} + +static void print_gpt_info(void) +{ + struct list_head *pos; + struct disk_part *curr; + char partstartstr[16]; + char partsizestr[16]; + + list_for_each(pos, &disk_partitions) { + curr = list_entry(pos, struct disk_part, list); + prettyprint_part_size(partstartstr, curr->gpt_part_info.start, + curr->gpt_part_info.blksz); + prettyprint_part_size(partsizestr, curr->gpt_part_info.size, + curr->gpt_part_info.blksz); + + printf("Partition %d:\n", curr->partnum); + printf("Start %s, size %s\n", partstartstr, partsizestr); + printf("Block size %lu, name %s\n", curr->gpt_part_info.blksz, + curr->gpt_part_info.name); + printf("Type %s, bootable %d\n", curr->gpt_part_info.type, + curr->gpt_part_info.bootable); +#ifdef CONFIG_PARTITION_UUIDS + printf("UUID %s\n", curr->gpt_part_info.uuid); +#endif + printf("\n"); + } +} + +/* + * create the string that upstream 'gpt write' command will accept as an + * argument + * + * From doc/README.gpt, Format of partitions layout: + * "uuid_disk=...;name=u-boot,size=60MiB,uuid=...; + * name=kernel,size=60MiB,uuid=...;" + * The fields 'name' and 'size' are mandatory for every partition. + * The field 'start' is optional. The fields 'uuid' and 'uuid_disk' + * are optional if CONFIG_RANDOM_UUID is enabled. + */ +static int create_gpt_partitions_list(int numparts, const char *guid, + char *partitions_list) +{ + struct list_head *pos; + struct disk_part *curr; + char partstr[PART_NAME_LEN + 1]; + + if (!partitions_list) + return -EINVAL; + + strcpy(partitions_list, "uuid_disk="); + strncat(partitions_list, guid, UUID_STR_LEN + 1); + strcat(partitions_list, ";"); + + list_for_each(pos, &disk_partitions) { + curr = list_entry(pos, struct disk_part, list); + strcat(partitions_list, "name="); + strncat(partitions_list, (const char *)curr->gpt_part_info.name, + PART_NAME_LEN + 1); + strcat(partitions_list, ",start="); + prettyprint_part_size(partstr, (unsigned long)curr->gpt_part_info.start, + (unsigned long) curr->gpt_part_info.blksz); + /* one extra byte for NULL */ + strncat(partitions_list, partstr, PART_NAME_LEN + 1); + strcat(partitions_list, ",size="); + prettyprint_part_size(partstr, curr->gpt_part_info.size, + curr->gpt_part_info.blksz); + strncat(partitions_list, partstr, PART_NAME_LEN + 1); + + strcat(partitions_list, ",uuid="); + strncat(partitions_list, curr->gpt_part_info.uuid, + UUID_STR_LEN + 1); + strcat(partitions_list, ";"); + } + return 0; +} + +/* + * read partition info into disk_partitions list where + * it can be printed or modified + */ +static int get_gpt_info(struct blk_desc *dev_desc) +{ + /* start partition numbering at 1, as U-Boot does */ + int valid_parts = 0, p, ret; + disk_partition_t info; + struct disk_part *new_disk_part; + + /* + * Always re-read partition info from device, in case + * it has changed + */ + INIT_LIST_HEAD(&disk_partitions); + + for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { + ret = part_get_info(dev_desc, p, &info); + if (ret) + continue; + + /* Add 1 here because counter is zero-based but p1 is + the first partition */ + new_disk_part = allocate_disk_part(&info, valid_parts+1); + if (IS_ERR(new_disk_part)) + goto out; + + list_add_tail(&new_disk_part->list, &disk_partitions); + valid_parts++; + } + if (valid_parts == 0) { + printf("** No valid partitions found **\n"); + goto out; + } + return valid_parts; + out: + if (valid_parts >= 1) + del_gpt_info(); + return -ENODEV; +} + +/* a wrapper to test get_gpt_info */ +static int do_get_gpt_info(struct blk_desc *dev_desc) +{ + int ret; + + ret = get_gpt_info(dev_desc); + if (ret > 0) { + print_gpt_info(); + del_gpt_info(); + return 0; + } + return ret; +} +#endif + /** * set_gpt_info(): Fill partition information from string * function allocates memory, remember to free! @@ -178,6 +385,7 @@ static int set_gpt_info(struct blk_desc *dev_desc, int errno = 0; uint64_t size_ll, start_ll; lbaint_t offset = 0; + int max_str_part = calc_parts_list_len(MAX_SEARCH_PARTITIONS); debug("%s: lba num: 0x%x %d\n", __func__, (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba); @@ -186,6 +394,8 @@ static int set_gpt_info(struct blk_desc *dev_desc, return -1; str = strdup(str_part); + if (str == NULL) + return -ENOMEM; /* extract disk guid */ s = str; @@ -193,6 +403,8 @@ static int set_gpt_info(struct blk_desc *dev_desc, if (!val) { #ifdef CONFIG_RANDOM_UUID *str_disk_guid = malloc(UUID_STR_LEN + 1); + if (str_disk_guid == NULL) + return -ENOMEM; gen_rand_uuid_str(*str_disk_guid, UUID_STR_FORMAT_STD); #else free(str); @@ -207,10 +419,14 @@ static int set_gpt_info(struct blk_desc *dev_desc, /* Move s to first partition */ strsep(&s, ";"); } - if (strlen(s) == 0) + if (s == NULL) { + printf("Error: is the partitions string NULL-terminated?\n"); + return -EINVAL; + } + if (strnlen(s, max_str_part) == 0) return -3; - i = strlen(s) - 1; + i = strnlen(s, max_str_part) - 1; if (s[i] == ';') s[i] = '\0'; @@ -224,6 +440,8 @@ static int set_gpt_info(struct blk_desc *dev_desc, /* allocate memory for partitions */ parts = calloc(sizeof(disk_partition_t), p_count); + if (parts == NULL) + return -ENOMEM; /* retrieve partitions data from string */ for (i = 0; i < p_count; i++) { @@ -245,12 +463,12 @@ static int set_gpt_info(struct blk_desc *dev_desc, } else { if (extract_env(val, &p)) p = val; - if (strlen(p) >= sizeof(parts[i].uuid)) { + if (strnlen(p, max_str_part) >= sizeof(parts[i].uuid)) { printf("Wrong uuid format for partition %d\n", i); errno = -4; goto err; } - strcpy((char *)parts[i].uuid, p); + strncpy((char *)parts[i].uuid, p, max_str_part); free(val); } #ifdef CONFIG_PARTITION_TYPE_GUID @@ -260,13 +478,13 @@ static int set_gpt_info(struct blk_desc *dev_desc, /* 'type' is optional */ if (extract_env(val, &p)) p = val; - if (strlen(p) >= sizeof(parts[i].type_guid)) { + if (strnlen(p, max_str_part) >= sizeof(parts[i].type_guid)) { printf("Wrong type guid format for partition %d\n", i); errno = -4; goto err; } - strcpy((char *)parts[i].type_guid, p); + strncpy((char *)parts[i].type_guid, p, max_str_part); free(val); } #endif @@ -278,11 +496,11 @@ static int set_gpt_info(struct blk_desc *dev_desc, } if (extract_env(val, &p)) p = val; - if (strlen(p) >= sizeof(parts[i].name)) { + if (strnlen(p, max_str_part) >= sizeof(parts[i].name)) { errno = -4; goto err; } - strcpy((char *)parts[i].name, p); + strncpy((char *)parts[i].name, p, max_str_part); free(val); /* size */ @@ -398,6 +616,144 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part) return ret; } +static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr) +{ + int ret; + char disk_guid[UUID_STR_LEN + 1]; + + ret = get_disk_guid(dev_desc, disk_guid); + if (ret < 0) + return CMD_RET_FAILURE; + + if (namestr) + env_set(namestr, disk_guid); + else + printf("%s\n", disk_guid); + + return ret; +} + +#ifdef CONFIG_CMD_GPT_RENAME +static int do_rename_gpt_parts(struct blk_desc *dev_desc, char *subcomm, + char *name1, char *name2) +{ + struct list_head *pos; + struct disk_part *curr; + disk_partition_t *new_partitions = NULL; + char disk_guid[UUID_STR_LEN + 1]; + char *partitions_list, *str_disk_guid; + u8 part_count = 0; + int partlistlen, ret, numparts = 0, partnum, i = 1, ctr1 = 0, ctr2 = 0; + + if ((subcomm == NULL) || (name1 == NULL) || (name2 == NULL) || + (strcmp(subcomm, "swap") && (strcmp(subcomm, "rename")))) + return -EINVAL; + + ret = get_disk_guid(dev_desc, disk_guid); + if (ret < 0) + return ret; + numparts = get_gpt_info(dev_desc); + if (numparts <= 0) + return numparts ? numparts : -ENODEV; + + partlistlen = calc_parts_list_len(numparts); + partitions_list = malloc(partlistlen); + if (partitions_list == NULL) + return -ENOMEM; + memset(partitions_list, '\0', partlistlen); + + ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); + if (ret < 0) + return ret; + /* + * Uncomment the following line to print a string that 'gpt write' + * or 'gpt verify' will accept as input. + */ + debug("OLD partitions_list is %s with %u chars\n", partitions_list, + (unsigned)strlen(partitions_list)); + + ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, + &new_partitions, &part_count); + if (ret < 0) + return ret; + + if (!strcmp(subcomm, "swap")) { + if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > PART_NAME_LEN)) { + printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); + return -EINVAL; + } + list_for_each(pos, &disk_partitions) { + curr = list_entry(pos, struct disk_part, list); + if (!strcmp((char *)curr->gpt_part_info.name, name1)) { + strcpy((char *)curr->gpt_part_info.name, name2); + ctr1++; + } else if (!strcmp((char *)curr->gpt_part_info.name, name2)) { + strcpy((char *)curr->gpt_part_info.name, name1); + ctr2++; + } + } + if ((ctr1 + ctr2 < 2) || (ctr1 != ctr2)) { + printf("Cannot swap partition names except in pairs.\n"); + return -EINVAL; + } + } else { /* rename */ + if (strlen(name2) > PART_NAME_LEN) { + printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN); + return -EINVAL; + } + partnum = (int)simple_strtol(name1, NULL, 10); + if ((partnum < 0) || (partnum > numparts)) { + printf("Illegal partition number %s\n", name1); + return -EINVAL; + } + ret = part_get_info(dev_desc, partnum, new_partitions); + if (ret < 0) + return ret; + + /* U-Boot partition numbering starts at 1 */ + list_for_each(pos, &disk_partitions) { + curr = list_entry(pos, struct disk_part, list); + if (i == partnum) { + strcpy((char *)curr->gpt_part_info.name, name2); + break; + } + i++; + } + } + + ret = create_gpt_partitions_list(numparts, disk_guid, partitions_list); + if (ret < 0) + return ret; + debug("NEW partitions_list is %s with %u chars\n", partitions_list, + (unsigned)strlen(partitions_list)); + + ret = set_gpt_info(dev_desc, partitions_list, &str_disk_guid, + &new_partitions, &part_count); + if (ret < 0) + return ret; + + debug("Writing new partition table\n"); + ret = gpt_restore(dev_desc, disk_guid, new_partitions, numparts); + if (ret < 0) { + printf("Writing new partition table failed\n"); + return ret; + } + + debug("Reading back new partition table\n"); + numparts = get_gpt_info(dev_desc); + if (numparts <= 0) + return numparts ? numparts : -ENODEV; + printf("new partition table with %d partitions is:\n", numparts); + print_gpt_info(); + + del_gpt_info(); + free(partitions_list); + free(str_disk_guid); + free(new_partitions); + return ret; +} +#endif + /** * do_gpt(): Perform GPT operations * @@ -415,7 +771,11 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *ep; struct blk_desc *blk_dev_desc = NULL; +#ifndef CONFIG_CMD_GPT_RENAME if (argc < 4 || argc > 5) +#else + if (argc < 4 || argc > 6) +#endif return CMD_RET_USAGE; dev = (int)simple_strtoul(argv[3], &ep, 10); @@ -436,6 +796,15 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } else if ((strcmp(argv[1], "verify") == 0)) { ret = gpt_verify(blk_dev_desc, argv[4]); printf("Verify GPT: "); + } else if (strcmp(argv[1], "guid") == 0) { + ret = do_disk_guid(blk_dev_desc, argv[4]); +#ifdef CONFIG_CMD_GPT_RENAME + } else if (strcmp(argv[1], "read") == 0) { + ret = do_get_gpt_info(blk_dev_desc); + } else if ((strcmp(argv[1], "swap") == 0) || + (strcmp(argv[1], "rename") == 0)) { + ret = do_rename_gpt_parts(blk_dev_desc, argv[1], argv[4], argv[5]); +#endif } else { return CMD_RET_USAGE; } @@ -458,4 +827,24 @@ U_BOOT_CMD(gpt, CONFIG_SYS_MAXARGS, 1, do_gpt, " Example usage:\n" " gpt write mmc 0 $partitions\n" " gpt verify mmc 0 $partitions\n" + " read <interface> <dev>\n" + " - read GPT into a data structure for manipulation\n" + " guid <interface> <dev>\n" + " - print disk GUID\n" + " guid <interface> <dev> <varname>\n" + " - set environment variable to disk GUID\n" + " Example usage:\n" + " gpt guid mmc 0\n" + " gpt guid mmc 0 varname\n" +#ifdef CONFIG_CMD_GPT_RENAME + "gpt partition renaming commands:\n" + "gpt swap <interface> <dev> <name1> <name2>\n" + " - change all partitions named name1 to name2\n" + " and vice-versa\n" + "gpt rename <interface> <dev> <part> <name>\n" + " - rename the specified partition\n" + " Example usage:\n" + " gpt swap mmc 0 foo bar\n" + " gpt rename mmc 0 3 foo\n" +#endif ); @@ -219,7 +219,7 @@ static int ini_handler(void *user, char *section, char *name, char *value) for (i = 0; i < strlen(value); i++) value[i] = tolower(value[i]); #endif - setenv(name, value); + env_set(name, value); printf("ini: Imported %s as %s\n", name, value); } @@ -238,9 +238,9 @@ static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) section = argv[1]; file_address = (char *)simple_strtoul( - argc < 3 ? getenv("loadaddr") : argv[2], NULL, 16); + argc < 3 ? env_get("loadaddr") : argv[2], NULL, 16); file_size = (size_t)simple_strtoul( - argc < 4 ? getenv("filesize") : argv[3], NULL, 16); + argc < 4 ? env_get("filesize") : argv[3], NULL, 16); return ini_parse(file_address, file_size, ini_handler, (void *)section); } diff --git a/cmd/itest.c b/cmd/itest.c index e1896d9f97..70db04a04f 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -101,7 +101,7 @@ static char * evalstr(char *s) i++; } s[i] = 0; - return getenv((const char *)&s[2]); + return env_get((const char *)&s[2]); } else { return s; } diff --git a/cmd/jffs2.c b/cmd/jffs2.c index dc94705ccd..aee2f4513d 100644 --- a/cmd/jffs2.c +++ b/cmd/jffs2.c @@ -479,9 +479,9 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ulong offset = load_addr; /* pre-set Boot file name */ - if ((filename = getenv("bootfile")) == NULL) { + filename = env_get("bootfile"); + if (!filename) filename = "uImage"; - } if (argc == 2) { filename = argv[1]; @@ -512,7 +512,7 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (size > 0) { printf("### %s load complete: %d bytes loaded to 0x%lx\n", fsname, size, offset); - setenv_hex("filesize", size); + env_set_hex("filesize", size); } else { printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); } diff --git a/cmd/load.c b/cmd/load.c index 4597ec5618..519c309a61 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -50,11 +50,11 @@ static int do_load_serial(cmd_tbl_t *cmdtp, int flag, int argc, load_baudrate = current_baudrate = gd->baudrate; #endif - if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) { + env_echo = env_get("loads_echo"); + if (env_echo && *env_echo == '1') do_echo = 1; - } else { + else do_echo = 0; - } #ifdef CONFIG_SYS_LOADS_BAUD_CHANGE if (argc >= 2) { @@ -182,7 +182,7 @@ static ulong load_serial(long offset) start_addr, end_addr, size, size ); flush_cache(start_addr, size); - setenv_hex("filesize", size); + env_set_hex("filesize", size); return (addr); case SREC_START: break; @@ -427,9 +427,9 @@ static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc, offset = CONFIG_SYS_LOAD_ADDR; /* pre-set offset from $loadaddr */ - if ((s = getenv("loadaddr")) != NULL) { + s = env_get("loadaddr"); + if (s) offset = simple_strtoul(s, NULL, 16); - } load_baudrate = current_baudrate = gd->baudrate; @@ -529,7 +529,7 @@ static ulong load_serial_bin(ulong offset) flush_cache(offset, size); printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - setenv_hex("filesize", size); + env_set_hex("filesize", size); return offset; } @@ -1000,7 +1000,7 @@ static ulong load_serial_ymodem(ulong offset, int mode) flush_cache(offset, ALIGN(size, ARCH_DMA_MINALIGN)); printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - setenv_hex("filesize", size); + env_set_hex("filesize", size); return offset; } @@ -71,7 +71,8 @@ void logbuff_init_ptrs(void) #endif /* Set up log version */ - if ((s = getenv ("logversion")) != NULL) + s = env_get("logversion"); + if (s) log_version = (int)simple_strtoul(s, NULL, 10); if (log_version == 2) @@ -94,7 +95,8 @@ void logbuff_init_ptrs(void) log->v2.start = log->v2.con; /* Initialize default loglevel if present */ - if ((s = getenv ("loglevel")) != NULL) + s = env_get("loglevel"); + if (s) console_loglevel = (int)simple_strtoul(s, NULL, 10); gd->flags |= GD_FLG_LOGINIT; diff --git a/cmd/lzmadec.c b/cmd/lzmadec.c index c78df825e8..1b482edb58 100644 --- a/cmd/lzmadec.c +++ b/cmd/lzmadec.c @@ -42,7 +42,7 @@ static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) return 1; printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len, (ulong)src_len); - setenv_hex("filesize", src_len); + env_set_hex("filesize", src_len); return 0; } diff --git a/cmd/md5sum.c b/cmd/md5sum.c index 23bb81e88c..c737cb23b5 100644 --- a/cmd/md5sum.c +++ b/cmd/md5sum.c @@ -35,7 +35,7 @@ static void store_result(const u8 *sum, const char *dest) sprintf(str_ptr, "%02x", sum[i]); str_ptr += 2; } - setenv(dest, str_output); + env_set(dest, str_output); } } @@ -54,7 +54,7 @@ static int parse_verify_sum(char *verify_str, u8 *vsum) if (strlen(verify_str) == 32) vsum_str = verify_str; else { - vsum_str = getenv(verify_str); + vsum_str = env_get(verify_str); if (vsum_str == NULL || strlen(vsum_str) != 32) return 1; } diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c index 683c48bdad..615aa7459a 100644 --- a/cmd/mtdparts.c +++ b/cmd/mtdparts.c @@ -239,19 +239,19 @@ static void index_partitions(void) dev = list_entry(dentry, struct mtd_device, link); if (dev == current_mtd_dev) { mtddevnum += current_mtd_partnum; - setenv_ulong("mtddevnum", mtddevnum); + env_set_ulong("mtddevnum", mtddevnum); break; } mtddevnum += dev->num_parts; } part = mtd_part_info(current_mtd_dev, current_mtd_partnum); - setenv("mtddevname", part->name); + env_set("mtddevname", part->name); debug("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name); } else { - setenv("mtddevnum", NULL); - setenv("mtddevname", NULL); + env_set("mtddevnum", NULL); + env_set("mtddevname", NULL); debug("=> mtddevnum NULL\n=> mtddevname NULL\n"); } @@ -270,12 +270,12 @@ static void current_save(void) sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type), current_mtd_dev->id->num, current_mtd_partnum); - setenv("partition", buf); + env_set("partition", buf); strncpy(last_partition, buf, 16); debug("=> partition %s\n", buf); } else { - setenv("partition", NULL); + env_set("partition", NULL); last_partition[0] = '\0'; debug("=> partition NULL\n"); @@ -1213,9 +1213,9 @@ static int generate_mtdparts_save(char *buf, u32 buflen) ret = generate_mtdparts(buf, buflen); if ((buf[0] != '\0') && (ret == 0)) - setenv("mtdparts", buf); + env_set("mtdparts", buf); else - setenv("mtdparts", NULL); + env_set("mtdparts", NULL); return ret; } @@ -1533,11 +1533,11 @@ static int spread_partitions(void) * @param buf temporary buffer pointer MTDPARTS_MAXLEN long * @return mtdparts variable string, NULL if not found */ -static const char *getenv_mtdparts(char *buf) +static const char *env_get_mtdparts(char *buf) { if (gd->flags & GD_FLG_ENV_READY) - return getenv("mtdparts"); - if (getenv_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1) + return env_get("mtdparts"); + if (env_get_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1) return buf; return NULL; } @@ -1565,7 +1565,7 @@ static int parse_mtdparts(const char *const mtdparts) } /* re-read 'mtdparts' variable, mtd_devices_init may be updating env */ - p = getenv_mtdparts(tmp_parts); + p = env_get_mtdparts(tmp_parts); if (!p) p = mtdparts; @@ -1741,9 +1741,9 @@ int mtdparts_init(void) } /* get variables */ - ids = getenv("mtdids"); - parts = getenv_mtdparts(tmp_parts); - current_partition = getenv("partition"); + ids = env_get("mtdids"); + parts = env_get_mtdparts(tmp_parts); + current_partition = env_get("partition"); /* save it for later parsing, cannot rely on current partition pointer * as 'partition' variable may be updated during init */ @@ -1764,7 +1764,7 @@ int mtdparts_init(void) if (mtdids_default) { debug("mtdids variable not defined, using default\n"); ids = mtdids_default; - setenv("mtdids", (char *)ids); + env_set("mtdids", (char *)ids); } else { printf("mtdids not defined, no default present\n"); return 1; @@ -1780,7 +1780,7 @@ int mtdparts_init(void) if (!parts) { if (mtdparts_default && use_defaults) { parts = mtdparts_default; - if (setenv("mtdparts", (char *)parts) == 0) + if (env_set("mtdparts", (char *)parts) == 0) use_defaults = 0; } else printf("mtdparts variable not set, see 'help mtdparts'\n"); @@ -1850,7 +1850,7 @@ int mtdparts_init(void) current_mtd_partnum = pnum; current_save(); } - } else if (getenv("partition") == NULL) { + } else if (env_get("partition") == NULL) { debug("no partition variable set, setting...\n"); current_save(); } @@ -1956,9 +1956,9 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, { if (argc == 2) { if (strcmp(argv[1], "default") == 0) { - setenv("mtdids", NULL); - setenv("mtdparts", NULL); - setenv("partition", NULL); + env_set("mtdids", NULL); + env_set("mtdparts", NULL); + env_set("partition", NULL); use_defaults = 1; mtdparts_init(); @@ -1967,7 +1967,7 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, /* this may be the first run, initialize lists if needed */ mtdparts_init(); - setenv("mtdparts", NULL); + env_set("mtdparts", NULL); /* mtd_devices_init() calls current_save() */ return mtd_devices_init(); diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c index ea46e7b108..a1997ac0d3 100644 --- a/cmd/mvebu/bubt.c +++ b/cmd/mvebu/bubt.c @@ -98,7 +98,7 @@ static ulong get_load_addr(void) const char *addr_str; unsigned long addr; - addr_str = getenv("loadaddr"); + addr_str = env_get("loadaddr"); if (addr_str) addr = simple_strtoul(addr_str, NULL, 16); else diff --git a/cmd/nand.c b/cmd/nand.c index a2152ec826..a22945d144 100644 --- a/cmd/nand.c +++ b/cmd/nand.c @@ -305,9 +305,9 @@ static void nand_print_and_set_info(int idx) printf(" bbt options 0x%08x\n", chip->bbt_options); /* Set geometry info */ - setenv_hex("nand_writesize", mtd->writesize); - setenv_hex("nand_oobsize", mtd->oobsize); - setenv_hex("nand_erasesize", mtd->erasesize); + env_set_hex("nand_writesize", mtd->writesize); + env_set_hex("nand_oobsize", mtd->oobsize); + env_set_hex("nand_erasesize", mtd->erasesize); } static int raw_access(struct mtd_info *mtd, ulong addr, loff_t off, @@ -383,7 +383,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #else int quiet = 0; #endif - const char *quiet_str = getenv("quiet"); + const char *quiet_str = env_get("quiet"); int dev = nand_curr_device; int repeat = flag & CMD_FLAG_REPEAT; @@ -966,11 +966,11 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc, switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; - boot_device = getenv("bootdevice"); + boot_device = env_get("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); - boot_device = getenv("bootdevice"); + boot_device = env_get("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); @@ -42,7 +42,7 @@ U_BOOT_CMD( ); #ifdef CONFIG_CMD_TFTPPUT -int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { return netboot_common(TFTPPUT, cmdtp, argc, argv); } @@ -116,23 +116,23 @@ static void netboot_update_env(void) if (net_gateway.s_addr) { ip_to_string(net_gateway, tmp); - setenv("gatewayip", tmp); + env_set("gatewayip", tmp); } if (net_netmask.s_addr) { ip_to_string(net_netmask, tmp); - setenv("netmask", tmp); + env_set("netmask", tmp); } if (net_hostname[0]) - setenv("hostname", net_hostname); + env_set("hostname", net_hostname); if (net_root_path[0]) - setenv("rootpath", net_root_path); + env_set("rootpath", net_root_path); if (net_ip.s_addr) { ip_to_string(net_ip, tmp); - setenv("ipaddr", tmp); + env_set("ipaddr", tmp); } #if !defined(CONFIG_BOOTP_SERVERIP) /* @@ -141,32 +141,32 @@ static void netboot_update_env(void) */ if (net_server_ip.s_addr) { ip_to_string(net_server_ip, tmp); - setenv("serverip", tmp); + env_set("serverip", tmp); } #endif if (net_dns_server.s_addr) { ip_to_string(net_dns_server, tmp); - setenv("dnsip", tmp); + env_set("dnsip", tmp); } #if defined(CONFIG_BOOTP_DNS2) if (net_dns_server2.s_addr) { ip_to_string(net_dns_server2, tmp); - setenv("dnsip2", tmp); + env_set("dnsip2", tmp); } #endif if (net_nis_domain[0]) - setenv("domain", net_nis_domain); + env_set("domain", net_nis_domain); #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) if (net_ntp_time_offset) { sprintf(tmp, "%d", net_ntp_time_offset); - setenv("timeoffset", tmp); + env_set("timeoffset", tmp); } #endif #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) if (net_ntp_server.s_addr) { ip_to_string(net_ntp_server, tmp); - setenv("ntpserverip", tmp); + env_set("ntpserverip", tmp); } #endif } @@ -181,7 +181,7 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc, ulong addr; /* pre-set load_addr */ - s = getenv("loadaddr"); + s = env_get("loadaddr"); if (s != NULL) load_addr = simple_strtoul(s, NULL, 16); @@ -291,14 +291,14 @@ static void cdp_update_env(void) printf("CDP offered appliance VLAN %d\n", ntohs(cdp_appliance_vlan)); vlan_to_string(cdp_appliance_vlan, tmp); - setenv("vlan", tmp); + env_set("vlan", tmp); net_our_vlan = cdp_appliance_vlan; } if (cdp_native_vlan != htons(-1)) { printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan)); vlan_to_string(cdp_native_vlan, tmp); - setenv("nvlan", tmp); + env_set("nvlan", tmp); net_native_vlan = cdp_native_vlan; } } @@ -331,7 +331,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *toff; if (argc < 2) { - net_ntp_server = getenv_ip("ntpserverip"); + net_ntp_server = env_get_ip("ntpserverip"); if (net_ntp_server.s_addr == 0) { printf("ntpserverip not set\n"); return CMD_RET_FAILURE; @@ -344,7 +344,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } } - toff = getenv("timeoffset"); + toff = env_get("timeoffset"); if (toff == NULL) net_ntp_time_offset = 0; else @@ -423,14 +423,14 @@ static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, net_gateway.s_addr = 0; ip_to_string(net_gateway, tmp); - setenv("gatewayip", tmp); + env_set("gatewayip", tmp); ip_to_string(net_netmask, tmp); - setenv("netmask", tmp); + env_set("netmask", tmp); ip_to_string(net_ip, tmp); - setenv("ipaddr", tmp); - setenv("llipaddr", tmp); /* store this for next time */ + env_set("ipaddr", tmp); + env_set("llipaddr", tmp); /* store this for next time */ return CMD_RET_SUCCESS; } diff --git a/cmd/nvedit.c b/cmd/nvedit.c index cd17db6409..4033d90c8e 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -283,7 +283,7 @@ static int _do_env_set(int flag, int argc, char * const argv[], int env_flag) return 0; } -int setenv(const char *varname, const char *varvalue) +int env_set(const char *varname, const char *varvalue) { const char * const argv[4] = { "setenv", varname, varvalue, NULL }; @@ -304,12 +304,12 @@ int setenv(const char *varname, const char *varvalue) * @param value Value to set it to * @return 0 if ok, 1 on error */ -int setenv_ulong(const char *varname, ulong value) +int env_set_ulong(const char *varname, ulong value) { /* TODO: this should be unsigned */ char *str = simple_itoa(value); - return setenv(varname, str); + return env_set(varname, str); } /** @@ -319,21 +319,21 @@ int setenv_ulong(const char *varname, ulong value) * @param value Value to set it to * @return 0 if ok, 1 on error */ -int setenv_hex(const char *varname, ulong value) +int env_set_hex(const char *varname, ulong value) { char str[17]; sprintf(str, "%lx", value); - return setenv(varname, str); + return env_set(varname, str); } -ulong getenv_hex(const char *varname, ulong default_val) +ulong env_get_hex(const char *varname, ulong default_val) { const char *s; ulong value; char *endp; - s = getenv(varname); + s = env_get(varname); if (s) value = simple_strtoul(s, &endp, 16); if (!s || endp == s) @@ -594,7 +594,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, return 1; /* Set read buffer to initial value or empty sting */ - init_val = getenv(argv[1]); + init_val = env_get(argv[1]); if (init_val) snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val); else @@ -622,7 +622,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, * return address of storage for that variable, * or NULL if not found */ -char *getenv(const char *name) +char *env_get(const char *name) { if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ ENTRY e, *ep; @@ -637,7 +637,7 @@ char *getenv(const char *name) } /* restricted capabilities before import */ - if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) + if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) return (char *)(gd->env_buf); return NULL; @@ -646,7 +646,7 @@ char *getenv(const char *name) /* * Look up variable from environment for restricted C runtime env. */ -int getenv_f(const char *name, char *buf, unsigned len) +int env_get_f(const char *name, char *buf, unsigned len) { int i, nxt; @@ -690,13 +690,13 @@ int getenv_f(const char *name, char *buf, unsigned len) * found * @return the decoded value, or default_val if not found */ -ulong getenv_ulong(const char *name, int base, ulong default_val) +ulong env_get_ulong(const char *name, int base, ulong default_val) { /* - * We can use getenv() here, even before relocation, since the + * We can use env_get() here, even before relocation, since the * environment variable value is an integer and thus short. */ - const char *str = getenv(name); + const char *str = env_get(name); return str ? simple_strtoul(str, NULL, base) : default_val; } @@ -706,9 +706,11 @@ ulong getenv_ulong(const char *name, int base, ulong default_val) static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - printf("Saving Environment to %s...\n", env_name_spec); + struct env_driver *env = env_driver_lookup_default(); - return saveenv() ? 1 : 0; + printf("Saving Environment to %s...\n", env->name); + + return env_save() ? 1 : 0; } U_BOOT_CMD( @@ -929,7 +931,7 @@ NXTARG: ; return 1; } sprintf(buf, "%zX", (size_t)len); - setenv("filesize", buf); + env_set("filesize", buf); return 0; } @@ -955,7 +957,7 @@ NXTARG: ; envp->flags = ACTIVE_FLAG; #endif } - setenv_hex("filesize", len + offsetof(env_t, data)); + env_set_hex("filesize", len + offsetof(env_t, data)); return 0; diff --git a/cmd/nvme.c b/cmd/nvme.c new file mode 100644 index 0000000000..e1ef95fdf3 --- /dev/null +++ b/cmd/nvme.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2017 NXP Semiconductors + * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <nvme.h> +#include <part.h> +#include <linux/math64.h> + +static int nvme_curr_device; + +static int do_nvme_scan(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + int ret; + + ret = nvme_scan_namespace(); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + +static int do_nvme_list(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + blk_list_devices(IF_TYPE_NVME); + + return CMD_RET_SUCCESS; +} + +static int do_nvme_info(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + int devnum; + struct udevice *udev; + int ret; + + if (argc > 1) + devnum = (int)simple_strtoul(argv[1], NULL, 10); + else + devnum = nvme_curr_device; + + ret = blk_get_device(IF_TYPE_NVME, devnum, &udev); + if (ret < 0) + return CMD_RET_FAILURE; + + nvme_print_info(udev); + + return CMD_RET_SUCCESS; +} + +static int do_nvme_device(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + if (argc > 1) { + int devnum = (int)simple_strtoul(argv[1], NULL, 10); + + if (!blk_show_device(IF_TYPE_NVME, devnum)) { + nvme_curr_device = devnum; + printf("... is now current device\n"); + } else { + return CMD_RET_FAILURE; + } + } else { + blk_show_device(IF_TYPE_NVME, nvme_curr_device); + } + + return CMD_RET_SUCCESS; +} + +static int do_nvme_part(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + if (argc > 1) { + int devnum = (int)simple_strtoul(argv[2], NULL, 10); + + if (blk_print_part_devnum(IF_TYPE_NVME, devnum)) { + printf("\nNVMe device %d not available\n", devnum); + return CMD_RET_FAILURE; + } + } else { + blk_print_part_devnum(IF_TYPE_NVME, nvme_curr_device); + } + + return CMD_RET_SUCCESS; +} + +static int do_nvme_read(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + unsigned long time; + if (argc != 4) + return CMD_RET_USAGE; + + ulong addr = simple_strtoul(argv[1], NULL, 16); + ulong cnt = simple_strtoul(argv[3], NULL, 16); + ulong n; + lbaint_t blk = simple_strtoul(argv[2], NULL, 16); + + printf("\nNVMe read: device %d block # " LBAFU " count %ld ... ", + nvme_curr_device, blk, cnt); + + time = get_timer(0); + n = blk_read_devnum(IF_TYPE_NVME, nvme_curr_device, blk, + cnt, (ulong *)addr); + time = get_timer(time); + + printf("read: %s\n", (n == cnt) ? "OK" : "ERROR"); + printf("%lu bytes read in %lu ms", cnt * 512, time); + if (time > 0) { + puts(" ("); + print_size(div_u64(cnt * 512, time) * 1000, "/s"); + puts(")"); + } + puts("\n"); + + return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; +} + +static int do_nvme_write(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + unsigned long time; + if (argc != 4) + return CMD_RET_USAGE; + + ulong addr = simple_strtoul(argv[1], NULL, 16); + ulong cnt = simple_strtoul(argv[3], NULL, 16); + ulong n; + lbaint_t blk = simple_strtoul(argv[2], NULL, 16); + + printf("\nNVMe write: device %d block # " LBAFU " count %ld ... ", + nvme_curr_device, blk, cnt); + + time = get_timer(0); + n = blk_write_devnum(IF_TYPE_NVME, nvme_curr_device, blk, + cnt, (ulong *)addr); + time = get_timer(time); + + printf("write: %s\n", (n == cnt) ? "OK" : "ERROR"); + printf("%lu bytes write in %lu ms", cnt * 512, time); + if (time > 0) { + puts(" ("); + print_size(div_u64(cnt * 512, time) * 1000, "/s"); + puts(")"); + } + puts("\n"); + + return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; +} + +static cmd_tbl_t cmd_nvme[] = { + U_BOOT_CMD_MKENT(scan, 1, 1, do_nvme_scan, "", ""), + U_BOOT_CMD_MKENT(list, 1, 1, do_nvme_list, "", ""), + U_BOOT_CMD_MKENT(info, 2, 1, do_nvme_info, "", ""), + U_BOOT_CMD_MKENT(device, 2, 1, do_nvme_device, "", ""), + U_BOOT_CMD_MKENT(part, 2, 1, do_nvme_part, "", ""), + U_BOOT_CMD_MKENT(write, 4, 0, do_nvme_write, "", ""), + U_BOOT_CMD_MKENT(read, 4, 0, do_nvme_read, "", "") +}; + +static int do_nvmecops(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + cmd_tbl_t *cp; + + cp = find_cmd_tbl(argv[1], cmd_nvme, ARRAY_SIZE(cmd_nvme)); + + argc--; + argv++; + + if (cp == NULL || argc > cp->maxargs) + return CMD_RET_USAGE; + + if (flag == CMD_FLAG_REPEAT && !cp->repeatable) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + nvme, 8, 1, do_nvmecops, + "NVM Express sub-system", + "\nnvme scan - scan NVMe blk devices\n" + "nvme list - show all available NVMe blk devices\n" + "nvme info [dev]- show current or a specific NVMe blk device\n" + "nvme device [dev] - show or set current device\n" + "nvme part [dev] - print partition table\n" + "nvme read addr blk# cnt\n" + "nvme write addr blk# cnt" +); diff --git a/cmd/part.c b/cmd/part.c index 8ba05984e4..746bf40b2d 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -38,7 +38,7 @@ static int do_part_uuid(int argc, char * const argv[]) return 1; if (argc > 2) - setenv(argv[2], info.uuid); + env_set(argv[2], info.uuid); else printf("%s\n", info.uuid); @@ -99,7 +99,7 @@ static int do_part_list(int argc, char * const argv[]) sprintf(t, "%s%x", str[0] ? " " : "", p); strcat(str, t); } - setenv(var, str); + env_set(var, str); return 0; } @@ -135,7 +135,7 @@ static int do_part_start(int argc, char * const argv[]) snprintf(buf, sizeof(buf), LBAF, info.start); if (argc > 3) - setenv(argv[3], buf); + env_set(argv[3], buf); else printf("%s\n", buf); @@ -169,7 +169,7 @@ static int do_part_size(int argc, char * const argv[]) snprintf(buf, sizeof(buf), LBAF, info.size); if (argc > 3) - setenv(argv[3], buf); + env_set(argv[3], buf); else printf("%s\n", buf); @@ -694,7 +694,7 @@ static int do_pci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if ((bdf = get_pci_dev(argv[2])) == -1) return 1; break; -#if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI) +#if defined(CONFIG_DM_PCI) case 'e': pci_init(); return 0; @@ -782,7 +782,7 @@ static int do_pci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) static char pci_help_text[] = "[bus] [long]\n" " - short or long list of PCI devices on bus 'bus'\n" -#if defined(CONFIG_CMD_PCI_ENUM) || defined(CONFIG_DM_PCI) +#if defined(CONFIG_DM_PCI) "pci enum\n" " - Enumerate PCI buses\n" #endif diff --git a/cmd/portio.c b/cmd/portio.c deleted file mode 100644 index bf3a99791c..0000000000 --- a/cmd/portio.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * (C) Copyright 2003 - * Marc Singer, elf@buici.com - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -/* - * Port I/O Functions - * - * Copied from FADS ROM, Dan Malek (dmalek@jlc.net) - */ - -#include <common.h> -#include <command.h> - -/* Display values from last command. - * Memory modify remembered values are different from display memory. - */ -static uint in_last_addr, in_last_size; -static uint out_last_addr, out_last_size, out_last_value; - - -int do_portio_out (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) -{ - uint addr = out_last_addr; - uint size = out_last_size; - uint value = out_last_value; - - if (argc != 3) - return CMD_RET_USAGE; - - if ((flag & CMD_FLAG_REPEAT) == 0) { - /* - * New command specified. Check for a size specification. - * Defaults to long if no or incorrect specification. - */ - size = cmd_get_data_size (argv[0], 1); - addr = simple_strtoul (argv[1], NULL, 16); - value = simple_strtoul (argv[2], NULL, 16); - } -#if defined (CONFIG_X86) - - { - unsigned short port = addr; - - switch (size) { - default: - case 1: - { - unsigned char ch = value; - __asm__ volatile ("out %0, %%dx"::"a" (ch), "d" (port)); - } - break; - case 2: - { - unsigned short w = value; - __asm__ volatile ("out %0, %%dx"::"a" (w), "d" (port)); - } - break; - case 4: - __asm__ volatile ("out %0, %%dx"::"a" (value), "d" (port)); - - break; - } - } - -#endif /* CONFIG_X86 */ - - out_last_addr = addr; - out_last_size = size; - out_last_value = value; - - return 0; -} - -U_BOOT_CMD( - out, 3, 1, do_portio_out, - "write datum to IO port", - "[.b, .w, .l] port value\n - output to IO port" -); - -int do_portio_in (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) -{ - uint addr = in_last_addr; - uint size = in_last_size; - - if (argc != 2) - return CMD_RET_USAGE; - - if ((flag & CMD_FLAG_REPEAT) == 0) { - /* - * New command specified. Check for a size specification. - * Defaults to long if no or incorrect specification. - */ - size = cmd_get_data_size (argv[0], 1); - addr = simple_strtoul (argv[1], NULL, 16); - } -#if defined (CONFIG_X86) - - { - unsigned short port = addr; - - switch (size) { - default: - case 1: - { - unsigned char ch; - __asm__ volatile ("in %%dx, %0":"=a" (ch):"d" (port)); - - printf (" %02x\n", ch); - } - break; - case 2: - { - unsigned short w; - __asm__ volatile ("in %%dx, %0":"=a" (w):"d" (port)); - - printf (" %04x\n", w); - } - break; - case 4: - { - unsigned long l; - __asm__ volatile ("in %%dx, %0":"=a" (l):"d" (port)); - - printf (" %08lx\n", l); - } - break; - } - } -#endif /* CONFIG_X86 */ - - in_last_addr = addr; - in_last_size = size; - - return 0; -} - -U_BOOT_CMD( - in, 2, 1, do_portio_in, - "read data from an IO port", - "[.b, .w, .l] port\n" - " - read datum from IO port" -); @@ -33,15 +33,15 @@ const char *pxe_default_paths[] = { static bool is_pxe; /* - * Like getenv, but prints an error if envvar isn't defined in the - * environment. It always returns what getenv does, so it can be used in - * place of getenv without changing error handling otherwise. + * Like env_get, but prints an error if envvar isn't defined in the + * environment. It always returns what env_get does, so it can be used in + * place of env_get without changing error handling otherwise. */ static char *from_env(const char *envvar) { char *ret; - ret = getenv(envvar); + ret = env_get(envvar); if (!ret) printf("missing environment variable: %s\n", envvar); @@ -70,8 +70,7 @@ static int format_mac_pxe(char *outbuf, size_t outbuf_len) return -EINVAL; } - if (!eth_getenv_enetaddr_by_index("eth", eth_get_dev_index(), - ethaddr)) + if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr)) return -ENOENT; sprintf(outbuf, "01-%02x-%02x-%02x-%02x-%02x-%02x", @@ -591,7 +590,7 @@ static int label_localboot(struct pxe_label *label) char bootargs[CONFIG_SYS_CBSIZE]; cli_simple_process_macros(label->append, bootargs); - setenv("bootargs", bootargs); + env_set("bootargs", bootargs); } debug("running: %s\n", localcmd); @@ -649,9 +648,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) } bootm_argv[2] = initrd_str; - strcpy(bootm_argv[2], getenv("ramdisk_addr_r")); + strcpy(bootm_argv[2], env_get("ramdisk_addr_r")); strcat(bootm_argv[2], ":"); - strcat(bootm_argv[2], getenv("filesize")); + strcat(bootm_argv[2], env_get("filesize")); } if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) { @@ -662,8 +661,8 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) if (label->ipappend & 0x1) { sprintf(ip_str, " ip=%s:%s:%s:%s", - getenv("ipaddr"), getenv("serverip"), - getenv("gatewayip"), getenv("netmask")); + env_get("ipaddr"), env_get("serverip"), + env_get("gatewayip"), env_get("netmask")); } #ifdef CONFIG_CMD_NET @@ -695,11 +694,11 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) strcat(bootargs, mac_str); cli_simple_process_macros(bootargs, finalbootargs); - setenv("bootargs", finalbootargs); + env_set("bootargs", finalbootargs); printf("append: %s\n", finalbootargs); } - bootm_argv[1] = getenv("kernel_addr_r"); + bootm_argv[1] = env_get("kernel_addr_r"); /* * fdt usage is optional: @@ -714,7 +713,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) * * Scenario 3: fdt blob is not available. */ - bootm_argv[3] = getenv("fdt_addr_r"); + bootm_argv[3] = env_get("fdt_addr_r"); /* if fdt label is defined then get fdt from server */ if (bootm_argv[3]) { @@ -726,7 +725,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) } else if (label->fdtdir) { char *f1, *f2, *f3, *f4, *slash; - f1 = getenv("fdtfile"); + f1 = env_get("fdtfile"); if (f1) { f2 = ""; f3 = ""; @@ -739,9 +738,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) * or the boot scripts should set $fdtfile * before invoking "pxe" or "sysboot". */ - f1 = getenv("soc"); + f1 = env_get("soc"); f2 = "-"; - f3 = getenv("board"); + f3 = env_get("board"); f4 = ".dtb"; } @@ -781,7 +780,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) } if (!bootm_argv[3]) - bootm_argv[3] = getenv("fdt_addr"); + bootm_argv[3] = env_get("fdt_addr"); if (bootm_argv[3]) { if (!bootm_argv[2]) @@ -1671,10 +1670,10 @@ static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } if (argc < 6) - filename = getenv("bootfile"); + filename = env_get("bootfile"); else { filename = argv[5]; - setenv("bootfile", filename); + env_set("bootfile", filename); } if (strstr(argv[3], "ext2")) @@ -55,7 +55,7 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr) * when invoking qemu), do not update bootargs */ if (*data_addr != '\0') { - if (setenv("bootargs", data_addr) < 0) + if (env_set("bootargs", data_addr) < 0) printf("warning: unable to change bootargs\n"); } } @@ -123,7 +123,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag, void *load_addr; void *initrd_addr; - env = getenv("loadaddr"); + env = env_get("loadaddr"); load_addr = env ? (void *)simple_strtoul(env, NULL, 16) : #ifdef CONFIG_LOADADDR @@ -132,7 +132,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag, NULL; #endif - env = getenv("ramdiskaddr"); + env = env_get("ramdiskaddr"); initrd_addr = env ? (void *)simple_strtoul(env, NULL, 16) : #ifdef CONFIG_RAMDISK_ADDR diff --git a/cmd/read.c b/cmd/read.c index 61d8ce73e4..ecf925426f 100644 --- a/cmd/read.c +++ b/cmd/read.c @@ -66,7 +66,7 @@ int do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } - if (blk_read(dev_desc, offset + blk, cnt, addr) < 0) { + if (blk_dread(dev_desc, offset + blk, cnt, addr) < 0) { printf("Error reading blocks\n"); return 1; } diff --git a/cmd/reiser.c b/cmd/reiser.c index 9c3e9e9e58..e10c7b9eba 100644 --- a/cmd/reiser.c +++ b/cmd/reiser.c @@ -88,18 +88,18 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) switch (argc) { case 3: - addr_str = getenv("loadaddr"); + addr_str = env_get("loadaddr"); if (addr_str != NULL) { addr = simple_strtoul (addr_str, NULL, 16); } else { addr = CONFIG_SYS_LOAD_ADDR; } - filename = getenv ("bootfile"); + filename = env_get("bootfile"); count = 0; break; case 4: addr = simple_strtoul (argv[3], NULL, 16); - filename = getenv ("bootfile"); + filename = env_get("bootfile"); count = 0; break; case 5: @@ -157,7 +157,7 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) load_addr = addr; printf ("\n%ld bytes read\n", filelen); - setenv_hex("filesize", filelen); + env_set_hex("filesize", filelen); return filelen; } diff --git a/cmd/scsi.c b/cmd/scsi.c index 570971891e..8e36de107e 100644 --- a/cmd/scsi.c +++ b/cmd/scsi.c @@ -36,7 +36,9 @@ static int do_scsi(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) case 2: if (strncmp(argv[1], "res", 3) == 0) { printf("\nReset SCSI\n"); +#ifndef CONFIG_DM_SCSI scsi_bus_reset(NULL); +#endif ret = scsi_scan(true); if (ret) return CMD_RET_FAILURE; diff --git a/cmd/setexpr.c b/cmd/setexpr.c index e7194fc4f4..af210225f1 100644 --- a/cmd/setexpr.c +++ b/cmd/setexpr.c @@ -145,7 +145,7 @@ static int regex_sub(const char *name, } if (t == NULL) { - value = getenv(name); + value = env_get(name); if (value == NULL) { printf("## Error: variable \"%s\" not defined\n", name); @@ -282,11 +282,11 @@ static int regex_sub(const char *name, if (!global) break; } - debug("## FINAL (now setenv()) : %s\n", data); + debug("## FINAL (now env_set()) : %s\n", data); printf("%s=%s\n", name, data); - return setenv(name, data); + return env_set(name, data); } #endif @@ -314,7 +314,7 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* plain assignment: "setexpr name value" */ if (argc == 3) { - setenv_hex(argv[1], a); + env_set_hex(argv[1], a); return 0; } @@ -370,7 +370,7 @@ static int do_setexpr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } - setenv_hex(argv[1], value); + env_set_hex(argv[1], value); return 0; } diff --git a/cmd/source.c b/cmd/source.c index 177f86bb54..a9831b6608 100644 --- a/cmd/source.c +++ b/cmd/source.c @@ -40,7 +40,7 @@ source (ulong addr, const char *fit_uname) size_t fit_len; #endif - verify = getenv_yesno ("verify"); + verify = env_get_yesno("verify"); buf = map_sysmem(addr, 0); switch (genimg_get_format(buf)) { @@ -231,7 +231,7 @@ static int type_string_write_vars(const char *type_str, uint8_t *data, default: return -1; } - if (setenv_ulong(*vars, value)) + if (env_set_ulong(*vars, value)) return -1; } @@ -624,7 +624,7 @@ static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char * &key_handle); if (!err) { printf("Key handle is 0x%x\n", key_handle); - setenv_hex("key_handle", key_handle); + env_set_hex("key_handle", key_handle); } return report_return_code(err); diff --git a/cmd/trace.c b/cmd/trace.c index 1a6d8c3047..a0a7dd1995 100644 --- a/cmd/trace.c +++ b/cmd/trace.c @@ -16,10 +16,10 @@ static int get_args(int argc, char * const argv[], char **buff, if (argc < 2) return -1; if (argc < 4) { - *buff_size = getenv_ulong("profsize", 16, 0); - *buff = map_sysmem(getenv_ulong("profbase", 16, 0), + *buff_size = env_get_ulong("profsize", 16, 0); + *buff = map_sysmem(env_get_ulong("profbase", 16, 0), *buff_size); - *buff_ptr = getenv_ulong("profoffset", 16, 0); + *buff_ptr = env_get_ulong("profoffset", 16, 0); } else { *buff_size = simple_strtoul(argv[3], NULL, 16); *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16), @@ -46,9 +46,9 @@ static int create_func_list(int argc, char * const argv[]) used = min(avail, (size_t)needed); printf("Function trace dumped to %08lx, size %#zx\n", (ulong)map_to_sysmem(buff + buff_ptr), used); - setenv_hex("profbase", map_to_sysmem(buff)); - setenv_hex("profsize", buff_size); - setenv_hex("profoffset", buff_ptr + used); + env_set_hex("profbase", map_to_sysmem(buff)); + env_set_hex("profsize", buff_size); + env_set_hex("profoffset", buff_ptr + used); return 0; } @@ -71,9 +71,9 @@ static int create_call_list(int argc, char * const argv[]) printf("Call list dumped to %08lx, size %#zx\n", (ulong)map_to_sysmem(buff + buff_ptr), used); - setenv_hex("profbase", map_to_sysmem(buff)); - setenv_hex("profsize", buff_size); - setenv_hex("profoffset", buff_ptr + used); + env_set_hex("profbase", map_to_sysmem(buff)); + env_set_hex("profsize", buff_size); + env_set_hex("profoffset", buff_ptr + used); return 0; } diff --git a/cmd/unzip.c b/cmd/unzip.c index a8bcb1f529..94f883f92a 100644 --- a/cmd/unzip.c +++ b/cmd/unzip.c @@ -29,7 +29,7 @@ static int do_unzip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len); - setenv_hex("filesize", src_len); + env_set_hex("filesize", src_len); return 0; } @@ -150,6 +150,8 @@ static void usb_display_string(struct usb_device *dev, int index) static void usb_display_desc(struct usb_device *dev) { + uint packet_size = dev->descriptor.bMaxPacketSize0; + if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) { printf("%d: %s, USB Revision %x.%x\n", dev->devnum, usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass), @@ -171,9 +173,10 @@ static void usb_display_desc(struct usb_device *dev) usb_get_class_desc( dev->config.if_desc[0].desc.bInterfaceClass)); } + if (dev->descriptor.bcdUSB >= cpu_to_le16(0x0300)) + packet_size = 1 << packet_size; printf(" - PacketSize: %d Configurations: %d\n", - dev->descriptor.bMaxPacketSize0, - dev->descriptor.bNumConfigurations); + packet_size, dev->descriptor.bNumConfigurations); printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\n", dev->descriptor.idVendor, dev->descriptor.idProduct, (dev->descriptor.bcdDevice>>8) & 0xff, diff --git a/cmd/ximg.c b/cmd/ximg.c index d033c15b62..21b5c37721 100644 --- a/cmd/ximg.c +++ b/cmd/ximg.c @@ -52,7 +52,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) #endif uint8_t comp; - verify = getenv_yesno("verify"); + verify = env_get_yesno("verify"); if (argc > 1) { addr = simple_strtoul(argv[1], NULL, 16); @@ -251,8 +251,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) flush_cache(dest, len); - setenv_hex("fileaddr", data); - setenv_hex("filesize", len); + env_set_hex("fileaddr", data); + env_set_hex("filesize", len); return 0; } @@ -51,10 +51,10 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] count = 0; addr = simple_strtoul(argv[3], NULL, 16); - filename = getenv("bootfile"); + filename = env_get("bootfile"); switch (argc) { case 3: - addr_str = getenv("loadaddr"); + addr_str = env_get("loadaddr"); if (addr_str != NULL) addr = simple_strtoul(addr_str, NULL, 16); else @@ -115,7 +115,7 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] load_addr = addr; printf("%llu bytes read\n", zfile.size); - setenv_hex("filesize", zfile.size); + env_set_hex("filesize", zfile.size); return 0; } @@ -30,7 +30,7 @@ static int do_zip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; printf("Compressed size: %ld = 0x%lX\n", dst_len, dst_len); - setenv_hex("filesize", dst_len); + env_set_hex("filesize", dst_len); return 0; } |