All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] smbios: missing strings, RISC-V processor ID
@ 2024-01-29 21:04 Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 1/7] cmd: smbios: always use '0x%04x' for printing handles Heinrich Schuchardt
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

When a string value cannot be provided we should not create a string
'Unknown' but just set the string index to 0 as suggested by the
SMBIOS specification. Program dmidecode will render this as
'Not Specified'.

Set the chassis handle in the type 2 structure.

In the type 4 structure fill the RISC-V SMBIOS Processor ID.

Correct the output formatting of the smbios command:

* Add a missing colon after UUID.
* Format handle references consistently.
* Render missing strings as 'Not Specified'.

Heinrich Schuchardt (7):
  cmd: smbios: always use '0x%04x' for printing handles
  cmd: smbios: add missing colon after UUID
  cmd: smbios: replace missing string by 'Not Specified'
  smbios: string table always needs two terminating NUL bytes
  smbios: if a string value is unknown, use string number 0
  smbios: provide type 4 RISC-V SMBIOS Processor ID
  smbios: correctly fill chassis handle

 cmd/smbios.c            | 12 ++++++++----
 drivers/cpu/riscv_cpu.c | 12 ++++++++++++
 lib/smbios.c            | 38 +++++++++++++++++++++++---------------
 3 files changed, 43 insertions(+), 19 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/7] cmd: smbios: always use '0x%04x' for printing handles
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 2/7] cmd: smbios: add missing colon after UUID Heinrich Schuchardt
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

Handles are u16 numbers. Consistently use '0x%04x' to print them.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 cmd/smbios.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/smbios.c b/cmd/smbios.c
index feebf930b79..67f3a9f5f19 100644
--- a/cmd/smbios.c
+++ b/cmd/smbios.c
@@ -95,9 +95,9 @@ static void smbios_print_type2(struct smbios_type2 *table)
 	smbios_print_str("Version", table, table->version);
 	smbios_print_str("Serial Number", table, table->serial_number);
 	smbios_print_str("Asset Tag", table, table->asset_tag_number);
-	printf("\tFeature Flags: 0x%2x\n", table->feature_flags);
+	printf("\tFeature Flags: 0x%04x\n", table->feature_flags);
 	smbios_print_str("Chassis Location", table, table->chassis_location);
-	printf("\tChassis Handle: 0x%2x\n", table->chassis_handle);
+	printf("\tChassis Handle: 0x%04x\n", table->chassis_handle);
 	smbios_print_str("Board Type", table, table->board_type);
 	printf("\tContained Object Handles: ");
 	handle = (void *)table->eos;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/7] cmd: smbios: add missing colon after UUID
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 1/7] cmd: smbios: always use '0x%04x' for printing handles Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-02-01  8:40   ` Ilias Apalodimas
  2024-01-29 21:04 ` [PATCH 3/7] cmd: smbios: replace missing string by 'Not Specified' Heinrich Schuchardt
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

For consistent formatting add a colon ':' after the UUID label.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 cmd/smbios.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/smbios.c b/cmd/smbios.c
index 67f3a9f5f19..62935ecd1a2 100644
--- a/cmd/smbios.c
+++ b/cmd/smbios.c
@@ -76,7 +76,7 @@ static void smbios_print_type1(struct smbios_type1 *table)
 	smbios_print_str("Version", table, table->version);
 	smbios_print_str("Serial Number", table, table->serial_number);
 	if (table->length >= 0x19) {
-		printf("\tUUID %pUl\n", table->uuid);
+		printf("\tUUID: %pUl\n", table->uuid);
 		smbios_print_str("Wake Up Type", table, table->serial_number);
 	}
 	if (table->length >= 0x1b) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/7] cmd: smbios: replace missing string by 'Not Specified'
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 1/7] cmd: smbios: always use '0x%04x' for printing handles Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 2/7] cmd: smbios: add missing colon after UUID Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 4/7] smbios: string table always needs two terminating NUL bytes Heinrich Schuchardt
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

