2 * This file is part of the coreinfo project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
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.
20 extern struct coreinfo_module cpuinfo_module
;
21 extern struct coreinfo_module pci_module
;
22 extern struct coreinfo_module coreboot_module
;
23 extern struct coreinfo_module multiboot_module
;
24 extern struct coreinfo_module nvram_module
;
25 extern struct coreinfo_module bootlog_module
;
26 extern struct coreinfo_module ramdump_module
;
27 extern struct coreinfo_module cbfs_module
;
28 extern struct coreinfo_module timestamps_module
;
30 struct coreinfo_module
*system_modules
[] = {
31 #if CONFIG(MODULE_CPUINFO)
34 #if CONFIG(MODULE_PCI)
37 #if CONFIG(MODULE_NVRAM)
40 #if CONFIG(MODULE_RAMDUMP)
45 struct coreinfo_module
*firmware_modules
[] = {
46 #if CONFIG(MODULE_COREBOOT)
49 #if CONFIG(MODULE_MULTIBOOT)
52 #if CONFIG(MODULE_BOOTLOG)
55 #if CONFIG(MODULE_CBFS)
58 #if CONFIG(MODULE_TIMESTAMPS)
67 struct coreinfo_module
**modules
;
71 .modules
= system_modules
,
72 .count
= ARRAY_SIZE(system_modules
),
76 .modules
= firmware_modules
,
77 .count
= ARRAY_SIZE(firmware_modules
),
81 static WINDOW
*modwin
, *menuwin
;
84 void print_module_title(WINDOW
*win
, const char *title
)
88 wattrset(win
, COLOR_PAIR(2));
89 mvwprintw(win
, 0, 1, title
);
92 for (i
= 0; i
< 78; i
++)
93 waddch(win
, ACS_HLINE
);
96 static void print_submenu(struct coreinfo_cat
*cat
)
102 wmove(menuwin
, 0, 0);
104 for (j
= 0; j
< SCREEN_X
; j
++)
105 waddch(menuwin
, ' ');
110 for (i
= 0; i
< cat
->count
; i
++)
111 ptr
+= sprintf(ptr
, "[%c: %s] ", 'A' + i
,
112 cat
->modules
[i
]->name
);
114 mvwprintw(menuwin
, 0, 0, menu
);
117 #if CONFIG(SHOW_DATE_TIME)
118 static void print_time_and_date(void)
122 while (nvram_updating())
127 mvwprintw(menuwin
, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
128 tm
.tm_mon
+ 1, tm
.tm_mday
, 1900 + tm
.tm_year
, tm
.tm_hour
,
129 tm
.tm_min
, tm
.tm_sec
);
133 static void print_menu(void)
139 wmove(menuwin
, 1, 0);
140 for (j
= 0; j
< SCREEN_X
; j
++)
141 waddch(menuwin
, ' ');
143 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
144 if (categories
[i
].count
== 0)
147 ptr
+= sprintf(ptr
, "F%zu: %s ", i
+ 1, categories
[i
].name
);
150 mvwprintw(menuwin
, 1, 0, menu
);
152 #if CONFIG(SHOW_DATE_TIME)
153 print_time_and_date();
157 static void center(int row
, const char *str
)
159 int j
, len
= strlen(str
);
161 wmove(stdscr
, row
, 0);
162 for (j
= 0; j
< SCREEN_X
; j
++)
165 mvprintw(row
, (SCREEN_X
- len
) / 2, str
);
168 /* FIXME: Currently unused. */
170 static void header(int row
, const char *str
)
175 int len
= strlen(str
) + 4;
177 for (i
= 0; i
< (SCREEN_X
- len
) / 2; i
++)
178 ptr
+= sprintf(ptr
, "=");
180 ptr
+= sprintf(ptr
, "[ %s ]", str
);
182 for (i
= ((SCREEN_X
- len
) / 2) + len
; i
< SCREEN_X
; i
++)
183 ptr
+= sprintf(ptr
, "=");
185 mvprintw(row
, 0, buf
);
189 static void redraw_module(struct coreinfo_cat
*cat
)
195 cat
->modules
[cat
->cur
]->redraw(modwin
);
199 static void handle_category_key(struct coreinfo_cat
*cat
, int key
)
201 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z')) {
203 if (key
>= 'A' && key
<= 'Z') {
208 if (index
< cat
->count
) {
215 if (cat
->count
&& cat
->modules
[cat
->cur
]->handle
) {
216 if (cat
->modules
[cat
->cur
]->handle(key
))
221 static void print_no_modules_selected(void)
223 int height
= getmaxy(stdscr
);
225 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++)
226 if (categories
[i
].count
> 0)
229 color_set(2, NULL
); // White on black
230 center(height
/ 2, "No modules selected");
233 static int first_nonempty_category(void)
235 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++)
236 if (categories
[i
].count
> 0)
241 static void loop(void)
245 center(0, CONFIG_PAYLOAD_INFO_NAME
" " CONFIG_PAYLOAD_INFO_VERSION
);
246 print_no_modules_selected();
249 curwin
= first_nonempty_category();
251 print_submenu(&categories
[curwin
]);
252 redraw_module(&categories
[curwin
]);
259 #if CONFIG(SHOW_DATE_TIME)
260 print_time_and_date();
269 if (key
>= KEY_F(1) && key
<= KEY_F(9))
271 if (key
>= '1' && key
<= '9')
274 if (ch
>= 0 && (unsigned int)ch
<= ARRAY_SIZE(categories
)) {
275 if (ch
== ARRAY_SIZE(categories
))
277 if (categories
[ch
].count
== 0)
281 print_submenu(&categories
[curwin
]);
282 redraw_module(&categories
[curwin
]);
289 handle_category_key(&categories
[curwin
], key
);
303 init_pair(1, COLOR_WHITE
, COLOR_GREEN
);
304 init_pair(2, COLOR_WHITE
, COLOR_BLACK
);
305 init_pair(3, COLOR_BLACK
, COLOR_WHITE
);
307 modwin
= newwin(SCREEN_Y
- 3, SCREEN_X
, 1, 0);
308 menuwin
= newwin(2, SCREEN_X
, SCREEN_Y
- 2, 0);
310 wattrset(stdscr
, COLOR_PAIR(1) | A_BOLD
);
311 wattrset(modwin
, COLOR_PAIR(2));
312 wattrset(menuwin
, COLOR_PAIR(1) | A_BOLD
);
316 for (size_t i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
317 for (j
= 0; j
< categories
[i
].count
; j
++)
318 categories
[i
].modules
[j
]->init();
321 noecho(); /* don't let curses echo keyboard chars */
322 keypad(stdscr
, TRUE
); /* allow KEY_F(n) keys to be seen */
323 curs_set(0); /* Hide blinking cursor */
333 PAYLOAD_INFO(name
, CONFIG_PAYLOAD_INFO_NAME
);
334 PAYLOAD_INFO(listname
, CONFIG_PAYLOAD_INFO_LISTNAME
);
335 PAYLOAD_INFO(desc
, CONFIG_PAYLOAD_INFO_DESC
);