2020-05-08 19:28:13 +02:00
|
|
|
/* parser generator for flashmap descriptor language */
|
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-2.0-only */
|
2015-02-26 20:47:19 +01:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include "fmd_scanner.h"
|
2015-03-18 18:13:48 +01:00
|
|
|
#include "common.h"
|
2015-02-26 20:47:19 +01:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct flashmap_descriptor *res = NULL;
|
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
unsigned intval;
|
|
|
|
char *strval;
|
|
|
|
struct unsigned_option maybe_intval;
|
|
|
|
struct flashmap_descriptor *region_ptr;
|
2019-03-04 07:28:37 +01:00
|
|
|
union flashmap_flags flags;
|
2015-02-26 20:47:19 +01:00
|
|
|
struct descriptor_list region_listhdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
%code requires {
|
|
|
|
#include "fmd.h"
|
|
|
|
#include "option.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
struct descriptor_node {
|
|
|
|
struct flashmap_descriptor *val;
|
|
|
|
struct descriptor_node *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct descriptor_list {
|
|
|
|
size_t len;
|
|
|
|
struct descriptor_node *head;
|
|
|
|
struct descriptor_node *tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct flashmap_descriptor *res;
|
|
|
|
|
2019-03-04 07:28:37 +01:00
|
|
|
struct flashmap_descriptor *parse_descriptor(
|
|
|
|
char *name, union flashmap_flags flags, struct unsigned_option offset,
|
|
|
|
struct unsigned_option size, struct descriptor_list children);
|
2015-02-26 20:47:19 +01:00
|
|
|
void yyerror(const char *s);
|
|
|
|
}
|
|
|
|
|
|
|
|
%token <intval> INTEGER
|
|
|
|
%token OCTAL
|
|
|
|
%token <strval> STRING
|
2019-03-04 07:28:37 +01:00
|
|
|
%token FLAG_CBFS
|
2019-03-04 08:41:09 +01:00
|
|
|
%token FLAG_PRESERVE
|
2015-02-26 20:47:19 +01:00
|
|
|
|
|
|
|
%type <region_ptr> flash_region
|
|
|
|
%type <strval> region_name
|
2019-03-04 07:28:37 +01:00
|
|
|
%type <flags> region_flags_opt
|
|
|
|
%type <flags> region_flags
|
|
|
|
%type <flags> region_flag
|
2015-02-26 20:47:19 +01:00
|
|
|
%type <maybe_intval> region_offset_opt
|
|
|
|
%type <maybe_intval> region_offset
|
|
|
|
%type <maybe_intval> region_size_opt
|
|
|
|
%type <maybe_intval> region_size
|
|
|
|
%type <region_listhdr> region_list_opt
|
|
|
|
%type <region_listhdr> region_list
|
|
|
|
%type <region_listhdr> region_list_entries
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
flash_chip: region_name region_offset_opt region_size region_list
|
|
|
|
{
|
2019-03-04 07:28:37 +01:00
|
|
|
union flashmap_flags flags = { .v=0 };
|
|
|
|
if (!(res = parse_descriptor($1, flags, $2, $3, $4)))
|
2015-02-26 20:47:19 +01:00
|
|
|
YYABORT;
|
|
|
|
};
|
2019-03-04 07:28:37 +01:00
|
|
|
flash_region: region_name region_flags_opt region_offset_opt region_size_opt
|
|
|
|
region_list_opt
|
2015-02-26 20:47:19 +01:00
|
|
|
{
|
2019-03-04 07:28:37 +01:00
|
|
|
struct flashmap_descriptor *node = parse_descriptor($1, $2, $3, $4, $5);
|
2015-02-26 20:47:19 +01:00
|
|
|
if (!node)
|
|
|
|
YYABORT;
|
|
|
|
|
2019-03-04 07:28:37 +01:00
|
|
|
if (node->flags.f.cbfs && !fmd_process_flag_cbfs(node)) {
|
|
|
|
ERROR("Section '%s' cannot have flag 'CBFS''\n", node->name);
|
2015-02-26 20:47:19 +01:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = node;
|
|
|
|
};
|
|
|
|
region_name: STRING
|
|
|
|
{
|
|
|
|
if (!$1) {
|
2015-03-18 18:13:48 +01:00
|
|
|
perror("E: While allocating section name");
|
2015-02-26 20:47:19 +01:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
};
|
2019-03-04 07:28:37 +01:00
|
|
|
region_flags_opt: { $$ = (union flashmap_flags){ .v=0 }; }
|
|
|
|
| '(' region_flags ')' { $$ = $2; };
|
|
|
|
region_flags: region_flag | region_flag region_flags { $$.v = $1.v | $2.v; };
|
|
|
|
region_flag: FLAG_CBFS { $$.v = 0; $$.f.cbfs = 1; };
|
2019-03-04 08:41:09 +01:00
|
|
|
region_flag: FLAG_PRESERVE { $$.v = 0; $$.f.preserve = 1; };
|
2015-02-26 20:47:19 +01:00
|
|
|
region_offset_opt: { $$ = (struct unsigned_option){false, 0}; }
|
|
|
|
| region_offset;
|
|
|
|
region_offset: '@' INTEGER { $$ = (struct unsigned_option){true, $2}; };
|
|
|
|
region_size_opt: { $$ = (struct unsigned_option){false, 0}; }
|
|
|
|
| region_size;
|
|
|
|
region_size: INTEGER { $$ = (struct unsigned_option){true, $1}; };
|
|
|
|
region_list_opt:
|
|
|
|
{
|
|
|
|
$$ = (struct descriptor_list)
|
|
|
|
{.len = 0, .head = NULL, .tail = NULL};
|
|
|
|
}
|
|
|
|
| region_list;
|
|
|
|
region_list: '{' region_list_entries '}' { $$ = $2; };
|
|
|
|
region_list_entries: flash_region
|
|
|
|
{
|
|
|
|
struct descriptor_node *node = malloc(sizeof(*node));
|
|
|
|
if (!node) {
|
2015-03-18 18:13:48 +01:00
|
|
|
perror("E: While allocating linked list node");
|
2015-02-26 20:47:19 +01:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
node->val = $1;
|
|
|
|
node->next = NULL;
|
|
|
|
$$ = (struct descriptor_list){.len = 1, .head = node, .tail = node};
|
|
|
|
}
|
|
|
|
| region_list_entries flash_region
|
|
|
|
{
|
|
|
|
struct descriptor_node *node = malloc(sizeof(*node));
|
|
|
|
if (!node) {
|
2015-03-18 18:13:48 +01:00
|
|
|
perror("E: While allocating linked list node");
|
2015-02-26 20:47:19 +01:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
node->val = $2;
|
|
|
|
node->next = NULL;
|
|
|
|
|
|
|
|
$1.tail->next = node;
|
|
|
|
$$ = (struct descriptor_list)
|
|
|
|
{.len = $1.len + 1, .head = $1.head, .tail = node};
|
|
|
|
};
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2019-03-04 07:28:37 +01:00
|
|
|
struct flashmap_descriptor *parse_descriptor(
|
|
|
|
char *name, union flashmap_flags flags, struct unsigned_option offset,
|
|
|
|
struct unsigned_option size, struct descriptor_list children)
|
2015-02-26 20:47:19 +01:00
|
|
|
{
|
|
|
|
struct flashmap_descriptor *region = malloc(sizeof(*region));
|
|
|
|
if (!region) {
|
2015-03-18 18:13:48 +01:00
|
|
|
perror("E: While allocating descriptor section");
|
2015-02-26 20:47:19 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
region->name = name;
|
2019-03-04 07:28:37 +01:00
|
|
|
region->flags = flags;
|
2015-02-26 20:47:19 +01:00
|
|
|
region->offset_known = offset.val_known;
|
|
|
|
region->offset = offset.val;
|
|
|
|
region->size_known = size.val_known;
|
|
|
|
region->size = size.val;
|
|
|
|
region->list_len = children.len;
|
|
|
|
if (region->list_len) {
|
|
|
|
region->list = malloc(region->list_len * sizeof(*region->list));
|
|
|
|
if (!region->list) {
|
2015-03-18 18:13:48 +01:00
|
|
|
perror("E: While allocating node children array");
|
2015-02-26 20:47:19 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
struct descriptor_node *cur_node = children.head;
|
|
|
|
for (unsigned idx = 0; idx < region->list_len; ++idx) {
|
|
|
|
region->list[idx] = cur_node->val;
|
|
|
|
|
|
|
|
struct descriptor_node *next_node = cur_node->next;
|
|
|
|
free(cur_node);
|
|
|
|
cur_node = next_node;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
region->list = NULL;
|
|
|
|
}
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
void yyerror(const char *s)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", s);
|
|
|
|
}
|