diff options
| author | Tom Rini <[email protected]> | 2023-07-10 14:29:14 -0400 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2023-07-10 14:29:14 -0400 |
| commit | 146a82c017d51eb2c3b8be33854f200f1e52a1cb (patch) | |
| tree | c2bb134d105bcc9855e6c39ac5b422e5416735ff /common | |
| parent | 05aa6516c6bb419d01d69fac457c0de563bfd694 (diff) | |
| parent | 76c61f29d63163d178b1584ecc9fc2c96c538ff0 (diff) | |
Merge branch 'next'
Diffstat (limited to 'common')
| -rw-r--r-- | common/Kconfig | 1 | ||||
| -rw-r--r-- | common/cli_hush.c | 2 | ||||
| -rw-r--r-- | common/fdt_support.c | 75 | ||||
| -rw-r--r-- | common/memsize.c | 24 | ||||
| -rw-r--r-- | common/spl/Kconfig | 123 | ||||
| -rw-r--r-- | common/spl/Kconfig.tpl | 1 | ||||
| -rw-r--r-- | common/spl/Makefile | 2 | ||||
| -rw-r--r-- | common/spl/spl.c | 4 | ||||
| -rw-r--r-- | common/spl/spl_blk_fs.c | 134 | ||||
| -rw-r--r-- | common/spl/spl_mmc.c | 2 | ||||
| -rw-r--r-- | common/spl/spl_nor.c | 2 | ||||
| -rw-r--r-- | common/spl/spl_nvme.c | 32 | ||||
| -rw-r--r-- | common/stdio.c | 8 |
13 files changed, 304 insertions, 106 deletions
diff --git a/common/Kconfig b/common/Kconfig index bbabadb35e1..42baca20a61 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -256,6 +256,7 @@ config SYS_CONSOLE_OVERWRITE_ROUTINE config SYS_CONSOLE_ENV_OVERWRITE bool "Update environment variables during console init" + depends on SYS_CONSOLE_IS_IN_ENV help The console environment variables (stdout, stdin, stderr) can be used to determine the correct console devices on start-up. This diff --git a/common/cli_hush.c b/common/cli_hush.c index 171069f5f49..cee87249bc2 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -324,7 +324,7 @@ typedef struct { /* I can almost use ordinary FILE *. Is open_memstream() universally * available? Where is it documented? */ struct in_str { - const char *p; + const unsigned char *p; #ifndef __U_BOOT__ char peek_buf[2]; #endif diff --git a/common/fdt_support.c b/common/fdt_support.c index 2053fe3bad8..5e49078f8c3 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -13,6 +13,7 @@ #include <mapmem.h> #include <net.h> #include <stdio_dev.h> +#include <dm/ofnode.h> #include <linux/ctype.h> #include <linux/types.h> #include <asm/global_data.h> @@ -1050,6 +1051,79 @@ void fdt_fixup_mtdparts(void *blob, const struct node_info *node_info, } #endif +int fdt_copy_fixed_partitions(void *blob) +{ + ofnode node, subnode; + int off, suboff, res; + char path[256]; + int address_cells, size_cells; + u8 i, j, child_count; + + node = ofnode_by_compatible(ofnode_null(), "fixed-partitions"); + while (ofnode_valid(node)) { + /* copy the U-Boot fixed partition */ + address_cells = ofnode_read_simple_addr_cells(node); + size_cells = ofnode_read_simple_size_cells(node); + + res = ofnode_get_path(ofnode_get_parent(node), path, sizeof(path)); + if (res) + return res; + + off = fdt_path_offset(blob, path); + if (off < 0) + return -ENODEV; + + off = fdt_find_or_add_subnode(blob, off, "partitions"); + res = fdt_setprop_string(blob, off, "compatible", "fixed-partitions"); + if (res) + return res; + + res = fdt_setprop_u32(blob, off, "#address-cells", address_cells); + if (res) + return res; + + res = fdt_setprop_u32(blob, off, "#size-cells", size_cells); + if (res) + return res; + + /* + * parse partition in reverse order as fdt_find_or_add_subnode() only + * insert the new node after the parent's properties + */ + child_count = ofnode_get_child_count(node); + for (i = child_count; i > 0 ; i--) { + subnode = ofnode_first_subnode(node); + if (!ofnode_valid(subnode)) + break; + + for (j = 0; (j < i - 1); j++) + subnode = ofnode_next_subnode(subnode); + + if (!ofnode_valid(subnode)) + break; + + const u32 *reg; + int len; + + suboff = fdt_find_or_add_subnode(blob, off, ofnode_get_name(subnode)); + res = fdt_setprop_string(blob, suboff, "label", + ofnode_read_string(subnode, "label")); + if (res) + return res; + + reg = ofnode_get_property(subnode, "reg", &len); + res = fdt_setprop(blob, suboff, "reg", reg, len); + if (res) + return res; + } + + /* go to next fixed-partitions node */ + node = ofnode_by_compatible(node, "fixed-partitions"); + } + + return 0; +} + void fdt_del_node_and_alias(void *blob, const char *alias) { int off = fdt_path_offset(blob, alias); @@ -1065,7 +1139,6 @@ void fdt_del_node_and_alias(void *blob, const char *alias) /* Max address size we deal with */ #define OF_MAX_ADDR_CELLS 4 -#define OF_BAD_ADDR FDT_ADDR_T_NONE #define OF_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \ (ns) > 0) diff --git a/common/memsize.c b/common/memsize.c index 66d5be6a1ff..d646df8b04c 100644 --- a/common/memsize.c +++ b/common/memsize.c @@ -7,9 +7,18 @@ #include <common.h> #include <init.h> #include <asm/global_data.h> +#include <cpu_func.h> +#include <stdint.h> DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_SYS_CACHELINE_SIZE +# define MEMSIZE_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE +#else +/* Just use the greatest cache flush alignment requirement I'm aware of */ +# define MEMSIZE_CACHELINE_SIZE 128 +#endif + #ifdef __PPC__ /* * At least on G2 PowerPC cores, sequential accesses to non-existent @@ -20,6 +29,15 @@ DECLARE_GLOBAL_DATA_PTR; # define sync() /* nothing */ #endif +static void dcache_flush_invalidate(volatile long *p) +{ + uintptr_t start, stop; + start = ALIGN_DOWN((uintptr_t)p, MEMSIZE_CACHELINE_SIZE); + stop = start + MEMSIZE_CACHELINE_SIZE; + flush_dcache_range(start, stop); + invalidate_dcache_range(start, stop); +} + /* * Check memory range for valid RAM. A simple memory test determines * the actually available RAM size between addresses `base' and @@ -34,6 +52,7 @@ long get_ram_size(long *base, long maxsize) long val; long size; int i = 0; + int dcache_en = dcache_status(); for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { addr = base + cnt; /* pointer arith! */ @@ -41,6 +60,8 @@ long get_ram_size(long *base, long maxsize) save[i++] = *addr; sync(); *addr = ~cnt; + if (dcache_en) + dcache_flush_invalidate(addr); } addr = base; @@ -50,6 +71,9 @@ long get_ram_size(long *base, long maxsize) *addr = 0; sync(); + if (dcache_en) + dcache_flush_invalidate(addr); + if ((val = *addr) != 0) { /* Restore the original data before leaving the function. */ sync(); diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 2c042ad3066..bee231b583a 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -1263,6 +1263,33 @@ config SPL_SATA_RAW_U_BOOT_SECTOR Sector on the SATA disk to load U-Boot from, when the SATA disk is being used in raw mode. Units: SATA disk sectors (1 sector = 512 bytes). +config SPL_NVME + bool "NVM Express device support" + depends on BLK + select HAVE_BLOCK_DEVICE + select FS_LOADER + select SPL_BLK_FS + help + This option enables support for NVM Express devices. + It supports basic functions of NVMe (read/write). + +config SPL_NVME_PCI + bool "NVM Express PCI device support for SPL" + depends on SPL_PCI && SPL_NVME + help + This option enables support for NVM Express PCI devices. + This allows use of NVMe devices for loading u-boot. + +config SPL_NVME_BOOT_DEVICE + hex "NVMe boot device number" + depends on SPL_NVME + default 0x0 + +config SYS_NVME_BOOT_PARTITION + hex "NVMe boot partition number" + depends on SPL_NVME + default 0x1 + config SPL_SERIAL bool "Support serial" select SPL_PRINTF @@ -1345,96 +1372,6 @@ config SPL_THERMAL automatic power-off when the temperature gets too high or low. Other devices may be discrete but connected on a suitable bus. -config SPL_USB_HOST - bool "Support USB host drivers" - help - Enable access to USB (Universal Serial Bus) host devices so that - SPL can load U-Boot from a connected USB peripheral, such as a USB - flash stick. While USB takes a little longer to start up than most - buses, it is very flexible since many different types of storage - device can be attached. This option enables the drivers in - drivers/usb/host as part of an SPL build. - -config SPL_USB_STORAGE - bool "Support loading from USB" - depends on SPL_USB_HOST - help - Enable support for USB devices in SPL. This allows use of USB - devices such as hard drives and flash drivers for loading U-Boot. - The actual drivers are enabled separately using the normal U-Boot - config options. This enables loading from USB using a configured - device. - -config SYS_USB_FAT_BOOT_PARTITION - int "Partition on USB to use to load U-Boot from" - depends on SPL_USB_STORAGE - default 1 - help - Partition on the USB storage device to load U-Boot from - -config SPL_USB_GADGET - bool "Suppport USB Gadget drivers" - help - Enable USB Gadget API which allows to enable USB device functions - in SPL. - -if SPL_USB_GADGET - -config SPL_USB_ETHER - bool "Support USB Ethernet drivers" - depends on SPL_NET - help - Enable access to the USB network subsystem and associated - drivers in SPL. This permits SPL to load U-Boot over a - USB-connected Ethernet link (such as a USB Ethernet dongle) rather - than from an onboard peripheral. Environment support is required - since the network stack uses a number of environment variables. - See also SPL_NET and SPL_ETH. - -config SPL_DFU - bool "Support DFU (Device Firmware Upgrade)" - select SPL_HASH - select SPL_DFU_NO_RESET - depends on SPL_RAM_SUPPORT - help - This feature enables the DFU (Device Firmware Upgrade) in SPL with - RAM memory device support. The ROM code will load and execute - the SPL built with dfu. The user can load binaries (u-boot/kernel) to - selected device partition from host-pc using dfu-utils. - This feature is useful to flash the binaries to factory or bare-metal - boards using USB interface. - -choice - bool "DFU device selection" - depends on SPL_DFU - -config SPL_DFU_RAM - bool "RAM device" - depends on SPL_DFU && SPL_RAM_SUPPORT - help - select RAM/DDR memory device for loading binary images - (u-boot/kernel) to the selected device partition using - DFU and execute the u-boot/kernel from RAM. - -endchoice - -config SPL_USB_SDP_SUPPORT - bool "Support SDP (Serial Download Protocol)" - depends on SPL_SERIAL - help - Enable Serial Download Protocol (SDP) device support in SPL. This - allows to download images into memory and execute (jump to) them - using the same protocol as implemented by the i.MX family's boot ROM. - -config SPL_SDP_USB_DEV - int "SDP USB controller index" - default 0 - depends on SPL_USB_SDP_SUPPORT - help - Some boards have USB controller other than 0. Define this option - so it can be used in compiled environment. -endif - config SPL_WATCHDOG bool "Support watchdog drivers" imply SPL_WDT if !HW_WATCHDOG @@ -1524,8 +1461,10 @@ config SPL_OPENSBI_SCRATCH_OPTIONS default 0x1 depends on SPL_OPENSBI help - Options passed to fw_dynamic, for example SBI_SCRATCH_NO_BOOT_PRINTS or - SBI_SCRATCH_DEBUG_PRINTS. + This bitmap of options is passed from U-Boot SPL to OpenSBI. + As of OpenSBI 1.3 the following bits are defined: + - SBI_SCRATCH_NO_BOOT_PRINTS = 0x1 (Disable prints during boot) + - SBI_SCRATCH_DEBUG_PRINTS = 0x2 (Enable runtime debug prints) config SPL_TARGET string "Addtional build targets for 'make'" diff --git a/common/spl/Kconfig.tpl b/common/spl/Kconfig.tpl index 1874f9db4f9..3d6cf1e59f3 100644 --- a/common/spl/Kconfig.tpl +++ b/common/spl/Kconfig.tpl @@ -43,6 +43,7 @@ config TPL_FRAMEWORK config TPL_BANNER_PRINT bool "Enable output of the TPL banner 'U-Boot TPL ...'" + depends on DEBUG_UART && TPL_SERIAL default y help If this option is enabled, TPL will print the banner with version diff --git a/common/spl/Makefile b/common/spl/Makefile index 13db3df9933..bad2bbf6cf1 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o +obj-$(CONFIG_$(SPL_TPL_)BLK_FS) += spl_blk_fs.o obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_FORMAT) += spl_legacy.o obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o @@ -28,6 +29,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o +obj-$(CONFIG_$(SPL_TPL_)NVME) += spl_nvme.o obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o diff --git a/common/spl/spl.c b/common/spl/spl.c index 72078a8ebc8..d74acec10b5 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -321,7 +321,7 @@ static int spl_load_fit_image(struct spl_image_info *spl_image, spl_image->fdt_addr = (void *)dt_data; if (spl_image->os == IH_OS_U_BOOT) { - /* HACK: U-boot expects FDT at a specific address */ + /* HACK: U-Boot expects FDT at a specific address */ fdt_hack = spl_image->load_addr + spl_image->size; fdt_hack = (fdt_hack + 3) & ~3; debug("Relocating FDT to %p\n", spl_image->fdt_addr); @@ -331,7 +331,7 @@ static int spl_load_fit_image(struct spl_image_info *spl_image, conf_noffset = fit_conf_get_node((const void *)header, fit_uname_config); - if (conf_noffset <= 0) + if (conf_noffset < 0) return 0; for (idx = 0; diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c new file mode 100644 index 00000000000..d97adc4d39a --- /dev/null +++ b/common/spl/spl_blk_fs.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 + * Ventana Micro Systems Inc. + * + */ + +#include <common.h> +#include <spl.h> +#include <image.h> +#include <fs.h> + +struct blk_dev { + const char *ifname; + char dev_part_str[8]; +}; + +static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, + ulong size, void *buf) +{ + loff_t actlen; + int ret; + struct blk_dev *dev = (struct blk_dev *)load->priv; + + ret = fs_set_blk_dev(dev->ifname, dev->dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev->ifname, dev->dev_part_str, ret); + return ret; + } + + ret = fs_read(load->filename, (ulong)buf, file_offset, size, &actlen); + if (ret < 0) { + printf("spl: error reading image %s. Err - %d\n", + load->filename, ret); + return ret; + } + + return actlen; +} + +int spl_blk_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev, + enum uclass_id uclass_id, int devnum, int partnum) +{ + const char *filename = CONFIG_SPL_PAYLOAD; + struct disk_partition part_info = {}; + struct legacy_img_hdr *header; + struct blk_desc *blk_desc; + loff_t actlen, filesize; + struct blk_dev dev; + int ret; + + blk_desc = blk_get_devnum_by_uclass_id(uclass_id, devnum); + if (!blk_desc) { + printf("blk desc for %d %d not found\n", uclass_id, devnum); + goto out; + } + + blk_show_device(uclass_id, devnum); + header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); + ret = part_get_info(blk_desc, 1, &part_info); + if (ret) { + printf("spl: no partition table found. Err - %d\n", ret); + goto out; + } + + dev.ifname = blk_get_uclass_name(uclass_id); + snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%d:%d", + devnum, partnum); + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_read(filename, (ulong)header, 0, + sizeof(struct legacy_img_hdr), &actlen); + if (ret) { + printf("spl: unable to read file %s. Err - %d\n", filename, + ret); + goto out; + } + + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && + image_get_magic(header) == FDT_MAGIC) { + struct spl_load_info load; + + debug("Found FIT\n"); + load.read = spl_fit_read; + load.bl_len = 1; + load.filename = (void *)filename; + load.priv = &dev; + + return spl_load_simple_fit(spl_image, &load, 0, header); + } + + ret = spl_parse_image_header(spl_image, bootdev, header); + if (ret) { + printf("spl: unable to parse image header. Err - %d\n", + ret); + goto out; + } + + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_size(filename, &filesize); + if (ret) { + printf("spl: unable to get file size: %s. Err - %d\n", + filename, ret); + goto out; + } + + ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY); + if (ret) { + printf("spl: unable to set blk_dev %s %s. Err - %d\n", + dev.ifname, dev.dev_part_str, ret); + goto out; + } + + ret = fs_read(filename, (ulong)spl_image->load_addr, 0, filesize, + &actlen); + if (ret) + printf("spl: unable to read file %s. Err - %d\n", + filename, ret); +out: + return ret; +} diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c index a0722167044..a665091b00f 100644 --- a/common/spl/spl_mmc.c +++ b/common/spl/spl_mmc.c @@ -250,7 +250,7 @@ static int mmc_load_image_raw_os(struct spl_image_info *spl_image, return ret; if (spl_image->os != IH_OS_LINUX && spl_image->os != IH_OS_TEE) { - puts("Expected image is not found. Trying to start U-boot\n"); + puts("Expected image is not found. Trying to start U-Boot\n"); return -ENOENT; } diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index 1ef5e412624..5b65b96a77d 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -121,6 +121,6 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, &hdr); } - return 0; + return -EINVAL; } SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image); diff --git a/common/spl/spl_nvme.c b/common/spl/spl_nvme.c new file mode 100644 index 00000000000..2af63f1dc8c --- /dev/null +++ b/common/spl/spl_nvme.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 + * Ventana Micro Systems Inc. + * + */ + +#include <common.h> +#include <spl.h> +#include <init.h> +#include <nvme.h> + +static int spl_nvme_load_image(struct spl_image_info *spl_image, + struct spl_boot_device *bootdev) +{ + int ret; + + ret = pci_init(); + if (ret < 0) + return ret; + + ret = nvme_scan_namespace(); + if (ret < 0) + return ret; + + ret = spl_blk_load_image(spl_image, bootdev, UCLASS_NVME, + CONFIG_SPL_NVME_BOOT_DEVICE, + CONFIG_SYS_NVME_BOOT_PARTITION); + return ret; +} + +SPL_LOAD_IMAGE_METHOD("NVME", 0, BOOT_DEVICE_NVME, spl_nvme_load_image); diff --git a/common/stdio.c b/common/stdio.c index cbedfdda539..894cbd3fb44 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -386,11 +386,3 @@ int stdio_add_devices(void) return 0; } - -int stdio_init(void) -{ - stdio_init_tables(); - stdio_add_devices(); - - return 0; -} |
