Merge branch '2022-08-20-assorted-updates'
[platform/kernel/u-boot.git] / common / board_info.c
index 42d0641..e0f2d93 100644 (file)
@@ -1,35 +1,56 @@
-/*
- * SPDX-License-Identifier:    GPL-2.0+
- */
+// SPDX-License-Identifier: GPL-2.0+
 
 #include <common.h>
-#include <libfdt.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)
 {
-       printf("Board: Unknown\n");
        return 0;
 }
 
 /*
- * If the root node of the DTB has a "model" property, show it.
- * If CONFIG_OF_CONTROL is disabled or the "model" property is missing,
- * fall back to checkboard().
+ * Check sysinfo for board information. Failing that if the root node of the DTB
+ * has a "model" property, show it.
+ *
+ * Then call checkboard().
  */
-int show_board_info(void)
+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 = sysinfo_get(&dev);
+                       if (!ret) {
+                               ret = sysinfo_detect(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);
-               return 0;
+               if (model)
+                       printf("Model: %s\n", model);
        }
-#endif
 
        return checkboard();
 }