d6af39016e9b37377f7217060e251297d8d97931
[coreboot.git] / payloads / coreinfo / nvram_module.c
1 /*
2  * This file is part of the coreinfo project.
3  *
4  * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include "coreinfo.h"
21
22 #ifdef CONFIG_MODULE_NVRAM
23
24 /**
25  * Dump 256 bytes of NVRAM.
26  */
27 static void dump_nvram(WINDOW *win, int row, int col)
28 {
29         int i, x = 0, y = 0;
30
31         for (i = 1; i < 257; i++) {
32                 mvwprintw(win, row + y, col + x, "%02x ", nvram_read(i - 1));
33                 x += 3;
34                 if (i % 16 == 0) {
35                         y++;    /* Start a newline after 16 bytes. */
36                         x = 0;
37                 }
38                 if (i % 64 == 0) {
39                         y++;    /* Add an empty line after 64 bytes. */
40                         x = 0;
41                 }
42         }
43 }
44
45 static int nvram_module_redraw(WINDOW *win)
46 {
47         print_module_title(win, "NVRAM Dump");
48         dump_nvram(win, 2, 1);
49         return 0;
50 }
51
52 static int nvram_module_init(void)
53 {
54         return 0;
55 }
56
57 struct coreinfo_module nvram_module = {
58         .name = "NVRAM",
59         .init = nvram_module_init,
60         .redraw = nvram_module_redraw,
61 };
62
63 #else
64
65 struct coreinfo_module nvram_module = {
66 };
67
68 #endif