blob: 3fb2f7296a912d8c95fb154c4f97545a87a9357b [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[] = {
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070031#if IS_ENABLED(CONFIG_MODULE_CPUINFO)
Jordan Crouse7249f792008-03-20 00:11:05 +000032 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000033#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070034#if IS_ENABLED(CONFIG_MODULE_PCI)
Jordan Crouse7249f792008-03-20 00:11:05 +000035 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000036#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070037#if IS_ENABLED(CONFIG_MODULE_NVRAM)
Jordan Crouse7ce26662008-05-06 22:00:55 +000038 &nvram_module,
39#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070040#if IS_ENABLED(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[] = {
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070046#if IS_ENABLED(CONFIG_MODULE_COREBOOT)
Jordan Crousede7fc552008-05-06 22:03:16 +000047 &coreboot_module,
48#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070049#if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000050 &multiboot_module,
51#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070052#if IS_ENABLED(CONFIG_MODULE_BOOTLOG)
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000053 &bootlog_module,
54#endif
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070055#if IS_ENABLED(CONFIG_MODULE_CBFS)
Uwe Hermann941c1fd2009-07-07 15:10:13 +000056 &cbfs_module,
Jordan Crouseaa6e3782008-05-07 20:43:15 +000057#endif
Antonello Dettori4b1668f2016-07-08 11:14:40 +020058#if IS_ENABLED(CONFIG_MODULE_TIMESTAMPS)
59 &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
Stefan Reinauer04fb7a82015-06-29 16:08:39 -0700117#if IS_ENABLED(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{
Uwe Hermann35845a22008-03-20 20:05:22 +0000135 int i, 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
Jordan Crousede7fc552008-05-06 22:03:16 +0000143 for (i = 0; i < ARRAY_SIZE(categories); i++) {
144 if (categories[i].count == 0)
145 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000146
Jordan Crousede7fc552008-05-06 22:03:16 +0000147 ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
148 }
149
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000150 mvwprintw(menuwin, 1, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000151
Stefan Reinauer04fb7a82015-06-29 16:08:39 -0700152#if IS_ENABLED(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{
201 if (key >= 'a' && key <= 'z') {
202 int index = key - 'a';
Jordan Crousede7fc552008-05-06 22:03:16 +0000203 if (index < cat->count) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000204 cat->cur = index;
Jordan Crousede7fc552008-05-06 22:03:16 +0000205 redraw_module(cat);
206 return;
207 }
208 }
209
210 if (cat->count && cat->modules[cat->cur]->handle) {
211 if (cat->modules[cat->cur]->handle(key))
212 redraw_module(cat);
213 }
214}
215
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100216static void print_no_modules_selected(void)
217{
218 int height = getmaxy(stdscr), i;
219
220 for (i = 0; i < ARRAY_SIZE(categories); i++)
221 if (categories[i].count > 0)
222 return;
223
224 color_set(2, NULL); // White on black
225 center(height / 2, "No modules selected");
226}
227
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100228static int first_nonempty_category(void)
229{
230 int i;
231
232 for (i = 0; i < ARRAY_SIZE(categories); i++)
233 if (categories[i].count > 0)
234 return i;
235 return 0;
236}
237
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000238static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000239{
240 int key;
241
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000242 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100243 print_no_modules_selected();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000244 refresh();
Jordan Crouse7249f792008-03-20 00:11:05 +0000245
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100246 curwin = first_nonempty_category();
Jordan Crouse7249f792008-03-20 00:11:05 +0000247 print_menu();
Jordan Crousede7fc552008-05-06 22:03:16 +0000248 print_submenu(&categories[curwin]);
249 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000250
Jordan Crouse19337862008-05-06 22:15:31 +0000251 halfdelay(10);
252
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000253 while (1) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800254 int ch = -1;
255
Stefan Reinauer04fb7a82015-06-29 16:08:39 -0700256#if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000257 print_time_and_date();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000258 wrefresh(menuwin);
Jordan Crouse19337862008-05-06 22:15:31 +0000259#endif
260
Jordan Crouse7249f792008-03-20 00:11:05 +0000261 key = getch();
262
263 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000264 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000265
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800266 if (key >= KEY_F(1) && key <= KEY_F(9))
267 ch = key - KEY_F(1);
268 if (key >= '1' && key <= '9')
269 ch = key - '1';
Jordan Crouse7249f792008-03-20 00:11:05 +0000270
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800271 if (ch >= 0 && ch <= ARRAY_SIZE(categories)) {
272 if (ch == ARRAY_SIZE(categories))
Jordan Crouse7249f792008-03-20 00:11:05 +0000273 continue;
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800274 if (categories[ch].count == 0)
275 continue;
276
277 curwin = ch;
278 print_submenu(&categories[curwin]);
279 redraw_module(&categories[curwin]);
280 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000281 }
282
Uwe Hermann29413c72008-05-21 13:49:03 +0000283 if (key == KEY_ESC)
Jordan Crouse98cc0562008-05-20 20:16:34 +0000284 return;
Jordan Crousede7fc552008-05-06 22:03:16 +0000285
286 handle_category_key(&categories[curwin], key);
Jordan Crouse7249f792008-03-20 00:11:05 +0000287 }
288}
289
290int main(void)
291{
292 int i, j;
293
Stefan Reinauer04fb7a82015-06-29 16:08:39 -0700294#if IS_ENABLED(CONFIG_LP_USB)
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700295 usb_initialize();
296#endif
297
Jordan Crouse7249f792008-03-20 00:11:05 +0000298 initscr();
299
Dave Frodin1b0c3522012-12-05 17:26:03 -0700300 start_color();
Jordan Crouse7249f792008-03-20 00:11:05 +0000301 init_pair(1, COLOR_WHITE, COLOR_GREEN);
Dave Frodin1b0c3522012-12-05 17:26:03 -0700302 init_pair(2, COLOR_WHITE, COLOR_BLACK);
303 init_pair(3, COLOR_BLACK, COLOR_WHITE);
Jordan Crouse7249f792008-03-20 00:11:05 +0000304
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000305 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
306 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000307
308 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
309 wattrset(modwin, COLOR_PAIR(2));
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000310 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
Jordan Crouse7249f792008-03-20 00:11:05 +0000311
Ulf Jordan22d5ddc2008-09-24 14:21:02 +0000312 werase(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000313
Jordan Crousede7fc552008-05-06 22:03:16 +0000314 for (i = 0; i < ARRAY_SIZE(categories); i++) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000315 for (j = 0; j < categories[i].count; j++)
Jordan Crousede7fc552008-05-06 22:03:16 +0000316 categories[i].modules[j]->init();
Jordan Crousede7fc552008-05-06 22:03:16 +0000317 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000318
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700319 noecho(); /* don't let curses echo keyboard chars */
320 keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */
Yasha Cherikovsky619fc952015-11-14 19:16:58 +0200321 curs_set(0); /* Hide blinking cursor */
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700322
Jordan Crouse7249f792008-03-20 00:11:05 +0000323 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000324
Maxime de Roucy81900782015-09-27 15:53:40 +0200325 /* reboot */
326 outb(0x6, 0xcf9);
327 halt();
Uwe Hermann35845a22008-03-20 20:05:22 +0000328 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000329}
Jordan Crouse50838112008-05-27 20:07:47 +0000330
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000331PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
332PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
333PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);