A missing string value is indicated by a string index of 0. In this case
print 'Not Specified' like the Linux dmidecode command does.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 cmd/smbios.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cmd/smbios.c b/cmd/smbios.c
index 62935ecd1a2..95bdff60268 100644
--- a/cmd/smbios.c
+++ b/cmd/smbios.c
@@ -25,6 +25,10 @@ static const char *smbios_get_string(void *table, int index)
 {
 	const char *str = (char *)table +
 			  ((struct smbios_header *)table)->length;
+	static const char fallback[] = "Not Specified";
+
+	if (!index)
+		return fallback;
 
 	if (!*str)
 		++str;
@@ -41,7 +45,7 @@ static struct smbios_header *next_table(struct smbios_header *table)
 	if (table->type == SMBIOS_END_OF_TABLE)
 		return NULL;
 
-	str = smbios_get_string(table, 0);
+	str = smbios_get_string(table, -1);
 	return (struct smbios_header *)(++str);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/7] smbios: string table always needs two terminating NUL bytes
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
                   ` (2 preceding siblings ...)
  2024-01-29 21:04 ` [PATCH 3/7] cmd: smbios: replace missing string by 'Not Specified' Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-01-31 17:15   ` Matthias Brugger
  2024-02-01  8:38   ` Ilias Apalodimas
  2024-01-29 21:04 ` [PATCH 5/7] smbios: if a string value is unknown, use string number 0 Heinrich Schuchardt
                   ` (2 subsequent siblings)
  6 siblings, 2 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

The string section of the different SMBIOS structures is always terminated
by two NUL bytes even if there is no string at all. This is described in
section 6.1.3 "Text string" of the SMBIOS 3.7.0 specification.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/smbios.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/smbios.c b/lib/smbios.c
index 7bd9805fec0..81908e89610 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -311,6 +311,9 @@ int smbios_update_version(const char *version)
  */
 static int smbios_string_table_len(const struct smbios_ctx *ctx)
 {
+	/* If the structure contains no string it is followed by to NUL bytes */
+	if (ctx->next_ptr == ctx->eos)
+		return 2;
 	/* Allow for the final \0 after all strings */
 	return (ctx->next_ptr + 1) - ctx->eos;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 5/7] smbios: if a string value is unknown, use string number 0
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
                   ` (3 preceding siblings ...)
  2024-01-29 21:04 ` [PATCH 4/7] smbios: string table always needs two terminating NUL bytes Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-02-01  8:41   ` Ilias Apalodimas
  2024-01-29 21:04 ` [PATCH 6/7] smbios: provide type 4 RISC-V SMBIOS Processor ID Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 7/7] smbios: correctly fill chassis handle Heinrich Schuchardt
  6 siblings, 1 reply; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

The SMBIOS specification describes: "If a string field references no
string, a null (0) is placed in that string field."

Accordingly we should avoid writing a string "Unknown" to the SMBIOS table.

dmidecode displays 'Not Specified' if the string number is 0.

Commit 00a871d34e2f ("smbios: empty strings in smbios_add_string()")
correctly identified that strings may not have length 0 as two
consecutive NULs indentify the end of the string list. But the suggested
solution did not match the intent of the SMBIOS specification.

Fixes: 00a871d34e2f ("smbios: empty strings in smbios_add_string()")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/smbios.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/lib/smbios.c b/lib/smbios.c
index 81908e89610..50072adb4e8 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;
@@ -216,7 +219,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);
@@ -378,19 +381,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;
@@ -409,12 +412,12 @@ 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;
 
