提交 07c9e683 编写于 作者: S Simon Glass 提交者: Bin Meng

smbios: Allow a few values to come from sysinfo

While static configuration is useful it cannot cover every case. Sometimes
board revisions are encoded in resistor straps and must be read at
runtime.

The easiest way to provide this information is via sysinfo, since the
board can then provide a driver to read whatever is needed.

Add some standard sysinfo options for this, and use them to obtain the
required information.
Signed-off-by: NSimon Glass <sjg@chromium.org>
Reviewed-by: NBin Meng <bmeng.cn@gmail.com>
上级 2764cf5e
...@@ -31,6 +31,17 @@ ...@@ -31,6 +31,17 @@
* to read the serial number. * to read the serial number.
*/ */
/** enum sysinfo_id - Standard IDs defined by U-Boot */
enum sysinfo_id {
SYSINFO_ID_NONE,
SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
/* First value available for downstream/board used */
SYSINFO_ID_USER = 0x1000,
};
struct sysinfo_ops { struct sysinfo_ops {
/** /**
* detect() - Run the hardware info detection procedure for this * detect() - Run the hardware info detection procedure for this
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <env.h> #include <env.h>
#include <mapmem.h> #include <mapmem.h>
#include <smbios.h> #include <smbios.h>
#include <sysinfo.h>
#include <tables_csum.h> #include <tables_csum.h>
#include <version.h> #include <version.h>
#ifdef CONFIG_CPU #ifdef CONFIG_CPU
...@@ -108,14 +109,25 @@ static int smbios_add_string(struct smbios_ctx *ctx, const char *str) ...@@ -108,14 +109,25 @@ static int smbios_add_string(struct smbios_ctx *ctx, const char *str)
} }
/** /**
* smbios_add_prop() - Add a property from the device tree * smbios_add_prop_si() - Add a property from the devicetree or sysinfo
*
* Sysinfo is used if available, with a fallback to devicetree
* *
* @ctx: context for writing the tables * @ctx: context for writing the tables
* @prop: property to write * @prop: property to write
* @return 0 if not found, else SMBIOS string number (1 or more) * @return 0 if not found, else SMBIOS string number (1 or more)
*/ */
static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop) static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
int sysinfo_id)
{ {
if (sysinfo_id && ctx->dev) {
char val[SMBIOS_STR_MAX];
int ret;
ret = sysinfo_get_str(ctx->dev, sysinfo_id, sizeof(val), val);
if (!ret)
return smbios_add_string(ctx, val);
}
if (IS_ENABLED(CONFIG_OF_CONTROL)) { if (IS_ENABLED(CONFIG_OF_CONTROL)) {
const char *str; const char *str;
...@@ -127,6 +139,17 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop) ...@@ -127,6 +139,17 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)
return 0; return 0;
} }
/**
* smbios_add_prop() - Add a property from the devicetree
*
* @prop: property to write
* @return 0 if not found, else SMBIOS string number (1 or more)
*/
static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)
{
return smbios_add_prop_si(ctx, prop, SYSINFO_ID_NONE);
}
static void smbios_set_eos(struct smbios_ctx *ctx, char *eos) static void smbios_set_eos(struct smbios_ctx *ctx, char *eos)
{ {
ctx->eos = eos; ctx->eos = eos;
...@@ -240,7 +263,8 @@ static int smbios_write_type1(ulong *current, int handle, ...@@ -240,7 +263,8 @@ static int smbios_write_type1(ulong *current, int handle,
smbios_set_eos(ctx, t->eos); smbios_set_eos(ctx, t->eos);
t->manufacturer = smbios_add_prop(ctx, "manufacturer"); t->manufacturer = smbios_add_prop(ctx, "manufacturer");
t->product_name = smbios_add_prop(ctx, "product"); t->product_name = smbios_add_prop(ctx, "product");
t->version = smbios_add_prop(ctx, "version"); t->version = smbios_add_prop_si(ctx, "version",
SYSINFO_ID_SMBIOS_SYSTEM_VERSION);
if (serial_str) { if (serial_str) {
t->serial_number = smbios_add_string(ctx, serial_str); t->serial_number = smbios_add_string(ctx, serial_str);
strncpy((char *)t->uuid, serial_str, sizeof(t->uuid)); strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
...@@ -269,6 +293,8 @@ static int smbios_write_type2(ulong *current, int handle, ...@@ -269,6 +293,8 @@ static int smbios_write_type2(ulong *current, int handle,
smbios_set_eos(ctx, t->eos); smbios_set_eos(ctx, t->eos);
t->manufacturer = smbios_add_prop(ctx, "manufacturer"); t->manufacturer = smbios_add_prop(ctx, "manufacturer");
t->product_name = smbios_add_prop(ctx, "product"); t->product_name = smbios_add_prop(ctx, "product");
t->version = smbios_add_prop_si(ctx, "version",
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION);
t->asset_tag_number = smbios_add_prop(ctx, "asset-tag"); t->asset_tag_number = smbios_add_prop(ctx, "asset-tag");
t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING; t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
t->board_type = SMBIOS_BOARD_MOTHERBOARD; t->board_type = SMBIOS_BOARD_MOTHERBOARD;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册