From: Simon Glass <sjg@chromium.org> The PXE parser prints informational messages like "Ignoring unknown command" and "Ignoring malformed menu command" unconditionally. This is useful during interactive boot, but not appropriate when parsing is done silently for metadata extraction, such as during bootflow scanning. Thread the pxe_context through parse_label() and parse_label_menu() so they can check ctx->quiet, and gate all three warning printf() calls on !ctx->quiet Set ctx->quiet in pxe_parse() since it is a non-interactive parsing API intended for callers that handle output themselves. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/pxe_parse.c | 27 ++++++++++++++++----------- boot/pxe_utils.c | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/boot/pxe_parse.c b/boot/pxe_parse.c index a33e40002e9..44cbb9aba86 100644 --- a/boot/pxe_parse.c +++ b/boot/pxe_parse.c @@ -498,8 +498,9 @@ static int parse_menu(struct pxe_context *ctx, char **c, struct pxe_menu *cfg, err = parse_sliteral(c, &cfg->bmp, limit); break; default: - printf("Ignoring malformed menu command: %.*s\n", - (int)(*c - s), s); + if (!ctx->quiet) + printf("Ignoring malformed menu command: %.*s\n", + (int)(*c - s), s); } free(t.val); if (err < 0) @@ -513,8 +514,9 @@ static int parse_menu(struct pxe_context *ctx, char **c, struct pxe_menu *cfg, /* * Handles parsing a 'menu line' when we're parsing a label. */ -static int parse_label_menu(char **c, struct pxe_menu *cfg, - struct pxe_label *label, const char *limit) +static int parse_label_menu(struct pxe_context *ctx, char **c, + struct pxe_menu *cfg, struct pxe_label *label, + const char *limit) { struct token t; char *s; @@ -536,8 +538,9 @@ static int parse_label_menu(char **c, struct pxe_menu *cfg, parse_sliteral(c, &label->menu, limit); break; default: - printf("Ignoring malformed menu command: %.*s\n", - (int)(*c - s), s); + if (!ctx->quiet) + printf("Ignoring malformed menu command: %.*s\n", + (int)(*c - s), s); } free(t.val); @@ -584,7 +587,8 @@ static int parse_label_kernel(char **c, struct pxe_label *label, * get some input we otherwise don't have a handler defined * for. */ -static int parse_label(char **c, struct pxe_menu *cfg, const char *limit) +static int parse_label(struct pxe_context *ctx, char **c, struct pxe_menu *cfg, + const char *limit) { struct token t; int len; @@ -614,7 +618,7 @@ static int parse_label(char **c, struct pxe_menu *cfg, const char *limit) err = 0; switch (t.type) { case T_MENU: - err = parse_label_menu(c, cfg, label, limit); + err = parse_label_menu(ctx, c, cfg, label, limit); break; case T_KERNEL: case T_LINUX: @@ -770,7 +774,7 @@ int parse_pxefile_top(struct pxe_context *ctx, char *p, const char *limit, err = parse_integer(&p, &cfg->timeout, limit); break; case T_LABEL: - err = parse_label(&p, cfg, limit); + err = parse_label(ctx, &p, cfg, limit); break; case T_DEFAULT: case T_ONTIMEOUT: @@ -806,8 +810,9 @@ int parse_pxefile_top(struct pxe_context *ctx, char *p, const char *limit, free(t.val); return 1; default: - printf("Ignoring unknown command: %.*s\n", - (int)(p - s), s); + if (!ctx->quiet) + printf("Ignoring unknown command: %.*s\n", + (int)(p - s), s); eol_or_eof(&p); } diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index e5f1f3e46c2..f5f8e38de2e 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -1426,6 +1426,7 @@ struct pxe_context *pxe_parse(ulong addr, ulong size, const char *bootfile) free(ctx); return NULL; } + ctx->quiet = true; ctx->pxe_file_size = size; abuf_init_addr(&buf, addr, size); -- 2.43.0