[U-Boot] [PATCH v6 00/10] efi_loader: Expose SMBIOS table

We generate a few tables on x86 today that really can be used on ARM just the same. One such example is the SMBIOS table, which people use with tools like "dmidecode" to identify which hardware they are running on.
We're slowly growing needs to collect serial numbers from various devices on ARM and SMBIOS seems the natural choice. So this patch set moves the current SMBIOS generation into generic code and adds serial number exposure to it.
I have verified that I get a correct serial number printed in dmidecode on the RPi3.
v1 -> v2:
- Also populate UUID - Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file - New patch: Make type4 table available on all archs
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo - s/smbios_write_type4_arch/smbios_write_type4_dm/
v5 -> v6:
- move csum into C file - new patch: cpu: Add DMTF id and family fields - new patch: cpu: Add get_vendor callback - change calling convention of get_vendor() - add comments on DMTF fields
Alexander Graf (10): x86: Move table csum into separate file x86: Move smbios generation into arch independent directory efi_loader: Expose efi_install_configuration_table smbios: Allow compilation on 64bit systems cpu: Add DMTF id and family fields cpu: Add get_vendor callback smbios: Generate type 4 on non-x86 systems smbios: Expose in efi_loader as table efi_loader: Fix efi_install_configuration_table smbios: Provide serial number
arch/x86/Kconfig | 27 ---------- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 18 +++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 13 +++++ arch/x86/include/asm/tables.h | 2 + arch/x86/lib/Makefile | 1 - arch/x86/lib/tables.c | 21 +++----- cmd/bootefi.c | 3 ++ drivers/cpu/cpu-uclass.c | 10 ++++ include/cpu.h | 22 ++++++++ include/efi_api.h | 4 ++ include/efi_loader.h | 4 ++ {arch/x86/include/asm => include}/smbios.h | 8 ++- include/tables_csum.h | 12 +++++ lib/Kconfig | 33 ++++++++++++ lib/Makefile | 2 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 24 +++++---- lib/efi_loader/efi_smbios.c | 32 ++++++++++++ {arch/x86/lib => lib}/smbios.c | 82 +++++++++++++++++++++--------- lib/tables_csum.c | 20 ++++++++ 23 files changed, 265 insertions(+), 77 deletions(-) rename {arch/x86/include/asm => include}/smbios.h (95%) create mode 100644 include/tables_csum.h create mode 100644 lib/efi_loader/efi_smbios.c rename {arch/x86/lib => lib}/smbios.c (78%) create mode 100644 lib/tables_csum.c

