blob: 799791134ad68d526efbe3ad4bab69980fc7d401 [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.
Uwe Hermannab5b3e02008-03-31 20:30:18 +000014 */
15
16#include "coreinfo.h"
17
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070018#if IS_ENABLED(CONFIG_MODULE_NVRAM)
Uwe Hermannab5b3e02008-03-31 20:30:18 +000019
20/**
21 * Dump 256 bytes of NVRAM.
22 */
23static void dump_nvram(WINDOW *win, int row, int col)
24{
25 int i, x = 0, y = 0;
26
Uwe Hermann16acf8b2008-04-22 16:56:21 +000027 /* Print vertical and horizontal index numbers. */
28 for (i = 0; i < 16; i++) {
Jonathan Neuschäfer71d31012016-03-10 09:57:28 +010029 mvwprintw(win, ((i < 8) ? 4 : 5) + i, 1, "%2.2X ", i * 0x10);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000030 mvwprintw(win, 2, 4 + (i * 3), "%2.2X ", i);
31 }
32
33 /* Print vertical and horizontal line. */
34 for (i = 0; i < 18; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000035 mvwaddch(win, 3 + i, 3, ACS_VLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000036 for (i = 0; i < 48; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000037 mvwaddch(win, 3, 3 + i, (i == 0) ? ACS_ULCORNER : ACS_HLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000038
39 /* Dump NVRAM contents. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000040 for (i = 1; i < 257; i++) {
41 mvwprintw(win, row + y, col + x, "%02x ", nvram_read(i - 1));
42 x += 3;
43 if (i % 16 == 0) {
44 y++; /* Start a newline after 16 bytes. */
45 x = 0;
46 }
Uwe Hermann16acf8b2008-04-22 16:56:21 +000047 if (i % 128 == 0) {
48 y++; /* Add an empty line after 128 bytes. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000049 x = 0;
50 }
51 }
52}
53
54static int nvram_module_redraw(WINDOW *win)
55{
56 print_module_title(win, "NVRAM Dump");
Uwe Hermann16acf8b2008-04-22 16:56:21 +000057 dump_nvram(win, 4, 4);
Uwe Hermannab5b3e02008-03-31 20:30:18 +000058 return 0;
59}
60
61static int nvram_module_init(void)
62{
63 return 0;
64}
65
66struct coreinfo_module nvram_module = {
67 .name = "NVRAM",
68 .init = nvram_module_init,
69 .redraw = nvram_module_redraw,
70};
71
72#else
73
74struct coreinfo_module nvram_module = {
75};
76
77#endif