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 X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EEE1C4338F for ; Thu, 19 Aug 2021 03:49:50 +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 227A96109E for ; Thu, 19 Aug 2021 03:49:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 227A96109E 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 879ED83237; Thu, 19 Aug 2021 05:47:33 +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="ZGPzrAN8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 606BE831C7; Thu, 19 Aug 2021 05:46:42 +0200 (CEST) Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (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 7F71A831AC for ; Thu, 19 Aug 2021 05:46:33 +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-oo1-xc33.google.com with SMTP id m11-20020a056820034b00b0028bb60b551fso1408553ooe.5 for ; Wed, 18 Aug 2021 20:46:33 -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=sv8pRvsa8pcj8Vxz0b48t0AEucfhPeiAWqpCF9Iptpg=; b=ZGPzrAN8mALlupzpMiED2q5AKJTnzHhPe6z9ppCHbxyrgdJ+iSqxz1W37uhKKCiSlg NDsqewfXtpnmxu79BSVMGy7oaEpQa+R4lRBHZNu62u16qMlUcA+geLnwRhh2RsRLLGJt k6+WIehMlc8t2WSYZkxExUavbD3x2mXpo0iLc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sv8pRvsa8pcj8Vxz0b48t0AEucfhPeiAWqpCF9Iptpg=; b=VLO3mi8I6f8jODIxR4NqquNqGc0U0I+fD6UdafQPQuePD8dljgFV4CiX7LD3hPzuHQ FBRX6enjZSkqSw5tr/e1giE28adtOdz0RMlY7OhnzQUkFvGdopWmQaBm+2ATkHgv8F5/ AkAGL9zkQ3mtEa+1kWEcb8zVD8Jnfl8y6aCbRSZBlkD8npc+N4GsgLNXcswNH3/4yta3 WaVZfP+jd/cEFRTugaR4//b8VwPY82WglzyYqyLtQag5JpLiFHDxlr11HZx8/tCBxf5c Q9tA9wGa8E0Zb89CC6Q7IwyI0UqoOK8Al22HQ4uTHl203ax79Phev6JYaZPnkkAhiwoW uT0A== X-Gm-Message-State: AOAM5317Q7EZk8UEToSKuqo0nyX8YFuHQ/49pV8xPtTGyHF5AP1lYgBI lkZJ7V2urzFfIHhoKBgKo/KLzhoXMbLAGw== X-Google-Smtp-Source: ABdhPJzmoEO0Nu3iNTu7+mPkplqPB9qiwHLJAGW3E78EoPJxMsZyXYG1n4RvPRZfnMgGrEaKP2zyfQ== X-Received: by 2002:a4a:d892:: with SMTP id b18mr9634273oov.0.1629344791602; Wed, 18 Aug 2021 20:46:31 -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 q3sm370025ooa.13.2021.08.18.20.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:46:31 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Steffen Jaeckel , Michal Simek , Tom Rini , Dennis Gilmore , Daniel Schwierzeck , Lukas Auer , Simon Glass Subject: [PATCH 18/28] pxe: Allow calling the pxe_get logic directly Date: Wed, 18 Aug 2021 21:45:51 -0600 Message-Id: <20210818214547.18.Ie921ec7581f232b07cda0e740bf65d66fb93f230@changeid> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210819034601.1618773-1-sjg@chromium.org> References: <20210819034601.1618773-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 Refactor this code so that we can call the 'pxe get' command without going through the command-line interpreter. This makes it easier to get the information we need, without going through environment variables. Signed-off-by: Simon Glass --- cmd/pxe.c | 92 +++++++++++++++++++++++++++++---------------- include/pxe_utils.h | 14 +++++++ 2 files changed, 73 insertions(+), 33 deletions(-) diff --git a/cmd/pxe.c b/cmd/pxe.c index 81703386c42..db8e4697f24 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -104,6 +104,49 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_ return -ENOENT; } + +int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep) +{ + struct cmd_tbl cmdtp[] = {}; /* dummy */ + struct pxe_context ctx; + int i; + + if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, + env_get("bootfile"))) + return -ENOMEM; + /* + * Keep trying paths until we successfully get a file we're looking + * for. + */ + if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 || + pxe_mac_path(&ctx, pxefile_addr_r) > 0 || + pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) + goto done; + + i = 0; + while (pxe_default_paths[i]) { + if (get_pxelinux_path(&ctx, pxe_default_paths[i], + pxefile_addr_r) > 0) + goto done; + i++; + } + + pxe_destroy_ctx(&ctx); + + return -ENOENT; +done: + *bootdirp = env_get("bootfile"); + + /* + * The PXE file size is returned but not the name. It is probably not + * that useful. + */ + *sizep = ctx.pxe_file_size; + pxe_destroy_ctx(&ctx); + + return 0; +} + /* * Entry point for the 'pxe get' command. * This Follows pxelinux's rules to download a config file from a tftp server. @@ -122,9 +165,10 @@ static int do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { char *pxefile_addr_str; - unsigned long pxefile_addr_r; - struct pxe_context ctx; - int err, i = 0; + ulong pxefile_addr_r; + char *fname; + ulong size; + int ret; if (argc != 1) return CMD_RET_USAGE; @@ -134,43 +178,25 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (!pxefile_addr_str) return 1; - err = strict_strtoul(pxefile_addr_str, 16, + ret = strict_strtoul(pxefile_addr_str, 16, (unsigned long *)&pxefile_addr_r); - if (err < 0) + if (ret < 0) return 1; - if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, - env_get("bootfile"))) { + ret = pxe_get(pxefile_addr_r, &fname, &size); + switch (ret) { + case 0: + printf("Config file '%s' found\n", fname); + break; + case -ENOMEM: printf("Out of memory\n"); return CMD_RET_FAILURE; + default: + printf("Config file not found\n"); + return CMD_RET_FAILURE; } - /* - * Keep trying paths until we successfully get a file we're looking - * for. - */ - if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 || - pxe_mac_path(&ctx, pxefile_addr_r) > 0 || - pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) { - printf("Config file found\n"); - pxe_destroy_ctx(&ctx); - - return 0; - } - - while (pxe_default_paths[i]) { - if (get_pxelinux_path(&ctx, pxe_default_paths[i], - pxefile_addr_r) > 0) { - printf("Config file found\n"); - pxe_destroy_ctx(&ctx); - return 0; - } - i++; - } - - printf("Config file not found\n"); - pxe_destroy_ctx(&ctx); - return 1; + return 0; } /* diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 194a5ed8cc7..b7037f841a6 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -236,4 +236,18 @@ int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); */ int pxe_get_file_size(ulong *sizep); +/** + * pxe_get() - Get the PXE file from the server + * + * This tries various filenames to obtain a PXE file + * + * @pxefile_addr_r: Address to put file + * @bootdirp: Returns the boot filename, or NULL if none. This is the 'bootfile' + * option provided by the DHCP server. If none, returns NULL. For example, + * "rpi/info", which indicates that all files should be fetched from the + * "rpi/" subdirectory + * @sizep: Size of the PXE file (not bootfile) + */ +int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep); + #endif /* __PXE_UTILS_H */ -- 2.33.0.rc1.237.g0d66db33f3-goog