coreinfo: Add a module for browsing the boot LAR
[coreboot.git] / payloads / coreinfo / coreinfo.c
index 13a08f24a2f1f45eb53afb2fa73013fa2d0c1e34..ae43357e6291f9ba8550ce5c392d4d08d2a885b5 100644 (file)
@@ -27,25 +27,51 @@ extern struct coreinfo_module pci_module;
 extern struct coreinfo_module coreboot_module;
 extern struct coreinfo_module nvram_module;
 extern struct coreinfo_module bootlog_module;
+extern struct coreinfo_module lar_module;
 
-struct coreinfo_module *modules[] = {
+struct coreinfo_module *system_modules[] = {
 #ifdef CONFIG_MODULE_CPUINFO
        &cpuinfo_module,
 #endif
 #ifdef CONFIG_MODULE_PCI
        &pci_module,
 #endif
-#ifdef CONFIG_MODULE_COREBOOT
-       &coreboot_module,
-#endif
 #ifdef CONFIG_MODULE_NVRAM
        &nvram_module,
 #endif
+};
+
+struct coreinfo_module *coreboot_modules[] = {
+#ifdef CONFIG_MODULE_COREBOOT
+       &coreboot_module,
+#endif
 #ifdef CONFIG_MODULE_BOOTLOG
        &bootlog_module,
 #endif
+#ifdef CONFIG_MODULE_LAR
+       &lar_module
+#endif
+};
+
+struct coreinfo_cat {
+       char name[15];
+       int cur;
+       int count;
+       struct coreinfo_module **modules;
+} categories[] = {
+       {
+               .name = "System",
+               .modules = system_modules,
+               .count = ARRAY_SIZE(system_modules),
+       },
+       {
+               .name = "Coreboot",
+               .modules = coreboot_modules,
+               .count = ARRAY_SIZE(coreboot_modules),
+       }
 };
 
+
 static WINDOW *modwin;
 static int curwin;
 
@@ -62,31 +88,64 @@ void print_module_title(WINDOW *win, const char *title)
                waddch(win, '\304');
 }
 
+static void print_submenu(struct coreinfo_cat *cat)
+{
+       int i, j;
+       char menu[80];
+       char *ptr = menu;
+
+       wmove(stdscr, SCREEN_Y - 2, 0);
+
+       for (j = 0; j < SCREEN_X; j++)
+               waddch(stdscr, ' ');
+
+       if (!cat->count)
+               return;
+
+       for (i = 0; i < cat->count; i++)
+               ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, cat->modules[i]->name);
+
+       mvprintw(SCREEN_Y - 2, 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);
+
+       mvprintw(23, 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(stdscr, SCREEN_Y - 1, 0);
 
        for (j = 0; j < SCREEN_X; j++)
                waddch(stdscr, ' ');
 
-       for (i = 0; i < ARRAY_SIZE(modules); i++)
-               ptr += sprintf(ptr, "F%d: %s ", i + 1, modules[i]->name);
+       for (i = 0; i < ARRAY_SIZE(categories); i++) {
+               if (categories[i].count == 0)
+                       continue;
+
+               ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
+       }
 
-       if (ARRAY_SIZE(modules) != 0)
-               mvprintw(23, 0, menu);
+       mvprintw(23, 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
 }
 
@@ -117,6 +176,8 @@ 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, "=");
 
@@ -124,16 +185,35 @@ static void header(int row, const char *str)
 }
 #endif
 
-static void redraw_module(void)
+static void redraw_module(struct coreinfo_cat *cat)
 {
-       if (ARRAY_SIZE(modules) == 0)
+       if (cat->count == 0)
                return;
 
        wclear(modwin);
-       modules[curwin]->redraw(modwin);
+       cat->modules[cat->cur]->redraw(modwin);
        refresh();
 }
 
+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;
+                       redraw_module(cat);
+                       return;
+               }
+       }
+
+       if (cat->count && cat->modules[cat->cur]->handle) {
+               if (cat->modules[cat->cur]->handle(key))
+                       redraw_module(cat);
+       }
+}
+
 static void loop(void)
 {
        int key;
@@ -141,11 +221,17 @@ static void loop(void)
        center(0, "coreinfo v0.1");
 
        print_menu();
-       if (ARRAY_SIZE(modules) != 0)
-               modules[curwin]->redraw(modwin);
-       refresh();
+       print_submenu(&categories[curwin]);
+       redraw_module(&categories[curwin]);
+
+       halfdelay(10);
 
        while (1) {
+#ifdef CONFIG_SHOW_DATE_TIME
+               print_time_and_date();
+               refresh();
+#endif
+
                key = getch();
 
                if (key == ERR)
@@ -154,18 +240,21 @@ static void loop(void)
                if (key >= KEY_F(1) && key <= KEY_F(9)) {
                        unsigned char ch = key - KEY_F(1);
 
-                       if (ch <= ARRAY_SIZE(modules)) {
-                               if (ch == ARRAY_SIZE(modules))
+                       if (ch <= ARRAY_SIZE(categories)) {
+                               if (ch == ARRAY_SIZE(categories))
                                        continue;
+                               if (categories[ch].count == 0)
+                                       continue;
+
                                curwin = ch;
-                               redraw_module();
+                               print_submenu(&categories[curwin]);
+                               redraw_module(&categories[curwin]);
                                continue;
                        }
                }
 
-               if (ARRAY_SIZE(modules) != 0 && modules[curwin]->handle)
-                       if (modules[curwin]->handle(key))
-                               redraw_module();
+
+               handle_category_key(&categories[curwin], key);
        }
 }
 
@@ -182,12 +271,12 @@ int main(void)
        init_pair(2, COLOR_BLACK, COLOR_WHITE);
        init_pair(3, COLOR_WHITE, COLOR_WHITE);
 
-       modwin = newwin(23, 80, 1, 0);
+       modwin = newwin(SCREEN_Y-2, SCREEN_X, 1, 0);
 
        wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
        wattrset(modwin, COLOR_PAIR(2));
 
-       for (i = 0; i < 23; i++) {
+       for (i = 0; i < SCREEN_Y - 1; i++) {
                wmove(modwin, i - 1, 0);
 
                for (j = 0; j < SCREEN_X; j++)
@@ -196,8 +285,11 @@ int main(void)
 
        refresh();
 
-       for (i = 0; i < ARRAY_SIZE(modules); i++)
-               modules[i]->init();
+       for (i = 0; i < ARRAY_SIZE(categories); i++) {
+               for(j = 0; j < categories[i].count; j++)
+                       categories[i].modules[j]->init();
+
+       }
 
        loop();