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 A9082C4338F for ; Thu, 19 Aug 2021 03:50:04 +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 04E496109F for ; Thu, 19 Aug 2021 03:50:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 04E496109F 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 120998323A; Thu, 19 Aug 2021 05:47:36 +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="jXFHhCJf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9780F831D4; Thu, 19 Aug 2021 05:46:44 +0200 (CEST) Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) (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 025F682F38 for ; Thu, 19 Aug 2021 05:46:30 +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-ot1-x32e.google.com with SMTP id x10-20020a056830408a00b004f26cead745so6982358ott.10 for ; Wed, 18 Aug 2021 20:46:30 -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=dONihDLfV69R5oG8UjvGdvL+a2tH1ZBchRvaoHMa73o=; b=jXFHhCJf1RMvjA06tTsvA29ZfuHyhFcS05oSD2HjVLVoGIl99ey1lbVX5/uV+72gM5 CZJ4HmW9hbneQr8PUCHmIJKlnR+QpxGeKuG4s5N6VpWb5fuBeo9ciSOSdwAT56lW/kps LlYWwTbsD7+wmsQhrJ9y46xaeC4GhhhKNC4zU= 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=dONihDLfV69R5oG8UjvGdvL+a2tH1ZBchRvaoHMa73o=; b=rfXhtsesaZuUESIalAq2B8EY8N/w02YVDNFWDlBpUuWxE5OewQTfxR/ij/riW/FK8e eUA5rxNxZWCxSFYHQ/MBqkoLoQOt6S0CjNXkJ8lOoLtZvPb4U4+lkFzZ5fwZyAJmVyEv DxR0B11VbXzBRmGiKX2/EQrBjqb0CicPjcNzTXotjZiDyw595RACbFmLERTJgC66Hs9p F6u8mceuUmhgU9feGijkE1zXPVgDS46/YmXpg3fOM+hcMxn6wJ+qjOpxm2mdHZIhTkC6 sJ1I/WPxtECTJY7TlEnTkYKsEw5b8/Dq8sgM7E+TjE8yp4ZMwej254CSrggIHLSz/7lb v/YQ== X-Gm-Message-State: AOAM531np7Q/9ukzm0N8nacAOkvW8nsb5vGR7FZ+rNZcZXVG0vuxIgVM CKyeMmwqmPXrl8wcSKz7YHM2ba4bdG6CQw== X-Google-Smtp-Source: ABdhPJxA1P3n3VqhrSL1nxGG8mS54TaBLNFZGFyVwDf46Gf4koUR+nLUHMpngmjWjUX7lt1vOtIfmg== X-Received: by 2002:a05:6830:4084:: with SMTP id x4mr10302681ott.280.1629344789318; Wed, 18 Aug 2021 20:46:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:46:28 -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 16/28] pxe: Refactor sysboot to have one helper Date: Wed, 18 Aug 2021 21:45:49 -0600 Message-Id: <20210818214547.16.Ibd54f1a4872bc99ab0822d2c44492dc6c7581b60@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 The only difference between the three helpers is the filesystem type. Factor this out and call the filesystem functions directly, instead of through the command-line interpreter. This allows the file size to be obtained directly, instead of via an environment variable. We cannot do the same thing with PXE's tftpboot since there is no API at present to obtain information about the file that was read. So there is no point in changing pxe_getfile_func to use a ulong for the address, for example. This is as far as the refactoring can go for the present. Signed-off-by: Simon Glass --- cmd/sysboot.c | 94 ++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 58 deletions(-) diff --git a/cmd/sysboot.c b/cmd/sysboot.c index 6344ecd357b..04c07020269 100644 --- a/cmd/sysboot.c +++ b/cmd/sysboot.c @@ -6,63 +6,40 @@ #include #include -static char *fs_argv[5]; - -static int do_get_ext2(struct pxe_context *ctx, const char *file_path, - char *file_addr, ulong *sizep) +/** + * struct sysboot_info - useful information for sysboot helpers + * + * @fstype: Filesystem type (FS_TYPE_...) + * @ifname: Interface name (e.g. "ide", "scsi") + * @dev_part_str is in the format: + * .: where is the device number, + * is the optional hardware partition number and + * is the partition number + */ +struct sysboot_info { + int fstype; + const char *ifname; + const char *dev_part_str; +}; + +static int sysboot_read_file(struct pxe_context *ctx, const char *file_path, + char *file_addr, ulong *sizep) { -#ifdef CONFIG_CMD_EXT2 + struct sysboot_info *info = ctx->userdata; + loff_t len_read; + ulong addr; int ret; - fs_argv[0] = "ext2load"; - fs_argv[3] = file_addr; - fs_argv[4] = (void *)file_path; - - if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv)) - return 1; - ret = pxe_get_file_size(sizep); + addr = simple_strtoul(file_addr, NULL, 16); + ret = fs_set_blk_dev(info->ifname, info->dev_part_str, info->fstype); if (ret) - return log_msg_ret("tftp", ret); -#endif - return -ENOENT; -} - -static int do_get_fat(struct pxe_context *ctx, const char *file_path, - char *file_addr, ulong *sizep) -{ -#ifdef CONFIG_CMD_FAT - int ret; - - fs_argv[0] = "fatload"; - fs_argv[3] = file_addr; - fs_argv[4] = (void *)file_path; - - if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv)) - return 1; - ret = pxe_get_file_size(sizep); + return ret; + ret = fs_read(file_path, addr, 0, 0, &len_read); if (ret) - return log_msg_ret("tftp", ret); -#endif - return -ENOENT; -} - -static int do_get_any(struct pxe_context *ctx, const char *file_path, - char *file_addr, ulong *sizep) -{ -#ifdef CONFIG_CMD_FS_GENERIC - int ret; - - fs_argv[0] = "load"; - fs_argv[3] = file_addr; - fs_argv[4] = (void *)file_path; + return ret; + *sizep = len_read; - if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY)) - return 1; - ret = pxe_get_file_size(sizep); - if (ret) - return log_msg_ret("tftp", ret); -#endif - return -ENOENT; + return 0; } /* @@ -74,9 +51,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { unsigned long pxefile_addr_r; - pxe_getfile_func getfile; struct pxe_context ctx; char *pxefile_addr_str; + struct sysboot_info info; char *filename; int prompt = 0; int ret; @@ -106,24 +83,25 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, } if (strstr(argv[3], "ext2")) { - getfile = do_get_ext2; + info.fstype = FS_TYPE_EXT; } else if (strstr(argv[3], "fat")) { - getfile = do_get_fat; + info.fstype = FS_TYPE_FAT; } else if (strstr(argv[3], "any")) { - getfile = do_get_any; + info.fstype = FS_TYPE_ANY; } else { printf("Invalid filesystem: %s\n", argv[3]); return 1; } - fs_argv[1] = argv[1]; - fs_argv[2] = argv[2]; + info.ifname = argv[1]; + info.dev_part_str = argv[2]; if (strict_strtoul(pxefile_addr_str, 16, &pxefile_addr_r) < 0) { printf("Invalid pxefile address: %s\n", pxefile_addr_str); return 1; } - if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) { + if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true, + filename)) { printf("Out of memory\n"); return CMD_RET_FAILURE; } -- 2.33.0.rc1.237.g0d66db33f3-goog