From 13b17acc5505236b68fed50ff75dc9fdb70d3706 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Fri, 12 Jan 2024 21:40:39 +0100 Subject: [PATCH] kboot: Add SMBIOS information for U-Boot Signed-off-by: Mark Kettenis --- src/kboot.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/kboot.c b/src/kboot.c index a0656dc74..0cb732e15 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -349,6 +349,52 @@ static int dt_set_serial_number(void) return 0; } +static int dt_set_smbios(void) +{ + int fdt_root = fdt_path_offset(dt, "/"); + int len, node, smbios_node; + + if (fdt_root < 0) + bail("FDT: could not open a handle to FDT root.\n"); + + node = fdt_add_subnode(dt, fdt_root, "smbios"); + if (node < 0) + bail("FDT: failed to add node 'smbios' to '/'\n"); + fdt_setprop_string(dt, node, "compatible", "u-boot,sysinfo-smbios"); + + smbios_node = fdt_add_subnode(dt, node, "smbios"); + if (smbios_node < 0) + bail("FDT: failed to add node 'smbios' to '/smbios'\n"); + + node = fdt_add_subnode(dt, smbios_node, "system"); + if (node < 0) + bail("FDT: failed to add node 'system' to '/smbios'\n"); + fdt_setprop_string(dt, node, "manufacturer", "Apple"); + const char *model = fdt_getprop(dt, fdt_root, "model", &len); + if (!model) + bail("FDT: failed to get model property\n"); + if (len < 6) + fdt_setprop_string(dt, node, "product", "Unknown"); + else + fdt_setprop_string(dt, node, "product", model + 6); + + node = fdt_add_subnode(dt, smbios_node, "baseboard"); + if (node < 0) + bail("FDT: failed to add node 'baseboard' to '/smbios'\n"); + fdt_setprop_string(dt, node, "manufacturer", "Apple"); + const char *target_type = adt_getprop(adt, 0, "target-type", NULL); + if (!target_type) + bail("ADT: failed to get target-type property\n"); + fdt_setprop_string(dt, node, "product", target_type); + + node = fdt_add_subnode(dt, smbios_node, "chassis"); + if (node < 0) + bail("FDT: failed to add node 'chassis' to '/smbios'\n"); + fdt_setprop_string(dt, node, "manufacturer", "Apple"); + + return 0; +} + static int dt_set_cpus(void) { int ret = 0; @@ -2266,6 +2312,8 @@ int kboot_prepare_dt(void *fdt) return -1; if (dt_set_serial_number()) return -1; + if (dt_set_smbios()) + return -1; if (dt_set_cpus()) return -1; if (dt_set_mac_addresses())