]> Git Repo - J-u-boot.git/blob - common/board_info.c
xyz-modem: Add missing fallthrough annotation
[J-u-boot.git] / common / board_info.c
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <dm.h>
4 #include <init.h>
5 #include <sysinfo.h>
6 #include <asm/global_data.h>
7 #include <linux/libfdt.h>
8 #include <linux/compiler.h>
9
10 DECLARE_GLOBAL_DATA_PTR;
11
12 int __weak checkboard(void)
13 {
14         return 0;
15 }
16
17 static const struct to_show {
18         const char *name;
19         enum sysinfo_id id;
20 } to_show[] = {
21         { "Manufacturer", SYSINFO_ID_BOARD_MANUFACTURER},
22         { "Prior-stage version", SYSINFO_ID_PRIOR_STAGE_VERSION },
23         { "Prior-stage date", SYSINFO_ID_PRIOR_STAGE_DATE },
24         { /* sentinel */ }
25 };
26
27 static int try_sysinfo(void)
28 {
29         struct udevice *dev;
30         char str[80];
31         int ret;
32
33         /* This might provide more detail */
34         ret = sysinfo_get(&dev);
35         if (ret)
36                 return ret;
37
38         ret = sysinfo_detect(dev);
39         if (ret)
40                 return ret;
41
42         ret = sysinfo_get_str(dev, SYSINFO_ID_BOARD_MODEL, sizeof(str), str);
43         if (ret)
44                 return ret;
45         printf("Model: %s\n", str);
46
47         if (IS_ENABLED(CONFIG_SYSINFO_EXTRA)) {
48                 const struct to_show *item;
49
50                 for (item = to_show; item->id; item++) {
51                         ret = sysinfo_get_str(dev, item->id, sizeof(str), str);
52                         if (!ret)
53                                 printf("%s: %s\n", item->name, str);
54                 }
55         }
56
57         return 0;
58 }
59
60 int show_board_info(void)
61 {
62         if (IS_ENABLED(CONFIG_OF_CONTROL)) {
63                 int ret = -ENOSYS;
64
65                 if (IS_ENABLED(CONFIG_SYSINFO))
66                         ret = try_sysinfo();
67
68                 /* Fail back to the main 'model' if available */
69                 if (ret) {
70                         const char *model;
71
72                         model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
73                         if (model)
74                                 printf("Model: %s\n", model);
75                 }
76         }
77
78         return checkboard();
79 }
This page took 0.052642 seconds and 4 git commands to generate.