summaryrefslogtreecommitdiff
path: root/util/amdfwtool
diff options
context:
space:
mode:
authorZheng Bao <fishbaozi@gmail.com>2021-09-13 18:00:09 +0800
committerPatrick Georgi <pgeorgi@google.com>2021-09-23 06:26:47 +0000
commitb1fb8cebf8de061b6c29f9504293e838d5638f74 (patch)
treef281694ca34696d5aac02f3ee35046225d5469da /util/amdfwtool
parent425fdeb2f9e530ff3670a68a25a668bb47d66dde (diff)
amdfwtool: Add an optional column of level
The value of level defined in table is the default one. We now give an extra option in config file to change this value so some FWs can be dropped in a more optimized way. For the non A/B recovery mode, The value could be L1, L2, Lb or Lx, which are level 1, leve 2, level both and using default value. If it is empty or Lx, left the level in table unchanged. Give a redundant field [12bxBX] in regular exprssion for A/B recovery which will be done later. Change-Id: I0847bc3793467a2299f14d1d2d2486f3f858d7f3 Signed-off-by: Zheng Bao <fishbaozi@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/57612 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'util/amdfwtool')
-rw-r--r--util/amdfwtool/data_parse.c85
1 files changed, 79 insertions, 6 deletions
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c
index 026480f64d..784ee67026 100644
--- a/util/amdfwtool/data_parse.c
+++ b/util/amdfwtool/data_parse.c
@@ -33,6 +33,38 @@ static const char entries_line_regex[] =
"[[:space:]]*$";
static regex_t entries_line_expr;
+static const char entries_lvl_line_regex[] =
+ /* optional whitespace */
+ "^[[:space:]]*"
+ /* followed by a chunk of nonwhitespace for macro field */
+ "([^[:space:]]+)"
+ /* followed by one or more whitespace characters */
+ "[[:space:]]+"
+ /* followed by a chunk of nonwhitespace for filename field */
+ "([^[:space:]]+)"
+ /* followed by one or more whitespace characters */
+ "[[:space:]]+"
+ /* followed by a chunk of nonwhitespace for level field
+ 1st char L: Indicator of field "level"
+ 2nd char:
+ Directory level to be dropped in.
+ 1: Level 1
+ 2: Level 2
+ b: Level both 1&2
+ x: use default value hardcoded in table
+ 3rd char:
+ For A/B recovery. Defined same as 2nd char.
+
+ Examples:
+ L2: Level 2 for normal mode
+ L12: Level 1 for normal mode, level 2 for A/B mode
+ Lx1: Use default value for normal mode, level 1 for A/B mode
+ */
+ "([Ll][12bxBX]{1,2})"
+ /* followed by optional whitespace */
+ "[[:space:]]*$";
+static regex_t entries_lvl_line_expr;
+
void compile_reg_expr(int cflags, const char *expr, regex_t *reg)
{
static const size_t ERROR_BUF_SIZE = 256;
@@ -46,11 +78,30 @@ void compile_reg_expr(int cflags, const char *expr, regex_t *reg)
}
}
+#define SET_LEVEL(tableptr, l, TABLE) \
+ do { \
+ switch ((l)) { \
+ case '1': \
+ (tableptr)->level = TABLE##_LVL1;\
+ break; \
+ case '2': \
+ (tableptr)->level = TABLE##_LVL2;\
+ break; \
+ case 'b': \
+ case 'B': \
+ (tableptr)->level = TABLE##_BOTH;\
+ break; \
+ default: \
+ /* use default value */ \
+ break; \
+ } \
+ } while (0)
+
extern amd_fw_entry amd_psp_fw_table[];
extern amd_bios_entry amd_bios_table[];
static uint8_t find_register_fw_filename_psp_dir(char *fw_name, char *filename,
- amd_cb_config *cb_config)
+ char level_to_set, amd_cb_config *cb_config)
{
amd_fw_type fw_type = AMD_FW_INVALID;
amd_fw_entry *psp_tableptr;
@@ -262,6 +313,7 @@ static uint8_t find_register_fw_filename_psp_dir(char *fw_name, char *filename,
/* instance are not used in PSP table */
if (psp_tableptr->type == fw_type && psp_tableptr->subprog == subprog) {
psp_tableptr->filename = filename;
+ SET_LEVEL(psp_tableptr, level_to_set, PSP);
break;
}
psp_tableptr++;
@@ -274,7 +326,7 @@ static uint8_t find_register_fw_filename_psp_dir(char *fw_name, char *filename,
}
static uint8_t find_register_fw_filename_bios_dir(char *fw_name, char *filename,
- amd_cb_config *cb_config)
+ char level_to_set, amd_cb_config *cb_config)
{
amd_bios_type fw_type = AMD_BIOS_INVALID;
amd_bios_entry *bhd_tableptr;
@@ -338,6 +390,7 @@ static uint8_t find_register_fw_filename_bios_dir(char *fw_name, char *filename,
bhd_tableptr->subpr == subprog &&
bhd_tableptr->inst == instance) {
bhd_tableptr->filename = filename;
+ SET_LEVEL(bhd_tableptr, level_to_set, BDT);
break;
}
bhd_tableptr++;
@@ -379,8 +432,18 @@ static int is_valid_entry(char *oneline, regmatch_t *match)
oneline[match[1].rm_eo] = '\0';
oneline[match[2].rm_eo] = '\0';
retval = 1;
- } else
+ } else if (regexec(&entries_lvl_line_expr, oneline, 4, match, 0) == 0) {
+ /* match[1]: FW type
+ match[2]: FW filename
+ match[3]: Directory level to be dropped
+ */
+ oneline[match[1].rm_eo] = '\0';
+ oneline[match[2].rm_eo] = '\0';
+ oneline[match[3].rm_eo] = '\0';
+ retval = 1;
+ } else {
retval = 0;
+ }
return retval;
}
@@ -409,7 +472,7 @@ static int skip_comment_blank_line(char *oneline)
uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps)
{
char oneline[MAX_LINE_SIZE], *path_filename;
- regmatch_t match[N_MATCHES];
+ regmatch_t match[N_MATCHES] = {0};
char dir[MAX_LINE_SIZE] = {'\0'};
uint32_t dir_len;
@@ -417,6 +480,8 @@ uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_dep
blank_or_comment_regex, &blank_or_comment_expr);
compile_reg_expr(REG_EXTENDED | REG_NEWLINE,
entries_line_regex, &entries_line_expr);
+ compile_reg_expr(REG_EXTENDED | REG_NEWLINE,
+ entries_lvl_line_regex, &entries_lvl_line_expr);
/* Get a line */
/* Get FIRMWARE_LOCATION in the first loop */
@@ -450,17 +515,25 @@ uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_dep
if (strcmp(&(oneline[match[1].rm_so]), "FIRMWARE_LOCATION") == 0) {
continue;
} else {
+ char ch_lvl = 'x';
path_filename = malloc(MAX_LINE_SIZE * 2 + 2);
snprintf(path_filename, MAX_LINE_SIZE * 2 + 2, "%.*s/%.*s",
MAX_LINE_SIZE, dir, MAX_LINE_SIZE,
&(oneline[match[2].rm_so]));
+ /* If the optional level field is present,
+ extract the level char. */
+ if (match[3].rm_so != 0) {
+ ch_lvl = oneline[match[3].rm_so + 1];
+ }
+
if (find_register_fw_filename_psp_dir(
&(oneline[match[1].rm_so]),
- path_filename, cb_config) == 0) {
+ path_filename, ch_lvl, cb_config) == 0) {
if (find_register_fw_filename_bios_dir(
&(oneline[match[1].rm_so]),
- path_filename, cb_config) == 0) {
+ path_filename, ch_lvl, cb_config)
+ == 0) {
fprintf(stderr, "Module's name \"%s\" is not valid\n", oneline);
return 0; /* Stop parsing. */
} else {