From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F08EDC433EF for ; Tue, 9 Nov 2021 08:10:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E6CF6112D for ; Tue, 9 Nov 2021 08:10:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6E6CF6112D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3BE98391D; Tue, 9 Nov 2021 09:10:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mrKuEZGL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 82B7383918; Tue, 9 Nov 2021 09:10:16 +0100 (CET) Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C79F283911 for ; Tue, 9 Nov 2021 09:10:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rfried.dev@gmail.com Received: by mail-ot1-x333.google.com with SMTP id o15-20020a9d410f000000b0055c942cc7a0so7038093ote.8 for ; Tue, 09 Nov 2021 00:10:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0wPEfDnrA5Y3TvPDLKylxK26e1U3NSu1CmCcQUPKax8=; b=mrKuEZGLRdNe9FtTJQ6wTCnXuHR50WRePH9DNjrHDkz8p3Od4taL3EGaJUky5ZbOWe NQWEJc4XrGDgVgefaqjMlEw4PYRC/sc9W+xqO5oVMWNvVfF0X6OqahhaSp0V+xJidePH YBT3XyQ9WNr1TyHa/falilFRUm2R8NupDofd7DkKS5RHUCSpcsFycItfHDB7JWJ7lXCn jxZptaR5g0oTD6EPeFFv9s2yH48YpWa1dVOcx6O8FoyGKWKyurQo5XMrMONCYMqH34oK VOm04IhIN9mfHTQuo4URWQ4B/UsI6g/dKF+U7urhsCLtQl7t61UpNHwc5CjD7CJK9cvU oDhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0wPEfDnrA5Y3TvPDLKylxK26e1U3NSu1CmCcQUPKax8=; b=ArYgfvwZDVB+F+41e8Y61Chf/v6Cq1wJPCSHTF1LXG4loI8BCBWoBJEDyo5dhhqFC/ pKNm+8nH6L1rM1hOPxiUDJSfdO0S4O1uPerA15VlGWCSTow24nNhIfZz+Fi3BTYX/fDt 0yF28CH4IPPrif0hoPPayJhLi1Xd2sKTZAhzmaRmfGx6LoIi1109UCWrdbgius4xm6vz HswWgmSTJbMOG2L8sPZXZWshMcP3bWQUCxPgAneg1ip/lWuwvSiM7028tjdGRDpxeP91 IhgQNS+zj5kUqxb6iOL1EOUiNQrgwS1z+hokoi8Wpys+f1dPh6orb+KffSUEYr/j7DRZ dMng== X-Gm-Message-State: AOAM532enka6E8uCnDP56s49GtDpLGpAcaxg6EApPbJiFEfc6vyQAZ5e RP5CoEcIMcpaupCe4kRCIXRJAerXgLmcYuOnxDw= X-Google-Smtp-Source: ABdhPJznED9APxoytqEwzqzvKzjtlYjibC/1X49JydxSnlaTSJ4bmEJxl4nx6yLvRDjbAaJhFdaWV8YOSxj02vZ53t8= X-Received: by 2002:a9d:6646:: with SMTP id q6mr4432351otm.327.1636445410473; Tue, 09 Nov 2021 00:10:10 -0800 (PST) MIME-Version: 1.0 References: <20211014184811.482560-1-sjg@chromium.org> <20211014124803.v3.10.I46706f534446a1cae5a459722b7d4c0c90ca777e@changeid> In-Reply-To: <20211014124803.v3.10.I46706f534446a1cae5a459722b7d4c0c90ca777e@changeid> From: Ramon Fried Date: Tue, 9 Nov 2021 10:09:59 +0200 Message-ID: Subject: Re: [PATCH v3 10/18] pxe: Move common parsing coding into pxe_util To: Simon Glass Cc: U-Boot Mailing List , Patrice Chotard , Artem Lapkin , Tom Rini , Joe Hershberger , Heinrich Schuchardt , Peter Hoyes Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Thu, Oct 14, 2021 at 9:51 PM Simon Glass wrote: > > Both the syslinux and pxe commands use essentially the same code to parse > and run extlinux.conf files. Move this into a common function. > > Signed-off-by: Simon Glass > --- > > (no changes since v1) > > boot/pxe_utils.c | 20 ++++++++++++++++++++ > cmd/pxe.c | 15 ++++----------- > cmd/sysboot.c | 18 ++++-------------- > include/pxe_utils.h | 9 +++++++++ > 4 files changed, 37 insertions(+), 25 deletions(-) > > diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c > index 9f3edeab06a..225729ce57f 100644 > --- a/boot/pxe_utils.c > +++ b/boot/pxe_utils.c > @@ -1486,3 +1486,23 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, > ctx->userdata = userdata; > ctx->allow_abs_path = allow_abs_path; > } > + > +int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt) > +{ > + struct pxe_menu *cfg; > + > + cfg = parse_pxefile(ctx, pxefile_addr_r); > + if (!cfg) { > + printf("Error parsing config file\n"); > + return 1; > + } > + > + if (prompt) > + cfg->prompt = 1; > + > + handle_pxe_menu(ctx, cfg); > + > + destroy_pxe_menu(cfg); > + > + return 0; > +} > diff --git a/cmd/pxe.c b/cmd/pxe.c > index 17fe364bed9..4fa51d2e053 100644 > --- a/cmd/pxe.c > +++ b/cmd/pxe.c > @@ -171,9 +171,9 @@ static int > do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > { > unsigned long pxefile_addr_r; > - struct pxe_menu *cfg; > char *pxefile_addr_str; > struct pxe_context ctx; > + int ret; > > pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false); > > @@ -193,16 +193,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > return 1; > } > > - cfg = parse_pxefile(&ctx, pxefile_addr_r); > - > - if (!cfg) { > - printf("Error parsing config file\n"); > - return 1; > - } > - > - handle_pxe_menu(&ctx, cfg); > - > - destroy_pxe_menu(cfg); > + ret = pxe_process(&ctx, pxefile_addr_r, false); > + if (ret) > + return CMD_RET_FAILURE; > > copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name)); > > diff --git a/cmd/sysboot.c b/cmd/sysboot.c > index b81255e155a..7ee14df79e5 100644 > --- a/cmd/sysboot.c > +++ b/cmd/sysboot.c > @@ -60,10 +60,10 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, > { > unsigned long pxefile_addr_r; > struct pxe_context ctx; > - struct pxe_menu *cfg; > char *pxefile_addr_str; > char *filename; > int prompt = 0; > + int ret; > > if (argc > 1 && strstr(argv[1], "-p")) { > prompt = 1; > @@ -113,19 +113,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, > return 1; > } > > - cfg = parse_pxefile(&ctx, pxefile_addr_r); > - > - if (!cfg) { > - printf("Error parsing config file\n"); > - return 1; > - } > - > - if (prompt) > - cfg->prompt = 1; > - > - handle_pxe_menu(&ctx, cfg); > - > - destroy_pxe_menu(cfg); > + ret = pxe_process(&ctx, pxefile_addr_r, prompt); > + if (ret) > + return CMD_RET_FAILURE; > > return 0; > } > diff --git a/include/pxe_utils.h b/include/pxe_utils.h > index 6681442ea55..0cae0dabec3 100644 > --- a/include/pxe_utils.h > +++ b/include/pxe_utils.h > @@ -202,4 +202,13 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, > pxe_getfile_func getfile, void *userdata, > bool allow_abs_path); > > +/** > + * pxe_process() - Process a PXE file through to boot > + * > + * @ctx: PXE context created with pxe_setup_ctx() > + * @pxefile_addr_r: Address to load file > + * @prompt: Force a prompt for the user > + */ > +int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); > + > #endif /* __PXE_UTILS_H */ > -- > 2.33.0.1079.g6e70778dc9-goog > Reviewed-by: Ramon Fried