blob: b357f97988b31b6e3be25f04e38a8182f0692086 [file] [log] [blame]
Jacob Garber07201d72020-09-08 12:25:44 -06001/* SPDX-License-Identifier: GPL-2.0-only */
Jordan Crouse7249f792008-03-20 00:11:05 +00002
3#include "coreinfo.h"
4
Uwe Hermann29413c72008-05-21 13:49:03 +00005#define KEY_ESC 27
6
Jordan Crouse7249f792008-03-20 00:11:05 +00007extern struct coreinfo_module cpuinfo_module;
8extern struct coreinfo_module pci_module;
9extern struct coreinfo_module coreboot_module;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000010extern struct coreinfo_module multiboot_module;
Uwe Hermannab5b3e02008-03-31 20:30:18 +000011extern struct coreinfo_module nvram_module;
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000012extern struct coreinfo_module bootlog_module;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000013extern struct coreinfo_module ramdump_module;
Uwe Hermann941c1fd2009-07-07 15:10:13 +000014extern struct coreinfo_module cbfs_module;
Antonello Dettori4b1668f2016-07-08 11:14:40 +020015extern struct coreinfo_module timestamps_module;
Jordan Crouse7249f792008-03-20 00:11:05 +000016
Jordan Crousede7fc552008-05-06 22:03:16 +000017struct coreinfo_module *system_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080018#if CONFIG(MODULE_CPUINFO)
Jordan Crouse7249f792008-03-20 00:11:05 +000019 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000020#endif
Julius Wernereab2a292019-03-05 16:55:15 -080021#if CONFIG(MODULE_PCI)
Jordan Crouse7249f792008-03-20 00:11:05 +000022 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000023#endif
Julius Wernereab2a292019-03-05 16:55:15 -080024#if CONFIG(MODULE_NVRAM)
Jordan Crouse7ce26662008-05-06 22:00:55 +000025 &nvram_module,
26#endif
Julius Wernereab2a292019-03-05 16:55:15 -080027#if CONFIG(MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +000028 &ramdump_module,
29#endif
Jordan Crousede7fc552008-05-06 22:03:16 +000030};
31
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000032struct coreinfo_module *firmware_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080033#if CONFIG(MODULE_COREBOOT)
Jordan Crousede7fc552008-05-06 22:03:16 +000034 &coreboot_module,
35#endif
Julius Wernereab2a292019-03-05 16:55:15 -080036#if CONFIG(MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000037 &multiboot_module,
38#endif
Julius Wernereab2a292019-03-05 16:55:15 -080039#if CONFIG(MODULE_BOOTLOG)
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000040 &bootlog_module,
41#endif
Julius Wernereab2a292019-03-05 16:55:15 -080042#if CONFIG(MODULE_CBFS)
Uwe Hermann941c1fd2009-07-07 15:10:13 +000043 &cbfs_module,
Jordan Crouseaa6e3782008-05-07 20:43:15 +000044#endif
Julius Wernereab2a292019-03-05 16:55:15 -080045#if CONFIG(MODULE_TIMESTAMPS)
Antonello Dettori4b1668f2016-07-08 11:14:40 +020046 &timestamps_module,
47#endif
Jordan Crouse7249f792008-03-20 00:11:05 +000048};
49
Jordan Crousede7fc552008-05-06 22:03:16 +000050struct coreinfo_cat {
51 char name[15];
52 int cur;
53 int count;
54 struct coreinfo_module **modules;
55} categories[] = {
56 {
57 .name = "System",
58 .modules = system_modules,
59 .count = ARRAY_SIZE(system_modules),
60 },
61 {
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000062 .name = "Firmware",
63 .modules = firmware_modules,
64 .count = ARRAY_SIZE(firmware_modules),
Jordan Crousede7fc552008-05-06 22:03:16 +000065 }
66};
67
Uwe Hermann695cff32008-08-07 14:35:39 +000068static WINDOW *modwin, *menuwin;
Jordan Crouse7249f792008-03-20 00:11:05 +000069static int curwin;
70
71void print_module_title(WINDOW *win, const char *title)
72{
73 int i;
74
75 wattrset(win, COLOR_PAIR(2));
76 mvwprintw(win, 0, 1, title);
77
78 wmove(win, 1, 1);
Uwe Hermann3a406fe2008-03-20 01:11:28 +000079 for (i = 0; i < 78; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000080 waddch(win, ACS_HLINE);
Jordan Crouse7249f792008-03-20 00:11:05 +000081}
82
Jordan Crousede7fc552008-05-06 22:03:16 +000083static void print_submenu(struct coreinfo_cat *cat)
84{
85 int i, j;
86 char menu[80];
87 char *ptr = menu;
88
Jordan Crouse9b1c7c12008-05-20 20:16:03 +000089 wmove(menuwin, 0, 0);
Jordan Crousede7fc552008-05-06 22:03:16 +000090
91 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +000092 waddch(menuwin, ' ');
Jordan Crousede7fc552008-05-06 22:03:16 +000093
94 if (!cat->count)
95 return;
96
97 for (i = 0; i < cat->count; i++)
Uwe Hermann695cff32008-08-07 14:35:39 +000098 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i,
99 cat->modules[i]->name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000100
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000101 mvwprintw(menuwin, 0, 0, menu);
Jordan Crousede7fc552008-05-06 22:03:16 +0000102}
103
Julius Wernereab2a292019-03-05 16:55:15 -0800104#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000105static void print_time_and_date(void)
106{
107 struct tm tm;
108
Uwe Hermann941aaee2008-07-18 14:08:18 +0000109 while (nvram_updating())
Jordan Crouse19337862008-05-06 22:15:31 +0000110 mdelay(10);
111
112 rtc_read_clock(&tm);
113
Jonathan Neuschäfer2bf7a2c2016-04-04 19:44:30 +0200114 mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
Yasha Cherikovskyae16c402015-11-14 19:16:58 +0200115 tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour,
Uwe Hermann941aaee2008-07-18 14:08:18 +0000116 tm.tm_min, tm.tm_sec);
Jordan Crouse19337862008-05-06 22:15:31 +0000117}
118#endif
119
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000120static void print_menu(void)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000121{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600122 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000123 char menu[80];
124 char *ptr = menu;
Jordan Crouse7249f792008-03-20 00:11:05 +0000125
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000126 wmove(menuwin, 1, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000127 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000128 waddch(menuwin, ' ');
Jordan Crouse7249f792008-03-20 00:11:05 +0000129
Jacob Garbera711e9c2019-06-28 10:58:56 -0600130 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Jordan Crousede7fc552008-05-06 22:03:16 +0000131 if (categories[i].count == 0)
132 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000133
Jacob Garbera711e9c2019-06-28 10:58:56 -0600134 ptr += sprintf(ptr, "F%zu: %s ", i + 1, categories[i].name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000135 }
136
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000137 mvwprintw(menuwin, 1, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000138
Julius Wernereab2a292019-03-05 16:55:15 -0800139#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000140 print_time_and_date();
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000141#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000142}
143
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000144static void center(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000145{
Uwe Hermann695cff32008-08-07 14:35:39 +0000146 int j, len = strlen(str);
Jordan Crouse7249f792008-03-20 00:11:05 +0000147
148 wmove(stdscr, row, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000149 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000150 waddch(stdscr, ' ');
151
152 mvprintw(row, (SCREEN_X - len) / 2, str);
153}
154
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000155/* FIXME: Currently unused. */
156#if 0
157static void header(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000158{
159 char buf[SCREEN_X];
160 char *ptr = buf;
161 int i;
162 int len = strlen(str) + 4;
163
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000164 for (i = 0; i < (SCREEN_X - len) / 2; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000165 ptr += sprintf(ptr, "=");
166
167 ptr += sprintf(ptr, "[ %s ]", str);
168
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000169 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000170 ptr += sprintf(ptr, "=");
171
172 mvprintw(row, 0, buf);
173}
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000174#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000175
Jordan Crousede7fc552008-05-06 22:03:16 +0000176static void redraw_module(struct coreinfo_cat *cat)
Jordan Crouse7249f792008-03-20 00:11:05 +0000177{
Jordan Crousede7fc552008-05-06 22:03:16 +0000178 if (cat->count == 0)
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000179 return;
180
Jordan Crouse7249f792008-03-20 00:11:05 +0000181 wclear(modwin);
Jordan Crousede7fc552008-05-06 22:03:16 +0000182 cat->modules[cat->cur]->redraw(modwin);
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000183 wrefresh(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000184}
185
Jordan Crousede7fc552008-05-06 22:03:16 +0000186static void handle_category_key(struct coreinfo_cat *cat, int key)
187{
Himanshu Sahdevd3d38c92019-09-23 15:08:18 +0530188 if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) {
189 int index;
190 if (key >= 'A' && key <= 'Z') {
191 index = key - 'A';
192 } else {
193 index = key - 'a';
194 }
Jordan Crousede7fc552008-05-06 22:03:16 +0000195 if (index < cat->count) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000196 cat->cur = index;
Jordan Crousede7fc552008-05-06 22:03:16 +0000197 redraw_module(cat);
198 return;
199 }
200 }
201
202 if (cat->count && cat->modules[cat->cur]->handle) {
203 if (cat->modules[cat->cur]->handle(key))
204 redraw_module(cat);
205 }
206}
207
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100208static void print_no_modules_selected(void)
209{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600210 int height = getmaxy(stdscr);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100211
Jacob Garbera711e9c2019-06-28 10:58:56 -0600212 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100213 if (categories[i].count > 0)
214 return;
215
216 color_set(2, NULL); // White on black
217 center(height / 2, "No modules selected");
218}
219
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100220static int first_nonempty_category(void)
221{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600222 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100223 if (categories[i].count > 0)
224 return i;
225 return 0;
226}
227
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000228static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000229{
230 int key;
231
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000232 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100233 print_no_modules_selected();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000234 refresh();
Jordan Crouse7249f792008-03-20 00:11:05 +0000235
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100236 curwin = first_nonempty_category();
Jordan Crouse7249f792008-03-20 00:11:05 +0000237 print_menu();
Jordan Crousede7fc552008-05-06 22:03:16 +0000238 print_submenu(&categories[curwin]);
239 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000240
Jordan Crouse19337862008-05-06 22:15:31 +0000241 halfdelay(10);
242
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000243 while (1) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800244 int ch = -1;
245
Julius Wernereab2a292019-03-05 16:55:15 -0800246#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000247 print_time_and_date();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000248 wrefresh(menuwin);
Jordan Crouse19337862008-05-06 22:15:31 +0000249#endif
250
Jordan Crouse7249f792008-03-20 00:11:05 +0000251 key = getch();
252
253 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000254 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000255
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800256 if (key >= KEY_F(1) && key <= KEY_F(9))
257 ch = key - KEY_F(1);
258 if (key >= '1' && key <= '9')
259 ch = key - '1';
Jordan Crouse7249f792008-03-20 00:11:05 +0000260
Jacob Garbera711e9c2019-06-28 10:58:56 -0600261 if (ch >= 0 && (unsigned int)ch <= ARRAY_SIZE(categories)) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800262 if (ch == ARRAY_SIZE(categories))
Jordan Crouse7249f792008-03-20 00:11:05 +0000263 continue;
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800264 if (categories[ch].count == 0)
265 continue;
266
267 curwin = ch;
268 print_submenu(&categories[curwin]);
269 redraw_module(&categories[curwin]);
270 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000271 }
272
Uwe Hermann29413c72008-05-21 13:49:03 +0000273 if (key == KEY_ESC)
Jordan Crouse98cc0562008-05-20 20:16:34 +0000274 return;
Jordan Crousede7fc552008-05-06 22:03:16 +0000275
276 handle_category_key(&categories[curwin], key);
Jordan Crouse7249f792008-03-20 00:11:05 +0000277 }
278}
279
Jacob Garberbd624722019-10-02 14:44:28 -0600280int main(int argc, char **argv)
Jordan Crouse7249f792008-03-20 00:11:05 +0000281{
Jacob Garberbd624722019-10-02 14:44:28 -0600282 (void)argc;
283 (void)argv;
284
Jacob Garbera711e9c2019-06-28 10:58:56 -0600285 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000286
Julius Wernereab2a292019-03-05 16:55:15 -0800287 if (CONFIG(LP_USB))
Nicola Corna71693ba2017-03-14 10:26:58 +0100288 usb_initialize();
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700289
Jordan Crouse7249f792008-03-20 00:11:05 +0000290 initscr();
291
Dave Frodin1b0c3522012-12-05 17:26:03 -0700292 start_color();
Jordan Crouse7249f792008-03-20 00:11:05 +0000293 init_pair(1, COLOR_WHITE, COLOR_GREEN);
Dave Frodin1b0c3522012-12-05 17:26:03 -0700294 init_pair(2, COLOR_WHITE, COLOR_BLACK);
295 init_pair(3, COLOR_BLACK, COLOR_WHITE);
Jordan Crouse7249f792008-03-20 00:11:05 +0000296
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000297 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
298 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000299
300 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
301 wattrset(modwin, COLOR_PAIR(2));
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000302 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
Jordan Crouse7249f792008-03-20 00:11:05 +0000303
Ulf Jordan22d5ddc2008-09-24 14:21:02 +0000304 werase(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000305
Jacob Garbera711e9c2019-06-28 10:58:56 -0600306 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000307 for (j = 0; j < categories[i].count; j++)
Jordan Crousede7fc552008-05-06 22:03:16 +0000308 categories[i].modules[j]->init();
Jordan Crousede7fc552008-05-06 22:03:16 +0000309 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000310
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700311 noecho(); /* don't let curses echo keyboard chars */
312 keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */
Yasha Cherikovsky619fc952015-11-14 19:16:58 +0200313 curs_set(0); /* Hide blinking cursor */
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700314
Jordan Crouse7249f792008-03-20 00:11:05 +0000315 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000316
Maxime de Roucy81900782015-09-27 15:53:40 +0200317 /* reboot */
318 outb(0x6, 0xcf9);
319 halt();
Uwe Hermann35845a22008-03-20 20:05:22 +0000320 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000321}
Jordan Crouse50838112008-05-27 20:07:47 +0000322
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000323PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
324PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
325PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);