From 615828721abfe8c73b5103d4436402ecbf9b9897 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 14 Jul 2023 13:24:50 +0200 Subject: Revert "lib: string: Fix strlcpy return value", fix callers Both the Linux kernel and libbsd agree that strlcpy() should always return strlen(src) and not include the NUL termination. The incorrect U-Boot implementation makes it impossible to check the return value for truncation, and breaks code written with the usual implementation in mind (for example, fdtdec_add_reserved_memory() was subtly broken). I reviewed all callers of strlcpy() and strlcat() and fixed them according to my understanding of the intended function. This reverts commit d3358ecc54be0bc3b4dd11f7a63eab0a2842f772 and adds related fixes. Fixes: d3358ecc54be ("lib: string: Fix strlcpy return value") Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass Reviewed-by: Sean Anderson --- lib/string.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/string.c b/lib/string.c index ecea755f405..f2c61471288 100644 --- a/lib/string.c +++ b/lib/string.c @@ -116,20 +116,18 @@ char * strncpy(char * dest,const char *src,size_t count) * of course, the buffer size is zero). It does not pad * out the result like strncpy() does. * - * Return: the number of bytes copied + * Return: strlen(src) */ size_t strlcpy(char *dest, const char *src, size_t size) { - if (size) { - size_t srclen = strlen(src); - size_t len = (srclen >= size) ? size - 1 : srclen; + size_t ret = strlen(src); + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; memcpy(dest, src, len); dest[len] = '\0'; - return len + 1; } - - return 0; + return ret; } #endif @@ -191,6 +189,8 @@ char * strncat(char *dest, const char *src, size_t count) * Compatible with *BSD: the result is always a valid NUL-terminated string that * fits in the buffer (unless, of course, the buffer size is zero). It does not * write past @size like strncat() does. + * + * Return: min(strlen(dest), size) + strlen(src) */ size_t strlcat(char *dest, const char *src, size_t size) { -- cgit v1.2.3 From 7c00b80d48cbb28e5f6dfc232c344526e28f7176 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 14 Jul 2023 13:24:51 +0200 Subject: lib/charset: fix u16_strlcat() return value strlcat returns min(strlen(dest), count)+strlen(src). Make u16_strlcat's behaviour the same for consistency. Fixes: eca08ce94ceb ("lib/charset: add u16_strlcat() function") Signed-off-by: Matthias Schiffer --- lib/charset.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/charset.c b/lib/charset.c index b1842755eb1..5e4c4f948a4 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -444,14 +444,14 @@ u16 *u16_strdup(const void *src) size_t u16_strlcat(u16 *dest, const u16 *src, size_t count) { - size_t destlen = u16_strlen(dest); + size_t destlen = u16_strnlen(dest, count); size_t srclen = u16_strlen(src); - size_t ret = destlen + srclen + 1; + size_t ret = destlen + srclen; if (destlen >= count) return ret; - if (ret > count) - srclen -= ret - count; + if (ret >= count) + srclen -= (ret - count + 1); memcpy(&dest[destlen], src, 2 * srclen); dest[destlen + srclen] = 0x0000; -- cgit v1.2.3 From 1a549c8961a6db72db374a4db2be598b30c9c46d Mon Sep 17 00:00:00 2001 From: Ilya Lukin <4.shket@gmail.com> Date: Fri, 14 Jul 2023 17:39:32 +0300 Subject: crc32: Drop duplicates crc header includes Fixes: 3db711085752 ("crc32: Use the crc.h header for crc functions") Signed-off-by: Ilya Lukin <4.shket@gmail.com> --- lib/crc32.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/crc32.c b/lib/crc32.c index aa94d70ef3e..f6fad8c15df 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -10,7 +10,6 @@ #ifdef USE_HOSTCC #include -#include #else #include #include -- cgit v1.2.3 From a077ac13d03c8cde646ddab30b03ec0f8b753e1e Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 2 Aug 2023 11:09:43 -0400 Subject: Kconfigs: Correct default of "0" on hex type entries It is not a parse error to have a default value of "0" for a "hex" type entry, instead of "0x0". However, "0" and "0x0" are not treated the same even by the tools themselves. Correct this by changing the default value from "0" to "0x0" for all hex type questions that had the incorrect default. Fix one instance (in two configs) of a default of "0" being used on a hex question to be "0x0". Remove the cases where a defconfig had set a value of "0x0" to be used as the default had been "0". Signed-off-by: Tom Rini Reviewed-by: Simon Glass --- lib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index 07e61de5b64..42e559ad0b5 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -862,7 +862,7 @@ config OF_LIBFDT config OF_LIBFDT_ASSUME_MASK hex "Mask of conditions to assume for libfdt" depends on OF_LIBFDT || FIT - default 0 + default 0x0 help Use this to change the assumptions made by libfdt about the device tree it is working with. A value of 0 means that no assumptions -- cgit v1.2.3 From ccea96f443e2d35cf5ecc341bb14569029eb93b8 Mon Sep 17 00:00:00 2001 From: Shiji Yang Date: Thu, 3 Aug 2023 09:47:17 +0800 Subject: treewide: unify the linker symbol reference format Now all linker symbols are declared as type char[]. Though we can reference the address via both the array name 'var' and its address '&var'. It's better to unify them to avoid confusing developers. This patch converts all '&var' linker symbol refrences to the most commonly used format 'var'. Signed-off-by: Shiji Yang Reviewed-by: Tom Rini --- lib/fdtdec.c | 6 +++--- lib/trace.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/fdtdec.c b/lib/fdtdec.c index c60972dfbe8..7a691676483 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1230,12 +1230,12 @@ static void *fdt_find_separate(void) #ifdef CONFIG_SPL_BUILD /* FDT is at end of BSS unless it is in a different memory region */ if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) - fdt_blob = (ulong *)&_image_binary_end; + fdt_blob = (ulong *)_image_binary_end; else - fdt_blob = (ulong *)&__bss_end; + fdt_blob = (ulong *)__bss_end; #else /* FDT is at end of image */ - fdt_blob = (ulong *)&_end; + fdt_blob = (ulong *)_end; if (_DEBUG && !fdtdec_prepare_fdt(fdt_blob)) { int stack_ptr; diff --git a/lib/trace.c b/lib/trace.c index 1091a5793a1..4874bef861b 100644 --- a/lib/trace.c +++ b/lib/trace.c @@ -51,7 +51,7 @@ static inline uintptr_t __attribute__((no_instrument_function)) uintptr_t offset = (uintptr_t)func_ptr; #ifdef CONFIG_SANDBOX - offset -= (uintptr_t)&_init; + offset -= (uintptr_t)_init; #else if (gd->flags & GD_FLG_RELOC) offset -= gd->relocaddr; -- cgit v1.2.3 From 34ecba1f7616b388ee28490e8a3ed43fb1463011 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 14 Aug 2023 16:40:22 -0600 Subject: abuf: Allow incrementing the size Provide a convenience function to increment the size of the abuf. Signed-off-by: Simon Glass --- lib/abuf.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/abuf.c b/lib/abuf.c index bd270467dd4..ce2cff53dc9 100644 --- a/lib/abuf.c +++ b/lib/abuf.c @@ -82,6 +82,11 @@ bool abuf_realloc(struct abuf *abuf, size_t new_size) } } +bool abuf_realloc_inc(struct abuf *abuf, size_t inc) +{ + return abuf_realloc(abuf, abuf->size + inc); +} + void *abuf_uninit_move(struct abuf *abuf, size_t *sizep) { void *ptr; -- cgit v1.2.3 From 8d6337e69147557fb3c4b89a27156ac468a20500 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:36 -0600 Subject: uuid: Move function comments to header file These should be in the header file for easy browsing, not in the source code. Move them and add a missing Return on one of the functions. Signed-off-by: Simon Glass --- lib/uuid.c | 103 ------------------------------------------------------------- 1 file changed, 103 deletions(-) (limited to 'lib') diff --git a/lib/uuid.c b/lib/uuid.c index d0187007d0e..3bdb20b0e5b 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -23,50 +23,6 @@ #include #include -/* - * UUID - Universally Unique IDentifier - 128 bits unique number. - * There are 5 versions and one variant of UUID defined by RFC4122 - * specification. A UUID contains a set of fields. The set varies - * depending on the version of the UUID, as shown below: - * - time, MAC address(v1), - * - user ID(v2), - * - MD5 of name or URL(v3), - * - random data(v4), - * - SHA-1 of name or URL(v5), - * - * Layout of UUID: - * timestamp - 60-bit: time_low, time_mid, time_hi_and_version - * version - 4 bit (bit 4 through 7 of the time_hi_and_version) - * clock seq - 14 bit: clock_seq_hi_and_reserved, clock_seq_low - * variant: - bit 6 and 7 of clock_seq_hi_and_reserved - * node - 48 bit - * - * source: https://www.ietf.org/rfc/rfc4122.txt - * - * UUID binary format (16 bytes): - * - * 4B-2B-2B-2B-6B (big endian - network byte order) - * - * UUID string is 36 length of characters (36 bytes): - * - * 0 9 14 19 24 - * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - * be be be be be - * - * where x is a hexadecimal character. Fields are separated by '-'s. - * When converting to a binary UUID, le means the field should be converted - * to little endian and be means it should be converted to big endian. - * - * UUID is also used as GUID (Globally Unique Identifier) with the same binary - * format but it differs in string format like below. - * - * GUID: - * 0 9 14 19 24 - * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - * le le le be be - * - * GUID is used e.g. in GPT (GUID Partition Table) as a partiions unique id. - */ int uuid_str_valid(const char *uuid) { int i, valid; @@ -269,12 +225,6 @@ static const struct { #endif }; -/* - * uuid_guid_get_bin() - this function get GUID bin for string - * - * @param guid_str - pointer to partition type string - * @param guid_bin - pointer to allocated array for big endian output [16B] - */ int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin) { int i; @@ -288,13 +238,6 @@ int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin) return -ENODEV; } -/* - * uuid_guid_get_str() - this function get string for GUID. - * - * @param guid_bin - pointer to string with partition type guid [16B] - * - * Returns NULL if the type GUID is not known. - */ const char *uuid_guid_get_str(const unsigned char *guid_bin) { int i; @@ -307,13 +250,6 @@ const char *uuid_guid_get_str(const unsigned char *guid_bin) return NULL; } -/* - * uuid_str_to_bin() - convert string UUID or GUID to big endian binary data. - * - * @param uuid_str - pointer to UUID or GUID string [37B] or GUID shorcut - * @param uuid_bin - pointer to allocated array for big endian output [16B] - * @str_format - UUID string format: 0 - UUID; 1 - GUID - */ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, int str_format) { @@ -358,23 +294,6 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, return 0; } -/** - * uuid_str_to_le_bin() - Convert string UUID to little endian binary data. - * @uuid_str: pointer to UUID string - * @uuid_bin: pointer to allocated array for little endian output [16B] - * - * UUID string is 36 characters (36 bytes): - * - * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - * - * where x is a hexadecimal character. Fields are separated by '-'s. - * When converting to a little endian binary UUID, the string fields are reversed. - * - * Return: - * - * uuid_bin filled with little endian UUID data - * On success 0 is returned. Otherwise, failure code. - */ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) { u16 tmp16; @@ -402,14 +321,6 @@ int uuid_str_to_le_bin(const char *uuid_str, unsigned char *uuid_bin) return 0; } -/* - * uuid_bin_to_str() - convert big endian binary data to string UUID or GUID. - * - * @param uuid_bin: pointer to binary data of UUID (big endian) [16B] - * @param uuid_str: pointer to allocated array for output string [37B] - * @str_format: bit 0: 0 - UUID; 1 - GUID - * bit 1: 0 - lower case; 2 - upper case - */ void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, int str_format) { @@ -449,13 +360,6 @@ void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, } } -/* - * gen_rand_uuid() - this function generates a random binary UUID version 4. - * In this version all fields beside 4 bits of version and - * 2 bits of variant are randomly generated. - * - * @param uuid_bin - pointer to allocated array [16B]. Output is in big endian. -*/ #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID) void gen_rand_uuid(unsigned char *uuid_bin) { @@ -493,13 +397,6 @@ void gen_rand_uuid(unsigned char *uuid_bin) memcpy(uuid_bin, uuid, 16); } -/* - * gen_rand_uuid_str() - this function generates UUID v4 (random) in two string - * formats UUID or GUID. - * - * @param uuid_str - pointer to allocated array [37B]. - * @param - uuid output type: UUID - 0, GUID - 1 - */ void gen_rand_uuid_str(char *uuid_str, int str_format) { unsigned char uuid_bin[UUID_BIN_LEN]; -- cgit v1.2.3 From 966b16c59a70cd2e3383eb77d49c1e62b093b36f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:44 -0600 Subject: uuid: Add ChromiumOS partition types Add some GUIDs for ChromiumOS so we can detect the partitions. Signed-off-by: Simon Glass --- lib/uuid.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/uuid.c b/lib/uuid.c index 3bdb20b0e5b..afb40bff507 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -7,6 +7,8 @@ * Abdellatif El Khlifi */ +#define LOG_CATEGOT LOGC_CORE + #include #include #include @@ -61,6 +63,10 @@ static const struct { {"swap", PARTITION_LINUX_SWAP_GUID}, {"lvm", PARTITION_LINUX_LVM_GUID}, {"u-boot-env", PARTITION_U_BOOT_ENVIRONMENT}, + {"cros-kern", PARTITION_CROS_KERNEL}, + {"cros-root", PARTITION_CROS_ROOT}, + {"cros-fw", PARTITION_CROS_FIRMWARE}, + {"cros-rsrv", PARTITION_CROS_RESERVED}, #endif #if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI) { @@ -258,6 +264,7 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, uint64_t tmp64; if (!uuid_str_valid(uuid_str)) { + log_debug("not valid\n"); #ifdef CONFIG_PARTITION_TYPE_GUID if (!uuid_guid_get_bin(uuid_str, uuid_bin)) return 0; -- cgit v1.2.3 From c7d4dfcd142d624ed43ac590c6ef5eca24233e30 Mon Sep 17 00:00:00 2001 From: Sughosh Ganu Date: Tue, 22 Aug 2023 23:10:05 +0530 Subject: scripts/Makefile.lib: Embed capsule public key in platform's dtb The EFI capsule authentication logic in u-boot expects the public key in the form of an EFI Signature List(ESL) to be provided as part of the platform's dtb. Currently, the embedding of the ESL file into the dtb needs to be done manually. Add a target for generating a dtsi file which contains the signature node with the ESL file included as a property under the signature node. Include the dtsi file in the dtb. This brings the embedding of the ESL in the dtb into the U-Boot build flow. The path to the ESL file is specified through the CONFIG_EFI_CAPSULE_ESL_FILE symbol. Signed-off-by: Sughosh Ganu Reviewed-by: Tom Rini Reviewed-by: Ilias Apalodimas --- lib/efi_loader/Kconfig | 8 ++++++++ lib/efi_loader/capsule_esl.dtsi.in | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lib/efi_loader/capsule_esl.dtsi.in (limited to 'lib') diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 9989e3f384e..d20aaab6dba 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -272,6 +272,14 @@ config EFI_CAPSULE_MAX Select the max capsule index value used for capsule report variables. This value is used to create CapsuleMax variable. +config EFI_CAPSULE_ESL_FILE + string "Path to the EFI Signature List File" + depends on EFI_CAPSULE_AUTHENTICATE + help + Provides the path to the EFI Signature List file which will + be embedded in the platform's device tree and used for + capsule authentication at the time of capsule update. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/capsule_esl.dtsi.in b/lib/efi_loader/capsule_esl.dtsi.in new file mode 100644 index 00000000000..61a9f2b25e9 --- /dev/null +++ b/lib/efi_loader/capsule_esl.dtsi.in @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ +/** + * Devicetree file with the public key EFI Signature List(ESL) + * node. This file is used to generate the dtsi file to be + * included into the DTB. +*/ +/ { + signature { + capsule-key = /incbin/("ESL_BIN_FILE"); + }; +}; -- cgit v1.2.3 From 95311f7a194aabc1a52d4f240fef36f21b3178fd Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 23 Aug 2023 02:16:52 +0200 Subject: fwu: Initialize global fwu library state during CI test The current CI test worked by sheer luck, the g_dev global pointer in the fwu library was never initialized and the test equally well failed on sandbox64. Trigger the main loop in sandbox tests too to initialize that global state, and move the sandbox specific exit from fwu_boottime_checks after g_dev is initialized. Signed-off-by: Marek Vasut Acked-by: Sughosh Ganu Reviewed-by: Simon Glass --- lib/fwu_updates/fwu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 4d0c8b84b9d..22bdc78df59 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -623,18 +623,18 @@ static int fwu_boottime_checks(void *ctx, struct event *event) int ret; u32 boot_idx, active_idx; - /* Don't have boot time checks on sandbox */ - if (IS_ENABLED(CONFIG_SANDBOX)) { - boottime_check = 1; - return 0; - } - ret = uclass_first_device_err(UCLASS_FWU_MDATA, &g_dev); if (ret) { log_debug("Cannot find fwu device\n"); return ret; } + /* Don't have boot time checks on sandbox */ + if (IS_ENABLED(CONFIG_SANDBOX)) { + boottime_check = 1; + return 0; + } + ret = fwu_get_mdata(NULL); if (ret) { log_debug("Unable to read meta-data\n"); -- cgit v1.2.3 From e7f59dea880ea25078273473c575794dac08dca2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:49 -0600 Subject: Revert "initcall: Move to inline function" Somehow I do not see any inlining with initcalls now. I was sure I saw it when this commit went in, but now it seems to make things worse. This reverts commit 47870afab92fca6e672c03d0dea802a55e200675. Signed-off-by: Simon Glass --- lib/Makefile | 1 + lib/initcall.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 lib/initcall.c (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 8d8ccc8bbc3..839872d804b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-$(CONFIG_SMBIOS_PARSER) += smbios-parser.o obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o +obj-y += initcall.o obj-y += ldiv.o obj-$(CONFIG_XXHASH) += xxhash.o obj-y += net_utils.o diff --git a/lib/initcall.c b/lib/initcall.c new file mode 100644 index 00000000000..eedb0fbf1d5 --- /dev/null +++ b/lib/initcall.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2013 The Chromium OS Authors. + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* + * To enable debugging. add #define DEBUG at the top of the including file. + * + * To find a symbol, use grep on u-boot.map + */ +int initcall_run_list(const init_fnc_t init_sequence[]) +{ + const init_fnc_t *init_fnc_ptr; + + for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { + unsigned long reloc_ofs = 0; + int ret; + + /* + * Sandbox is relocated by the OS, so symbols always appear at + * the relocated address. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) + reloc_ofs = gd->reloc_off; +#ifdef CONFIG_EFI_APP + reloc_ofs = (unsigned long)image_base; +#endif + if (reloc_ofs) + debug("initcall: %p (relocated to %p)\n", + (char *)*init_fnc_ptr - reloc_ofs, + (char *)*init_fnc_ptr); + else + debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); + + ret = (*init_fnc_ptr)(); + if (ret) { + printf("initcall sequence %p failed at call %p (err=%d)\n", + init_sequence, + (char *)*init_fnc_ptr - reloc_ofs, ret); + return -1; + } + } + return 0; +} -- cgit v1.2.3 From 7d2e23394ffbbc1d5b5f2479e0c52db52907cc40 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:50 -0600 Subject: initcall: Factor out reloc_off calculation Move this into a function and do it once, not each time around the loop. Signed-off-by: Simon Glass --- lib/initcall.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index eedb0fbf1d5..89a68b2444f 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -11,6 +11,20 @@ DECLARE_GLOBAL_DATA_PTR; +static ulong calc_reloc_ofs(void) +{ +#ifdef CONFIG_EFI_APP + return (ulong)image_base; +#endif + /* + * Sandbox is relocated by the OS, so symbols always appear at + * the relocated address. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) + return gd->reloc_off; + + return 0; +} /* * To enable debugging. add #define DEBUG at the top of the including file. * @@ -18,21 +32,12 @@ DECLARE_GLOBAL_DATA_PTR; */ int initcall_run_list(const init_fnc_t init_sequence[]) { + ulong reloc_ofs = calc_reloc_ofs(); const init_fnc_t *init_fnc_ptr; for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - unsigned long reloc_ofs = 0; int ret; - /* - * Sandbox is relocated by the OS, so symbols always appear at - * the relocated address. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || (gd->flags & GD_FLG_RELOC)) - reloc_ofs = gd->reloc_off; -#ifdef CONFIG_EFI_APP - reloc_ofs = (unsigned long)image_base; -#endif if (reloc_ofs) debug("initcall: %p (relocated to %p)\n", (char *)*init_fnc_ptr - reloc_ofs, -- cgit v1.2.3 From 468e372e9ad4c551d513b2e73c1f5c1cbb2e4097 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:51 -0600 Subject: initcall: Adjust the loop logic Use a variable to hold the function, so we don't need to repeat the pointer access each time. Rename the init pointer to 'ptr' since we only refer to it in the for() statement now. Signed-off-by: Simon Glass --- lib/initcall.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index 89a68b2444f..81c5d245073 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -33,25 +33,25 @@ static ulong calc_reloc_ofs(void) int initcall_run_list(const init_fnc_t init_sequence[]) { ulong reloc_ofs = calc_reloc_ofs(); - const init_fnc_t *init_fnc_ptr; + const init_fnc_t *ptr; + init_fnc_t func; + int ret = 0; - for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - int ret; - - if (reloc_ofs) + for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) { + if (reloc_ofs) { debug("initcall: %p (relocated to %p)\n", - (char *)*init_fnc_ptr - reloc_ofs, - (char *)*init_fnc_ptr); - else - debug("initcall: %p\n", (char *)*init_fnc_ptr - reloc_ofs); + (char *)func - reloc_ofs, func); + } else { + debug("initcall: %p\n", (char *)func - reloc_ofs); + } - ret = (*init_fnc_ptr)(); + ret = func(); if (ret) { printf("initcall sequence %p failed at call %p (err=%d)\n", - init_sequence, - (char *)*init_fnc_ptr - reloc_ofs, ret); + init_sequence, (char *)func - reloc_ofs, ret); return -1; } } + return 0; } -- cgit v1.2.3 From 13123276806f5a2e209bd1ae16c894e0415e520d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:52 -0600 Subject: initcall: Adjust the failure message and return value Move the failure message outside the loop, so it is easier to follow the code. Avoid swallowing the error code - just pass it along. Drop the initcall-list address from the output. This is confusing since we show two addresses. Really it is only the function address which is useful, since it can be looked up in the map, e.g. with: grep -A1 -B1 serial_init u-boot.map Signed-off-by: Simon Glass --- lib/initcall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index 81c5d245073..0f74cef32f8 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -46,11 +46,13 @@ int initcall_run_list(const init_fnc_t init_sequence[]) } ret = func(); - if (ret) { - printf("initcall sequence %p failed at call %p (err=%d)\n", - init_sequence, (char *)func - reloc_ofs, ret); - return -1; - } + } + + if (ret) { + printf("initcall failed at call %p (err=%dE)\n", + (char *)func - reloc_ofs, ret); + + return ret; } return 0; -- cgit v1.2.3 From c9eff0a6b6ea2bcd54d30f8a02281681f3730223 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:54 -0600 Subject: initcall: Support emitting events At present the initcall list consists of a list of function pointers. Over time the initcall lists will likely change to mostly emitting events, since most of the calls are board- or arch-specific. As a first step, allow an initcall to be an event type instead of a function pointer. Add the required macro and update initcall_run_list() to emit an event in that case, or ignore it if events are not enabled. The bottom 8 bits of the function pointer are used to hold the event type, with the rest being all ones. This should avoid any collision, since initcalls should not be above 0xffffff00 in memory. Convert misc_init_f over to use this mechanism. Add comments to the initcall header file while we are here. Also fix up the trace test to handle the change. Signed-off-by: Simon Glass --- lib/initcall.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index 0f74cef32f8..33b7d761dc7 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -7,6 +7,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -25,6 +26,23 @@ static ulong calc_reloc_ofs(void) return 0; } + +/** + * initcall_is_event() - Get the event number for an initcall + * + * func: Function pointer to check + * Return: Event number, if this is an event, else 0 + */ +static int initcall_is_event(init_fnc_t func) +{ + ulong val = (ulong)func; + + if ((val & INITCALL_IS_EVENT) == INITCALL_IS_EVENT) + return val & INITCALL_EVENT_TYPE; + + return 0; +} + /* * To enable debugging. add #define DEBUG at the top of the including file. * @@ -34,23 +52,45 @@ int initcall_run_list(const init_fnc_t init_sequence[]) { ulong reloc_ofs = calc_reloc_ofs(); const init_fnc_t *ptr; + enum event_t type; init_fnc_t func; int ret = 0; for (ptr = init_sequence; func = *ptr, !ret && func; ptr++) { - if (reloc_ofs) { + type = initcall_is_event(func); + + if (type) { + if (!CONFIG_IS_ENABLED(EVENT)) + continue; + debug("initcall: event %d/%s\n", type, + event_type_name(type)); + } else if (reloc_ofs) { debug("initcall: %p (relocated to %p)\n", - (char *)func - reloc_ofs, func); + (char *)func - reloc_ofs, (char *)func); } else { debug("initcall: %p\n", (char *)func - reloc_ofs); } - ret = func(); + ret = type ? event_notify_null(type) : func(); } if (ret) { - printf("initcall failed at call %p (err=%dE)\n", - (char *)func - reloc_ofs, ret); + if (CONFIG_IS_ENABLED(EVENT)) { + char buf[60]; + + /* don't worry about buf size as we are dying here */ + if (type) { + sprintf(buf, "event %d/%s", type, + event_type_name(type)); + } else { + sprintf(buf, "call %p", func); + } + + printf("initcall failed at %s (err=%dE)\n", buf, ret); + } else { + printf("initcall failed at call %p (err=%d)\n", + (char *)func - reloc_ofs, ret); + } return ret; } -- cgit v1.2.3 From dd802467f44b68d6ed9315ffe3002b17dc43b622 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:55 -0600 Subject: initcall: Support manual relocation Move the manual-relocation code to the initcall file. Make sure to avoid manually relocating event types. Only true function pointers should be relocated. Signed-off-by: Simon Glass --- lib/initcall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index 33b7d761dc7..480490ea239 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -97,3 +97,13 @@ int initcall_run_list(const init_fnc_t init_sequence[]) return 0; } + +void initcall_manual_reloc(init_fnc_t init_sequence[]) +{ + init_fnc_t *ptr; + + for (ptr = init_sequence; *ptr; ptr++) { + if (!initcall_is_event(*ptr)) + MANUAL_RELOC(*ptr); + } +} -- cgit v1.2.3 From f72d0d4a2f9a2d05ebeefb583992cc620f7c4c2d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Aug 2023 21:16:56 -0600 Subject: event: Convert existing spy records to simple Very few of the existing event-spy records use the arguments they are passed. Update them to use a simple spy instead, to simplify the code. Where an adaptor function is currently used, remove it where possible. Signed-off-by: Simon Glass --- lib/fwu_updates/fwu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/fwu_updates/fwu.c b/lib/fwu_updates/fwu.c index 22bdc78df59..b5805740153 100644 --- a/lib/fwu_updates/fwu.c +++ b/lib/fwu_updates/fwu.c @@ -618,7 +618,7 @@ int fwu_trial_state_ctr_start(void) return ret; } -static int fwu_boottime_checks(void *ctx, struct event *event) +static int fwu_boottime_checks(void) { int ret; u32 boot_idx, active_idx; @@ -682,4 +682,4 @@ static int fwu_boottime_checks(void *ctx, struct event *event) return 0; } -EVENT_SPY(EVT_MAIN_LOOP, fwu_boottime_checks); +EVENT_SPY_SIMPLE(EVT_MAIN_LOOP, fwu_boottime_checks); -- cgit v1.2.3 From 49c59dd5ca3078a135f85bcd1cb00e57029a1cde Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 6 Sep 2023 23:29:44 +0200 Subject: common: board_r: Remove unused NEEDS_MANUAL_RELOC code bits The last user of the NEEDS_MANUAL_RELOC has been removed in commit 26af162ac8f8 ("arch: m68k: Implement relocation") Remove now unused NEEDS_MANUAL_RELOC code. Signed-off-by: Marek Vasut --- lib/initcall.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib') diff --git a/lib/initcall.c b/lib/initcall.c index 480490ea239..33b7d761dc7 100644 --- a/lib/initcall.c +++ b/lib/initcall.c @@ -97,13 +97,3 @@ int initcall_run_list(const init_fnc_t init_sequence[]) return 0; } - -void initcall_manual_reloc(init_fnc_t init_sequence[]) -{ - init_fnc_t *ptr; - - for (ptr = init_sequence; *ptr; ptr++) { - if (!initcall_is_event(*ptr)) - MANUAL_RELOC(*ptr); - } -} -- cgit v1.2.3 From a90b5946f488e8a36bd318220244ecd0908ce1d3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Sep 2023 10:55:39 -0600 Subject: lib: rational: Move the Kconfigs into the correct place These should not be part of the 'system tables' menu. Move them outside on their own. Signed-off-by: Simon Glass Fixes: 7d0f3fbb93c ("lib: rational: copy the rational fraction lib...") Reviewed-by: Tom Rini --- lib/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index 42e559ad0b5..9addcfab373 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -989,6 +989,8 @@ config GENERATE_SMBIOS_TABLE See also SMBIOS_SYSINFO which allows SMBIOS values to be provided in the devicetree. +endmenu + config LIB_RATIONAL bool "enable continued fraction calculation routines" @@ -996,8 +998,6 @@ config SPL_LIB_RATIONAL bool "enable continued fraction calculation routines for SPL" depends on SPL -endmenu - config ASN1_COMPILER bool help -- cgit v1.2.3 From 4cc40f618a83f58216f49040f08e3b5f1868c990 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Sep 2023 10:55:43 -0600 Subject: FWU: Avoid showing an unselectable menu option Use a menuconfig to avoid showing a menu which cannot be selected in many cases. Signed-off-by: Simon Glass Acked-by: Sughosh Ganu Reviewed-by: Tom Rini Acked-by: Ilias Apalodimas --- lib/Kconfig | 4 ---- lib/fwu_updates/Kconfig | 9 +++++---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index 9addcfab373..bfab2f3165a 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1118,8 +1118,4 @@ config PHANDLE_CHECK_SEQ endmenu -menu "FWU Multi Bank Updates" - source lib/fwu_updates/Kconfig - -endmenu diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index 71f34793d92..d35247d0e5d 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -1,4 +1,4 @@ -config FWU_MULTI_BANK_UPDATE +menuconfig FWU_MULTI_BANK_UPDATE bool "Enable FWU Multi Bank Update Feature" depends on EFI_CAPSULE_ON_DISK select PARTITION_TYPE_GUID @@ -10,24 +10,25 @@ config FWU_MULTI_BANK_UPDATE multiple banks(copies) of the firmware images. One of the bank is selected for updating all the firmware components +if FWU_MULTI_BANK_UPDATE + config FWU_NUM_BANKS int "Number of Banks defined by the platform" - depends on FWU_MULTI_BANK_UPDATE help Define the number of banks of firmware images on a platform config FWU_NUM_IMAGES_PER_BANK int "Number of firmware images per bank" - depends on FWU_MULTI_BANK_UPDATE help Define the number of firmware images per bank. This value should be the same for all the banks. config FWU_TRIAL_STATE_CNT int "Number of times system boots in Trial State" - depends on FWU_MULTI_BANK_UPDATE default 3 help With FWU Multi Bank Update feature enabled, number of times the platform is allowed to boot in Trial State after an update. + +endif -- cgit v1.2.3 From 040a604880c6eb86779ef564c055deb7b1bcb828 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Sep 2023 10:55:57 -0600 Subject: boot: Join FDT_FIXUP_PARTITIONS with related options Move this to be with the other devicetree-fixup options. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- lib/Kconfig | 9 --------- 1 file changed, 9 deletions(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index bfab2f3165a..eb2b1016182 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -953,15 +953,6 @@ config VPL_OF_LIBFDT_ASSUME_MASK 0xff means all assumptions are made and any invalid data may cause unsafe execution. See FDT_ASSUME_PERFECT, etc. in libfdt_internal.h -config FDT_FIXUP_PARTITIONS - bool "overwrite MTD partitions in DTS through defined in 'mtdparts'" - depends on OF_LIBFDT - depends on CMD_MTDPARTS - help - Allow overwriting defined partitions in the device tree blob - using partition info defined in the 'mtdparts' environment - variable. - menu "System tables" depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER) -- cgit v1.2.3 From 0c45c76ced7222ad8e5fb41b8be4d5237fd791a0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 19 Sep 2023 21:00:06 -0600 Subject: x86: Allow APCI in SPL This is needed so we can find the DBG2 table provided by coreboot. Add a Kconfig so it can be enabled. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- lib/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index eb2b1016182..7edaeebfdaf 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -289,6 +289,14 @@ config ACPI not necessarily include generation of tables (see GENERATE_ACPI_TABLE), but allows for tables to be located. +config SPL_ACPI + bool "Enable support for ACPI libraries in SPL" + depends on SPL && SUPPORT_ACPI + help + Provides library functions for dealing with ACPI tables in SPL. This + does not necessarily include generation of tables + (see GENERATE_ACPI_TABLE), but allows for tables to be located. + config GENERATE_ACPI_TABLE bool "Generate an ACPI (Advanced Configuration and Power Interface) table" depends on ACPI -- cgit v1.2.3 From 53e8e6f98679a30eb338ca98ec173aa6ddd28d54 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 19 Sep 2023 21:00:12 -0600 Subject: efi: x86: Correct the condition for installing ACPI tables It is not always the case that U-Boot builds the ACPI tables itself. For example, when booting from coreboot, the ACPI tables are built by coreboot. Correct the Makefile condition so that U-Boot can pass on tables built by a previous firmware stage. Tidy up the installation-condition code while we are here. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas Reviewed-by: Bin Meng --- lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_setup.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 1a8c8d7cab5..0eb748ff1a5 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -78,7 +78,7 @@ obj-$(CONFIG_EFI_ESRT) += efi_esrt.o obj-$(CONFIG_VIDEO) += efi_gop.o obj-$(CONFIG_BLK) += efi_disk.o obj-$(CONFIG_NETDEVICES) += efi_net.o -obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o +obj-$(CONFIG_ACPI) += efi_acpi.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 58d4e134023..ad719afd632 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -321,11 +321,11 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; #endif -#ifdef CONFIG_GENERATE_ACPI_TABLE - ret = efi_acpi_register(); - if (ret != EFI_SUCCESS) - goto out; -#endif + if (IS_ENABLED(CONFIG_ACPI)) { + ret = efi_acpi_register(); + if (ret != EFI_SUCCESS) + goto out; + } #ifdef CONFIG_GENERATE_SMBIOS_TABLE ret = efi_smbios_register(); if (ret != EFI_SUCCESS) -- cgit v1.2.3 From 8c11d19e7599442d0325f79c7c7705b951f821d4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 19 Sep 2023 21:00:13 -0600 Subject: x86: smbios: Add a Kconfig indicating SMBIOS-table presence When booted from coreboot, U-Boot does not build the SMBIOS tables, but it should still pass them on to the OS. Add a new option which indicates whether SMBIOS tables are present, however they were built. Flip the ordering so that the dependency is listed first, which is less confusing. Adjust GENERATE_SMBIOS_TABLE to depend on this new symbol. Signed-off-by: Simon Glass Reviewed-by: Heinrich Schuchardt Reviewed-by: Bin Meng --- lib/Kconfig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index 7edaeebfdaf..6b5389f3a87 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -975,8 +975,8 @@ config BLOBLIST_TABLES config GENERATE_SMBIOS_TABLE bool "Generate an SMBIOS (System Management BIOS) table" + depends on SMBIOS default y - depends on X86 || EFI_LOADER help The System Management BIOS (SMBIOS) specification addresses how motherboard and system vendors present management information about @@ -1045,6 +1045,19 @@ config SPL_OID_REGISTRY unambiguous persistent name (https://en.wikipedia.org/wiki/Object_identifier). Enable fast lookup object identifier registry in the SPL. +config SMBIOS + bool "SMBIOS support" + depends on X86 || EFI_LOADER + default y + help + Indicates that this platform can support System Management BIOS + (SMBIOS) tables. These provide various pieces of information about + the board, such as the manufacturer and the model name. + + See GENERATE_SMBIOS_TABLE which controls whether U-Boot actually + creates these tables, rather than them coming from a previous firmware + stage. + config SMBIOS_PARSER bool "SMBIOS parser" help -- cgit v1.2.3 From 53fab13a7b11630aeb731c8ef7553cf773311a9f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 20 Sep 2023 07:29:51 -0600 Subject: efi: Use the installed SMBIOS tables U-Boot should set up the SMBIOS tables during startup, as it does on x86. Ensure that it does this correctly on non-x86 machines too, by creating an event spy for last-stage init. Tidy up the installation-condition code while we are here. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- lib/Kconfig | 1 + lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_setup.c | 10 +++---- lib/efi_loader/efi_smbios.c | 72 +++++++++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/Kconfig b/lib/Kconfig index 6b5389f3a87..79cf9ef0fa3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1049,6 +1049,7 @@ config SMBIOS bool "SMBIOS support" depends on X86 || EFI_LOADER default y + select LAST_STAGE_INIT help Indicates that this platform can support System Management BIOS (SMBIOS) tables. These provide various pieces of information about diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 0eb748ff1a5..8d31fc61c60 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -79,7 +79,7 @@ obj-$(CONFIG_VIDEO) += efi_gop.o obj-$(CONFIG_BLK) += efi_disk.o obj-$(CONFIG_NETDEVICES) += efi_net.o obj-$(CONFIG_ACPI) += efi_acpi.o -obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o +obj-$(CONFIG_SMBIOS) += efi_smbios.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index ad719afd632..e6de685e879 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -326,11 +326,11 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; } -#ifdef CONFIG_GENERATE_SMBIOS_TABLE - ret = efi_smbios_register(); - if (ret != EFI_SUCCESS) - goto out; -#endif + if (IS_ENABLED(CONFIG_SMBIOS)) { + ret = efi_smbios_register(); + if (ret != EFI_SUCCESS) + goto out; + } ret = efi_watchdog_register(); if (ret != EFI_SUCCESS) goto out; diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c index 306c0bc54f9..48446f654d9 100644 --- a/lib/efi_loader/efi_smbios.c +++ b/lib/efi_loader/efi_smbios.c @@ -10,8 +10,14 @@ #include #include #include +#include #include #include +#include + +enum { + TABLE_SIZE = SZ_4K, +}; /* * Install the SMBIOS table as a configuration table. @@ -20,36 +26,50 @@ */ efi_status_t efi_smbios_register(void) { - /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ - u64 dmi_addr = U32_MAX; + ulong addr; efi_status_t ret; - void *dmi; - /* Reserve 4kiB page for SMBIOS */ - ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr); + addr = gd->arch.smbios_start; + if (!addr) { + log_err("No SMBIOS tables to install\n"); + return EFI_NOT_FOUND; + } + + /* Mark space used for tables */ + ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA); + if (ret) + return ret; + + log_debug("EFI using SMBIOS tables at %lx\n", addr); + + /* Install SMBIOS information as configuration table */ + return efi_install_configuration_table(&smbios_guid, + map_sysmem(addr, 0)); +} + +static int install_smbios_table(void) +{ + ulong addr; + void *buf; - if (ret != EFI_SUCCESS) { - /* Could not find space in lowmem, use highmem instead */ - ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, - EFI_RUNTIME_SERVICES_DATA, 1, - &dmi_addr); + if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86)) + return 0; - if (ret != EFI_SUCCESS) - return ret; + /* Align the table to a 4KB boundary to keep EFI happy */ + buf = memalign(SZ_4K, TABLE_SIZE); + if (!buf) + return log_msg_ret("mem", -ENOMEM); + + addr = map_to_sysmem(buf); + if (!write_smbios_table(addr)) { + log_err("Failed to write SMBIOS table\n"); + return log_msg_ret("smbios", -EINVAL); } - /* - * Generate SMBIOS tables - we know that efi_allocate_pages() returns - * a 4k-aligned address, so it is safe to assume that - * write_smbios_table() will write the table at that address. - */ - assert(!(dmi_addr & 0xf)); - dmi = (void *)(uintptr_t)dmi_addr; - if (write_smbios_table(map_to_sysmem(dmi))) - /* Install SMBIOS information as configuration table */ - return efi_install_configuration_table(&smbios_guid, dmi); - efi_free_pages(dmi_addr, 1); - log_err("Cannot create SMBIOS table\n"); - return EFI_SUCCESS; + /* Make a note of where we put it */ + log_debug("SMBIOS tables written to %lx\n", addr); + gd->arch.smbios_start = addr; + + return 0; } +EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table); -- cgit v1.2.3 From 1e94b46f73cedcebbff73799203f3266c5b28d90 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Sep 2023 18:21:46 -0600 Subject: common: Drop linux/printk.h from common header This old patch was marked as deferred. Bring it back to life, to continue towards the removal of common.h Move this out of the common header and include it only where needed. Signed-off-by: Simon Glass --- lib/asn1_decoder.c | 1 + lib/bch.c | 1 + lib/crypto/asymmetric_type.c | 1 + lib/crypto/pkcs7_parser.c | 1 + lib/crypto/pkcs7_verify.c | 1 + lib/crypto/public_key.c | 1 + lib/crypto/rsa_helper.c | 1 + lib/crypto/x509_cert_parser.c | 1 + lib/crypto/x509_public_key.c | 1 + lib/list_sort.c | 1 + 10 files changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/asn1_decoder.c b/lib/asn1_decoder.c index bcb0390eb41..1191fc36487 100644 --- a/lib/asn1_decoder.c +++ b/lib/asn1_decoder.c @@ -8,6 +8,7 @@ #ifdef __UBOOT__ #include #include +#include #else #include #endif diff --git a/lib/bch.c b/lib/bch.c index de66b1acba5..72b4fdcc9c4 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -61,6 +61,7 @@ #include #include +#include #else #include #if defined(__FreeBSD__) diff --git a/lib/crypto/asymmetric_type.c b/lib/crypto/asymmetric_type.c index 1d0532d0f2e..24c2d15ef97 100644 --- a/lib/crypto/asymmetric_type.c +++ b/lib/crypto/asymmetric_type.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #else #include diff --git a/lib/crypto/pkcs7_parser.c b/lib/crypto/pkcs7_parser.c index 0b85fe8286c..d5efa828d6a 100644 --- a/lib/crypto/pkcs7_parser.c +++ b/lib/crypto/pkcs7_parser.c @@ -11,6 +11,7 @@ #include #include #include +#include #endif #include #ifndef __UBOOT__ diff --git a/lib/crypto/pkcs7_verify.c b/lib/crypto/pkcs7_verify.c index b832f013566..9d7b9f6bce8 100644 --- a/lib/crypto/pkcs7_verify.c +++ b/lib/crypto/pkcs7_verify.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/crypto/public_key.c b/lib/crypto/public_key.c index 3671ed13855..6efe951c057 100644 --- a/lib/crypto/public_key.c +++ b/lib/crypto/public_key.c @@ -13,6 +13,7 @@ #include #include #include +#include #else #include #include diff --git a/lib/crypto/rsa_helper.c b/lib/crypto/rsa_helper.c index cc0c0d6637b..c941d40fd7a 100644 --- a/lib/crypto/rsa_helper.c +++ b/lib/crypto/rsa_helper.c @@ -15,6 +15,7 @@ #include #endif #include +#include #include "rsapubkey.asn1.h" #ifndef __UBOOT__ #include "rsaprivkey.asn1.h" diff --git a/lib/crypto/x509_cert_parser.c b/lib/crypto/x509_cert_parser.c index eb24349460c..a0f0689118f 100644 --- a/lib/crypto/x509_cert_parser.c +++ b/lib/crypto/x509_cert_parser.c @@ -16,6 +16,7 @@ #include #include #ifdef __UBOOT__ +#include #include #endif #include diff --git a/lib/crypto/x509_public_key.c b/lib/crypto/x509_public_key.c index 5c0e2b622db..30071233ee7 100644 --- a/lib/crypto/x509_public_key.c +++ b/lib/crypto/x509_public_key.c @@ -13,6 +13,7 @@ #include #include #include +#include #else #include #endif diff --git a/lib/list_sort.c b/lib/list_sort.c index 58e1e1614a5..1c9e0617327 100644 --- a/lib/list_sort.c +++ b/lib/list_sort.c @@ -8,6 +8,7 @@ #include #include #include +#include #endif #include #include -- cgit v1.2.3