Stub out FILE*, stdout/stdin/stderr and implement fprintf on these
[coreboot.git] / payloads / coreinfo / coreinfo.c
index c515d29bab2dd3850832e154187664c6f12d439b..846cf77c1852aca008fbc69024b7b2eac8a3369a 100644 (file)
 
 #include "coreinfo.h"
 
-#define SCREEN_Y 24
+#define SCREEN_Y 25
 #define SCREEN_X 80
 
+#define KEY_ESC 27
+
 extern struct coreinfo_module cpuinfo_module;
 extern struct coreinfo_module pci_module;
 extern struct coreinfo_module coreboot_module;
+extern struct coreinfo_module multiboot_module;
 extern struct coreinfo_module nvram_module;
 extern struct coreinfo_module bootlog_module;
+extern struct coreinfo_module ramdump_module;
+extern struct coreinfo_module lar_module;
+extern struct coreinfo_module cbfs_module;
 
 struct coreinfo_module *system_modules[] = {
 #ifdef CONFIG_MODULE_CPUINFO
@@ -38,15 +44,27 @@ struct coreinfo_module *system_modules[] = {
 #ifdef CONFIG_MODULE_NVRAM
        &nvram_module,
 #endif
+#ifdef CONFIG_MODULE_RAMDUMP
+       &ramdump_module,
+#endif
 };
 
-struct coreinfo_module *coreboot_modules[] = {
+struct coreinfo_module *firmware_modules[] = {
 #ifdef CONFIG_MODULE_COREBOOT
        &coreboot_module,
 #endif
+#ifdef CONFIG_MODULE_MULTIBOOT
+       &multiboot_module,
+#endif
 #ifdef CONFIG_MODULE_BOOTLOG
        &bootlog_module,
 #endif
+#ifdef CONFIG_MODULE_LAR
+       &lar_module,
+#endif
+#ifdef CONFIG_MODULE_CBFS
+       &cbfs_module,
+#endif
 };
 
 struct coreinfo_cat {
@@ -61,14 +79,13 @@ struct coreinfo_cat {
                .count = ARRAY_SIZE(system_modules),
        },
        {
-               .name = "Coreboot",
-               .modules = coreboot_modules,
-               .count = ARRAY_SIZE(coreboot_modules),
+               .name = "Firmware",
+               .modules = firmware_modules,
+               .count = ARRAY_SIZE(firmware_modules),
        }
 };
 
-
-static WINDOW *modwin;
+static WINDOW *modwin, *menuwin;
 static int curwin;
 
 void print_module_title(WINDOW *win, const char *title)
@@ -79,9 +96,8 @@ void print_module_title(WINDOW *win, const char *title)
        mvwprintw(win, 0, 1, title);
 
        wmove(win, 1, 1);
-
        for (i = 0; i < 78; i++)
-               waddch(win, '\304');
+               waddch(win, ACS_HLINE);
 }
 
 static void print_submenu(struct coreinfo_cat *cat)
@@ -90,30 +106,46 @@ static void print_submenu(struct coreinfo_cat *cat)
        char menu[80];
        char *ptr = menu;
 
-       wmove(stdscr, 22, 0);
+       wmove(menuwin, 0, 0);
 
        for (j = 0; j < SCREEN_X; j++)
-               waddch(stdscr, ' ');
+               waddch(menuwin, ' ');
 
        if (!cat->count)
                return;
 
        for (i = 0; i < cat->count; i++)
-               ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, cat->modules[i]->name);
+               ptr += sprintf(ptr, "[%c: %s] ", 'A' + i,
+                              cat->modules[i]->name);
 
-       mvprintw(22, 0, menu);
+       mvwprintw(menuwin, 0, 0, menu);
 }
 
