Attention is currently required from: Patrick Rudolph.
Hello Patrick Rudolph,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/flashrom/+/78302?usp=email
to review the following change.
Change subject: dmi: Scan in sysfs first ......................................................................
dmi: Scan in sysfs first
When not running on Windows scan the sysfs for DMI table 3 first. This is faster and less intrusive than accessing the memory directly.
Needs tests on internal programmer.
Change-Id: I0d0f461b64a6f6ed6c1a3a62d759b9c395ad0ec8 Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M dmi.c 1 file changed, 51 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/02/78302/1
diff --git a/dmi.c b/dmi.c index 94e47fb..5a50705 100644 --- a/dmi.c +++ b/dmi.c @@ -30,6 +30,10 @@ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> +#if !IS_WINDOWS +#include <sys/stat.h> +#endif
#include "flash.h" #include "hwaccess_physmap.h" @@ -41,6 +45,8 @@ /* Strings longer than 4096 in DMI are just insane. */ #define DMI_MAX_ANSWER_LEN 4096
+#define LINUX_DMI_SYSFS_TABLE_3 "/sys/firmware/dmi/entries/3-0/raw" + static bool g_has_dmi_support = false;
bool dmi_is_supported(void) @@ -232,6 +238,45 @@ physunmap(dmi_table_mem, len); }
+ +#if !IS_WINDOWS +/* read the chassis type from a sysfs file */ +static int dmi_sysfs(int *is_laptop) +{ + size_t bytes_read; + uint8_t buf[6]; + struct stat s; + FILE *fp; + + msg_pdbg("Using sysfs DMI decoder.\n"); + + if (stat(LINUX_DMI_SYSFS_TABLE_3, &s) < 0) { + msg_pdbg("Cannot stat "%s": %s\n", LINUX_DMI_SYSFS_TABLE_3, + strerror(errno)); + return 1; + } + + if ((fp = fopen(LINUX_DMI_SYSFS_TABLE_3, "r")) == NULL) { + msg_perr("Cannot open %s\n", LINUX_DMI_SYSFS_TABLE_3); + return 1; + } + + clearerr(fp); + bytes_read = fread(buf, 1, sizeof(buf), fp); + if (feof(fp) || ferror(fp) || bytes_read < sizeof(buf)) { + msg_perr("Error occurred when reading %s\n", + LINUX_DMI_SYSFS_TABLE_3); + fclose(fp); + return 1; + } + fclose(fp); + + *is_laptop = dmi_chassis_type(buf[5]); + + return 0; +} +#endif + #if SM_SUPPORT static int smbios_decode(uint8_t *buf, int *is_laptop) { @@ -400,6 +445,12 @@ return; }
+#if !IS_WINDOWS + /* Try to read sysfs first */ + if (!dmi_sysfs(is_laptop)) + return; +#endif + /* dmi_fill fills the dmi_strings array, and if possible set the is_laptop parameter. */ if (dmi_fill(is_laptop) != 0) return;