2020-05-08 19:28:13 +02:00
|
|
|
/* bincfg - Compiler/Decompiler for data blobs with specs */
|
util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
2016-11-16 11:06:54 +01:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-01-10 14:35:55 +01:00
|
|
|
#include "bincfg.tab.h"
|
2016-11-16 11:06:54 +01:00
|
|
|
|
|
|
|
extern struct blob binary;
|
|
|
|
|
|
|
|
unsigned int parsehex (char *s)
|
|
|
|
{
|
2021-02-14 07:19:51 +01:00
|
|
|
unsigned int i, nib, retval = 0;
|
2016-11-16 11:06:54 +01:00
|
|
|
unsigned int nibs = strlen(s) - 2;
|
|
|
|
|
|
|
|
for (i = 2; i < nibs + 2; i++) {
|
|
|
|
if (s[i] >= '0' && s[i] <= '9') {
|
|
|
|
nib = s[i] - '0';
|
|
|
|
} else if (s[i] >= 'a' && s[i] <= 'f') {
|
|
|
|
nib = s[i] - 'a' + 10;
|
|
|
|
} else if (s[i] >= 'A' && s[i] <= 'F') {
|
|
|
|
nib = s[i] - 'A' + 10;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-02-14 07:19:51 +01:00
|
|
|
retval |= nib << (((nibs - 1) - (i - 2)) * 4);
|
2016-11-16 11:06:54 +01:00
|
|
|
}
|
2021-02-14 07:19:51 +01:00
|
|
|
return retval;
|
2016-11-16 11:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char* stripquotes (char *string)
|
|
|
|
{
|
|
|
|
char *stripped;
|
|
|
|
unsigned int len = strlen(string);
|
2017-04-09 01:05:23 +02:00
|
|
|
if (len >= 2 && string[0] == '"' && string[len - 1] == '"') {
|
|
|
|
stripped = (char *) malloc (len - 1);
|
|
|
|
if (stripped == NULL) {
|
|
|
|
printf("Out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
snprintf (stripped, len - 1, "%s", string + 1);
|
2016-11-16 11:06:54 +01:00
|
|
|
return stripped;
|
|
|
|
}
|
2017-04-09 01:05:23 +02:00
|
|
|
return NULL;
|
2016-11-16 11:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%option noyywrap
|
|
|
|
%option nounput
|
|
|
|
|
|
|
|
DIGIT [0-9]
|
2017-04-09 01:05:23 +02:00
|
|
|
INT [-]?{DIGIT}|[-]?[1-9]{DIGIT}+
|
|
|
|
FRAC [.]{DIGIT}+
|
|
|
|
EXP [eE][+-]?{DIGIT}+
|
2016-11-16 11:06:54 +01:00
|
|
|
NUMBER {INT}|{INT}{FRAC}|{INT}{EXP}|{INT}{FRAC}{EXP}
|
2017-04-09 01:05:23 +02:00
|
|
|
HEX [0][x][0-9a-fA-F]+
|
|
|
|
STRING ["][^"]*["]
|
|
|
|
COMMENT [#][^\n]*$
|
2016-11-16 11:06:54 +01:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
{STRING} {
|
|
|
|
yylval.str = stripquotes(yytext);
|
|
|
|
return name;
|
|
|
|
};
|
|
|
|
|
|
|
|
{NUMBER} {
|
|
|
|
yylval.u32 = atoi(yytext);
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
{HEX} {
|
|
|
|
yylval.u32 = parsehex(yytext);
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
\{ {
|
|
|
|
return '{';
|
|
|
|
};
|
|
|
|
|
|
|
|
\} {
|
|
|
|
return '}';
|
|
|
|
};
|
|
|
|
|
|
|
|
\[ {
|
|
|
|
return '[';
|
|
|
|
};
|
|
|
|
|
|
|
|
\] {
|
|
|
|
return ']';
|
|
|
|
};
|
|
|
|
|
|
|
|
, {
|
|
|
|
return ',';
|
|
|
|
};
|
|
|
|
|
|
|
|
: {
|
|
|
|
return ':';
|
|
|
|
};
|
|
|
|
|
|
|
|
= {
|
|
|
|
return '=';
|
|
|
|
};
|
|
|
|
|
|
|
|
[ \t\n]+ /* ignore whitespace */;
|
|
|
|
|
|
|
|
{COMMENT} /* ignore comments */
|
|
|
|
|
|
|
|
\% {
|
|
|
|
return '%';
|
|
|
|
};
|
|
|
|
|
|
|
|
<<EOF>> { return eof; };
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
void set_input_string(char* in) {
|
|
|
|
yy_scan_string(in);
|
|
|
|
}
|