blob: 33c260b404e896c5e1ba86f4259f092dc808dafb [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
Simon Glass96dedb02021-03-21 16:50:06 +13003#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -06004#include <init.h>
Simon Glass96dedb02021-03-21 16:50:06 +13005#include <sysinfo.h>
Simon Glass401d1c42020-10-30 21:38:53 -06006#include <asm/global_data.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +09007#include <linux/libfdt.h>
Masahiro Yamada0365ffc2015-01-14 17:07:05 +09008#include <linux/compiler.h>
9
Simon Glass96dedb02021-03-21 16:50:06 +130010DECLARE_GLOBAL_DATA_PTR;
11
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090012int __weak checkboard(void)
13{
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090014 return 0;
15}
16
Simon Glass6f646d12023-11-12 19:58:28 -070017static 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
27static 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
Simon Glassd2a1b432023-11-12 19:58:27 -070060int show_board_info(void)
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090061{
Simon Glass96dedb02021-03-21 16:50:06 +130062 if (IS_ENABLED(CONFIG_OF_CONTROL)) {
Simon Glass96dedb02021-03-21 16:50:06 +130063 int ret = -ENOSYS;
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090064
Simon Glass6f646d12023-11-12 19:58:28 -070065 if (IS_ENABLED(CONFIG_SYSINFO))
66 ret = try_sysinfo();
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090067
Simon Glass96dedb02021-03-21 16:50:06 +130068 /* Fail back to the main 'model' if available */
Simon Glass6f646d12023-11-12 19:58:28 -070069 if (ret) {
70 const char *model;
Simon Glass96dedb02021-03-21 16:50:06 +130071
Simon Glass6f646d12023-11-12 19:58:28 -070072 model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
73 if (model)
74 printf("Model: %s\n", model);
75 }
Simon Glass96dedb02021-03-21 16:50:06 +130076 }
Masahiro Yamada0365ffc2015-01-14 17:07:05 +090077
78 return checkboard();
79}