Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 1 | /* |
| 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 Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "coreinfo.h" |
| 17 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 18 | #define KEY_ESC 27 |
| 19 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 20 | extern struct coreinfo_module cpuinfo_module; |
| 21 | extern struct coreinfo_module pci_module; |
| 22 | extern struct coreinfo_module coreboot_module; |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 23 | extern struct coreinfo_module multiboot_module; |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 24 | extern struct coreinfo_module nvram_module; |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 25 | extern struct coreinfo_module bootlog_module; |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 26 | extern struct coreinfo_module ramdump_module; |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 27 | extern struct coreinfo_module cbfs_module; |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 28 | extern struct coreinfo_module timestamps_module; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 29 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 30 | struct coreinfo_module *system_modules[] = { |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 31 | #if IS_ENABLED(CONFIG_MODULE_CPUINFO) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 32 | &cpuinfo_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 33 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 34 | #if IS_ENABLED(CONFIG_MODULE_PCI) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 35 | &pci_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 36 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_MODULE_NVRAM) |
Jordan Crouse | 7ce2666 | 2008-05-06 22:00:55 +0000 | [diff] [blame] | 38 | &nvram_module, |
| 39 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 40 | #if IS_ENABLED(CONFIG_MODULE_RAMDUMP) |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 41 | &ramdump_module, |
| 42 | #endif |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 45 | struct coreinfo_module *firmware_modules[] = { |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 46 | #if IS_ENABLED(CONFIG_MODULE_COREBOOT) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 47 | &coreboot_module, |
| 48 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 49 | #if IS_ENABLED(CONFIG_MODULE_MULTIBOOT) |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 50 | &multiboot_module, |
| 51 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_MODULE_BOOTLOG) |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 53 | &bootlog_module, |
| 54 | #endif |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 55 | #if IS_ENABLED(CONFIG_MODULE_CBFS) |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 56 | &cbfs_module, |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 57 | #endif |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 58 | #if IS_ENABLED(CONFIG_MODULE_TIMESTAMPS) |
| 59 | ×tamps_module, |
| 60 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 63 | struct 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 Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 75 | .name = "Firmware", |
| 76 | .modules = firmware_modules, |
| 77 | .count = ARRAY_SIZE(firmware_modules), |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 78 | } |
| 79 | }; |
| 80 | |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 81 | static WINDOW *modwin, *menuwin; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 82 | static int curwin; |
| 83 | |
| 84 | void 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 Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 92 | for (i = 0; i < 78; i++) |
Ulf Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 93 | waddch(win, ACS_HLINE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 96 | static void print_submenu(struct coreinfo_cat *cat) |
| 97 | { |
| 98 | int i, j; |
| 99 | char menu[80]; |
| 100 | char *ptr = menu; |
| 101 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 102 | wmove(menuwin, 0, 0); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 103 | |
| 104 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 105 | waddch(menuwin, ' '); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 106 | |
| 107 | if (!cat->count) |
| 108 | return; |
| 109 | |
| 110 | for (i = 0; i < cat->count; i++) |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 111 | ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, |
| 112 | cat->modules[i]->name); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 113 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 114 | mvwprintw(menuwin, 0, 0, menu); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 117 | #if IS_ENABLED(CONFIG_SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 118 | static void print_time_and_date(void) |
| 119 | { |
| 120 | struct tm tm; |
| 121 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 122 | while (nvram_updating()) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 123 | mdelay(10); |
| 124 | |
| 125 | rtc_read_clock(&tm); |
| 126 | |
Jonathan Neuschäfer | 2bf7a2c | 2016-04-04 19:44:30 +0200 | [diff] [blame] | 127 | mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d", |
Yasha Cherikovsky | ae16c40 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 128 | 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] | 129 | tm.tm_min, tm.tm_sec); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 130 | } |
| 131 | #endif |
| 132 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 133 | static void print_menu(void) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 134 | { |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 135 | int i, j; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 136 | char menu[80]; |
| 137 | char *ptr = menu; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 138 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 139 | wmove(menuwin, 1, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 140 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 141 | waddch(menuwin, ' '); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 142 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 143 | for (i = 0; i < ARRAY_SIZE(categories); i++) { |
| 144 | if (categories[i].count == 0) |
| 145 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 146 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 147 | ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name); |
| 148 | } |
| 149 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 150 | mvwprintw(menuwin, 1, 0, menu); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 151 | |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 152 | #if IS_ENABLED(CONFIG_SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 153 | print_time_and_date(); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 154 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 157 | static void center(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 158 | { |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 159 | int j, len = strlen(str); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 160 | |
| 161 | wmove(stdscr, row, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 162 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 163 | waddch(stdscr, ' '); |
| 164 | |
| 165 | mvprintw(row, (SCREEN_X - len) / 2, str); |
| 166 | } |
| 167 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 168 | /* FIXME: Currently unused. */ |
| 169 | #if 0 |
| 170 | static void header(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 171 | { |
| 172 | char buf[SCREEN_X]; |
| 173 | char *ptr = buf; |
| 174 | int i; |
| 175 | int len = strlen(str) + 4; |
| 176 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 177 | for (i = 0; i < (SCREEN_X - len) / 2; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 178 | ptr += sprintf(ptr, "="); |
| 179 | |
| 180 | ptr += sprintf(ptr, "[ %s ]", str); |
| 181 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 182 | for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 183 | ptr += sprintf(ptr, "="); |
| 184 | |
| 185 | mvprintw(row, 0, buf); |
| 186 | } |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 187 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 188 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 189 | static void redraw_module(struct coreinfo_cat *cat) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 190 | { |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 191 | if (cat->count == 0) |
Uwe Hermann | 6c44dfb | 2008-04-04 16:49:09 +0000 | [diff] [blame] | 192 | return; |
| 193 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 194 | wclear(modwin); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 195 | cat->modules[cat->cur]->redraw(modwin); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 196 | wrefresh(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 199 | static void handle_category_key(struct coreinfo_cat *cat, int key) |
| 200 | { |
| 201 | if (key >= 'a' && key <= 'z') { |
| 202 | int index = key - 'a'; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 203 | if (index < cat->count) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 204 | cat->cur = index; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 205 | 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äfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 216 | static 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äfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 228 | static 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 Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 238 | static void loop(void) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 239 | { |
| 240 | int key; |
| 241 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 242 | center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION); |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 243 | print_no_modules_selected(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 244 | refresh(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 245 | |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 246 | curwin = first_nonempty_category(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 247 | print_menu(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 248 | print_submenu(&categories[curwin]); |
| 249 | redraw_module(&categories[curwin]); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 250 | |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 251 | halfdelay(10); |
| 252 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 253 | while (1) { |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 254 | int ch = -1; |
| 255 | |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 256 | #if IS_ENABLED(CONFIG_SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 257 | print_time_and_date(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 258 | wrefresh(menuwin); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 259 | #endif |
| 260 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 261 | key = getch(); |
| 262 | |
| 263 | if (key == ERR) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 264 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 265 | |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 266 | 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 Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 270 | |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 271 | if (ch >= 0 && ch <= ARRAY_SIZE(categories)) { |
| 272 | if (ch == ARRAY_SIZE(categories)) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 273 | continue; |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 274 | if (categories[ch].count == 0) |
| 275 | continue; |
| 276 | |
| 277 | curwin = ch; |
| 278 | print_submenu(&categories[curwin]); |
| 279 | redraw_module(&categories[curwin]); |
| 280 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 283 | if (key == KEY_ESC) |
Jordan Crouse | 98cc056 | 2008-05-20 20:16:34 +0000 | [diff] [blame] | 284 | return; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 285 | |
| 286 | handle_category_key(&categories[curwin], key); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | int main(void) |
| 291 | { |
| 292 | int i, j; |
| 293 | |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 294 | #if IS_ENABLED(CONFIG_LP_USB) |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 295 | usb_initialize(); |
| 296 | #endif |
| 297 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 298 | initscr(); |
| 299 | |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 300 | start_color(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 301 | init_pair(1, COLOR_WHITE, COLOR_GREEN); |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 302 | init_pair(2, COLOR_WHITE, COLOR_BLACK); |
| 303 | init_pair(3, COLOR_BLACK, COLOR_WHITE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 304 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 305 | modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0); |
| 306 | menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 307 | |
| 308 | wattrset(stdscr, COLOR_PAIR(1) | A_BOLD); |
| 309 | wattrset(modwin, COLOR_PAIR(2)); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 310 | wattrset(menuwin, COLOR_PAIR(1) | A_BOLD); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 311 | |
Ulf Jordan | 22d5ddc | 2008-09-24 14:21:02 +0000 | [diff] [blame] | 312 | werase(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 313 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 314 | for (i = 0; i < ARRAY_SIZE(categories); i++) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 315 | for (j = 0; j < categories[i].count; j++) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 316 | categories[i].modules[j]->init(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 317 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 318 | |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 319 | noecho(); /* don't let curses echo keyboard chars */ |
| 320 | keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */ |
Yasha Cherikovsky | 619fc95 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 321 | curs_set(0); /* Hide blinking cursor */ |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 322 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 323 | loop(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 324 | |
Maxime de Roucy | 8190078 | 2015-09-27 15:53:40 +0200 | [diff] [blame] | 325 | /* reboot */ |
| 326 | outb(0x6, 0xcf9); |
| 327 | halt(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 328 | return 0; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 329 | } |
Jordan Crouse | 5083811 | 2008-05-27 20:07:47 +0000 | [diff] [blame] | 330 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 331 | PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME); |
| 332 | PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME); |
| 333 | PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC); |