SMBIOS describes how firmware can report a product UUID to the OS. Currently, we derive one from the machine ID, which should ensure uniqueness, but for easier identification, it would be good if board code could explicitly set a UUID that's reported as-is to the OS.
Add global.product.uuid to allow for this. Signed-off-by: Ahmad Fatoum <[email protected]> --- common/misc.c | 14 ++++++++++++++ include/barebox-info.h | 4 ++++ lib/smbios.c | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/common/misc.c b/common/misc.c index 0af5a9cf30cd..b99a1b4ad8e7 100644 --- a/common/misc.c +++ b/common/misc.c @@ -142,6 +142,7 @@ BAREBOX_MAGICVAR(global.model, "Product name of this hardware"); static char *hostname; static char *serial_number; +static uuid_t product_uuid; /* Note that HOST_NAME_MAX is 64 on Linux */ #define BAREBOX_HOST_NAME_MAX 64 @@ -252,6 +253,19 @@ const char *barebox_get_serial_number(void) BAREBOX_MAGICVAR(global.serial_number, "Board serial number"); +void barebox_set_product_uuid(const uuid_t *__product_uuid) +{ + globalvar_add_simple_uuid("product.uuid", &product_uuid); + product_uuid = *__product_uuid; +} + +const uuid_t *barebox_get_product_uuid(void) +{ + return &product_uuid; +} + +BAREBOX_MAGICVAR(global.product.uuid, "SMBIOS-reported product UUID"); + #ifdef CONFIG_OFTREE static char *of_machine_compatible; diff --git a/include/barebox-info.h b/include/barebox-info.h index bcceb7b0e021..70a940862ce2 100644 --- a/include/barebox-info.h +++ b/include/barebox-info.h @@ -4,6 +4,7 @@ #define __BAREBOX_INFO_H__ #include <linux/types.h> +#include <linux/uuid.h> extern const char version_string[]; extern const char release_string[]; @@ -25,6 +26,9 @@ bool barebox_hostname_is_valid(const char *s); const char *barebox_get_serial_number(void); void barebox_set_serial_number(const char *); +void barebox_set_product_uuid(const uuid_t *uuid); +const uuid_t *barebox_get_product_uuid(void); + #ifdef CONFIG_OFTREE void barebox_set_of_machine_compatible(const char *); const char *barebox_get_of_machine_compatible(void); diff --git a/lib/smbios.c b/lib/smbios.c index c50fc907b255..d5aae1651f86 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -221,6 +221,8 @@ static int smbios_write_type1(void **current, int handle, { struct smbios_type1 *t; int len = sizeof(*t); + const uuid_t *product_uuid = NULL; + uuid_t product_uuid_buf; char *vendor; t = map_sysmem(*current, len); @@ -236,16 +238,20 @@ static int smbios_write_type1(void **current, int handle, t->version = smbios_add_string(ctx, NULL); t->serial_number = smbios_add_string(ctx, barebox_get_serial_number()); - if (IS_ENABLED(CONFIG_MACHINE_ID_SPECIFIC)) { - uuid_t id; - int ret; + product_uuid = barebox_get_product_uuid(); + if (!product_uuid && IS_ENABLED(CONFIG_MACHINE_ID_SPECIFIC)) { + int err; - ret = machine_id_get_app_specific(&id, ARRAY_AND_SIZE("barebox-smbios"), + err = machine_id_get_app_specific(&product_uuid_buf, + ARRAY_AND_SIZE("barebox-smbios"), NULL); - if (!ret) - export_uuid(t->uuid, &id); + if (!err) + product_uuid = &product_uuid_buf; } + if (product_uuid) + export_uuid(t->uuid, product_uuid); + if (reset_source_get() == RESET_WKE) t->wakeup_type = SMBIOS_WAKEUP_TYPE_OTHER; else -- 2.47.3
