[LEDE-DEV] [RFC v2 2/2] x86: use sysfs DMI information to populate sysinfo

Jo-Philipp Wich jo at mein.io
Wed Jun 1 08:09:46 PDT 2016


Use the DMI data available in sysfs to extract manufacturer and model info
and write it to /tmp/sysinfo/.

The data will be picked up by board_detect and can be used by e.g. LuCI to
display a more appropriate model description.

On an APU board the files will contain the following values:

    # cat /tmp/sysinfo/model
    PC Engines APU

    # cat /tmp/sysinfo/board_name
    pc-engines-apu

Signed-off-by: Jo-Philipp Wich <jo at mein.io>
---
 target/linux/x86/Makefile                          |  2 +-
 target/linux/x86/base-files/lib/preinit/20_sysinfo | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 target/linux/x86/base-files/lib/preinit/20_sysinfo

diff --git a/target/linux/x86/Makefile b/target/linux/x86/Makefile
index 1eae227..7e397ab 100644
--- a/target/linux/x86/Makefile
+++ b/target/linux/x86/Makefile
@@ -13,7 +13,7 @@ FEATURES:=squashfs ext4 vdi vmdk pcmcia targz
 SUBTARGETS=generic xen_domu geode 64
 MAINTAINER:=Felix Fietkau <nbd at openwrt.org>
 
-DEFAULT_PACKAGES += partx-utils
+DEFAULT_PACKAGES += partx-utils dmidecode
 
 KERNEL_PATCHVER:=4.4
 
diff --git a/target/linux/x86/base-files/lib/preinit/20_sysinfo b/target/linux/x86/base-files/lib/preinit/20_sysinfo
new file mode 100644
index 0000000..ab2fbeb
--- /dev/null
+++ b/target/linux/x86/base-files/lib/preinit/20_sysinfo
@@ -0,0 +1,18 @@
+do_sysinfo_x86() {
+	local manufacturer productname boardname
+
+	[ -x /usr/sbin/dmidecode ] || return
+
+	manufacturer="$(dmidecode -s system-manufacturer 2>/dev/null)"
+	productname="$(dmidecode -s system-product-name 2>/dev/null)"
+
+	[ -n "$manufacturer" -a -n "$productname" ] || return
+
+	boardname="$(printf "%s %s" "$manufacturer" "$productname" | tr 'A-Z' 'a-z' | tr -cs 'a-z0-9_-' '-')"
+
+	mkdir -p /tmp/sysinfo
+	echo "$boardname" > /tmp/sysinfo/board_name
+	echo "$manufacturer $productname" > /tmp/sysinfo/model
+}
+
+boot_hook_add preinit_main do_sysinfo_x86
-- 
2.1.4




More information about the Lede-dev mailing list