summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/charset.c4
-rw-r--r--lib/efi_loader/efi_firmware.c10
-rw-r--r--lib/efi_loader/efi_helper.c6
-rw-r--r--lib/efi_loader/efi_tcg2.c34
-rw-r--r--lib/efi_loader/smbiosdump.c6
-rw-r--r--lib/efi_selftest/efi_selftest_miniapp_exit.c2
-rw-r--r--lib/efi_selftest/efi_selftest_tcg2.c97
-rw-r--r--lib/smbios-parser.c11
-rw-r--r--lib/smbios.c49
-rw-r--r--lib/uuid.c4
10 files changed, 110 insertions, 113 deletions
diff --git a/lib/charset.c b/lib/charset.c
index 89057ef7ce2..2b43175b1d9 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -570,6 +570,10 @@ int utf8_to_utf32_stream(u8 c, char *buffer)
}
if (pos == end)
return 0;
+ /*
+ * Appending the byte lead to an invalid UTF-8 byte sequence.
+ * Consider it as the start of a new code sequence.
+ */
*buffer = 0;
}
}
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 9fd13297a60..ba5aba098c0 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -400,18 +400,18 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in
}
size = num_banks * sizeof(*var_state);
- var_state = calloc(1, size);
+ var_state = malloc(size);
if (!var_state)
return EFI_OUT_OF_RESOURCES;
/*
* GetVariable may fail, EFI_NOT_FOUND is returned if FmpState
* variable has not been set yet.
- * Ignore the error here since the correct FmpState variable
- * is set later.
*/
- efi_get_variable_int(varname, image_type_id, NULL, &size, var_state,
- NULL);
+ ret = efi_get_variable_int(varname, image_type_id, NULL, &size,
+ var_state, NULL);
+ if (ret != EFI_SUCCESS)
+ memset(var_state, 0, num_banks * sizeof(*var_state));
/*
* Only the fw_version is set here.
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 11066eb505d..5dd9cc876e4 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -380,12 +380,12 @@ done:
}
/**
- * get_config_table() - get configuration table
+ * efi_get_configuration_table() - get configuration table
*
* @guid: GUID of the configuration table
* Return: pointer to configuration table or NULL
*/
-static void *get_config_table(const efi_guid_t *guid)
+void *efi_get_configuration_table(const efi_guid_t *guid)
{
size_t i;
@@ -430,7 +430,7 @@ efi_status_t efi_install_fdt(void *fdt)
uintptr_t fdt_addr;
/* Look for device tree that is already installed */
- if (get_config_table(&efi_guid_fdt))
+ if (efi_get_configuration_table(&efi_guid_fdt))
return EFI_SUCCESS;
/* Check if there is a hardware device tree */
fdt_opt = env_get("fdt_addr");
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index 8db35d0b3c8..b07e0099c27 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -1075,12 +1075,17 @@ error:
*/
static efi_status_t
tcg2_measure_smbios(struct udevice *dev,
- const struct smbios_entry *entry)
+ const struct smbios3_entry *entry)
{
efi_status_t ret;
struct smbios_header *smbios_copy;
struct smbios_handoff_table_pointers2 *event = NULL;
u32 event_size;
+ const char smbios3_anchor[] = "_SM3_";
+
+ /* We only support SMBIOS 3.0 Entry Point structure */
+ if (memcmp(entry->anchor, smbios3_anchor, sizeof(smbios3_anchor) - 1))
+ return EFI_UNSUPPORTED;
/*
* TCG PC Client PFP Spec says
@@ -1093,7 +1098,7 @@ tcg2_measure_smbios(struct udevice *dev,
*/
event_size = sizeof(struct smbios_handoff_table_pointers2) +
FIELD_SIZEOF(struct efi_configuration_table, guid) +
- entry->struct_table_length;
+ entry->table_maximum_size;
event = calloc(1, event_size);
if (!event) {
ret = EFI_OUT_OF_RESOURCES;
@@ -1104,11 +1109,11 @@ tcg2_measure_smbios(struct udevice *dev,
memcpy(event->table_description, SMBIOS_HANDOFF_TABLE_DESC,
sizeof(SMBIOS_HANDOFF_TABLE_DESC));
put_unaligned_le64(1, &event->number_of_tables);
- guidcpy(&event->table_entry[0].guid, &smbios_guid);
+ guidcpy(&event->table_entry[0].guid, &smbios3_guid);
smbios_copy = (struct smbios_header *)((uintptr_t)&event->table_entry[0].table);
memcpy(&event->table_entry[0].table,
(void *)((uintptr_t)entry->struct_table_address),
- entry->struct_table_length);
+ entry->table_maximum_size);
smbios_prepare_measurement(entry, smbios_copy);
@@ -1124,23 +1129,6 @@ out:
}
/**
- * find_smbios_table() - find smbios table
- *
- * Return: pointer to the smbios table
- */
-static void *find_smbios_table(void)
-{
- u32 i;
-
- for (i = 0; i < systab.nr_tables; i++) {
- if (!guidcmp(&smbios_guid, &systab.tables[i].guid))
- return systab.tables[i].table;
- }
-
- return NULL;
-}
-
-/**
* tcg2_measure_gpt_table() - measure gpt table
*
* @dev: TPM device
@@ -1360,7 +1348,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha
u32 pcr_index;
struct udevice *dev;
u32 event = 0;
- struct smbios_entry *entry;
+ struct smbios3_entry *entry;
if (!is_tcg2_protocol_installed())
return EFI_SUCCESS;
@@ -1382,7 +1370,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha
if (ret != EFI_SUCCESS)
goto out;
- entry = (struct smbios_entry *)find_smbios_table();
+ entry = efi_get_configuration_table(&smbios3_guid);
if (entry) {
ret = tcg2_measure_smbios(dev, entry);
if (ret != EFI_SUCCESS)
diff --git a/lib/efi_loader/smbiosdump.c b/lib/efi_loader/smbiosdump.c
index f0b901897e9..2f0b91a353d 100644
--- a/lib/efi_loader/smbiosdump.c
+++ b/lib/efi_loader/smbiosdump.c
@@ -329,7 +329,7 @@ efi_status_t do_check(void)
return EFI_LOAD_ERROR;
}
table = (void *)(uintptr_t)smbios3_anchor->struct_table_address;
- len = smbios3_anchor->max_struct_size;
+ len = smbios3_anchor->table_maximum_size;
} else {
struct smbios_entry *smbios_anchor;
int r;
@@ -469,7 +469,7 @@ static efi_status_t do_save(u16 *filename)
smbios3_anchor = get_config_table(&smbios3_guid);
if (smbios3_anchor) {
- size = 0x20 + smbios3_anchor->max_struct_size;
+ size = 0x20 + smbios3_anchor->table_maximum_size;
ret = bs->allocate_pool(EFI_LOADER_DATA, size, (void **)&buf);
if (ret != EFI_SUCCESS) {
error(u"Out of memory\n");
@@ -480,7 +480,7 @@ static efi_status_t do_save(u16 *filename)
memcpy(buf, smbios3_anchor, smbios3_anchor->length);
memcpy(buf + 0x20,
(void *)(uintptr_t)smbios3_anchor->struct_table_address,
- smbios3_anchor->max_struct_size);
+ smbios3_anchor->table_maximum_size);
smbios3_anchor = (struct smbios3_entry *)buf;
smbios3_anchor->struct_table_address = 0x20;
diff --git a/lib/efi_selftest/efi_selftest_miniapp_exit.c b/lib/efi_selftest/efi_selftest_miniapp_exit.c
index 8b2e60cc711..0909a5ca748 100644
--- a/lib/efi_selftest/efi_selftest_miniapp_exit.c
+++ b/lib/efi_selftest/efi_selftest_miniapp_exit.c
@@ -39,7 +39,7 @@ static efi_status_t EFIAPI check_loaded_image_protocol
NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (ret != EFI_SUCCESS) {
cout->output_string(cout,
- u"Could not open loaded image protocol");
+ u"Could not open loaded image protocol\n");
return ret;
}
if ((void *)check_loaded_image_protocol <
diff --git a/lib/efi_selftest/efi_selftest_tcg2.c b/lib/efi_selftest/efi_selftest_tcg2.c
index 67a886efaa8..fb8b997653a 100644
--- a/lib/efi_selftest/efi_selftest_tcg2.c
+++ b/lib/efi_selftest/efi_selftest_tcg2.c
@@ -126,41 +126,40 @@ static u8 boot_order[] = {0x02, 0x10, 0x00, 0x10, 0x01, 0x10};
static void *orig_smbios_table;
static u64 dmi_addr = U32_MAX;
-#define SMBIOS_ENTRY_HEADER_SIZE 0x20
+#define SMBIOS3_ENTRY_HEADER_SIZE 0x18
/* smbios table for the measurement test */
-static u8 smbios_table_test[] = {
-0x5f, 0x53, 0x4d, 0x5f, 0x2c, 0x1f, 0x03, 0x00, 0x54, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x5f, 0x44, 0x4d, 0x49, 0x5f, 0xe4, 0x5c, 0x01,
-0x20, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
-0x01, 0x02, 0x00, 0x00, 0x03, 0x00, 0x80, 0x08, 0x01, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x0c, 0x15, 0x0a, 0xff, 0xff, 0x55, 0x2d, 0x42, 0x6f,
-0x6f, 0x74, 0x00, 0x32, 0x30, 0x32, 0x31, 0x2e, 0x31, 0x30, 0x2d, 0x72,
-0x63, 0x34, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x35, 0x2d, 0x67, 0x37, 0x32,
-0x37, 0x63, 0x33, 0x66, 0x33, 0x32, 0x35, 0x39, 0x2d, 0x64, 0x69, 0x72,
-0x74, 0x79, 0x00, 0x31, 0x30, 0x2f, 0x30, 0x31, 0x2f, 0x32, 0x30, 0x32,
-0x31, 0x00, 0x00, 0x01, 0x1b, 0x01, 0x00, 0x01, 0x02, 0x00, 0x03, 0x31,
-0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77,
-0x6e, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x50, 0x72,
-0x6f, 0x64, 0x75, 0x63, 0x74, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
-0x37, 0x38, 0x00, 0x00, 0x02, 0x0e, 0x02, 0x00, 0x01, 0x02, 0x00, 0x04,
-0x03, 0x01, 0x01, 0x01, 0x00, 0x0a, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77,
-0x6e, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x50, 0x72,
-0x6f, 0x64, 0x75, 0x63, 0x74, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
-0x33, 0x33, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00,
-0x00, 0x03, 0x15, 0x03, 0x00, 0x01, 0x03, 0x00, 0x02, 0x03, 0x03, 0x03,
-0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x6e,
-0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
-0x37, 0x38, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00,
-0x00, 0x04, 0x30, 0x04, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x01, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x03, 0x04,
-0x04, 0x04, 0x08, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x08, 0x00, 0x01,
-0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x00, 0x31, 0x32, 0x33,
-0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
-0x33, 0x33, 0x00, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x00,
-0x00, 0x20, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x7f, 0x04, 0x06, 0x00, 0x00, 0x00
+static u8 smbios3_table_test[] = {
+0x5f, 0x53, 0x4d, 0x33, 0x5f, 0x00, 0x18, 0x03, 0x07, 0x00, 0x01, 0x00,
+0x5c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x18, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x03, 0x00, 0x80, 0x08,
+0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x15, 0x0a, 0xff, 0xff,
+0x55, 0x2d, 0x42, 0x6f, 0x6f, 0x74, 0x00, 0x32, 0x30, 0x32, 0x31, 0x2e,
+0x31, 0x30, 0x2d, 0x72, 0x63, 0x34, 0x2d, 0x30, 0x30, 0x30, 0x30, 0x35,
+0x2d, 0x67, 0x37, 0x32, 0x37, 0x63, 0x33, 0x66, 0x33, 0x32, 0x35, 0x39,
+0x2d, 0x64, 0x69, 0x72, 0x74, 0x79, 0x00, 0x31, 0x30, 0x2f, 0x30, 0x31,
+0x2f, 0x32, 0x30, 0x32, 0x31, 0x00, 0x00, 0x01, 0x1b, 0x01, 0x00, 0x01,
+0x02, 0x00, 0x03, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x55, 0x6e,
+0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77,
+0x6e, 0x20, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x00, 0x31, 0x32,
+0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x00, 0x02, 0x0e, 0x02, 0x00,
+0x01, 0x02, 0x00, 0x04, 0x03, 0x01, 0x01, 0x01, 0x00, 0x0a, 0x55, 0x6e,
+0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77,
+0x6e, 0x20, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x00, 0x33, 0x33,
+0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35,
+0x36, 0x37, 0x38, 0x00, 0x00, 0x03, 0x15, 0x03, 0x00, 0x01, 0x03, 0x00,
+0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x00, 0x31, 0x32,
+0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33,
+0x33, 0x33, 0x33, 0x00, 0x00, 0x04, 0x30, 0x04, 0x00, 0x00, 0x03, 0x02,
+0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff,
+0xff, 0x02, 0x03, 0x04, 0x04, 0x04, 0x08, 0x00, 0x00, 0x02, 0x00, 0x08,
+0x00, 0x08, 0x00, 0x01, 0x00, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e,
+0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x00, 0x33, 0x33,
+0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x35, 0x35, 0x35, 0x35, 0x35,
+0x35, 0x35, 0x35, 0x00, 0x00, 0x20, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x04, 0x06, 0x00, 0x00, 0x00
};
#define IDX_ARRAY_SZ 3 /* support 24 PCRs */
@@ -179,10 +178,10 @@ static u8 expected_pcrs[EFI_TCG2_MAX_PCR_INDEX + 1][TPM2_SHA256_DIGEST_SIZE] = {
0x7b, 0xb9, 0xfe, 0xa1, 0xcd, 0x64, 0x49, 0xdd,
0xed, 0xe2, 0x65, 0x82, 0xc5, 0x3e, 0xf4, 0xc4},
- {0xf5, 0x79, 0xf3, 0x20, 0x62, 0x6e, 0x8b, 0x58,
- 0x62, 0xa3, 0x4e, 0x2f, 0xb7, 0x10, 0xac, 0x34,
- 0x4e, 0x68, 0x94, 0x37, 0x87, 0x29, 0xc4, 0xbe,
- 0xa3, 0xc4, 0xd9, 0x14, 0x2b, 0x66, 0x79, 0x9b},
+ {0x75, 0xb5, 0x91, 0x54, 0x12, 0xa8, 0xa4, 0x25,
+ 0x73, 0x79, 0xa7, 0x47, 0xd9, 0x32, 0x54, 0x78,
+ 0x9a, 0x80, 0x3f, 0xa8, 0x34, 0xfe, 0xd2, 0xae,
+ 0x76, 0xd3, 0x16, 0x4a, 0xb2, 0x03, 0xac, 0xe6},
{0x3d, 0x45, 0x8c, 0xfe, 0x55, 0xcc, 0x03, 0xea,
0x1f, 0x44, 0x3f, 0x15, 0x62, 0xbe, 0xec, 0x8d,
@@ -543,7 +542,7 @@ static void *find_smbios_table(const struct efi_system_table *systable)
u32 i;
for (i = 0; i < systable->nr_tables; i++) {
- if (!guidcmp(&smbios_guid, &systable->tables[i].guid))
+ if (!guidcmp(&smbios3_guid, &systable->tables[i].guid))
return systable->tables[i].table;
}
@@ -558,14 +557,12 @@ static void *find_smbios_table(const struct efi_system_table *systable)
*/
static efi_status_t setup_smbios_table(const struct efi_system_table *systable)
{
- struct smbios_entry *se;
+ struct smbios3_entry *se;
efi_status_t ret;
/* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
void *dmi;
- char *istart;
- int isize;
- if (sizeof(smbios_table_test) > EFI_PAGE_SIZE)
+ if (sizeof(smbios3_table_test) > EFI_PAGE_SIZE)
return EFI_OUT_OF_RESOURCES;
orig_smbios_table = find_smbios_table(systable);
@@ -586,19 +583,15 @@ static efi_status_t setup_smbios_table(const struct efi_system_table *systable)
dmi = (void *)(uintptr_t)dmi_addr;
se = dmi;
- boottime->copy_mem(se, smbios_table_test, sizeof(smbios_table_test));
+ boottime->copy_mem(se, smbios3_table_test, sizeof(smbios3_table_test));
/* update smbios table start address */
- se->struct_table_address = (uintptr_t)((u8 *)dmi + SMBIOS_ENTRY_HEADER_SIZE);
+ se->struct_table_address = (uintptr_t)((u8 *)dmi + SMBIOS3_ENTRY_HEADER_SIZE);
- /* calculate checksums */
- istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
- isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
- se->intermediate_checksum = table_compute_checksum(istart, isize);
- se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));
+ se->checksum = table_compute_checksum(se, sizeof(struct smbios3_entry));
/* Install SMBIOS information as configuration table */
- ret = boottime->install_configuration_table(&smbios_guid, dmi);
+ ret = boottime->install_configuration_table(&smbios3_guid, dmi);
if (ret != EFI_SUCCESS) {
efi_st_error("Cannot install SMBIOS table\n");
boottime->free_pages(dmi_addr, 1);
@@ -992,7 +985,7 @@ static int efi_st_tcg2_teardown(void)
* If orig_smbios_table is NULL, calling install_configuration_table()
* removes dummy SMBIOS table form systab.
*/
- r = boottime->install_configuration_table(&smbios_guid, orig_smbios_table);
+ r = boottime->install_configuration_table(&smbios3_guid, orig_smbios_table);
if (r != EFI_SUCCESS) {
efi_st_error("Failed to restore SMBOIS table\n");
return EFI_ST_FAILURE;
diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
index ac9a367a878..9a62b3c760d 100644
--- a/lib/smbios-parser.c
+++ b/lib/smbios-parser.c
@@ -15,7 +15,7 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size)
{
const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address;
- if (!address | !size)
+ if (!address || !size)
return NULL;
if (memcmp(entry->anchor, "_SM_", 4))
@@ -223,21 +223,24 @@ static void clear_smbios_table(struct smbios_header *header,
}
}
-void smbios_prepare_measurement(const struct smbios_entry *entry,
+void smbios_prepare_measurement(const struct smbios3_entry *entry,
struct smbios_header *smbios_copy)
{
u32 i, j;
+ void *table_end;
struct smbios_header *header;
+ table_end = (void *)((u8 *)smbios_copy + entry->table_maximum_size);
+
for (i = 0; i < ARRAY_SIZE(smbios_filter_tables); i++) {
header = smbios_copy;
- for (j = 0; j < entry->struct_count; j++) {
+ for (j = 0; (void *)header < table_end; j++) {
if (header->type == smbios_filter_tables[i].type)
break;
header = get_next_header(header);
}
- if (j >= entry->struct_count)
+ if ((void *)header >= table_end)
continue;
clear_smbios_table(header,
diff --git a/lib/smbios.c b/lib/smbios.c
index 7bd9805fec0..c83af730a91 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -135,13 +135,16 @@ static const struct map_sysinfo *convert_sysinfo_to_dt(const char *node, const c
*
* @ctx: SMBIOS context
* @str: string to add
- * Return: string number in the string area (1 or more)
+ * Return: string number in the string area. 0 if str is NULL.
*/
static int smbios_add_string(struct smbios_ctx *ctx, const char *str)
{
int i = 1;
char *p = ctx->eos;
+ if (!str)
+ return 0;
+
for (;;) {
if (!*p) {
ctx->last_str = p;
@@ -207,6 +210,7 @@ void get_str_from_dt(const struct map_sysinfo *nprop, char *str, size_t size)
*
* @ctx: context for writing the tables
* @prop: property to write
+ * @sysinfo_id: unique identifier for the string value to be read
* @dval: Default value to use if the string is not found or is empty
* Return: 0 if not found, else SMBIOS string number (1 or more)
*/
@@ -216,7 +220,7 @@ static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
int ret;
if (!dval || !*dval)
- dval = "Unknown";
+ dval = NULL;
if (!prop)
return smbios_add_string(ctx, dval);
@@ -311,6 +315,10 @@ int smbios_update_version(const char *version)
*/
static int smbios_string_table_len(const struct smbios_ctx *ctx)
{
+ /* In case no string is defined we have to return two \0 */
+ if (ctx->next_ptr == ctx->eos)
+ return 2;
+
/* Allow for the final \0 after all strings */
return (ctx->next_ptr + 1) - ctx->eos;
}
@@ -375,19 +383,19 @@ static int smbios_write_type1(ulong *current, int handle,
memset(t, 0, sizeof(struct smbios_type1));
fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
smbios_set_eos(ctx, t->eos);
- t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown");
- t->product_name = smbios_add_prop(ctx, "product", "Unknown");
+ t->manufacturer = smbios_add_prop(ctx, "manufacturer", NULL);
+ t->product_name = smbios_add_prop(ctx, "product", NULL);
t->version = smbios_add_prop_si(ctx, "version",
SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
- "Unknown");
+ NULL);
if (serial_str) {
t->serial_number = smbios_add_prop(ctx, NULL, serial_str);
strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
} else {
- t->serial_number = smbios_add_prop(ctx, "serial", "Unknown");
+ t->serial_number = smbios_add_prop(ctx, "serial", NULL);
}
- t->sku_number = smbios_add_prop(ctx, "sku", "Unknown");
- t->family = smbios_add_prop(ctx, "family", "Unknown");
+ t->sku_number = smbios_add_prop(ctx, "sku", NULL);
+ t->family = smbios_add_prop(ctx, "family", NULL);
len = t->length + smbios_string_table_len(ctx);
*current += len;
@@ -406,14 +414,15 @@ static int smbios_write_type2(ulong *current, int handle,
memset(t, 0, sizeof(struct smbios_type2));
fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
smbios_set_eos(ctx, t->eos);
- t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown");
- t->product_name = smbios_add_prop(ctx, "product", "Unknown");
+ t->manufacturer = smbios_add_prop(ctx, "manufacturer", NULL);
+ t->product_name = smbios_add_prop(ctx, "product", NULL);
t->version = smbios_add_prop_si(ctx, "version",
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
- "Unknown");
- t->asset_tag_number = smbios_add_prop(ctx, "asset-tag", "Unknown");
+ NULL);
+ t->asset_tag_number = smbios_add_prop(ctx, "asset-tag", NULL);
t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
t->board_type = SMBIOS_BOARD_MOTHERBOARD;
+ t->chassis_handle = handle + 1;
len = t->length + smbios_string_table_len(ctx);
*current += len;
@@ -432,7 +441,7 @@ static int smbios_write_type3(ulong *current, int handle,
memset(t, 0, sizeof(struct smbios_type3));
fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
smbios_set_eos(ctx, t->eos);
- t->manufacturer = smbios_add_prop(ctx, "manufacturer", "Unknown");
+ t->manufacturer = smbios_add_prop(ctx, "manufacturer", NULL);
t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
t->bootup_state = SMBIOS_STATE_SAFE;
t->power_supply_state = SMBIOS_STATE_SAFE;
@@ -450,8 +459,8 @@ static void smbios_write_type4_dm(struct smbios_type4 *t,
struct smbios_ctx *ctx)
{
u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
- const char *vendor = "Unknown";
- const char *name = "Unknown";
+ const char *vendor = NULL;
+ const char *name = NULL;
#ifdef CONFIG_CPU
char processor_name[49];
@@ -542,6 +551,7 @@ static struct smbios_write_method smbios_write_funcs[] = {
{ smbios_write_type0, "bios", },
{ smbios_write_type1, "system", },
{ smbios_write_type2, "baseboard", },
+ /* Type 3 must immediately follow type 2 due to chassis handle. */
{ smbios_write_type3, "chassis", },
{ smbios_write_type4, },
{ smbios_write_type32, },
@@ -556,7 +566,6 @@ ulong write_smbios_table(ulong addr)
struct smbios_ctx ctx;
ulong tables;
int len = 0;
- int max_struct_size = 0;
int handle = 0;
int i;
@@ -578,7 +587,6 @@ ulong write_smbios_table(ulong addr)
/* populate minimum required tables */
for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
const struct smbios_write_method *method;
- int tmp;
method = &smbios_write_funcs[i];
ctx.subnode_name = NULL;
@@ -588,10 +596,7 @@ ulong write_smbios_table(ulong addr)
ctx.node = ofnode_find_subnode(parent_node,
method->subnode_name);
}
- tmp = method->write((ulong *)&addr, handle++, &ctx);
-
- max_struct_size = max(max_struct_size, tmp);
- len += tmp;
+ len += method->write((ulong *)&addr, handle++, &ctx);
}
/*
@@ -610,7 +615,7 @@ ulong write_smbios_table(ulong addr)
se->minor_ver = SMBIOS_MINOR_VER;
se->doc_rev = 0;
se->entry_point_rev = 1;
- se->max_struct_size = len;
+ se->table_maximum_size = len;
se->struct_table_address = table_addr;
se->checksum = table_compute_checksum(se, sizeof(struct smbios3_entry));
unmap_sysmem(se);
diff --git a/lib/uuid.c b/lib/uuid.c
index 0be22bc05f7..2d7d99535e7 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -177,6 +177,10 @@ static const struct {
SMBIOS_TABLE_GUID,
},
{
+ "SMBIOS3 table",
+ SMBIOS3_TABLE_GUID,
+ },
+ {
"Runtime properties",
EFI_RT_PROPERTIES_TABLE_GUID,
},