From patchwork Wed Sep 27 09:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726692 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430524wrm; Wed, 27 Sep 2023 02:37:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQf4RgCHhm//dIesGGzgokPVsVZBTEnJE8bRm0o/8guQ/fau+OtaOUa4F9SXUwIVFSwz6s X-Received: by 2002:a1c:720a:0:b0:405:39b4:3145 with SMTP id n10-20020a1c720a000000b0040539b43145mr1538650wmc.2.1695807457335; Wed, 27 Sep 2023 02:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807457; cv=none; d=google.com; s=arc-20160816; b=DBd9ebo21R5oqYOhGI+umLNUq6QvleUIaIMsXtZcZP59uYRZwBO2jpmM2NQY2HiH+x zVp2Pg2kALMBhLUozUjwwV4aFv6x6SW+fKgHCAc9r1bTx+8CXP/UqcwGCVhNGNC+tx2y Dm6Eo9D0+ZTmDo2DKJimdIMevixZVES55zAYVNLrPu+nXz0zkKkqMkjvOjPis9SxKPOj 9SpuiXeqWRr3xnvxND9FkvZQKm+ItjRCpo2IJG2nZ4thkVhlW6wrzvoNNJHIqdSRzT/s x9InY0N/qsL7hYU/dkJfts4MSJvv3/WutjRNGOJk+SPI+JrO9O8BXOHFYaB5O3FLCHkK RmLQ== 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=DPpoO3E3wKSKmirTYAQ6I9w0N2Cw2YOKQMy00nQW3fw=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=pm4L+RzOHyfUtQdzkn5y7Ecfa06m/iZYdMjxDcQaeEQkgd5xGnsRag6u3ry0U1U6lK wKBlvKBXAWkhVETTOKN9JXRZ75wW0Sk15OoBLBg9Lu+EySBaMSm/7YzyGrslFWoFEMqD +AKeekf2qNmSZJ2aoA142JpU0dwSKlHkspvZA0XcgnCe1d74UadHBTmHSpCA2vROOAtk eroXmOCRl43kwfPnJIG1Zwqg/XyyptYYlZqTk88F0dPBwU5lRYT2Q7sgQt81VnX0AICl 7wlyPwyM+iVnKx4ZdYfkBUKQhDd5h9iVd/BxPOpIThvd89gMbdSWl130MW8Vz1SdX09Z 7WzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G5lDVLdP; 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 b10-20020a5d550a000000b0032326716ba4si3778977wrv.520.2023.09.27.02.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:37 -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=G5lDVLdP; 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 9ABDF86D52; Wed, 27 Sep 2023 11:37:30 +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="G5lDVLdP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD8AD86D82; Wed, 27 Sep 2023 11:37: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-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 8780C86D4F for ; Wed, 27 Sep 2023 11:37:27 +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-pf1-x42c.google.com with SMTP id d2e1a72fcca58-690bd59322dso8082465b3a.3 for ; Wed, 27 Sep 2023 02:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807445; x=1696412245; 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=DPpoO3E3wKSKmirTYAQ6I9w0N2Cw2YOKQMy00nQW3fw=; b=G5lDVLdPQ/S16Gh0kHVv/fhVLNJh02CPa435CcrdMmlRPLvUmW78wwqpvRMUUOq71W /YnRNBUCXCEJr+Zu7TQIbaZaVEdIKkGBof4Amh+IXUlojr/Rsl1PpW9DrLv0g6BJhxtG OXZk6633w5bX8xig+4AfYAFqV6E4y4I8jCJrp+HxSuwWOTTGAjz53TwNIsdpZSEjsdAS 0r4Hz0igRe3V9cLZAN+FGmkoBPNr3xVtlYJJXZZ7vXyUSQeNDYJ6DJbh0ahijPtvFnTl Al+kbS5/K8MgYYsHsWMlTFKddQ09HFMdINAk3BhlJx14HcaXgRc1/MjJfjgAi4gwR8nD myjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807445; x=1696412245; 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=DPpoO3E3wKSKmirTYAQ6I9w0N2Cw2YOKQMy00nQW3fw=; b=O5P5gFditBVNEFdj3DHmKYqIvhsskboKVMlqZ89BI1Y95Y961TBWO9u7EH7AfuMx9O IV0c7TYmmu+7vr5pu4JdcGHVtDiES4I/3O+ro12HGrNeeQX0swvAZD6gM5ZjqroTSANK EvDrJ/hX5f/AWm79gmB3e/Ynl2C8D3yXBcPt0Ly7IkCIl+70rt6CMdBAme7d64SJ6jWX hoYLBBdCg+XcC+YNQvbY7w3VNv3o9RbI/uMBzGeZWjgtty0LxxB/KzvTag9z6HXtl5Dw BNL9VY6yYrNNm5fx6RBvBT2bjNy5LS9mQjjV1kA9/Zd3icIMY08kXh76GqIxH6Diintp Mv2w== X-Gm-Message-State: AOJu0YwOaJ4jNd0MWrkrMBHafabMPaWJJae9Y8rGV3i9SaLDKrpmSnQZ /2G/ItP8ntgeQaoA6BNM+sd8m91lsYmr6EocQoU= X-Received: by 2002:a05:6a21:a5aa:b0:13a:ccb9:d5b7 with SMTP id gd42-20020a056a21a5aa00b0013accb9d5b7mr1925664pzc.41.1695807445421; Wed, 27 Sep 2023 02:37:25 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jd3-20020a170903260300b001c3bc7b880csm12650173plb.256.2023.09.27.02.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:24 -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 v5 1/7] net: wget: prevent overwriting reserved memory Date: Wed, 27 Sep 2023 18:36:25 +0900 Message-Id: <20230927093631.1595494-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 Acked-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Ramon Fried --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 2dbfeb1a1d..a48a8cb624 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,29 @@ 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 */ +static ulong wget_load_size; + +/** + * wget_init_max_size() - initialize maximum load size + * + * Return: 0 if success, -1 if fails + */ +static int wget_init_load_size(void) +{ + 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; + + return 0; +} + /** * store_block() - store block in memory * @src: source of data @@ -63,10 +90,25 @@ 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); + if (IS_ENABLED(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) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); memcpy(ptr, src, len); unmap_sysmem(ptr); @@ -240,25 +282,39 @@ 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); + net_set_state(NETLOOP_FAIL); + 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); + net_set_state(NETLOOP_FAIL); + return; + } } } } @@ -330,6 +386,7 @@ static void wget_handler(uchar *pkt, u16 dport, len) != 0) { wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); return; } @@ -420,6 +477,15 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (IS_ENABLED(CONFIG_LMB)) { + if (wget_init_load_size()) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + net_set_state(NETLOOP_FAIL); + return; + } + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Wed Sep 27 09:36:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726693 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430575wrm; Wed, 27 Sep 2023 02:37:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxipSUSQ3WsKZN6vV7bcnDkVenhQ1656Ok2ufj+gJLAePQNKRdpCcG/nM4IyaGmiKBsrDv X-Received: by 2002:adf:e791:0:b0:31f:fdcf:b2b6 with SMTP id n17-20020adfe791000000b0031ffdcfb2b6mr1284485wrm.55.1695807468230; Wed, 27 Sep 2023 02:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807468; cv=none; d=google.com; s=arc-20160816; b=HS8MyW9eNaN8jbbfQXzIVtT0B834iCy0nSJX8W78NGUu11OwTEsY2WnNXxVmaVSM9H AiCW3MbRWAhJ8sYod648TEcpG5jAbC+Yi3hjx3tzURmk+JR3/HRmR79nXobvXAKZZekE BZgWQjeMT07xBZ8Fl3hPqvKy4LN+8WgaLZE7bx4zjaaU5G2TNCCBGq1ONWQbBr+0gL5I JbotkgOhuBsQd6rnrm4k0MG+PpcXAsBOROpkf3znKgTSTIxBF9xMfe+V15AqLk7TE/yN V6PXgAahGYN0sB/p5Q/HsFt2/t6ACP/olhcKTMlXL3PjrEozjtrSfmPOWtDcFymGjlm7 KjgA== 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=ITfXMW0fZwZ7CaL2ADfkNrX5rwSrEEISxf6LmoDLP9bgK+E+VE17YweCaqKxwZ548J zJyKEl6nqWVMJy0EZr/aR+Fpjek+Ao+rcO1sdous5Qcn/4prTahS9heRO9eWDKdfc7ZA Kfra3449uJpRWs5a0TKqgWDugAzSKQ/DCWFwOfzu5Y/WOMZXP2fm3u+7oZXiqAfySYwD W3OjmBRpOpvVeuwgmVz7q7Uwe66uG9STfQ5vi3xsQRZ31hU0jYX4aV65gLjZLI4KNuqp s3i4y6+UEn7HZKp5mx2Fv87oNW+kLo5cBNcJFJlb7CzS7OrbzXqCMGXC2nZby+Snsajz Wmcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdRDwubt; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id x18-20020adfdd92000000b0032160212b91si7226120wrl.206.2023.09.27.02.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdRDwubt; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 08AC686D4F; Wed, 27 Sep 2023 11:37:39 +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="bdRDwubt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 62CBE85C98; Wed, 27 Sep 2023 11:37:37 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 338C586D4F for ; Wed, 27 Sep 2023 11:37:35 +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-pf1-x433.google.com with SMTP id d2e1a72fcca58-690ba63891dso8082444b3a.2 for ; Wed, 27 Sep 2023 02:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807453; x=1696412253; 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; b=bdRDwubtHafiTQnFAVL4LqNBBYX3i4YniOlNLgcuxI5oVVFYCks+9lP8Nw+elcysp7 TGRJpuq87AYT+BMb+F5IVFAdDK/ZSh7j8G3l04hu9+IEMs7AWkEJaUYB1CDQPrL3cIaM lzG/cF4oFM1iTqaHoin5cFCwsvPTWQCs2bBnb1Dbs+uCJ+fSN7Rpogxw719LpCYWh2rF +nTLQWLw7464lX+zP/ANS+mwdttDEFHuFx/3znwp67NBAMWeeuS5SbvIotOQMYtd+Rsg HqlE1fV/7TnXv36prkPtMBM7O6wTQRHhjQP6BVIu+94q4u6HCLrwvNehA1yGRxIUuljX 6CTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807453; x=1696412253; 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=23L8aS493+zafOpjLr+4gUrZEYR4Ae5sZvaUqjD4Qh0=; b=tXnnfw8Wkej6xojaHv/rluHj63laaFnIsrWePb/YCX8krZGtISZKR2fGV+Pc33IecM lc0kO4gtJTkeLm5bdIYoKeVrIK37fUBTsKgtHXch3SRomegpYOdLUmE1tYZuMmd2LBBp uKWthA3DMpBMn9NXqdM+2quIbdTkf6Bf8XxY8bCsOUx2u4vXG4y24Z9h7Sy+kh0nF/Xn 7iNq88JCP+zkHHtUf50g06h4Arr36rnIrlTghUMJE8J4mX/2oxfMfY4zHS4PscnL+3mw HOc/YVfV4RohNLYBeLXpLYbUdTN5weu+2l3TdK6WDOh/5b1bviTj0Zx8b409456vQEKG A9Zg== X-Gm-Message-State: AOJu0YyWshjXV3zVS7xlUyFyFWWomTFptCNANIM2D8HzyLuY5nf5TpOK 9VI/MfhWVCs25ptMasloMSwSI//zYQ/X74GIEk0= X-Received: by 2002:a05:6a20:3d14:b0:15f:b5:bfee with SMTP id y20-20020a056a203d1400b0015f00b5bfeemr1535024pzi.5.1695807453112; Wed, 27 Sep 2023 02:37:33 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jb19-20020a170903259300b001aaf2e8b1eesm6694183plb.248.2023.09.27.02.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:32 -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 v5 2/7] net: wget: add wget with dns utility function Date: Wed, 27 Sep 2023 18:36:26 +0900 Message-Id: <20230927093631.1595494-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index a48a8cb624..4801e28eb9 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -504,3 +505,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, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Wed Sep 27 09:36:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726694 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430631wrm; Wed, 27 Sep 2023 02:37:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYhBwqHV5fsPr4db5hAFZHI16n26gNyLmiMqwYusOAFCYT7aZTzD2a7im5esF6WR0O13DY X-Received: by 2002:adf:cd12:0:b0:321:4d1c:425f with SMTP id w18-20020adfcd12000000b003214d1c425fmr1250814wrm.47.1695807479643; Wed, 27 Sep 2023 02:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807479; cv=none; d=google.com; s=arc-20160816; b=ya6Hw1dQ6VgPGJ5bfGFyaNFIC8CK/xlbWIuObYH/+xRVYUYuBRmRPOyt3f+020+yXw 5JA27OLaf/MJZCTsL8mkTxyf23rtlR5xmflhdWIeeybP3OTNwTryFeFBZ+yoYWRJEbPn 6HUm51B3LiSn26vtc4hAIyQApBTWXmXVN1oNEOL2QgFVn9ebNGWEvT8xtTptQYFVV5cs mck7SjKaTOpx1fyY0cqlZFIf2tD9ukN49Eey79PzV88fNEClr4YtFW8MkL5SlzC4MJiQ OBJAE//qffJwLZE4vjXnGLPb0OROSZmVU4voC2pqZBHYU/z3WvKPnr5sfimoPO0i45Gk PxJg== 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; fh=/7JtEi60Oc1He789ODhlJpQcggvkyewSA9z0FHm3qP4=; b=Bh8UQEHnjKtMczKf/f8VLbz7BfEm1Wza4ju526AKe4jgQp35X2hzue6LdZBxb5h7Mn E4zbF2X+aU1PwhXOGCZV3f9n+G5qp2cqtQ78WNv5fJmRt09lgqr6JdlKHhdd1sHdcKtt ypyVrmarjSXyA5Sjl6qe110HMjyAs4ZHNcsTnRylOrLa8ZJcqI5m/eBWoxe0wKvuPk7i mLGmbKOp50fgtlxPUxNYgoiGaAHOU1eUPlTwt/m2GatIu3fACn2JOfhkdKDtiZ5aF9hv gIsltz+FCixWXv/X926RBcB/GuAATzs8MZCtPvTVT+9yETu7ERcv0L0Wg8jHREDIIMjc uoOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HkDMYsNU; 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 s9-20020adfdb09000000b003232f15438esi2793466wri.1039.2023.09.27.02.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:59 -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=HkDMYsNU; 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 66BE286DA7; Wed, 27 Sep 2023 11:37:44 +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="HkDMYsNU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EACEA85C98; Wed, 27 Sep 2023 11:37:43 +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-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) (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 0D39386DB0 for ; Wed, 27 Sep 2023 11:37:41 +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-oi1-x22d.google.com with SMTP id 5614622812f47-3af5b26d5a8so284425b6e.2 for ; Wed, 27 Sep 2023 02:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807459; x=1696412259; 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; b=HkDMYsNU5psf+Ik208GmXw31AWG/UHxdkwTCRmLHmMPccjo41PTNtgRpIVl5A3SWic PHOKiMRKi7GhBhAqPhKtCBL5DM72qvQj8bBn7XWV1feR43Nygc7yTlsMBG3xGx2FYjPe fcONk5obYVClBuiLxVkoWYbLMZTjDBS6Qop7i+grS6NaocRSqBefEZOLTYXHGVT9nFqk /z35drUJ2wMBmYBtD8teUKqGm+h+o2HKALnzUIVSPmOdcrsi4PnQG0Mjfv3meG6Xszdo 06UzRw7RCVwsZdD3tHJvHWdL4OZTRppcK3kkSVJejX64DspAb8bl2/W736AmVPOy0Qpl Ku/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807459; x=1696412259; 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; b=cAvkRF4uSYUzNLz7c6IN+x0XERT0X0HDrHSi/nuSj/Vo9xa91iTnns/ajBTn7ANUZl kWtXV5lkD0lMdABmsbbYTFZlocVKGBI6WRDThtOH0jFK5j34g0p2Wzhnj7t5zNpFOll/ 9Y4FGHZ6dnr1VDzp8Stmn8iKZYxzUzexWb5cyBnOD+UaJYwK32D/EAn7EIjMOVXI6go3 BWa1MJz+sAzKuaR6+2Dt/wssnndEMI0HwbaD7qRxLpnQy9yqXnMZj6rX+DweCxFYo6IW g8aipJHGETdbCrmd/po0w+Y9PSwezFqUJ2briMOHPl9nIFjAXrEeMC1GZpQ4HwPZabkF C5fw== X-Gm-Message-State: AOJu0Yx9zXPx0ktHYVdQon503i+qyQ34vaKpkBtyRrrf1nI4CFbj6MFW k+RMPyn6GTD63C0ys5OcIyeTxndsNtPH4ZX8Ziw= X-Received: by 2002:a05:6808:bd5:b0:3a7:366f:3b01 with SMTP id o21-20020a0568080bd500b003a7366f3b01mr2150777oik.33.1695807459326; Wed, 27 Sep 2023 02:37:39 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h11-20020a63574b000000b0056368adf5e2sm10947339pgm.87.2023.09.27.02.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:38 -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 v5 3/7] blk: blkmap: add ramdisk creation utility function Date: Wed, 27 Sep 2023 18:36:27 +0900 Message-Id: <20230927093631.1595494-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 Reviewed-by: Ilias Apalodimas --- 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 Wed Sep 27 09:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726695 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430718wrm; Wed, 27 Sep 2023 02:38:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHx1jR8DgNTQgdkxZrooD+aa1rXpzG7TEm3/DBABldAp1uXj3E6k6qE8vJAGH7Dk3wzxAlN X-Received: by 2002:a05:6512:3ca1:b0:500:b88c:ea79 with SMTP id h33-20020a0565123ca100b00500b88cea79mr1478098lfv.54.1695807491624; Wed, 27 Sep 2023 02:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807491; cv=none; d=google.com; s=arc-20160816; b=LUNNhh67l50QTfs94O6eXdZHRZ/qNbQIl+5QyR2Q7uVGq9f2hE2uVM52aPO5Q3T02t YKg2b+1TdC7IYPFOn8Hexq0pq33Cn5CT4bMFI9m8IXJOsExnpGsDQ/taVzbkgHxcF0E2 YvfJIbM8gF0ThL/d0Hp1rkKjEriJcM4eCjbdGcrOS1rlhkAjduuHOSRoBpZk4c/kC0Oi 7qPsgzerxxEwjxd62/h9mv3YB31F6k2bNgIo5ykCaCkJJqGr5I8fx5dwETDr0LSboQ4c xIiJily04j2bZ/1E4V7qhRF625E325GQq7L+Eu1C4lk575AcQwcpXi2/rlV5Z/XI3zXq An7g== 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=N1AsBZDMagcwhVH5MHk4s7ySm+OXoAUqVLonpxVJiAk=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=JvvrarRvTaGHGfosHJNZCEu3Vmcp0utIN9bWEDvQKUl2/ifsHCv2TLwCR+j2Mtr1QY rYcjqjyEBEt/Oj1XPvoTo9ZpTypKcBxSJR/d+nh8ZYzStDoMY0do+XHZ+nLJ9o7gPY1x 5ZCqt907lavE0IVLrExRXRXRBjG/AXamY8uzcDQf2MC4UUYspbTRmo0GJRYEitjs70O0 IjWhHRQh/dRs+sJjif7tLAUXRZmdgr7euAOHnH4gxb3coSWKlvEJTLNUYo4XVjXhnCib 32Z5UWV7I82+bzEjsii3IXvV7679aFJPrI5FwbHsrSAt14K7pl6LvcO2VWDhqXu9MPky Cydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="cOZz/atC"; 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 r3-20020a5d4943000000b0031ffb841bffsi7274948wrs.249.2023.09.27.02.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:38:11 -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="cOZz/atC"; 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 D166686D93; Wed, 27 Sep 2023 11:37:49 +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="cOZz/atC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D857E86D93; Wed, 27 Sep 2023 11:37:48 +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-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 842AE86DB9 for ; Wed, 27 Sep 2023 11:37:46 +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-x629.google.com with SMTP id d9443c01a7336-1c63164a2b6so23524105ad.0 for ; Wed, 27 Sep 2023 02:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807464; x=1696412264; 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=N1AsBZDMagcwhVH5MHk4s7ySm+OXoAUqVLonpxVJiAk=; b=cOZz/atC0G9fNbp/y/CPl8L8+qKcBonL65od8TAcHI1HD0VuUMYG6KCtojDHNriQ2F knWW/UBTOFqREjzF74d8iTWRrD+w1XT0XOJedoyEvZ3XGa6vZm7/XueCRpyV7OHGDgAg 91awSWlsrzVO/OGI8lUIrKMU4oHDVOmMFWUVINtkATdkSoH7m0DG1+F38EstRPOEGpqm BBK5i35YGgslHySX17DEfJPXYm1ELLyC5lG4z9GUYQhRmen9jwf4jvO1CBj6aEiDmZ3t guhK0OafjzaUhJTp9w6aCZkR/5zYInZWxKB5keh90CPUX4N2gbOs9Jf0XUQC4pHGCZ02 AYKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807464; x=1696412264; 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=N1AsBZDMagcwhVH5MHk4s7ySm+OXoAUqVLonpxVJiAk=; b=MPyw6I7pwXJA3N5SEHG2mRxG+ga/mj3tRnkGok8ae2WUK7tJagqlaLVxgWWo0sWvOm vmxyh0sE3cdgJ/pi6j+NP8s5g6/CyBwzCJRWMjguJ/lNakauhFQPXqVBsQ9PhxFMd2le o1K7wg2o9N8UsJ7+BQypGrVmPUz1llnGHFPZG/N/8Hlsc0tJwwQEUvgkzJcap+SQprrW HTJzTJUh4hl4EBj9HxY1nQ6Kw/m+lAmj61saRoHbqJKw/6Hc/LPAQmB/gWBbRJBRO6Oz 9z7DZB2swALDdbcK80Zdhte2zG9S/Yfvc4ItOvCtDxMUw1VBc3H+7Yhg+3IDu5iiByWg Ydkw== X-Gm-Message-State: AOJu0YzzxK02PKdupxIIVZdnQRKQdtpzl4kLr2yIP2fBQclMw3tt5j16 X12FkddKUVPFtxEXmRRjz0IK8m9rchAmTjJfsgI= X-Received: by 2002:a17:902:e84d:b0:1c7:21cc:2750 with SMTP id t13-20020a170902e84d00b001c721cc2750mr3692985plg.28.1695807464478; Wed, 27 Sep 2023 02:37:44 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id n12-20020a170902d2cc00b001c474d6a408sm12579998plc.201.2023.09.27.02.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:43 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v5 4/7] efi_loader: support boot from URI device path Date: Wed, 27 Sep 2023 18:36:28 +0900 Message-Id: <20230927093631.1595494-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 PE-COFF file, load and start the downloaded file. The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image. For PE-COFF file case, this memory reservation is done in LoadImage Boot Service. Signed-off-by: Masahisa Kojima --- include/efi_loader.h | 2 + lib/efi_loader/efi_bootmgr.c | 198 +++++++++++++++++++++++++++++++++- lib/efi_loader/efi_dt_fixup.c | 2 +- 3 files changed, 200 insertions(+), 2 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 4a29ddaef4..c4207edc91 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -554,6 +554,8 @@ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition, void **address); +/* add reserved memory to memory map */ +void efi_reserve_memory(u64 addr, u64 size, bool nomap); /* Carve out DT reserved memory ranges */ void efi_carve_out_dt_rsv(void *fdt); /* Purge unused kaslr-seed */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..a5030d50c0 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,187 @@ out: return ret; } +/** + * 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 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 **)&handle)) { + log_warning("DM_TAG_EFI not found\n"); + return EFI_INVALID_PARAMETER; + } + + ret = efi_search_protocol(handle, + &efi_simple_file_system_protocol_guid, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(bs->open_protocol(handle, &efi_guid_device_path, + (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 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); + if (ret != EFI_SUCCESS) + return ret; + + /* whole ramdisk must be reserved */ + efi_reserve_memory(image_addr, image_size, true); + } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) { + efi_handle_t mem_handle = NULL; + struct efi_device_path *file_path = NULL; + + 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; +} + /** * try_load_entry() - try to load image for boot option * @@ -185,7 +370,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, { struct efi_load_option lo; u16 varname[9]; - void *load_option; + void *load_option = NULL; efi_uintn_t size; efi_status_t ret; @@ -211,6 +396,17 @@ 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); + } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) { + if (IS_ENABLED(CONFIG_BLKMAP) && + IS_ENABLED(CONFIG_CMD_WGET) && + IS_ENABLED(CONFIG_CMD_DNS)) { + ret = try_load_from_uri_path( + (struct efi_device_path_uri *) + lo.file_path, + lo.label, handle); + } else { + ret = EFI_LOAD_ERROR; + } } else { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 838023c78f..edc515b9ff 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -22,7 +22,7 @@ const efi_guid_t efi_guid_dt_fixup_protocol = EFI_DT_FIXUP_PROTOCOL_GUID; * @nomap: indicates that the memory range shall not be accessed by the * UEFI payload */ -static void efi_reserve_memory(u64 addr, u64 size, bool nomap) +void efi_reserve_memory(u64 addr, u64 size, bool nomap) { int type; efi_uintn_t ret; From patchwork Wed Sep 27 09:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726696 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430783wrm; Wed, 27 Sep 2023 02:38:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbVPxuCKPOyOET9xJNqYmsZZBi056Eg//3k55nbN6x469QxUXC3qwiCGRqo+KdbaAggf/A X-Received: by 2002:a5d:5944:0:b0:321:c888:1de7 with SMTP id e4-20020a5d5944000000b00321c8881de7mr1201498wri.54.1695807502558; Wed, 27 Sep 2023 02:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807502; cv=none; d=google.com; s=arc-20160816; b=NbJszhO8vADvDtmZfPP1btC+8EFgYflZ3rFPomdXxE19gMCVXkELAbZVYyIQp4m40R qqAW2Fu4/TwOActNWAgr0u9aUniO6XPFv7yzODeVOwvOmje9wC2ttsIh7BZLSWnu2+EQ mk/IgHdITJ1cd3/a2wq/PSfrYioRHt19azavKsFrHuWRoB0WRFSk8y4OajVWkcecSKvI kTUbwXQEgkRTXFp4VNnr9tCxccf4eBnV52WeILxY1HtetGJ5WqrS53ekw4hVR/dSf1KZ WUXieOjcyuL3gvyaaPrlEPMHYYW4nr1VQtIRnti9GrnTtptHi8kvLyF5PuHc16rP0DRE C7Zw== 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=oaMDGqRnc0d/jvmwKTYWFSifA73Ii6B1GLrcLxcteYI=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=v+BOKiGoPXOtCrjERfj47tcrGaAB+dBujRsgnbZvPCPo41fP9B6ZuWhKvV7OrwJV91 d3zNAPTpNVRWc1U6L3ChavLwyx8o6LA2DEA694Vczd+Z5+RCYZyDJX0TQdnD5Ru1rvf3 FhbydgE2OYO8VyPDnKjeru+amEBxc5ZUQaSNbEcbUVNcUuo3onB+QZjNcHIdbKIuc9Kg x66++JIqisds6vYXJGAJ0m+BJ8tOeGTm5cnaJmphf8Sq5RIJDOrKu/JGrOCJekIn6Te3 LI6aGSi0a3nA2BPc1b0ZPPcQsfXTk8H1ueWaYeKwv9mbgpcc2oQ/RoVrOxsTk6/fpi8H asvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hwhtFUgY; 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 o16-20020a5d4a90000000b0031c65922bf7si7672819wrq.920.2023.09.27.02.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:38:22 -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=hwhtFUgY; 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 3D28386DBC; Wed, 27 Sep 2023 11:37:56 +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="hwhtFUgY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3D21286DC5; Wed, 27 Sep 2023 11:37:54 +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-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (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 F129A86DC1 for ; Wed, 27 Sep 2023 11:37:51 +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-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690bf8fdd1aso8455688b3a.2 for ; Wed, 27 Sep 2023 02:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807470; x=1696412270; 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=oaMDGqRnc0d/jvmwKTYWFSifA73Ii6B1GLrcLxcteYI=; b=hwhtFUgY4+7K5wDQgIORKkhKWN8wj3zfQY5Uy8BSa8+g7Bw9VgDzCkSJGNUsJAaAsq rj1e0/FwzG1E5SCZXe07y2LpP457d0pyaXG9wUNPy1bYoYJ1cpTpm5JVsYw0HJ+augGR tzABRC0+Zw+6rxE5o2R7h7qk6HQjesejbwG0eARjaq10swY5VYZYuFoeuxbVMe2J8B6B H1WoDpDtbhfUuvAB+7eXlX+472D8QrjJGfV1m0qTdq5hJq7dso4tMnP20BU7PTlDQQ6k U5kCmYFljQkBEdjVZic6nRnQkRdGpUAwvBxzrCLeNJfDieEg4OfGFqxAgXjdOgKeZwwC xnig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807470; x=1696412270; 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=oaMDGqRnc0d/jvmwKTYWFSifA73Ii6B1GLrcLxcteYI=; b=F1VqEuNo/r1WvewQhBq88WVUELhMJsgrB0ArayhtgTKfWzTIddg2A8dU5NTLHr9F7D ZK34QX5jg0qlxlxk0F9vpBzOsbJIOr5AUxQqk+9ODDaFptI9gT9c0hPBW6+NJv/FUaWc XJoAiGEpGZnwSw2qHGo8Z94F5NNeaNHPoMCX4Yc62xFjmPTbjafNRZtI5LxQclNN2gZl Oyuf/kqiVN2ixV4p9pwIDnaEvRmLDZ8CMJdW0HwEvRsqVaNxxiAxH5pb97GvFLkT3uzo pPR6vF1B9hkINmnGpG/l1nhV7C6++jelCur3Zl8NQB1Ql+CvqZNfDDBrSSSTaxRtZPo5 BU8w== X-Gm-Message-State: AOJu0YznTSma7dC7DuIDm+8glKJnIkSpb9e19jW+LSrOF2gsaR+K1EGj 69sD98NQhupbOCQOxww9JrzhspnVo+TWbv3pqHE= X-Received: by 2002:a05:6a00:2e86:b0:68b:e29c:b61 with SMTP id fd6-20020a056a002e8600b0068be29c0b61mr1520886pfb.19.1695807469955; Wed, 27 Sep 2023 02:37:49 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id x18-20020a62fb12000000b0068fe6ad4e18sm11396151pfm.157.2023.09.27.02.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:49 -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 v5 5/7] cmd: efidebug: add uri device path Date: Wed, 27 Sep 2023 18:36:29 +0900 Message-Id: <20230927093631.1595494-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 | 8 ++++++ net/wget.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 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