blob: 9ac734a76cea659df17f8a68e7cb4ad00b256b11 [file] [log] [blame]
Uwe Hermannab5b3e02008-03-31 20:30:18 +00001/*
Uwe Hermannab5b3e02008-03-31 20:30:18 +00002 *
3 * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Uwe Hermannab5b3e02008-03-31 20:30:18 +000013 */
14
15#include "coreinfo.h"
16
Julius Wernereab2a292019-03-05 16:55:15 -080017#if CONFIG(MODULE_NVRAM)
Uwe Hermannab5b3e02008-03-31 20:30:18 +000018
19/**
20 * Dump 256 bytes of NVRAM.
21 */
22static void dump_nvram(WINDOW *win, int row, int col)
23{
24 int i, x = 0, y = 0;
25
Uwe Hermann16acf8b2008-04-22 16:56:21 +000026 /* Print vertical and horizontal index numbers. */
27 for (i = 0; i < 16; i++) {
Jonathan Neuschäfer71d31012016-03-10 09:57:28 +010028 mvwprintw(win, ((i < 8) ? 4 : 5) + i, 1, "%2.2X ", i * 0x10);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000029 mvwprintw(win, 2, 4 + (i * 3), "%2.2X ", i);
30 }
31
32 /* Print vertical and horizontal line. */
33 for (i = 0; i < 18; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000034 mvwaddch(win, 3 + i, 3, ACS_VLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000035 for (i = 0; i < 48; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000036 mvwaddch(win, 3, 3 + i, (i == 0) ? ACS_ULCORNER : ACS_HLINE);
Uwe Hermann16acf8b2008-04-22 16:56:21 +000037
38 /* Dump NVRAM contents. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000039 for (i = 1; i < 257; i++) {
40 mvwprintw(win, row + y, col + x, "%02x ", nvram_read(i - 1));
41 x += 3;
42 if (i % 16 == 0) {
43 y++; /* Start a newline after 16 bytes. */
44 x = 0;
45 }
Uwe Hermann16acf8b2008-04-22 16:56:21 +000046 if (i % 128 == 0) {
47 y++; /* Add an empty line after 128 bytes. */
Uwe Hermannab5b3e02008-03-31 20:30:18 +000048 x = 0;
49 }
50 }
51}
52
53static int nvram_module_redraw(WINDOW *win)
54{
55 print_module_title(win, "NVRAM Dump");
Uwe Hermann16acf8b2008-04-22 16:56:21 +000056 dump_nvram(win, 4, 4);
Uwe Hermannab5b3e02008-03-31 20:30:18 +000057 return 0;
58}
59
60static int nvram_module_init(void)
61{
62 return 0;
63}
64
65struct coreinfo_module nvram_module = {
66 .name = "NVRAM",
67 .init = nvram_module_init,
68 .redraw = nvram_module_redraw,
69};
70
71#else
72
73struct coreinfo_module nvram_module = {
74};
75
76#endif