diff options
-rw-r--r-- | util/cbfstool/fmap_from_fmd.c | 15 | ||||
-rw-r--r-- | util/cbfstool/fmd.c | 27 | ||||
-rw-r--r-- | util/cbfstool/fmd_parser.c | 85 | ||||
-rw-r--r-- | util/cbfstool/fmd_parser.h | 4 | ||||
-rw-r--r-- | util/cbfstool/fmd_parser.y | 13 |
5 files changed, 68 insertions, 76 deletions
diff --git a/util/cbfstool/fmap_from_fmd.c b/util/cbfstool/fmap_from_fmd.c index fa1024bd57..267174386b 100644 --- a/util/cbfstool/fmap_from_fmd.c +++ b/util/cbfstool/fmap_from_fmd.c @@ -28,9 +28,8 @@ static bool fmap_append_fmd_node(struct fmap **flashmap, const struct flashmap_descriptor *section, unsigned absolute_watermark) { if (strlen(section->name) >= FMAP_STRLEN) { - fprintf(stderr, - "ERROR: Section name ('%s') exceeds %d character FMAP format limit\n", - section->name, FMAP_STRLEN - 1); + ERROR("Section name ('%s') exceeds %d character FMAP format limit\n", + section->name, FMAP_STRLEN - 1); return false; } @@ -38,9 +37,8 @@ static bool fmap_append_fmd_node(struct fmap **flashmap, if (fmap_append_area(flashmap, absolute_watermark, section->size, (uint8_t *)section->name, 0) < 0) { - fprintf(stderr, - "ERROR: Failed to insert section '%s' into FMAP\n", - section->name); + ERROR("Failed to insert section '%s' into FMAP\n", + section->name); return false; } @@ -59,8 +57,7 @@ struct fmap *fmap_from_fmd(const struct flashmap_descriptor *desc) assert(desc->size_known); if (strlen(desc->name) >= FMAP_STRLEN) { - fprintf(stderr, - "ERROR: Image name ('%s') exceeds %d character FMAP header limit\n", + ERROR("Image name ('%s') exceeds %d character FMAP header limit\n", desc->name, FMAP_STRLEN - 1); return NULL; } @@ -68,7 +65,7 @@ struct fmap *fmap_from_fmd(const struct flashmap_descriptor *desc) struct fmap *fmap = fmap_create(desc->offset_known ? desc->offset : 0, desc->size, (uint8_t *)desc->name); if (!fmap) { - fputs("ERROR: Failed to allocate FMAP header\n", stderr); + ERROR("Failed to allocate FMAP header\n"); return fmap; } diff --git a/util/cbfstool/fmd.c b/util/cbfstool/fmd.c index bfce0490cd..a4430bed58 100644 --- a/util/cbfstool/fmd.c +++ b/util/cbfstool/fmd.c @@ -19,6 +19,7 @@ #include "fmd.h" +#include "common.h" #include "fmd_parser.h" #include "fmd_scanner.h" #include "option.h" @@ -56,8 +57,7 @@ static bool validate_descriptor_node(const struct flashmap_descriptor *node, ENTRY search_key = {node->name, NULL}; if (hsearch(search_key, FIND)) { - fprintf(stderr, "ERROR: Multiple sections with name '%s'\n", - node->name); + ERROR("Multiple sections with name '%s'\n", node->name); return false; } if (!hsearch(search_key, ENTER)) @@ -65,26 +65,22 @@ static bool validate_descriptor_node(const struct flashmap_descriptor *node, if (node->offset_known) { if (start.val_known && node->offset < start.val) { - fprintf(stderr, "ERROR: Section '%s' starts too low\n", - node->name); + ERROR("Section '%s' starts too low\n", node->name); return false; } else if (end.val_known && node->offset > end.val) { - fprintf(stderr, "ERROR: Section '%s' starts too high\n", - node->name); + ERROR("Section '%s' starts too high\n", node->name); return false; } } if (node->size_known) { if (node->size == 0) { - fprintf(stderr, "ERROR: Section '%s' given no space\n", - node->name); + ERROR("Section '%s' given no space\n", node->name); return false; } else if (node->offset_known) { unsigned node_end = node->offset + node->size; if (end.val_known && node_end > end.val) { - fprintf(stderr, "ERROR: Section '%s' too big\n", - node->name); + ERROR("Section '%s' too big\n", node->name); return false; } } @@ -120,16 +116,14 @@ static bool complete_missing_info_backward( assert(cur->offset_known || cur->size_known); if (!cur->offset_known) { if (cur->size > end_watermark) { - fprintf(stderr, "ERROR: Section '%s' too big\n", - cur->name); + ERROR("Section '%s' too big\n", cur->name); return false; } cur->offset_known = true; cur->offset = end_watermark -= cur->size; } else if (!cur->size_known) { if (cur->offset > end_watermark) { - fprintf(stderr, - "ERROR: Section '%s' starts too high\n", + ERROR("Section '%s' starts too high\n", cur->name); return false; } @@ -230,8 +224,7 @@ static bool validate_and_complete_info(struct flashmap_descriptor *cur_level) if (!cur_section->size_known) { if (!cur_section->offset_known) { - fprintf(stderr, - "ERROR: Cannot determine either offset or size of section '%s'\n", + ERROR("Cannot determine either offset or size of section '%s'\n", cur_section->name); return false; } else if (!first_incomplete_it) { @@ -315,7 +308,7 @@ struct flashmap_descriptor *fmd_create(FILE *stream) // This hash table is used to store the declared name of each // section and ensure that each is globally unique. if (!hcreate(fmd_count_nodes(ret))) { - perror("ERROR: While initializing hashtable"); + perror("E: While initializing hashtable"); fmd_cleanup(ret); return NULL; } diff --git a/util/cbfstool/fmd_parser.c b/util/cbfstool/fmd_parser.c index d97e7439e2..d463393256 100644 --- a/util/cbfstool/fmd_parser.c +++ b/util/cbfstool/fmd_parser.c @@ -65,12 +65,13 @@ #line 20 "fmd_parser.y" /* yacc.c:339 */ #include "fmd_scanner.h" +#include "common.h" #include <stdlib.h> struct flashmap_descriptor *res = NULL; -#line 74 "y.tab.c" /* yacc.c:339 */ +#line 75 "y.tab.c" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -100,7 +101,7 @@ struct flashmap_descriptor *res = NULL; extern int yydebug; #endif /* "%code requires" blocks. */ -#line 36 "fmd_parser.y" /* yacc.c:355 */ +#line 37 "fmd_parser.y" /* yacc.c:355 */ #include "fmd.h" #include "option.h" @@ -125,7 +126,7 @@ struct flashmap_descriptor *parse_descriptor(char *name, struct descriptor_list children); void yyerror(const char *s); -#line 129 "y.tab.c" /* yacc.c:355 */ +#line 130 "y.tab.c" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -147,7 +148,7 @@ void yyerror(const char *s); typedef union YYSTYPE YYSTYPE; union YYSTYPE { -#line 28 "fmd_parser.y" /* yacc.c:355 */ +#line 29 "fmd_parser.y" /* yacc.c:355 */ unsigned intval; char *strval; @@ -155,7 +156,7 @@ union YYSTYPE struct flashmap_descriptor *region_ptr; struct descriptor_list region_listhdr; -#line 159 "y.tab.c" /* yacc.c:355 */ +#line 160 "y.tab.c" /* yacc.c:355 */ }; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 @@ -170,7 +171,7 @@ int yyparse (void); /* Copy the second part of user declarations. */ -#line 174 "y.tab.c" /* yacc.c:358 */ +#line 175 "y.tab.c" /* yacc.c:358 */ #ifdef short # undef short @@ -468,8 +469,8 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 79, 79, 84, 101, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 118, 122, 123, 124, 135 + 0, 80, 80, 85, 102, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 119, 123, 124, 125, 136 }; #endif @@ -1251,16 +1252,16 @@ yyreduce: switch (yyn) { case 2: -#line 80 "fmd_parser.y" /* yacc.c:1646 */ +#line 81 "fmd_parser.y" /* yacc.c:1646 */ { if (!(res = parse_descriptor((yyvsp[-3].strval), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr)))) YYABORT; } -#line 1260 "y.tab.c" /* yacc.c:1646 */ +#line 1261 "y.tab.c" /* yacc.c:1646 */ break; case 3: -#line 86 "fmd_parser.y" /* yacc.c:1646 */ +#line 87 "fmd_parser.y" /* yacc.c:1646 */ { struct flashmap_descriptor *node = parse_descriptor((yyvsp[-4].strval), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr)); if (!node) @@ -1268,7 +1269,7 @@ yyreduce: char *annotation = (yyvsp[-3].strval); if (annotation && !fmd_process_annotation_impl(node, annotation)) { - fprintf(stderr, "ERROR: Section '%s' has unexpected annotation '(%s)'\n", + ERROR("Section '%s' has unexpected annotation '(%s)'\n", node->name, annotation); YYABORT; } @@ -1276,92 +1277,92 @@ yyreduce: (yyval.region_ptr) = node; } -#line 1280 "y.tab.c" /* yacc.c:1646 */ +#line 1281 "y.tab.c" /* yacc.c:1646 */ break; case 4: -#line 102 "fmd_parser.y" /* yacc.c:1646 */ +#line 103 "fmd_parser.y" /* yacc.c:1646 */ { if (!(yyvsp[0].strval)) { - perror("ERROR: While allocating section name"); + perror("E: While allocating section name"); YYABORT; } } -#line 1291 "y.tab.c" /* yacc.c:1646 */ +#line 1292 "y.tab.c" /* yacc.c:1646 */ break; case 5: -#line 108 "fmd_parser.y" /* yacc.c:1646 */ +#line 109 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.strval) = NULL; } -#line 1297 "y.tab.c" /* yacc.c:1646 */ +#line 1298 "y.tab.c" /* yacc.c:1646 */ break; case 7: -#line 110 "fmd_parser.y" /* yacc.c:1646 */ +#line 111 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.strval) = (yyvsp[-1].strval); } -#line 1303 "y.tab.c" /* yacc.c:1646 */ +#line 1304 "y.tab.c" /* yacc.c:1646 */ break; case 8: -#line 111 "fmd_parser.y" /* yacc.c:1646 */ +#line 112 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.maybe_intval) = (struct unsigned_option){false, 0}; } -#line 1309 "y.tab.c" /* yacc.c:1646 */ +#line 1310 "y.tab.c" /* yacc.c:1646 */ break; case 10: -#line 113 "fmd_parser.y" /* yacc.c:1646 */ +#line 114 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.maybe_intval) = (struct unsigned_option){true, (yyvsp[0].intval)}; } -#line 1315 "y.tab.c" /* yacc.c:1646 */ +#line 1316 "y.tab.c" /* yacc.c:1646 */ break; case 11: -#line 114 "fmd_parser.y" /* yacc.c:1646 */ +#line 115 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.maybe_intval) = (struct unsigned_option){false, 0}; } -#line 1321 "y.tab.c" /* yacc.c:1646 */ +#line 1322 "y.tab.c" /* yacc.c:1646 */ break; case 13: -#line 116 "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 1327 "y.tab.c" /* yacc.c:1646 */ +#line 1328 "y.tab.c" /* yacc.c:1646 */ break; case 14: -#line 118 "fmd_parser.y" /* yacc.c:1646 */ +#line 119 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.region_listhdr) = (struct descriptor_list) {.len = 0, .head = NULL, .tail = NULL}; } -#line 1336 "y.tab.c" /* yacc.c:1646 */ +#line 1337 "y.tab.c" /* yacc.c:1646 */ break; case 16: -#line 123 "fmd_parser.y" /* yacc.c:1646 */ +#line 124 "fmd_parser.y" /* yacc.c:1646 */ { (yyval.region_listhdr) = (yyvsp[-1].region_listhdr); } -#line 1342 "y.tab.c" /* yacc.c:1646 */ +#line 1343 "y.tab.c" /* yacc.c:1646 */ break; case 17: -#line 125 "fmd_parser.y" /* yacc.c:1646 */ +#line 126 "fmd_parser.y" /* yacc.c:1646 */ { struct descriptor_node *node = malloc(sizeof(*node)); if (!node) { - perror("ERROR: While allocating linked list node"); + perror("E: While allocating linked list node"); YYABORT; } node->val = (yyvsp[0].region_ptr); node->next = NULL; (yyval.region_listhdr) = (struct descriptor_list){.len = 1, .head = node, .tail = node}; } -#line 1357 "y.tab.c" /* yacc.c:1646 */ +#line 1358 "y.tab.c" /* yacc.c:1646 */ break; case 18: -#line 136 "fmd_parser.y" /* yacc.c:1646 */ +#line 137 "fmd_parser.y" /* yacc.c:1646 */ { struct descriptor_node *node = malloc(sizeof(*node)); if (!node) { - perror("ERROR: While allocating linked list node"); + perror("E: While allocating linked list node"); YYABORT; } node->val = (yyvsp[0].region_ptr); @@ -1371,11 +1372,11 @@ yyreduce: (yyval.region_listhdr) = (struct descriptor_list) {.len = (yyvsp[-1].region_listhdr).len + 1, .head = (yyvsp[-1].region_listhdr).head, .tail = node}; } -#line 1375 "y.tab.c" /* yacc.c:1646 */ +#line 1376 "y.tab.c" /* yacc.c:1646 */ break; -#line 1379 "y.tab.c" /* yacc.c:1646 */ +#line 1380 "y.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1603,7 +1604,7 @@ yyreturn: #endif return yyresult; } -#line 150 "fmd_parser.y" /* yacc.c:1906 */ +#line 151 "fmd_parser.y" /* yacc.c:1906 */ struct flashmap_descriptor *parse_descriptor(char *name, @@ -1612,7 +1613,7 @@ struct flashmap_descriptor *parse_descriptor(char *name, { struct flashmap_descriptor *region = malloc(sizeof(*region)); if (!region) { - perror("ERROR: While allocating descriptor section"); + perror("E: While allocating descriptor section"); return NULL; } region->name = name; @@ -1624,7 +1625,7 @@ struct flashmap_descriptor *parse_descriptor(char *name, if (region->list_len) { region->list = malloc(region->list_len * sizeof(*region->list)); if (!region->list) { - perror("ERROR: While allocating node children array"); + perror("E: While allocating node children array"); return NULL; } struct descriptor_node *cur_node = children.head; diff --git a/util/cbfstool/fmd_parser.h b/util/cbfstool/fmd_parser.h index 393a8fff4c..dc6301d926 100644 --- a/util/cbfstool/fmd_parser.h +++ b/util/cbfstool/fmd_parser.h @@ -40,7 +40,7 @@ extern int yydebug; #endif /* "%code requires" blocks. */ -#line 36 "fmd_parser.y" /* yacc.c:1909 */ +#line 37 "fmd_parser.y" /* yacc.c:1909 */ #include "fmd.h" #include "option.h" @@ -87,7 +87,7 @@ void yyerror(const char *s); typedef union YYSTYPE YYSTYPE; union YYSTYPE { -#line 28 "fmd_parser.y" /* yacc.c:1909 */ +#line 29 "fmd_parser.y" /* yacc.c:1909 */ unsigned intval; char *strval; diff --git a/util/cbfstool/fmd_parser.y b/util/cbfstool/fmd_parser.y index 292fba3d8a..2327ae4fbe 100644 --- a/util/cbfstool/fmd_parser.y +++ b/util/cbfstool/fmd_parser.y @@ -19,6 +19,7 @@ %{ #include "fmd_scanner.h" +#include "common.h" #include <stdlib.h> @@ -90,7 +91,7 @@ flash_region: region_name region_annotation_opt region_offset_opt char *annotation = $2; if (annotation && !fmd_process_annotation_impl(node, annotation)) { - fprintf(stderr, "ERROR: Section '%s' has unexpected annotation '(%s)'\n", + ERROR("Section '%s' has unexpected annotation '(%s)'\n", node->name, annotation); YYABORT; } @@ -101,7 +102,7 @@ flash_region: region_name region_annotation_opt region_offset_opt region_name: STRING { if (!$1) { - perror("ERROR: While allocating section name"); + perror("E: While allocating section name"); YYABORT; } }; @@ -125,7 +126,7 @@ region_list_entries: flash_region { struct descriptor_node *node = malloc(sizeof(*node)); if (!node) { - perror("ERROR: While allocating linked list node"); + perror("E: While allocating linked list node"); YYABORT; } node->val = $1; @@ -136,7 +137,7 @@ region_list_entries: flash_region { struct descriptor_node *node = malloc(sizeof(*node)); if (!node) { - perror("ERROR: While allocating linked list node"); + perror("E: While allocating linked list node"); YYABORT; } node->val = $2; @@ -155,7 +156,7 @@ struct flashmap_descriptor *parse_descriptor(char *name, { struct flashmap_descriptor *region = malloc(sizeof(*region)); if (!region) { - perror("ERROR: While allocating descriptor section"); + perror("E: While allocating descriptor section"); return NULL; } region->name = name; @@ -167,7 +168,7 @@ struct flashmap_descriptor *parse_descriptor(char *name, if (region->list_len) { region->list = malloc(region->list_len * sizeof(*region->list)); if (!region->list) { - perror("ERROR: While allocating node children array"); + perror("E: While allocating node children array"); return NULL; } struct descriptor_node *cur_node = children.head; |