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
11DECLARE_GLOBAL_DATA_PTR;
12
13int __weak checkboard(void)
14{
15	return 0;
16}
17
18static 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
61int show_board_info(void)
62{
63	if (IS_ENABLED(CONFIG_OF_CONTROL)) {
64		int ret = -ENOSYS;
65
66		if (IS_ENABLED(CONFIG_SYSINFO))
67			ret = try_sysinfo();
68
69		/* Fail back to the main 'model' if available */
70		if (ret) {
71			const char *model;
72
73			model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
74			if (model)
75				printf("Model: %s\n", model);
76		}
77	}
78
79	return checkboard();
80}
81