Skip to contentSkip to conversation

Add a module for retrieving SMBIOS information

PATCH In review David Michael 4 participants 5 messages Jul 5, 2019 – Jul 11, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v7 2/2 Add a module for retrieving SMBIOS information

The following are two use cases from Rajat Jain <[email protected]>:

1) We have a board that boots Linux and this board itself can be plugged into one of different chassis types. We need to pass different parameters to the kernel based on the "CHASSIS_TYPE" information that is passed by the bios in the DMI / SMBIOS tables.

2) We may have a USB stick that can go into multiple boards, and the exact kernel to be loaded depends on the machine information (PRODUCT_NAME etc) passed via the DMI.

---

No changes since v6, just rebased onto 2.04

Hi,

I'm resending this after the 2.04 release assuming development is open for new features again. Let me know if there is anything more to do to make it acceptable for merging.

Thanks.

David

 docs/grub.texi                       |  75 ++++++
 grub-core/Makefile.core.def          |  15 ++
 grub-core/commands/efi/smbios.c      |  59 +++++
 grub-core/commands/i386/pc/smbios.c  |  50 ++++
 grub-core/commands/smbios.c          | 364 +++++++++++++++++++++++++++
 grub-core/efiemu/i386/pc/cfgtables.c |  15 +-
 include/grub/smbios.h                |  68 +++++
 7 files changed, 635 insertions(+), 11 deletions(-)
 create mode 100644 grub-core/commands/efi/smbios.c
 create mode 100644 grub-core/commands/i386/pc/smbios.c
 create mode 100644 grub-core/commands/smbios.c
 create mode 100644 include/grub/smbios.h
docs/grub.texi +75 -0
index 87795075a..114991e5e 100644
@@ -3944,6 +3944,7 @@ you forget a command, you can run the command @command{help}
 * sha256sum::                   Compute or check SHA256 hash
 * sha512sum::                   Compute or check SHA512 hash
 * sleep::                       Wait for a specified number of seconds
+* smbios::                      Retrieve SMBIOS information
 * source::                      Read a configuration file in same context
 * test::                        Check file types and compare values
 * true::                        Do nothing, successfully
@@ -5083,6 +5084,80 @@ if timeout was interrupted by @key{ESC}.
 @end deffn
 
 