@@ -435,7 +438,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;
@@ -453,8 +456,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];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 6/7] smbios: provide type 4 RISC-V SMBIOS Processor ID
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
                   ` (4 preceding siblings ...)
  2024-01-29 21:04 ` [PATCH 5/7] smbios: if a string value is unknown, use string number 0 Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-01-29 21:04 ` [PATCH 7/7] smbios: correctly fill chassis handle Heinrich Schuchardt
  6 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

For RISC-V CPUs the SMBIOS Processor ID field contains
the Machine Vendor ID from CSR mvendorid.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 drivers/cpu/riscv_cpu.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c
index 034b9b49c05..f3e10daf7ec 100644
--- a/drivers/cpu/riscv_cpu.c
+++ b/drivers/cpu/riscv_cpu.c
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <log.h>
 #include <asm/global_data.h>
+#include <asm/sbi.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
 #include <linux/bitops.h>
@@ -95,13 +96,24 @@ static int riscv_cpu_bind(struct udevice *dev)
 	struct cpu_plat *plat = dev_get_parent_plat(dev);
 	struct driver *drv;
 	int ret;
+	long mvendorid;
 
 	/* save the hart id */
 	plat->cpu_id = dev_read_addr(dev);
+	/* provide data for SMBIOS */
 	if (IS_ENABLED(CONFIG_64BIT))
 		plat->family = 0x201;
 	else
 		plat->family = 0x200;
+	if (CONFIG_IS_ENABLED(RISCV_SMODE)) {
+		/*
+		 * For RISC-V CPUs the SMBIOS Processor ID field contains
+		 * the Machine Vendor ID from CSR mvendorid.
+		 */
+		ret = sbi_get_mvendorid(&mvendorid);
+		if (!ret)
+			plat->id[0] = mvendorid;
+	}
 	/* first examine the property in current cpu node */
 	ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
 	/* if not found, then look at the parent /cpus node */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 7/7] smbios: correctly fill chassis handle
  2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
                   ` (5 preceding siblings ...)
  2024-01-29 21:04 ` [PATCH 6/7] smbios: provide type 4 RISC-V SMBIOS Processor ID Heinrich Schuchardt
@ 2024-01-29 21:04 ` Heinrich Schuchardt
  2024-02-01  8:42   ` Ilias Apalodimas
  6 siblings, 1 reply; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-29 21:04 UTC (permalink / raw)
  To: Tom Rini
  Cc: Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot,
	Heinrich Schuchardt

The chassis handle field in the type 2 structure must point to the handle
of the type 3 structure.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/smbios.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/smbios.c b/lib/smbios.c
index 50072adb4e8..5a6a980ff6f 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -420,6 +420,7 @@ static int smbios_write_type2(ulong *current, int handle,
 	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;
@@ -548,6 +549,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, },
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/7] smbios: string table always needs two terminating NUL bytes
  2024-01-29 21:04 ` [PATCH 4/7] smbios: string table always needs two terminating NUL bytes Heinrich Schuchardt
@ 2024-01-31 17:15   ` Matthias Brugger
  2024-01-31 18:02     ` Heinrich Schuchardt
  2024-02-01  8:38   ` Ilias Apalodimas
  1 sibling, 1 reply; 14+ messages in thread
From: Matthias Brugger @ 2024-01-31 17:15 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Tom Rini, Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot

On Mon, Jan 29, 2024 at 10:04:50PM +0100, Heinrich Schuchardt wrote:
> The string section of the different SMBIOS structures is always terminated
> by two NUL bytes even if there is no string at all. This is described in
> section 6.1.3 "Text string" of the SMBIOS 3.7.0 specification.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

I send the very same patch some years ago [1], unfortunately it got
somehow lost. Happy to see you trying to fix the same problem, so:
Reviewed-by: Matthias Brugger <mbrugger@suse.com>


[1] https://patchwork.ozlabs.org/project/uboot/patch/20210406090435.19357-1-matthias.bgg@kernel.org/ 

> ---
>  lib/smbios.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/smbios.c b/lib/smbios.c
> index 7bd9805fec0..81908e89610 100644
> --- a/lib/smbios.c
> +++ b/lib/smbios.c
> @@ -311,6 +311,9 @@ int smbios_update_version(const char *version)
>   */
>  static int smbios_string_table_len(const struct smbios_ctx *ctx)
>  {
> +	/* If the structure contains no string it is followed by to NUL bytes */
> +	if (ctx->next_ptr == ctx->eos)
> +		return 2;
>  	/* Allow for the final \0 after all strings */
>  	return (ctx->next_ptr + 1) - ctx->eos;
>  }
> -- 
> 2.43.0

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/7] smbios: string table always needs two terminating NUL bytes
  2024-01-31 17:15   ` Matthias Brugger
