From patchwork Fri Sep 1 10:25:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 719511 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp158677wrh; Fri, 1 Sep 2023 03:26:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOh6gN7ZANGVAJlcECN7/HnOaeT6LJj2Vcu5PrAEsVazwDqgQAmP8wOV17zZoZyRx+BaK3 X-Received: by 2002:a7b:c389:0:b0:401:cdc1:ac82 with SMTP id s9-20020a7bc389000000b00401cdc1ac82mr1533185wmj.9.1693563998816; Fri, 01 Sep 2023 03:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693563998; cv=none; d=google.com; s=arc-20160816; b=OEYFb+RIjSKu86Qnty2RakbPlSGB0nyBuSgGU5WSSiel8FR9cDWHIfuK4YVvF9rCJ5 XGhrzJUktaYbc2HBaKcGE2QsFL6lFWOYbPmJTIQwv3eFEQ9NF5Ro8IegViI6ufSYJZEZ /LksMOXm5DWkMre2PpcYxh5KDxXUGR8zrO3KB7zbacyfMjb4sV9UOr84WS8Rxn6C4od7 3GH9oF1wUcfMCLuuIB/UbPjx4v4ig78IB1x5oaryTZUQQVZTDog+UDMAXcq5nghtASgd BizZYHa5VWK+tYoiu+Z87trnmLHZoPYdTqPKbr/25oMsXShCCZd++zDm1581ULVxg0xq Wlqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K5o7rE4kZSShVKtRcA18G41Zui4Hcxs84NmAGyEAImE=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=rcudDB55erXPtvqUrDzFQX0RfUkByuYfp5o1Z+zwaIXYPEjQbbrBAcUy8lVI/kk+Vy aQQQUvLfU5+9VkH7SOQ0nY5KFif/PkDZos/8A7z26biC+k+nn7ClXzakLt08R9qNtdJn L8VKkpg1Hl2fNSL/mQkTtxju/oLk4vwCvCtXkQXdlduZp0XcuOlTT/BCEz5ts0vwbIAz Skn/8JWbpp0sM8VQ3Iuuc8U9YwnNoSNGGg5JvAu6HwWVr+figlfnGfm3+fBNZgIvvQIh CJRcVtt6LVYs9NnA/I7gw1mwGt337bvcEmEn3fCLSJvGFD6HHNQKGisrWncTRf9gctuw pRkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i82uFwhF; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id s4-20020a05600c45c400b003fef279421bsi1768767wmo.197.2023.09.01.03.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i82uFwhF; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B472F868CA; Fri, 1 Sep 2023 12:26:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="i82uFwhF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E6B3386886; Fri, 1 Sep 2023 12:26:29 +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,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-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 0C9D286146 for ; Fri, 1 Sep 2023 12:26:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bf5c314a57so13626075ad.1 for ; Fri, 01 Sep 2023 03:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693563984; x=1694168784; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K5o7rE4kZSShVKtRcA18G41Zui4Hcxs84NmAGyEAImE=; b=i82uFwhFEr4qH/d7v6odlOrvFZpUXgG8WfdERi8NCZl7sb5f04e1QHtOe1cwTRYnj9 X0HFEKKJvMXksFsI/HskQAJe2DfDWx9iSrOuy5vNIOR7Waq1TWA+m5FE9UU5hKSImWD1 iprfOHti4y/01fTOplFvw7SYD/MLgxfE4ZX4dsPfvgnYG1TKZAbOgGsDWRcxvZaXWAJc nFI0ZvTSqwMzRu2Xls1+Jwg80tYrUHAoG6NFD9mzVnoijpAP+/eboaB5W9k3f0tmU524 CSGQa1JbW0V9ROBQ6topx2BK6WqSheruSl0jF+Epio98w3SrkUys1QtrRVPxvfMwe/TP bRGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693563984; x=1694168784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K5o7rE4kZSShVKtRcA18G41Zui4Hcxs84NmAGyEAImE=; b=guzmKn+ygpBGnsymMhi0VCOK/tOFIopXfoKi8p0vqlOcfrWj5g1aq9Uu5lFekMADti 2tcXkThGp3xNTY7OANrWkxb9jSvYcDZf3P3H2CwtvE5Qrw6zhtIxE3KLectMlp1SuBsO Tlr3XAYxnceUc/Xujfi9sQsffCmB/jO3Z3Js287zGDnmmMuXgXzbhKIydHB947cUJzxG i+k43k/e/2ZyExTxD7hVZTL0bvVPZ1RJaXgM/foEIxmhL+z5qqrzRpDM4HPqPRLs3OoJ zBnY14THCAc+4H1QXyzCPUY1aBXqkal1BwVpHPd/DuaobVakzQHVYh07oxTvNfI/GfeL E/Gg== X-Gm-Message-State: AOJu0YzEE7zPeNYdGURQ8+Yk+JFQz8B1fnqrHfYsxNN8SxwySVbiG+tq vYVd1XHZMP5YfEA6DyZWeNu07Rm1zQ8+7nnf2M8= X-Received: by 2002:a17:902:e808:b0:1bf:70be:ca8b with SMTP id u8-20020a170902e80800b001bf70beca8bmr2745835plg.43.1693563984114; Fri, 01 Sep 2023 03:26:24 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id y4-20020a170902700400b001c0c86a5415sm2677052plk.154.2023.09.01.03.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:23 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v2 1/6] net: wget: prevent overwriting reserved memory Date: Fri, 1 Sep 2023 19:25:37 +0900 Message-Id: <20230901102542.609239-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901102542.609239-1-masahisa.kojima@linaro.org> References: <20230901102542.609239-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean This introduces the valid range check to store the received blocks using lmb. The same logic is implemented in tftp. Signed-off-by: Masahisa Kojima --- net/wget.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 2dbfeb1a1d..8bf4db4d04 100644 --- a/net/wget.c +++ b/net/wget.c @@ -4,16 +4,20 @@ * Copyright Duncan Hare 2017 */ +#include #include #include #include #include #include +#include #include #include #include #include +DECLARE_GLOBAL_DATA_PTR; + static const char bootfile1[] = "GET "; static const char bootfile3[] = " HTTP/1.0\r\n\r\n"; static const char http_eom[] = "\r\n\r\n"; @@ -55,6 +59,32 @@ static unsigned int retry_tcp_ack_num; /* TCP retry acknowledge number*/ static unsigned int retry_tcp_seq_num; /* TCP retry sequence number */ static int retry_len; /* TCP retry length */ +#ifdef CONFIG_LMB +static ulong wget_load_size; +#endif + +/** + * wget_init_max_size() - initialize maximum load size + * + * Return: 0 if success, -1 if fails + */ +static int wget_init_load_size(void) +{ +#ifdef CONFIG_LMB + struct lmb lmb; + phys_size_t max_size; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + + max_size = lmb_get_free_size(&lmb, image_load_addr); + if (!max_size) + return -1; + + wget_load_size = max_size; +#endif + return 0; +} + /** * store_block() - store block in memory * @src: source of data @@ -63,10 +93,24 @@ static int retry_len; /* TCP retry length */ */ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) { + ulong store_addr = image_load_addr + offset; ulong newsize = offset + len; uchar *ptr; - ptr = map_sysmem(image_load_addr + offset, len); +#ifdef CONFIG_LMB + ulong end_addr = image_load_addr + wget_load_size; + + if (!end_addr) + end_addr = ULONG_MAX; + + if (store_addr < image_load_addr || + store_addr + len > end_addr) { + puts("\nwget error: "); + puts("trying to overwrite reserved memory...\n"); + return -1; + } +#endif + ptr = map_sysmem(store_addr, len); memcpy(ptr, src, len); unmap_sysmem(ptr); @@ -240,25 +284,37 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, net_boot_file_size = 0; - if (len > hlen) - store_block(pkt + hlen, 0, len - hlen); + if (len > hlen) { + if (store_block(pkt + hlen, 0, len - hlen) != 0) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + return; + } + } debug_cond(DEBUG_WGET, "wget: Connected Pkt %p hlen %x\n", pkt, hlen); for (i = 0; i < pkt_q_idx; i++) { + int err; + ptr1 = map_sysmem( (phys_addr_t)(pkt_q[i].pkt), pkt_q[i].len); - store_block(ptr1, - pkt_q[i].tcp_seq_num - - initial_data_seq_num, - pkt_q[i].len); + err = store_block(ptr1, + pkt_q[i].tcp_seq_num - + initial_data_seq_num, + pkt_q[i].len); unmap_sysmem(ptr1); debug_cond(DEBUG_WGET, "wget: Connctd pkt Q %p len %x\n", pkt_q[i].pkt, pkt_q[i].len); + if (err) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + return; + } } } } @@ -420,6 +476,12 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (wget_init_load_size()) { + puts("\nwget error: "); + puts("trying to overwrite reserved memory...\n"); + return; + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Fri Sep 1 10:25:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 719512 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp158733wrh; Fri, 1 Sep 2023 03:26:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCyzfK38nhTqMSYM9H58QZ1rhhLUb3CCBiVgLEPtxiNiurSLJWUPLFCMUzl0j65jax08Td X-Received: by 2002:a05:6000:1210:b0:319:6ae0:cae5 with SMTP id e16-20020a056000121000b003196ae0cae5mr1274658wrx.70.1693564009783; Fri, 01 Sep 2023 03:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693564009; cv=none; d=google.com; s=arc-20160816; b=qLRv3PEeVwd+RANAdoVMODktqczFQoINGGqyovq7ixHo/APIQ1zw2s7jYzZ2X0e6/4 PUmvzMe2zodHJQLezJiWsPajja2rqGMx+5qkqEfxIS8iD/K5oiqK21fBpTPWMYm7lByU Gp8gbouF0e5uGOIjCNTqppoX1PFX94dVKYYitboWitwvdYhfiiGQrNLmoe+h9hxSoQE9 0DpImXAHOIUzz0tEWVNpd+f//MwW7X4nulnpZM9wOmRgKCZylu8TVlEFHPS8fOJn7eE8 U5cKjBji40PR530LjZiomnd8eK840pvVqh/7dd/ing9DCSE6pb+fClbtQU9fWBa8ATPt UHxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zEZxobHc4/hRgzipngl1BkvsvqKAXCkdxt0x/nbRs0M=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=In/jvp2vgJ8NtmrbD1gm47ngWCkJ80szz4TNCPFLKgYH3xtA8L0NgOed06iTH2qt8B 8GeuhMru/W2XlohbmK4Gr6sKmIA1pui7542wKi4tqqI6G0NRZeGJJRs+bYJkHPgElt1L eam+NjzQRmX7CpgbOTbEHwQh/PUE/5WsvpEfknop6GBx+h8tE95eLlzVcGB9ddQQcNFz UyXcH9YtcpoaYE5VSn6FdbEDIQcJNMlcfWHrazj067ZXWVK0RFMgcTah/56Eh6Ks3U2v 1KO6u08+/gZFn1FgeXAqEC4HySyxohOtfjrZ8o9v+VzsWoA8hEwTY/5ub7qAXQs9N+9t UrnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IUAxSKg0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id u2-20020a5d6ac2000000b0031ad64a8288si1529310wrw.717.2023.09.01.03.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IUAxSKg0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F2B688688B; Fri, 1 Sep 2023 12:26:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="IUAxSKg0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9682B8688B; Fri, 1 Sep 2023 12:26:36 +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,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-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (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 F212086900 for ; Fri, 1 Sep 2023 12:26:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-565f86ff4d1so1256134a12.2 for ; Fri, 01 Sep 2023 03:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693563990; x=1694168790; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zEZxobHc4/hRgzipngl1BkvsvqKAXCkdxt0x/nbRs0M=; b=IUAxSKg0oTtSthQeU/N5h2uw4dQFHGKRTos/3w439hbCUa5t5N1/bVSf0p3dN89EwY zZuhUkRcQxlgfGocgzLMaaIhRscto2cC4Zby45XYr6CDU+sz+kkSXenfwCqgT+V6IRhj 9uV6FCeTKszfGbBE4yIWJxeTyrqrDcE6uX4vF0FVsfLeln42f/BzoxfUnpGnG+ZeQQJO 4cTvb+ib6bo13eYOqyjSLLHiVr11NtQd7n0hVNfRtaxlYuhVXDv+zsXV0RWP4Q10Xv20 aniR7dVjASdJjWsWo0Uz4XLNpaLR5XVA6djBVgvBEaz2ufYsJe634fXizryKliKn53uu NmLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693563990; x=1694168790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zEZxobHc4/hRgzipngl1BkvsvqKAXCkdxt0x/nbRs0M=; b=F4jVQoylVkV3EV3WmZmTKzDvDs43C1cnCAbaOemuXF4iOB3kJoow3cqau9nCenQANF Qg8c44nGQzr2boGaHseeJ3Pk8p79TWM4V6GtMCOdltflMACLR1SsQNE/4L7umfTmDN2b BtuqmaIdaJc/N0zs2ytmMBLputjiq/AFgGtvscE1VKHBlfCg9RRKM4ylqHnOvx4KOHAC aWXj/rB7AbO/gmLkJlzXIk4R6oOaVIYMijGNuKFWJ3ROGX5H7nBQviXDpSpXz0WwkslO ySPW3uzErRSaiASPOfX8pcuDSEKRqHMuozZYLl9aOl5+pZiF/E8dxjEqHAs9jcR5lnp8 aIag== X-Gm-Message-State: AOJu0Yym3HQ5/VqCjf3C/wLTkTIi+PcpBt7BHpuBy8Peyg3299ASN8YY OthHpXRPDut9nhY3dxwL+1iYO2pd1/2PKWIaX9c= X-Received: by 2002:a05:6a21:7903:b0:145:6857:457a with SMTP id bg3-20020a056a21790300b001456857457amr2016897pzc.4.1693563989779; Fri, 01 Sep 2023 03:26:29 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id d15-20020aa78e4f000000b0066ebaeb149dsm2699753pfr.88.2023.09.01.03.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:29 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v2 2/6] net: wget: add wget with dns utility function Date: Fri, 1 Sep 2023 19:25:38 +0900 Message-Id: <20230901102542.609239-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901102542.609239-1-masahisa.kojima@linaro.org> References: <20230901102542.609239-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima --- include/net.h | 4 ++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..b4bbf95732 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,8 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +#if (IS_ENABLED(CONFIG_CMD_WGET) && IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri); +#endif + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 8bf4db4d04..5718f1cf92 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -500,3 +501,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, 1024); + strlcat(net_boot_file_name, ":/", 1024); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, 1024); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Fri Sep 1 10:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 719513 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp158784wrh; Fri, 1 Sep 2023 03:27:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6ieOONvjqzKaVRRaHt0tFAfJ7Z6jcUFMQnTFFvH1Ff0P9l/u911d5aAhOURDcKwgcVI9x X-Received: by 2002:a5d:51c8:0:b0:317:6704:72c with SMTP id n8-20020a5d51c8000000b003176704072cmr1510164wrv.52.1693564020286; Fri, 01 Sep 2023 03:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693564020; cv=none; d=google.com; s=arc-20160816; b=agmOyCYgq5ZRMVc9eKJQt0hQFg1mpqXJObRO5Xt14e+pYTCzMX2cwgcuG61WmLFbqM LFeWy619JYlHFPeTjaUAiH8D9SoRYwpaBoUrVzaAkzw3D1rZoU4OF6gAWoltjwc8ucaO 3Xw8cnFri73mhSSalFI5qUR+pEiqwYQpTwFPbioXn6RECt8a90Gn5HkA/L4FFXTGPv1w 9H89J2mjNZiBFe7ivzCo7Y6KcECO2nSW5WsPfVZmXY7hjFXV6bFBiUtgEjlZ6j0XDLJr 38HJxy2DSjd3piiBNbiUkE+i9nx/8jGmg1luzuz5EoYaCPmpszhobnjK0J45sqVChLm0 NhTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=96BtuKz6Nt+rW/pzCpyzhAIQGlcGujDJNae48u8P4dQ=; fh=/7JtEi60Oc1He789ODhlJpQcggvkyewSA9z0FHm3qP4=; b=KDX+f4sYUPPxcWYdRxiRHJPvLi+Gmy8yfoQnVs1uL3Pb0aO+4ejd22yzMsJGVdpMyB zYJHyHd1sJhIijo3zOXCNZu/FWfi63myqg+ZiQGah1d6rJz2/mrZOSM5+vf42e0hXZbn WGhxwNQbbbajea/IMQ3XZobBEbD7f2xbDoRQ8xv5ynn9Aa/xTDxm/Y5dA2CrzcP4Iu/l gPXKne75aUi8gZ7TXAv1XF+zfzloJ3NppNF/Qy48PydVzPf/PlGC65tgEtk2M2bTZT+a P8eYiJPNil9R399a/c1Uwk9l4qlkknXhrs9KnNFOjX/G6Lc2Yos9ybelHch/E7Yx5eVU hbbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k4Q5N0Wi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id t11-20020a5d49cb000000b0031972d57cf7si1515156wrs.964.2023.09.01.03.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k4Q5N0Wi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3EC36868B8; Fri, 1 Sep 2023 12:26:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="k4Q5N0Wi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EC05386900; Fri, 1 Sep 2023 12:26:41 +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,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-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 0549F868B8 for ; Fri, 1 Sep 2023 12:26:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c0d5b16aacso14306085ad.1 for ; Fri, 01 Sep 2023 03:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693563996; x=1694168796; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=96BtuKz6Nt+rW/pzCpyzhAIQGlcGujDJNae48u8P4dQ=; b=k4Q5N0WiWpYGShLOEFv7xFzwdaLxp+Ig6tThzL4+HHeNfg71H9IbMx12UHQY84R2lI udf9FdkQ5od5KHdqn638/GlWhErswkDAnqTAl3iEiNt1O+N3zLjHCEV7XYrK7rTcSO5Y JfuXSDksJOJ6RnaXsZAR4EZS7rizI7RzmWEP0loaH6h65Q2AyRCl+6LULu5+KLZFNTeV XpdTSwfDRGm+PsQICzmfdlWV/VLmCkihGxHwD3iy28Xycwz9AHD/Ci98nsjhAep46+pX KDkkCBJXzUpxjD+KxC0aS+Ix9dLUcmVNZmanNxtVF6umTwkCtE9Nr7iW24AJPR+wSgNq saJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693563996; x=1694168796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=96BtuKz6Nt+rW/pzCpyzhAIQGlcGujDJNae48u8P4dQ=; b=RzCR44YzeXmnRL/YLnK5cyRkKSYcaRPg/MvXY8LbxTIVuLXt547AslgtJHLl5AAlZV xWAvNoqfxMCnAaiGJs4g9sqEMWBvO4LtXE4UyEPxrVAEy/kFlRS0g0QKdn8OKQHu/QYx nrKjuEGiJI3tUbSJxqo5zTmDtswYOQjfFzl1ZNWOB4Pd5Qu6h2sd8TlLGbQeXGpmbfo4 BN3uMSiWgic23FwPUYf++MLJmA4m296fDqWqKpyLudYoHorG1zveuBpnXh+XcndLPfxj 1XTRwN9jKBLuz/HTOKFl9dK7TDQ0+7j1BjsK1ba/U9g2qgT2oz9m0f2Qsnrz3qpfYUA2 DZKg== X-Gm-Message-State: AOJu0YxuM8s8I38pDx7eM0tMjOgAePISf1b9p/+/iDLL7OxUOGsmXnmV on37H2GLAdyI9s9twNUUNgtj1JcgzSCK3zKwQ7w= X-Received: by 2002:a17:902:e80a:b0:1bd:d718:5833 with SMTP id u10-20020a170902e80a00b001bdd7185833mr2209785plg.18.1693563996068; Fri, 01 Sep 2023 03:26:36 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id g15-20020a1709029f8f00b001bba3a4888bsm2691892plq.102.2023.09.01.03.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:35 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Tobias Waldekranz , Jaehoon Chung Subject: [PATCH v2 3/6] blk: blkmap: add ramdisk creation utility function Date: Fri, 1 Sep 2023 19:25:39 +0900 Message-Id: <20230901102542.609239-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901102542.609239-1-masahisa.kojima@linaro.org> References: <20230901102542.609239-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean User needs to call several functions to create the ramdisk with blkmap. This adds the utility function to create blkmap device and mount the ramdisk. Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass --- drivers/block/Makefile | 1 + drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..c3ccfc03e5 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -15,6 +15,7 @@ endif obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o obj-$(CONFIG_BLKMAP) += blkmap.o +obj-$(CONFIG_BLKMAP) += blkmap_helper.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 2bb0acc20f..4e95997f61 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Fri Sep 1 10:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 719514 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp158843wrh; Fri, 1 Sep 2023 03:27:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUKUnm+aRim+/KRQokzXqS/rXEQpBV7X6BQXfnUf+i4cmWWa3lwb8a/jIgqvI8zS02vSSS X-Received: by 2002:a05:600c:291:b0:3fe:da37:d59 with SMTP id 17-20020a05600c029100b003feda370d59mr1569214wmk.4.1693564030973; Fri, 01 Sep 2023 03:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693564030; cv=none; d=google.com; s=arc-20160816; b=r30pcpRIod/cR52w9nPbaJQgU7KD816sBMugY3hN1yTkCA8c3E9qwMwNMUNzbI4g8m VJHDrdl/sm62N0Oz4YiYSS/26g3ZsHcR5Uu5kVdsAXZsTc52xYRFN/y+N3EvyvWuxEYw DvlkBfOHmuLWNpT2kcxallymSja1webcWQDqCA65j6zg32Lnch92h9ogzDK94diNvfH5 wh2Go3zR00Rq6AMEFu65AFtEInSMr+13Pqgl1XvWW/6RQJFKQ5Mr7Znd7oE/KL1Djtyv GkSv5vuabJ4I3uie+ZkRddDiryximAFgUrwe8UzK0eEFra9xwEpGr7jgzdK4asxvPJJw WvPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xCgaQAxtd2A8HOgkWFhH3ch4Tsgwryr9I3qfko9RayQ=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=DSnAX8XWxsPceouayrxlNpR40tT5m4bQzrFFK0R2OMguLdUvmhwGE9dwpo8sOQCJ0Z 4tv8hkE6+VIlYEgsLfvNO55ZfQuwz3X4J/87WPEF2uZ/IwoHcFyj6ObLzXJ093SOMH82 vKEm6ffggPncJwvU013Lsxndeea7num15UaVu9mRTixvAJAPecVcn1m+NpZccgrCykDI +mzxkbTBdXpiVQiRGTMaStdgIsW7i/Ul84KfsQepTJ8fgJRXjcN+NZC+W+YoYTKDw9cr mfX7DZRoFo4EqVIK8q6EHdpnTVEbrn2yuMKDb026kcGwpXo68a1hJB3F2OpdQKaznu1L Qh0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oeBH9xnx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id p23-20020a1c7417000000b003fef56e8217si1763894wmc.94.2023.09.01.03.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:27:10 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oeBH9xnx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8454886886; Fri, 1 Sep 2023 12:26:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="oeBH9xnx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F101186886; Fri, 1 Sep 2023 12:26:47 +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,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-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 EA90B86907 for ; Fri, 1 Sep 2023 12:26:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c0d0bf18d7so13584075ad.0 for ; Fri, 01 Sep 2023 03:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693564002; x=1694168802; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xCgaQAxtd2A8HOgkWFhH3ch4Tsgwryr9I3qfko9RayQ=; b=oeBH9xnxMFX0+uYxYYiWNK/CP29kenPquvwcuvGKRITJwwYHQzHW04+8o+UgG26JPv maC6ewPeyl+e7tfGnzNED4BCBYuOI25tsog+gO5BBR6LsyWoTnb2Wh+G212WASx6Dr/L SDs1EcuR+6c6smzguneVlh+RmYWsGIXk3dhOHbJ52ZKKGhKP0ovTUQRN8wTzy3VH0Kty QdK/z5x2lqs61BCNk7U6uFCGicJBR/IOGaJx1+nMJAm0askTuc3uwlvrjBq+jt7LfmcR UlyJMGeHsUCCRiOeRQLE8o5wGiDfwxjuoVXw3A9EBgmZ3Sw2Q/ZkEviMVoomNUFLtkOE DF+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693564002; x=1694168802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xCgaQAxtd2A8HOgkWFhH3ch4Tsgwryr9I3qfko9RayQ=; b=XsqlXb22ctkYP3qAP4+MoXaYM/+qoJx2QgixxWWBEJ1zgaqlZ1KB89vmFKFnkxmLWn Pdo0NsdoVxaudFlBFLfKOBR9zVVgZnpo5rijLCjdAKhfjzkRtDS5E8tjt6Wt3SHZ4SSH sEXvCiXCWbSWnWLSJ4Iov6xiwIgy86rs6eqo73KzEHe4B79fS2EzKwoNjdMkhgV91Tlo x4MJFXNsdRKDEyQ75flPMf5JiZk0RPGgxO/lIM/WsNKcGeGTtk5+f0WahxVPrDPYAJkp GoP2CuJm7gxVX0tEvqKdMNrL5vFm3zziWcsSf13s+cH7PA5A8rgnC5LjRl2ztRqsztFO sB+Q== X-Gm-Message-State: AOJu0YxRzSzrjfwS9+BLF9AXHYXnn6uumYUyyKjvagvion3I4QCaK0wI 7inlQNfFBQr1XSd3UrGPMOhCvjGy7SRtfgd3Q5U= X-Received: by 2002:a17:902:e88f:b0:1b8:3786:3344 with SMTP id w15-20020a170902e88f00b001b837863344mr2532395plg.49.1693564002002; Fri, 01 Sep 2023 03:26:42 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id w5-20020a170902a70500b001bbb22652a4sm2660189plq.226.2023.09.01.03.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:41 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v2 4/6] efi_loader: support boot from URI device path Date: Fri, 1 Sep 2023 19:25:40 +0900 Message-Id: <20230901102542.609239-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901102542.609239-1-masahisa.kojima@linaro.org> References: <20230901102542.609239-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean This supports to boot from the URI device path. When user selects the URI device path, bootmgr downloads the file using wget into the address specified by loadaddr env variable. If the file is .iso or .img file, mount the image with blkmap then try to boot with the default file(e.g. EFI/BOOT/BOOTAA64.EFI). If the file is .efi file, load and start the downloaded file. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 197 +++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..0e8d2ca9d1 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -7,10 +7,14 @@ #define LOG_CATEGORY LOGC_EFI +#include +#include #include #include +#include #include #include +#include #include #include #include @@ -168,6 +172,193 @@ out: return ret; } +#if (IS_ENABLED(CONFIG_BLKMAP) && IS_ENABLED(CONFIG_CMD_WGET) && IS_ENABLED(CONFIG_CMD_DNS)) +/** + * mount_image() - mount the image with blkmap + * + * @lo_label u16 label string of load option + * @image_addr: image address + * @image_size image size + * Return: pointer to the UCLASS_BLK udevice, NULL if failed + */ +static struct udevice *mount_image(u16 *lo_label, ulong image_addr, int image_size) +{ + int err; + struct blkmap *bm; + struct udevice *bm_dev; + char *label = NULL, *p; + + label = efi_alloc(utf16_utf8_strlen(lo_label) + 1); + if (!label) + return NULL; + + p = label; + utf16_utf8_strcpy(&p, lo_label); + err = blkmap_create_ramdisk(label, image_addr, image_size, &bm_dev); + if (err) { + efi_free_pool(label); + return NULL; + } + bm = dev_get_plat(bm_dev); + + efi_free_pool(label); + + return bm->blk; +} + +/** + * try_load_default_file() - try to load the default file + * + * Search the device having EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, + * then try to load with the default boot file(e.g. EFI/BOOT/BOOTAA64.EFI). + * + * @dev pointer to the UCLASS_BLK or UCLASS_PARTITION udevice + * @image_handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t try_load_default_file(struct udevice *dev, + efi_handle_t *image_handle) +{ + efi_status_t ret; + efi_handle_t bm_handle; + struct efi_handler *handler; + struct efi_device_path *file_path; + struct efi_device_path *device_path; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&bm_handle)) { + log_warning("DM_TAG_EFI not found\n"); + return EFI_INVALID_PARAMETER; + } + + ret = efi_search_protocol(bm_handle, + &efi_simple_file_system_protocol_guid, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_search_protocol(bm_handle, &efi_guid_device_path, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_protocol_open(handler, (void **)&device_path, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + return ret; + + file_path = expand_media_path(device_path); + ret = EFI_CALL(efi_load_image(true, efi_root, file_path, NULL, 0, + image_handle)); + + efi_free_pool(file_path); + + return ret; +} + +/** + * load_default_file_from_blk_dev() - load the default file + * + * @blk pointer to the UCLASS_BLK udevice + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t load_default_file_from_blk_dev(struct udevice *blk, + efi_handle_t *handle) +{ + efi_status_t ret; + struct udevice *partition; + + /* image that has no partition table but a file system */ + ret = try_load_default_file(blk, handle); + if (ret == EFI_SUCCESS) + return ret; + + /* try the partitions */ + device_foreach_child(partition, blk) { + enum uclass_id id; + + id = device_get_uclass_id(partition); + if (id != UCLASS_PARTITION) + continue; + + ret = try_load_default_file(partition, handle); + if (ret == EFI_SUCCESS) + return ret; + } + + return EFI_NOT_FOUND; +} + +/** + * try_load_from_uri_path() - Handle the URI device path + * + * @uridp: uri device path + * @lo_label label of load option + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, + u16 *lo_label, + efi_handle_t *handle) +{ + char *s; + int uri_len; + int image_size; + efi_status_t ret; + ulong image_addr; + + s = env_get("loadaddr"); + if (!s) { + log_err("Error: loadaddr is not set\n"); + return EFI_INVALID_PARAMETER; + } + image_addr = hextoul(s, NULL); + image_size = wget_with_dns(image_addr, uridp->uri); + if (image_size < 0) + return EFI_INVALID_PARAMETER; + + /* + * If the file extension is ".iso" or ".img", mount it and try to load + * the default file. + * If the file is ".efi" and PE-COFF image, load the downloaded file. + */ + uri_len = strlen(uridp->uri); /* todo: directly use uridp->uri */ + if (!strncmp(&uridp->uri[uri_len - 4], ".iso", 4) || + !strncmp(&uridp->uri[uri_len - 4], ".img", 4)) { + struct udevice *blk; + + blk = mount_image(lo_label, image_addr, image_size); + if (!blk) + return EFI_INVALID_PARAMETER; + + ret = load_default_file_from_blk_dev(blk, handle); + } else if (!strncmp(&uridp->uri[uri_len - 4], ".efi", 4)) { + efi_handle_t mem_handle = NULL; + struct efi_device_path *file_path = NULL; + + ret = efi_check_pe((void *)image_addr, image_size, NULL); + if (ret != EFI_SUCCESS) { + log_err("Error: downloaded image is not a PE-COFF image\n"); + return EFI_INVALID_PARAMETER; + } + + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_addr, image_size); + ret = efi_install_multiple_protocol_interfaces( + &mem_handle, &efi_guid_device_path, file_path, NULL); + if (ret != EFI_SUCCESS) + return EFI_INVALID_PARAMETER; + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, + (void *)image_addr, image_size, + handle)); + } else { + log_err("Error: file type is not supported\n"); + return EFI_INVALID_PARAMETER; + } + + return ret; +} +#endif + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +402,12 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) { /* file_path doesn't contain a device path */ ret = try_load_from_short_path(lo.file_path, handle); +#if (IS_ENABLED(CONFIG_BLKMAP) && IS_ENABLED(CONFIG_CMD_WGET) && IS_ENABLED(CONFIG_CMD_DNS)) + } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) { + ret = try_load_from_uri_path( + (struct efi_device_path_uri *)lo.file_path, + lo.label, handle); +#endif } else { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, From patchwork Fri Sep 1 10:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 719515 Delivered-To: patch@linaro.org Received: by 2002:adf:d08b:0:b0:31d:da82:a3b4 with SMTP id y11csp158925wrh; Fri, 1 Sep 2023 03:27:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEen4tQFJnQoSia1Z6zmTh5wqVHc/zj1aiyraknr9SD5G/Si2fw2hvT0zuThYtLcBBwSUa4 X-Received: by 2002:a5d:500a:0:b0:315:a32d:311f with SMTP id e10-20020a5d500a000000b00315a32d311fmr1523581wrt.14.1693564041184; Fri, 01 Sep 2023 03:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693564041; cv=none; d=google.com; s=arc-20160816; b=k6yj5TbJHW+zldSVy3YUFF1YGPSDJDWqA3SZWD8n1sTDx86fwNeirVvbBDmYDo8hCT 3Glw6RG+hiBXZmj/tqrjNHgsIO0Jfqhgaz1LaiyTHE8ChKCbeNB1xcyx7nHl/p7EZTE6 x05tfxTdVSlm6dxsSv+oHu33gbTqOzG28DHCbWTAaMSX+CKQUEvJskIfkudbkbIOo0Xm Id/847deEPekGP+hOf/d2flbwspWKvG1mjLGAZevr3O35OuDVZS1RN/cladlFTL+K+QP oWbUrW4nqKpLGLFqXDCIQJHTGUBgyi0/zYN4zf1tDZQWsRjk1oYMaDfZc+MllV2AMsxe 6euw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+lvF6Z97KxKbq3h008c7NhdQLnxb3iYbPzFOWKZw1+w=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=nHI0M5iprt5JDzJZHvWMzK9eBng7GFHdbnWLzlv/sstO+6h4NVk6XzE95el5lMmGSC 5ldNt9rVF5dRTsKP4JxOMauzXDawUWPuqZRVIYkgu+L8kTeDbf/aRX+LwQNhBhN2GC+q fhrorhkxYvTpWAHSHRGq20oYejPvMTjmIP/uAZVoZVL99zF6AtAHLKC/92vf0xeJxM0P d15tJeaWynEIZe8uGr6s0cwotNXwUU3F0iEV1vkD5kLtjq9rKrEeu7HO69dMa1YL7aAU 4f0RPJRJl5pq3QrL3dY/nrAQiaMd+TGO1YClixZSL3bP4ijfoQ5w7sImDZ9kzy5djcFj HqYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qhn+ll5l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id f15-20020adff44f000000b003141b531e4fsi1602376wrp.900.2023.09.01.03.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qhn+ll5l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CCD1286908; Fri, 1 Sep 2023 12:26:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="Qhn+ll5l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E31E186925; Fri, 1 Sep 2023 12:26:53 +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,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-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 DA3D1857BF for ; Fri, 1 Sep 2023 12:26:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-26f7f71b9a7so1281055a91.0 for ; Fri, 01 Sep 2023 03:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693564009; x=1694168809; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+lvF6Z97KxKbq3h008c7NhdQLnxb3iYbPzFOWKZw1+w=; b=Qhn+ll5ln5U4FFylVW+USeTVBAoDM7NNX67fUeLqkrkTyDFSa/QJBqcp+8RDdE10pv CNcp/fK4DswVaXbwQtFomjSViQdNCnISqTXKjAkALY60Vk8t8P4U9Awn9HCV0YB8JZ7s uom/Brm1gViWKsIE+ePSHkZwtf9GjwDdEWAY3yz4IxspWzV8ACi0/PBrc0vHMF9T9zOd hT0runMKabzQoXwiLe7mw2E6gZToPabJKjLY1nS8Zv3IaZNNmCxscXIHVXyJjus0cRf3 3RLkGMXrm24PDySe2nT0Q6RLQotlbe7GLWQkx81fiiWaVkWKBdlwsU4e3Qea91lvAJB0 PquQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693564009; x=1694168809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lvF6Z97KxKbq3h008c7NhdQLnxb3iYbPzFOWKZw1+w=; b=AjKwD32rA7dD+LbKMRgMIZEt0wFmK9TvvwW3amGIlI5M5tp3Kfa+3hqpFjiOxdkIpt /QvthmvEOlEMmkcvQNrGdXV06Ba5JrT2WEooee9wnWl3zv6NXZalOdxWdJOkqd66VvMV KSHWlpra7KjOOnxH6UNwZN6GWnT2aCXdA2eTC/dUwUVWvzcVSGxfJlYScxFMxkn9zRA7 ZfnrzKyXIykQrUlqLPH8H/jjY/aOduNEG86PD7fO83yrucPiAbKvyGJbQxPJE7eKYa5c EeFdthebPRgUXabiggO8/e5cePZyrPz7Scgkeux8/sXVcMex1R+Jd0bfGFtqxfepNrpZ rE1w== X-Gm-Message-State: AOJu0YwagMnu6dXfojSvO3xchsAJoonGV/6yvD4tcSXp5LApCdQ/g54M TvBTITto3r58uwZ6clVjrljoVXJWo575jbxCDqo= X-Received: by 2002:a17:90a:bb96:b0:26d:291b:cfc7 with SMTP id v22-20020a17090abb9600b0026d291bcfc7mr1893400pjr.45.1693564008816; Fri, 01 Sep 2023 03:26:48 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 9-20020a17090a190900b0026b6b17ca5dsm2917358pjg.54.2023.09.01.03.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 03:26:48 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v2 5/6] cmd: efidebug: add uri device path Date: Fri, 1 Sep 2023 19:25:41 +0900 Message-Id: <20230901102542.609239-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901102542.609239-1-masahisa.kojima@linaro.org> References: <20230901102542.609239-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean This adds the URI device path option for 'boot add' subcommand. User can add the URI load option for downloading ISO image file or EFI application through network. Currently HTTP is only supported. Signed-off-by: Masahisa Kojima --- cmd/efidebug.c | 50 +++++++++++++++++++++++++++++++++++ include/net.h | 4 +++ net/wget.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 0be3af3e76..f2fd6ba71d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -829,6 +830,52 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, argc -= 1; argv += 1; break; +#if (IS_ENABLED(CONFIG_BLKMAP) && IS_ENABLED(CONFIG_CMD_WGET) && IS_ENABLED(CONFIG_CMD_DNS)) + case 'u': + { + char *pos; + int uridp_len; + struct efi_device_path_uri *uridp; + + if (argc < 3 || lo.label) { + r = CMD_RET_USAGE; + goto out; + } + id = (int)hextoul(argv[1], &endp); + if (*endp != '\0' || id > 0xffff) + return CMD_RET_USAGE; + + efi_create_indexed_name(var_name16, sizeof(var_name16), + "Boot", id); + + label = efi_convert_string(argv[2]); + if (!label) + return CMD_RET_FAILURE; + lo.label = label; + + uridp_len = sizeof(struct efi_device_path) + strlen(argv[3]) + 1; + fp_free = efi_alloc(uridp_len + sizeof(END)); + uridp = (struct efi_device_path_uri *)fp_free; + uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; + uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; + uridp->dp.length = uridp_len; + if (!wget_validate_uri(argv[3])) { + printf("ERROR: invalid URI\n"); + r = CMD_RET_FAILURE; + goto out; + } + + strcpy(uridp->uri, argv[3]); + pos = (char *)uridp + uridp_len; + memcpy(pos, &END, sizeof(END)); + fp_size += uridp_len + sizeof(END); + file_path = (struct efi_device_path *)uridp; + argc -= 3; + argv += 3; + break; + } +#endif + default: r = CMD_RET_USAGE; goto out; @@ -1492,6 +1539,9 @@ static char efidebug_help_text[] = " -b|-B