+@node smbios
+@subsection smbios
+
+@deffn Command smbios @
+ [@option{--type} @var{type}] @
+ [@option{--handle} @var{handle}] @
+ [@option{--match} @var{match}] @
+ (@option{--get-byte} | @option{--get-word} | @option{--get-dword} | @
+  @option{--get-qword} | @option{--get-string} | @option{--get-uuid}) @
+ @var{offset} @
+ [@option{--set} @var{variable}]
+Retrieve SMBIOS information.
+
+The @command{smbios} command returns the value of a field in an SMBIOS
+structure.  The following options determine which structure to select.
+
+@itemize @bullet
+@item
+Specifying @option{--type} will select structures with a matching
+@var{type}.  The type can be any integer from 0 to 255.
+@item
+Specifying @option{--handle} will select structures with a matching
+@var{handle}.  The handle can be any integer from 0 to 65535.
+@item
+Specifying @option{--match} will select structure number @var{match} in the
+filtered list of structures; e.g. @code{smbios --type 4 --match 2} will select
+the second Process Information (Type 4) structure.  The list is always ordered
+the same as the hardware's SMBIOS table.  The match number must be a positive
+integer.  If unspecified, the first matching structure will be selected.
+@end itemize
+
+The remaining options determine which field in the selected SMBIOS structure to
+return.  Only one of these options may be specified at a time.
+
+@itemize @bullet
+@item
+When given @option{--get-byte}, return the value of the byte
+at @var{offset} bytes into the selected SMBIOS structure.
+It will be formatted as an unsigned decimal integer.
+@item
+When given @option{--get-word}, return the value of the word (two bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+It will be formatted as an unsigned decimal integer.
+@item
+When given @option{--get-dword}, return the value of the dword (four bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+It will be formatted as an unsigned decimal integer.
+@item
+When given @option{--get-qword}, return the value of the qword (eight bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+It will be formatted as an unsigned decimal integer.
+@item
+When given @option{--get-string}, return the string with its index found
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-uuid}, return the value of the UUID (sixteen bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+It will be formatted as lower-case hyphenated hexadecimal digits, with the
+first three fields as little-endian, and the rest printed byte-by-byte.
+@end itemize
+
+The default action is to print the value of the requested field to the console,
+but a variable name can be specified with @option{--set} to store the value
+instead of printing it.
+
+For example, this will store and then display the system manufacturer's name.
+
+@example
+smbios --type 1 --get-string 4 --set system_manufacturer
+echo $system_manufacturer
+@end example
+@end deffn
+
+
 @node source
 @subsection source
 
grub-core/Makefile.core.def +15 -0
index 474a63e68..269370417 100644
@@ -1097,6 +1097,21 @@ module = {
   common = commands/sleep.c;
 };
 
+module = {
+  name = smbios;
+
+  common = commands/smbios.c;
+  efi = commands/efi/smbios.c;
+  i386_pc = commands/i386/pc/smbios.c;
+  i386_coreboot = commands/i386/pc/smbios.c;
+  i386_multiboot = commands/i386/pc/smbios.c;
+
+  enable = efi;
+  enable = i386_pc;
+  enable = i386_coreboot;
+  enable = i386_multiboot;
+};
+
 module = {
   name = suspend;
   ieee1275 = commands/ieee1275/suspend.c;
grub-core/commands/efi/smbios.c new file +59 -0

59 lines not on this page · raw message

grub-core/commands/i386/pc/smbios.c new file +50 -0

50 lines not on this page · raw message

grub-core/commands/smbios.c new file +364 -0

364 lines not on this page · raw message

grub-core/efiemu/i386/pc/cfgtables.c +4 -11
index 492c07c46..e5fffb7d4 100644
@@ -22,11 +22,11 @@
 #include <grub/misc.h>
 #include <grub/mm.h>
 #include <grub/acpi.h>
+#include <grub/smbios.h>
 
 grub_err_t
 grub_machine_efiemu_init_tables (void)
 {
-  grub_uint8_t *ptr;
   void *table;
   grub_err_t err;
   grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
@@ -57,17 +57,10 @@ grub_machine_efiemu_init_tables (void)
       if (err)
 	return err;
     }
-
-  for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000;
-       ptr += 16)
-    if (grub_memcmp (ptr, "_SM_", 4) == 0
-	&& grub_byte_checksum (ptr, *(ptr + 5)) == 0)
-      break;
-
-  if (ptr < (grub_uint8_t *) 0x100000)
+  table = grub_smbios_get_eps ();
+  if (table)
     {
-      grub_dprintf ("efiemu", "Registering SMBIOS\n");
-      err = grub_efiemu_register_configuration_table (smbios, 0, 0, ptr);
+      err = grub_efiemu_register_configuration_table (smbios, 0, 0, table);
       if (err)
 	return err;
     }
include/grub/smbios.h new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · David Michael

The following are two use cases from Rajat Jain <[email protected]>:

1) We have a board that boots Linux and this board itself can be plugged into one of different chassis types. We need to pass different parameters to the kernel based on the "CHASSIS_TYPE" information that is passed by the bios in the DMI / SMBIOS tables.

2) We may have a USB stick that can go into multiple boards, and the exact kernel to be loaded depends on the machine information (PRODUCT_NAME etc) passed via the DMI.

Another use case is aarch64 laptops effort. We have the same kernel, and the same image bootable and usable across 4 different laptop models, with the only difference between them being the DTB to load. I was looking at how I can distinguish between the four models and automatically pick the right dtb. I did see these patches and was very sad when I found out that they didn't get merged.

Thank you for rebasing these on top of v2.04. I will try to cherrypick them on top of Debian's experimental 2.04 grub and try to build an installer "that just boots" without requiring users to pick a particular dtb menuentry by hand. There are only dtbs in these images, and only one right one for each model.

(Post install, we have flash-kernel mechanisms to continuously flash and use the right dtb, this is needed for the installer's grub to be able to detect models and thus boot the right dtb)

Whilst these laptops might become dtb-free in the future, I expect new hardware to come out which would need dtb picker based on SMBIOS info again.

Signature · 3 lines
Regards,

Dimitri.
#2 lore raw
Quoted 14 lines · Dimitri John Ledkov
Quoted 13 lines · David Michael

The following are two use cases from Rajat Jain <[email protected]>:

1) We have a board that boots Linux and this board itself can be plugged into one of different chassis types. We need to pass different parameters to the kernel based on the "CHASSIS_TYPE" information that is passed by the bios in the DMI / SMBIOS tables.

2) We may have a USB stick that can go into multiple boards, and the exact kernel to be loaded depends on the machine information (PRODUCT_NAME etc) passed via the DMI.

