cbfstool: Add update-fit command

Add support for filling in the Firmware Interface Table.
For now it only supports adding microcode entries.

It takes 2 options:
1. Name of file in cbfs where the mircocode is located
2. The number of empty entries in the table.

Verified with go firmware tools. Also commented out updating
microcode in the bootblock. When romstage runs, the CPUs indicate
their microcode is already loaded.

Change-Id: Iaccaa9c226ee24868a5f4c0ba79729015d15bbef
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2712
Reviewed-by: Aaron Durbin <adurbin@google.com>
Tested-by: build bot (Jenkins)
This commit is contained in:
Aaron Durbin
2012-12-14 17:16:21 -06:00
committed by Stefan Reinauer
parent dc7bc8e589
commit 6b0d0d6e14
5 changed files with 343 additions and 1 deletions

View File

@@ -28,6 +28,7 @@
#include "common.h"
#include "cbfs.h"
#include "cbfs_image.h"
#include "fit.h"
struct command {
const char *name;
@@ -53,6 +54,7 @@ static struct param {
uint32_t pagesize;
uint32_t offset;
uint32_t top_aligned;
int fit_empty_entries;
comp_algo algo;
} param = {
/* All variables not listed are initialized as zero. */
@@ -415,6 +417,36 @@ static int cbfs_extract(void)
return result;
}
static int cbfs_update_fit(void)
{
int ret = 0;
struct cbfs_image image;
if (!param.name) {
ERROR("You need to specify -n/--name.\n");
return 1;
}
if (param.fit_empty_entries <= 0) {
ERROR("Invalid number of fit entries "
"(-x/--empty-fits): %d\n", param.fit_empty_entries);
return 1;
}
if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
}
ret = fit_update_table(&image, param.fit_empty_entries, param.name);
if (!ret)
ret = cbfs_image_write_file(&image, param.cbfs_name);
cbfs_image_delete(&image);
return ret;
}
static const struct command commands[] = {
{"add", "f:n:t:b:vh?", cbfs_add},
{"add-payload", "f:n:t:c:b:vh?", cbfs_add_payload},
@@ -425,6 +457,7 @@ static const struct command commands[] = {
{"locate", "f:n:P:a:Tvh?", cbfs_locate},
{"print", "vh?", cbfs_print},
{"extract", "n:f:vh?", cbfs_extract},
{"update-fit", "n:x:vh?", cbfs_update_fit},
};
static struct option long_options[] = {
@@ -442,6 +475,7 @@ static struct option long_options[] = {
{"offset", required_argument, 0, 'o' },
{"file", required_argument, 0, 'f' },
{"arch", required_argument, 0, 'm' },
{"empty-fits", required_argument, 0, 'x' },
{"verbose", no_argument, 0, 'v' },
{"help", no_argument, 0, 'h' },
{NULL, 0, 0, 0 }
@@ -476,6 +510,8 @@ static void usage(char *name)
"Show the contents of the ROM\n"
" extract -n NAME -f FILE "
"Extracts a raw payload from ROM\n"
" update-fit -n MICROCODE_BLOB_NAME -x EMTPY_FIT_ENTRIES\n "
"Updates the FIT table with microcode entries\n"
"\n"
"ARCHes:\n"
" armv7, x86\n"
@@ -586,6 +622,9 @@ int main(int argc, char **argv)
case 'T':
param.top_aligned = 1;
break;
case 'x':
param.fit_empty_entries = strtol(optarg, NULL, 0);
break;
case 'v':
verbose++;
break;