Merge https://source.denx.de/u-boot/custodians/u-boot-usb
[platform/kernel/u-boot.git] / common / board_info.c
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <common.h>
4 #include <dm.h>
5 #include <init.h>
6 #include <sysinfo.h>
7 #include <asm/global_data.h>
8 #include <linux/libfdt.h>
9 #include <linux/compiler.h>
10
11 DECLARE_GLOBAL_DATA_PTR;
12
13 int __weak checkboard(void)
14 {
15         return 0;
16 }
17
18 /*
19  * Check sysinfo for board information. Failing that if the root node of the DTB
20  * has a "model" property, show it.
21  *
22  * Then call checkboard().
23  */
24 int __weak show_board_info(void)
25 {
26         if (IS_ENABLED(CONFIG_OF_CONTROL)) {
27                 struct udevice *dev;
28                 const char *model;
29                 char str[80];
30                 int ret = -ENOSYS;
31
32                 if (IS_ENABLED(CONFIG_SYSINFO)) {
33                         /* This might provide more detail */
34                         ret = sysinfo_get(&dev);
35                         if (!ret) {
36                                 ret = sysinfo_detect(dev);
37                                 if (!ret) {
38                                         ret = sysinfo_get_str(dev,
39                                                       SYSINFO_ID_BOARD_MODEL,
40                                                       sizeof(str), str);
41                                 }
42                         }
43                 }
44
45                 /* Fail back to the main 'model' if available */
46                 if (ret)
47                         model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
48                 else
49                         model = str;
50
51                 if (model)
52                         printf("Model: %s\n", model);
53         }
54
55         return checkboard();
56 }