blob: b1017f079cbd1507e8782e30225994712943b244 [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001/*
2 * This file is part of the coreinfo project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Jordan Crouse7249f792008-03-20 00:11:05 +000014 */
15
16#include "coreinfo.h"
17
Uwe Hermann29413c72008-05-21 13:49:03 +000018#define KEY_ESC 27
19
Jordan Crouse7249f792008-03-20 00:11:05 +000020extern struct coreinfo_module cpuinfo_module;
21extern struct coreinfo_module pci_module;
22extern struct coreinfo_module coreboot_module;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000023extern struct coreinfo_module multiboot_module;
Uwe Hermannab5b3e02008-03-31 20:30:18 +000024extern struct coreinfo_module nvram_module;
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000025extern struct coreinfo_module bootlog_module;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000026extern struct coreinfo_module ramdump_module;
Uwe Hermann941c1fd2009-07-07 15:10:13 +000027extern struct coreinfo_module cbfs_module;
Antonello Dettori4b1668f2016-07-08 11:14:40 +020028extern struct coreinfo_module timestamps_module;
Jordan Crouse7249f792008-03-20 00:11:05 +000029
Jordan Crousede7fc552008-05-06 22:03:16 +000030struct coreinfo_module *system_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080031#if CONFIG(MODULE_CPUINFO)
Jordan Crouse7249f792008-03-20 00:11:05 +000032 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000033#endif
Julius Wernereab2a292019-03-05 16:55:15 -080034#if CONFIG(MODULE_PCI)
Jordan Crouse7249f792008-03-20 00:11:05 +000035 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000036#endif
Julius Wernereab2a292019-03-05 16:55:15 -080037#if CONFIG(MODULE_NVRAM)
Jordan Crouse7ce26662008-05-06 22:00:55 +000038 &nvram_module,
39#endif
Julius Wernereab2a292019-03-05 16:55:15 -080040#if CONFIG(MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +000041 &ramdump_module,
42#endif
Jordan Crousede7fc552008-05-06 22:03:16 +000043};
44
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000045struct coreinfo_module *firmware_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080046#if CONFIG(MODULE_COREBOOT)
Jordan Crousede7fc552008-05-06 22:03:16 +000047 &coreboot_module,
48#endif
Julius Wernereab2a292019-03-05 16:55:15 -080049#if CONFIG(MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000050 &multiboot_module,
51#endif
Julius Wernereab2a292019-03-05 16:55:15 -080052#if CONFIG(MODULE_BOOTLOG)
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000053 &bootlog_module,
54#endif
Julius Wernereab2a292019-03-05 16:55:15 -080055#if CONFIG(MODULE_CBFS)
Uwe Hermann941c1fd2009-07-07 15:10:13 +000056 &cbfs_module,
Jordan Crouseaa6e3782008-05-07 20:43:15 +000057#endif
Julius Wernereab2a292019-03-05 16:55:15 -080058#if CONFIG(MODULE_TIMESTAMPS)
Antonello Dettori4b1668f2016-07-08 11:14:40 +020059 &timestamps_module,
60#endif
Jordan Crouse7249f792008-03-20 00:11:05 +000061};
62
Jordan Crousede7fc552008-05-06 22:03:16 +000063struct coreinfo_cat {
64 char name[15];
65 int cur;
66 int count;
67 struct coreinfo_module **modules;
68} categories[] = {
69 {
70 .name = "System",
71 .modules = system_modules,
72 .count = ARRAY_SIZE(system_modules),
73 },
74 {
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000075 .name = "Firmware",
76 .modules = firmware_modules,
77 .count = ARRAY_SIZE(firmware_modules),
Jordan Crousede7fc552008-05-06 22:03:16 +000078 }
79};
80
Uwe Hermann695cff32008-08-07 14:35:39 +000081static WINDOW *modwin, *menuwin;
Jordan Crouse7249f792008-03-20 00:11:05 +000082static int curwin;
83
84void print_module_title(WINDOW *win, const char *title)
85{
86 int i;
87
88 wattrset(win, COLOR_PAIR(2));
89 mvwprintw(win, 0, 1, title);
90
91 wmove(win, 1, 1);
Uwe Hermann3a406fe2008-03-20 01:11:28 +000092 for (i = 0; i < 78; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000093 waddch(win, ACS_HLINE);
Jordan Crouse7249f792008-03-20 00:11:05 +000094}
95
Jordan Crousede7fc552008-05-06 22:03:16 +000096static void print_submenu(struct coreinfo_cat *cat)
97{
98 int i, j;
99 char menu[80];
100 char *ptr = menu;
101
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000102 wmove(menuwin, 0, 0);
Jordan Crousede7fc552008-05-06 22:03:16 +0000103
104 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000105 waddch(menuwin, ' ');
Jordan Crousede7fc552008-05-06 22:03:16 +0000106
107 if (!cat->count)
108 return;
109
110 for (i = 0; i < cat->count; i++)
Uwe Hermann695cff32008-08-07 14:35:39 +0000111 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i,
112 cat->modules[i]->name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000113
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000114 mvwprintw(menuwin, 0, 0, menu);
Jordan Crousede7fc552008-05-06 22:03:16 +0000115}
116
Julius Wernereab2a292019-03-05 16:55:15 -0800117#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000118static void print_time_and_date(void)
119{
120 struct tm tm;
121
Uwe Hermann941aaee2008-07-18 14:08:18 +0000122 while (nvram_updating())
Jordan Crouse19337862008-05-06 22:15:31 +0000123 mdelay(10);
124
125 rtc_read_clock(&tm);
126
Jonathan Neuschäfer2bf7a2c2016-04-04 19:44:30 +0200127 mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
Yasha Cherikovskyae16c402015-11-14 19:16:58 +0200128 tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour,
Uwe Hermann941aaee2008-07-18 14:08:18 +0000129 tm.tm_min, tm.tm_sec);
Jordan Crouse19337862008-05-06 22:15:31 +0000130}
131#endif
132
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000133static void print_menu(void)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000134{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600135 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000136 char menu[80];
137 char *ptr = menu;
Jordan Crouse7249f792008-03-20 00:11:05 +0000138
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000139 wmove(menuwin, 1, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000140 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000141 waddch(menuwin, ' ');
Jordan Crouse7249f792008-03-20 00:11:05 +0000142
Jacob Garbera711e9c2019-06-28 10:58:56 -0600143 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Jordan Crousede7fc552008-05-06 22:03:16 +0000144 if (categories[i].count == 0)
145 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000146
Jacob Garbera711e9c2019-06-28 10:58:56 -0600147 ptr += sprintf(ptr, "F%zu: %s ", i + 1, categories[i].name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000148 }
149
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000150 mvwprintw(menuwin, 1, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000151
Julius Wernereab2a292019-03-05 16:55:15 -0800152#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000153 print_time_and_date();
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000154#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000155}
156
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000157static void center(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000158{
Uwe Hermann695cff32008-08-07 14:35:39 +0000159 int j, len = strlen(str);
Jordan Crouse7249f792008-03-20 00:11:05 +0000160
161 wmove(stdscr, row, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000162 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000163 waddch(stdscr, ' ');
164
165 mvprintw(row, (SCREEN_X - len) / 2, str);
166}
167
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000168/* FIXME: Currently unused. */
169#if 0
170static void header(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000171{
172 char buf[SCREEN_X];
173 char *ptr = buf;
174 int i;
175 int len = strlen(str) + 4;
176
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000177 for (i = 0; i < (SCREEN_X - len) / 2; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000178 ptr += sprintf(ptr, "=");
179
180 ptr += sprintf(ptr, "[ %s ]", str);
181
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000182 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000183 ptr += sprintf(ptr, "=");
184
185 mvprintw(row, 0, buf);
186}
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000187#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000188
Jordan Crousede7fc552008-05-06 22:03:16 +0000189static void redraw_module(struct coreinfo_cat *cat)
Jordan Crouse7249f792008-03-20 00:11:05 +0000190{
Jordan Crousede7fc552008-05-06 22:03:16 +0000191 if (cat->count == 0)
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000192 return;
193
Jordan Crouse7249f792008-03-20 00:11:05 +0000194 wclear(modwin);
Jordan Crousede7fc552008-05-06 22:03:16 +0000195 cat->modules[cat->cur]->redraw(modwin);
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000196 wrefresh(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000197}
198
Jordan Crousede7fc552008-05-06 22:03:16 +0000199static void handle_category_key(struct coreinfo_cat *cat, int key)
200{
Himanshu Sahdevd3d38c92019-09-23 15:08:18 +0530201 if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) {
202 int index;
203 if (key >= 'A' && key <= 'Z') {
204 index = key - 'A';
205 } else {
206 index = key - 'a';
207 }
Jordan Crousede7fc552008-05-06 22:03:16 +0000208 if (index < cat->count) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000209 cat->cur = index;
Jordan Crousede7fc552008-05-06 22:03:16 +0000210 redraw_module(cat);
211 return;
212 }
213 }
214
215 if (cat->count && cat->modules[cat->cur]->handle) {
216 if (cat->modules[cat->cur]->handle(key))
217 redraw_module(cat);
218 }
219}
220
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100221static void print_no_modules_selected(void)
222{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600223 int height = getmaxy(stdscr);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100224
Jacob Garbera711e9c2019-06-28 10:58:56 -0600225 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100226 if (categories[i].count > 0)
227 return;
228
229 color_set(2, NULL); // White on black
230 center(height / 2, "No modules selected");
231}
232
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100233static int first_nonempty_category(void)
234{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600235 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100236 if (categories[i].count > 0)
237 return i;
238 return 0;
239}
240
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000241static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000242{
243 int key;
244
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000245 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100246 print_no_modules_selected();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000247 refresh();
Jordan Crouse7249f792008-03-20 00:11:05 +0000248
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100249 curwin = first_nonempty_category();
Jordan Crouse7249f792008-03-20 00:11:05 +0000250 print_menu();
Jordan Crousede7fc552008-05-06 22:03:16 +0000251 print_submenu(&categories[curwin]);
252 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000253
Jordan Crouse19337862008-05-06 22:15:31 +0000254 halfdelay(10);
255
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000256 while (1) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800257 int ch = -1;
258
Julius Wernereab2a292019-03-05 16:55:15 -0800259#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000260 print_time_and_date();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000261 wrefresh(menuwin);
Jordan Crouse19337862008-05-06 22:15:31 +0000262#endif
263
Jordan Crouse7249f792008-03-20 00:11:05 +0000264 key = getch();
265
266 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000267 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000268
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800269 if (key >= KEY_F(1) && key <= KEY_F(9))
270 ch = key - KEY_F(1);
271 if (key >= '1' && key <= '9')
272 ch = key - '1';
Jordan Crouse7249f792008-03-20 00:11:05 +0000273
Jacob Garbera711e9c2019-06-28 10:58:56 -0600274 if (ch >= 0 && (unsigned int)ch <= ARRAY_SIZE(categories)) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800275 if (ch == ARRAY_SIZE(categories))
Jordan Crouse7249f792008-03-20 00:11:05 +0000276 continue;
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800277 if (categories[ch].count == 0)
278 continue;
279
280 curwin = ch;
281 print_submenu(&categories[curwin]);
282 redraw_module(&categories[curwin]);
283 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000284 }
285
Uwe Hermann29413c72008-05-21 13:49:03 +0000286 if (key == KEY_ESC)
Jordan Crouse98cc0562008-05-20 20:16:34 +0000287 return;
Jordan Crousede7fc552008-05-06 22:03:16 +0000288
289 handle_category_key(&categories[curwin], key);
Jordan Crouse7249f792008-03-20 00:11:05 +0000290 }
291}
292
Jacob Garberbd624722019-10-02 14:44:28 -0600293int main(int argc, char **argv)
Jordan Crouse7249f792008-03-20 00:11:05 +0000294{
Jacob Garberbd624722019-10-02 14:44:28 -0600295 (void)argc;
296 (void)argv;
297
Jacob Garbera711e9c2019-06-28 10:58:56 -0600298 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000299
Julius Wernereab2a292019-03-05 16:55:15 -0800300 if (CONFIG(LP_USB))
Nicola Corna71693ba2017-03-14 10:26:58 +0100301 usb_initialize();
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700302
Jordan Crouse7249f792008-03-20 00:11:05 +0000303 initscr();
304
Dave Frodin1b0c3522012-12-05 17:26:03 -0700305 start_color();
Jordan Crouse7249f792008-03-20 00:11:05 +0000306 init_pair(1, COLOR_WHITE, COLOR_GREEN);
Dave Frodin1b0c3522012-12-05 17:26:03 -0700307 init_pair(2, COLOR_WHITE, COLOR_BLACK);
308 init_pair(3, COLOR_BLACK, COLOR_WHITE);
Jordan Crouse7249f792008-03-20 00:11:05 +0000309
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000310 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
311 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000312
313 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
314 wattrset(modwin, COLOR_PAIR(2));
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000315 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
Jordan Crouse7249f792008-03-20 00:11:05 +0000316
Ulf Jordan22d5ddc2008-09-24 14:21:02 +0000317 werase(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000318
Jacob Garbera711e9c2019-06-28 10:58:56 -0600319 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000320 for (j = 0; j < categories[i].count; j++)
Jordan Crousede7fc552008-05-06 22:03:16 +0000321 categories[i].modules[j]->init();
Jordan Crousede7fc552008-05-06 22:03:16 +0000322 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000323
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700324 noecho(); /* don't let curses echo keyboard chars */
325 keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */
Yasha Cherikovsky619fc952015-11-14 19:16:58 +0200326 curs_set(0); /* Hide blinking cursor */
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700327
Jordan Crouse7249f792008-03-20 00:11:05 +0000328 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000329
Maxime de Roucy81900782015-09-27 15:53:40 +0200330 /* reboot */
331 outb(0x6, 0xcf9);
332 halt();
Uwe Hermann35845a22008-03-20 20:05:22 +0000333 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000334}
Jordan Crouse50838112008-05-27 20:07:47 +0000335
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000336PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
337PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
338PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);