+#ifdef CONFIG_SHOW_DATE_TIME
+static void print_time_and_date(void)
+{
+       struct tm tm;
+
+       while (nvram_updating())
+               mdelay(10);
+
+       rtc_read_clock(&tm);
+
+       mvwprintw(menuwin, 0, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
+                 tm.tm_mon, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour,
+                 tm.tm_min, tm.tm_sec);
+}
+#endif
+
 static void print_menu(void)
 {
        int i, j;
        char menu[80];
        char *ptr = menu;
 
-       wmove(stdscr, 23, 0);
-
+       wmove(menuwin, 1, 0);
        for (j = 0; j < SCREEN_X; j++)
-               waddch(stdscr, ' ');
+               waddch(menuwin, ' ');
 
        for (i = 0; i < ARRAY_SIZE(categories); i++) {
                if (categories[i].count == 0)
@@ -122,26 +154,18 @@ static void print_menu(void)
                ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
        }
 
-       mvprintw(23, 0, menu);
+       mvwprintw(menuwin, 1, 0, menu);
 
 #ifdef CONFIG_SHOW_DATE_TIME
-       mvprintw(23, 59, "%02d/%02d/20%02d - %02d:%02d:%02d",
-                bcd2dec(nvram_read(NVRAM_RTC_MONTH)),
-                bcd2dec(nvram_read(NVRAM_RTC_DAY)),
-                bcd2dec(nvram_read(NVRAM_RTC_YEAR)),
-                bcd2dec(nvram_read(NVRAM_RTC_HOURS)),
-                bcd2dec(nvram_read(NVRAM_RTC_MINUTES)),
-                bcd2dec(nvram_read(NVRAM_RTC_SECONDS)));
+       print_time_and_date();
 #endif
 }
 
 static void center(int row, const char *str)
 {
-       int len = strlen(str);
-       int j;
+       int j, len = strlen(str);
 
        wmove(stdscr, row, 0);
-
        for (j = 0; j < SCREEN_X; j++)
                waddch(stdscr, ' ');
 
@@ -162,8 +186,6 @@ static void header(int row, const char *str)
 
        ptr += sprintf(ptr, "[ %s ]", str);
 
-
-
        for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
                ptr += sprintf(ptr, "=");
 
@@ -178,17 +200,15 @@ static void redraw_module(struct coreinfo_cat *cat)
 
        wclear(modwin);
        cat->modules[cat->cur]->redraw(modwin);
-       refresh();
+       wrefresh(modwin);
 }
 
 static void handle_category_key(struct coreinfo_cat *cat, int key)
 {
        if (key >= 'a' && key <= 'z') {
                int index = key - 'a';
-
                if (index < cat->count) {
-
-               cat->cur = index;
+                       cat->cur = index;
                        redraw_module(cat);
                        return;
                }
@@ -204,13 +224,21 @@ static void loop(void)
 {
        int key;
 
-       center(0, "coreinfo v0.1");
+       center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
+       refresh();
 
        print_menu();
        print_submenu(&categories[curwin]);
        redraw_module(&categories[curwin]);
 
+       halfdelay(10);
+
        while (1) {
+#ifdef CONFIG_SHOW_DATE_TIME
+               print_time_and_date();
+               wrefresh(menuwin);
+#endif
+
                key = getch();
 
                if (key == ERR)
@@ -232,6 +260,8 @@ static void loop(void)
                        }
                }
 
+               if (key == KEY_ESC)
+                       return;
 
                handle_category_key(&categories[curwin], key);
        }
@@ -241,36 +271,31 @@ int main(void)
 {
        int i, j;
 
-       curses_enable_serial(0);
-       curses_enable_vga(1);
-
        initscr();
 
        init_pair(1, COLOR_WHITE, COLOR_GREEN);
        init_pair(2, COLOR_BLACK, COLOR_WHITE);
        init_pair(3, COLOR_WHITE, COLOR_WHITE);
 
-       modwin = newwin(22, 80, 1, 0);
+       modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
+       menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
 
        wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
        wattrset(modwin, COLOR_PAIR(2));
+       wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
 
-       for (i = 0; i < 23; i++) {
-               wmove(modwin, i - 1, 0);
-
-               for (j = 0; j < SCREEN_X; j++)
-                       waddch(modwin, ' ');
-       }
-
-       refresh();
+       werase(modwin);
 
        for (i = 0; i < ARRAY_SIZE(categories); i++) {
-               for(j = 0; j < categories[i].count; j++)
+               for (j = 0; j < categories[i].count; j++)
                        categories[i].modules[j]->init();
-
        }
 
        loop();
 
        return 0;
 }
+
+PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
+PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
+PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);