summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@no-log.org>2018-01-12 04:21:14 +0100
committerMartin Roth <martinroth@google.com>2018-01-23 05:21:48 +0000
commitd5dee1e8a0757ba0f9ca5daac67111c5c2e7752e (patch)
tree3576205a17e5e360a2edc5b6ad2b4b9a22e307e8 /util
parentfa0bdfc1207b6675bb1f46708e02aa1462a5ec1d (diff)
downloadcoreboot-d5dee1e8a0757ba0f9ca5daac67111c5c2e7752e.tar.xz
util/bincfg: don't use fp shared variable
Change-Id: Ie710f8c6c06332830c3edb9e5490d1e4877ee33b Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org> Reviewed-on: https://review.coreboot.org/23241 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/bincfg/bincfg.h3
-rw-r--r--util/bincfg/bincfg.y32
2 files changed, 18 insertions, 17 deletions
diff --git a/util/bincfg/bincfg.h b/util/bincfg/bincfg.h
index 35c6e9f17c..b8c668889e 100644
--- a/util/bincfg/bincfg.h
+++ b/util/bincfg/bincfg.h
@@ -39,10 +39,9 @@ struct blob {
static struct field *putsym (char const *, unsigned int);
static struct field *getsym (char const *);
-static void yyerror (char const *);
+static void yyerror (FILE* fp, char const *);
int yylex (void);
-static FILE* fp;
static struct blob *binary;
static struct field *sym_table;
static struct field *sym_table_tail;
diff --git a/util/bincfg/bincfg.y b/util/bincfg/bincfg.y
index 0b4a8815c0..8be11e9a92 100644
--- a/util/bincfg/bincfg.y
+++ b/util/bincfg/bincfg.y
@@ -208,7 +208,7 @@ static void interpret_next_blob_value (struct field *f)
}
/* {}%BIN -> {} */
-static void generate_setter_bitfields(unsigned char *bin)
+static void generate_setter_bitfields(FILE* fp, unsigned char *bin)
{
unsigned int i;
struct field *ptr;
@@ -233,7 +233,7 @@ static void generate_setter_bitfields(unsigned char *bin)
fprintf (fp, "\n}\n");
}
-static void generate_binary_with_gbe_checksum(void)
+static void generate_binary_with_gbe_checksum(FILE* fp)
{
int i;
unsigned short checksum;
@@ -305,7 +305,7 @@ static void generate_binary_with_gbe_checksum(void)
}
/* {}{} -> BIN */
-static void generate_binary(void)
+static void generate_binary(FILE* fp)
{
unsigned int i;
struct field *ptr;
@@ -317,7 +317,7 @@ static void generate_binary(void)
}
if (getsym ("checksum_gbe")) {
- generate_binary_with_gbe_checksum();
+ generate_binary_with_gbe_checksum(fp);
return;
}
@@ -353,6 +353,7 @@ static void generate_binary(void)
unsigned char u8;
unsigned char *u8array;
}
+%parse-param {FILE* fp}
%token <str> name
%token <u32> val
@@ -377,7 +378,7 @@ input:
;
blob:
- '%' eof { generate_setter_bitfields(
+ '%' eof { generate_setter_bitfields(fp,
binary->actualblob); }
;
@@ -400,7 +401,7 @@ specpair:
setter:
'{' '}' { fprintf (stderr, "No values\n"); }
| '{' valuemembers '}' { fprintf (stderr, "Parsed all values\n");
- generate_binary(); }
+ generate_binary(fp); }
;
valuemembers:
@@ -416,7 +417,7 @@ setpair:
%%
/* Called by yyparse on error. */
-static void yyerror (char const *s)
+static void yyerror (FILE* fp, char const *s)
{
fprintf (stderr, "yyerror: %s\n", s);
}
@@ -425,12 +426,12 @@ static void yyerror (char const *s)
void set_input_string(char* in);
/* This function parses a string */
-static int parse_string(unsigned char* in) {
+static int parse_string(FILE* fp, unsigned char* in) {
set_input_string ((char *)in);
- return yyparse ();
+ return yyparse (fp);
}
-static unsigned int loadfile (char *file, char *filetype,
+static unsigned int loadfile (FILE* fp, char *file, char *filetype,
unsigned char **parsestring, unsigned int lenstr)
{
unsigned int lenfile;
@@ -462,6 +463,7 @@ int main (int argc, char *argv[])
unsigned char c;
unsigned int pos = 0;
int ret = 0;
+ FILE* fp;
#if YYDEBUG == 1
yydebug = 1;
@@ -473,8 +475,8 @@ int main (int argc, char *argv[])
/* Compile mode */
/* Load Spec */
- lenspec = loadfile(argv[1], "spec", &parsestring, 0);
- loadfile(argv[2], "setter", &parsestring, lenspec);
+ lenspec = loadfile(fp, argv[1], "spec", &parsestring, 0);
+ loadfile(fp, argv[2], "setter", &parsestring, lenspec);
/* Open output and parse string - output to fp */
if ((fp = fopen(argv[3], "wb")) == NULL) {
@@ -482,13 +484,13 @@ int main (int argc, char *argv[])
argv[3]);
exit(1);
}
- ret = parse_string(parsestring);
+ ret = parse_string(fp, parsestring);
free(parsestring);
} else if (argc == 5 && strcmp (argv[1], "-d") == 0) {
/* Decompile mode */
/* Load Spec */
- lenspec = loadfile(argv[2], "spec", &parsestring, 0);
+ lenspec = loadfile(fp, argv[2], "spec", &parsestring, 0);
parsestring[lenspec] = '%';
parsestring[lenspec + 1] = '\0';
@@ -514,7 +516,7 @@ int main (int argc, char *argv[])
argv[4]);
exit(1);
}
- ret = parse_string(parsestring);
+ ret = parse_string(fp, parsestring);
free(parsestring);
free(binary->actualblob);
fclose(fp);