Jacob Garber | 07201d7 | 2020-09-08 12:25:44 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 2 | |
| 3 | #include "coreinfo.h" |
| 4 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 5 | #define KEY_ESC 27 |
| 6 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 7 | extern struct coreinfo_module cpuinfo_module; |
| 8 | extern struct coreinfo_module pci_module; |
| 9 | extern struct coreinfo_module coreboot_module; |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 10 | extern struct coreinfo_module multiboot_module; |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 11 | extern struct coreinfo_module nvram_module; |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 12 | extern struct coreinfo_module bootlog_module; |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 13 | extern struct coreinfo_module ramdump_module; |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 14 | extern struct coreinfo_module cbfs_module; |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 15 | extern struct coreinfo_module timestamps_module; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 16 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 17 | struct coreinfo_module *system_modules[] = { |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 18 | #if CONFIG(MODULE_CPUINFO) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 19 | &cpuinfo_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 20 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 21 | #if CONFIG(MODULE_PCI) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 22 | &pci_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 23 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 24 | #if CONFIG(MODULE_NVRAM) |
Jordan Crouse | 7ce2666 | 2008-05-06 22:00:55 +0000 | [diff] [blame] | 25 | &nvram_module, |
| 26 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 27 | #if CONFIG(MODULE_RAMDUMP) |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 28 | &ramdump_module, |
| 29 | #endif |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 32 | struct coreinfo_module *firmware_modules[] = { |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 33 | #if CONFIG(MODULE_COREBOOT) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 34 | &coreboot_module, |
| 35 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 36 | #if CONFIG(MODULE_MULTIBOOT) |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 37 | &multiboot_module, |
| 38 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 39 | #if CONFIG(MODULE_BOOTLOG) |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 40 | &bootlog_module, |
| 41 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 42 | #if CONFIG(MODULE_CBFS) |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 43 | &cbfs_module, |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 44 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 45 | #if CONFIG(MODULE_TIMESTAMPS) |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 46 | ×tamps_module, |
| 47 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 50 | struct 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 Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 62 | .name = "Firmware", |
| 63 | .modules = firmware_modules, |
| 64 | .count = ARRAY_SIZE(firmware_modules), |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 65 | } |
| 66 | }; |
| 67 | |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 68 | static WINDOW *modwin, *menuwin; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 69 | static int curwin; |
| 70 | |
| 71 | void 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 Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 79 | for (i = 0; i < 78; i++) |
Ulf Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 80 | waddch(win, ACS_HLINE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 83 | static void print_submenu(struct coreinfo_cat *cat) |
| 84 | { |
| 85 | int i, j; |
| 86 | char menu[80]; |
| 87 | char *ptr = menu; |
| 88 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 89 | wmove(menuwin, 0, 0); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 90 | |
| 91 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 92 | waddch(menuwin, ' '); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 93 | |
| 94 | if (!cat->count) |
| 95 | return; |
| 96 | |
| 97 | for (i = 0; i < cat->count; i++) |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 98 | ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, |
| 99 | cat->modules[i]->name); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 100 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 101 | mvwprintw(menuwin, 0, 0, menu); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 104 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 105 | static void print_time_and_date(void) |
| 106 | { |
| 107 | struct tm tm; |
| 108 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 109 | while (nvram_updating()) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 110 | mdelay(10); |
| 111 | |
| 112 | rtc_read_clock(&tm); |
| 113 | |
Jonathan Neuschäfer | 2bf7a2c | 2016-04-04 19:44:30 +0200 | [diff] [blame] | 114 | mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d", |
Yasha Cherikovsky | ae16c40 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 115 | tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour, |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 116 | tm.tm_min, tm.tm_sec); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 117 | } |
| 118 | #endif |
| 119 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 120 | static void print_menu(void) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 121 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 122 | int j; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 123 | char menu[80]; |
| 124 | char *ptr = menu; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 125 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 126 | wmove(menuwin, 1, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 127 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 128 | waddch(menuwin, ' '); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 129 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 130 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) { |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 131 | if (categories[i].count == 0) |
| 132 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 133 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 134 | ptr += sprintf(ptr, "F%zu: %s ", i + 1, categories[i].name); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 137 | mvwprintw(menuwin, 1, 0, menu); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 138 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 139 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 140 | print_time_and_date(); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 141 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 144 | static void center(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 145 | { |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 146 | int j, len = strlen(str); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 147 | |
| 148 | wmove(stdscr, row, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 149 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 150 | waddch(stdscr, ' '); |
| 151 | |
| 152 | mvprintw(row, (SCREEN_X - len) / 2, str); |
| 153 | } |
| 154 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 155 | /* FIXME: Currently unused. */ |
| 156 | #if 0 |
| 157 | static void header(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 158 | { |
| 159 | char buf[SCREEN_X]; |
| 160 | char *ptr = buf; |
| 161 | int i; |
| 162 | int len = strlen(str) + 4; |
| 163 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 164 | for (i = 0; i < (SCREEN_X - len) / 2; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 165 | ptr += sprintf(ptr, "="); |
| 166 | |
| 167 | ptr += sprintf(ptr, "[ %s ]", str); |
| 168 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 169 | for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 170 | ptr += sprintf(ptr, "="); |
| 171 | |
| 172 | mvprintw(row, 0, buf); |
| 173 | } |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 174 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 175 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 176 | static void redraw_module(struct coreinfo_cat *cat) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 177 | { |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 178 | if (cat->count == 0) |
Uwe Hermann | 6c44dfb | 2008-04-04 16:49:09 +0000 | [diff] [blame] | 179 | return; |
| 180 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 181 | wclear(modwin); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 182 | cat->modules[cat->cur]->redraw(modwin); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 183 | wrefresh(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 186 | static void handle_category_key(struct coreinfo_cat *cat, int key) |
| 187 | { |
Himanshu Sahdev | d3d38c9 | 2019-09-23 15:08:18 +0530 | [diff] [blame] | 188 | 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 Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 195 | if (index < cat->count) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 196 | cat->cur = index; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 197 | 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äfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 208 | static void print_no_modules_selected(void) |
| 209 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 210 | int height = getmaxy(stdscr); |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 211 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 212 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 213 | 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äfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 220 | static int first_nonempty_category(void) |
| 221 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 222 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 223 | if (categories[i].count > 0) |
| 224 | return i; |
| 225 | return 0; |
| 226 | } |
| 227 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 228 | static void loop(void) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 229 | { |
| 230 | int key; |
| 231 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 232 | center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION); |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 233 | print_no_modules_selected(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 234 | refresh(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 235 | |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 236 | curwin = first_nonempty_category(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 237 | print_menu(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 238 | print_submenu(&categories[curwin]); |
| 239 | redraw_module(&categories[curwin]); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 240 | |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 241 | halfdelay(10); |
| 242 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 243 | while (1) { |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 244 | int ch = -1; |
| 245 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 246 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 247 | print_time_and_date(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 248 | wrefresh(menuwin); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 249 | #endif |
| 250 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 251 | key = getch(); |
| 252 | |
| 253 | if (key == ERR) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 254 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 255 | |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 256 | 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 Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 260 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 261 | if (ch >= 0 && (unsigned int)ch <= ARRAY_SIZE(categories)) { |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 262 | if (ch == ARRAY_SIZE(categories)) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 263 | continue; |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 264 | if (categories[ch].count == 0) |
| 265 | continue; |
| 266 | |
| 267 | curwin = ch; |
| 268 | print_submenu(&categories[curwin]); |
| 269 | redraw_module(&categories[curwin]); |
| 270 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 273 | if (key == KEY_ESC) |
Jordan Crouse | 98cc056 | 2008-05-20 20:16:34 +0000 | [diff] [blame] | 274 | return; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 275 | |
| 276 | handle_category_key(&categories[curwin], key); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Jacob Garber | bd62472 | 2019-10-02 14:44:28 -0600 | [diff] [blame] | 280 | int main(int argc, char **argv) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 281 | { |
Jacob Garber | bd62472 | 2019-10-02 14:44:28 -0600 | [diff] [blame] | 282 | (void)argc; |
| 283 | (void)argv; |
| 284 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 285 | int j; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 286 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 287 | if (CONFIG(LP_USB)) |
Nicola Corna | 71693ba | 2017-03-14 10:26:58 +0100 | [diff] [blame] | 288 | usb_initialize(); |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 289 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 290 | initscr(); |
| 291 | |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 292 | start_color(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 293 | init_pair(1, COLOR_WHITE, COLOR_GREEN); |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 294 | init_pair(2, COLOR_WHITE, COLOR_BLACK); |
| 295 | init_pair(3, COLOR_BLACK, COLOR_WHITE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 296 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 297 | modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0); |
| 298 | menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 299 | |
| 300 | wattrset(stdscr, COLOR_PAIR(1) | A_BOLD); |
| 301 | wattrset(modwin, COLOR_PAIR(2)); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 302 | wattrset(menuwin, COLOR_PAIR(1) | A_BOLD); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 303 | |
Ulf Jordan | 22d5ddc | 2008-09-24 14:21:02 +0000 | [diff] [blame] | 304 | werase(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 305 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 306 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 307 | for (j = 0; j < categories[i].count; j++) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 308 | categories[i].modules[j]->init(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 309 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 310 | |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 311 | noecho(); /* don't let curses echo keyboard chars */ |
| 312 | keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */ |
Yasha Cherikovsky | 619fc95 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 313 | curs_set(0); /* Hide blinking cursor */ |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 314 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 315 | loop(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 316 | |
Maxime de Roucy | 8190078 | 2015-09-27 15:53:40 +0200 | [diff] [blame] | 317 | /* reboot */ |
| 318 | outb(0x6, 0xcf9); |
| 319 | halt(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 320 | return 0; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 321 | } |
Jordan Crouse | 5083811 | 2008-05-27 20:07:47 +0000 | [diff] [blame] | 322 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 323 | PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME); |
| 324 | PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME); |
| 325 | PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC); |