Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 2 | * |
| 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 Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include "coreinfo.h" |
| 16 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 17 | #if CONFIG(MODULE_NVRAM) |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Dump 256 bytes of NVRAM. |
| 21 | */ |
| 22 | static void dump_nvram(WINDOW *win, int row, int col) |
| 23 | { |
| 24 | int i, x = 0, y = 0; |
| 25 | |
Uwe Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 26 | /* Print vertical and horizontal index numbers. */ |
| 27 | for (i = 0; i < 16; i++) { |
Jonathan Neuschäfer | 71d3101 | 2016-03-10 09:57:28 +0100 | [diff] [blame] | 28 | mvwprintw(win, ((i < 8) ? 4 : 5) + i, 1, "%2.2X ", i * 0x10); |
Uwe Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 29 | 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 Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 34 | mvwaddch(win, 3 + i, 3, ACS_VLINE); |
Uwe Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 35 | for (i = 0; i < 48; i++) |
Ulf Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 36 | mvwaddch(win, 3, 3 + i, (i == 0) ? ACS_ULCORNER : ACS_HLINE); |
Uwe Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 37 | |
| 38 | /* Dump NVRAM contents. */ |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 39 | 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 Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 46 | if (i % 128 == 0) { |
| 47 | y++; /* Add an empty line after 128 bytes. */ |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 48 | x = 0; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | static int nvram_module_redraw(WINDOW *win) |
| 54 | { |
| 55 | print_module_title(win, "NVRAM Dump"); |
Uwe Hermann | 16acf8b | 2008-04-22 16:56:21 +0000 | [diff] [blame] | 56 | dump_nvram(win, 4, 4); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int nvram_module_init(void) |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | struct coreinfo_module nvram_module = { |
| 66 | .name = "NVRAM", |
| 67 | .init = nvram_module_init, |
| 68 | .redraw = nvram_module_redraw, |
| 69 | }; |
| 70 | |
| 71 | #else |
| 72 | |
| 73 | struct coreinfo_module nvram_module = { |
| 74 | }; |
| 75 | |
| 76 | #endif |