From patchwork Fri Sep 15 10:16:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723104 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285510wro; Fri, 15 Sep 2023 03:17:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7khArdAj+il1E0BW5QnVNcf3r7n0BC9rt3y5Z1/kNfDPlS3fYVrCjIMWKErWoPbqNa/uR X-Received: by 2002:adf:e807:0:b0:314:3e77:f210 with SMTP id o7-20020adfe807000000b003143e77f210mr1236282wrm.59.1694773061165; Fri, 15 Sep 2023 03:17:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773061; cv=none; d=google.com; s=arc-20160816; b=ljE5lXhssSoZAkqQNZ8OU/EVClfwVp4g9Jaoccgdcf3cfpyHgQ/cGgYBNyY+7p10aP rwuRXpoYP+DErrSBkokHirGQOIpbnySq5gCbnL2wgosNTjVEbmkExm87uScBpO7KIu4x /wNoZRVZHqgMyaKKKj2yXPJrrWHk5iIE3JNJzWrdkeWj1AW4FQL798Eu6NdtIfiVly53 UZrLVJ8djWYk2CPF9WhGHQeLDjiDr9/DsN5qxki523AQdDHdJA0M0lMvXfmRltfamrXj bGgywfpk51iM/yQ2nbxUCRhlgU7XFY76NN2wyaauhcy9HdQvuu/5Fo8dRTu+lnmYf/ip UPKA== 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=uXypzoBjnA7EBhpmHWSKfXof0kGA/ra0Hb3wmn7+bGs=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=MEF7UE07n686kVMdfz1V1B579kcvYxeM7RMXdvtoIh+dA1G5Vi1KkwN3sT/7LTur1F UMliBZ8+NpmeEqQOu8LacAEfP5YKWQTC0PgwL7qc8ZBrWw7ZlUl6OBhMiRJeZwJhrd4q hB5QR/ZXRnj4ALhWIOeYuM5uwtSdXvHRnUJMnWwL9YP9wwarlLjhZIOJkLskU/5YN250 JToKuB6JLtq1VVPuNAwfftR0ZcKkF5zgb2ui4aRwn+Y1vw9CFolHcpWklSDAtLBj8nOV QU2Qyv21kR29gYsb3hjCwqnh4QCm4EpU8HrSB5uUqs8kLy+JUjE5+rhv62V8Om6ggeiu tWeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zJS77mR1; 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 o4-20020a5d4744000000b0031facb6dcf0si1453458wrs.1042.2023.09.15.03.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:41 -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=zJS77mR1; 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 9DD7286529; Fri, 15 Sep 2023 12:17:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="zJS77mR1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F3B38654B; Fri, 15 Sep 2023 12:17:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 CEB2286503 for ; Fri, 15 Sep 2023 12:17:33 +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-x631.google.com with SMTP id d9443c01a7336-1bd9b4f8e0eso15357235ad.1 for ; Fri, 15 Sep 2023 03:17:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773052; x=1695377852; 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=uXypzoBjnA7EBhpmHWSKfXof0kGA/ra0Hb3wmn7+bGs=; b=zJS77mR1ruMIrDdzH2qijfQUY8WhHYYCs0xTlkhb/Igv2nj29m3kXFtmNkqgYOdhsy m1lu3E33dnElPnF6BmCpT+uqat5K1A4L0eNMLNZv4UExYXH3lHpX3Zih4No09cbdjPAx bkQIlNnHAxjH3aZaTiMYYPh0APzSIfyYv9KW2VsRc4oJvXYVy7NblcNzjm5TQEcOsx8P jTXHDgJo84Zb0RWZ9DVfsXY72hnr52Uq7I2Jmdxh5h1VuU+H24fFNCv727tOPj51wnba v2Wj+CCU928v9pAn40ovTRywz4o+tIbtAZ5KCb4ef1REEllUH4+Ql7KRnwQ+p6cWM7HM LO6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773052; x=1695377852; 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=uXypzoBjnA7EBhpmHWSKfXof0kGA/ra0Hb3wmn7+bGs=; b=gQmW6AEc3ZEtC0Y/bHKjqL7Ohc1a8zlAHVzs3cNzPpslwALBDtOQrwdNnp74mSBGJF bpQlwD2anvfqdZpzTPv1foGtxM9P2sjSaESONEKDvdJY0KchhF7SmTbFcmt8WIr5h6Ax iKApPm1V9VChUuv6rJNSxdnP+3gw9kqV/ESG3jxEHk3Sf8Ts4K5q55JPoITTVZne143+ I7AJbWb0J+h/fCn7CwdEwKd0jB9eSM/9M94Q43Z+b9O8u6mLgK4ssy9xf3vdpf7VugkV 4HJnqUXLAja3BtSTZphAUL2nC4lITsa85cpHBwvA4qAEwyOh9CwvanAJdc6PgncWpvu1 fRVw== X-Gm-Message-State: AOJu0Yzp7N62mt+JQUHnMNenB0YIBFjwtdAKVbH4VFKfLJaB2yefkXBr ucGXUEpgxtswZjSkOQGpfFAPS/i69XUNsJIU5Ig= X-Received: by 2002:a17:902:9303:b0:1c3:a1a8:969a with SMTP id bc3-20020a170902930300b001c3a1a8969amr1133987plb.8.1694773051832; Fri, 15 Sep 2023 03:17:31 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 12-20020a170902ee4c00b001bf5c12e9fesm3119761plo.125.2023.09.15.03.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:31 -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 v3 1/7] net: wget: prevent overwriting reserved memory Date: Fri, 15 Sep 2023 19:16:34 +0900 Message-Id: <20230915101640.1166332-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-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 --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 2dbfeb1a1d..9690e4539c 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) { + puts("\nwget error: "); + puts("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 15 10:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723105 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285587wro; Fri, 15 Sep 2023 03:17:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPQGUaJtvfes7odDQxtY5Be8woiSc/TppRezMFGjV4dCzRuEfDSFGnQmn+aFTH3ppAcyp0 X-Received: by 2002:a05:600c:2990:b0:400:ce4f:f184 with SMTP id r16-20020a05600c299000b00400ce4ff184mr1174964wmd.41.1694773070967; Fri, 15 Sep 2023 03:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773070; cv=none; d=google.com; s=arc-20160816; b=NqhSt1frUR0Ho/K2w8jwGhtBFOYkILtwQiy4VtO/ugWrLqW8zBbFBG9lr8aAhHOdFT MqcQFrkN8u3ROa6esb712ImGXjGKpnMui5YGcENuz09MOOcvgy+kee6mLnSmuH2Iwewo vbRNZDkuow172cjEtYBq6jtkAFZb7bye8I4mlv1ZxuMBesd/sWdTuZxgptHp1PHnNmco ycp5+hM7loW0BoNRsg/5L51BDG3txA4cLSs5+nWYcYMNtjFakML6vlM/4xeQN7umryVl 0AnSw1pjWH2dvkLpu5PkQljvMzeaqeXa52mevOfs/QqM1ENyh8hqPWvmndFW7xSYkErw HThw== 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=aqWSkntABQtwEoqV+tvayCqBU8eJJ8/peN3qcF7tSvA=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=Q4uTuZdozTJ1UNCmv3YM7AOecZhQOV6+0ZV9DFZ6p9Fg6KPQDj1BJbEl21MzyE0tQ4 L5wRK8wWac38LSrkMl2joquJ+ZXIaDSon3QNnFJKTwIedqpITfvbBFpLV3z0j0o8TP4w artzaDIXEeDXJHnTZKEQKSvLZ9elRxXaQ66LXewN1jUkqyyhFfJPU4NDdZStKAx+X0TL OEh60rIj5fN+bfbh0JeeW92QAONb+HsBPyJmBVLq38F8qpcGJ5xW4LoT2f0w3uzTDfbu HXNYQSjyLqN1o00JlQ/dwCEvmzcSDvqpJxnlt8qzG1gFne/akVlPW1LkUaTyoCaN+OGy S/mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=miTb7dqo; 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 x18-20020a05600c2d1200b00401fbd5c6besi3056672wmf.167.2023.09.15.03.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:50 -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=miTb7dqo; 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 ED1328653C; Fri, 15 Sep 2023 12:17:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="miTb7dqo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8A32D86503; Fri, 15 Sep 2023 12:17:42 +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-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 66FBE864D9 for ; Fri, 15 Sep 2023 12:17:40 +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-x634.google.com with SMTP id d9443c01a7336-1c35ee3b0d2so15555115ad.2 for ; Fri, 15 Sep 2023 03:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773058; x=1695377858; 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=aqWSkntABQtwEoqV+tvayCqBU8eJJ8/peN3qcF7tSvA=; b=miTb7dqojtJJvKHfK3trstXWymAb/U0J1r8+1zRhbRZtoslvOev/gMRoFfYnSe3xWL eeTF6sJMWNsNaHnz0ETOSBJkR1KbFHGamHdjMcUEE4bOzH3XuWmgEHVHtbrGEfmSOxz8 EYA1hbxJ07LnxY2vYNe2WJVs1UciMrn3hhFNKCGkFbeV95IIc3d/JdIwjdVcFJzXZO3p bgrfbS8eoVMrKP+s7fc47hLBZq4ZKP4fmmjFEMXBkyzwL3P1fRnCXdebgy11nYl/UeL0 b7FYdgJTxrUZBSl6KYunIwzNhnlrSpAPTdoFG9pCXSVAB2/nWTO4X8vw48pA1pNHtUiH Rqqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773058; x=1695377858; 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=aqWSkntABQtwEoqV+tvayCqBU8eJJ8/peN3qcF7tSvA=; b=OTMR0kcylTDKSTFaIXbU6Za0OZZF6h8iWM/z0edcq1gvquQrLUW9sZ0qspO9D2K8vF DPdqkwDqIDQsXZ8IWRIpJFong+GqmK9gaPpJUIAb+0PaHGzk7/k8zgBbsYJft3cLgUqK A9VAuPtHT2QUXLN0oWWv8i58bYu0YzkuuG6ANJoaK0gYM6ZODZgmds72HZUdtxc/w1aD yIEiHkaV8pSQdo8Ub2W44Z2u34n3S3Rh4+r45qqyCO907K4Oo5J8OMOr0W0hmhohRb/7 tiQMwy6fwPDYy9fHcOTMa8yb5ud94PymyvmNT+ip5w/eJtHjBLQNvmz/1aIKtE2/KXOr osPg== X-Gm-Message-State: AOJu0YyOEOdgpEdUteaK0N5/C0wsdzfqBqAwzxhJ8T4kaUrVc+ReDN9P uHD5CvjruTwJZJFjEhl+n0suhpa1bvl4eyRuugs= X-Received: by 2002:a17:90a:fd84:b0:268:ac99:4bb4 with SMTP id cx4-20020a17090afd8400b00268ac994bb4mr916646pjb.46.1694773058424; Fri, 15 Sep 2023 03:17:38 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id t14-20020a17090ae50e00b002676e961261sm4630920pjy.1.2023.09.15.03.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:37 -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 v3 2/7] net: wget: add wget with dns utility function Date: Fri, 15 Sep 2023 19:16:35 +0900 Message-Id: <20230915101640.1166332-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima --- include/net.h | 2 ++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..b9cba5244a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,6 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 9690e4539c..bdf940a315 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 15 10:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723106 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285675wro; Fri, 15 Sep 2023 03:18:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4akdk86urIY2oONuNW2eeC8b48rPrvXhNQ1DnFLIxvJgNHmV2U9oKFPJkVreH0RCtE9N7 X-Received: by 2002:a05:600c:ad7:b0:402:f555:6523 with SMTP id c23-20020a05600c0ad700b00402f5556523mr1160358wmr.9.1694773082158; Fri, 15 Sep 2023 03:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773082; cv=none; d=google.com; s=arc-20160816; b=pqaj+rRQ08E0m4eBLwNYMIzu4lCGANUpsG7xgYXWgGWRo3c2uPB8lufMLx0EvoQ452 huwBr3//fiHPLfGB2ZbEdpLJMIiHfG5FWFoxS9ArkZdb06tHij5ZEEzqBgFpje2hLaBz D3v78KLrHtwUQb/CuLtqAhmhakiJVonUGK+7Y+EjUkD8VaH5aJ8nk6dKvYPE8+f2OO5+ VsPUG3nrXtwqf8rsCDjrof0Kl+PMqQdHHmgOl+mvPByGFvahSnWuAyqIC5lth7BziPGG Z2f3NFy26QF2ZkRGGkknNWoUx91RFDgYpbDzhfXyApHxV9jNXddZ8E+9Y8bSrkkDH1dc Ej6g== 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=P1EnxlLiNcgyu57fvLTomagdxD5bSPdfR73tgF5Mw/9k/sh0TDU59O4tGCaXArc3Ug N7O/vGhLoU78KLtZw/4WmJbpdqBtzCoN73mGd7DBqzTLuY6bLF75PRPPx0fxDmeARrTH 2FPKiXHNS4L7zJ6iQs3eW7zP1XjEyWeu7DFNBoj4McwCXjvYoQwFJFfh7zT3DoiEWES8 Vec0/x+ypVngHk/tWTRmLTm2jIk4Fn+FGiYiNCQOAGWGeP2zkHyEYJEn8cl22WPzlSgI qGvqezBiq/ue+onGpcOyjPrXdDandBno0HumrYNBuNjRq3aLqrlblJN6qM/tEJj7+LLN nHXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l5gYUm3p; 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 fc7-20020a05600c524700b003fc063645c5si3100206wmb.8.2023.09.15.03.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:02 -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=l5gYUm3p; 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 50A2686177; Fri, 15 Sep 2023 12:17:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="l5gYUm3p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A1F1286590; Fri, 15 Sep 2023 12:17:49 +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-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 6C22186504 for ; Fri, 15 Sep 2023 12:17:47 +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-x632.google.com with SMTP id d9443c01a7336-1c43fe0c0bfso1437905ad.1 for ; Fri, 15 Sep 2023 03:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773065; x=1695377865; 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=l5gYUm3pNvX4JAP/KcWobIPsjK+lkWavkeirrR2fWwKeWLOZz7wXXWx1OaSNtmBJfi WqldexLQ3oR1kp/PNzDOccdKQQL3vd2ytAWLjQMLSvRTmz98HXOh15ElAbeH8CmpZz1E VEaX/OPHu7yS1bSZiA/Ty/KIc0GjWdpjomWSEw2noUi2HG33FMEBGtrWkr8lBBGbXUZM YguBgI5xtK4AaZ6PciXlsMfiqn9xxGSjW7uhoN1bNB4Q0kUVr3dFtmpvH7dPaTGKJrAi FNyhk/EqB+OI6JzOPYWJzPpxWJ3d4c9WBhCGPcClqi0sJh9w6v0jSuZ6YdGRkgcn00FF Sj8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773065; x=1695377865; 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=wj5OFmmZDwjN9yqKNupEhwqU2G2J0pfFK89FTQfzjVVgDZfTNmJNssg0IXlLH3+6b/ KalMhmBGBMLV/dpZREAanNZ8Oh0tucAqUMRuli8APNsMiYdma7juBzLOinE2/xN0wNjX g0DrN/ghUqmCQEDopNpF1Mq1VgqB00rsChKXRAzOy95KKE5V3dmZ7P+XCHoTbSQD+NuI b8Yq4Utn0irz8GPWRQNlgdc6jIBJletSRkNrivi8E6+cuudFcXBAe9mvFBpWKQC3G7FP ynW645+Yd4ZQO4jJq/r2CBOGkpQGLVlt59BIkOHqWQpjZoTSHy//X3EMmiklxykP5Xd7 vZkw== X-Gm-Message-State: AOJu0YysrhoOoPlXA1B6A7QSbbZ1SNIhBr7HaEIPa7OccEi4HLdBAfyM dBpXOL67zY1MIzFtjvDH99rddGvKhN4tpR+R8ww= X-Received: by 2002:a17:903:2310:b0:1af:aafb:64c8 with SMTP id d16-20020a170903231000b001afaafb64c8mr1383788plh.21.1694773065635; Fri, 15 Sep 2023 03:17:45 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h5-20020a170902748500b001a5fccab02dsm3148345pll.177.2023.09.15.03.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:43 -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 v3 3/7] blk: blkmap: add ramdisk creation utility function Date: Fri, 15 Sep 2023 19:16:36 +0900 Message-Id: <20230915101640.1166332-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean User needs to call several functions to create the ramdisk with blkmap. This adds the utility function to create blkmap device and mount the ramdisk. Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass --- drivers/block/Makefile | 1 + drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..c3ccfc03e5 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -15,6 +15,7 @@ endif obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o obj-$(CONFIG_BLKMAP) += blkmap.o +obj-$(CONFIG_BLKMAP) += blkmap_helper.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 2bb0acc20f..4e95997f61 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Fri Sep 15 10:16:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723107 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285772wro; Fri, 15 Sep 2023 03:18:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3dx/XGNW4sza39dUoSLuQ1jc4x8Yynn9RcuGfbCsZ380PzAz4poYmosX56EoHyvc8U69n X-Received: by 2002:a5d:6104:0:b0:319:6c90:5274 with SMTP id v4-20020a5d6104000000b003196c905274mr962614wrt.30.1694773092851; Fri, 15 Sep 2023 03:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773092; cv=none; d=google.com; s=arc-20160816; b=NOVKSvUo9UkNcQpFUzJ55iJ4qXYwQFVXZfqQyTQgGZQatLDYp38GQmWI0XclkF6BKl ckATqkSKVczlo2WfDJgLrMcoP95ofV1neuM/86wxzA15FI7PJhtukfQe5uNT/hZ5CigF +etTp79UXXFOzjbNskNGhFEpFPYRLQ9KIUgNRVfB3DTbDzKeChlVIoySukJ0RtA6HQoG JyhU7zizZE9Q6CGbG46agv8m+D/hB5f/bCsH6C4G4uqf++mNokcg/i7A03uDGXYWGYkL XfrKcIe3rUaU4F24NqJxZWifPRzSBTqfyBiJ749iTyEnEyDLWS17/1GR9ZoxNojidAfP AXVg== 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=HV+tFrMvW8Ei1g+Ssw5SNJ8BmFh88MCoelRWsO/P5H0=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=xXUVShPn2CQESQdbgjCexldI2mv4QM49mVoW9m3RAZ03FdQfX4VseKML0ym7n4en7/ T9XgbndhuqpGduPQ0m+igKgQ/RCI3oSmdALl06T2TRVeMcchiQkrXb6wEGbIKuB1HU80 f1QH3KDqIYPj6xIaTKgRCOrUNzNI8xAzs0gmu9lQYwgGjakpnUoHwHMYtRFgzcNwURUU KXIpmeug+mdTBOasUkOEDo7OPb7fwPjKWlOMzoqaT7U8kjNGCGr+leJDixTWtbh17WkJ dPv+0EnEnco2gjgW5CA/wACVHfCXdtrLQnr6ei+RjHOect9LneAletgdYGbR0q8PuxWH OOLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iiJMad3l; 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 o17-20020a5d58d1000000b0031fe55b5e8esi1258853wrf.425.2023.09.15.03.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:12 -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=iiJMad3l; 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 A4416868D7; Fri, 15 Sep 2023 12:17: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=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="iiJMad3l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 233E7868D7; Fri, 15 Sep 2023 12:17:56 +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-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 D14E8868BC for ; Fri, 15 Sep 2023 12:17:53 +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-x42f.google.com with SMTP id d2e1a72fcca58-68fb5bd8f02so1879093b3a.0 for ; Fri, 15 Sep 2023 03:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773072; x=1695377872; 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=HV+tFrMvW8Ei1g+Ssw5SNJ8BmFh88MCoelRWsO/P5H0=; b=iiJMad3lUmUm7+SMOkR1uIGeGTj4mT9PxboDVO8WdwDl5sr3B/zATMuT0mxJ70BkPv D55Ly99pwjM6yJzUzy0f30JQw1LyU76xHF3R04I0VY4RAIBDdUvOiAfNFYrQY5Rw7T7p iT+NTXYNwHAWZcj//UFrXp7YsoPjf1eXzxxPCjfVyY2cxqj6pEcd11u1u+VivLGYVgXw g4EvTABViDblP4lLqOTexxlL/CLmVSQBK0zt9yBNmg/9YCKZslx9gdTXYv+FvzByukZG RFt8zFMX4+EUrBTPczirBkDHgTadoy4fO6+lqFDBSJ5teKsSh/cKxXjK9+E5sNHrWWrE NHHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773072; x=1695377872; 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=HV+tFrMvW8Ei1g+Ssw5SNJ8BmFh88MCoelRWsO/P5H0=; b=W/09UbRBSSAiPR6BEKMm/HXlbpIc4rUoDmQ90V49Xn4D+yZ50m6HmFkw+aAZx+rdzW ue9xIwxccyoZrqSTqgR0croxPvPdhu4mYzmhTnrMFdnWzRU8m7z44McHiDuaAOT/hb/V smeoX9wGV4enggjkv3t1wS1FyRuX/sRJo1EYv9PPD8Kz+ONGRARlJM79dFMajAjCHWfU nNrvQzlZqCboPhxndS9iuyaZxwYwLE+NspV83CvGGk+iSLNJ6h2tbn4j/F/xhF6Yc9Rx 4kHPDLCioFTTYtdMNQIWUYGB9k34DGd5PKSpGJmSEO+75PCJvAdmr662gW8UDSDYk/x5 jj3w== X-Gm-Message-State: AOJu0Yy3PTF+T80spUnuiDjXm8AWL0YXwIMCbNR0TeVn1caGcqR+0/vN DtsgJkfu+6+QlS3F/JU5LybF9gpSaPyZ+qbbFPA= X-Received: by 2002:a05:6a00:24d2:b0:68f:d35d:2168 with SMTP id d18-20020a056a0024d200b0068fd35d2168mr1300008pfv.0.1694773071925; Fri, 15 Sep 2023 03:17:51 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id e23-20020a62aa17000000b0068fba4800cfsm2684917pff.56.2023.09.15.03.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:51 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v3 4/7] efi_loader: support boot from URI device path Date: Fri, 15 Sep 2023 19:16:37 +0900 Message-Id: <20230915101640.1166332-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-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..1a287ad89d 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 bm_handle; + struct efi_handler *handler; + struct efi_device_path *file_path; + struct efi_device_path *device_path; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&bm_handle)) { + log_warning("DM_TAG_EFI not found\n"); + return EFI_INVALID_PARAMETER; + } + + ret = efi_search_protocol(bm_handle, + &efi_simple_file_system_protocol_guid, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(bs->open_protocol(bm_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 15 10:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723108 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285837wro; Fri, 15 Sep 2023 03:18:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3famXtPa3qHuHYxl5StYf3GdGE1Uo55SZpICjyjlyVza2wTkO1MNiA241OjLEsK82X/KM X-Received: by 2002:a05:6000:5c7:b0:31f:f753:5897 with SMTP id bh7-20020a05600005c700b0031ff7535897mr1024635wrb.59.1694773103121; Fri, 15 Sep 2023 03:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773103; cv=none; d=google.com; s=arc-20160816; b=mrPy0DLTggsaxq6iF5HDONSnERp5N5z2cuXJw3Xwbea+0m+zM/3R9T+L8i8WKnq0gL 3OESiqzyBA3/Xcar9Szh3sfWT/PwNeDkrFevrUy6G935B5M73w0Te2U+93HJIreXZXUM iinaY2VxdkStq1vMAaKYS4f0QT43SHgTsj28Xh99HqDg9jR9MWLBm8bgxVj5lt/mK7P0 rniyC3GBUODLt+vncLTPv8Wm1FwIPFd24NEC6Lnrqg+ffbmEWdxQnBFdafuJIyL0xI2U aZDGhjs9P17mJipMeszFnQFtD8ZgH7U5/jSJTLtocjBbEedS/VFsCffRwQ1b2a/ZkMFz I0Kw== 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=eAEkTiJl9hL0/S8FWqxLeLTXC/UPPNW3XKd2IR52Ef9cYqLaAQQbVWgWN6ng/+MnXI yQgmU8TpxubLra00/c/e+g8K8GQgEaEDHTjVtPos+2iF2ZKp+PvakJKXM7Txp6FXQtIa 9/ZRM+ghJm8p7omRyNKa+oBl9FQrPipJjm/FmFS9BGkdgK7fcr8Jm8tcXznFd8YGgl6o /DmTHO+h2gY30gwESCRZebe+k60Lkvb6rK+ip7GIVLif7zHTIff/HtKR3QDFoAPMHSqW xlt+iDKzZNEylZb48+Glfa0lwq/RD+LthPyKsPQkdu/PUGcZycI6gfpAWtT5h1PVFgTC A9iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RFP5nsl2; 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 n3-20020a5d4003000000b0031970b91a5csi1466886wrp.962.2023.09.15.03.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:23 -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=RFP5nsl2; 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 0493B86828; Fri, 15 Sep 2023 12:18:03 +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="RFP5nsl2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A8A1868C0; Fri, 15 Sep 2023 12:18:01 +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 1699186504 for ; Fri, 15 Sep 2023 12:17:59 +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-68fdd5c1bbbso1451063b3a.1 for ; Fri, 15 Sep 2023 03:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773077; x=1695377877; 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; b=RFP5nsl2KMste4NccYa0A8KZUX9cxgG5oMrhcoB2htgganFbqa2An9KQfaOLjvTK1/ 48FzjKNPDqzYRYIhu+hSj3pMdr+8COCdt72G4Z5LMhIjWp6PC1hm19d+3n9WBXtItkJK TNX3SVik1VVZ2I/D0xmypQ7sDR09XufPymLjPit3vnGhNAFoYwhkhE75AWrlfC9RSEGR jP8UGZmcDWZWy8Ii8PcqGUp8kng/j0QSPr4S2tQQlao3lJAhSQl+XES+8pHXKR6F+cfr sd9cnupO8I2kJbL48STTSpq+HnDrGiJR1RoBBm/jhngjPKtRNX0YMeSFPEKxdbolB+CK q1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773077; x=1695377877; 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; b=C0dobyeEPgvILxIA1vkx+kTkA0y11rQkn6c8BtnB8BMB/gbB9QLRNfv7PMehTMk5MB jgo7PdQpBQDbdMnSbegnDyIXAQcmKeOoeae3PRjq0OeonNlFc1yuL+R3visSAzU2/i5h zb0msar4RpSLmsjwOcNsuNBW6JHwkg/Cc6dn6Fz3LvU1L1U8FGjvYmry1p68h4gC+zI+ 4NQpRUYEEGDWM7OwGKLZ7d8HFjXBJkrBgT1U2pB/E5Xbs9NPEGIAGDDv1g9LDDfuXxNZ vv+PnGmjogtKpr/zvWUdoJXBMqCPEQzWqz7zm0LufdrsV/Umy/W4VoWwSLr+t0SIeP0A lVjg== X-Gm-Message-State: AOJu0YzzBS8QGjxR0QdO/Wkllg5ziChbRQvbgutsBIvQHVzMA5cpaT3F 7/B7DqePoPSCUP5MiCchVsEhN6RUXqKKYT872T8= X-Received: by 2002:a05:6a00:2d9d:b0:68a:6018:a66f with SMTP id fb29-20020a056a002d9d00b0068a6018a66fmr1620054pfb.2.1694773077264; Fri, 15 Sep 2023 03:17:57 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id g7-20020aa78187000000b0066a31111cc5sm2695732pfi.152.2023.09.15.03.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:56 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v3 5/7] efi_loader: set EFI HTTP Boot download buffer as reserved Date: Fri, 15 Sep 2023 19:16:38 +0900 Message-Id: <20230915101640.1166332-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-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 1a287ad89d..d26c607815 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 15 10:16:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723109 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285896wro; Fri, 15 Sep 2023 03:18:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSJExaP8fJIZ9p0jtBSAZnUbdwafcqDVUF3RnoyT9VJe24e/X13qFuwTYvllCZyrsFRxT2 X-Received: by 2002:a5d:4b07:0:b0:31f:e89f:b3fe with SMTP id v7-20020a5d4b07000000b0031fe89fb3femr1053637wrq.1.1694773112809; Fri, 15 Sep 2023 03:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773112; cv=none; d=google.com; s=arc-20160816; b=HDFfePbPr4SDLAeus1zOO5LKwU9+u30Bjm9L2ZspE4HFf2t6CqM1BCBwn/abv3Z5Xn gUbV1kOtf1Nvl7VghRgku9FXVS7oK9GHuDB0ZlFrqCOm6aO0MpGucbL8qaYX0B4AfNSx eviXXtj7J5DbFzA3lJK9BR8eWGUwbecnG0EouKl9ANwWzHbuN80V46ZY418yL6SvaPXn zOzZkiCyetmN/FNZe8Ar/ymj0lWfoHSasvlX7bUHWpeAxQHqy+I2lRY7J83c7fjxuxmz SKMLHQ/CKioUIQvMlTyGFesyTM/IRzJXQY34U2ew5yg3JyZSEn684FLJDDYq27bBlDoH N9zA== 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=2LWiqwehaOJfaSmRgwHlzxULDaEEZ5775jRQ1ZEyTgk=; fh=O5Tcc7OxYmMQkVi+jNNm3q1qDsnUZdKiJar3RqhYUSs=; b=RP9ARJ4bLrKBD18yH3p0Mmh+c22s0z+//kAHraja8Au+UnlNDbvitjImbNUuhwkEI9 sOfi5dKUGlF1S7eyyXBCLNESmHWgTzCejfxJtJx6pZihaqLl0nzJVwa7xRZFkYSvegRq vgNRu57V+EGC9OjQde/cQ0NpTipB0pZ+3ANol6heSc5rEE+3frtBjKXqS2G2AZBnoh0F 7F2L3g1G7Ml6NXVQiOsnQVsgD4xt9NL1+yKfstZd1oazvnjJ3sPMetGh0cmpJ8+Ge/+x SgRgyf9tnpZgsxbGEBCARZp7NevMwVaMPqd7ZnC6wxQ/nd1whawT794BU7tAkW3m9Q1t GmGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eNJP4UWF; 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 t5-20020a5d49c5000000b0031ff8c394f3si176659wrs.522.2023.09.15.03.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:32 -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=eNJP4UWF; 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 53EF386900; Fri, 15 Sep 2023 12:18: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=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="eNJP4UWF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 99DD586900; Fri, 15 Sep 2023 12:18:07 +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-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (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 73E9886906 for ; Fri, 15 Sep 2023 12:18: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=masahisa.kojima@linaro.org Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3ab3aceaf2aso1168524b6e.2 for ; Fri, 15 Sep 2023 03:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773083; x=1695377883; 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=2LWiqwehaOJfaSmRgwHlzxULDaEEZ5775jRQ1ZEyTgk=; b=eNJP4UWFg3MAd/bdMq19PDu5HrjTqepyaXI8JiCeesInuUrCHCqtpPvqM8axt1DASl IHyZP/2KK7LywvtS/qwXW6X192Tg/DHkBULXtqEM1tkr95WaMqikVvRCLoH6j7rqQ7LD ERwwUR9TkZpsywn9TsYBlM9HF3g01BLHWFLVoumGoGQz5LuBzHtTA63JKiztjPWMLTgO 0Fes0FIL1c36MSjfphWDaAE8VPgKXm+3rWanS1BH5s4xbDHmZUL94mK9f9kJQtrJzSFd E+ufZ3slxD0/DPfCO2ifKvMJke9zRF02cwmUZkf+wx/N8qQw4QcWpfS85gmANNuEUxWM nBFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773083; x=1695377883; 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=2LWiqwehaOJfaSmRgwHlzxULDaEEZ5775jRQ1ZEyTgk=; b=BiM7aDteQRYYDDGMRQ1/VQtOWY9wKrKj6guCEwgOcISO/N2wGQh0+1gjxoywEftrV5 sdB28GqxDXQOSKfSAyBpWfkWt27oRY/lhTYTz+Kiug7Iv8lUVWkZ5WvXZ5E6VC3QuTDA Rh7RqghJ9I0sgLyLS5t7PuHbbDodft5OmzhXyZkj5rJM2+lGtSaa1bVjniSS7RcCZDVc Nk1VZvatqLfasNUhHg3SG6vYpoGY8bdRgxBu4NP28T5KwUEB3rQi6hcJQzy+xoyiyjRA Phzw95sBrJKpqqxBB7rqT77t0e5fluhKcTwDit8Nv8lO8BR8TMuHWa2PVFviWz/O0a/J /Ucw== X-Gm-Message-State: AOJu0Yz+eBZxUyK3XXM3n3tXQiS7f/QYYzwXQ08ahFF8c8K9qRlADzyg OpbQzHMSo8G/Tp9Cmk/HNrxa/kNxbO4DBclSyH0= X-Received: by 2002:a05:6808:242:b0:3a8:43c6:3cf with SMTP id m2-20020a056808024200b003a843c603cfmr1064408oie.57.1694773083579; Fri, 15 Sep 2023 03:18:03 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id i16-20020aa78b50000000b0068883728c16sm2782583pfd.144.2023.09.15.03.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:02 -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 v3 6/7] cmd: efidebug: add uri device path Date: Fri, 15 Sep 2023 19:16:39 +0900 Message-Id: <20230915101640.1166332-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-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 | 1 + net/wget.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 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