Re: [PATCH v6] boot/bootfdt: Add smbios3-entrypoint to FDT for non-EFI boots

2025-12-02 Thread Tom Rini
On Thu, 27 Nov 2025 08:28:34 -0800, Adriana Nicolae wrote:

> The Linux kernel can discover SMBIOS tables through two primary methods:
> 1. Via EFI tables, when using EFI boot;
> 2. Via the 'smbios3-entrypoint' property in the /chosen node of the
> device tree.
> 
> When U-Boot boots a Linux kernel using a non-EFI command ("bootm",
> "bootz", or "booti"), the kernel relies on the device tree to detect
> the hardware. If SMBIOS tables are available in U-Boot, they should
> be passed to the kernel via this device tree property.
> 
> [...]

Applied to u-boot/master, thanks!

[1/1] boot/bootfdt: Add smbios3-entrypoint to FDT for non-EFI boots
  commit: 209bbc4e0032228c6ea17e2172a8a6b89756c4f5
-- 
Tom




[PATCH v6] boot/bootfdt: Add smbios3-entrypoint to FDT for non-EFI boots

2025-11-27 Thread Adriana Nicolae
The Linux kernel can discover SMBIOS tables through two primary methods:
1. Via EFI tables, when using EFI boot;
2. Via the 'smbios3-entrypoint' property in the /chosen node of the
device tree.

When U-Boot boots a Linux kernel using a non-EFI command ("bootm",
"bootz", or "booti"), the kernel relies on the device tree to detect
the hardware. If SMBIOS tables are available in U-Boot, they should
be passed to the kernel via this device tree property.

This patch modifies boot_fdt_prepare(), to inject the SMBIOSv3 table
address into the device tree if there is a table generated by U-boot.
The "board_fdt_chosen_smbios" is weak in order to leave the possibilty
for specific boards to select custom SMBIOS addresses.

The changes in this patch are added in the context of supporting this
device tree property in linux kernel:
https://lkml.org/lkml/2025/10/24/1393

Device tree schema was updated to include the "smbios3-entrypoint" node
in pull request: https://github.com/devicetree-org/dt-schema/pull/177

Signed-off-by: Adriana Nicolae 
---
Changes in v6:
  - Update fdt_test_chosen to include smbios3-entrypoint.

Changes in v5:
  - Allocate 4KiB extra space for fdt blob and align it to 8 bytes.

Changes in v4:
  - Remove weak function board_fdt_chosen_smbios(), replace with
gd_smbios_start();
  - Return -EAGAIN in test if GENERATE_SMBIOS_TABLE is not enabled;
  - Remove unnecessary fdt cleanup at the end of the test;
  - Added missing newlines at the end of the modified files.

Changes in v3:
  - Moved "board_fdt_chosen_smbios" function to lib/smbios.c
  - Return physical address of smbios entry and use map_sysmem to
access the entry point;
  - Removed check for config enabled and added check for
GENERATE_SMBIOS_TABLE;
  - Add test to check that smbios entry address is added into fdt;

Changes in v2:
  - Renamed device tree property to "smbios3-entrypoint".
  - Removed redundant check for CONFIG_SMBIOS.
---
 boot/fdt_support.c | 19 ++
 test/cmd/fdt.c |  9 +
 test/dm/fdtdec.c   | 48 ++
 3 files changed, 76 insertions(+)

diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 92f2f534ee0..1c215e548db 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -333,6 +334,7 @@ int fdt_chosen(void *fdt)
int   nodeoffset;
int   err;
const char *str;/* used to set string properties */
+   ulong smbiosaddr;   /* SMBIOS table address */
 
err = fdt_check_header(fdt);
if (err < 0) {
@@ -387,6 +389,23 @@ int fdt_chosen(void *fdt)
return err;
}
 
+   if (CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE)) {
+   /* Inject SMBIOS address when we have a valid address.
+   * This is useful for systems using booti/bootm instead of 
bootefi.
+   * Failure to set this property is non-fatal, we only generate a
+   * warning.
+   */
+   smbiosaddr = gd_smbios_start();
+   if (smbiosaddr) {
+   err = fdt_setprop_u64(fdt, nodeoffset, 
"smbios3-entrypoint",
+   smbiosaddr);
+   if (err < 0) {
+   printf("WARNING: could not set 
smbios3-entrypoint %s.\n",
+   fdt_strerror(err));
+   }
+   }
+   }
+
return fdt_fixup_stdout(fdt, nodeoffset);
 }
 
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 96a8488e172..c519ecd3793 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1268,6 +1268,7 @@ static int fdt_test_chosen(struct unit_test_state *uts)
const char *env_bootargs = env_get("bootargs");
char fdt[8192];
ulong addr;
+   ulong smbios_addr = gd_smbios_start();
 
ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
@@ -1281,6 +1282,10 @@ static int fdt_test_chosen(struct unit_test_state *uts)
ut_assertok(run_commandf("fdt chosen"));
ut_assertok(run_commandf("fdt print /chosen"));
ut_assert_nextline("chosen {");
+   if (CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE))
+   ut_assert_nextline("\tsmbios3-entrypoint = <0x%08x 0x%08x>;",
+  upper_32_bits(smbiosaddr),
+  lower_32_bits(smbiosaddr));
ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version 
string */
if (env_bootargs)
ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
@@ -1300,6 +1305,10 @@ static int fdt_test_chosen(struct unit_test_state *uts)
   lower_32_bits(0x1234 + 0x5678 - 1));
ut_assert_nextline("\tlinux,initrd-start = <0x%08x 0x%08x>;",