cbfstool: Add an add-int command that adds a raw 64-bit integer CBFS file

This simplifies storing SeaBIOS parameters in CBFS.

Change-Id: I301644ba0d7a9cb5917c37a3b4ceddfa59e34e77
Signed-off-by: Peter Stuge <peter@stuge.se>
Reviewed-on: http://review.coreboot.org/3733
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
Peter Stuge 2013-07-09 19:39:13 +02:00 committed by Patrick Georgi
parent a4e70578db
commit 3bfd5b8252
1 changed files with 60 additions and 0 deletions

View File

@ -42,6 +42,7 @@ static struct param {
char *name; char *name;
char *filename; char *filename;
char *bootblock; char *bootblock;
uint64_t u64val;
uint32_t type; uint32_t type;
uint32_t baseaddress; uint32_t baseaddress;
uint32_t baseaddress_assigned; uint32_t baseaddress_assigned;
@ -63,6 +64,50 @@ static struct param {
typedef int (*convert_buffer_t)(struct buffer *buffer, uint32_t *offset); typedef int (*convert_buffer_t)(struct buffer *buffer, uint32_t *offset);
static int cbfs_add_integer_component(const char *cbfs_name,
const char *name,
uint64_t u64val,
uint32_t offset) {
struct cbfs_image image;
struct buffer buffer;
int i, ret = 1;
if (!name) {
ERROR("You need to specify -n/--name.\n");
return 1;
}
if (buffer_create(&buffer, 8, name) != 0)
return 1;
for (i = 0; i < 8; i++)
buffer.data[i] = (u64val >> i*8) & 0xff;
if (cbfs_image_from_file(&image, cbfs_name) != 0) {
ERROR("Could not load ROM image '%s'.\n", cbfs_name);
buffer_delete(&buffer);
return 1;
}
if (cbfs_get_entry(&image, name)) {
ERROR("'%s' already in ROM image.\n", name);
goto done;
}
if (cbfs_add_entry(&image, &buffer, name, CBFS_COMPONENT_RAW, param.baseaddress) != 0) {
ERROR("Failed to add %llu into ROM image as '%s'.\n", (long long unsigned)u64val, name);
goto done;
}
if (cbfs_image_write_file(&image, cbfs_name) == 0)
ret = 0;
done:
buffer_delete(&buffer);
cbfs_image_delete(&image);
return ret;
}
static int cbfs_add_component(const char *cbfs_name, static int cbfs_add_component(const char *cbfs_name,
const char *filename, const char *filename,
const char *name, const char *name,
@ -227,6 +272,14 @@ static int cbfs_add_flat_binary(void)
cbfstool_convert_mkflatpayload); cbfstool_convert_mkflatpayload);
} }
static int cbfs_add_integer(void)
{
return cbfs_add_integer_component(param.cbfs_name,
param.name,
param.u64val,
param.baseaddress);
}
static int cbfs_remove(void) static int cbfs_remove(void)
{ {
struct cbfs_image image; struct cbfs_image image;
@ -452,6 +505,7 @@ static const struct command commands[] = {
{"add-payload", "f:n:t:c:b:vh?", cbfs_add_payload}, {"add-payload", "f:n:t:c:b:vh?", cbfs_add_payload},
{"add-stage", "f:n:t:c:b:vh?", cbfs_add_stage}, {"add-stage", "f:n:t:c:b:vh?", cbfs_add_stage},
{"add-flat-binary", "f:n:l:e:c:b:vh?", cbfs_add_flat_binary}, {"add-flat-binary", "f:n:l:e:c:b:vh?", cbfs_add_flat_binary},
{"add-int", "i:n:b:vh?", cbfs_add_integer},
{"remove", "n:vh?", cbfs_remove}, {"remove", "n:vh?", cbfs_remove},
{"create", "s:B:b:H:a:o:m:vh?", cbfs_create}, {"create", "s:B:b:H:a:o:m:vh?", cbfs_create},
{"locate", "f:n:P:a:Tvh?", cbfs_locate}, {"locate", "f:n:P:a:Tvh?", cbfs_locate},
@ -474,6 +528,7 @@ static struct option long_options[] = {
{"page-size", required_argument, 0, 'P' }, {"page-size", required_argument, 0, 'P' },
{"offset", required_argument, 0, 'o' }, {"offset", required_argument, 0, 'o' },
{"file", required_argument, 0, 'f' }, {"file", required_argument, 0, 'f' },
{"int", required_argument, 0, 'i' },
{"machine", required_argument, 0, 'm' }, {"machine", required_argument, 0, 'm' },
{"empty-fits", required_argument, 0, 'x' }, {"empty-fits", required_argument, 0, 'x' },
{"verbose", no_argument, 0, 'v' }, {"verbose", no_argument, 0, 'v' },
@ -500,6 +555,8 @@ static void usage(char *name)
" add-flat-binary -f FILE -n NAME -l load-address \\\n" " add-flat-binary -f FILE -n NAME -l load-address \\\n"
" -e entry-point [-c compression] [-b base] " " -e entry-point [-c compression] [-b base] "
"Add a 32bit flat mode binary\n" "Add a 32bit flat mode binary\n"
" add-int -i INTEGER -n NAME [-b base] "
"Add a raw 64-bit integer value\n"
" remove -n NAME " " remove -n NAME "
"Remove a component\n" "Remove a component\n"
" create -s size -B bootblock -m ARCH [-a align] [-o offset] " " create -s size -B bootblock -m ARCH [-a align] [-o offset] "
@ -619,6 +676,9 @@ int main(int argc, char **argv)
case 'f': case 'f':
param.filename = optarg; param.filename = optarg;
break; break;
case 'i':
param.u64val = strtoull(optarg, NULL, 0);
break;
case 'T': case 'T':
param.top_aligned = 1; param.top_aligned = 1;
break; break;