fmaptool: Conform to cbfstool's error message format

The tool now makes use of the ERROR() macros from common.h.

Change-Id: Ie38f40c65f7b6d3bc2adb97e246224cd38d4cb99
Signed-off-by: Sol Boucher <solb@chromium.org>
Reviewed-on: http://review.coreboot.org/10048
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Sol Boucher 2015-03-18 10:13:48 -07:00 committed by Stefan Reinauer
parent e3260a042f
commit b974081c13
5 changed files with 68 additions and 76 deletions

View File

@ -28,9 +28,8 @@ 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) {
if (strlen(section->name) >= FMAP_STRLEN) { if (strlen(section->name) >= FMAP_STRLEN) {
fprintf(stderr, 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);
return false; return false;
} }
@ -38,9 +37,8 @@ static bool fmap_append_fmd_node(struct fmap **flashmap,
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, 0) < 0) {
fprintf(stderr, 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;
} }
@ -59,8 +57,7 @@ struct fmap *fmap_from_fmd(const struct flashmap_descriptor *desc)
assert(desc->size_known); assert(desc->size_known);
if (strlen(desc->name) >= FMAP_STRLEN) { 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); desc->name, FMAP_STRLEN - 1);
return NULL; 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, struct fmap *fmap = fmap_create(desc->offset_known ? desc->offset : 0,
desc->size, (uint8_t *)desc->name); desc->size, (uint8_t *)desc->name);
if (!fmap) { if (!fmap) {
fputs("ERROR: Failed to allocate FMAP header\n", stderr); ERROR("Failed to allocate FMAP header\n");
return fmap; return fmap;
} }

View File

