Quickfix to repair 'make clean; make menuconfig' (trivial).
[coreboot.git] / payloads / coreinfo / lar_module.c
1 /*
2  * This file is part of the coreinfo project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
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_LAR
23
24 static struct LAR *lar;
25 static int lcount;
26 static char **lnames;
27
28 static int lar_module_init(void)
29 {
30         int index = 0;
31         struct larent *larent;
32
33         lar = openlar(NULL);
34
35         if (lar == NULL)
36                 return 0;
37
38         while((larent = readlar(lar)))
39                 lcount++;
40
41         lnames = malloc(lcount * sizeof(char *));
42
43         if (lnames == NULL)
44                 return 0;
45
46         rewindlar(lar);
47
48         while((larent = readlar(lar)))
49                 lnames[index++] = strdup((const char *) larent->name);
50
51         return 0;
52 }
53
54 static int selected;
55
56 static int lar_module_redraw(WINDOW *win)
57 {
58         int i;
59         int row = 2;
60         struct larstat stat;
61
62         print_module_title(win, "LAR Listing");
63
64         if (lar == 0) {
65                 mvwprintw(win, 11, 61/2,  "Bad or missing LAR");
66                 return 0;
67         }
68
69         /* Draw a line down the middle */
70
71         for(i = 2; i < 20; i++) {
72                 wmove(win, i, 30);
73                 waddch(win, '\263');
74         }
75
76         /* Draw the names down the left side */
77
78         for(i = 0; i < lcount; i++) {
79                 if (i == selected)
80                         wattrset(win, COLOR_PAIR(3) | A_BOLD);
81                 else
82                         wattrset(win, COLOR_PAIR(2));
83
84                 mvwprintw(win, 2 + i, 1, "%.25s", lnames[i]);
85         }
86
87         /* Get the information for the LAR */
88
89         if (larstat(lar, lnames[selected], &stat)) {
90                 printf("larstat failed\n");
91                 return 0;
92         }
93
94         wattrset(win, COLOR_PAIR(2));
95
96         mvwprintw(win, row++, 32, "Offset: 0x%x", stat.offset);
97
98         if (stat.compression) {
99                 switch(stat.compression) {
100                 case ALGO_LZMA:
101                         mvwprintw(win, row++, 32, "Compression: LZMA");
102                         break;
103                 case ALGO_NRV2B:
104                         mvwprintw(win, row++, 32, "Compression: NRV2B");
105                         break;
106                 case ALGO_ZEROES:
107                         mvwprintw(win, row++, 32, "Compression: zeroes");
108                         break;
109                 }
110
111                 mvwprintw(win, row++, 32, "Compressed length: %d", stat.len);
112                 mvwprintw(win, row++, 32, "Compressed checksum: 0x%x", stat.compchecksum);
113         }
114
115         mvwprintw(win, row++, 32, "Length: %d", stat.reallen);
116         mvwprintw(win, row++, 32, "Checksum: 0x%x", stat.checksum);
117         mvwprintw(win, row++, 32, "Load Address: 0x%llx", stat.loadaddress);
118         mvwprintw(win, row++, 32, "Entry Point: 0x%llx", stat.entry);
119
120         return 0;
121 }
122
123 static int lar_module_handle(int key)
124 {
125         int ret = 0;
126
127         if (lar == NULL)
128                 return 0;
129
130         switch (key) {
131         case KEY_DOWN:
132                 if (selected + 1 < lcount) {
133                         selected++;
134                         ret = 1;
135                 }
136                 break;
137         case KEY_UP:
138                 if (selected > 0) {
139                         selected--;
140                         ret = 1;
141                 }
142                 break;
143         }
144
145         return ret;
146 }
147
148 struct coreinfo_module lar_module = {
149         .name = "LAR",
150         .init = lar_module_init,
151         .redraw = lar_module_redraw,
152         .handle = lar_module_handle
153 };
154 #else
155
156 struct coreinfo_module lar_module = {
157 };
158
159 #endif
160
161
162
163