We need the checksum function without all the other table functionality soon, so let's split it out into its own C file.
Signed-off-by: Alexander Graf agraf@suse.de
---
v5 -> v6:
- Move to C file --- arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 12 ++++++++++++ lib/Makefile | 1 + lib/tables_csum.c | 20 ++++++++++++++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h create mode 100644 lib/tables_csum.c
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h index ae9f0d0..81f98f2 100644 --- a/arch/x86/include/asm/tables.h +++ b/arch/x86/include/asm/tables.h @@ -7,6 +7,8 @@ #ifndef _X86_TABLES_H_ #define _X86_TABLES_H_
+#include <tables_csum.h> + /* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index f92111e..9ee6b5e 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -38,18 +38,6 @@ static table_write table_write_funcs[] = { #endif };
-u8 table_compute_checksum(void *v, int len) -{ - u8 *bytes = v; - u8 checksum = 0; - int i; - - for (i = 0; i < len; i++) - checksum -= bytes[i]; - - return checksum; -} - void table_fill_string(char *dest, const char *src, size_t n, char pad) { int start, len; diff --git a/include/tables_csum.h b/include/tables_csum.h new file mode 100644 index 0000000..a021efb --- /dev/null +++ b/include/tables_csum.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2015, Bin Meng bmeng.cn@gmail.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +u8 table_compute_checksum(void *v, int len); + +#endif diff --git a/lib/Makefile b/lib/Makefile index f6a8ba1..137e9e5 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -72,6 +72,7 @@ obj-y += linux_string.o obj-y += membuff.o obj-$(CONFIG_REGEX) += slre.o obj-y += string.o +obj-y += tables_csum.o obj-y += time.o obj-$(CONFIG_TRACE) += trace.o obj-$(CONFIG_LIB_UUID) += uuid.o diff --git a/lib/tables_csum.c b/lib/tables_csum.c new file mode 100644 index 0000000..340d7b3 --- /dev/null +++ b/lib/tables_csum.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015, Bin Meng bmeng.cn@gmail.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <linux/ctype.h> + +u8 table_compute_checksum(void *v, int len) +{ + u8 *bytes = v; + u8 checksum = 0; + int i; + + for (i = 0; i < len; i++) + checksum -= bytes[i]; + + return checksum; +}

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
We need the checksum function without all the other table functionality soon, so let's split it out into its own C file.
Signed-off-by: Alexander Graf agraf@suse.de
v5 -> v6:
- Move to C file
arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 12 ++++++++++++ lib/Makefile | 1 + lib/tables_csum.c | 20 ++++++++++++++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h create mode 100644 lib/tables_csum.c
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Aug 19, 2016 at 7:23 AM, Alexander Graf agraf@suse.de wrote:
We need the checksum function without all the other table functionality soon, so let's split it out into its own C file.
Signed-off-by: Alexander Graf agraf@suse.de
v5 -> v6:
- Move to C file
arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 12 ++++++++++++ lib/Makefile | 1 + lib/tables_csum.c | 20 ++++++++++++++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h create mode 100644 lib/tables_csum.c
Reviewed-by: Bin Meng bmeng.cn@gmail.com

We need the checksum function without all the other table functionality soon, so let's split it out into its own C file.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to

We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org --- arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h index ae9f0d0..81f98f2 100644 --- a/arch/x86/include/asm/tables.h +++ b/arch/x86/include/asm/tables.h @@ -7,6 +7,8 @@ #ifndef _X86_TABLES_H_ #define _X86_TABLES_H_
+#include <tables_csum.h> + /* * All x86 tables happen to like the address range from 0xf0000 to 0x100000. * We use 0xf0000 as the starting address to store those tables, including diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index f92111e..9ee6b5e 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -38,18 +38,6 @@ static table_write table_write_funcs[] = { #endif };
-u8 table_compute_checksum(void *v, int len) -{ - u8 *bytes = v; - u8 checksum = 0; - int i; - - for (i = 0; i < len; i++) - checksum -= bytes[i]; - - return checksum; -} - void table_fill_string(char *dest, const char *src, size_t n, char pad) { int start, len; diff --git a/include/tables_csum.h b/include/tables_csum.h new file mode 100644 index 0000000..27d147b --- /dev/null +++ b/include/tables_csum.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2015, Bin Meng bmeng.cn@gmail.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _TABLES_CSUM_H_ +#define _TABLES_CSUM_H_ + +static inline u8 table_compute_checksum(void *v, int len) +{ + u8 *bytes = v; + u8 checksum = 0; + int i; + + for (i = 0; i < len; i++) + checksum -= bytes[i]; + + return checksum; +} + +#endif

On Fri, Aug 19, 2016 at 7:23 AM, Alexander Graf agraf@suse.de wrote:
We need the checksum function without all the other table functionality soon, so let's split it out into its own header file.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
arch/x86/include/asm/tables.h | 2 ++ arch/x86/lib/tables.c | 12 ------------ include/tables_csum.h | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 include/tables_csum.h
I see on patchwork, this patch was assigned to me, so I will pick up this patch via u-boot-x86 tree.
applied to u-boot-x86, thanks!

We will need the SMBIOS generation function on ARM as well going forward, so let's move it into a non arch specific location.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com --- arch/x86/Kconfig | 27 ------------------------ arch/x86/lib/Makefile | 1 - arch/x86/lib/tables.c | 2 +- {arch/x86/include/asm => include}/smbios.h | 0 lib/Kconfig | 33 ++++++++++++++++++++++++++++++ lib/Makefile | 1 + {arch/x86/lib => lib}/smbios.c | 4 ++-- 7 files changed, 37 insertions(+), 31 deletions(-) rename {arch/x86/include/asm => include}/smbios.h (100%) rename {arch/x86/lib => lib}/smbios.c (99%)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 29d1120..682ebb8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -457,33 +457,6 @@ config GENERATE_ACPI_TABLE by the operating system. It defines platform-independent interfaces for configuration and power management monitoring.
-config GENERATE_SMBIOS_TABLE - bool "Generate an SMBIOS (System Management BIOS) table" - default y - help - The System Management BIOS (SMBIOS) specification addresses how - motherboard and system vendors present management information about - their products in a standard format by extending the BIOS interface - on Intel architecture systems. - - Check http://www.dmtf.org/standards/smbios for details. - -config SMBIOS_MANUFACTURER - string "SMBIOS Manufacturer" - depends on GENERATE_SMBIOS_TABLE - default SYS_VENDOR - help - The board manufacturer to store in SMBIOS structures. - Change this to override the default one (CONFIG_SYS_VENDOR). - -config SMBIOS_PRODUCT_NAME - string "SMBIOS Product Name" - depends on GENERATE_SMBIOS_TABLE - default SYS_BOARD - help - The product name to store in SMBIOS structures. - Change this to override the default one (CONFIG_SYS_BOARD). - endmenu
config MAX_PIRQ_LINKS diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index e17f0bb..40ea6bf 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -29,7 +29,6 @@ obj-y += relocate.o obj-y += physmem.o obj-$(CONFIG_X86_RAMTEST) += ramtest.o obj-y += sfi.o -obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-y += string.o ifndef CONFIG_QEMU obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index 9ee6b5e..e62705a 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -5,9 +5,9 @@ */
#include <common.h> +#include <smbios.h> #include <asm/sfi.h> #include <asm/mpspec.h> -#include <asm/smbios.h> #include <asm/tables.h> #include <asm/acpi_table.h> #include <asm/coreboot_tables.h> diff --git a/arch/x86/include/asm/smbios.h b/include/smbios.h similarity index 100% rename from arch/x86/include/asm/smbios.h rename to include/smbios.h diff --git a/lib/Kconfig b/lib/Kconfig index 02ca405..5a14530 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -149,6 +149,39 @@ config SPL_OF_LIBFDT particular compatible nodes. The library operates on a flattened version of the device tree.
+menu "System tables" + depends on !EFI && !SYS_COREBOOT + +config GENERATE_SMBIOS_TABLE + bool "Generate an SMBIOS (System Management BIOS) table" + default y + depends on X86 + help + The System Management BIOS (SMBIOS) specification addresses how + motherboard and system vendors present management information about + their products in a standard format by extending the BIOS interface + on Intel architecture systems. + + Check http://www.dmtf.org/standards/smbios for details. + +config SMBIOS_MANUFACTURER + string "SMBIOS Manufacturer" + depends on GENERATE_SMBIOS_TABLE + default SYS_VENDOR + help + The board manufacturer to store in SMBIOS structures. + Change this to override the default one (CONFIG_SYS_VENDOR). + +config SMBIOS_PRODUCT_NAME + string "SMBIOS Product Name" + depends on GENERATE_SMBIOS_TABLE + default SYS_BOARD + help + The product name to store in SMBIOS structures. + Change this to override the default one (CONFIG_SYS_BOARD). + +endmenu + source lib/efi/Kconfig source lib/efi_loader/Kconfig
diff --git a/lib/Makefile b/lib/Makefile index 137e9e5..f0b0b3f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o obj-$(CONFIG_GZIP) += gunzip.o obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o +obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o obj-y += initcall.o obj-$(CONFIG_LMB) += lmb.o obj-y += ldiv.o diff --git a/arch/x86/lib/smbios.c b/lib/smbios.c similarity index 99% rename from arch/x86/lib/smbios.c rename to lib/smbios.c index 9f30550..9808ee7 100644 --- a/arch/x86/lib/smbios.c +++ b/lib/smbios.c @@ -7,10 +7,10 @@ */
#include <common.h> +#include <smbios.h> +#include <tables_csum.h> #include <version.h> #include <asm/cpu.h> -#include <asm/smbios.h> -#include <asm/tables.h>
DECLARE_GLOBAL_DATA_PTR;

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
We will need the SMBIOS generation function on ARM as well going forward, so let's move it into a non arch specific location.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com
arch/x86/Kconfig | 27 ------------------------ arch/x86/lib/Makefile | 1 - arch/x86/lib/tables.c | 2 +- {arch/x86/include/asm => include}/smbios.h | 0 lib/Kconfig | 33 ++++++++++++++++++++++++++++++ lib/Makefile | 1 + {arch/x86/lib => lib}/smbios.c | 4 ++-- 7 files changed, 37 insertions(+), 31 deletions(-) rename {arch/x86/include/asm => include}/smbios.h (100%) rename {arch/x86/lib => lib}/smbios.c (99%)
Reviewed-by: Simon Glass sjg@chromium.org

We will need the SMBIOS generation function on ARM as well going forward, so let's move it into a non arch specific location.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to

We want to be able to add configuration table entries from our own code as well as from EFI payload code. Export the boot service function internally too, so that we can reuse it.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org
---
v5 -> v6:
- Mark guid as const --- include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/include/efi_loader.h b/include/efi_loader.h index 91d6a84..6522b09 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -130,6 +130,8 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, bool overlap_only_ram); /* Called by board init to initialize the EFI memory map */ int efi_memory_init(void); +/* Adds new or overrides configuration table entry to the system table */ +efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table);
#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER extern void *efi_bounce_buffer; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index be6f5e8..8da0063 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -37,7 +37,7 @@ static bool efi_is_direct_boot = true; * In most cases we want to pass an FDT to the payload, so reserve one slot of * config table space for it. The pointer gets populated by do_bootefi_exec(). */ -static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[1]; +static struct efi_configuration_table EFI_RUNTIME_DATA efi_conf_table[2];
/* * The "gd" pointer lives in a register on ARM and AArch64 that we declare @@ -375,31 +375,35 @@ static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, return EFI_EXIT(EFI_NOT_FOUND); }
-static efi_status_t EFIAPI efi_install_configuration_table(efi_guid_t *guid, - void *table) +efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table) { int i;
- EFI_ENTRY("%p, %p", guid, table); - /* Check for guid override */ for (i = 0; i < systab.nr_tables; i++) { if (!guidcmp(guid, &efi_conf_table[i].guid)) { efi_conf_table[i].table = table; - return EFI_EXIT(EFI_SUCCESS); + return EFI_SUCCESS; } }
/* No override, check for overflow */ if (i >= ARRAY_SIZE(efi_conf_table)) - return EFI_EXIT(EFI_OUT_OF_RESOURCES); + return EFI_OUT_OF_RESOURCES;
/* Add a new entry */ memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); efi_conf_table[i].table = table; systab.nr_tables = i;
- return EFI_EXIT(EFI_SUCCESS); + return EFI_SUCCESS; +} + +static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, + void *table) +{ + EFI_ENTRY("%p, %p", guid, table); + return EFI_EXIT(efi_install_configuration_table(guid, table)); }
static efi_status_t EFIAPI efi_load_image(bool boot_policy, @@ -750,7 +754,7 @@ static const struct efi_boot_services efi_boot_services = { .register_protocol_notify = efi_register_protocol_notify, .locate_handle = efi_locate_handle, .locate_device_path = efi_locate_device_path, - .install_configuration_table = efi_install_configuration_table, + .install_configuration_table = efi_install_configuration_table_ext, .load_image = efi_load_image, .start_image = efi_start_image, .exit = efi_exit,

We want to be able to add configuration table entries from our own code as well as from EFI payload code. Export the boot service function internally too, so that we can reuse it.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to

The SMBIOS generation code passes pointers as u32. That causes the compiler to warn on casts to pointers. This patch moves all address pointers to uintptr_t instead.
Technically u32 would be enough for the current SMBIOS2 style tables, but we may want to extend the code to SMBIOS3 in the future which is 64bit address capable.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org --- arch/x86/lib/tables.c | 7 ++++++- include/smbios.h | 4 ++-- lib/smbios.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c index e62705a..025b183 100644 --- a/arch/x86/lib/tables.c +++ b/arch/x86/lib/tables.c @@ -12,6 +12,11 @@ #include <asm/acpi_table.h> #include <asm/coreboot_tables.h>
+static u32 write_smbios_table_wrapper(u32 addr) +{ + return write_smbios_table(addr); +} + /** * Function prototype to write a specific configuration table * @@ -34,7 +39,7 @@ static table_write table_write_funcs[] = { write_acpi_tables, #endif #ifdef CONFIG_GENERATE_SMBIOS_TABLE - write_smbios_table, + write_smbios_table_wrapper, #endif };
diff --git a/include/smbios.h b/include/smbios.h index 623a703..5962d4c 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -221,7 +221,7 @@ static inline void fill_smbios_header(void *table, int type, * @handle: the structure's handle, a unique 16-bit number * @return: size of the structure */ -typedef int (*smbios_write_type)(u32 *addr, int handle); +typedef int (*smbios_write_type)(uintptr_t *addr, int handle);
/** * write_smbios_table() - Write SMBIOS table @@ -231,6 +231,6 @@ typedef int (*smbios_write_type)(u32 *addr, int handle); * @addr: start address to write SMBIOS table * @return: end address of SMBIOS table */ -u32 write_smbios_table(u32 addr); +uintptr_t write_smbios_table(uintptr_t addr);
#endif /* _SMBIOS_H_ */ diff --git a/lib/smbios.c b/lib/smbios.c index 9808ee7..8dfd486 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -69,7 +69,7 @@ static int smbios_string_table_len(char *start) return len + 1; }
-static int smbios_write_type0(u32 *current, int handle) +static int smbios_write_type0(uintptr_t *current, int handle) { struct smbios_type0 *t = (struct smbios_type0 *)*current; int len = sizeof(struct smbios_type0); @@ -98,7 +98,7 @@ static int smbios_write_type0(u32 *current, int handle) return len; }
-static int smbios_write_type1(u32 *current, int handle) +static int smbios_write_type1(uintptr_t *current, int handle) { struct smbios_type1 *t = (struct smbios_type1 *)*current; int len = sizeof(struct smbios_type1); @@ -114,7 +114,7 @@ static int smbios_write_type1(u32 *current, int handle) return len; }
-static int smbios_write_type2(u32 *current, int handle) +static int smbios_write_type2(uintptr_t *current, int handle) { struct smbios_type2 *t = (struct smbios_type2 *)*current; int len = sizeof(struct smbios_type2); @@ -132,7 +132,7 @@ static int smbios_write_type2(u32 *current, int handle) return len; }
-static int smbios_write_type3(u32 *current, int handle) +static int smbios_write_type3(uintptr_t *current, int handle) { struct smbios_type3 *t = (struct smbios_type3 *)*current; int len = sizeof(struct smbios_type3); @@ -152,7 +152,7 @@ static int smbios_write_type3(u32 *current, int handle) return len; }
-static int smbios_write_type4(u32 *current, int handle) +static int smbios_write_type4(uintptr_t *current, int handle) { struct smbios_type4 *t = (struct smbios_type4 *)*current; int len = sizeof(struct smbios_type4); @@ -185,7 +185,7 @@ static int smbios_write_type4(u32 *current, int handle) return len; }
-static int smbios_write_type32(u32 *current, int handle) +static int smbios_write_type32(uintptr_t *current, int handle) { struct smbios_type32 *t = (struct smbios_type32 *)*current; int len = sizeof(struct smbios_type32); @@ -198,7 +198,7 @@ static int smbios_write_type32(u32 *current, int handle) return len; }
-static int smbios_write_type127(u32 *current, int handle) +static int smbios_write_type127(uintptr_t *current, int handle) { struct smbios_type127 *t = (struct smbios_type127 *)*current; int len = sizeof(struct smbios_type127); @@ -221,7 +221,7 @@ static smbios_write_type smbios_write_funcs[] = { smbios_write_type127 };
-u32 write_smbios_table(u32 addr) +uintptr_t write_smbios_table(uintptr_t addr) { struct smbios_entry *se; u32 tables;

The SMBIOS generation code passes pointers as u32. That causes the compiler to warn on casts to pointers. This patch moves all address pointers to uintptr_t instead.
Technically u32 would be enough for the current SMBIOS2 style tables, but we may want to extend the code to SMBIOS3 in the future which is 64bit address capable.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to

For SMBIOS tables we need to know the CPU family as well as CPU IDs. This patches allocates some space for them in the cpu device and populates it on x86.
Signed-off-by: Alexander Graf agraf@suse.de --- arch/x86/cpu/cpu_x86.c | 5 +++++ include/cpu.h | 2 ++ 2 files changed, 7 insertions(+)
diff --git a/arch/x86/cpu/cpu_x86.c b/arch/x86/cpu/cpu_x86.c index 0941041..39004ee 100644 --- a/arch/x86/cpu/cpu_x86.c +++ b/arch/x86/cpu/cpu_x86.c @@ -15,9 +15,14 @@ DECLARE_GLOBAL_DATA_PTR; int cpu_x86_bind(struct udevice *dev) { struct cpu_platdata *plat = dev_get_parent_platdata(dev); + struct cpuid_result res;
plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "intel,apic-id", -1); + plat->family = gd->arch.x86; + res = cpuid(1); + plat->id[0] = res.eax; + plat->id[1] = res.edx;
return 0; } diff --git a/include/cpu.h b/include/cpu.h index bda5315..7d4486b 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -21,6 +21,8 @@ struct cpu_platdata { int cpu_id; int ucode_version; ulong device_id; + u16 family; /* DMTF CPU Family */ + u32 id[2]; /* DMTF CPU Processor IDs */ };
/* CPU features - mostly just a placeholder for now */

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
For SMBIOS tables we need to know the CPU family as well as CPU IDs. This patches allocates some space for them in the cpu device and populates it on x86.
Signed-off-by: Alexander Graf agraf@suse.de
arch/x86/cpu/cpu_x86.c | 5 +++++ include/cpu.h | 2 ++ 2 files changed, 7 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Aug 19, 2016 at 7:23 AM, Alexander Graf agraf@suse.de wrote:
For SMBIOS tables we need to know the CPU family as well as CPU IDs. This patches allocates some space for them in the cpu device and populates it on x86.
Signed-off-by: Alexander Graf agraf@suse.de
arch/x86/cpu/cpu_x86.c | 5 +++++ include/cpu.h | 2 ++ 2 files changed, 7 insertions(+)
Reviewed-by: Bin Meng bmeng.cn@gmail.com

For SMBIOS tables we need to know the CPU family as well as CPU IDs. This patches allocates some space for them in the cpu device and populates it on x86.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to

The CPU udevice already has a few callbacks to retreive information about the currently running CPUs. This patch adds a new get_vendor() call that returns the vendor of the main CPUs.
Signed-off-by: Alexander Graf agraf@suse.de --- arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 +++++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 13 +++++++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++++ include/cpu.h | 20 ++++++++++++++++++++ 7 files changed, 59 insertions(+)
diff --git a/arch/x86/cpu/baytrail/cpu.c b/arch/x86/cpu/baytrail/cpu.c index b1faf8c..c454db0 100644 --- a/arch/x86/cpu/baytrail/cpu.c +++ b/arch/x86/cpu/baytrail/cpu.c @@ -141,6 +141,7 @@ static const struct cpu_ops cpu_x86_baytrail_ops = { .get_desc = cpu_x86_get_desc, .get_info = baytrail_get_info, .get_count = baytrail_get_count, + .get_vendor = cpu_x86_get_vendor, };
static const struct udevice_id cpu_x86_baytrail_ids[] = { diff --git a/arch/x86/cpu/broadwell/cpu.c b/arch/x86/cpu/broadwell/cpu.c index 3ba21aa..6977e86 100644 --- a/arch/x86/cpu/broadwell/cpu.c +++ b/arch/x86/cpu/broadwell/cpu.c @@ -743,6 +743,7 @@ static const struct cpu_ops cpu_x86_broadwell_ops = { .get_desc = cpu_x86_get_desc, .get_info = broadwell_get_info, .get_count = broadwell_get_count, + .get_vendor = cpu_x86_get_vendor, };
static const struct udevice_id cpu_x86_broadwell_ids[] = { diff --git a/arch/x86/cpu/cpu_x86.c b/arch/x86/cpu/cpu_x86.c index 39004ee..157f3de 100644 --- a/arch/x86/cpu/cpu_x86.c +++ b/arch/x86/cpu/cpu_x86.c @@ -27,6 +27,18 @@ int cpu_x86_bind(struct udevice *dev) return 0; }
+int cpu_x86_get_vendor(struct udevice *dev, char *buf, int size) +{ + const char *vendor = cpu_vendor_name(gd->arch.x86_vendor); + + if (size < (strlen(vendor) + 1)) + return -ENOSPC; + + strcpy(buf, vendor); + + return 0; +} + int cpu_x86_get_desc(struct udevice *dev, char *buf, int size) { if (size < CPU_MAX_NAME_LEN) @@ -65,6 +77,7 @@ static int cpu_x86_get_count(struct udevice *dev) static const struct cpu_ops cpu_x86_ops = { .get_desc = cpu_x86_get_desc, .get_count = cpu_x86_get_count, + .get_vendor = cpu_x86_get_vendor, };
static const struct udevice_id cpu_x86_ids[] = { diff --git a/arch/x86/cpu/ivybridge/model_206ax.c b/arch/x86/cpu/ivybridge/model_206ax.c index 38e244b..d8eb2e7 100644 --- a/arch/x86/cpu/ivybridge/model_206ax.c +++ b/arch/x86/cpu/ivybridge/model_206ax.c @@ -478,6 +478,7 @@ static const struct cpu_ops cpu_x86_model_206ax_ops = { .get_desc = cpu_x86_get_desc, .get_info = model_206ax_get_info, .get_count = model_206ax_get_count, + .get_vendor = cpu_x86_get_vendor, };
static const struct udevice_id cpu_x86_model_206ax_ids[] = { diff --git a/arch/x86/include/asm/cpu_x86.h b/arch/x86/include/asm/cpu_x86.h index 1940480..74b82ed 100644 --- a/arch/x86/include/asm/cpu_x86.h +++ b/arch/x86/include/asm/cpu_x86.h @@ -31,4 +31,17 @@ int cpu_x86_bind(struct udevice *dev); */ int cpu_x86_get_desc(struct udevice *dev, char *buf, int size);
+/** + * cpu_x86_get_vendor() - Get a vendor string for an x86 CPU + * + * This uses cpu_vendor_name() and is suitable to use as the get_vendor() + * method for the CPU uclass. + * + * @dev: Device to check (UCLASS_CPU) + * @buf: Buffer to place string + * @size: Size of string space + * @return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error + */ +int cpu_x86_get_vendor(struct udevice *dev, char *buf, int size); + #endif /* _ASM_CPU_X86_H */ diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c index 7660f99..c57ac16 100644 --- a/drivers/cpu/cpu-uclass.c +++ b/drivers/cpu/cpu-uclass.c @@ -44,6 +44,16 @@ int cpu_get_count(struct udevice *dev) return ops->get_count(dev); }
+int cpu_get_vendor(struct udevice *dev, char *buf, int size) +{ + struct cpu_ops *ops = cpu_get_ops(dev); + + if (!ops->get_vendor) + return -ENOSYS; + + return ops->get_vendor(dev, buf, size); +} + U_BOOT_DRIVER(cpu_bus) = { .name = "cpu_bus", .id = UCLASS_SIMPLE_BUS, diff --git a/include/cpu.h b/include/cpu.h index 7d4486b..9542577 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -73,6 +73,16 @@ struct cpu_ops { * @return CPU count if OK, -ve on error */ int (*get_count)(struct udevice *dev); + + /** + * get_vendor() - Get vendor name of a CPU + * + * @dev: Device to check (UCLASS_CPU) + * @buf: Buffer to place string + * @size: Size of string space + * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error + */ + int (*get_vendor)(struct udevice *dev, char *buf, int size); };
#define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) @@ -104,4 +114,14 @@ int cpu_get_info(struct udevice *dev, struct cpu_info *info); */ int cpu_get_count(struct udevice *dev);
+/** + * cpu_get_vendor() - Get vendor name of a CPU + * + * @dev: Device to check (UCLASS_CPU) + * @buf: Buffer to place string + * @size: Size of string space + * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error + */ +int cpu_get_vendor(struct udevice *dev, char *buf, int size); + #endif

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
The CPU udevice already has a few callbacks to retreive information about the currently running CPUs. This patch adds a new get_vendor() call that returns the vendor of the main CPUs.
Signed-off-by: Alexander Graf agraf@suse.de
arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 +++++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 13 +++++++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++++ include/cpu.h | 20 ++++++++++++++++++++ 7 files changed, 59 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Aug 19, 2016 at 7:23 AM, Alexander Graf agraf@suse.de wrote:
The CPU udevice already has a few callbacks to retreive information about the currently running CPUs. This patch adds a new get_vendor() call that returns the vendor of the main CPUs.
Signed-off-by: Alexander Graf agraf@suse.de
arch/x86/cpu/baytrail/cpu.c | 1 + arch/x86/cpu/broadwell/cpu.c | 1 + arch/x86/cpu/cpu_x86.c | 13 +++++++++++++ arch/x86/cpu/ivybridge/model_206ax.c | 1 + arch/x86/include/asm/cpu_x86.h | 13 +++++++++++++ drivers/cpu/cpu-uclass.c | 10 ++++++++++ include/cpu.h | 20 ++++++++++++++++++++ 7 files changed, 59 insertions(+)
Reviewed-by: Bin Meng bmeng.cn@gmail.com

The CPU udevice already has a few callbacks to retreive information about the currently running CPUs. This patch adds a new get_vendor() call that returns the vendor of the main CPUs.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to

The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de
---
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo - s/smbios_write_type4_arch/smbios_write_type4_dm/
v5 -> v6:
- Split cpu hunks into separate patches --- include/smbios.h | 3 +++ lib/smbios.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/include/smbios.h b/include/smbios.h index 5962d4c..3cbc687 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -139,6 +139,9 @@ struct __packed smbios_type3 { #define SMBIOS_PROCESSOR_STATUS_ENABLED 1 #define SMBIOS_PROCESSOR_UPGRADE_NONE 6
+#define SMBIOS_PROCESSOR_FAMILY_OTHER 1 +#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN 2 + struct __packed smbios_type4 { u8 type; u8 length; diff --git a/lib/smbios.c b/lib/smbios.c index 8dfd486..09a90ca 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -10,7 +10,11 @@ #include <smbios.h> #include <tables_csum.h> #include <version.h> -#include <asm/cpu.h> +#ifdef CONFIG_CPU +#include <cpu.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -152,26 +156,47 @@ static int smbios_write_type3(uintptr_t *current, int handle) return len; }
+static void smbios_write_type4_dm(struct smbios_type4 *t) +{ + u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN; + const char *vendor = "Unknown"; + const char *name = "Unknown"; + +#ifdef CONFIG_CPU + char processor_name[49]; + char vendor_name[49]; + struct udevice *dev = NULL; + + uclass_find_first_device(UCLASS_CPU, &dev); + if (dev) { + struct cpu_platdata *plat = dev_get_parent_platdata(dev); + + if (plat->family) + processor_family = plat->family; + t->processor_id[0] = plat->id[0]; + t->processor_id[1] = plat->id[1]; + + if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name))) + vendor = vendor_name; + if (!cpu_get_desc(dev, processor_name, sizeof(processor_name))) + name = processor_name; + } +#endif + + t->processor_family = processor_family; + t->processor_manufacturer = smbios_add_string(t->eos, vendor); + t->processor_version = smbios_add_string(t->eos, name); +} + static int smbios_write_type4(uintptr_t *current, int handle) { struct smbios_type4 *t = (struct smbios_type4 *)*current; int len = sizeof(struct smbios_type4); - const char *vendor; - char *name; - char processor_name[CPU_MAX_NAME_LEN]; - struct cpuid_result res;
memset(t, 0, sizeof(struct smbios_type4)); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; - t->processor_family = gd->arch.x86; - vendor = cpu_vendor_name(gd->arch.x86_vendor); - t->processor_manufacturer = smbios_add_string(t->eos, vendor); - res = cpuid(1); - t->processor_id[0] = res.eax; - t->processor_id[1] = res.edx; - name = cpu_get_name(processor_name); - t->processor_version = smbios_add_string(t->eos, name); + smbios_write_type4_dm(t); t->status = SMBIOS_PROCESSOR_STATUS_ENABLED; t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE; t->l1_cache_handle = 0xffff;

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo
- s/smbios_write_type4_arch/smbios_write_type4_dm/
v5 -> v6:
- Split cpu hunks into separate patches
include/smbios.h | 3 +++ lib/smbios.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
You probably don't need the _dm suffix, but it doesn't matter.

On Fri, Aug 19, 2016 at 7:23 AM, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de
v3 -> v4:
- Use device model
v4 -> v5:
- s/get_info/get_vendor/ typo
- s/smbios_write_type4_arch/smbios_write_type4_dm/
v5 -> v6:
- Split cpu hunks into separate patches
include/smbios.h | 3 +++ lib/smbios.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 13 deletions(-)
Reviewed-by: Bin Meng bmeng.cn@gmail.com

The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to

On Thu, Oct 13, 2016 at 10:35 PM, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to
Applied to where?
Regards, Bin

Am 14.10.2016 um 03:50 schrieb Bin Meng bmeng.cn@gmail.com:
On Thu, Oct 13, 2016 at 10:35 PM, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to
Applied to where?
Sorry, my efi-next tree.
Alex

On Fri, Oct 14, 2016 at 1:13 PM, Alexander Graf agraf@suse.de wrote:
Am 14.10.2016 um 03:50 schrieb Bin Meng bmeng.cn@gmail.com:
On Thu, Oct 13, 2016 at 10:35 PM, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to
Applied to where?
Sorry, my efi-next tree.
At which repo? I don't see it at git.denx.de. I thought it was going to be applied by Tom directly.
Regards, Bin

On 10/14/2016 07:21 AM, Bin Meng wrote:
On Fri, Oct 14, 2016 at 1:13 PM, Alexander Graf agraf@suse.de wrote:
Am 14.10.2016 um 03:50 schrieb Bin Meng bmeng.cn@gmail.com:
On Thu, Oct 13, 2016 at 10:35 PM, Alexander Graf agraf@suse.de wrote:
The type 4 table generation code is very x86 centric today. Refactor things out into the device model cpu class to allow the tables to get generated for other architectures as well.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org Reviewed-by: Bin Meng bmeng.cn@gmail.com
Thanks, applied to
Applied to where?
Sorry, my efi-next tree.
At which repo? I don't see it at git.denx.de. I thought it was going to be applied by Tom directly.
We're moving to a model where I apply efi patches, the custodian tree just isn't set up yet, so I pushed it to:
https://github.com/agraf/u-boot/tree/efi-next
instead, but wanted to notify people that there is indeed progress on their patches.
Alex

We can pass SMBIOS easily as EFI configuration table to an EFI payload. This patch adds enablement for that case.
While at it, we also enable SMBIOS generation for ARM systems, since they support EFI_LOADER.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com
---
v1 -> v2:
- Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file --- cmd/bootefi.c | 3 +++ include/efi_api.h | 4 ++++ include/efi_loader.h | 2 ++ include/smbios.h | 1 + lib/Kconfig | 4 ++-- lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_smbios.c | 32 ++++++++++++++++++++++++++++++++ lib/smbios.c | 6 ++++++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_smbios.c
diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 53a6ee3..e241b7d 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -205,6 +205,9 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6)) loaded_image_info.device_handle = nethandle; #endif +#ifdef CONFIG_GENERATE_SMBIOS_TABLE + efi_smbios_register(); +#endif
/* Initialize EFI runtime services */ efi_reset_system_init(); diff --git a/include/efi_api.h b/include/efi_api.h index f572b88..bdb600e 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -201,6 +201,10 @@ struct efi_runtime_services { EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \ 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
+#define SMBIOS_TABLE_GUID \ + EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \ + 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) + struct efi_configuration_table { efi_guid_t guid; diff --git a/include/efi_loader.h b/include/efi_loader.h index 6522b09..6b0e9a0 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -85,6 +85,8 @@ int efi_disk_register(void); int efi_gop_register(void); /* Called by bootefi to make the network interface available */ int efi_net_register(void **handle); +/* Called by bootefi to make SMBIOS tables available */ +void efi_smbios_register(void);
/* Called by networking code to memorize the dhcp ack package */ void efi_net_set_dhcp_ack(void *pkt, int len); diff --git a/include/smbios.h b/include/smbios.h index 3cbc687..d582d4f 100644 --- a/include/smbios.h +++ b/include/smbios.h @@ -55,6 +55,7 @@ struct __packed smbios_entry { #define BIOS_CHARACTERISTICS_SELECTABLE_BOOT (1 << 16)
#define BIOS_CHARACTERISTICS_EXT1_ACPI (1 << 0) +#define BIOS_CHARACTERISTICS_EXT1_UEFI (1 << 3) #define BIOS_CHARACTERISTICS_EXT2_TARGET (1 << 2)
struct __packed smbios_type0 { diff --git a/lib/Kconfig b/lib/Kconfig index 5a14530..d7f75fe 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -150,12 +150,12 @@ config SPL_OF_LIBFDT version of the device tree.
menu "System tables" - depends on !EFI && !SYS_COREBOOT + depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER)
config GENERATE_SMBIOS_TABLE bool "Generate an SMBIOS (System Management BIOS) table" default y - depends on X86 + depends on X86 || EFI_LOADER help The System Management BIOS (SMBIOS) specification addresses how motherboard and system vendors present management information about diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 2a3849e..12159dd 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -12,3 +12,4 @@ obj-y += efi_memory.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o obj-$(CONFIG_NET) += efi_net.o +obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c new file mode 100644 index 0000000..5bc24f7 --- /dev/null +++ b/lib/efi_loader/efi_smbios.c @@ -0,0 +1,32 @@ +/* + * EFI application tables support + * + * Copyright (c) 2016 Alexander Graf + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <efi_loader.h> +#include <inttypes.h> +#include <smbios.h> + +static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; + +void efi_smbios_register(void) +{ + /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ + uint64_t dmi = 0xffffffff; + /* Reserve 4kb for SMBIOS */ + uint64_t pages = 1; + int memtype = EFI_RUNTIME_SERVICES_DATA; + + if (efi_allocate_pages(1, memtype, pages, &dmi) != EFI_SUCCESS) + return; + + /* Generate SMBIOS tables */ + write_smbios_table(dmi); + + /* And expose them to our EFI payload */ + efi_install_configuration_table(&smbios_guid, (void*)dmi); +} diff --git a/lib/smbios.c b/lib/smbios.c index 09a90ca..237f5f0 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -83,14 +83,20 @@ static int smbios_write_type0(uintptr_t *current, int handle) t->vendor = smbios_add_string(t->eos, "U-Boot"); t->bios_ver = smbios_add_string(t->eos, PLAIN_VERSION); t->bios_release_date = smbios_add_string(t->eos, U_BOOT_DMI_DATE); +#ifdef CONFIG_ROM_SIZE t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1; +#endif t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED | BIOS_CHARACTERISTICS_SELECTABLE_BOOT | BIOS_CHARACTERISTICS_UPGRADEABLE; #ifdef CONFIG_GENERATE_ACPI_TABLE t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI; #endif +#ifdef CONFIG_EFI_LOADER + t->bios_characteristics_ext1 |= BIOS_CHARACTERISTICS_EXT1_UEFI; +#endif t->bios_characteristics_ext2 = BIOS_CHARACTERISTICS_EXT2_TARGET; + t->bios_major_release = 0xff; t->bios_minor_release = 0xff; t->ec_major_release = 0xff;

On 18 August 2016 at 17:23, Alexander Graf agraf@suse.de wrote:
We can pass SMBIOS easily as EFI configuration table to an EFI payload. This patch adds enablement for that case.
While at it, we also enable SMBIOS generation for ARM systems, since they support EFI_LOADER.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com
v1 -> v2:
- Fix whitespace
v2 -> v3:
- Move efi smbios generation to own file
cmd/bootefi.c | 3 +++ include/efi_api.h | 4 ++++ include/efi_loader.h | 2 ++ include/smbios.h | 1 + lib/Kconfig | 4 ++-- lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_smbios.c | 32 ++++++++++++++++++++++++++++++++ lib/smbios.c | 6 ++++++ 8 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_smbios.c
Reviewed-by: Simon Glass sjg@chromium.org

We can pass SMBIOS easily as EFI configuration table to an EFI payload. This patch adds enablement for that case.
While at it, we also enable SMBIOS generation for ARM systems, since they support EFI_LOADER.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to

So far we were only installing the FDT table and didn't have space to store any other. Hence nobody realized that our efi table allocation was broken in that it didn't set the indicator for the number of tables plus one.
This patch fixes it, allowing code to allocate new efi tables.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org --- lib/efi_loader/efi_boottime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 8da0063..da40ddb 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -394,7 +394,7 @@ efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table /* Add a new entry */ memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); efi_conf_table[i].table = table; - systab.nr_tables = i; + systab.nr_tables = i + 1;
return EFI_SUCCESS; }

So far we were only installing the FDT table and didn't have space to store any other. Hence nobody realized that our efi table allocation was broken in that it didn't set the indicator for the number of tables plus one.
This patch fixes it, allowing code to allocate new efi tables.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to

If the system has a valid "serial#" environment variable set (which boards that can find it out programatically set automatically), use that as input for the serial number and UUID fields in the SMBIOS tables.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
---
v1 -> v2:
- Also populate UUID --- lib/smbios.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/lib/smbios.c b/lib/smbios.c index 237f5f0..ce1974d 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -112,11 +112,16 @@ static int smbios_write_type1(uintptr_t *current, int handle) { struct smbios_type1 *t = (struct smbios_type1 *)*current; int len = sizeof(struct smbios_type1); + char *serial_str = getenv("serial#");
memset(t, 0, sizeof(struct smbios_type1)); fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME); + if (serial_str) { + strncpy((char*)t->uuid, serial_str, sizeof(t->uuid)); + t->serial_number = smbios_add_string(t->eos, serial_str); + }
len = t->length + smbios_string_table_len(t->eos); *current += len;

If the system has a valid "serial#" environment variable set (which boards that can find it out programatically set automatically), use that as input for the serial number and UUID fields in the SMBIOS tables.
Signed-off-by: Alexander Graf agraf@suse.de Reviewed-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
Thanks, applied to
participants (3)
-
Alexander Graf
-
Bin Meng
-
Simon Glass