From patchwork Mon Sep 27 15:23:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1533414 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=kiSq+xaU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HJ64f4WMmz9ssP for ; Tue, 28 Sep 2021 01:29:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 26F8183223; Mon, 27 Sep 2021 17:29:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kiSq+xaU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF48982BD6; Mon, 27 Sep 2021 17:25:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (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 B853582DF6 for ; Mon, 27 Sep 2021 17:24:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2f.google.com with SMTP id i62so7266810ioa.6 for ; Mon, 27 Sep 2021 08:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cQTOuab3xbtixSxGRiR2iM4AeqSgrlDO8ykQtasbETQ=; b=kiSq+xaU5jZFvekyWZFONVbJYiqsBF3fhmqfpjh0j3CXLcspJoH3vdeljjxuI2dfcy 4HVaNPHp2KJBsrUs6lv5gD9cW+ZZLCnICHqLtWasI6SsMq6EACdIboPe85PRp8NLWKtG B2znnPvxFNd0bzSSIcmbfcgTBE4EEr9qAHGxI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cQTOuab3xbtixSxGRiR2iM4AeqSgrlDO8ykQtasbETQ=; b=czn5Ux+qNSbleDvieV21Y3igg+pad1CXXq5+G9ZZmWkVJjfpug+CP1dPeEvcDjMSuI ORZDKEdcDno9JfaQXd+jIbdsvd8nUGD8Kt0t4Hq8hdQ1Xk+pKF3sOW+gWEYiAAZ11Nun CUbvdcElIb2RmXyLz4mPWfW4cvY+T7qJRVWa93A+vGRO31TxicYiy+9lVpEticRDtyXY nQ9/Vd3Rm0RnwGIrOWoj0hU4jMx+NNur7+yjcFJtx8PAn999GTdG3La4CRCrDG1ljBtP xNi9HIsYmGEZvn6dmfirmjfGh12PSmrhCttb6RpKwQPPkZL1xX0j+PxIhSOJEqbK6288 wGgQ== X-Gm-Message-State: AOAM530LEgkN1ci9urJjzhXDDe+IFC1GOIQ/Q/tumiQFcXIVvkTJD86a 1ASFqyVB4ex08L/w4ejv1GlWfzFR2ftzVQ== X-Google-Smtp-Source: ABdhPJwXxZPf3YV6zsCPlWD4hHgaHorKPoDCeyxGuTwgl2iFtNCpiL9sxbj7rxSDKYJyioPxxiZozQ== X-Received: by 2002:a02:5444:: with SMTP id t65mr464594jaa.42.1632756252774; Mon, 27 Sep 2021 08:24:12 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id c14sm5587793ioz.21.2021.09.27.08.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 08:24:12 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Patrice Chotard , Tom Rini , Simon Glass Subject: [PATCH v2 10/18] pxe: Move common parsing coding into pxe_util Date: Mon, 27 Sep 2021 09:23:52 -0600 Message-Id: <20210927092350.v2.10.I46706f534446a1cae5a459722b7d4c0c90ca777e@changeid> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog In-Reply-To: <20210927152400.433569-1-sjg@chromium.org> References: <20210927152400.433569-1-sjg@chromium.org> MIME-Version: 1.0 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 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 */