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 48199C433EF for ; Thu, 14 Oct 2021 18:51:10 +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 C1D1361090 for ; Thu, 14 Oct 2021 18:51:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C1D1361090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 3B77C837CC; Thu, 14 Oct 2021 20:50:32 +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="TiIxRvoI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4A38A83653; Thu, 14 Oct 2021 20:49:06 +0200 (CEST) Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (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 1F15983693 for ; Thu, 14 Oct 2021 20:48:34 +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-xd31.google.com with SMTP id r134so4942411iod.11 for ; Thu, 14 Oct 2021 11:48:34 -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=KB33g9ojk4OvgLupxO1SRGsWbQhWROK4vdtrvXvosd8=; b=TiIxRvoIRq41BS4DCq9y8c3ZVnpan1TXRiKa1dEjTLSX2yYLBWR/MgV/g+9KFRES+G adClJWNPU7kdkb+xgQQpIBRhk1YNfuOk0hHTqRpBAco4LTC24QfDtuC3GNvekoTd2Zx0 RvHBzuYfUDd5b7XvXDLY4SBmppxOvszV8Gu6U= 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=KB33g9ojk4OvgLupxO1SRGsWbQhWROK4vdtrvXvosd8=; b=YgcJ+oidJFBpwjXeYqWmH0TfE9rVwGxnySvVsTRLwstxUdAuGLk7bsnVPFjZR+g5YM VnvDkR/TncEn//XScb8/FVE0es9sZKd0DF+6Efw+cGqH8O2GjHHtyojTf6G+vK3btcWu 5tKFSy+AQ4e6jP2Yjm6B58f3sAe6auU6K0V0cmUbUVcXoVgtMEXqGJSWHf6MVV5/mA1d xM+HNQLPD5FcS8JprYN45hnoYwxQfdNAIEz9uPN/VixfDS6UQ50FLyuzXmPFJw3NT7xD v/1M8Gopn8C8cYZ/IROPf0eXEkZNue2W4Um9ATHmIBDH7SCpAMhNEDAgI9sn0RFMKaCi 87SA== X-Gm-Message-State: AOAM531QNvcGCY8k2XG8r8mLVkNDmAwl1QyvS7tokj13YZaPiHEEib4g ttW0wdvWXLn9DbZ9KVGv0UaieFNjT9I1+g== X-Google-Smtp-Source: ABdhPJzMJD1CgzMSYuQrIc/Z8OBayTCu/rTCqfP0bk6MTZrVFdLPOw/5Q9TG4qhHv8HjI4LrisWUNg== X-Received: by 2002:a5d:9d9c:: with SMTP id ay28mr514271iob.206.1634237312561; Thu, 14 Oct 2021 11:48:32 -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 w15sm1697625ill.23.2021.10.14.11.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 11:48:32 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Patrice Chotard , Artem Lapkin , Tom Rini , Joe Hershberger , Heinrich Schuchardt , Peter Hoyes , Simon Glass Subject: [PATCH v3 10/18] pxe: Move common parsing coding into pxe_util Date: Thu, 14 Oct 2021 12:48:03 -0600 Message-Id: <20211014124803.v3.10.I46706f534446a1cae5a459722b7d4c0c90ca777e@changeid> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211014184811.482560-1-sjg@chromium.org> References: <20211014184811.482560-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 */ -- 2.33.0.1079.g6e70778dc9-goog