2 * This file is part of the coreinfo project.
4 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
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.
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.
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
23 #ifdef CONFIG_MODULE_CBFS
25 #define ALIGN(_v, _a) (((_v) + ((_a) - 1)) & ~((_a) - 1))
27 #define HEADER_MAGIC 0x4F524243
28 #define HEADER_ADDR 0xfffffffc
29 #define LARCHIVE_MAGIC 0x455649484352414cLL /* "LARCHIVE" */
31 #define COMPONENT_DELETED 0x00
32 #define COMPONENT_STAGE 0x10
33 #define COMPONENT_PAYLOAD 0x20
34 #define COMPONENT_OPTIONROM 0x30
35 #define COMPONENT_NULL 0xffffffff
46 } __attribute__ ((packed
));
55 } __attribute__ ((packed
));
57 static int filecount
= 0, selected
= 0;
58 static char **filenames
;
59 static struct cbheader
*header
= NULL
;
61 static struct cbfile
*getfile(struct cbfile
*f
)
64 if (f
< (struct cbfile
*)(0xffffffff - ntohl(header
->romsize
)))
68 if (f
->magic
== LARCHIVE_MAGIC
)
70 f
= (void *)f
+ ntohl(header
->align
);
74 static struct cbfile
*firstfile(void)
76 return getfile((void *)(0 - ntohl(header
->romsize
) +
77 ntohl(header
->offset
)));
80 static struct cbfile
*nextfile(struct cbfile
*f
)
82 f
= (void *)f
+ ALIGN(ntohl(f
->len
) + ntohl(f
->offset
),
83 ntohl(header
->align
));
87 static struct cbfile
*findfile(const char *filename
)
90 for (f
= firstfile(); f
; f
= nextfile(f
)) {
91 if (strcmp(filename
, f
->filename
) == 0)
97 static int cbfs_module_init(void)
102 header
= *(void **)HEADER_ADDR
;
103 if (header
->magic
!= ntohl(HEADER_MAGIC
)) {
108 for (f
= firstfile(); f
; f
= nextfile(f
))
111 filenames
= malloc(filecount
* sizeof(char *));
112 if (filenames
== NULL
)
115 for (f
= firstfile(); f
; f
= nextfile(f
))
116 filenames
[index
++] = strdup((const char *)f
->filename
);
121 static int cbfs_module_redraw(WINDOW
* win
)
126 print_module_title(win
, "CBFS Listing");
129 mvwprintw(win
, 11, 61 / 2, "Bad or missing CBFS header");
133 /* Draw a line down the middle. */
134 for (i
= 2; i
< 21; i
++)
135 mvwaddch(win
, i
, 30, ACS_VLINE
);
137 /* Draw the names down the left side. */
138 for (i
= 0; i
< filecount
; i
++) {
140 wattrset(win
, COLOR_PAIR(3) | A_BOLD
);
142 wattrset(win
, COLOR_PAIR(2));
143 if (i
== filecount
- 1)
144 mvwprintw(win
, 2 + i
, 1, "<free space>");
146 mvwprintw(win
, 2 + i
, 1, "%.25s", filenames
[i
]);
149 f
= findfile(filenames
[selected
]);
151 mvwprintw(win
, 11, 32, "ERROR: CBFS component not found");
155 wattrset(win
, COLOR_PAIR(2));
157 /* mvwprintw(win, row++, 32, "Offset: 0x%x", f->offset); *//* FIXME */
158 mvwprintw(win
, row
, 32, "Type: ");
159 switch (ntohl(f
->type
)) {
160 case COMPONENT_STAGE
:
161 mvwprintw(win
, row
++, 38, "stage");
163 case COMPONENT_PAYLOAD
:
164 mvwprintw(win
, row
++, 38, "payload");
166 case COMPONENT_OPTIONROM
:
167 mvwprintw(win
, row
++, 38, "optionrom");
170 mvwprintw(win
, row
++, 38, "free");
172 case COMPONENT_DELETED
:
173 mvwprintw(win
, row
++, 38, "deleted");
176 mvwprintw(win
, row
++, 38, "Unknown (0x%x)", ntohl(f
->type
));
179 mvwprintw(win
, row
++, 32, "Size: %d", ntohl(f
->len
));
180 mvwprintw(win
, row
++, 32, "Checksum: 0x%x", ntohl(f
->checksum
));
185 static int cbfs_module_handle(int key
)
194 if (selected
+ 1 < filecount
) {
210 struct coreinfo_module cbfs_module
= {
212 .init
= cbfs_module_init
,
213 .redraw
= cbfs_module_redraw
,
214 .handle
= cbfs_module_handle
219 struct coreinfo_module cbfs_module
= {