cbfstool: Support new FMD flag "PRESERVE"

When updating firmware, it is very often that we may want to preserve
few sections, for example vital product data (VPD) including serial
number, calibration data and cache. A firmware updater has to hard-code
the section names that need to be preserved and is hard to maintain.

A better approach is to specify that in FMAP area flags (the `area_flag`
field) using FMAP_AREA_PRESERVE. With this patchset, a FMD parser flag
"PRESERVE" is introduced and will be converted to FMAP_AREA_PRESERVE
when generating FMAP data (by fmap_from_fmd.c).

For example, The FMD statement:

  RO_VPD(PRESERVE)@0x0 16k

will generate an FMAP firmware section that:

  area_name = "RO_VPD"
  area_offset = 0
  area_size = 16384
  area_flags = FMAP_AREA_PRESERVE

BUG=chromium:936768
TEST=make; boots on x86 "google/eve" and arm "google/kukui" devices
     Manually added 'PRESERVE' to some FMD files, and verify (by running
     fmap.py) the output coreboot.rom has FMAP_AREA_PRESERVE set

Change-Id: I51e7d31029b98868a1cab0d26bf04a14db01b1c0
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31707
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Hung-Te Lin 2019-03-04 15:41:09 +08:00 committed by Patrick Georgi
parent 44b4ec740d
commit 49a4450563
8 changed files with 178 additions and 151 deletions

View File

