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 lar_module
;
28 extern struct coreinfo_module cbfs_module
;
30 struct coreinfo_module
*system_modules
[] = {
31 #if IS_ENABLED(CONFIG_MODULE_CPUINFO)
34 #if IS_ENABLED(CONFIG_MODULE_PCI)
37 #if IS_ENABLED(CONFIG_MODULE_NVRAM)
40 #if IS_ENABLED(CONFIG_MODULE_RAMDUMP)
45 struct coreinfo_module
*firmware_modules
[] = {
46 #if IS_ENABLED(CONFIG_MODULE_COREBOOT)
49 #if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
52 #if IS_ENABLED(CONFIG_MODULE_BOOTLOG)
55 #if IS_ENABLED(CONFIG_MODULE_LAR)
58 #if IS_ENABLED(CONFIG_MODULE_CBFS)
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 IS_ENABLED(CONFIG_SHOW_DATE_TIME)
118 static void print_time_and_date(void)
122 while (nvram_updating())
127 mvwprintw(menuwin
, 0, 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 (i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
144 if (categories
[i
].count
== 0)
147 ptr
+= sprintf(ptr
, "F%d: %s ", i
+ 1, categories
[i
].name
);
150 mvwprintw(menuwin
, 1, 0, menu
);
152 #if IS_ENABLED(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') {
202 int index
= key
- 'a';
203 if (index
< cat
->count
) {
210 if (cat
->count
&& cat
->modules
[cat
->cur
]->handle
) {
211 if (cat
->modules
[cat
->cur
]->handle(key
))
216 static void loop(void)
220 center(0, CONFIG_PAYLOAD_INFO_NAME
" " CONFIG_PAYLOAD_INFO_VERSION
);
224 print_submenu(&categories
[curwin
]);
225 redraw_module(&categories
[curwin
]);
230 #if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
231 print_time_and_date();
240 if (key
>= KEY_F(1) && key
<= KEY_F(9)) {
241 unsigned char ch
= key
- KEY_F(1);
243 if (ch
<= ARRAY_SIZE(categories
)) {
244 if (ch
== ARRAY_SIZE(categories
))
246 if (categories
[ch
].count
== 0)
250 print_submenu(&categories
[curwin
]);
251 redraw_module(&categories
[curwin
]);
259 handle_category_key(&categories
[curwin
], key
);
267 #if IS_ENABLED(CONFIG_LP_USB)
274 init_pair(1, COLOR_WHITE
, COLOR_GREEN
);
275 init_pair(2, COLOR_WHITE
, COLOR_BLACK
);
276 init_pair(3, COLOR_BLACK
, COLOR_WHITE
);
278 modwin
= newwin(SCREEN_Y
- 3, SCREEN_X
, 1, 0);
279 menuwin
= newwin(2, SCREEN_X
, SCREEN_Y
- 2, 0);
281 wattrset(stdscr
, COLOR_PAIR(1) | A_BOLD
);
282 wattrset(modwin
, COLOR_PAIR(2));
283 wattrset(menuwin
, COLOR_PAIR(1) | A_BOLD
);
287 for (i
= 0; i
< ARRAY_SIZE(categories
); i
++) {
288 for (j
= 0; j
< categories
[i
].count
; j
++)
289 categories
[i
].modules
[j
]->init();
292 noecho(); /* don't let curses echo keyboard chars */
293 keypad(stdscr
, TRUE
); /* allow KEY_F(n) keys to be seen */
294 curs_set(0); /* Hide blinking cursor */
304 PAYLOAD_INFO(name
, CONFIG_PAYLOAD_INFO_NAME
);
305 PAYLOAD_INFO(listname
, CONFIG_PAYLOAD_INFO_LISTNAME
);
306 PAYLOAD_INFO(desc
, CONFIG_PAYLOAD_INFO_DESC
);