blob: 52f127af88dffac4a9604a76463047ec5187c9f1 [file] [log] [blame]
Uwe Hermannab5b3e02008-03-31 20:30:18 +00001/*
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 */
27static void dump_nvram(WINDOW *win, int row, int col)
28{
29 int i, x = 0, y = 0;
30
Uwe Hermann16acf8b2008-04-22 16:56:21 +000031 /* Print vertical and horizontal index numbers. */
32 for (i = 0; i < 16; i++) {
33 mvwprintw(win, ((i < 8) ? 4 : 5) + i, 1, "%2.2X ", i);
34 mvwprintw(win, 2, 4 + (i * 3), "%2.2X ", i);
35 }
36
37 /* Print vertical and horizontal line. */
38 for (i = 0; i < 18; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000039 mvwaddch(win, 3 + i, 3, ACS_VLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000040 for (i = 0; i < 48; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000041 mvwaddch(win, 3, 3 + i, (i == 0) ? ACS_ULCORNER : ACS_HLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000042
43 /* Dump NVRAM contents. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000044 for (i = 1; i < 257; i++) {
45 mvwprintw(win, row + y, col + x, "%02x ", nvram_read(i - 1));
46 x += 3;
47 if (i % 16 == 0) {
48 y++; /* Start a newline after 16 bytes. */
49 x = 0;
50 }
Uwe Hermann16acf8b2008-04-22 16:56:21 +000051 if (i % 128 == 0) {
52 y++; /* Add an empty line after 128 bytes. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000053 x = 0;
54 }
55 }
56}
57
58static int nvram_module_redraw(WINDOW *win)
59{
60 print_module_title(win, "NVRAM Dump");
Uwe Hermann16acf8b2008-04-22 16:56:21 +000061 dump_nvram(win, 4, 4);
Uwe Hermannab5b3e02008-03-31 20:30:18 +000062 return 0;
63}
64
65static int nvram_module_init(void)
66{
67 return 0;
68}
69
70struct coreinfo_module nvram_module = {
71 .name = "NVRAM",
72 .init = nvram_module_init,
73 .redraw = nvram_module_redraw,
74};
75
76#else
77
78struct coreinfo_module nvram_module = {
79};
80
81#endif