From 039c031e080c5b127c036a5db73e1ba91f5c0ed1 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Wed, 14 Aug 2019 01:23:05 -0700 Subject: [PATCH 01/11] x86: qemu: Fix build warnings with CONFIG_DISTRO_DEFAULTS=n Use DISTRO_BOOTENV to decouple BOOTENV from CONFIG_DISTRO_DEFAULTS. Reported-by: Heinrich Schuchardt Signed-off-by: Bin Meng --- include/configs/x86-common.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h index ca27a4f9e2..54214f99e9 100644 --- a/include/configs/x86-common.h +++ b/include/configs/x86-common.h @@ -105,11 +105,14 @@ #define CONFIG_OTHBOOTARGS "othbootargs=acpi=off\0" #endif -#ifndef CONFIG_DISTRO_DEFAULTS -#define BOOTENV +#if defined(CONFIG_DISTRO_DEFAULTS) +#define DISTRO_BOOTENV BOOTENV +#else +#define DISTRO_BOOTENV #endif #define CONFIG_EXTRA_ENV_SETTINGS \ + DISTRO_BOOTENV \ CONFIG_STD_DEVICES_SETTINGS \ "pciconfighost=1\0" \ "netdev=eth0\0" \ @@ -118,8 +121,8 @@ "scriptaddr=0x7000000\0" \ "kernel_addr_r=0x1000000\0" \ "ramdisk_addr_r=0x4000000\0" \ - "ramdiskfile=initramfs.gz\0" \ - BOOTENV + "ramdiskfile=initramfs.gz\0" + #define CONFIG_RAMBOOTCOMMAND \ "setenv bootargs root=/dev/ram rw " \ From 79bf4450a1a59b99e638045f6b93e9b32d514d55 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 15 Aug 2019 21:02:30 +0200 Subject: [PATCH 02/11] doc: formatting slimbootloader.rst Avoid a warning when building the 'make htmldocs' target: doc/board/intel/slimbootloader.rst:90: WARNING: Title underline too short. Signed-off-by: Heinrich Schuchardt Reviewed-by: Bin Meng Tested-by: Bin Meng --- doc/board/intel/slimbootloader.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/board/intel/slimbootloader.rst b/doc/board/intel/slimbootloader.rst index 4a46fed069..07c9b126f7 100644 --- a/doc/board/intel/slimbootloader.rst +++ b/doc/board/intel/slimbootloader.rst @@ -87,7 +87,7 @@ The PayloadId can be any 4 Bytes value. $ qemu-system-x86_64 -machine q35 -nographic -serial mon:stdio -pflash Outputs/qemu/SlimBootloader.bin Build Instruction for Slim Bootloader for LeafHill (APL) target --------------------------------------------------------------- +--------------------------------------------------------------- LeafHill is using PCI UART2 device as a serial port. For MEM32 serial port, CONFIG_SYS_NS16550_MEM32 needs to be enabled in U-Boot. From 0c4a0e601bad7c590c968d0e4c4a7e9f440cedd6 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 15 Aug 2019 21:20:56 +0200 Subject: [PATCH 03/11] doc: arch: correct links in x86.rst Correctly reference uefi/uefi.rst and uefi/u-boot_on_efi.rst. Signed-off-by: Heinrich Schuchardt Reviewed-by: Bin Meng Tested-by: Bin Meng --- doc/arch/x86.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/arch/x86.rst b/doc/arch/x86.rst index 2eb524cc8f..a441738ad1 100644 --- a/doc/arch/x86.rst +++ b/doc/arch/x86.rst @@ -709,7 +709,8 @@ to load a 'u-boot-payload.efi', see below test logs on QEMU. No controllers found Hit any key to stop autoboot: 0 -See README.u-boot_on_efi and README.uefi for details of EFI support in U-Boot. +See :doc:`../uefi/u-boot_on_efi` and :doc:`../uefi/uefi` for details of +EFI support in U-Boot. TODO List --------- From 72b2465c6b897f7ac4a2a151f648dff9239b1cfe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:10 -0600 Subject: [PATCH 04/11] cbfs: Allow CBFS to be used in SPL Add a new Kconfig option to enable CBFS in SPL. This can be useful when the memory-init code is in CBFS. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- fs/Makefile | 1 + fs/cbfs/Kconfig | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/fs/Makefile b/fs/Makefile index 2ed4aeac0e..42e669c40c 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -8,6 +8,7 @@ ifdef CONFIG_SPL_BUILD obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/ +obj-$(CONFIG_SPL_FS_CBFS) += cbfs/ else obj-y += fs.o diff --git a/fs/cbfs/Kconfig b/fs/cbfs/Kconfig index 16089547a5..03980d830d 100644 --- a/fs/cbfs/Kconfig +++ b/fs/cbfs/Kconfig @@ -6,3 +6,15 @@ config FS_CBFS on systems that use coreboot as the first boot-loader and then load U-Boot to actually boot the Operating System. You can also enable CMD_CBFS to get command-line access. + +config SPL_FS_CBFS + bool "Enable CBFS (Coreboot Filesystem) in SPL" + help + Define this to enable support for reading from a Coreboot + filesystem. This is a ROM-based filesystem used for accessing files + on systems that use coreboot as the first boot-loader and then load + U-Boot to actually boot the Operating System. + + Note that most functions in the CBFS API do not work with SPL. Only + those which accept a cbfs_priv * can be used, since BSS is not + available. From fc7b9e16a04610b951a9d36abf41d80edb87e3e5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:11 -0600 Subject: [PATCH 05/11] cbfs: Move declarations above functions At present this file has a function at the top, above declarations. This is normally avoided, so fix it. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- fs/cbfs/cbfs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index af4d3c5e56..2a9edcc9a0 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -9,6 +9,11 @@ #include enum cbfs_result file_cbfs_result; +static const u32 good_magic = 0x4f524243; +static const u8 good_file_magic[] = "LARCHIVE"; +static int initialized; +static struct cbfs_header cbfs_header; +static struct cbfs_cachenode *file_cache; const char *file_cbfs_error(void) { @@ -28,15 +33,6 @@ const char *file_cbfs_error(void) } } - -static const u32 good_magic = 0x4f524243; -static const u8 good_file_magic[] = "LARCHIVE"; - - -static int initialized; -static struct cbfs_header cbfs_header; -static struct cbfs_cachenode *file_cache; - /* Do endian conversion on the CBFS header structure. */ static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) { From 02e4af63a9f5531b7975d21828edea04d6d519d2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:12 -0600 Subject: [PATCH 06/11] cbfs: Move static variables into a struct At present there are a number of static variables in BSS. This cannot work with SPL, at least until BSS is available in board_init_r(). Move the variables into a struct, so it is possible to malloc() it and use it before BSS is available. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- fs/cbfs/cbfs.c | 91 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 2a9edcc9a0..daae716297 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -11,9 +11,14 @@ enum cbfs_result file_cbfs_result; static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; -static int initialized; -static struct cbfs_header cbfs_header; -static struct cbfs_cachenode *file_cache; + +struct cbfs_priv { + int initialized; + struct cbfs_header header; + struct cbfs_cachenode *file_cache; +}; + +static struct cbfs_priv cbfs_s; const char *file_cbfs_error(void) { @@ -69,8 +74,9 @@ static void swap_file_header(struct cbfs_fileheader *dest, * * @return 1 if a file is found, 0 if one isn't. */ -static int file_cbfs_next_file(u8 *start, u32 size, u32 align, - struct cbfs_cachenode *newNode, u32 *used) +static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, + u32 align, struct cbfs_cachenode *newNode, + u32 *used) { struct cbfs_fileheader header; @@ -117,20 +123,21 @@ static int file_cbfs_next_file(u8 *start, u32 size, u32 align, } /* Look through a CBFS instance and copy file metadata into regular memory. */ -static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) +static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, + u32 align) { struct cbfs_cachenode *cache_node; struct cbfs_cachenode *newNode; - struct cbfs_cachenode **cache_tail = &file_cache; + struct cbfs_cachenode **cache_tail = &priv->file_cache; /* Clear out old information. */ - cache_node = file_cache; + cache_node = priv->file_cache; while (cache_node) { struct cbfs_cachenode *oldNode = cache_node; cache_node = cache_node->next; free(oldNode); } - file_cache = NULL; + priv->file_cache = NULL; while (size >= align) { int result; @@ -138,8 +145,8 @@ static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) newNode = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); - result = file_cbfs_next_file(start, size, align, - newNode, &used); + result = file_cbfs_next_file(priv, start, size, align, newNode, + &used); if (result < 0) { free(newNode); @@ -175,27 +182,35 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, return 0; } -void file_cbfs_init(uintptr_t end_of_rom) +static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) { u8 *start_of_rom; - initialized = 0; - if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + priv->initialized = 0; + + if (file_cbfs_load_header(end_of_rom, &priv->header)) return; - start_of_rom = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); + start_of_rom = (u8 *)(end_of_rom + 1 - priv->header.rom_size); - file_cbfs_fill_cache(start_of_rom, cbfs_header.rom_size, - cbfs_header.align); + file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, + priv->header.align); if (file_cbfs_result == CBFS_SUCCESS) - initialized = 1; + priv->initialized = 1; +} + +void file_cbfs_init(uintptr_t end_of_rom) +{ + cbfs_init(&cbfs_s, end_of_rom); } const struct cbfs_header *file_cbfs_get_header(void) { - if (initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (priv->initialized) { file_cbfs_result = CBFS_SUCCESS; - return &cbfs_header; + return &priv->header; } else { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; @@ -204,20 +219,24 @@ const struct cbfs_header *file_cbfs_get_header(void) const struct cbfs_cachenode *file_cbfs_get_first(void) { - if (!initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; } else { file_cbfs_result = CBFS_SUCCESS; - return file_cache; + return priv->file_cache; } } void file_cbfs_get_next(const struct cbfs_cachenode **file) { - if (!initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; - file = NULL; + *file = NULL; return; } @@ -226,11 +245,12 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file) file_cbfs_result = CBFS_SUCCESS; } -const struct cbfs_cachenode *file_cbfs_find(const char *name) +const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, + const char *name) { - struct cbfs_cachenode *cache_node = file_cache; + struct cbfs_cachenode *cache_node = priv->file_cache; - if (!initialized) { + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; } @@ -248,26 +268,33 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name) return cache_node; } +const struct cbfs_cachenode *file_cbfs_find(const char *name) +{ + return cbfs_find_file(&cbfs_s, name); +} + const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, const char *name) { + struct cbfs_priv *priv = &cbfs_s; u8 *start; u32 size; u32 align; static struct cbfs_cachenode node; - if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + if (file_cbfs_load_header(end_of_rom, &priv->header)) return NULL; - start = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); - size = cbfs_header.rom_size; - align = cbfs_header.align; + start = (u8 *)(end_of_rom + 1 - priv->header.rom_size); + size = priv->header.rom_size; + align = priv->header.align; while (size >= align) { int result; u32 used; - result = file_cbfs_next_file(start, size, align, &node, &used); + result = file_cbfs_next_file(priv, start, size, align, &node, + &used); if (result < 0) return NULL; From c7f16934749b054ce1f0b75bd664d22af8b7c588 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:13 -0600 Subject: [PATCH 07/11] cbfs: Move result variable into the struct Move the result variable into the struct also, so that it can be used when BSS is not available. Add a function to read it. Note that all functions sill use the BSS version of the data. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- cmd/cbfs.c | 4 ++-- fs/cbfs/cbfs.c | 48 ++++++++++++++++++++++++++++-------------------- include/cbfs.h | 7 +++++++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/cmd/cbfs.c b/cmd/cbfs.c index 3d1fc95972..98e652a4e7 100644 --- a/cmd/cbfs.c +++ b/cmd/cbfs.c @@ -29,7 +29,7 @@ static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, } } file_cbfs_init(end_of_rom); - if (file_cbfs_result != CBFS_SUCCESS) { + if (cbfs_get_result() != CBFS_SUCCESS) { printf("%s.\n", file_cbfs_error()); return 1; } @@ -67,7 +67,7 @@ static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, file = file_cbfs_find(argv[2]); if (!file) { - if (file_cbfs_result == CBFS_FILE_NOT_FOUND) + if (cbfs_get_result() == CBFS_FILE_NOT_FOUND) printf("%s: %s\n", file_cbfs_error(), argv[2]); else printf("%s.\n", file_cbfs_error()); diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index daae716297..d9a8562e5c 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -8,7 +8,6 @@ #include #include -enum cbfs_result file_cbfs_result; static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; @@ -16,13 +15,14 @@ struct cbfs_priv { int initialized; struct cbfs_header header; struct cbfs_cachenode *file_cache; + enum cbfs_result result; }; static struct cbfs_priv cbfs_s; const char *file_cbfs_error(void) { - switch (file_cbfs_result) { + switch (cbfs_s.result) { case CBFS_SUCCESS: return "Success"; case CBFS_NOT_INITIALIZED: @@ -38,6 +38,11 @@ const char *file_cbfs_error(void) } } +enum cbfs_result cbfs_get_result(void) +{ + return cbfs_s.result; +} + /* Do endian conversion on the CBFS header structure. */ static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) { @@ -99,7 +104,7 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, swap_file_header(&header, fileHeader); if (header.offset < sizeof(struct cbfs_fileheader)) { - file_cbfs_result = CBFS_BAD_FILE; + priv->result = CBFS_BAD_FILE; return -1; } newNode->next = NULL; @@ -161,7 +166,7 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, size -= used; start += used; } - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; } /* Get the CBFS header out of the ROM and do endian conversion. */ @@ -176,7 +181,7 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, if (header->magic != good_magic || header->offset > header->rom_size - header->boot_block_size) { - file_cbfs_result = CBFS_BAD_HEADER; + cbfs_s.result = CBFS_BAD_HEADER; return 1; } return 0; @@ -195,7 +200,7 @@ static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, priv->header.align); - if (file_cbfs_result == CBFS_SUCCESS) + if (priv->result == CBFS_SUCCESS) priv->initialized = 1; } @@ -209,10 +214,10 @@ const struct cbfs_header *file_cbfs_get_header(void) struct cbfs_priv *priv = &cbfs_s; if (priv->initialized) { - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return &priv->header; } else { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } } @@ -222,10 +227,10 @@ const struct cbfs_cachenode *file_cbfs_get_first(void) struct cbfs_priv *priv = &cbfs_s; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } else { - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return priv->file_cache; } } @@ -235,14 +240,14 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file) struct cbfs_priv *priv = &cbfs_s; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; *file = NULL; return; } if (*file) *file = (*file)->next; - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; } const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, @@ -251,7 +256,7 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, struct cbfs_cachenode *cache_node = priv->file_cache; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } @@ -261,9 +266,9 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, cache_node = cache_node->next; } if (!cache_node) - file_cbfs_result = CBFS_FILE_NOT_FOUND; + priv->result = CBFS_FILE_NOT_FOUND; else - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return cache_node; } @@ -307,25 +312,28 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, size -= used; start += used; } - file_cbfs_result = CBFS_FILE_NOT_FOUND; + cbfs_s.result = CBFS_FILE_NOT_FOUND; return NULL; } const char *file_cbfs_name(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; + return file->name; } u32 file_cbfs_size(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; + return file->data_length; } u32 file_cbfs_type(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; + return file->type; } @@ -339,7 +347,7 @@ long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, size = maxsize; memcpy(buffer, file->data, size); + cbfs_s.result = CBFS_SUCCESS; - file_cbfs_result = CBFS_SUCCESS; return size; } diff --git a/include/cbfs.h b/include/cbfs.h index b8d1dabbf6..742e34e24f 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -90,6 +90,13 @@ extern enum cbfs_result file_cbfs_result; */ const char *file_cbfs_error(void); +/** + * cbfs_get_result() - Get the result of the last CBFS operation + * + *@return last result + */ +enum cbfs_result cbfs_get_result(void); + /** * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. * From 630b2f39ddabd43a27a98f0356b948df18e97d88 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:14 -0600 Subject: [PATCH 08/11] cbfs: Add functions to support multiple CBFSs Sometimes an image has multiple CBFS. The current CBFS API is limited to handling only one at time. Also it keeps track of the CBFS internally in BSS, which does not work before relocation, for example. Add a few new functions to overcome these limitations. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- fs/cbfs/cbfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/cbfs.h | 22 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index d9a8562e5c..35f919afee 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -187,6 +187,23 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, return 0; } +static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base, + struct cbfs_header *header) +{ + struct cbfs_header *header_in_rom; + + header_in_rom = (struct cbfs_header *)base; + swap_header(header, header_in_rom); + + if (header->magic != good_magic || header->offset > + header->rom_size - header->boot_block_size) { + priv->result = CBFS_BAD_HEADER; + return -EFAULT; + } + + return 0; +} + static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) { u8 *start_of_rom; @@ -209,6 +226,35 @@ void file_cbfs_init(uintptr_t end_of_rom) cbfs_init(&cbfs_s, end_of_rom); } +int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) +{ + struct cbfs_priv priv_s, *priv = &priv_s; + int ret; + + /* + * Use a local variable to start with until we know that the CBFS is + * valid. Assume that a master header appears at the start, at offset + * 0x38. + */ + ret = cbfs_load_header_ptr(priv, base + 0x38, &priv->header); + if (ret) + return ret; + + file_cbfs_fill_cache(priv, (u8 *)base, priv->header.rom_size, + priv->header.align); + if (priv->result != CBFS_SUCCESS) + return -EINVAL; + + priv->initialized = 1; + priv = malloc(sizeof(priv_s)); + if (!priv) + return -ENOMEM; + memcpy(priv, &priv_s, sizeof(priv_s)); + *privp = priv; + + return 0; +} + const struct cbfs_header *file_cbfs_get_header(void) { struct cbfs_priv *priv = &cbfs_s; diff --git a/include/cbfs.h b/include/cbfs.h index 742e34e24f..6d4c4d4b06 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -135,6 +135,28 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file); */ const struct cbfs_cachenode *file_cbfs_find(const char *name); +struct cbfs_priv *priv; + +/** + * cbfs_find_file() - Find a file in a given CBFS + * + * @cbfs: CBFS to look in (use cbfs_init_mem() to set it up) + * @name: Filename to look for + * @return pointer to CBFS node if found, else NULL + */ +const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *cbfs, + const char *name); + +/** + * cbfs_init_mem() - Set up a new CBFS + * + * @base: Base address of CBFS + * @size: Size of CBFS in bytes + * @cbfsp: Returns a pointer to CBFS on success + * @return 0 if OK, -ve on error + */ +int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp); + /***************************************************************************/ /* All of the functions below can be used without first initializing CBFS. */ From ad79d603aa68a7a523005ce694ee4b43efdf7382 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 14 Aug 2019 19:56:15 -0600 Subject: [PATCH 09/11] cbfs: Rename camel-case variables Rename some camel-case variables to match U-Boot style. Camel case is not generally allowed in U-Boot. Rename this variable to fit in with the style. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- fs/cbfs/cbfs.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 35f919afee..1aa6f8ee84 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -73,14 +73,14 @@ static void swap_file_header(struct cbfs_fileheader *dest, * @param start The location in memory to start from. * @param size The size of the memory region to search. * @param align The alignment boundaries to check on. - * @param newNode A pointer to the file structure to load. + * @param new_node A pointer to the file structure to load. * @param used A pointer to the count of of bytes scanned through, * including the file if one is found. * * @return 1 if a file is found, 0 if one isn't. */ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, - u32 align, struct cbfs_cachenode *newNode, + u32 align, struct cbfs_cachenode *new_node, u32 *used) { struct cbfs_fileheader header; @@ -88,34 +88,34 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, *used = 0; while (size >= align) { - const struct cbfs_fileheader *fileHeader = + const struct cbfs_fileheader *file_header = (const struct cbfs_fileheader *)start; u32 name_len; u32 step; /* Check if there's a file here. */ - if (memcmp(good_file_magic, &(fileHeader->magic), - sizeof(fileHeader->magic))) { + if (memcmp(good_file_magic, &file_header->magic, + sizeof(file_header->magic))) { *used += align; size -= align; start += align; continue; } - swap_file_header(&header, fileHeader); + swap_file_header(&header, file_header); if (header.offset < sizeof(struct cbfs_fileheader)) { priv->result = CBFS_BAD_FILE; return -1; } - newNode->next = NULL; - newNode->type = header.type; - newNode->data = start + header.offset; - newNode->data_length = header.len; + new_node->next = NULL; + new_node->type = header.type; + new_node->data = start + header.offset; + new_node->data_length = header.len; name_len = header.offset - sizeof(struct cbfs_fileheader); - newNode->name = (char *)fileHeader + + new_node->name = (char *)file_header + sizeof(struct cbfs_fileheader); - newNode->name_length = name_len; - newNode->attributes_offset = header.attributes_offset; + new_node->name_length = name_len; + new_node->attributes_offset = header.attributes_offset; step = header.len; if (step % align) @@ -132,15 +132,15 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, u32 align) { struct cbfs_cachenode *cache_node; - struct cbfs_cachenode *newNode; + struct cbfs_cachenode *new_node; struct cbfs_cachenode **cache_tail = &priv->file_cache; /* Clear out old information. */ cache_node = priv->file_cache; while (cache_node) { - struct cbfs_cachenode *oldNode = cache_node; + struct cbfs_cachenode *old_node = cache_node; cache_node = cache_node->next; - free(oldNode); + free(old_node); } priv->file_cache = NULL; @@ -148,20 +148,20 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, int result; u32 used; - newNode = (struct cbfs_cachenode *) + new_node = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); - result = file_cbfs_next_file(priv, start, size, align, newNode, + result = file_cbfs_next_file(priv, start, size, align, new_node, &used); if (result < 0) { - free(newNode); + free(new_node); return; } else if (result == 0) { - free(newNode); + free(new_node); break; } - *cache_tail = newNode; - cache_tail = &newNode->next; + *cache_tail = new_node; + cache_tail = &new_node->next; size -= used; start += used; From 8ad01ce36f71113d9b4c58fb71422d47e86df176 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Fri, 16 Aug 2019 14:45:28 +0200 Subject: [PATCH 10/11] x86: Remove x86 specific GD flags as they are not referenced at all This patch removes the x86 architecture specific GD flags (GD_FLG_COLD_BOOT & GD_FLG_WARM_BOOT), as they are not used. Only GD_FLG_COLD_BOOT is referenced in coreboot.c but assigned in start16.S. But the coreboot target does not use start16.S at all and boots directly from the 32-bit start code. Signed-off-by: Stefan Roese Cc: Bin Meng Cc: Simon Glass Cc: Tom Rini Cc: Simon Goldschmidt Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Simon Goldschmidt --- arch/x86/cpu/coreboot/coreboot.c | 3 --- arch/x86/cpu/start.S | 9 +-------- arch/x86/cpu/start16.S | 3 --- arch/x86/include/asm/global_data.h | 6 ------ 4 files changed, 1 insertion(+), 20 deletions(-) diff --git a/arch/x86/cpu/coreboot/coreboot.c b/arch/x86/cpu/coreboot/coreboot.c index 4c6ed0bfb2..9686f8ed5b 100644 --- a/arch/x86/cpu/coreboot/coreboot.c +++ b/arch/x86/cpu/coreboot/coreboot.c @@ -73,9 +73,6 @@ static void board_final_cleanup(void) int last_stage_init(void) { - if (gd->flags & GD_FLG_COLD_BOOT) - timestamp_add_to_bootstage(); - /* start usb so that usb keyboard can be used as input device */ if (CONFIG_IS_ENABLED(USB_KEYBOARD)) usb_init(); diff --git a/arch/x86/cpu/start.S b/arch/x86/cpu/start.S index 71cd70f9cd..3c9bdf2a9d 100644 --- a/arch/x86/cpu/start.S +++ b/arch/x86/cpu/start.S @@ -40,9 +40,6 @@ _x86boot_start: movl %eax, %cr0 wbinvd - /* Tell 32-bit code it is being entered from an in-RAM copy */ - movl $GD_FLG_WARM_BOOT, %ebx - /* * Zero the BIST (Built-In Self Test) value since we don't have it. * It must be 0 or the previous loader would have reported an error. @@ -55,11 +52,7 @@ _x86boot_start: .align 4 .long 0x12345678 _start: - /* - * This is the 32-bit cold-reset entry point, coming from start16. - * Set %ebx to GD_FLG_COLD_BOOT to indicate this. - */ - movl $GD_FLG_COLD_BOOT, %ebx + /* This is the 32-bit cold-reset entry point, coming from start16 */ /* Save BIST */ movl %eax, %ebp diff --git a/arch/x86/cpu/start16.S b/arch/x86/cpu/start16.S index dd659278ff..474efe4df5 100644 --- a/arch/x86/cpu/start16.S +++ b/arch/x86/cpu/start16.S @@ -23,9 +23,6 @@ start16: /* Save BIST */ movl %eax, %ecx - /* Set the Cold Boot / Hard Reset flag */ - movl $GD_FLG_COLD_BOOT, %ebx - xorl %eax, %eax movl %eax, %cr3 /* Invalidate TLB */ diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h index 797397e697..17a4d34491 100644 --- a/arch/x86/include/asm/global_data.h +++ b/arch/x86/include/asm/global_data.h @@ -137,10 +137,4 @@ static inline __attribute__((no_instrument_function)) gd_t *get_fs_gd_ptr(void) #endif -/* - * Our private Global Data Flags - */ -#define GD_FLG_COLD_BOOT 0x10000 /* Cold Boot */ -#define GD_FLG_WARM_BOOT 0x20000 /* Warm Boot */ - #endif /* __ASM_GBL_DATA_H */ From d117f917bfd2ccf4eaf90bddfa256501a554b1a4 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Fri, 16 Aug 2019 14:45:29 +0200 Subject: [PATCH 11/11] global_data: Remove comment of reserved arch-specific GD flags With the removal of the x86 specific GD flags, there are no arch- specific GD flags any more. Let's remove the comment about reserving the upper 16 bits for arch-specific flags in the common header. This gives us more flexibility with the usage of the GD flags. As a matter of fact, we are already using more than 16 bits for common GD flags (with the addition of GD_FLG_WDT_READY). Signed-off-by: Stefan Roese Cc: Bin Meng Cc: Simon Glass Cc: Tom Rini Cc: Simon Goldschmidt Reviewed-by: Bin Meng Reviewed-by: Simon Goldschmidt Reviewed-by: Simon Glass --- include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 5372d5d8cd..7587ba2ee5 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -150,7 +150,7 @@ typedef struct global_data { #endif /* - * Global Data Flags - the top 16 bits are reserved for arch-specific flags + * Global Data Flags */ #define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */ #define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */