On 8/16/24 17:46, Raymond Mao wrote:
Current SMBIOS library does not fully match to the specification.
It hardcodes values instead of exposing values from the device.
It does not support dynamic length for contained object handles
or elements and misses the handling of a few fields.

The refactoring of this patch includes:
1. Expose values from device via sysinfo interface.
2. Replace smbios_add_prop with smbios_add_prop_si to allow getting
    string values from sysinfo.
3. Add smbios_get_val_si to get int values from sysinfo.
4. Use sysinfo_get_data to get data area like contained object
    handles, elements or processor id.
5. Refactor SMBIOS cmd print functions to match the command output
    with the specification
6. Add new print functions for Type 0, 3 and 4.
7. Miscellaneous fixes in SMBIOS.

Signed-off-by: Raymond Mao <raymond....@linaro.org>
---
  cmd/smbios.c     | 268 +++++++++++++++++++++++++++++++++--
  include/smbios.h | 116 +++++++++++----
  lib/smbios.c     | 358 ++++++++++++++++++++++++++++++++++++++---------
  3 files changed, 632 insertions(+), 110 deletions(-)

diff --git a/cmd/smbios.c b/cmd/smbios.c
index d3bd8b12a67..8e2bf46a09c 100644
--- a/cmd/smbios.c
+++ b/cmd/smbios.c
@@ -26,6 +26,71 @@ static const char * const wakeup_type_strings[] = {
        "AC Power Restored",  /* 0x08 */
  };
+static const char * const boardtype_strings[] = {
+       "Reserved",                   /* 0x00 */
+       "Unknown",                    /* 0x01 */
+       "Other",                      /* 0x02 */
+       "Server Blade",                       /* 0x03 */
+       "Connectivity Switch",                /* 0x04 */
+       "System Management Module",   /* 0x05 */
+       "Processor Module",           /* 0x06 */
+       "I/O Module",                 /* 0x07 */
+       "Memory Module",              /* 0x08 */
+       "Daughter board",             /* 0x09 */
+       "Motherboard",                        /* 0x0a */
+       "Processor/Memory Module",    /* 0x0b */
+       "Processor/IO Module",                /* 0x0c */
+       "Interconnect board",         /* 0x0d */
+};
+
+static const char * const chassis_state_strings[] = {
+       "Reserved",                   /* 0x00 */
+       "Other",                      /* 0x01 */
+       "Unknown",                    /* 0x02 */
+       "Safe",                               /* 0x03 */
+       "Warning",                    /* 0x04 */
+       "Critical",                   /* 0x05 */
+       "Non-recoverable",            /* 0x06 */
+};
+
+static const char * const chassis_security_strings[] = {
+       "Reserved",                   /* 0x00 */
+       "Other",                      /* 0x01 */
+       "Unknown",                    /* 0x02 */
+       "None",                               /* 0x03 */
+       "External interface locked out",/* 0x04 */
+       "External interface enabled", /* 0x05 */
+};
+
+static const char * const processor_type_strings[] = {
+       "Reserved",                   /* 0x00 */
+       "Other",                      /* 0x01 */
+       "Unknown",                    /* 0x02 */
+       "Central Processor",          /* 0x03 */
+       "Math Processor",             /* 0x04 */
+       "DSP Processor",              /* 0x05 */
+       "Video Processor",            /* 0x06 */
+};
+
+static const char * const processor_family_strings[] = {
+       [0] = "Other",
+       [1] = "Unknown",
+       [2 ... 253] = "Other", /* skip these definitions from now */
+       [254] = "Refer to 'Processor Family 2'",
+       [255] = "Reserved",
+       [256] = "ARMv7",
+       [257] = "ARMv8",
+};
+
+static const char * const processor_upgrade_strings[] = {
+       [0] = "Reserved",
+       [1] = "Other",
+       [2] = "Unknown",
+       [3 ... 5] = "Other", /* skip these definitions from now */
+       [6] = "None",
+       [7 ... 80] = "Other", /* skip these definitions from now */
+};
+
  /**
   * smbios_get_string() - get SMBIOS string from table
   *
@@ -92,6 +157,32 @@ const char *smbios_wakeup_type_str(u8 wakeup_type)
        return wakeup_type_strings[wakeup_type];
  }
+static void smbios_print_type0(struct smbios_type0 *table)
+{
+       printf("BIOS Information\n");
+       smbios_print_str("Vendor", table, table->vendor);
+       smbios_print_str("BIOS Version", table, table->bios_ver);
+       /* Keep table->bios_start_segment as 0 for UEFI-based systems */
+       smbios_print_str("BIOS Release Date", table, table->bios_release_date);
+       printf("\tBIOS ROM Size: 0x%02x\n", table->bios_rom_size);
+       printf("\tBIOS Characteristics: 0x%016llx\n",
+              table->bios_characteristics);
+       printf("\tBIOS Characteristics Extension Byte 1: 0x%02x\n",
+              table->bios_characteristics_ext1);
+       printf("\tBIOS Characteristics Extension Byte 2: 0x%02x\n",
+              table->bios_characteristics_ext2);
+       printf("\tSystem BIOS Major Release: 0x%02x\n",
+              table->bios_major_release);
+       printf("\tSystem BIOS Minor Release: 0x%02x\n",
+              table->bios_minor_release);
+       printf("\tEmbedded Controller Firmware Major Release: 0x%02x\n",
+              table->ec_major_release);
+       printf("\tEmbedded Controller Firmware Minor Release: 0x%02x\n",
+              table->ec_minor_release);
+       printf("\tExtended BIOS ROM Size: 0x%04x\n",
+              table->extended_bios_rom_size);
+}
+
  static void smbios_print_type1(struct smbios_type1 *table)
  {
        printf("System Information\n");
@@ -99,38 +190,180 @@ static void smbios_print_type1(struct smbios_type1 *table)
        smbios_print_str("Product Name", table, table->product_name);
        smbios_print_str("Version", table, table->version);
        smbios_print_str("Serial Number", table, table->serial_number);
-       if (table->length >= 0x19) {
+       if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V21) {
                printf("\tUUID: %pUl\n", table->uuid);
                printf("\tWake-up Type: %s\n",
                       smbios_wakeup_type_str(table->wakeup_type));
        }
-       if (table->length >= 0x1b) {
+       if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V24) {
                smbios_print_str("SKU Number", table, table->sku_number);
                smbios_print_str("Family", table, table->family);
        }
  }
+const char *smbios_baseboard_type_str(u8 borad_type)

typo board_type


+{
+       if (borad_type >= ARRAY_SIZE(boardtype_strings))
+               borad_type = 0;

newline but is 0 proper here? It means Reserved. Shouldn't be Unknown?


+       return boardtype_strings[borad_type];
+}
+
  static void smbios_print_type2(struct smbios_type2 *table)
  {
-       u16 *handle;
+       int i;
+       u8 *addr = (u8 *)table + offsetof(struct smbios_type2, eos);
- printf("Base Board Information\n");
+       printf("Baseboard Information\n");
        smbios_print_str("Manufacturer", table, table->manufacturer);
        smbios_print_str("Product Name", table, table->product_name);
        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%04x\n", table->feature_flags);
+       printf("\tFeature Flags: 0x%02x\n", table->feature_flags);
        smbios_print_str("Chassis Location", table, table->chassis_location);
        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;
-       for (int i = 0; i < table->number_contained_objects; ++i)
-               printf("0x%04x ", handle[i]);
+       printf("\tBoard Type: %s\n",
+              smbios_baseboard_type_str(table->board_type));
+       printf("\tNumber of Contained Object Handles: 0x%02x\n",
+              table->number_contained_objects);
+       if (!table->number_contained_objects)
+               return;
+
+       printf("\tContained Object Handles:\n");
+       for (i = 0; i < table->number_contained_objects; i++) {
+               printf("\t\tObject[%03d]:\n", i);
+               if (CONFIG_IS_ENABLED(HEXDUMP))
+                       print_hex_dump("\t\t", DUMP_PREFIX_OFFSET, 16, 1, addr,
+                                      sizeof(u16), false);
+               addr += sizeof(u16);
+       }
        printf("\n");
  }
+const char *smbios_chassis_state_str(u8 state)
+{
+       if (state >= ARRAY_SIZE(chassis_state_strings))
+               state = 0;

newline and same as above.

+       return chassis_state_strings[state];
+}
+
+const char *smbios_chassis_security_str(u8 status)
+{
+       if (status >= ARRAY_SIZE(chassis_security_strings))
+               status = 0;

ditto.

M

Reply via email to