Quoted 8 lines
Quoted 1 line

Another use case is aarch64 laptops effort. We have the same kernel, and the same image bootable and usable across 4 different laptop models, with the only difference between them being the DTB to load. I was looking at how I can distinguish between the four models and automatically pick the right dtb. I did see these patches and was very sad when I found out that they didn't get merged.

I very much don't want us to depend on aarch64-laptops-special-sauce though, so while I want this functionality in GRUB, I do not consider the aarch64-laptops project an argument for that.

I am working on extending the standalone DtbLoader driver to do this selection instead, meaning we won't need to roll special installers.
https://git.linaro.org/people/leif.lindholm/edk2.git/log/?h=dtbloader

/
Leif

Quoted 22 lines

Thank you for rebasing these on top of v2.04. I will try to cherrypick them on top of Debian's experimental 2.04 grub and try to build an installer "that just boots" without requiring users to pick a particular dtb menuentry by hand. There are only dtbs in these images, and only one right one for each model.

(Post install, we have flash-kernel mechanisms to continuously flash and use the right dtb, this is needed for the installer's grub to be able to detect models and thus boot the right dtb)

Whilst these laptops might become dtb-free in the future, I expect new hardware to come out which would need dtb picker based on SMBIOS info again.

Signature · 7 lines
Regards,

Dimitri.
_______________________________________________
Aarch64-laptops mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/aarch64-laptops
#3 lore raw
Quoted 10 lines · Leif Lindholm
Quoted 6 lines

Another use case is aarch64 laptops effort. We have the same kernel, and the same image bootable and usable across 4 different laptop models, with the only difference between them being the DTB to load. I was looking at how I can distinguish between the four models and automatically pick the right dtb. I did see these patches and was very sad when I found out that they didn't get merged.

I very much don't want us to depend on aarch64-laptops-special-sauce though, so while I want this functionality in GRUB, I do not consider the aarch64-laptops project an argument for that.

Sorry, the above may have come across more arrogantly than intended:
I mean it is not an argument for that *for me*, clearly others may have different opinions.

/
Leif

Reviewed-by on v7 2/2
#4 lore raw
In reply to David Michael
Quoted 7 lines · David Michael

The following are two use cases from Rajat Jain <[email protected]>:

1) We have a board that boots Linux and this board itself can be plugged into one of different chassis types. We need to pass different parameters to the kernel based on the "CHASSIS_TYPE" information that is passed by the bios in the DMI / SMBIOS tables.

2) We may have a USB stick that can go into multiple boards, and the exact kernel to be loaded depends on the machine information (PRODUCT_NAME etc) passed via the DMI.

There are some nitpicks but I fix them before committing.

Daniel