1 /* SPDX-License-Identifier: GPL-2.0-only */
7 extern struct coreinfo_module cpuinfo_module
;
8 extern struct coreinfo_module pci_module
;
9 extern struct coreinfo_module coreboot_module
;
10 extern struct coreinfo_module multiboot_module
;
11 extern struct coreinfo_module nvram_module
;
12 extern struct coreinfo_module bootlog_module
;
13 extern struct coreinfo_module ramdump_module
;
14 extern struct coreinfo_module cbfs_module
;
15 extern struct coreinfo_module timestamps_module
;
17 struct coreinfo_module
*system_modules
[] = {
18 #if CONFIG(MODULE_CPUINFO)
21 #if CONFIG(MODULE_PCI)
24 #if CONFIG(MODULE_NVRAM)
27 #if CONFIG(MODULE_RAMDUMP)
32 struct coreinfo_module
*firmware_modules
[] = {
33 #if CONFIG(MODULE_COREBOOT)
36 #if CONFIG(MODULE_MULTIBOOT)
39 #if CONFIG(MODULE_BOOTLOG)
42 #if CONFIG(MODULE_CBFS)
45 #if CONFIG(MODULE_TIMESTAMPS)
54 struct coreinfo_module
**modules
;
58 .modules
= system_modules
,
59 .count
= ARRAY_SIZE(system_modules
),
63 .modules
= firmware_modules
,
64 .count
= ARRAY_SIZE(firmware_modules
),
68 static WINDOW
*modwin
, *menuwin
;
71 void print_module_title(WINDOW
*win
, const char *title
)
75 wattrset(win
, COLOR_PAIR(2));
76 mvwprintw(win
, 0, 1, title
);
79 for (i
= 0; i
< 78; i
++)
80 waddch(win
, ACS_HLINE
);
83 static void print_submenu(struct coreinfo_cat
*cat
)
91 for (j
= 0; j
< SCREEN_X
; j
++)
97 for (i
= 0; i
< cat
->count
; i
++)
98 ptr
+= sprintf(ptr
, "[%c: %s] ", 'A' + i
,
99 cat
->modules
[i
]->name
);
101 mvwprintw(menuwin
, 0, 0, menu
);
104 #if CONFIG(SHOW_DATE_TIME)
105 static void print_time_and_date(void)
109 while (nvram_updating())
114 mvwprintw(menuwin
, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
115 tm
.tm_mon
+ 1, tm
.tm_mday
, 1900 + tm
.tm_year
, tm
.tm_hour
,
116 tm
.tm_min
, tm
.tm_sec
);
120 static void print_menu(void)
126 wmove(menuwin
, 1, 0);
127 for (j
= 0; j
< SCREEN_X
; j
++)
128 waddch(menuwin
, ' ');
130 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
131 if (categories
[i
].count
== 0)
134 ptr
+= sprintf(ptr
, "F%zu: %s ", i
+ 1, categories
[i
].name
);
137 mvwprintw(menuwin
, 1, 0, menu
);
139 #if CONFIG(SHOW_DATE_TIME)
140 print_time_and_date();
144 static void center(int row
, const char *str
)
146 int j
, len
= strlen(str
);
148 wmove(stdscr
, row
, 0);
149 for (j
= 0; j
< SCREEN_X
; j
++)
152 mvprintw(row
, (SCREEN_X
- len
) / 2, str
);
155 /* FIXME: Currently unused. */
157 static void header(int row
, const char *str
)
162 int len
= strlen(str
) + 4;
164 for (i
= 0; i
< (SCREEN_X
- len
) / 2; i
++)
165 ptr
+= sprintf(ptr
, "=");
167 ptr
+= sprintf(ptr
, "[ %s ]", str
);
169 for (i
= ((SCREEN_X
- len
) / 2) + len
; i
< SCREEN_X
; i
++)
170 ptr
+= sprintf(ptr
, "=");
172 mvprintw(row
, 0, buf
);
176 static void redraw_module(struct coreinfo_cat
*cat
)
182 cat
->modules
[cat
->cur
]->redraw(modwin
);
186 static void handle_category_key(struct coreinfo_cat
*cat
, int key
)
188 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z')) {
190 if (key
>= 'A' && key
<= 'Z') {
195 if (index
< cat
->count
) {
202 if (cat
->count
&& cat
->modules
[cat
->cur
]->handle
) {
203 if (cat
->modules
[cat
->cur
]->handle(key
))
208 static void print_no_modules_selected(void)
210 int height
= getmaxy(stdscr
);
212 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++)
213 if (categories
[i
].count
> 0)
216 color_set(2, NULL
); // White on black
217 center(height
/ 2, "No modules selected");
220 static int first_nonempty_category(void)
222 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++)
223 if (categories
[i
].count
> 0)
228 static void loop(void)
232 center(0, CONFIG_COREINFO_NAME
" " CONFIG_COREINFO_VERSION
);
233 print_no_modules_selected();
236 curwin
= first_nonempty_category();
238 print_submenu(&categories
[curwin
]);
239 redraw_module(&categories
[curwin
]);
246 #if CONFIG(SHOW_DATE_TIME)
247 print_time_and_date();
256 if (key
>= KEY_F(1) && key
<= KEY_F(9))
258 if (key
>= '1' && key
<= '9')
261 if (ch
>= 0 && (unsigned int)ch
<= ARRAY_SIZE(categories
)) {
262 if (ch
== ARRAY_SIZE(categories
))
264 if (categories
[ch
].count
== 0)
268 print_submenu(&categories
[curwin
]);
269 redraw_module(&categories
[curwin
]);
276 handle_category_key(&categories
[curwin
], key
);
280 int main(int argc
, char **argv
)
293 init_pair(1, COLOR_WHITE
, COLOR_GREEN
);
294 init_pair(2, COLOR_WHITE
, COLOR_BLACK
);
295 init_pair(3, COLOR_BLACK
, COLOR_WHITE
);
297 modwin
= newwin(SCREEN_Y
- 3, SCREEN_X
, 1, 0);
298 menuwin
= newwin(2, SCREEN_X
, SCREEN_Y
- 2, 0);
300 wattrset(stdscr
, COLOR_PAIR(1) | A_BOLD
);
301 wattrset(modwin
, COLOR_PAIR(2));
302 wattrset(menuwin
, COLOR_PAIR(1) | A_BOLD
);
306 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
307 for (j
= 0; j
< categories
[i
].count
; j
++)
308 categories
[i
].modules
[j
]->init();
311 noecho(); /* don't let curses echo keyboard chars */
312 keypad(stdscr
, TRUE
); /* allow KEY_F(n) keys to be seen */
313 curs_set(0); /* Hide blinking cursor */