Fix the case where the user selects no modules in Kconfig at all.
[coreboot.git] / payloads / coreinfo / coreinfo.c
index 09a405d83b06d6757a0f891d1a6948170e371552..40c4d07cba1172239cb01177182212ae24cf5e56 100644 (file)
 extern struct coreinfo_module cpuinfo_module;
 extern struct coreinfo_module pci_module;
 extern struct coreinfo_module coreboot_module;
+extern struct coreinfo_module nvram_module;
 
 struct coreinfo_module *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
 };
 
 static WINDOW *modwin;
@@ -62,7 +72,18 @@ static void print_menu(void)
        for (i = 0; i < ARRAY_SIZE(modules); i++)
                ptr += sprintf(ptr, "F%d: %s ", i + 1, modules[i]->name);
 
-       mvprintw(23, 0, menu);
+       if (ARRAY_SIZE(modules) != 0)
+               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)));
+#endif
 }
 
 static void center(int row, const char *str)
@@ -101,6 +122,9 @@ static void header(int row, const char *str)
 
 static void redraw_module(void)
 {
+       if (ARRAY_SIZE(modules) == 0)
+               return;
+
        wclear(modwin);
        modules[curwin]->redraw(modwin);
        refresh();
@@ -113,7 +137,8 @@ static void loop(void)
        center(0, "coreinfo v0.1");
 
        print_menu();
-       modules[curwin]->redraw(modwin);
+       if (ARRAY_SIZE(modules) != 0)
+               modules[curwin]->redraw(modwin);
        refresh();
 
        while (1) {
@@ -125,14 +150,16 @@ 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(modules))
+                                       continue;
                                curwin = ch;
                                redraw_module();
                                continue;
                        }
                }
 
-               if (modules[curwin]->handle)
+               if (ARRAY_SIZE(modules) != 0 && modules[curwin]->handle)
                        if (modules[curwin]->handle(key))
                                redraw_module();
        }