@ 2024-01-31 18:02     ` Heinrich Schuchardt
  0 siblings, 0 replies; 14+ messages in thread
From: Heinrich Schuchardt @ 2024-01-31 18:02 UTC (permalink / raw)
  To: Matthias Brugger
  Cc: Tom Rini, Ilias Apalodimas, Simon Glass, Peter Robinson, u-boot

On 31.01.24 18:15, Matthias Brugger wrote:
> On Mon, Jan 29, 2024 at 10:04:50PM +0100, Heinrich Schuchardt wrote:
>> The string section of the different SMBIOS structures is always terminated
>> by two NUL bytes even if there is no string at all. This is described in
>> section 6.1.3 "Text string" of the SMBIOS 3.7.0 specification.
>>
>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> 
> I send the very same patch some years ago [1], unfortunately it got
> somehow lost. Happy to see you trying to fix the same problem, so:
> Reviewed-by: Matthias Brugger <mbrugger@suse.com>
> 
> 
> [1] https://patchwork.ozlabs.org/project/uboot/patch/20210406090435.19357-1-matthias.bgg@kernel.org/

Thanks for the pointer. I assume not answering Simon's question lead to 
your patch not being merged.

To answer it:

 >> But where are the \0 bytes
 >> actually written? Perhaps that should be in smbios_set_eos()?

We have defined SMBIOS_STRUCT_EOS_BYTES as 2 and we have an array
char eos[SMBIOS_STRUCT_EOS_BYTES];
at the end of each SMBIOS structure.

We call memset(t, 0, sizeof(struct smbios_typeX)); for each table.
This is enough to ensure two zero bytes exist if there are no strings.

Best regards

Heinrich

> 
>> ---
>>   lib/smbios.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/smbios.c b/lib/smbios.c
>> index 7bd9805fec0..81908e89610 100644
>> --- a/lib/smbios.c
>> +++ b/lib/smbios.c
>> @@ -311,6 +311,9 @@ int smbios_update_version(const char *version)
>>    */
>>   static int smbios_string_table_len(const struct smbios_ctx *ctx)
>>   {
>> +	/* If the structure contains no string it is followed by two NUL bytes */
>> +	if (ctx->next_ptr == ctx->eos)
>> +		return 2;
>>   	/* Allow for the final \0 after all strings */
>>   	return (ctx->next_ptr + 1) - ctx->eos;
>>   }
>> -- 
>> 2.43.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/7] smbios: string table always needs two terminating NUL bytes
  2024-01-29 21:04 ` [PATCH 4/7] smbios: string table always needs two terminating NUL bytes Heinrich Schuchardt
  2024-01-31 17:15   ` Matthias Brugger
@ 2024-02-01  8:38   ` Ilias Apalodimas
  1 sibling, 0 replies; 14+ messages in thread
From: Ilias Apalodimas @ 2024-02-01  8:38 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Tom Rini, Simon Glass, Peter Robinson, u-boot

On Mon, 29 Jan 2024 at 23:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> The string section of the different SMBIOS structures is always terminated
> by two NUL bytes even if there is no string at all. This is described in
> section 6.1.3 "Text string" of the SMBIOS 3.7.0 specification.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/smbios.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/smbios.c b/lib/smbios.c
> index 7bd9805fec0..81908e89610 100644
> --- a/lib/smbios.c
> +++ b/lib/smbios.c
> @@ -311,6 +311,9 @@ int smbios_update_version(const char *version)
>   */
>  static int smbios_string_table_len(const struct smbios_ctx *ctx)
>  {
> +       /* If the structure contains no string it is followed by to NUL bytes */
> +       if (ctx->next_ptr == ctx->eos)
> +               return 2;
>         /* Allow for the final \0 after all strings */
>         return (ctx->next_ptr + 1) - ctx->eos;
>  }
> --
> 2.43.0
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/7] cmd: smbios: add missing colon after UUID
  2024-01-29 21:04 ` [PATCH 2/7] cmd: smbios: add missing colon after UUID Heinrich Schuchardt
@ 2024-02-01  8:40   ` Ilias Apalodimas
  0 siblings, 0 replies; 14+ messages in thread
From: Ilias Apalodimas @ 2024-02-01  8:40 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Tom Rini, Simon Glass, Peter Robinson, u-boot

