aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig36
-rw-r--r--lib/Makefile2
-rw-r--r--lib/acpi/acpi_device.c2
-rw-r--r--lib/acpi/acpi_table.c4
-rw-r--r--lib/binman.c14
-rw-r--r--lib/efi_loader/Kconfig4
-rw-r--r--lib/efi_loader/Makefile1
-rw-r--r--lib/efi_loader/efi_boottime.c19
-rw-r--r--lib/efi_loader/efi_string.c36
-rw-r--r--lib/getopt.c125
-rw-r--r--lib/rsa/rsa-mod-exp.c2
-rw-r--r--lib/smbios-parser.c96
-rw-r--r--lib/smbios.c120
13 files changed, 401 insertions, 60 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 37aae73a26..7673d2e4e0 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -550,6 +550,11 @@ config SPL_HEXDUMP
This enables functions for printing dumps of binary data in
SPL.
+config GETOPT
+ bool "Enable getopt"
+ help
+ This enables functions for parsing command-line options.
+
config OF_LIBFDT
bool "Enable the FDT library"
default y if OF_CONTROL
@@ -632,6 +637,15 @@ config FDT_FIXUP_PARTITIONS
menu "System tables"
depends on (!EFI && !SYS_COREBOOT) || (ARM && EFI_LOADER)
+config BLOBLIST_TABLES
+ bool "Put tables in a bloblist"
+ depends on X86
+ help
+ Normally tables are placed at address 0xf0000 and can be up to 64KB
+ long. With this option, tables are instead placed in the bloblist
+ with a pointer from 0xf0000. The size can then be larger and the
+ tables can be placed high in memory.
+
config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
default y
@@ -644,21 +658,8 @@ config GENERATE_SMBIOS_TABLE
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).
+ See also SMBIOS_SYSINFO which allows SMBIOS values to be provided in
+ the devicetree.
endmenu
@@ -675,6 +676,11 @@ config OID_REGISTRY
help
Enable fast lookup object identifier registry.
+config SMBIOS_PARSER
+ bool "SMBIOS parser"
+ help
+ A simple parser for SMBIOS data.
+
source lib/efi/Kconfig
source lib/efi_loader/Kconfig
source lib/optee/Kconfig
diff --git a/lib/Makefile b/lib/Makefile
index 0cd7bea282..851a80ef3b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o
obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
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 += ldiv.o
obj-$(CONFIG_XXHASH) += xxhash.o
@@ -106,6 +107,7 @@ obj-y += string.o
obj-y += tables_csum.o
obj-y += time.o
obj-y += hexdump.o
+obj-$(CONFIG_GETOPT) += getopt.o
obj-$(CONFIG_TRACE) += trace.o
obj-$(CONFIG_LIB_UUID) += uuid.o
obj-$(CONFIG_LIB_RAND) += rand.o
diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
index 95dfac583f..c3439a5988 100644
--- a/lib/acpi/acpi_device.c
+++ b/lib/acpi/acpi_device.c
@@ -422,7 +422,7 @@ int acpi_device_add_power_res(struct acpi_ctx *ctx, u32 tx_state_val,
/* Method (_ON, 0, Serialized) */
acpigen_write_method_serialized(ctx, "_ON", 0);
- if (reset_gpio) {
+ if (has_reset) {
ret = acpigen_set_enable_tx_gpio(ctx, tx_state_val, dw0_read,
dw0_write, &reset, true);
if (ret)
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 908d890389..a0f0961be5 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -183,8 +183,8 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
return 0;
}
-static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
- struct acpi_xsdt *xsdt)
+void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
+ struct acpi_xsdt *xsdt)
{
memset(rsdp, 0, sizeof(struct acpi_rsdp));
diff --git a/lib/binman.c b/lib/binman.c
index 7a8ad62c4a..e71c1b9e99 100644
--- a/lib/binman.c
+++ b/lib/binman.c
@@ -43,7 +43,7 @@ static int binman_entry_find_internal(ofnode node, const char *name,
ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
if (ret)
- return log_msg_ret("import-pos", ret);
+ return log_msg_ret("image-pos", ret);
ret = ofnode_read_u32(node, "size", &entry->size);
if (ret)
return log_msg_ret("size", ret);
@@ -83,6 +83,11 @@ void binman_set_rom_offset(int rom_offset)
binman->rom_offset = rom_offset;
}
+int binman_get_rom_offset(void)
+{
+ return binman->rom_offset;
+}
+
int binman_init(void)
{
binman = malloc(sizeof(struct binman_info));
@@ -91,6 +96,13 @@ int binman_init(void)
binman->image = ofnode_path("/binman");
if (!ofnode_valid(binman->image))
return log_msg_ret("binman node", -EINVAL);
+ if (ofnode_read_bool(binman->image, "multiple-images")) {
+ ofnode node = ofnode_first_subnode(binman->image);
+
+ if (!ofnode_valid(node))
+ return log_msg_ret("first image", -ENOENT);
+ binman->image = node;
+ }
binman->rom_offset = ROM_OFFSET_NONE;
return 0;
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index ab42f3ba75..075481428c 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -27,6 +27,10 @@ config EFI_LOADER
if EFI_LOADER
+config EFI_SETUP_EARLY
+ bool
+ default n
+
choice
prompt "Store for non-volatile UEFI variables"
default EFI_VARIABLE_FILE_STORE
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 9bad1d159b..8892fb01e1 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -34,6 +34,7 @@ obj-y += efi_memory.o
obj-y += efi_root_node.o
obj-y += efi_runtime.o
obj-y += efi_setup.o
+obj-y += efi_string.o
obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o
obj-y += efi_var_common.o
obj-y += efi_var_mem.o
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index b26ac9fbfc..dfa71b1774 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -3523,6 +3523,7 @@ static efi_status_t EFIAPI efi_disconnect_controller(
size_t number_of_children = 0;
efi_status_t r;
struct efi_object *efiobj;
+ bool sole_child;
EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle,
child_handle);
@@ -3545,16 +3546,18 @@ static efi_status_t EFIAPI efi_disconnect_controller(
}
/* Create list of child handles */
+ r = efi_get_child_controllers(efiobj,
+ driver_image_handle,
+ &number_of_children,
+ &child_handle_buffer);
+ if (r != EFI_SUCCESS)
+ return r;
+ sole_child = (number_of_children == 1);
+
if (child_handle) {
number_of_children = 1;
+ free(child_handle_buffer);
child_handle_buffer = &child_handle;
- } else {
- r = efi_get_child_controllers(efiobj,
- driver_image_handle,
- &number_of_children,
- &child_handle_buffer);
- if (r != EFI_SUCCESS)
- return r;
}
/* Get the driver binding protocol */
@@ -3579,7 +3582,7 @@ static efi_status_t EFIAPI efi_disconnect_controller(
}
}
/* Remove the driver */
- if (!child_handle) {
+ if (!child_handle || sole_child) {
r = EFI_CALL(binding_protocol->stop(binding_protocol,
controller_handle,
0, NULL));
diff --git a/lib/efi_loader/efi_string.c b/lib/efi_loader/efi_string.c
new file mode 100644
index 0000000000..3de721f06c
--- /dev/null
+++ b/lib/efi_loader/efi_string.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * String functions
+ *
+ * Copyright (c) 2020 AKASHI Takahiro, Linaro Limited
+ */
+
+#include <common.h>
+#include <charset.h>
+
+/**
+ * efi_create_indexed_name - create a string name with an index
+ * @buffer: Buffer
+ * @name: Name string
+ * @index: Index
+ *
+ * Create a utf-16 string with @name, appending @index.
+ * For example, L"Capsule0001"
+ *
+ * The caller must ensure that the buffer has enough space for the resulting
+ * string including the trailing L'\0'.
+ *
+ * Return: A pointer to the next position after the created string
+ * in @buffer, or NULL otherwise
+ */
+u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int index)
+{
+ u16 *p = buffer;
+ char index_buf[5];
+
+ utf8_utf16_strcpy(&p, name);
+ sprintf(index_buf, "%04X", index);
+ utf8_utf16_strcpy(&p, index_buf);
+
+ return p;
+}
diff --git a/lib/getopt.c b/lib/getopt.c
new file mode 100644
index 0000000000..8b4515dc19
--- /dev/null
+++ b/lib/getopt.c
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * getopt.c - a simple getopt(3) implementation. See getopt.h for explanation.
+ *
+ * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
+ * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ */
+
+#define LOG_CATEGORY LOGC_CORE
+
+#include <common.h>
+#include <getopt.h>
+#include <log.h>
+
+void getopt_init_state(struct getopt_state *gs)
+{
+ gs->index = 1;
+ gs->arg_index = 1;
+}
+
+int __getopt(struct getopt_state *gs, int argc, char *const argv[],
+ const char *optstring, bool silent)
+{
+ char curopt; /* current option character */
+ const char *curoptp; /* pointer to the current option in optstring */
+
+ while (1) {
+ log_debug("arg_index: %d index: %d\n", gs->arg_index,
+ gs->index);
+
+ /* `--` indicates the end of options */
+ if (gs->arg_index == 1 && argv[gs->index] &&
+ !strcmp(argv[gs->index], "--")) {
+ gs->index++;
+ return -1;
+ }
+
+ /* Out of arguments */
+ if (gs->index >= argc)
+ return -1;
+
+ /* Can't parse non-options */
+ if (*argv[gs->index] != '-')
+ return -1;
+
+ /* We have found an option */
+ curopt = argv[gs->index][gs->arg_index];
+ if (curopt)
+ break;
+ /*
+ * no more options in current argv[] element; try the next one
+ */
+ gs->index++;
+ gs->arg_index = 1;
+ }
+
+ /* look up current option in optstring */
+ curoptp = strchr(optstring, curopt);
+
+ if (!curoptp) {
+ if (!silent)
+ printf("%s: invalid option -- %c\n", argv[0], curopt);
+ gs->opt = curopt;
+ gs->arg_index++;
+ return '?';
+ }
+
+ if (*(curoptp + 1) != ':') {
+ /* option with no argument. Just return it */
+ gs->arg = NULL;
+ gs->arg_index++;
+ return curopt;
+ }
+
+ if (*(curoptp + 1) && *(curoptp + 2) == ':') {
+ /* optional argument */
+ if (argv[gs->index][gs->arg_index + 1]) {
+ /* optional argument with directly following arg */
+ gs->arg = argv[gs->index++] + gs->arg_index + 1;
+ gs->arg_index = 1;
+ return curopt;
+ }
+ if (gs->index + 1 == argc) {
+ /* We are at the last argv[] element */
+ gs->arg = NULL;
+ gs->index++;
+ return curopt;
+ }
+ if (*argv[gs->index + 1] != '-') {
+ /*
+ * optional argument with arg in next argv[] element
+ */
+ gs->index++;
+ gs->arg = argv[gs->index++];
+ gs->arg_index = 1;
+ return curopt;
+ }
+
+ /* no optional argument found */
+ gs->arg = NULL;
+ gs->arg_index = 1;
+ gs->index++;
+ return curopt;
+ }
+
+ if (argv[gs->index][gs->arg_index + 1]) {
+ /* required argument with directly following arg */
+ gs->arg = argv[gs->index++] + gs->arg_index + 1;
+ gs->arg_index = 1;
+ return curopt;
+ }
+
+ gs->index++;
+ gs->arg_index = 1;
+
+ if (gs->index >= argc || argv[gs->index][0] == '-') {
+ if (!silent)
+ printf("option requires an argument -- %c\n", curopt);
+ gs->opt = curopt;
+ return ':';
+ }
+
+ gs->arg = argv[gs->index++];
+ return curopt;
+}
diff --git a/lib/rsa/rsa-mod-exp.c b/lib/rsa/rsa-mod-exp.c
index 78c688d14c..74f9eb16cc 100644
--- a/lib/rsa/rsa-mod-exp.c
+++ b/lib/rsa/rsa-mod-exp.c
@@ -321,7 +321,7 @@ int rsa_mod_exp_sw(const uint8_t *sig, uint32_t sig_len,
* pow_mod calculation required for zynq is bit different from
* pw_mod above here, hence defined zynq specific routine.
*/
-int zynq_pow_mod(u32 *keyptr, u32 *inout)
+int zynq_pow_mod(uint32_t *keyptr, uint32_t *inout)
{
u32 *result, *ptr;
uint i;
diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
new file mode 100644
index 0000000000..b89f988ef9
--- /dev/null
+++ b/lib/smbios-parser.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020, Bachmann electronic GmbH
+ */
+
+#include <common.h>
+#include <smbios.h>
+
+static inline int verify_checksum(const struct smbios_entry *e)
+{
+ /*
+ * Checksums for SMBIOS tables are calculated to have a value, so that
+ * the sum over all bytes yields zero (using unsigned 8 bit arithmetic).
+ */
+ u8 *byte = (u8 *)e;
+ u8 sum = 0;
+
+ for (int i = 0; i < e->length; i++)
+ sum += byte[i];
+
+ return sum;
+}
+
+const struct smbios_entry *smbios_entry(u64 address, u32 size)
+{
+ const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address;
+
+ if (!address | !size)
+ return NULL;
+
+ if (memcmp(entry->anchor, "_SM_", 4))
+ return NULL;
+
+ if (verify_checksum(entry))
+ return NULL;
+
+ return entry;
+}
+
+static const struct smbios_header *next_header(const struct smbios_header *curr)
+{
+ u8 *pos = ((u8 *)curr) + curr->length;
+
+ /* search for _double_ NULL bytes */
+ while (!((*pos == 0) && (*(pos + 1) == 0)))
+ pos++;
+
+ /* step behind the double NULL bytes */
+ pos += 2;
+
+ return (struct smbios_header *)pos;
+}
+
+const struct smbios_header *smbios_header(const struct smbios_entry *entry, int type)
+{
+ const unsigned int num_header = entry->struct_count;
+ const struct smbios_header *header = (struct smbios_header *)entry->struct_table_address;
+
+ for (unsigned int i = 0; i < num_header; i++) {
+ if (header->type == type)
+ return header;
+
+ header = next_header(header);
+ }
+
+ return NULL;
+}
+
+static const char *string_from_smbios_table(const struct smbios_header *header,
+ int idx)
+{
+ unsigned int i = 1;
+ u8 *pos;
+
+ if (!header)
+ return NULL;
+
+ pos = ((u8 *)header) + header->length;
+
+ while (i < idx) {
+ if (*pos == 0x0)
+ i++;
+
+ pos++;
+ }
+
+ return (const char *)pos;
+}
+
+const char *smbios_string(const struct smbios_header *header, int index)
+{
+ if (!header)
+ return NULL;
+
+ return string_from_smbios_table(header, index);
+}
diff --git a/lib/smbios.c b/lib/smbios.c
index 11790443e1..485a812c77 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -6,6 +6,7 @@
*/
#include <common.h>
+#include <dm.h>
#include <env.h>
#include <mapmem.h>
#include <smbios.h>
@@ -13,11 +14,22 @@
#include <version.h>
#ifdef CONFIG_CPU
#include <cpu.h>
-#include <dm.h>
#include <dm/uclass-internal.h>
#endif
/**
+ * struct smbios_write_method - Information about a table-writing function
+ *
+ * @write: Function to call
+ * @subnode_name: Name of subnode which has the information for this function,
+ * NULL if none
+ */
+struct smbios_write_method {
+ smbios_write_type write;
+ const char *subnode_name;
+};
+
+/**
* smbios_add_string() - add a string to the string area
*
* This adds a string to the string area which is appended directly after
@@ -25,7 +37,7 @@
*
* @start: string area start address
* @str: string to add
- * @return: string number in the string area
+ * @return: string number in the string area (1 or more)
*/
static int smbios_add_string(char *start, const char *str)
{
@@ -53,6 +65,28 @@ static int smbios_add_string(char *start, const char *str)
}
/**
+ * smbios_add_prop() - Add a property from the device tree
+ *
+ * @start: string area start address
+ * @node: node containing the information to write (ofnode_null() if none)
+ * @prop: property to write
+ * @return 0 if not found, else SMBIOS string number (1 or more)
+ */
+static int smbios_add_prop(char *start, ofnode node, const char *prop)
+{
+
+ if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+ const char *str;
+
+ str = ofnode_read_string(node, prop);
+ if (str)
+ return smbios_add_string(start, str);
+ }
+
+ return 0;
+}
+
+/**
* smbios_string_table_len() - compute the string area size
*
* This computes the size of the string area including the string terminator.
@@ -74,7 +108,7 @@ static int smbios_string_table_len(char *start)
return len + 1;
}
-static int smbios_write_type0(ulong *current, int handle)
+static int smbios_write_type0(ulong *current, int handle, ofnode node)
{
struct smbios_type0 *t;
int len = sizeof(struct smbios_type0);
@@ -111,7 +145,7 @@ static int smbios_write_type0(ulong *current, int handle)
return len;
}
-static int smbios_write_type1(ulong *current, int handle)
+static int smbios_write_type1(ulong *current, int handle, ofnode node)
{
struct smbios_type1 *t;
int len = sizeof(struct smbios_type1);
@@ -120,12 +154,17 @@ static int smbios_write_type1(ulong *current, int handle)
t = map_sysmem(*current, len);
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);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
+ t->product_name = smbios_add_prop(t->eos, node, "product");
+ t->version = smbios_add_prop(t->eos, node, "version");
if (serial_str) {
- strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
t->serial_number = smbios_add_string(t->eos, serial_str);
+ strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
+ } else {
+ t->serial_number = smbios_add_prop(t->eos, node, "serial");
}
+ t->sku_number = smbios_add_prop(t->eos, node, "sku");
+ t->family = smbios_add_prop(t->eos, node, "family");
len = t->length + smbios_string_table_len(t->eos);
*current += len;
@@ -134,7 +173,7 @@ static int smbios_write_type1(ulong *current, int handle)
return len;
}
-static int smbios_write_type2(ulong *current, int handle)
+static int smbios_write_type2(ulong *current, int handle, ofnode node)
{
struct smbios_type2 *t;
int len = sizeof(struct smbios_type2);
@@ -142,8 +181,9 @@ static int smbios_write_type2(ulong *current, int handle)
t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type2));
fill_smbios_header(t, SMBIOS_BOARD_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);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
+ t->product_name = smbios_add_prop(t->eos, node, "product");
+ t->asset_tag_number = smbios_add_prop(t->eos, node, "asset-tag");
t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
t->board_type = SMBIOS_BOARD_MOTHERBOARD;
@@ -154,7 +194,7 @@ static int smbios_write_type2(ulong *current, int handle)
return len;
}
-static int smbios_write_type3(ulong *current, int handle)
+static int smbios_write_type3(ulong *current, int handle, ofnode node)
{
struct smbios_type3 *t;
int len = sizeof(struct smbios_type3);
@@ -162,7 +202,7 @@ static int smbios_write_type3(ulong *current, int handle)
t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type3));
fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
- t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
+ t->manufacturer = smbios_add_prop(t->eos, node, "manufacturer");
t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
t->bootup_state = SMBIOS_STATE_SAFE;
t->power_supply_state = SMBIOS_STATE_SAFE;
@@ -176,7 +216,7 @@ static int smbios_write_type3(ulong *current, int handle)
return len;
}
-static void smbios_write_type4_dm(struct smbios_type4 *t)
+static void smbios_write_type4_dm(struct smbios_type4 *t, ofnode node)
{
u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
const char *vendor = "Unknown";
@@ -185,20 +225,20 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
#ifdef CONFIG_CPU
char processor_name[49];
char vendor_name[49];
- struct udevice *dev = NULL;
+ struct udevice *cpu = NULL;
- uclass_find_first_device(UCLASS_CPU, &dev);
- if (dev) {
- struct cpu_platdata *plat = dev_get_parent_platdata(dev);
+ uclass_find_first_device(UCLASS_CPU, &cpu);
+ if (cpu) {
+ struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
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)))
+ if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name)))
vendor = vendor_name;
- if (!cpu_get_desc(dev, processor_name, sizeof(processor_name)))
+ if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name)))
name = processor_name;
}
#endif
@@ -208,7 +248,7 @@ static void smbios_write_type4_dm(struct smbios_type4 *t)
t->processor_version = smbios_add_string(t->eos, name);
}
-static int smbios_write_type4(ulong *current, int handle)
+static int smbios_write_type4(ulong *current, int handle, ofnode node)
{
struct smbios_type4 *t;
int len = sizeof(struct smbios_type4);
@@ -217,7 +257,7 @@ static int smbios_write_type4(ulong *current, int handle)
memset(t, 0, sizeof(struct smbios_type4));
fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
- smbios_write_type4_dm(t);
+ smbios_write_type4_dm(t, node);
t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
t->l1_cache_handle = 0xffff;
@@ -232,7 +272,7 @@ static int smbios_write_type4(ulong *current, int handle)
return len;
}
-static int smbios_write_type32(ulong *current, int handle)
+static int smbios_write_type32(ulong *current, int handle, ofnode node)
{
struct smbios_type32 *t;
int len = sizeof(struct smbios_type32);
@@ -247,7 +287,7 @@ static int smbios_write_type32(ulong *current, int handle)
return len;
}
-static int smbios_write_type127(ulong *current, int handle)
+static int smbios_write_type127(ulong *current, int handle, ofnode node)
{
struct smbios_type127 *t;
int len = sizeof(struct smbios_type127);
@@ -262,19 +302,21 @@ static int smbios_write_type127(ulong *current, int handle)
return len;
}
-static smbios_write_type smbios_write_funcs[] = {
- smbios_write_type0,
- smbios_write_type1,
- smbios_write_type2,
- smbios_write_type3,
- smbios_write_type4,
- smbios_write_type32,
- smbios_write_type127
+static struct smbios_write_method smbios_write_funcs[] = {
+ { smbios_write_type0, },
+ { smbios_write_type1, "system", },
+ { smbios_write_type2, "baseboard", },
+ { smbios_write_type3, "chassis", },
+ { smbios_write_type4, },
+ { smbios_write_type32, },
+ { smbios_write_type127 },
};
ulong write_smbios_table(ulong addr)
{
+ ofnode parent_node = ofnode_null();
struct smbios_entry *se;
+ struct udevice *dev;
ulong table_addr;
ulong tables;
int len = 0;
@@ -284,6 +326,12 @@ ulong write_smbios_table(ulong addr)
int isize;
int i;
+ if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+ uclass_first_device(UCLASS_SYSINFO, &dev);
+ if (dev)
+ parent_node = dev_read_subnode(dev, "smbios");
+ }
+
/* 16 byte align the table address */
addr = ALIGN(addr, 16);
@@ -296,7 +344,15 @@ ulong write_smbios_table(ulong addr)
/* populate minimum required tables */
for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
- int tmp = smbios_write_funcs[i]((ulong *)&addr, handle++);
+ const struct smbios_write_method *method;
+ ofnode node = ofnode_null();
+ int tmp;
+
+ method = &smbios_write_funcs[i];
+ if (IS_ENABLED(CONFIG_OF_CONTROL) && method->subnode_name)
+ node = ofnode_find_subnode(parent_node,
+ method->subnode_name);
+ tmp = method->write((ulong *)&addr, handle++, node);
max_struct_size = max(max_struct_size, tmp);
len += tmp;