From patchwork Fri Sep 22 07:11:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725216 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp875842wrm; Fri, 22 Sep 2023 00:12:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHY/OwDDJIyom8jZ2IjVazy9kLXgvstAJIcE9HCXfYJmEdKQTLTymlqpj6nP3valSxquLDi X-Received: by 2002:adf:f043:0:b0:31f:e026:30ac with SMTP id t3-20020adff043000000b0031fe02630acmr6989487wro.34.1695366725716; Fri, 22 Sep 2023 00:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366725; cv=none; d=google.com; s=arc-20160816; b=DyjfEq0LX14KdK3vDkewUiVSfzuLykDUYNPFLuq662JHEQTOtyjxN8RM2BuMuqChlU Maxh+u1WHTBY0Lu4KMmsyzcaOmA9JOKXK/Vt6zJM4YlpYRknDJs4NqK3KshRjMIQ6IR/ nlA7/i4tKht7eFPW5P5CU/eBF3yCqdyttBYApMw83YA2/wi2fjdlnQszRmf7WhulbOey iLKIP3kTLR04b8NUT38/iUe5Co42sLOW0MC8W70Lv5i9aOpoHqtFpGNA3ILzyOj26SVe sM8nfrMVjf/staQezvb16F+YhQ/wOBTpuZ/p2Oi0aR6UAhNffNPBvbBH32/N9ENL3hbe uUgA== 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=WU12nRc3PY07Ru07cR6taZkTqc1pHCkiZamCQo1Qz1c=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=AF8qwGjIpDl9ZZ4SuL19pJUNPn+TnxmKZyZEwMkxgNGy0Clldh3gXQ7x5TN7C8z1XR aGLTiOOlMfnkbRCR+SGenTr7dZpI0vLU0zutcSDNDo+XfJByqeDtsMTjXmeFfPEzHk9m qGg1TSKmnn4/vlGFKiPMbs1CbYAL9HgRiI31d9StI/+frXbPCwM07ycBKbNFhehe3lP7 AbqvpdC8FeBgoHS5z8QcnfTQH0wRHOaJIz2bef9wsHs771KaGCQrwF9Ew7s3X1F5MtNi bFnHezniOoNsAEdtxcC9mh0N//YGLB56viSqDqRrL3LR1kbNOXrtmSe/SOXjjyGHTsc1 Z6HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F+hOPqi/"; 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 d12-20020adfe88c000000b0032171fc3307si1606525wrm.867.2023.09.22.00.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:05 -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="F+hOPqi/"; 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 7A716867D2; Fri, 22 Sep 2023 09:12:01 +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="F+hOPqi/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 83A7786680; Fri, 22 Sep 2023 09:11:59 +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 4FCFD86575 for ; Fri, 22 Sep 2023 09:11:57 +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-1c3bd829b86so15658875ad.0 for ; Fri, 22 Sep 2023 00:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366715; x=1695971515; 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=WU12nRc3PY07Ru07cR6taZkTqc1pHCkiZamCQo1Qz1c=; b=F+hOPqi/r6No+psk77FBLtcuI951uNxD1u+Uor2o7+IqQ2IZiOJZ4uJQJJwG3DQuvC MJRnT1RbsFOxvu9O6IZm7Jo3bV9nWEPsB5Q3JV7wORNyNOIwz/JD9G1qgOekKu1uMwus li/xffUa8XxG/JLsnX7BIBmZuqLYBzIF1iZXknOqpNUfWC5h36zr+Yb7dtDkQtdfL3wb /0f6B/bu0Qnk3FWVj5socpyZ9N+0xZEXpsQriGZ9k6GwVJ7PSBqMIEwZ9ZTbBYymeC/A NU024ctUNGKoXLOhNVyI62huFfAQ7dMWRK3JRp9xtdIxHVSv0CMnbZnNQvShRAk+yO+p Ba8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366715; x=1695971515; 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=WU12nRc3PY07Ru07cR6taZkTqc1pHCkiZamCQo1Qz1c=; b=rLFJwjNkc0Tz1zMP8neQJ9Am7gP6bPBNfU6E4lxArk1khYq9WRWJda6Sg57EKEutKy zk9nVAKKn81lNpByfEem8Aai0GdQJY2oVMM7PLeAdg902sJiNqaHuLXsEZ/IQVDsd2n1 ugC7b3eRLuWOCZhWaX+L69igIhqWdZdOewrhWB06qZEjHCgOQZOrVZ9HztsSIDgYcTA5 e0/HtS6cMleJjrGFXlCwV0+Swq2vlLN3bnonaOaoZBf8A96dT6msnPoXaubz9NM0wphT 9rdI4w27sBWWLdD7AbYokYkb6LTRhtyp8dYUzsl10mxP9rIJOuE9SfMyOg+2cj0g9wlc veFA== X-Gm-Message-State: AOJu0Ywfku3rqEasbFBfZw5t4owzSOX1MFJYTtxqIItFOCXr/714TILD 3fw3RRp4WJW4+JMtT9SODtGTCpUm+MWvVkB5HLQ= X-Received: by 2002:a17:902:ec8a:b0:1c4:660d:3d19 with SMTP id x10-20020a170902ec8a00b001c4660d3d19mr8821185plg.26.1695366715474; Fri, 22 Sep 2023 00:11:55 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ji12-20020a170903324c00b001c44489ee55sm2713253plb.273.2023.09.22.00.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:11:54 -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 v4 1/8] net: wget: prevent overwriting reserved memory Date: Fri, 22 Sep 2023 16:11:12 +0900 Message-Id: <20230922071119.1439482-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 Reviewed-by: Simon Glass Acked-by: Ilias Apalodimas --- 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 Fri Sep 22 07:11:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725217 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp875909wrm; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYAcRTuF2md/qjFTVuOoy0P+0EDk0bbH39EQ+FNQIU95ZD6kWlxPBGcVoAodxHRMDp+Fxt X-Received: by 2002:adf:e710:0:b0:31f:e19e:a2c with SMTP id c16-20020adfe710000000b0031fe19e0a2cmr6615952wrm.32.1695366735183; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366735; cv=none; d=google.com; s=arc-20160816; b=z2In8q7wfC6hilYKV3rUi7igGyEKB0XK6LHWQF9078RQqnSGcZzM6iasMYo+vEKHRO bn48yeraU8we/DPRCaCAoZpt3MUb2O9OyB+A9JY1eBNET0FlQf5d+TdKz1HY37lnhZyk JzuRe/s9pJXg3WJE1z2IhYapU7WzrAH6ul3Ivs2x5LgDwg5jmZ+9awM/q4UcFYr+eSks FQTb79fhrurt6VCv234jhPpZ/CJq2uxU8zhARsS6rkKe7MKjWysUNECWKNY3momB4bC5 mlTYM/eB16M5atbjNR13vWR5PIX5GlgziohOCMhqfuscKB3BlMIro4esbjsTIOgPOJA3 1Jsg== 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=ontwmu1bQVmRNHAh9MZs2APgZVMpvSF6k0yf2AYHqWHmNVSlhpyFim99XpSL431Acm yoHrbX4CNsa+vZHGOu+xpHaLHwQFyGTSaS0nvQ1bI5hQasdDJmEk+KjUNf5nFL9RPBom Qpe7ALAEG3wiiQTlwWTqI5X8O3nwNonaCkYKK8S/OUROk/obXQ6PfUk5pyjqapAqfmU4 gtH5l3iwVolPOkoIBpAmij2fMeBLhSFR83S5T18JP5YizDU4PFBNucHf0KIR3vlfnCwa Or+2gZN2bE0pt3vYtH2RNDeQagg+OxoAlDMgdXC9N9Ywq0LjyZhHJyuqlvNLAbNDwqA0 qHNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VeX6Gd4s; 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 h10-20020adff18a000000b0031c80449ca5si1526232wro.895.2023.09.22.00.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:15 -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=VeX6Gd4s; 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 D17198667B; Fri, 22 Sep 2023 09:12:05 +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="VeX6Gd4s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BCE686290; Fri, 22 Sep 2023 09:12:04 +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-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 3BFA68667B for ; Fri, 22 Sep 2023 09:12:02 +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-x1032.google.com with SMTP id 98e67ed59e1d1-27499bb759cso1265185a91.3 for ; Fri, 22 Sep 2023 00:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366720; x=1695971520; 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; b=VeX6Gd4sOBuZWt1hkrIcL+9apfO/B6Dq9PEp17bKw6yh444y/SeYIdzTTR1NSO8fby WcDBsrlQhto8U5evDcJ5adygr/9YWne3Y8soPHOjOg7NbXxilQ5V++uGjji1tzPkikJ+ StKdtI4zhE8f3wTt+9jTX0X6ptjMzCRS463QulGc+wTK6F8HGenmax7HcvthrHU4A+wS J/KF5sHblE/DvM5KfIapSxfIeOGndX/vNqRZ6ieyFrhcRjGX/YGHfjPtPldNGIjNHfBo FRztdingdtt1FJ0DNPyq0KQYG/t2igfVTtx5L4j5B+zt6I/s7nIWcUQwD7CgzPv/PrJ5 DNCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366720; x=1695971520; 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=KGdSB+1Sc+3rE1pD5ZrEOwcyiOX7+KHT5RdxLZLHyek=; b=t69MqgVgJm9q4lNQsSrCEogS/Z8s9Y9t4lggUL/INsr6uQlk2R4XRHWH1vQtEoqNW4 XPfu57uaWGAz4iWq3bKnNaOpaJtOr6m0yAox9s4zKqhGLYwPWJQGtOXhn/CJB/4vP2/T MPa1byOxi3jasxOY31AOg2TS9D2fo0yPNxXQCgw9j1f7dlDQQV/i8J+Iff8GpxWinXp7 99C3mGNQkUF3Aj6gmDlUbeliRqQMTajry0/BEJksb8Y69iJ9uqa0tBc185yzhhzb8jzz gTAzES0Ml6sxmcn4qttj9Hpg1cG+q+SFdctK0Jg7A7q3bQG7ibfWTqLXAHwPEr7BLbFh SDDg== X-Gm-Message-State: AOJu0YyFLKu9t3T0vZRuuEurs2gO9lBVffMRTTyHaKfWRngRNNb/+Uof 1OY9nVWBnv+6iRjVz7JrObES9q/hwFAUWwP/qME= X-Received: by 2002:a17:90a:b78e:b0:26d:3d86:9a8e with SMTP id m14-20020a17090ab78e00b0026d3d869a8emr8032816pjr.25.1695366720408; Fri, 22 Sep 2023 00:12:00 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 6-20020a17090a194600b002684b837d88sm2812464pjh.14.2023.09.22.00.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:11:59 -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 v4 2/8] net: wget: add wget with dns utility function Date: Fri, 22 Sep 2023 16:11:13 +0900 Message-Id: <20230922071119.1439482-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 --- 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 Fri Sep 22 07:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725218 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp875964wrm; Fri, 22 Sep 2023 00:12:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtE4fR3wmzaJyEMLSjhs30AFXginpPz+b0TnJC2sYL0+xAxiyRxV6YHaLo/Iza4q1YefHj X-Received: by 2002:adf:ec4b:0:b0:319:735f:92c5 with SMTP id w11-20020adfec4b000000b00319735f92c5mr1314671wrn.32.1695366745257; Fri, 22 Sep 2023 00:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366745; cv=none; d=google.com; s=arc-20160816; b=CYbawp2e2iEvj5FRjhlMwjBhHO+pboiEUys78FL6jBB5T6L3l92DHfVQyo59fxmtwJ N9vOku99cIfoVoYyMwozwQ88S4VzO6HCphoUmlaawCzW477aObH4PXwrcO1o9O0xyC0P isfMgBdmjDnJ1BPzfrybkTKXXHYNgZTQCNkujsWVHtsELtS7jvZduc9WiM6lPwxNmUrk tBADq2suttGXzWKZx5HeE+29VLDePCIHfFKQ7YgVt0YKOiQW9Z/QSCdLe+K6cxr72laA NIsWZiCVJ24JTldCl5RRqH7QlNiZGFDldieOS6vJJKNPOFzpdQPpaOu3dA0Is4cqHEMr WGUA== 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; fh=/7JtEi60Oc1He789ODhlJpQcggvkyewSA9z0FHm3qP4=; b=awrWlUgM0/a1zd9C1TQh17A4SZKvP4zmuafcJqAYmuRRA63vH0KmVhipSBax8IDqPA WLRCJhVvMbFGzYo4TKogaFEpBlwWBcDj8I8QEbfVOt6df2bKwqHT9245HrzCqUC6LsaC Oq027NvGqwhndxMeJrR672uFsj6gzzvd6m3nqrgR2UJ6dqI8nIliEzJ8g979owH+OaF8 SgeIUknGdhJr3oJZkTHHi2iHDBIGusp1+Mj4se2/yNTzEiMDOjxNo8idniG556WrzOGe 12FuZvEgJzgCvt7vWRM1jg01CqyHKhLSTr/qab/POSFr3XH4sXFfTkxQOGFqueWmYBbk S0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UZCY8ITf; 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 l9-20020adffe89000000b0031b60f6a160si1513512wrr.815.2023.09.22.00.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:25 -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=UZCY8ITf; 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 345AF869AC; Fri, 22 Sep 2023 09:12:11 +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="UZCY8ITf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3BC0886996; Fri, 22 Sep 2023 09:12:10 +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-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 075C286575 for ; Fri, 22 Sep 2023 09:12:08 +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-x434.google.com with SMTP id d2e1a72fcca58-690bd59322dso1413111b3a.3 for ; Fri, 22 Sep 2023 00:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366726; x=1695971526; 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; b=UZCY8ITful9RbXSA0SGy2cjY2wRBAz9ouicc29z5rxjp93+XPat0Lir93Ss/VNt0Zu aA3nfBNGx1181vQBHyglUiQKmj4kvhV8iWq4cvLETuJ8LYNycDjpdRTOono1opFv5WS4 Rf9YC5VcqsiiePdPZdfMx51yxB3+VjwEJeJkTbc24tTGpPQ1CPSr4t7YnQ7QD0Bkwjhz xMxOXUEGEQXKO17QE/ARbPZNuZKUFtR/AHEJY9LHsg7GvJ6qFfufivoLyGnpjDcf9fEX O41TuOy4Thx/AivgOpd+15aNprf99RHqhPvE3sIfVuhKwxQo4MhoAxqal0AmOhnEFmAP sNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366726; x=1695971526; 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; b=FX+3i4yjrEq7zMTY0RzLcIUFv3NzgEa5KrYwNCDVHcQjbwb0BoWRe0GMamTo5HYdox SrawDqvEP79ZgXrbIzWVam6FdEQC58IrtGAzHk7pDLz/cj/AQ+buHDDUewhFPr1jZbhk Bwq0HgNDTdTBlrlug8hgX3hDxOO+nEZDNELJLWNCFOCyJ9XW+SF/kVVfCCn9qnWZmVph TLcqZ4UMIjA+uwhV6+8g0onq/B6KOY6UPFj/sL2BfPKqjMoVfHeGFgaIXBfm2SiI4Zec HVZF7tre51cKzxzHXtYLU1UlDsjwOoAtZrV76sh1ro8xsJI2+yJgubyn9rltLawfv9Gr 8BvA== X-Gm-Message-State: AOJu0YwS/jb2ahyCbhdKmqq8qfm99fvsUmOiQRB7Ht65tiY8fk6x8V5P KJPhHr6b2mJYt+0v5TKVJGMXPNe20u1cC5sH3eQ= X-Received: by 2002:a05:6a21:66c5:b0:15d:c86d:27a6 with SMTP id ze5-20020a056a2166c500b0015dc86d27a6mr640509pzb.55.1695366726104; Fri, 22 Sep 2023 00:12:06 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id s10-20020aa78d4a000000b0068fc9025a08sm2510759pfe.151.2023.09.22.00.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:05 -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 v4 3/8] blk: blkmap: add ramdisk creation utility function Date: Fri, 22 Sep 2023 16:11:14 +0900 Message-Id: <20230922071119.1439482-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 Fri Sep 22 07:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725219 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp876015wrm; Fri, 22 Sep 2023 00:12:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxCvMLb10C8PRrxhd8fGIQ49F2MvMnGdZNSdBmsdjgIy88oJS7SvXet98NxAV1svrQ1Rv8 X-Received: by 2002:adf:e481:0:b0:31f:fa1a:83fb with SMTP id i1-20020adfe481000000b0031ffa1a83fbmr7343676wrm.7.1695366756093; Fri, 22 Sep 2023 00:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366756; cv=none; d=google.com; s=arc-20160816; b=Vke7UhtZ+h6v0mLvKCaCS8+b0evzMsWiNJcJubODwxtwWTAjU+kHepIgIKq1vT5iV1 opcrQkC8IYpJ1tVFSAU5FspEFTuWoakR70gXzWITJPjMDrHApzG6anGI1zLba4JaGZrh ixoUmkpKfy749urrW9Y007S9FrgiRbNBMU0y24T1/roMkrPgvRHERHF/iZfZQhcYnywn XNxafW4qMqyIQ/9kNN8TzXg+8Em0GLL+sl8fkpMJjBamee1PiwC2UXjzLyb+xSGUACgi MjnEZOFG/6vP1zOYPyGgUGNFRGvgtCTU+6Vmvw6Y3c+s+DDQcAVt2nXSWdh+Uqh8O88q SmSQ== 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=hjKdPATu9rX5NFaVLvYNi6a4qNIIeFp4lub4c0M/xVE=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=hwSWoOKxTI5JaiIV9F9iIjRLhK4ucTeJ3SayWaBqfpKsTWALOlkEfnoyG2e7udakZH X93DL+q5PUriNliYMPLYzAj2oQ2CacZPcpd1JPGNi+wBSVvQw2sU8aD0tFWF0+0W+t+d hfFW9D4c4i7sSO9wCwQfILlCM+Rh66Qgm12Jal+FRo++5G5OFnsSr1YA2QVqyho5ShW5 ymjOI0/TU24uE5T1Jqi+YENhfVfKcdYns/qHEI2OrCxg0k8J/1CAVmXJh67qJTnShMpT Q1FkDVYLewiE+QSy4AJIcOtJSh3HuuwJgmdFeizNBV245n3qogHcWJ89rk+sl6nIZcar PAVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jvsf+01F; 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 h4-20020a5d6e04000000b0032168adfe1esi1536758wrz.124.2023.09.22.00.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:36 -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=Jvsf+01F; 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 8779A86575; Fri, 22 Sep 2023 09:12:16 +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="Jvsf+01F"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A54986290; Fri, 22 Sep 2023 09:12:15 +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 B8E8F86575 for ; Fri, 22 Sep 2023 09:12:12 +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-690d9cda925so1632324b3a.3 for ; Fri, 22 Sep 2023 00:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366731; x=1695971531; 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=hjKdPATu9rX5NFaVLvYNi6a4qNIIeFp4lub4c0M/xVE=; b=Jvsf+01FfNCGaaDnmF9k93m4r42MBrHAXHXMgpvbweFv/k/H5HoFALWsesMbZH5ri/ 7ItFLDkYO0fiqDoPAjgoHPRsRy3Y8jN6Z2QzD/3saMLNp60WgneFt23Ar1n87anxhOsr Fsn2levnrdumHgmNJTa8zRektinPl/fToL5mfE5kvnZvlhAy4j62w3GPdXbQ+EiXoZWa lwcbn1+HG6BIwl9XAB9r1/rvuwJl82nrxsiJmK6dPyorxtJhbK7eDat7a5f6opqpl34g EHmYEVsf+ya86+JvKb2dIjGn189tcAiVOU0pS6ysmJZ4EEMGmlRpq/qUyf5pSLU4tVxS nzuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366731; x=1695971531; 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=hjKdPATu9rX5NFaVLvYNi6a4qNIIeFp4lub4c0M/xVE=; b=sf8/gybcCngRaGhhj4Z/IlOyvPjk1GulvMqLBk2gUJHcuDiKOBVeuWPd6z97sjBHM7 vFbXbISwPGu+d6up1RSOHimFPiaW0h1MXW10KVKafXtOgJx+hsoFDV5q6MQOcAS3f0d1 JmQAt6MZvzaQ7NZaacGjOnrqGGu39VX3lzX6pJFnymlNG85xY5XoVc4Q1eIohlvxguj+ FV8lniZo56IgMZn17OEz99qY11l8hv9doQ8aepv+HcNaG8uhBfq9VhIP9hUwAvUddu6G EAS0z/aNZqjxX7YF+bJ8eb2Ei+tOBMc7FKqpNvzlr88Bf08mDSUmWutukcG48NFG8kXH RMYA== X-Gm-Message-State: AOJu0YwfW6UhGBxPZ8igF3WdEMchCCv1dY16qwp4pGzBrxCobt8Fwt71 517A5zG5JXIgeJKCZo+ZLozEQYRzROzafpcGW3w= X-Received: by 2002:a05:6a00:1990:b0:68e:3def:c3cd with SMTP id d16-20020a056a00199000b0068e3defc3cdmr7796328pfl.17.1695366730867; Fri, 22 Sep 2023 00:12:10 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id do17-20020a056a004a1100b00692b0d413c8sm267414pfb.197.2023.09.22.00.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:10 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 4/8] efi_loader: support boot from URI device path Date: Fri, 22 Sep 2023 16:11:15 +0900 Message-Id: <20230922071119.1439482-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 | 189 +++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..605be5041e 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,182 @@ 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); + } 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 * @@ -211,6 +391,15 @@ 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 { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, From patchwork Fri Sep 22 07:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725220 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp876065wrm; Fri, 22 Sep 2023 00:12:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDZ5ZgNK9/FzSefCGDs/NAdcp00JqjYK8c4/hfiAl6T0bliyBGXRJUMS/Mb9wRiMRN4DLU X-Received: by 2002:a05:6000:104:b0:317:55c:4936 with SMTP id o4-20020a056000010400b00317055c4936mr7627172wrx.9.1695366766616; Fri, 22 Sep 2023 00:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366766; cv=none; d=google.com; s=arc-20160816; b=lkZ0bKiyP+DppEICavlhQQfqoqXs127WgA1aWQgSdhaYX7TSB/6eY4ty5sOXPS5UFE bqhqyp1qwRL8TlLrrbsYESwFd3TfLVgT5EZ4CLviWMC1zaSlMndvY+8VHiva3bdQ9AKv D1i7hLR6+NnqcnOsRHQ2iW8mrxkqaEH9T+qBC0Oilg99XAMD2gxlDKdI69OGAbKdcZS2 EODP7rByfudcQ6I05dgboHZEGIw1VVwwmvmbwMU0YiSkbF4RaxC9ZUpnsgiARps/cOLh PWdccZmQFf29AsVvKAqUIkI9spBg329usomWyAEY0FZuzSJpux4CmqGuZXBUnCJ3cyeg /CDg== 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=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=SFddoC/uPulMV4dBSGkg7gfVqun2XnrxyZTgku7LDnKGmRYcPN3Gu5zmRtMdi350tK g78vH494DBL9Kg024iylTNR0Je95LQh6ec1Cdfvd9jIEdFiqtHmF0veILKOHpZNx0t6C +V6YxQfeECrYjgrUdWKCnJGfb6nET7SJAcZ2ZkXE722/eG6oqpks98IcGHdNsimH2pwx pX+2DKraorDmZAHpje9fkZcsIVksiAvVFuSYrWwcFXpUD0eR2TeodFUZeHD3RlGIjxsx hQZZPZITIl+vFuwF+qBZ+f0kgLRt6ps8w7TER0tezHppQAvU47qGUoullix1s7Oj+S7C cK7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W6rG8e/S"; 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 m4-20020adfe944000000b003216f1c589bsi1603510wrn.781.2023.09.22.00.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:46 -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="W6rG8e/S"; 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 DBD9086A24; Fri, 22 Sep 2023 09:12:20 +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="W6rG8e/S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9537686925; Fri, 22 Sep 2023 09:12:19 +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-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) (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 833FE869F6 for ; Fri, 22 Sep 2023 09:12:17 +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-oo1-xc2a.google.com with SMTP id 006d021491bc7-57354433a7dso917802eaf.1 for ; Fri, 22 Sep 2023 00:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366735; x=1695971535; 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=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; b=W6rG8e/SIt1X1G3qFhVJk3UBXscu5WGoUz+7BUPUUK0twqneqGN7QVsyz+FleEJq4b R+P0athFnVVZsuLhIg0GTPjQm9dLPTpdEdw9H/5MIIXpEcbl40qBnAiY6OSnkBFSO8tX 7AkBSljjlgribwo07WCn+pvebgPctyxep3KNtjH5U2kREQShMfDvEsANvDXAKo+fGNwM oIpzkmzCTDw5pfBxjPKqSP4o42DiRvxoFRpGPF6IDdrkzljbOGkbi1TJQ5yx+KqSlOGm 4R4hwv8ycaKjWlByc41fuBhcUhharQxhgGtrMaBNVYRbyB38mh28/Z2DBRwZsmB5bJLj ogHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366735; x=1695971535; 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=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; b=cY5gdHJR56uXoMQzvCRF6WYXn5Qt4Pz1y7xAVMfsmGBI1BM0t/tNqzlUn6ePQhdcYd 4g2nZ0tkQzCqIiecQZnPhI/tlEq0r7I9CLhHXJLjHdcxwHAKyo7u/L/4aVo5aKs7CY9N Id4e74RbLfL0kYZGYYZSuHNGdJ7OIHaS+iA3mj6+F+z154opqhD1WfKyqQOcuzOj17Bt E6CiIWELGvvPoS2WZmZyyMGLeNmgr3jy1OWh0tt8bkOVclDhRurk1xS/ukE0U+bc39Et F6Cgpzd12KtZMJGG9I+cu80QalNF5issoGYk0HDWg3trVwFIIGNYdFPjGP+169ufBOm+ QoXw== X-Gm-Message-State: AOJu0Yx0Ty6GadT5UI0IeEDv/iO/IobIdKrqkPcwgNmvv6M8h0ktUFJH QViZdPrXLAIoILPr8o0Z+VPWU9kOWocxLqY/FPM= X-Received: by 2002:a05:6870:b4a5:b0:1db:f7f8:ab56 with SMTP id y37-20020a056870b4a500b001dbf7f8ab56mr8335522oap.53.1695366735619; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id t63-20020a638142000000b0055c178a8df1sm2435858pgd.94.2023.09.22.00.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:14 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 5/8] efi_loader: set EFI HTTP Boot download buffer as reserved Date: Fri, 22 Sep 2023 16:11:16 +0900 Message-Id: <20230922071119.1439482-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 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 | 5 +++++ lib/efi_loader/efi_dt_fixup.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) 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 605be5041e..4991056946 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -326,6 +326,11 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, 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; 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 Fri Sep 22 07:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725221 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp876132wrm; Fri, 22 Sep 2023 00:12:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElSQWukMCD1ZvZIpoHx2QmUd3oz7WB3+6BHlCKyRhkqh6BhBn9cZByinjTAf8P6n02PM6w X-Received: by 2002:a5d:604a:0:b0:31f:ebb5:cd51 with SMTP id j10-20020a5d604a000000b0031febb5cd51mr1215817wrt.33.1695366778346; Fri, 22 Sep 2023 00:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366778; cv=none; d=google.com; s=arc-20160816; b=jyDtD236ilzOuJ5fBBBLsIFaZEUczaaTnKBZPVXCb5VxpeeGNlTMl4nVf3aGaihF3f ZfgFkVCjvVyccvxAISWf2EbAJ4ZScfIcQmWP0Dg0Ji3UlMh52+M5SvMq85dT1MEqSghB gU6eTUkVXpW5ZHh33sl91+GnqJ9C2JuvlY3ULEIKOGrpVXBrlZ3QsVVWBFtEv/syMjWP Xlzd2UajYuiO2lLVNWB45FDt95r3TD+EMAqPWZuvzoXS5D+Qwnqsqf+metaQlydFV6Vc 6URpSLk0tV+ygjx9VcB9oo6RnAmX1/HLAX/HJnRDUuqEco49MjKHYVTEJbp9ZX53MDLU WoVg== 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=CxORb6sAK9YGHrJRPc4/EGoVavmPUJ7pQ6Tyv5AzWilzI2KH4ULuflMlYHo62cQXrP 3Qy8sELHOAaRuEPWy33suC2skQgSaY1dq+nVkaQPWkURDmBbsUHaG9iWQTkG8mXo62W2 89vY3UpKHf7vDOGD4fEDmaxG40oGCplGPFPwPd9LIfX3qDAwkKT9h+vaM221+4CN0Q4B HvqxilRWnj6330+WiYYcDL3LNKJ+SRgdEzI0g9xdHg8c4zMLTla+keG/IhYhlAAzDjTs 1K5cCPHzsdSW+uUZWWmwy262+bIMkjpwOe/ncl/wBi61HQLFXEeLPReC1/qsNytkQAAj ha8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZkhDLqMc; 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 p13-20020adfce0d000000b00319771ae26esi1502677wrn.871.2023.09.22.00.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:58 -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=ZkhDLqMc; 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 3ABD286925; Fri, 22 Sep 2023 09:12: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=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="ZkhDLqMc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D9DE886290; Fri, 22 Sep 2023 09:12:25 +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-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (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 A124886996 for ; Fri, 22 Sep 2023 09:12:23 +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-x435.google.com with SMTP id d2e1a72fcca58-690bccb0d8aso1462480b3a.0 for ; Fri, 22 Sep 2023 00:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366742; x=1695971542; 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=ZkhDLqMcK4w9S1BiGKge44xVGqpnWODV/tmEQ9WaWUpid7rvA8UW/kiABpxZ3CTviT fInoQU9EW3SafTALO6/MjaeqzP0Es8do2DC8bsN763bUqk8DzlxhXpopqmzPTP3mtXkM YytdFPPTUFzhMGWpXnSYcGf6iLPGHAG0RUSL4TsyrYv63CObtm1TMl1ZOqDlo9QNBgAe aanDueUwJ94PM1ghDWccuSm6yod7grhtQbUEWa59UQRjFjhJM9t+9GOrn8c0RZnCMc2F I8WT3OYhuHOucegbmJEPLxdo1GbXxnssXkHTV8nq8bqiSFKHYQ2lZ6pS/HQxbK9x3cuX rMTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366742; x=1695971542; 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=PHHy8KV7eHprYy0VE4bvPY4LlhSjRhHeRqOFhTWTnPH6grICvpX4Y/LvVsbvtpCGSt WUYeNpodYFsrKL3imUGxEx4YZG8EwLCI9Hdk47t3WVwt8uKrghW64kPKAetJSQHh6aRq NhKsRzcaVgUEHfWkgF45JAmQVU1viInTqjItAvopEiQZvELHRZkdTFg/xGAVwWl7zUEQ qVTt1GkB75EiB3gPruPRALVjrjTK3bzlfr3HEDKR2VQDA+0J+UHxsZzIYxZHgbOW3Pwo Jqk/cTkzb+KFGR9qOhrChx+b7Cv9pfVMVc8jyh9qAhha+SZ20eUXU1ocX94iRH45t3uY os3Q== X-Gm-Message-State: AOJu0YzvtzFT3WlaXU9LpbvQnGDr0FwIAPdL7lpceAdeUOFoVuJeEGnv qpU06wWPnr7douPDQUhE2E0YqOaU4k4gy+mh1x4= X-Received: by 2002:a05:6a20:1585:b0:13e:9dba:ea52 with SMTP id h5-20020a056a20158500b0013e9dbaea52mr9141686pzj.13.1695366741750; Fri, 22 Sep 2023 00:12:21 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 17-20020a17090a001100b00276a58e37c1sm4545333pja.38.2023.09.22.00.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:21 -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 v4 6/8] cmd: efidebug: add uri device path Date: Fri, 22 Sep 2023 16:11:17 +0900 Message-Id: <20230922071119.1439482-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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