blob: f4c385add90c7b92299b6ffe2b1cf321f0f98cae [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada0365ffc2015-01-14 17:07:05 +09002
Tom Rinid678a592024-05-18 20:20:43 -06003#include <common.h>
Simon Glass96dedb02021-03-21 16:50:06 +13004#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06005#include <init.h>
Simon Glass96dedb02021-03-21 16:50:06 +13006#include <sysinfo.h>
Simon Glass401d1c42020-10-30 21:38:53 -06007#include <asm/global_data.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +09008#include <linux/libfdt.h>
Masahiro Yamada0365ffc2015-01-14 17:07:05 +09009#include <linux/compiler.h>
10
Simon Glass96dedb02021-03-21 16:50:06 +130011DECLARE_GLOBAL_DATA_PTR;
12
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090013int __weak checkboard(void)
14{
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090015 return 0;
16}
17
Simon Glass6f646d12023-11-12 19:58:28 -070018static const struct to_show {
19 const char *name;
20 enum sysinfo_id id;
21} to_show[] = {
22 { "Manufacturer", SYSINFO_ID_BOARD_MANUFACTURER},
23 { "Prior-stage version", SYSINFO_ID_PRIOR_STAGE_VERSION },
24 { "Prior-stage date", SYSINFO_ID_PRIOR_STAGE_DATE },
25 { /* sentinel */ }
26};
27
28static int try_sysinfo(void)
29{
30 struct udevice *dev;
31 char str[80];
32 int ret;
33
34 /* This might provide more detail */
35 ret = sysinfo_get(&dev);
36 if (ret)
37 return ret;
38
39 ret = sysinfo_detect(dev);
40 if (ret)
41 return ret;
42
43 ret = sysinfo_get_str(dev, SYSINFO_ID_BOARD_MODEL, sizeof(str), str);
44 if (ret)
45 return ret;
46 printf("Model: %s\n", str);
47
48 if (IS_ENABLED(CONFIG_SYSINFO_EXTRA)) {
49 const struct to_show *item;
50
51 for (item = to_show; item->id; item++) {
52 ret = sysinfo_get_str(dev, item->id, sizeof(str), str);
53 if (!ret)
54 printf("%s: %s\n", item->name, str);
55 }
56 }
57
58 return 0;
59}
60
Simon Glassd2a1b432023-11-12 19:58:27 -070061int show_board_info(void)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090062{
Simon Glass96dedb02021-03-21 16:50:06 +130063 if (IS_ENABLED(CONFIG_OF_CONTROL)) {
Simon Glass96dedb02021-03-21 16:50:06 +130064 int ret = -ENOSYS;
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090065
Simon Glass6f646d12023-11-12 19:58:28 -070066 if (IS_ENABLED(CONFIG_SYSINFO))
67 ret = try_sysinfo();
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090068
Simon Glass96dedb02021-03-21 16:50:06 +130069 /* Fail back to the main 'model' if available */
Simon Glass6f646d12023-11-12 19:58:28 -070070 if (ret) {
71 const char *model;
Simon Glass96dedb02021-03-21 16:50:06 +130072
Simon Glass6f646d12023-11-12 19:58:28 -070073 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
74 if (model)
75 printf("Model: %s\n", model);
76 }
Simon Glass96dedb02021-03-21 16:50:06 +130077 }
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090078
79 return checkboard();
80}