@ -23,6 +23,7 @@
static bool fmap_append_fmd_node(struct fmap **flashmap, static bool fmap_append_fmd_node(struct fmap **flashmap,
const struct flashmap_descriptor *section, const struct flashmap_descriptor *section,
unsigned absolute_watermark) { unsigned absolute_watermark) {
uint16_t flags = 0;
if (strlen(section->name) >= FMAP_STRLEN) { if (strlen(section->name) >= FMAP_STRLEN) {
ERROR("Section name ('%s') exceeds %d character FMAP format limit\n", ERROR("Section name ('%s') exceeds %d character FMAP format limit\n",
section->name, FMAP_STRLEN - 1); section->name, FMAP_STRLEN - 1);
@ -31,8 +32,11 @@ static bool fmap_append_fmd_node(struct fmap **flashmap,
absolute_watermark += section->offset; absolute_watermark += section->offset;
if (section->flags.f.preserve)
flags |= FMAP_AREA_PRESERVE;
if (fmap_append_area(flashmap, absolute_watermark, section->size, if (fmap_append_area(flashmap, absolute_watermark, section->size,
(uint8_t *)section->name, 0) < 0) { (uint8_t *)section->name, flags) < 0) {
ERROR("Failed to insert section '%s' into FMAP\n", ERROR("Failed to insert section '%s' into FMAP\n",
section->name); section->name);
return false; return false;

View File

@ -32,6 +32,7 @@
union flashmap_flags { union flashmap_flags {
struct { struct {
int cbfs: 1; /* The section contains a CBFS area. */ int cbfs: 1; /* The section contains a CBFS area. */
int preserve: 1; /* Preserve the section before update. */
} f; } f;
int v; int v;
}; };

View File

@ -136,7 +136,8 @@ void yyerror(const char *s);
INTEGER = 258, INTEGER = 258,
OCTAL = 259, OCTAL = 259,
STRING = 260, STRING = 260,
FLAG_CBFS = 261 FLAG_CBFS = 261,
FLAG_PRESERVE = 262
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
@ -144,6 +145,7 @@ void yyerror(const char *s);
#define OCTAL 259 #define OCTAL 259
#define STRING 260 #define STRING 260
#define FLAG_CBFS 261 #define FLAG_CBFS 261
#define FLAG_PRESERVE 262
/* Value type. */ /* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@ -159,7 +161,7 @@ union YYSTYPE
union flashmap_flags flags; union flashmap_flags flags;
struct descriptor_list region_listhdr; struct descriptor_list region_listhdr;
#line 163 "y.tab.c" /* yacc.c:355 */ #line 165 "y.tab.c" /* yacc.c:355 */
}; };
typedef union YYSTYPE YYSTYPE; typedef union YYSTYPE YYSTYPE;
@ -176,7 +178,7 @@ int yyparse (void);
/* Copy the second part of user declarations. */ /* Copy the second part of user declarations. */
#line 180 "y.tab.c" /* yacc.c:358 */ #line 182 "y.tab.c" /* yacc.c:358 */
#ifdef short #ifdef short
# undef short # undef short
@ -418,21 +420,21 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
#define YYFINAL 4 #define YYFINAL 4
/* YYLAST -- Last index in YYTABLE. */ /* YYLAST -- Last index in YYTABLE. */
#define YYLAST 17 #define YYLAST 23
/* YYNTOKENS -- Number of terminals. */ /* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 12 #define YYNTOKENS 13
/* YYNNTS -- Number of nonterminals. */ /* YYNNTS -- Number of nonterminals. */
#define YYNNTS 14 #define YYNNTS 14
/* YYNRULES -- Number of rules. */ /* YYNRULES -- Number of rules. */
#define YYNRULES 20 #define YYNRULES 21
/* YYNSTATES -- Number of states. */ /* YYNSTATES -- Number of states. */
#define YYNSTATES 30 #define YYNSTATES 31
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
by yylex, with out-of-bounds checking. */ by yylex, with out-of-bounds checking. */
#define YYUNDEFTOK 2 #define YYUNDEFTOK 2
#define YYMAXUTOK 261 #define YYMAXUTOK 262
#define YYTRANSLATE(YYX) \ #define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@ -445,15 +447,15 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
7, 8, 2, 2, 2, 2, 2, 2, 2, 2, 8, 9, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 9, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 10, 2, 11, 2, 2, 2, 2, 2, 2, 2, 11, 2, 12, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@ -467,16 +469,16 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6 5, 6, 7
}; };
#if YYDEBUG #if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] = static const yytype_uint8 yyrline[] =
{ {
0, 79, 79, 85, 99, 106, 107, 108, 108, 109, 0, 80, 80, 86, 100, 107, 108, 109, 109, 110,
110, 111, 112, 113, 114, 115, 117, 121, 122, 123, 111, 112, 113, 114, 115, 116, 117, 119, 123, 124,
134 125, 136
}; };
#endif #endif
@ -486,10 +488,11 @@ static const yytype_uint8 yyrline[] =
static const char *const yytname[] = static const char *const yytname[] =
{ {
"$end", "error", "$undefined", "INTEGER", "OCTAL", "STRING", "$end", "error", "$undefined", "INTEGER", "OCTAL", "STRING",
"FLAG_CBFS", "'('", "')'", "'@'", "'{'", "'}'", "$accept", "flash_chip", "FLAG_CBFS", "FLAG_PRESERVE", "'('", "')'", "'@'", "'{'", "'}'",
"flash_region", "region_name", "region_flags_opt", "region_flags", "$accept", "flash_chip", "flash_region", "region_name",
"region_flag", "region_offset_opt", "region_offset", "region_size_opt", "region_flags_opt", "region_flags", "region_flag", "region_offset_opt",
"region_size", "region_list_opt", "region_list", "region_list_entries", YY_NULLPTR "region_offset", "region_size_opt", "region_size", "region_list_opt",
"region_list", "region_list_entries", YY_NULLPTR
}; };
#endif #endif
@ -498,8 +501,8 @@ static const char *const yytname[] =
(internal) symbol number NUM (which must be that of a token). */ (internal) symbol number NUM (which must be that of a token). */
static const yytype_uint16 yytoknum[] = static const yytype_uint16 yytoknum[] =
{ {
0, 256, 257, 258, 259, 260, 261, 40, 41, 64, 0, 256, 257, 258, 259, 260, 261, 262, 40, 41,
123, 125 64, 123, 125
}; };
# endif # endif
@ -517,9 +520,10 @@ static const yytype_uint16 yytoknum[] =
STATE-NUM. */ STATE-NUM. */
static const yytype_int8 yypact[] = static const yytype_int8 yypact[] =
{ {
-4, -12, 2, -6, -12, 1, 4, -12, -12, -12, -1, -12, 1, -2, -12, 2, 3, -12, -12, -12,
-2, -4, -12, -12, 3, -5, -1, -6, -12, -12, 0, -1, -12, -12, 4, -5, -4, -2, -12, -12,
-12, 5, -1, 4, -12, -12, -2, -12, -12, -12 -12, -12, 5, -4, 3, -12, -12, 0, -12, -12,
-12
}; };
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@ -527,23 +531,24 @@ static const yytype_int8 yypact[] =
means the default is an error. */ means the default is an error. */
static const yytype_uint8 yydefact[] = static const yytype_uint8 yydefact[] =
{ {
0, 4, 0, 10, 1, 0, 0, 11, 12, 15, 0, 4, 0, 11, 1, 0, 0, 12, 13, 16,
0, 0, 2, 19, 5, 0, 0, 10, 18, 20, 0, 0, 2, 20, 5, 0, 0, 11, 19, 21,
9, 0, 7, 13, 6, 8, 16, 14, 3, 17 9, 10, 0, 7, 14, 6, 8, 17, 15, 3,
18
}; };
/* YYPGOTO[NTERM-NUM]. */ /* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] = static const yytype_int8 yypgoto[] =
{ {
-12, -12, -3, 9, -12, -11, -12, 0, -12, -12, -12, -12, -6, 10, -12, -10, -12, 6, -12, -12,
-9, -12, -10, -12 -9, -12, -11, -12
}; };
/* YYDEFGOTO[NTERM-NUM]. */ /* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] = static const yytype_int8 yydefgoto[] =
{ {
-1, 2, 13, 14, 17, 21, 22, 6, 7, 26, -1, 2, 13, 14, 17, 22, 23, 6, 7, 27,
10, 28, 12, 15 10, 29, 12, 15
}; };
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
@ -551,39 +556,42 @@ static const yytype_int8 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */ number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_uint8 yytable[] = static const yytype_uint8 yytable[] =
{ {
1, 1, 4, 5, 8, 20, 18, 9, 11, 3, 1, 4, 20, 21, 1, 8, 9, 18, 5, 19,
16, 25, 19, 24, 27, 0, 29, 23 3, 11, 16, 26, 25, 28, 30, 0, 0, 0,
0, 0, 0, 24
}; };
static const yytype_int8 yycheck[] = static const yytype_int8 yycheck[] =
{ {
5, 5, 0, 9, 3, 6, 11, 3, 10, 0, 5, 0, 6, 7, 5, 3, 3, 12, 10, 15,
7, 22, 15, 8, 23, -1, 26, 17 0, 11, 8, 23, 9, 24, 27, -1, -1, -1,
-1, -1, -1, 17
}; };
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */ symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] = static const yytype_uint8 yystos[] =
{ {
0, 5, 13, 15, 0, 9, 19, 20, 3, 3, 0, 5, 14, 16, 0, 10, 20, 21, 3, 3,
22, 10, 24, 14, 15, 25, 7, 16, 11, 14, 23, 11, 25, 15, 16, 26, 8, 17, 12, 15,
6, 17, 18, 19, 8, 17, 21, 22, 23, 24 6, 7, 18, 19, 20, 9, 18, 22, 23, 24,
25
}; };
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] = static const yytype_uint8 yyr1[] =
{ {
0, 12, 13, 14, 15, 16, 16, 17, 17, 18, 0, 13, 14, 15, 16, 17, 17, 18, 18, 19,
19, 19, 20, 21, 21, 22, 23, 23, 24, 25, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25,
25 26, 26
}; };
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_uint8 yyr2[] = static const yytype_uint8 yyr2[] =
{ {
0, 2, 4, 5, 1, 0, 3, 1, 2, 1, 0, 2, 4, 5, 1, 0, 3, 1, 2, 1,
0, 1, 2, 0, 1, 1, 0, 1, 3, 1, 1, 0, 1, 2, 0, 1, 1, 0, 1, 3,
2 1, 2
}; };
@ -1260,17 +1268,17 @@ yyreduce:
switch (yyn) switch (yyn)
{ {
case 2: case 2:
#line 80 "fmd_parser.y" /* yacc.c:1646 */ #line 81 "fmd_parser.y" /* yacc.c:1646 */
{ {
union flashmap_flags flags = { .v=0 }; union flashmap_flags flags = { .v=0 };
if (!(res = parse_descriptor((yyvsp[-3].strval), flags, (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr)))) if (!(res = parse_descriptor((yyvsp[-3].strval), flags, (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr))))
YYABORT; YYABORT;
} }
#line 1270 "y.tab.c" /* yacc.c:1646 */ #line 1278 "y.tab.c" /* yacc.c:1646 */
break; break;
case 3: case 3:
#line 87 "fmd_parser.y" /* yacc.c:1646 */ #line 88 "fmd_parser.y" /* yacc.c:1646 */
{ {
struct flashmap_descriptor *node = parse_descriptor((yyvsp[-4].strval), (yyvsp[-3].flags), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr)); struct flashmap_descriptor *node = parse_descriptor((yyvsp[-4].strval), (yyvsp[-3].flags), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr));
if (!node) if (!node)
@ -1283,85 +1291,91 @@ yyreduce:
(yyval.region_ptr) = node; (yyval.region_ptr) = node;
} }
#line 1287 "y.tab.c" /* yacc.c:1646 */ #line 1295 "y.tab.c" /* yacc.c:1646 */
break; break;
case 4: case 4:
#line 100 "fmd_parser.y" /* yacc.c:1646 */ #line 101 "fmd_parser.y" /* yacc.c:1646 */
{ {
if (!(yyvsp[0].strval)) { if (!(yyvsp[0].strval)) {
perror("E: While allocating section name"); perror("E: While allocating section name");
YYABORT; YYABORT;
} }
} }
#line 1298 "y.tab.c" /* yacc.c:1646 */ #line 1306 "y.tab.c" /* yacc.c:1646 */
break; break;
case 5: case 5:
#line 106 "fmd_parser.y" /* yacc.c:1646 */ #line 107 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.flags) = (union flashmap_flags){ .v=0 }; } { (yyval.flags) = (union flashmap_flags){ .v=0 }; }
#line 1304 "y.tab.c" /* yacc.c:1646 */ #line 1312 "y.tab.c" /* yacc.c:1646 */
break; break;
case 6: case 6:
#line 107 "fmd_parser.y" /* yacc.c:1646 */ #line 108 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.flags) = (yyvsp[-1].flags); } { (yyval.flags) = (yyvsp[-1].flags); }
#line 1310 "y.tab.c" /* yacc.c:1646 */ #line 1318 "y.tab.c" /* yacc.c:1646 */
break; break;
case 8: case 8:
#line 108 "fmd_parser.y" /* yacc.c:1646 */ #line 109 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.flags).v = (yyvsp[-1].flags).v | (yyvsp[0].flags).v; } { (yyval.flags).v = (yyvsp[-1].flags).v | (yyvsp[0].flags).v; }
#line 1316 "y.tab.c" /* yacc.c:1646 */ #line 1324 "y.tab.c" /* yacc.c:1646 */
break; break;
case 9: case 9:
#line 109 "fmd_parser.y" /* yacc.c:1646 */ #line 110 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.flags).v = 0; (yyval.flags).f.cbfs = 1; } { (yyval.flags).v = 0; (yyval.flags).f.cbfs = 1; }
#line 1322 "y.tab.c" /* yacc.c:1646 */ #line 1330 "y.tab.c" /* yacc.c:1646 */
break; break;
case 10: case 10:
#line 110 "fmd_parser.y" /* yacc.c:1646 */ #line 111 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.maybe_intval) = (struct unsigned_option){false, 0}; } { (yyval.flags).v = 0; (yyval.flags).f.preserve = 1; }
#line 1328 "y.tab.c" /* yacc.c:1646 */ #line 1336 "y.tab.c" /* yacc.c:1646 */
break; break;
case 12: case 11:
#line 112 "fmd_parser.y" /* yacc.c:1646 */ #line 112 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.maybe_intval) = (struct unsigned_option){true, (yyvsp[0].intval)}; } { (yyval.maybe_intval) = (struct unsigned_option){false, 0}; }
#line 1334 "y.tab.c" /* yacc.c:1646 */ #line 1342 "y.tab.c" /* yacc.c:1646 */
break; break;
case 13: case 13:
#line 113 "fmd_parser.y" /* yacc.c:1646 */ #line 114 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.maybe_intval) = (struct unsigned_option){false, 0}; } { (yyval.maybe_intval) = (struct unsigned_option){true, (yyvsp[0].intval)}; }
#line 1340 "y.tab.c" /* yacc.c:1646 */ #line 1348 "y.tab.c" /* yacc.c:1646 */
break; break;
case 15: case 14:
#line 115 "fmd_parser.y" /* yacc.c:1646 */ #line 115 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.maybe_intval) = (struct unsigned_option){true, (yyvsp[0].intval)}; } { (yyval.maybe_intval) = (struct unsigned_option){false, 0}; }
#line 1346 "y.tab.c" /* yacc.c:1646 */ #line 1354 "y.tab.c" /* yacc.c:1646 */
break; break;
case 16: case 16:
#line 117 "fmd_parser.y" /* yacc.c:1646 */ #line 117 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.maybe_intval) = (struct unsigned_option){true, (yyvsp[0].intval)}; }
#line 1360 "y.tab.c" /* yacc.c:1646 */
break;
case 17:
#line 119 "fmd_parser.y" /* yacc.c:1646 */
{ {
(yyval.region_listhdr) = (struct descriptor_list) (yyval.region_listhdr) = (struct descriptor_list)
{.len = 0, .head = NULL, .tail = NULL}; {.len = 0, .head = NULL, .tail = NULL};
} }
#line 1355 "y.tab.c" /* yacc.c:1646 */ #line 1369 "y.tab.c" /* yacc.c:1646 */
break;
case 18:
#line 122 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.region_listhdr) = (yyvsp[-1].region_listhdr); }
#line 1361 "y.tab.c" /* yacc.c:1646 */
break; break;
case 19: case 19:
#line 124 "fmd_parser.y" /* yacc.c:1646 */ #line 124 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.region_listhdr) = (yyvsp[-1].region_listhdr); }
#line 1375 "y.tab.c" /* yacc.c:1646 */
break;
case 20:
#line 126 "fmd_parser.y" /* yacc.c:1646 */
{ {
struct descriptor_node *node = malloc(sizeof(*node)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
@ -1372,11 +1386,11 @@ yyreduce:
node->next = NULL; node->next = NULL;
(yyval.region_listhdr) = (struct descriptor_list){.len = 1, .head = node, .tail = node}; (yyval.region_listhdr) = (struct descriptor_list){.len = 1, .head = node, .tail = node};
} }
#line 1376 "y.tab.c" /* yacc.c:1646 */ #line 1390 "y.tab.c" /* yacc.c:1646 */
break; break;
case 20: case 21:
#line 135 "fmd_parser.y" /* yacc.c:1646 */ #line 137 "fmd_parser.y" /* yacc.c:1646 */
{ {
struct descriptor_node *node = malloc(sizeof(*node)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
@ -1390,11 +1404,11 @@ yyreduce:
(yyval.region_listhdr) = (struct descriptor_list) (yyval.region_listhdr) = (struct descriptor_list)
{.len = (yyvsp[-1].region_listhdr).len + 1, .head = (yyvsp[-1].region_listhdr).head, .tail = node}; {.len = (yyvsp[-1].region_listhdr).len + 1, .head = (yyvsp[-1].region_listhdr).head, .tail = node};
} }
#line 1394 "y.tab.c" /* yacc.c:1646 */ #line 1408 "y.tab.c" /* yacc.c:1646 */
break; break;
#line 1398 "y.tab.c" /* yacc.c:1646 */ #line 1412 "y.tab.c" /* yacc.c:1646 */
default: break; default: break;
} }
/* User semantic actions sometimes alter yychar, and that requires /* User semantic actions sometimes alter yychar, and that requires
@ -1622,7 +1636,7 @@ yyreturn:
#endif #endif
return yyresult; return yyresult;
} }
#line 149 "fmd_parser.y" /* yacc.c:1906 */ #line 151 "fmd_parser.y" /* yacc.c:1906 */
struct flashmap_descriptor *parse_descriptor( struct flashmap_descriptor *parse_descriptor(

View File

@ -75,7 +75,8 @@ void yyerror(const char *s);
INTEGER = 258, INTEGER = 258,
OCTAL = 259, OCTAL = 259,
STRING = 260, STRING = 260,
FLAG_CBFS = 261 FLAG_CBFS = 261,
FLAG_PRESERVE = 262
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
@ -83,6 +84,7 @@ void yyerror(const char *s);
#define OCTAL 259 #define OCTAL 259
#define STRING 260 #define STRING 260
#define FLAG_CBFS 261 #define FLAG_CBFS 261
#define FLAG_PRESERVE 262
/* Value type. */ /* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@ -98,7 +100,7 @@ union YYSTYPE
union flashmap_flags flags; union flashmap_flags flags;
struct descriptor_list region_listhdr; struct descriptor_list region_listhdr;
#line 102 "y.tab.h" /* yacc.c:1909 */ #line 104 "y.tab.h" /* yacc.c:1909 */
}; };
typedef union YYSTYPE YYSTYPE; typedef union YYSTYPE YYSTYPE;

View File

@ -60,6 +60,7 @@ void yyerror(const char *s);
%token OCTAL %token OCTAL
%token <strval> STRING %token <strval> STRING
%token FLAG_CBFS %token FLAG_CBFS
%token FLAG_PRESERVE
%type <region_ptr> flash_region %type <region_ptr> flash_region
%type <strval> region_name %type <strval> region_name
@ -107,6 +108,7 @@ region_flags_opt: { $$ = (union flashmap_flags){ .v=0 }; }
| '(' region_flags ')' { $$ = $2; }; | '(' region_flags ')' { $$ = $2; };
region_flags: region_flag | region_flag region_flags { $$.v = $1.v | $2.v; }; region_flags: region_flag | region_flag region_flags { $$.v = $1.v | $2.v; };
region_flag: FLAG_CBFS { $$.v = 0; $$.f.cbfs = 1; }; region_flag: FLAG_CBFS { $$.v = 0; $$.f.cbfs = 1; };
region_flag: FLAG_PRESERVE { $$.v = 0; $$.f.preserve = 1; };
region_offset_opt: { $$ = (struct unsigned_option){false, 0}; } region_offset_opt: { $$ = (struct unsigned_option){false, 0}; }
| region_offset; | region_offset;
region_offset: '@' INTEGER { $$ = (struct unsigned_option){true, $2}; }; region_offset: '@' INTEGER { $$ = (struct unsigned_option){true, $2}; };

View File

@ -363,8 +363,8 @@ static void yynoreturn yy_fatal_error (yyconst char* msg );
*yy_cp = '\0'; \ *yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp; (yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 12 #define YY_NUM_RULES 13
#define YY_END_OF_BUFFER 13 #define YY_END_OF_BUFFER 14
/* This struct is not used in this scanner, /* This struct is not used in this scanner,
but its presence is necessary. */ but its presence is necessary. */
struct yy_trans_info struct yy_trans_info
@ -372,12 +372,12 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; flex_int32_t yy_nxt;
}; };
static yyconst flex_int16_t yy_accept[32] = static yyconst flex_int16_t yy_accept[40] =
{ 0, { 0,
10, 10, 10, 10, 13, 10, 1, 1, 11, 3, 11, 11, 11, 11, 14, 11, 1, 1, 12, 3,
11, 6, 7, 4, 10, 10, 1, 0, 2, 8, 12, 7, 8, 4, 11, 11, 11, 1, 0, 2,
6, 10, 7, 7, 10, 8, 9, 10, 9, 5, 9, 7, 11, 8, 8, 11, 11, 9, 10, 11,
0 11, 10, 5, 11, 11, 11, 11, 6, 0
} ; } ;
static yyconst YY_CHAR yy_ec[256] = static yyconst YY_CHAR yy_ec[256] =
@ -388,13 +388,13 @@ static yyconst YY_CHAR yy_ec[256] =
1, 2, 1, 1, 4, 1, 1, 1, 1, 5, 1, 2, 1, 1, 4, 1, 1, 1, 1, 5,
6, 1, 1, 1, 1, 1, 1, 7, 8, 8, 6, 1, 1, 1, 1, 1, 1, 7, 8, 8,
8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1,
1, 1, 1, 9, 10, 11, 12, 10, 10, 13, 1, 1, 1, 9, 10, 11, 12, 10, 13, 14,
14, 1, 1, 1, 14, 1, 14, 1, 1, 1, 15, 1, 1, 1, 15, 1, 15, 1, 1, 16,
1, 1, 15, 1, 1, 1, 1, 16, 1, 1, 1, 17, 18, 1, 1, 19, 1, 20, 1, 1,
1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10,
10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20,
1, 1, 9, 1, 9, 1, 1, 1, 1, 1, 1, 1, 9, 1, 9, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -412,56 +412,54 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst YY_CHAR yy_meta[17] = static yyconst YY_CHAR yy_meta[21] =
{ 0, { 0,
1, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 1, 1, 2, 1,
1, 1, 1, 1, 1, 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
} ; } ;
static yyconst flex_uint16_t yy_base[35] = static yyconst flex_uint16_t yy_base[43] =
{ 0, { 0,
0, 0, 11, 12, 44, 0, 17, 19, 38, 77, 0, 8, 12, 13, 63, 0, 18, 20, 59, 64,
77, 18, 28, 77, 29, 0, 25, 36, 77, 15, 64, 23, 19, 64, 50, 43, 0, 30, 56, 64,
0, 42, 0, 0, 25, 0, 58, 22, 0, 0, 20, 0, 37, 0, 0, 44, 44, 0, 41, 28,
77, 32, 74, 29 24, 0, 0, 28, 22, 18, 23, 0, 64, 51,
0, 53
} ; } ;
static yyconst flex_int16_t yy_def[35] = static yyconst flex_int16_t yy_def[43] =
{ 0, { 0,
31, 1, 1, 1, 31, 32, 31, 31, 33, 31, 40, 40, 2, 2, 39, 41, 39, 39, 42, 39,
31, 32, 32, 31, 32, 32, 31, 33, 31, 12, 39, 41, 41, 39, 41, 41, 41, 39, 42, 39,
32, 34, 13, 32, 32, 32, 34, 32, 32, 32, 12, 41, 41, 13, 41, 41, 41, 41, 23, 41,
0, 31, 31, 31 41, 41, 41, 41, 41, 41, 41, 41, 0, 39,
39, 39
} ; } ;
static yyconst flex_uint16_t yy_nxt[94] = static yyconst flex_uint16_t yy_nxt[85] =
{ 0, { 0,
6, 7, 8, 9, 10, 11, 12, 13, 11, 6, 17, 7, 8, 9, 10, 11, 12, 13, 11, 7,
6, 6, 6, 6, 6, 6, 14, 14, 17, 17, 8, 9, 10, 11, 12, 13, 11, 14, 14, 18,
17, 17, 15, 15, 20, 20, 17, 17, 26, 27, 18, 18, 18, 15, 15, 24, 24, 16, 16, 21,
16, 21, 16, 22, 23, 23, 30, 28, 19, 25, 21, 18, 18, 25, 28, 38, 37, 22, 36, 17,
19, 24, 16, 31, 31, 31, 31, 31, 31, 31, 35, 34, 23, 29, 29, 33, 29, 29, 29, 29,
31, 31, 31, 31, 31, 16, 16, 16, 16, 31, 29, 6, 6, 19, 19, 32, 31, 30, 20, 27,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 26, 20, 39, 5, 39, 39, 39, 39, 39, 39,
31, 29, 16, 16, 18, 18, 5, 31, 31, 31, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 39, 39, 39
31, 31, 31
} ; } ;
static yyconst flex_int16_t yy_chk[94] = static yyconst flex_int16_t yy_chk[85] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 41, 1, 1, 1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 3, 4, 7, 7, 2, 2, 2, 2, 2, 2, 2, 3, 4, 7,
8, 8, 3, 4, 12, 12, 17, 17, 20, 34, 7, 8, 8, 3, 4, 13, 13, 3, 4, 12,
20, 12, 32, 12, 13, 13, 28, 25, 18, 15, 12, 18, 18, 13, 21, 37, 36, 12, 35, 21,
9, 13, 22, 5, 0, 0, 0, 0, 0, 0, 34, 31, 12, 23, 23, 30, 23, 23, 23, 23,
0, 0, 0, 0, 0, 22, 22, 22, 27, 0, 23, 40, 40, 42, 42, 29, 27, 26, 19, 16,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 9, 5, 39, 39, 39, 39, 39, 39, 39,
0, 27, 27, 27, 33, 33, 31, 31, 31, 31, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 39, 39, 39
31, 31, 31
} ; } ;
static yy_state_type yy_last_accepting_state; static yy_state_type yy_last_accepting_state;
@ -502,7 +500,7 @@ char *yytext;
int parse_integer(char *src, int base); int parse_integer(char *src, int base);
int copy_string(const char *src); int copy_string(const char *src);
#line 506 "<stdout>" #line 504 "<stdout>"
#define INITIAL 0 #define INITIAL 0
#define FLAGS 1 #define FLAGS 1
@ -723,7 +721,7 @@ YY_DECL
{ {
#line 31 "fmd_scanner.l" #line 31 "fmd_scanner.l"
#line 727 "<stdout>" #line 725 "<stdout>"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{ {
@ -750,13 +748,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 32 ) if ( yy_current_state >= 40 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_base[yy_current_state] != 77 ); while ( yy_base[yy_current_state] != 64 );
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
@ -810,38 +808,43 @@ YY_RULE_SETUP
return FLAG_CBFS; return FLAG_CBFS;
YY_BREAK YY_BREAK
case 6: case 6:
#line 38 "fmd_scanner.l"
case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 38 "fmd_scanner.l" #line 37 "fmd_scanner.l"
return parse_integer(yytext, 10); return FLAG_PRESERVE;
YY_BREAK YY_BREAK
case 7:
#line 39 "fmd_scanner.l"
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 39 "fmd_scanner.l" #line 39 "fmd_scanner.l"
return OCTAL; return parse_integer(yytext, 10);
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 40 "fmd_scanner.l" #line 40 "fmd_scanner.l"
return parse_integer(yytext + 2, 16); return OCTAL;
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 41 "fmd_scanner.l" #line 41 "fmd_scanner.l"
return copy_string(yytext); return parse_integer(yytext + 2, 16);
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 42 "fmd_scanner.l" #line 42 "fmd_scanner.l"
return *yytext; return copy_string(yytext);
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 44 "fmd_scanner.l" #line 43 "fmd_scanner.l"
return *yytext;
YY_BREAK
case 13:
YY_RULE_SETUP
#line 45 "fmd_scanner.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 845 "<stdout>" #line 848 "<stdout>"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(FLAGS): case YY_STATE_EOF(FLAGS):
yyterminate(); yyterminate();
@ -1135,7 +1138,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 32 ) if ( yy_current_state >= 40 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
@ -1163,11 +1166,11 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 32 ) if ( yy_current_state >= 40 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
yy_is_jam = (yy_current_state == 31); yy_is_jam = (yy_current_state == 39);
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
@ -1843,7 +1846,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
#line 44 "fmd_scanner.l" #line 45 "fmd_scanner.l"

View File

@ -317,7 +317,7 @@ extern int yylex (void);
#undef YY_DECL #undef YY_DECL
#endif #endif
#line 44 "fmd_scanner.l" #line 45 "fmd_scanner.l"
#line 324 "fmd_scanner.h_shipped" #line 324 "fmd_scanner.h_shipped"

View File

@ -34,6 +34,7 @@ MULTIPLIER [KMG]
\( BEGIN(FLAGS); return *yytext; \( BEGIN(FLAGS); return *yytext;
<FLAGS>\) BEGIN(INITIAL); return *yytext; <FLAGS>\) BEGIN(INITIAL); return *yytext;
<FLAGS>CBFS return FLAG_CBFS; <FLAGS>CBFS return FLAG_CBFS;
<FLAGS>PRESERVE return FLAG_PRESERVE;
0{MULTIPLIER}? | 0{MULTIPLIER}? |
[1-9][0-9]*{MULTIPLIER}? return parse_integer(yytext, 10); [1-9][0-9]*{MULTIPLIER}? return parse_integer(yytext, 10);
0[0-9]+{MULTIPLIER}? return OCTAL; 0[0-9]+{MULTIPLIER}? return OCTAL;