Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 2 | |
Tom Rini | d678a59 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 3 | #include <common.h> |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 4 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 5 | #include <init.h> |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 6 | #include <sysinfo.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 7 | #include <asm/global_data.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 8 | #include <linux/libfdt.h> |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 9 | #include <linux/compiler.h> |
| 10 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 13 | int __weak checkboard(void) |
| 14 | { |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 15 | return 0; |
| 16 | } |
| 17 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 18 | static 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 | |
| 28 | static 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 Glass | d2a1b43 | 2023-11-12 19:58:27 -0700 | [diff] [blame] | 61 | int show_board_info(void) |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 62 | { |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 63 | if (IS_ENABLED(CONFIG_OF_CONTROL)) { |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 64 | int ret = -ENOSYS; |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 65 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 66 | if (IS_ENABLED(CONFIG_SYSINFO)) |
| 67 | ret = try_sysinfo(); |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 68 | |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 69 | /* Fail back to the main 'model' if available */ |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 70 | if (ret) { |
| 71 | const char *model; |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 72 | |
Simon Glass | 6f646d1 | 2023-11-12 19:58:28 -0700 | [diff] [blame] | 73 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 74 | if (model) |
| 75 | printf("Model: %s\n", model); |
| 76 | } |
Simon Glass | 96dedb0 | 2021-03-21 16:50:06 +1300 | [diff] [blame] | 77 | } |
Masahiro Yamada | 0365ffc | 2015-01-14 17:07:05 +0900 | [diff] [blame] | 78 | |
| 79 | return checkboard(); |
| 80 | } |