@ -19,6 +19,7 @@
#include "fmd.h" #include "fmd.h"
#include "common.h"
#include "fmd_parser.h" #include "fmd_parser.h"
#include "fmd_scanner.h" #include "fmd_scanner.h"
#include "option.h" #include "option.h"
@ -56,8 +57,7 @@ static bool validate_descriptor_node(const struct flashmap_descriptor *node,
ENTRY search_key = {node->name, NULL}; ENTRY search_key = {node->name, NULL};
if (hsearch(search_key, FIND)) { if (hsearch(search_key, FIND)) {
fprintf(stderr, "ERROR: Multiple sections with name '%s'\n", ERROR("Multiple sections with name '%s'\n", node->name);
node->name);
return false; return false;
} }
if (!hsearch(search_key, ENTER)) if (!hsearch(search_key, ENTER))
@ -65,26 +65,22 @@ static bool validate_descriptor_node(const struct flashmap_descriptor *node,
if (node->offset_known) { if (node->offset_known) {
if (start.val_known && node->offset < start.val) { if (start.val_known && node->offset < start.val) {
fprintf(stderr, "ERROR: Section '%s' starts too low\n", ERROR("Section '%s' starts too low\n", node->name);
node->name);
return false; return false;
} else if (end.val_known && node->offset > end.val) { } else if (end.val_known && node->offset > end.val) {
fprintf(stderr, "ERROR: Section '%s' starts too high\n", ERROR("Section '%s' starts too high\n", node->name);
node->name);
return false; return false;
} }
} }
if (node->size_known) { if (node->size_known) {
if (node->size == 0) { if (node->size == 0) {
fprintf(stderr, "ERROR: Section '%s' given no space\n", ERROR("Section '%s' given no space\n", node->name);
node->name);
return false; return false;
} else if (node->offset_known) { } else if (node->offset_known) {
unsigned node_end = node->offset + node->size; unsigned node_end = node->offset + node->size;
if (end.val_known && node_end > end.val) { if (end.val_known && node_end > end.val) {
fprintf(stderr, "ERROR: Section '%s' too big\n", ERROR("Section '%s' too big\n", node->name);
node->name);
return false; return false;
} }
} }
@ -120,16 +116,14 @@ static bool complete_missing_info_backward(
assert(cur->offset_known || cur->size_known); assert(cur->offset_known || cur->size_known);
if (!cur->offset_known) { if (!cur->offset_known) {
if (cur->size > end_watermark) { if (cur->size > end_watermark) {
fprintf(stderr, "ERROR: Section '%s' too big\n", ERROR("Section '%s' too big\n", cur->name);
cur->name);
return false; return false;
} }
cur->offset_known = true; cur->offset_known = true;
cur->offset = end_watermark -= cur->size; cur->offset = end_watermark -= cur->size;
} else if (!cur->size_known) { } else if (!cur->size_known) {
if (cur->offset > end_watermark) { if (cur->offset > end_watermark) {
fprintf(stderr, ERROR("Section '%s' starts too high\n",
"ERROR: Section '%s' starts too high\n",
cur->name); cur->name);
return false; 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->size_known) {
if (!cur_section->offset_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); cur_section->name);
return false; return false;
} else if (!first_incomplete_it) { } 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 // This hash table is used to store the declared name of each
// section and ensure that each is globally unique. // section and ensure that each is globally unique.
if (!hcreate(fmd_count_nodes(ret))) { if (!hcreate(fmd_count_nodes(ret))) {
perror("ERROR: While initializing hashtable"); perror("E: While initializing hashtable");
fmd_cleanup(ret); fmd_cleanup(ret);
return NULL; return NULL;
} }

View File

@ -65,12 +65,13 @@
#line 20 "fmd_parser.y" /* yacc.c:339 */ #line 20 "fmd_parser.y" /* yacc.c:339 */
#include "fmd_scanner.h" #include "fmd_scanner.h"
#include "common.h"
#include <stdlib.h> #include <stdlib.h>
struct flashmap_descriptor *res = NULL; struct flashmap_descriptor *res = NULL;
#line 74 "y.tab.c" /* yacc.c:339 */ #line 75 "y.tab.c" /* yacc.c:339 */
# ifndef YY_NULLPTR # ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus # if defined __cplusplus && 201103L <= __cplusplus
@ -100,7 +101,7 @@ struct flashmap_descriptor *res = NULL;
extern int yydebug; extern int yydebug;
#endif #endif
/* "%code requires" blocks. */ /* "%code requires" blocks. */
#line 36 "fmd_parser.y" /* yacc.c:355 */ #line 37 "fmd_parser.y" /* yacc.c:355 */
#include "fmd.h" #include "fmd.h"
#include "option.h" #include "option.h"
@ -125,7 +126,7 @@ struct flashmap_descriptor *parse_descriptor(char *name,
struct descriptor_list children); struct descriptor_list children);
void yyerror(const char *s); void yyerror(const char *s);
#line 129 "y.tab.c" /* yacc.c:355 */ #line 130 "y.tab.c" /* yacc.c:355 */
/* Token type. */ /* Token type. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
@ -147,7 +148,7 @@ void yyerror(const char *s);
typedef union YYSTYPE YYSTYPE; typedef union YYSTYPE YYSTYPE;
union YYSTYPE union YYSTYPE
{ {
#line 28 "fmd_parser.y" /* yacc.c:355 */ #line 29 "fmd_parser.y" /* yacc.c:355 */
unsigned intval; unsigned intval;
char *strval; char *strval;
@ -155,7 +156,7 @@ union YYSTYPE
struct flashmap_descriptor *region_ptr; struct flashmap_descriptor *region_ptr;
struct descriptor_list region_listhdr; 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_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
@ -170,7 +171,7 @@ int yyparse (void);
/* Copy the second part of user declarations. */ /* 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 #ifdef short
# undef short # undef short
@ -468,8 +469,8 @@ static const yytype_uint8 yytranslate[] =
/* 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, 84, 101, 108, 109, 110, 111, 112, 0, 80, 80, 85, 102, 109, 110, 111, 112, 113,
113, 114, 115, 116, 118, 122, 123, 124, 135 114, 115, 116, 117, 119, 123, 124, 125, 136
}; };
#endif #endif
@ -1251,16 +1252,16 @@ 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 */
{ {
if (!(res = parse_descriptor((yyvsp[-3].strval), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr)))) if (!(res = parse_descriptor((yyvsp[-3].strval), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr))))
YYABORT; YYABORT;
} }
#line 1260 "y.tab.c" /* yacc.c:1646 */ #line 1261 "y.tab.c" /* yacc.c:1646 */
break; break;
case 3: 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)); struct flashmap_descriptor *node = parse_descriptor((yyvsp[-4].strval), (yyvsp[-2].maybe_intval), (yyvsp[-1].maybe_intval), (yyvsp[0].region_listhdr));
if (!node) if (!node)
@ -1268,7 +1269,7 @@ yyreduce:
char *annotation = (yyvsp[-3].strval); char *annotation = (yyvsp[-3].strval);
if (annotation && !fmd_process_annotation_impl(node, annotation)) { 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); node->name, annotation);
YYABORT; YYABORT;
} }
@ -1276,92 +1277,92 @@ yyreduce:
(yyval.region_ptr) = node; (yyval.region_ptr) = node;
} }
#line 1280 "y.tab.c" /* yacc.c:1646 */ #line 1281 "y.tab.c" /* yacc.c:1646 */
break; break;
case 4: case 4:
#line 102 "fmd_parser.y" /* yacc.c:1646 */ #line 103 "fmd_parser.y" /* yacc.c:1646 */
{ {
if (!(yyvsp[0].strval)) { if (!(yyvsp[0].strval)) {
perror("ERROR: While allocating section name"); perror("E: While allocating section name");
YYABORT; YYABORT;
} }
} }
#line 1291 "y.tab.c" /* yacc.c:1646 */ #line 1292 "y.tab.c" /* yacc.c:1646 */
break; break;
case 5: case 5:
#line 108 "fmd_parser.y" /* yacc.c:1646 */ #line 109 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.strval) = NULL; } { (yyval.strval) = NULL; }
#line 1297 "y.tab.c" /* yacc.c:1646 */ #line 1298 "y.tab.c" /* yacc.c:1646 */
break; break;
case 7: case 7:
#line 110 "fmd_parser.y" /* yacc.c:1646 */ #line 111 "fmd_parser.y" /* yacc.c:1646 */
{ (yyval.strval) = (yyvsp[-1].strval); } { (yyval.strval) = (yyvsp[-1].strval); }
#line 1303 "y.tab.c" /* yacc.c:1646 */ #line 1304 "y.tab.c" /* yacc.c:1646 */
break; break;
case 8: 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}; } { (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; break;
case 10: 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)}; } { (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; break;
case 11: 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}; } { (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; break;
case 13: 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)}; } { (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; break;
case 14: case 14:
#line 118 "fmd_parser.y" /* yacc.c:1646 */ #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 1336 "y.tab.c" /* yacc.c:1646 */ #line 1337 "y.tab.c" /* yacc.c:1646 */
break; break;
case 16: 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); } { (yyval.region_listhdr) = (yyvsp[-1].region_listhdr); }
#line 1342 "y.tab.c" /* yacc.c:1646 */ #line 1343 "y.tab.c" /* yacc.c:1646 */
break; break;
case 17: 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)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
perror("ERROR: While allocating linked list node"); perror("E: While allocating linked list node");
YYABORT; YYABORT;
} }
node->val = (yyvsp[0].region_ptr); node->val = (yyvsp[0].region_ptr);
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 1357 "y.tab.c" /* yacc.c:1646 */ #line 1358 "y.tab.c" /* yacc.c:1646 */
break; break;
case 18: 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)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
perror("ERROR: While allocating linked list node"); perror("E: While allocating linked list node");
YYABORT; YYABORT;
} }
node->val = (yyvsp[0].region_ptr); node->val = (yyvsp[0].region_ptr);
@ -1371,11 +1372,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 1375 "y.tab.c" /* yacc.c:1646 */ #line 1376 "y.tab.c" /* yacc.c:1646 */
break; break;
#line 1379 "y.tab.c" /* yacc.c:1646 */ #line 1380 "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
@ -1603,7 +1604,7 @@ yyreturn:
#endif #endif
return yyresult; 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, 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)); struct flashmap_descriptor *region = malloc(sizeof(*region));
if (!region) { if (!region) {
perror("ERROR: While allocating descriptor section"); perror("E: While allocating descriptor section");
return NULL; return NULL;
} }
region->name = name; region->name = name;
@ -1624,7 +1625,7 @@ struct flashmap_descriptor *parse_descriptor(char *name,
if (region->list_len) { if (region->list_len) {
region->list = malloc(region->list_len * sizeof(*region->list)); region->list = malloc(region->list_len * sizeof(*region->list));
if (!region->list) { if (!region->list) {
perror("ERROR: While allocating node children array"); perror("E: While allocating node children array");
return NULL; return NULL;
} }
struct descriptor_node *cur_node = children.head; struct descriptor_node *cur_node = children.head;

View File

@ -40,7 +40,7 @@
extern int yydebug; extern int yydebug;
#endif #endif
/* "%code requires" blocks. */ /* "%code requires" blocks. */
#line 36 "fmd_parser.y" /* yacc.c:1909 */ #line 37 "fmd_parser.y" /* yacc.c:1909 */
#include "fmd.h" #include "fmd.h"
#include "option.h" #include "option.h"
@ -87,7 +87,7 @@ void yyerror(const char *s);
typedef union YYSTYPE YYSTYPE; typedef union YYSTYPE YYSTYPE;
union YYSTYPE union YYSTYPE
{ {
#line 28 "fmd_parser.y" /* yacc.c:1909 */ #line 29 "fmd_parser.y" /* yacc.c:1909 */
unsigned intval; unsigned intval;
char *strval; char *strval;

View File

@ -19,6 +19,7 @@
%{ %{
#include "fmd_scanner.h" #include "fmd_scanner.h"
#include "common.h"
#include <stdlib.h> #include <stdlib.h>
@ -90,7 +91,7 @@ flash_region: region_name region_annotation_opt region_offset_opt
char *annotation = $2; char *annotation = $2;
if (annotation && !fmd_process_annotation_impl(node, annotation)) { 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); node->name, annotation);
YYABORT; YYABORT;
} }
@ -101,7 +102,7 @@ flash_region: region_name region_annotation_opt region_offset_opt
region_name: STRING region_name: STRING
{ {
if (!$1) { if (!$1) {
perror("ERROR: While allocating section name"); perror("E: While allocating section name");
YYABORT; YYABORT;
} }
}; };
@ -125,7 +126,7 @@ region_list_entries: flash_region
{ {
struct descriptor_node *node = malloc(sizeof(*node)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
perror("ERROR: While allocating linked list node"); perror("E: While allocating linked list node");
YYABORT; YYABORT;
} }
node->val = $1; node->val = $1;
@ -136,7 +137,7 @@ region_list_entries: flash_region
{ {
struct descriptor_node *node = malloc(sizeof(*node)); struct descriptor_node *node = malloc(sizeof(*node));
if (!node) { if (!node) {
perror("ERROR: While allocating linked list node"); perror("E: While allocating linked list node");
YYABORT; YYABORT;
} }
node->val = $2; node->val = $2;
@ -155,7 +156,7 @@ struct flashmap_descriptor *parse_descriptor(char *name,
{ {
struct flashmap_descriptor *region = malloc(sizeof(*region)); struct flashmap_descriptor *region = malloc(sizeof(*region));
if (!region) { if (!region) {
perror("ERROR: While allocating descriptor section"); perror("E: While allocating descriptor section");
return NULL; return NULL;
} }
region->name = name; region->name = name;
@ -167,7 +168,7 @@ struct flashmap_descriptor *parse_descriptor(char *name,
if (region->list_len) { if (region->list_len) {
region->list = malloc(region->list_len * sizeof(*region->list)); region->list = malloc(region->list_len * sizeof(*region->list));
if (!region->list) { if (!region->list) {
perror("ERROR: While allocating node children array"); perror("E: While allocating node children array");
return NULL; return NULL;
} }
struct descriptor_node *cur_node = children.head; struct descriptor_node *cur_node = children.head;