On Mon, 29 Jan 2024 at 23:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> For consistent formatting add a colon ':' after the UUID label.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  cmd/smbios.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cmd/smbios.c b/cmd/smbios.c
> index 67f3a9f5f19..62935ecd1a2 100644
> --- a/cmd/smbios.c
> +++ b/cmd/smbios.c
> @@ -76,7 +76,7 @@ static void smbios_print_type1(struct smbios_type1 *table)
>         smbios_print_str("Version", table, table->version);
>         smbios_print_str("Serial Number", table, table->serial_number);
>         if (table->length >= 0x19) {
> -               printf("\tUUID %pUl\n", table->uuid);
> +               printf("\tUUID: %pUl\n", table->uuid);
>                 smbios_print_str("Wake Up Type", table, table->serial_number);
>         }
>         if (table->length >= 0x1b) {
> --
> 2.43.0
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 5/7] smbios: if a string value is unknown, use string number 0
  2024-01-29 21:04 ` [PATCH 5/7] smbios: if a string value is unknown, use string number 0 Heinrich Schuchardt
@ 2024-02-01  8:41   ` Ilias Apalodimas
  0 siblings, 0 replies; 14+ messages in thread
From: Ilias Apalodimas @ 2024-02-01  8:41 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Tom Rini, Simon Glass, Peter Robinson, u-boot

On Mon, 29 Jan 2024 at 23:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> The SMBIOS specification describes: "If a string field references no
> string, a null (0) is placed in that string field."
>
> Accordingly we should avoid writing a string "Unknown" to the SMBIOS table.
>
> dmidecode displays 'Not Specified' if the string number is 0.
>
> Commit 00a871d34e2f ("smbios: empty strings in smbios_add_string()")
> correctly identified that strings may not have length 0 as two
> consecutive NULs indentify the end of the string list. But the suggested
> solution did not match the intent of the SMBIOS specification.
>
> Fixes: 00a871d34e2f ("smbios: empty strings in smbios_add_string()")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/smbios.c | 33 ++++++++++++++++++---------------
>  1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/lib/smbios.c b/lib/smbios.c
> index 81908e89610..50072adb4e8 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;
> @@ -216,7 +219,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);
> @@ -378,19 +381,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;
> @@ -409,12 +412,12 @@ 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;
>
> @@ -435,7 +438,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;
> @@ -453,8 +456,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];
> --
> 2.43.0
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 7/7] smbios: correctly fill chassis handle
  2024-01-29 21:04 ` [PATCH 7/7] smbios: correctly fill chassis handle Heinrich Schuchardt
@ 2024-02-01  8:42   ` Ilias Apalodimas
  0 siblings, 0 replies; 14+ messages in thread
From: Ilias Apalodimas @ 2024-02-01  8:42 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Tom Rini, Simon Glass, Peter Robinson, u-boot

On Mon, 29 Jan 2024 at 23:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> The chassis handle field in the type 2 structure must point to the handle
> of the type 3 structure.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/smbios.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lib/smbios.c b/lib/smbios.c
> index 50072adb4e8..5a6a980ff6f 100644
> --- a/lib/smbios.c
> +++ b/lib/smbios.c
> @@ -420,6 +420,7 @@ static int smbios_write_type2(ulong *current, int handle,
>         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;
> @@ -548,6 +549,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, },
> --
> 2.43.0
>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-02-01  8:42 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-29 21:04 [PATCH 0/7] smbios: missing strings, RISC-V processor ID Heinrich Schuchardt
2024-01-29 21:04 ` [PATCH 1/7] cmd: smbios: always use '0x%04x' for printing handles Heinrich Schuchardt
2024-01-29 21:04 ` [PATCH 2/7] cmd: smbios: add missing colon after UUID Heinrich Schuchardt
2024-02-01  8:40   ` Ilias Apalodimas
2024-01-29 21:04 ` [PATCH 3/7] cmd: smbios: replace missing string by 'Not Specified' Heinrich Schuchardt
2024-01-29 21:04 ` [PATCH 4/7] smbios: string table always needs two terminating NUL bytes Heinrich Schuchardt
2024-01-31 17:15   ` Matthias Brugger
2024-01-31 18:02     ` Heinrich Schuchardt
2024-02-01  8:38   ` Ilias Apalodimas
2024-01-29 21:04 ` [PATCH 5/7] smbios: if a string value is unknown, use string number 0 Heinrich Schuchardt
2024-02-01  8:41   ` Ilias Apalodimas
2024-01-29 21:04 ` [PATCH 6/7] smbios: provide type 4 RISC-V SMBIOS Processor ID Heinrich Schuchardt
2024-01-29 21:04 ` [PATCH 7/7] smbios: correctly fill chassis handle Heinrich Schuchardt
2024-02-01  8:42   ` Ilias Apalodimas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.