sysinfo: Allow showing model info from sysinfo
authorSimon Glass <sjg@chromium.org>
Sun, 21 Mar 2021 03:50:06 +0000 (16:50 +1300)
committerSimon Glass <sjg@chromium.org>
Sat, 27 Mar 2021 03:26:48 +0000 (16:26 +1300)
Some boards may want to show the SKU ID or other information obtained at
runtime. Allow this to come from sysinfo. The board can then provide a
sysinfo driver to provide it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
common/board_info.c
include/sysinfo.h

index b54aa30a94426457edb2520ad80b918a316398f9..1cfe34f7067852d4e2dd4e8b37266d9a40b04173 100644 (file)
@@ -1,31 +1,52 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include <common.h>
+#include <dm.h>
 #include <init.h>
+#include <sysinfo.h>
 #include <asm/global_data.h>
 #include <linux/libfdt.h>
 #include <linux/compiler.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int __weak checkboard(void)
 {
        return 0;
 }
 
 /*
- * If the root node of the DTB has a "model" property, show it.
+ * Check sysinfo for board information. Failing that if the root node of the DTB
+ * has a "model" property, show it.
+ *
  * Then call checkboard().
  */
 int __weak show_board_info(void)
 {
-#ifdef CONFIG_OF_CONTROL
-       DECLARE_GLOBAL_DATA_PTR;
-       const char *model;
+       if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+               struct udevice *dev;
+               const char *model;
+               char str[80];
+               int ret = -ENOSYS;
+
+               if (IS_ENABLED(CONFIG_SYSINFO)) {
+                       /* This might provide more detail */
+                       ret = uclass_first_device_err(UCLASS_SYSINFO, &dev);
+                       if (!ret)
+                               ret = sysinfo_get_str(dev,
+                                                     SYSINFO_ID_BOARD_MODEL,
+                                                     sizeof(str), str);
+               }
 
-       model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+               /* Fail back to the main 'model' if available */
+               if (ret)
+                       model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+               else
+                       model = str;
 
-       if (model)
-               printf("Model: %s\n", model);
-#endif
+               if (model)
+                       printf("Model: %s\n", model);
+       }
 
        return checkboard();
 }
index 270ac1b377fbbe81388f217d578a19ded083b9ce..68fad25a0659b20772a2f98e6b2d7f4b690761f1 100644 (file)
@@ -37,9 +37,13 @@ struct udevice;
 enum sysinfo_id {
        SYSINFO_ID_NONE,
 
+       /* For SMBIOS tables */
        SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
        SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
 
+       /* For show_board_info() */
+       SYSINFO_ID_BOARD_MODEL,
+
        /* First value available for downstream/board used */
        SYSINFO_ID_USER = 0x1000,
 };