2020-09-08 20:25:44 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-07-07 17:10:13 +02:00
|
|
|
|
|
|
|
#include "coreinfo.h"
|
2012-03-19 11:06:46 +01:00
|
|
|
#include "endian.h"
|
2009-07-07 17:10:13 +02:00
|
|
|
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(MODULE_CBFS)
|
2009-07-07 17:10:13 +02:00
|
|
|
|
2016-04-29 19:45:43 +02:00
|
|
|
#define FILES_VISIBLE 19
|
|
|
|
|
2009-07-07 17:10:13 +02:00
|
|
|
#define HEADER_MAGIC 0x4F524243
|
|
|
|
#define HEADER_ADDR 0xfffffffc
|
|
|
|
#define LARCHIVE_MAGIC 0x455649484352414cLL /* "LARCHIVE" */
|
|
|
|
|
|
|
|
#define COMPONENT_DELETED 0x00
|
2016-03-10 05:37:27 +01:00
|
|
|
#define COMPONENT_BOOTBLOCK 0x01
|
|
|
|
#define COMPONENT_CBFSHEADER 0x02
|
2009-07-07 17:10:13 +02:00
|
|
|
#define COMPONENT_STAGE 0x10
|
2018-05-02 09:44:08 +02:00
|
|
|
#define COMPONENT_SELF 0x20
|
2018-04-26 09:35:13 +02:00
|
|
|
#define COMPONENT_FIT 0x21
|
2009-07-07 17:10:13 +02:00
|
|
|
#define COMPONENT_OPTIONROM 0x30
|
2016-03-10 05:37:27 +01:00
|
|
|
#define COMPONENT_RAW 0x50
|
|
|
|
#define COMPONENT_MICROCODE 0x53
|
|
|
|
#define COMPONENT_CMOS_LAYOUT 0x1aa
|
2009-07-07 17:10:13 +02:00
|
|
|
#define COMPONENT_NULL 0xffffffff
|
|
|
|
|
|
|
|
struct cbheader {
|
|
|
|
u32 magic;
|
|
|
|
u32 version;
|
|
|
|
u32 romsize;
|
|
|
|
u32 bootblocksize;
|
|
|
|
u32 align;
|
|
|
|
u32 offset;
|
2012-11-16 23:48:22 +01:00
|
|
|
u32 architecture;
|
|
|
|
u32 pad[1];
|
2017-07-13 02:20:27 +02:00
|
|
|
} __packed;
|
2009-07-07 17:10:13 +02:00
|
|
|
|
|
|
|
struct cbfile {
|
|
|
|
u64 magic;
|
|
|
|
u32 len;
|
|
|
|
u32 type;
|
|
|
|
u32 checksum;
|
|
|
|
u32 offset;
|
|
|
|
char filename[0];
|
2017-07-13 02:20:27 +02:00
|
|
|
} __packed;
|
2009-07-07 17:10:13 +02:00
|
|
|
|
2016-04-29 19:45:43 +02:00
|
|
|
static int filecount = 0, selected = 0, start_row = 0;
|
2009-07-07 17:10:13 +02:00
|
|
|
static char **filenames;
|
|
|
|
static struct cbheader *header = NULL;
|
|
|
|
|
|
|
|
static struct cbfile *getfile(struct cbfile *f)
|
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
if (f < (struct cbfile *)(0xffffffff - ntohl(header->romsize)))
|
|
|
|
return NULL;
|
|
|
|
if (f->magic == 0)
|
|
|
|
return NULL;
|
|
|
|
if (f->magic == LARCHIVE_MAGIC)
|
|
|
|
return f;
|
2018-10-29 16:01:53 +01:00
|
|
|
f = (struct cbfile *)((u8 *)f + ntohl(header->align));
|
2009-07-07 17:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cbfile *firstfile(void)
|
|
|
|
{
|
|
|
|
return getfile((void *)(0 - ntohl(header->romsize) +
|
|
|
|
ntohl(header->offset)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cbfile *nextfile(struct cbfile *f)
|
|
|
|
{
|
2018-10-29 16:01:53 +01:00
|
|
|
f = (struct cbfile *)((u8 *)f + ALIGN(ntohl(f->len) + ntohl(f->offset),
|
|
|
|
ntohl(header->align)));
|
2009-07-07 17:10:13 +02:00
|
|
|
return getfile(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cbfile *findfile(const char *filename)
|
|
|
|
{
|
|
|
|
struct cbfile *f;
|
|
|
|
for (f = firstfile(); f; f = nextfile(f)) {
|
|
|
|
if (strcmp(filename, f->filename) == 0)
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cbfs_module_init(void)
|
|
|
|
{
|
|
|
|
struct cbfile *f;
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
header = *(void **)HEADER_ADDR;
|
|
|
|
if (header->magic != ntohl(HEADER_MAGIC)) {
|
|
|
|
header = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (f = firstfile(); f; f = nextfile(f))
|
|
|
|
filecount++;
|
|
|
|
|
|
|
|
filenames = malloc(filecount * sizeof(char *));
|
|
|
|
if (filenames == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (f = firstfile(); f; f = nextfile(f))
|
|
|
|
filenames[index++] = strdup((const char *)f->filename);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cbfs_module_redraw(WINDOW * win)
|
|
|
|
{
|
|
|
|
struct cbfile *f;
|
2016-04-29 19:45:43 +02:00
|
|
|
int i, row, frow;
|
2009-07-07 17:10:13 +02:00
|
|
|
|
|
|
|
print_module_title(win, "CBFS Listing");
|
|
|
|
|
|
|
|
if (!header) {
|
|
|
|
mvwprintw(win, 11, 61 / 2, "Bad or missing CBFS header");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw a line down the middle. */
|
|
|
|
for (i = 2; i < 21; i++)
|
|
|
|
mvwaddch(win, i, 30, ACS_VLINE);
|
|
|
|
|
|
|
|
/* Draw the names down the left side. */
|
2016-04-29 19:45:43 +02:00
|
|
|
for (frow = 0; frow < FILES_VISIBLE; frow++) {
|
|
|
|
row = 2 + frow;
|
|
|
|
i = start_row + frow;
|
|
|
|
if (i >= filecount)
|
|
|
|
break;
|
2009-07-07 17:10:13 +02:00
|
|
|
if (i == selected)
|
|
|
|
wattrset(win, COLOR_PAIR(3) | A_BOLD);
|
|
|
|
else
|
|
|
|
wattrset(win, COLOR_PAIR(2));
|
2016-03-10 04:32:46 +01:00
|
|
|
|
|
|
|
if (strlen(filenames[i]) == 0) {
|
|
|
|
if (findfile(filenames[i])->type == COMPONENT_NULL)
|
2016-04-29 19:45:43 +02:00
|
|
|
mvwprintw(win, row, 1, "<free space>");
|
2016-03-10 04:32:46 +01:00
|
|
|
else
|
2016-04-29 19:45:43 +02:00
|
|
|
mvwprintw(win, row, 1, "<unnamed>");
|
2016-03-10 04:32:46 +01:00
|
|
|
} else {
|
2016-04-29 19:45:43 +02:00
|
|
|
mvwprintw(win, row, 1, "%.25s", filenames[i]);
|
|
|
|
}
|
|
|
|
/* show scroll arrows */
|
|
|
|
if (frow == 0 && start_row > 0) {
|
|
|
|
wattrset(win, COLOR_PAIR(2));
|
|
|
|
mvwaddch(win, row, 28, ACS_UARROW);
|
|
|
|
}
|
|
|
|
if (frow == FILES_VISIBLE - 1 && i != filecount - 1) {
|
|
|
|
wattrset(win, COLOR_PAIR(2));
|
|
|
|
mvwaddch(win, row, 28, ACS_DARROW);
|
2016-03-10 04:32:46 +01:00
|
|
|
}
|
2009-07-07 17:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
f = findfile(filenames[selected]);
|
|
|
|
if (!f) {
|
|
|
|
mvwprintw(win, 11, 32, "ERROR: CBFS component not found");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wattrset(win, COLOR_PAIR(2));
|
|
|
|
|
2016-04-29 19:45:43 +02:00
|
|
|
/* Draw the file information */
|
|
|
|
row = 2;
|
2009-07-07 17:10:13 +02:00
|
|
|
/* mvwprintw(win, row++, 32, "Offset: 0x%x", f->offset); *//* FIXME */
|
|
|
|
mvwprintw(win, row, 32, "Type: ");
|
|
|
|
switch (ntohl(f->type)) {
|
2016-03-10 05:37:27 +01:00
|
|
|
case COMPONENT_BOOTBLOCK:
|
|
|
|
mvwprintw(win, row++, 38, "bootblock");
|
|
|
|
break;
|
|
|
|
case COMPONENT_CBFSHEADER:
|
|
|
|
mvwprintw(win, row++, 38, "CBFS header");
|
|
|
|
break;
|
2009-07-07 17:10:13 +02:00
|
|
|
case COMPONENT_STAGE:
|
|
|
|
mvwprintw(win, row++, 38, "stage");
|
|
|
|
break;
|
2018-05-02 09:44:08 +02:00
|
|
|
case COMPONENT_SELF:
|
2018-05-16 03:05:07 +02:00
|
|
|
mvwprintw(win, row++, 38, "simple ELF");
|
2009-07-07 17:10:13 +02:00
|
|
|
break;
|
2018-04-26 09:35:13 +02:00
|
|
|
case COMPONENT_FIT:
|
|
|
|
mvwprintw(win, row++, 38, "FIT");
|
|
|
|
break;
|
2009-07-07 17:10:13 +02:00
|
|
|
case COMPONENT_OPTIONROM:
|
|
|
|
mvwprintw(win, row++, 38, "optionrom");
|
|
|
|
break;
|
2016-03-10 05:37:27 +01:00
|
|
|
case COMPONENT_RAW:
|
|
|
|
mvwprintw(win, row++, 38, "raw");
|
|
|
|
break;
|
|
|
|
case COMPONENT_MICROCODE:
|
|
|
|
mvwprintw(win, row++, 38, "microcode");
|
|
|
|
break;
|
|
|
|
case COMPONENT_CMOS_LAYOUT:
|
|
|
|
mvwprintw(win, row++, 38, "cmos layout");
|
|
|
|
break;
|
2009-07-07 17:10:13 +02:00
|
|
|
case COMPONENT_NULL:
|
|
|
|
mvwprintw(win, row++, 38, "free");
|
|
|
|
break;
|
|
|
|
case COMPONENT_DELETED:
|
|
|
|
mvwprintw(win, row++, 38, "deleted");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mvwprintw(win, row++, 38, "Unknown (0x%x)", ntohl(f->type));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mvwprintw(win, row++, 32, "Size: %d", ntohl(f->len));
|
|
|
|
mvwprintw(win, row++, 32, "Checksum: 0x%x", ntohl(f->checksum));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cbfs_module_handle(int key)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (filecount == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (key) {
|
|
|
|
case KEY_DOWN:
|
|
|
|
if (selected + 1 < filecount) {
|
|
|
|
selected++;
|
2016-04-29 19:45:43 +02:00
|
|
|
if (selected >= start_row + FILES_VISIBLE - 1)
|
|
|
|
start_row = selected - (FILES_VISIBLE - 1);
|
2009-07-07 17:10:13 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
if (selected > 0) {
|
|
|
|
selected--;
|
2016-04-29 19:45:43 +02:00
|
|
|
if (selected < start_row)
|
|
|
|
start_row = selected;
|
2009-07-07 17:10:13 +02:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct coreinfo_module cbfs_module = {
|
|
|
|
.name = "CBFS",
|
|
|
|
.init = cbfs_module_init,
|
|
|
|
.redraw = cbfs_module_redraw,
|
|
|
|
.handle = cbfs_module_handle
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
struct coreinfo_module cbfs_module = {
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|