From patchwork Wed Oct 25 06:28: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: 737805 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131095wrq; Tue, 24 Oct 2023 23:30:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTeb+LQfscIPk3Ql04V7wLc2q3hbhiGSAL74LQJqa7ae6RmoXJAyxbMfxqzUt+t1XqBPqr X-Received: by 2002:a2e:84d0:0:b0:2c5:1d11:5691 with SMTP id q16-20020a2e84d0000000b002c51d115691mr9820729ljh.28.1698215432730; Tue, 24 Oct 2023 23:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215432; cv=none; d=google.com; s=arc-20160816; b=Cka0AymrM9fJnihMy6o4OWAilxqiG6oQdILVKrgD90TQScgt5EUrhQvo0xtkNwJ3sk CEZBiRW7tBS17MlkOiHtfGlUnUVpfxG9BrsJDe03PHcvuqqDUNIETF6PUv3lK0nf97Xo RB5fSa3WRmlI9XgOExJvw8arucRr47c/NzqWR8tkE/7VX9IKtl7KAb98NeSzjDycbkLW FbAdpG9xncCZwEosTPU4USMMRr1vxTT4Ng5F84uI6iMuoty7jtawNWAaj0fbn5yCgZwQ 8mplslr0uDRiWuG9+ehQxL6RCTg+wR+PnAXZZJKBzIIP64kBURyc27oX7D5Yt5fg0qQK yigA== 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=AqNZNjqQYhADk2f9LcxrecaAQ0zvQd04y6QhLiDYaOs=; fh=eBItVz4B+jX5FuRNHVjUaldxTsf8xOQKLrDTtjpPbrk=; b=kqq1aj/4uisOupPNJou5/F3iARg1f5lmvy6RgBTNxzBhzR/1pbF9jUZDApaMWIJXi6 t5LofKVihPyxkkl2peAbdak8AOXk2iEQvThaBUyF6tttEEXLjslpNS0FBvMT0d+LbWOB KuIWFW/oAlDKUVaOtlO7KgSlAYYqwJkf5s3KDn1S9yfTjXd5IPWBOfWSy2C/NNVB/aHP BhI7QaRZ0ZeA/0ILU3mpEYuWP/HtOLCTBUv9sMyokpYmQgUe7zwZQuM8KJExUn7/ahPw ObydSLFimswDQpEnQy8qr3LbHwICXwMzMHjyI3SM3c+VoA9O1X8bb3GF2OsV3u+G+7L9 nocw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U98tgawJ; 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 l15-20020adfe9cf000000b0032db6a28de5si6628765wrn.755.2023.10.24.23.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:32 -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=U98tgawJ; 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 8462887A41; Wed, 25 Oct 2023 08:30: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=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="U98tgawJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 648C087A45; Wed, 25 Oct 2023 08:30: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-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) (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 B091A879E0 for ; Wed, 25 Oct 2023 08:30:10 +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-x630.google.com with SMTP id d9443c01a7336-1ca74e77aecso4047835ad.1 for ; Tue, 24 Oct 2023 23:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215406; x=1698820206; 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=AqNZNjqQYhADk2f9LcxrecaAQ0zvQd04y6QhLiDYaOs=; b=U98tgawJvKlvw1Bmh4766lJPhERlTER8NOs/DcLEx02/o6dNXzZ369kwpOTZ5UKlxC bYzEXnX70JWofKd9TvDBOxvZOXEySQqgHgtWZy2a+dSX5l+8ok/4GE2DbdajXdjflSKe EMuS8WvFBVSljz9tSiJQrER3x3rLb0E0KHDE/Dvnn1QF56/m1V70G2PnQvcKfPnvTNbj ngvtx8KFpjcl7ZYD3qK0N6wPSlhzdvzw8P51pWAoPrRm6mejRyUmvziHG1fYZbhZiNRo CqqsuqaCvNOl42TGhGWqWu5/DacNntY6xRunKAg9RLgn3bGuLiK7tMuBKnCdxfSczyKS JcRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215406; x=1698820206; 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=AqNZNjqQYhADk2f9LcxrecaAQ0zvQd04y6QhLiDYaOs=; b=W9uTT7ldByDrk5PNlQKKJzH7yfT3fp1MQEwV1aD1IwMj4C9NYT5ZoFb8tYISTUQRAm g6FOLH3azi1nQ+UUTyUSuxNahLoA/DAgrL8g8X8YwVWoqxnlZId6lq6SsJzr9Nz922Ju 5wbN6L0ppaDISLbM/h8nbX4BDlDxIzOx/DodLHrPe8mVhVfc4chutaZDqxLfJJs3vSi4 aqaYfd40dIusmZjUg/aey/6RR/6KJC3CxACN5EuCU2fqZCDY2HN24ZYpkWXP8N9GZwP3 VXE/Nw4/BG11e+Ij03gToiJEApEGZ04AVFUbcpPOUTu5A8h1dGnJU2haN2noBcfzYOY+ 47nw== X-Gm-Message-State: AOJu0Yyw541Xvbqa3N6pQGDsvDQGepeniojiGBwRz5M8evbb+vC1iO4F cbNdOvqkcNNCkhEz2zyemV5/mlyICty5kC8mB8E= X-Received: by 2002:a17:902:cecc:b0:1ca:7909:6eda with SMTP id d12-20020a170902cecc00b001ca79096edamr18073775plg.23.1698215405808; Tue, 24 Oct 2023 23:30:05 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id j12-20020a170902da8c00b001c61afa7009sm8406126plx.114.2023.10.24.23.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:05 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v8 1/7] net: wget: prevent overwriting reserved memory Date: Wed, 25 Oct 2023 15:28:39 +0900 Message-Id: <20231025062845.3100964-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This introduces the valid range check to store the received blocks using lmb. The same logic is implemented in tftp. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Ramon Fried --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 8bb4d72db1..6f97eb1d12 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"; @@ -56,6 +60,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 @@ -64,10 +91,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); @@ -248,25 +290,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; + } } } } @@ -338,6 +394,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; } @@ -428,6 +485,15 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (IS_ENABLED(CONFIG_LMB)) { + if (wget_init_load_size()) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + net_set_state(NETLOOP_FAIL); + return; + } + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Wed Oct 25 06:28:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737806 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131214wrq; Tue, 24 Oct 2023 23:30:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1RhbYEL7VUSlRpuqmKmYXreR1L1eOL2UczaF7eCJ0xha7XEvwYM15RJwBStLg/QvN5WBf X-Received: by 2002:a5d:62cd:0:b0:32d:9df1:6f6d with SMTP id o13-20020a5d62cd000000b0032d9df16f6dmr9562083wrv.17.1698215453048; Tue, 24 Oct 2023 23:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215453; cv=none; d=google.com; s=arc-20160816; b=X/1KIeCkgGEnJ6ntNGKnyIcYlJSietvoLjTG/wP61BqIRkclItsJ6rNOzArSZU9Hde HPwV/qmiPrl+0dp9MLXU4XYp1vlQ5s31tV1W7YPE14Ifg821KuZmKoG2xdRqhX3gX989 ilIt2JDJiZIWwIQTGzx1+PeKFETDz6ezvpd71zQ/bPxsn7tgtziMTugN1DpEvDC8tSQD g2fm5W+gOta7zV4zlnqGxUc+ZQ/u+2OIWEp81RXZYGZNG4ZESKd8d5Zx/C1dberWu/hb yeKgKbIRuqYeUcVQruTSReEbFutVFzoqhK94zEieBHxYALN7WPjGf+iQLttMwwEz7Ke0 rHNw== 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; fh=eBItVz4B+jX5FuRNHVjUaldxTsf8xOQKLrDTtjpPbrk=; b=dB5AjyyilBE04s1KFsx3O+o3BC9z97K5PjnVRA/iL7LXsPAGwSSTbP951T9NBDVo+Z O0pb94edIM21B6ReHfrTlohkBPXABQVMEQdCFAyPI57DzbVS+88m7FwknHByEgeq0oy9 rl7fR/oHYn0vSkGW4mUVJHFPzAbtJF/MvrE0M1WpndSa78q/6ebix4hglIOkOmdILCGC 4GmUvJtDCaGNWuBZzOXo2yYcqKOCSPwn/Vj1vzThyS2tjLGK601AlQ5pZozMwp1Usv0A qp4jJ1mudEMcFwCqJrYH0nf2pyHWMNJTxd4368eJinDsusDNXUTo8BbS5tc9s0WVJJCF 4xYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k1RTOuO9; 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 l2-20020adfe9c2000000b0032dda7a59efsi7008046wrn.709.2023.10.24.23.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:53 -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=k1RTOuO9; 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 DC41A87A59; Wed, 25 Oct 2023 08:30:22 +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="k1RTOuO9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67785879E0; Wed, 25 Oct 2023 08:30:16 +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-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 69CEB87A2A for ; Wed, 25 Oct 2023 08:30: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-pl1-x62e.google.com with SMTP id d9443c01a7336-1ca72f8ff3aso37805995ad.0 for ; Tue, 24 Oct 2023 23:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215411; x=1698820211; 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; b=k1RTOuO9E9PZBvSk4c/KkXi2bA0hrMvYj1nyNxVxhbqZyWT3Rgj0VEzx3dhlNrY3e+ +RQCi5sH2puymCcD4T2Qw+mclZO/76IgrS1eZwTk1NBOOjxXIOxF43Ec24yR7bUj+Erj d4KpH6x7eMA7xR2Yd9enfNlMPGFlgupHIglDk5K29RQF5vVBTeiOipnfIMpECnn8oRr0 6kFyK/Udz4g74U2Vz1UOSOkwVfhCOHqiNmbox8cOe0ucKhRWqvAFjFLyWS1Cv7r0eoPr WzsFQjde8j/zRsVl5Y7XBnK8ai1b131ONU+ojFXnQOINOy7kwjHyXqipBT2Ceh1gvPsw FHeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215411; x=1698820211; 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=LpkU9wk3gj829EVx8p2lHMNKkbubof1kR3KeYVvX1vo=; b=d6zdm1XI/oSCTlBr4wttho/oTf762tXNbZltRihOjUrbjBJKiHKyGfbbvQXMNtopzv lpDNTWKyc36xJh+mAptaCklIrNP4ALpuh8RiHHNlTyR9cPdOm2nAX/S8g+BhfWYgDZBq UfZ/5wTEjOTDBE8RUYK1sSVysUYkpTi6it725GLQuT7vYMG4zj5ziF/2rbtScLXbFEzI UAuG7a6OBOi17Cv5Z4lLFAvxMZSDR4Y1WoqZT4shM9vqHAeS+viFkFg8V4+byaMsLgVi LdJJUiKZdaEmVsbXz+o65HDhV5oEoiu534ehudk1RnY9IRI3PvXsuUhiqOvge7SJuqm+ QDnQ== X-Gm-Message-State: AOJu0Yy4dzW6RhRfqcxe996wZ7ClAHDRQN1iq5E71OGtSxOTLtfwkdaW LvPwVG7TNQEgW5d3wvufQgOwUyag0HXYfsftl3A= X-Received: by 2002:a17:903:4052:b0:1ca:cc28:b4f with SMTP id n18-20020a170903405200b001cacc280b4fmr8677027pla.54.1698215410852; Tue, 24 Oct 2023 23:30:10 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b15-20020a170902650f00b001c6187f2875sm8663888plk.225.2023.10.24.23.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:10 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v8 2/7] net: wget: add wget with dns utility function Date: Wed, 25 Oct 2023 15:28:40 +0900 Message-Id: <20231025062845.3100964-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Wed Oct 25 06:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737807 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131295wrq; Tue, 24 Oct 2023 23:31:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtY1CkgYvxR5EPk7X444+j+qDudo2uUTaF4/orGI9RGLvxkMFttRTODSc13WkR/HwmYEjk X-Received: by 2002:a2e:84d0:0:b0:2c5:1d11:5691 with SMTP id q16-20020a2e84d0000000b002c51d115691mr9821519ljh.28.1698215467378; Tue, 24 Oct 2023 23:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215467; cv=none; d=google.com; s=arc-20160816; b=TlypLD0QqCfYF/rPbSbHksF16VMCE8JAboCotA7b2q4TDCLBN4UkhopNN9yorRQKsD GFPfYzvv/1Wu+wQTEgKjKRQ6KHjqEtXnahcYrUeqbsRAF2Fzcy5Pt5cFd+cv8/5Oywfm w7a1xhpL7jZDPX/HGk41p9ZIfi6GIkLWzkN6rZSDmMHOjYb5347aE2spFVZ4B0Now6qi qvN04ZDqAgEf/XIJUtloxrhj40Omk5kNQnZJNnSgUByy95aVuH/pMZamFVt5u1TfskOv oGNVqtt36flsXE+Ad3354t0Ri6hsucCNbcqSoRINF/AnU8ztB3v/aphu4HJCC8qzrgrp parg== 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; fh=nGxKOXCACQSu1eN/ZPnZQwsIMUpKToCCLMDjTFnWWa4=; b=wWJDuS5EnbBiLGQDL39E3JiuWgRrcJzv1eGJMArF/4FU78VppP7p290sMBW/AiGCu/ pVYnzjNEBLRYraGL49RxyCa+LbNDG5C0yNVwnLDRGEt/jZdPaW4fAPqONsSRDl5Nqojl HAlcgAG9igFBFjIqlPlxwwsXkwmh+nyALKKmY0blfoCPqCSjgPSKuSfSh0ooEHPnOu8u AZIOjUcdpqsdpSFi6nvO5Q3xczqpOmEhIt+LDgiXbpQtu17qHXDHwV6duZKHKfJpVqml n6BL3sxY4l7O63IcS1cE47FLkvAhCAhJ8z6+yRNOSEJpJ34eSR3PKOCQxjeWkVJDAc5h jSgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQbyKWz+; 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 m17-20020adffe51000000b0032d9cf7ce73si6930513wrs.282.2023.10.24.23.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:31:07 -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=RQbyKWz+; 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 680BF87A50; Wed, 25 Oct 2023 08:30:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="RQbyKWz+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A6644879D8; Wed, 25 Oct 2023 08:30:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3695287A57 for ; Wed, 25 Oct 2023 08:30:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c434c33ec0so36145725ad.3 for ; Tue, 24 Oct 2023 23:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215416; x=1698820216; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=RQbyKWz++ESx+OI4DhD3FJEbw8MIFU+ts+VxHZ9MZygilyId+tQcQEqLMXWinvJuox xpL25GwTq5aUnjvYn1FO0Wrax+i1drqqOWZLjinOJXbLqWzMtFL5t6kuiiPXrW29TLMM BMPcBHE0K7qsa59kRSxDzry5EZuPxabQMVXsrN/rFY/V+fpPZnrWR6uaKP7E00YsJPYk Zmway+hGMKzYQT1qJhnVJGFM0T32cN9ak8oCsi8WNQR5eQ/yQ6GVzET0ZzHALsy5veU2 3lj6xX6DgnK6pQ64GofWjM64Lj4mle2KYNeCZOr5EabWDkhkZMbsAseddu0uqqXNsDF6 M7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215416; x=1698820216; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=J+BzURqnPqLIjS34tMicOWJg7giku/cVqdlCU04wu4pjI1NqUnKOC0SJnc8HfqAqOU dbAHCoh1R7CnlE7PXriEHpG3rmVcNO6so0dJF9AJuUkA3D9XnKbSC4yzNDCLOVfDzsna SbyRhyiTB+mc+yheqh0XK4KSD+ugFgtjNsGjhljmo3Kmuqh2/fD2+WDCdCzai+4KsZ7X MXaQ9U76ujuXVRcAxdw6JtRc8Ao4DttGw6vz8ufJZWNoapBGvdGoLWLLc1GIv8OFLkUL 4hYSaMA885Bdojop6QpoxJkUYKAtxg9YyLjwFs1EHIfk1mqeJupx/wFbnyRZpx6eQd8K LZVw== X-Gm-Message-State: AOJu0YyCWvcnc5CIH4Q7oIjdTtv1+HVs8YbJO5H1N6YytRS35qVZWANL 5c4GllICEXLeL7jkaompT5Foym8K0/IxqxSu+j8= X-Received: by 2002:a17:902:f944:b0:1bd:c7e2:462 with SMTP id kx4-20020a170902f94400b001bdc7e20462mr10399601plb.11.1698215416186; Tue, 24 Oct 2023 23:30:16 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jh1-20020a170903328100b001c5fc291ef9sm8408967plb.209.2023.10.24.23.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:15 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Tobias Waldekranz , Jaehoon Chung Subject: [PATCH v8 3/7] blk: blkmap: add ramdisk creation utility function Date: Wed, 25 Oct 2023 15:28:41 +0900 Message-Id: <20231025062845.3100964-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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 | 3 +- drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..ec0575d135 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_IDE) += ide.o 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_$(SPL_TPL_)BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)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 149a4cac3e..21201409ed 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Wed Oct 25 06:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737808 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131401wrq; Tue, 24 Oct 2023 23:31:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVKt50ZL6vpXamNwI0dMTnjFs33zfwOCF1QK9S/wQ75pyXaycXPPIJK/VQfGLLsXBP8Isy X-Received: by 2002:a05:600c:1d09:b0:405:9666:5242 with SMTP id l9-20020a05600c1d0900b0040596665242mr11635643wms.31.1698215481687; Tue, 24 Oct 2023 23:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215481; cv=none; d=google.com; s=arc-20160816; b=JauIMeOoU9Sc+31QvdALv9jb7KlJk/eN2u2npkDP2Dz+OCHn9c95FcmVtMKfC0GwmW VIsfhcY1LiqRn4VJfPAu00Sliv/HP15Uk/v+TkuBfhl0N/JbpRre8fo3Zx0Zr2P0GVPp NoV5RZcHFmoYyJOmbAalGrkauV7QJsuTWCpcrvzpY1nDXcPqxbmcPrujRPJzD9hGt0E5 DP7T6SWFeKiwccLKPh/GuE9V9EA2UkzSUA6eM7pePCghrNpdUlX8AHUty59fPUni+SOW NJSUcePWPFQqkk3GVex7Qk3+gMADoirEQP+q7sGq/b9ElunLoWXCENmKA/uyhl99h4ev LNzw== 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=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; fh=OwlxGVC9rLycV+uRQL8XB4l1CrABnLtF7cR6HzvdRxs=; b=tkX1cw567htPz0yhuwqBUzlpzvty5w9xCdOfdzJetqK1dsucMyXdOtU2GKMrawIRWJ HPu+uhHmA71c6dvC0Lm16WmUYTKLJY+EQLqUXacIgHZti0PSZwzp/Y9HBLTdZ42ya+zY H5BKMIU0ajovxYIQOaWo+p7rVHmSd2vufefPAfdLYA7xPeodvyklMqPoi3/9TU+1k69g UEoVv6aKrT5/dyeOpdg7OkKQNxIs58Y/L2vwU1kMICI18KUlSy6t1hE1hgKHJQMGP6Ft pgQg4hF2Co1PxMHoBE0vbEsQH27PH2rt/TvhLrK3aYMYWzprAY1qbA845HEzj0zbC24m 75Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OzKYiQLL; 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 bi23-20020a05600c3d9700b004053fe477d0si8047060wmb.76.2023.10.24.23.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:31:21 -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=OzKYiQLL; 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 00C1387A5B; Wed, 25 Oct 2023 08:30:36 +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="OzKYiQLL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3717686308; Wed, 25 Oct 2023 08:30:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (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 EAE5487A5B for ; Wed, 25 Oct 2023 08:30:22 +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-x636.google.com with SMTP id d9443c01a7336-1c9c5a1b87bso35451065ad.3 for ; Tue, 24 Oct 2023 23:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215421; x=1698820221; 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=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; b=OzKYiQLL6J3owT8uf204gIQsxVaAnCxAitrJ4zDxSWJlhY9Vx3HD3DMJ9FiOu6rmtU YtMHFIRnJATlz4R+f6Cbzpv8siWlw/RKbhj69+lnpeoLd0sY0G+rwJpc6ICMRbNX30IB 0lXJdNeksyB65eCeo40NN4/MQVn2L4cuqVTJZK2wlsH9BZ/UJAsWAdzMtg/lxT1ECpnt 30SmbsNKJ5wi/XqMGCnbsw+ueoB1Tz9nfxbGi8zFSI+zldA9tpCK4SA9aSA1YY6oJWtR Uvf3CeMYD8RFRRe7N57mFX9DRpHuUiQIqPqV0YZzqv0hlib6DjWxAG3W7+JomQHt5cLN 6urg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215421; x=1698820221; 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=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; b=WAFsDMgteM6xVJMUMORbDD6mR2GSaHZ1pOrOCN47xjeJL/i7W/aprbGCk3Jm65wKxt FFKfpcKOlP9WC1jo5bAkxozaAnA+0qAjkHGU3FmyO+5xbp8p/VOthtBpDU3QlSD+PF3L tTy5DxG8635VpHpt/jaZFf2+0SJbz9HYJ59q0RUixCO+2OGE6/RwXixrkyPYUu3hMfk4 WS3qxg0ycTlVOm/hzdJv7R4w7RoFY6Sln17h/brqWoQuvVvXI9nea3wLHSHi0jZVOAsv NcHIeGkWl4YCzzfleWijaDkajRrBYl94tc1SRCXOTRkbXq0CF8rDG587Iay2Qzy56AX3 /THQ== X-Gm-Message-State: AOJu0Yx9xJp+t8+qi8cGEyK70D7QqBAkUIJ7JZZyza7i/qIAab3GJVj7 wokvY81B7mbjjVebi6Q8D6xX+T1AW0lAeUp7T+I= X-Received: by 2002:a17:902:e5cb:b0:1c3:aa8d:4daa with SMTP id u11-20020a170902e5cb00b001c3aa8d4daamr14069501plf.44.1698215420963; Tue, 24 Oct 2023 23:30:20 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id t12-20020a170902a5cc00b001c74876f032sm8359895plq.162.2023.10.24.23.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:20 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Raymond Mao , Masahisa Kojima , Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal Subject: [PATCH v8 4/7] efi_loader: Boot var automatic management Date: Wed, 25 Oct 2023 15:28:42 +0900 Message-Id: <20231025062845.3100964-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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 From: Raymond Mao Changes for complying to EFI spec ยง3.5.1.1 'Removable Media Boot Behavior'. Boot variables can be automatically generated during a removable media is probed. At the same time, unused boot variables will be detected and removed. Please note that currently the function 'efi_disk_remove' has no ability to distinguish below two scenarios a) Unplugging of a removable media under U-Boot b) U-Boot exiting and booting an OS Thus currently the boot variables management is not added into 'efi_disk_remove' to avoid boot options being added/erased repeatedly under scenario b) during power cycles See TODO comments under function 'efi_disk_remove' for more details The original efi_secboot tests expect that BootOrder EFI variable is not defined. With this commit, the BootOrder EFI variable is automatically added when the disk is detected. The original efi_secboot tests end up with unexpected failure. The efi_secboot tests need to be modified to explicitly set the BootOrder EFI variable. squashfs ls test is also affected by this modification, need to clear the previous state before squashfs ls test starts. Co-developed-by: Masahisa Kojima Signed-off-by: Masahisa Kojima Signed-off-by: Raymond Mao Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas Reviewed-by: Joao Marcos Costa --- lib/efi_loader/efi_disk.c | 18 ++++++++ lib/efi_loader/efi_setup.c | 7 ++++ test/py/tests/test_efi_secboot/test_signed.py | 42 +++++++++---------- .../test_efi_secboot/test_signed_intca.py | 14 +++---- .../tests/test_efi_secboot/test_unsigned.py | 14 +++---- .../test_fs/test_squashfs/test_sqfs_ls.py | 6 +++ 6 files changed, 66 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index f0d76113b0..b808a7fe62 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -690,6 +690,13 @@ int efi_disk_probe(void *ctx, struct event *event) return -1; } + /* only do the boot option management when UEFI sub-system is initialized */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + return -1; + } + return 0; } @@ -742,6 +749,17 @@ int efi_disk_remove(void *ctx, struct event *event) dev_tag_del(dev, DM_TAG_EFI); return 0; + + /* + * TODO A flag to distinguish below 2 different scenarios of this + * function call is needed: + * a) Unplugging of a removable media under U-Boot + * b) U-Boot exiting and booting an OS + * In case of scenario a), efi_bootmgr_update_media_device_boot_option() + * needs to be invoked here to update the boot options and remove the + * unnecessary ones. + */ + } /** diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index ad719afd63..c02569cb6d 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -245,6 +245,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { + /* update boot option after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py index ca52e853d8..2f862a259a 100644 --- a/test/py/tests/test_efi_secboot/test_signed.py +++ b/test/py/tests/test_efi_secboot/test_signed.py @@ -29,7 +29,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -37,7 +37,7 @@ class TestEfiSignedImage(object): # Test Case 1b, run unsigned image if no PK output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -59,13 +59,13 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('\'HELLO1\' failed' in ''.join(output)) assert('efi_start_image() returned: 26' in ''.join(output)) output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -77,12 +77,12 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -105,7 +105,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -143,7 +143,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -170,7 +170,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -181,7 +181,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -193,7 +193,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -205,7 +205,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -230,7 +230,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -254,7 +254,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -265,7 +265,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -279,7 +279,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -307,7 +307,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -330,7 +330,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -349,7 +349,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld_forged.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('hELLO, world!' in ''.join(output)) @@ -364,7 +364,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert(not 'hELLO, world!' in ''.join(output)) assert('\'HELLO1\' failed' in ''.join(output)) diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py index d8d599d22f..8d9a5f3e7f 100644 --- a/test/py/tests/test_efi_secboot/test_signed_intca.py +++ b/test/py/tests/test_efi_secboot/test_signed_intca.py @@ -40,7 +40,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_a host 0:1 /helloworld.efi.signed_a -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_a\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -49,7 +49,7 @@ class TestEfiSignedImageIntca(object): # Test Case 1b, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO_ab host 0:1 /helloworld.efi.signed_ab -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -71,7 +71,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -81,7 +81,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_b.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -91,7 +91,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) # Or, @@ -129,7 +129,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py index df63f0df08..7c078f220d 100644 --- a/test/py/tests/test_efi_secboot/test_unsigned.py +++ b/test/py/tests/test_efi_secboot/test_unsigned.py @@ -36,11 +36,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -65,7 +65,7 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -89,11 +89,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -107,11 +107,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index 527a556ed8..3b8118104f 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -118,6 +118,12 @@ def test_sqfs_ls(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled, default file(e.g. EFI/BOOT/BOOTAA64.EFI) + # is scanned when the new disk is detected. This ends up with the unexpected + # output at the first 'sqfsls' command. + # Clear the previous state. + u_boot_console.restart_uboot() + # setup test environment check_mksquashfs_version() generate_sqfs_src_dir(build_dir) From patchwork Wed Oct 25 06:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737809 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131488wrq; Tue, 24 Oct 2023 23:31:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3kAESx3EAcDSm6u7AmPOtD4K8CElj1tGgqthFQmRqq0qdldEjnxs4QxSyUsVgvlVfU2lZ X-Received: by 2002:ac2:4430:0:b0:500:b7ed:105a with SMTP id w16-20020ac24430000000b00500b7ed105amr10545139lfl.29.1698215497557; Tue, 24 Oct 2023 23:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215497; cv=none; d=google.com; s=arc-20160816; b=W6l9vt0ltnrxOvh5fjl7U+SUH6C6Nwjps8nvctbc1TnPKx2EqyeicO6xB+9LwytlEG sG3Zx4MRPM3zqnIQ9pNzOEkbytv9FIoHQ1FEmrQrSHgnNzUS3p9++CrCJPrTwucf3PQB w/3AJYJav6w0Fx5+Q+Ku76wVyC+uZPd/Jl005O91N0tvS/c59WBD2gPKYItf7pPSwrG2 +ta4Obs/FFwJKVBkC24nnkSKG9fly1V4N/1m8c2etvNju/DLIymYXDYvCG9lRoFYqSvZ fNe3iKmHYvpNyvvKE/ANWRbUBci3zhof+6oiJR+TsseTBhBA7W8OHZy20VMEU4cy23re W/6Q== 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=jBcgl+WOthLVrHfHg9ym25N5aCfLNvMApEqH2Y5JpA8=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=OR4/5d8IRoFS2Pxr0nQvZIrU1cFTgZ/dFbdnuw7VYB8+yku2ESM09hP1QbjQssdPiW 6QH1H1Bkp3YU7MZ7UA4ravPtXJ2ClsTPnLUuCMSPq/pwJweIeMiKc+UptfBH6KMOrTCH Y6M8WXvvJTPJiS2lDuUik+AIu7j4hXeF8i6gmCi1iFv2feY/sGsDmQrxlXRHuJdmFQKB ylSj7lENYKTyoNszI7QKwzNs2h5i2t+T28FUNU2FR0p3A0tWvObLM5/hGcsMhnrH7I8E +ztqH+uu5diSZnltZSPwwsJ+xxeHAtDfRSzEOuaRWOQX6PDDcEo/dBYEpR9i9oWQv7c5 Oirg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MJ2I2ilM; 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 d11-20020a5d4f8b000000b0032da2c106c4si6772143wru.337.2023.10.24.23.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:31:37 -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=MJ2I2ilM; 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 4063387A58; Wed, 25 Oct 2023 08:30:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="MJ2I2ilM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 016B287A5E; Wed, 25 Oct 2023 08:30: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-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 43CF7879D8 for ; Wed, 25 Oct 2023 08:30:29 +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-6934202b8bdso5159819b3a.1 for ; Tue, 24 Oct 2023 23:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215425; x=1698820225; 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=jBcgl+WOthLVrHfHg9ym25N5aCfLNvMApEqH2Y5JpA8=; b=MJ2I2ilMOCfsuvhpKQMtVnZxHoe6mBG+XN8WjsmO+qNC3CqS1wkVRAnDy3KS/YN+jV oLFd4hgOnqbu19gpgGE4+iJwpKgKLi+I2czlFdR6eQ5dJj7/vSfSt0J7kAoSy+gjby0j eAJzZ4klmRYkdIjmjZTf7eHdEFqZV+pc+AgN4vz7wzFN4CK2bijTbxXtLiNfDRzN58U9 bl2hRVe1Te3dMCdgnB//h4QXJW9oBM2bHq8VRV+d27N06GkSUkUYI1bUhljgwU7/G5mc lXotdaRKSPjqBsIXiLQV/2bIqTY56YNe7gutkTe8ZqFKtqg9CHVtMpexEZ6brNcOR5o7 u0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215425; x=1698820225; 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=jBcgl+WOthLVrHfHg9ym25N5aCfLNvMApEqH2Y5JpA8=; b=nSHsSv2Wy9s17YXTw3GPwYSKtQxIp5Djl6iTgnOoYP5wfoA/GX7F1YuW1zXaHmcxRj gUcEhJJxJgYROLlnGDMFN2oBlF+FwJQgD4RoqDGuOto3+XB50Q5/PSGL70YMkBgBvrvL msmEIodoBr9R6FceK3LhRQ5c9XWNNhKiRB+fsWgzYJnn2+Ec972k3OkTS1uv87dxFGUu vdvPMn2jRDuOgrRimx0d4oCm5fjpdpU/ZVOj98ifhgOjArFRHoQBhal5wrGpXGY8p86N FalYTPmWRI8tKQmjd0oDDHgYugdg8ErgK1at8JGircdIIHqV+IjavQ+kPtUsFAiFFj9V nTSw== X-Gm-Message-State: AOJu0YzFplFQNQ4u1pXTx1WTeYT7YyX0RPJkD4V55olHWTGwwm/zUEJ9 VrT225PbzgEaeuXl7qrQttaxRkyqL6BbRbZNmhY= X-Received: by 2002:a05:6a20:4426:b0:16a:4f24:d30 with SMTP id ce38-20020a056a20442600b0016a4f240d30mr6439827pzb.53.1698215425565; Tue, 24 Oct 2023 23:30:25 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id v12-20020a63f20c000000b005b32d6b4f2fsm8080288pgh.81.2023.10.24.23.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:24 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v8 5/7] efi_loader: support boot from URI device path Date: Wed, 25 Oct 2023 15:28:43 +0900 Message-Id: <20231025062845.3100964-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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). Since boot option indicating the default file is automatically created when new disk is detected, system can boot by selecting the automatically created blkmap boot option. If the file is PE-COFF file, load and start the downloaded file. The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image and expose the ramdisk to the OS. For PE-COFF file case, this memory reservation is done in LoadImage Boot Service. Signed-off-by: Masahisa Kojima --- cmd/bootefi.c | 5 + include/efi_loader.h | 1 + lib/efi_loader/Kconfig | 9 ++ lib/efi_loader/efi_bootmgr.c | 229 +++++++++++++++++++++++++++++++++++ 4 files changed, 244 insertions(+) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 20e5c94a33..74203ec5b6 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -394,6 +394,11 @@ out: log_err("Failed to remove loadfile2 for initrd\n"); } + if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) { + if (efi_bootmgr_release_ramdisk() != EFI_SUCCESS) + log_err("Failed to remove ramdisk\n"); + } + /* Control is returned to U-Boot, disable EFI watchdog */ efi_set_watchdog(0); diff --git a/include/efi_loader.h b/include/efi_loader.h index e24410505f..2fea1f17fb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -937,6 +937,7 @@ efi_status_t efi_set_load_options(efi_handle_t handle, efi_uintn_t load_options_size, void *load_options); efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options); +efi_status_t efi_bootmgr_release_ramdisk(void); /** * struct efi_image_regions - A list of memory regions diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index d20aaab6db..5d99206dc3 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -479,4 +479,13 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_HTTP_BOOT + bool "EFI HTTP Boot support" + depends on CMD_DNS + depends on CMD_WGET + depends on BLKMAP + help + Enabling this option adds EFI HTTP Boot support. It allows to + directly boot from network. + endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..abe148bd80 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 @@ -19,6 +23,10 @@ static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; +static u32 image_size; +static ulong image_addr; +static struct udevice *ramdisk_blk_dev = NULL; + const efi_guid_t efi_guid_bootmenu_auto_generated = EFICONFIG_AUTO_GENERATED_ENTRY_GUID; @@ -168,6 +176,197 @@ out: return ret; } +/** + * mount_image() - mount the image with blkmap + * + * @lo_label: u16 label string of load option + * @addr: image address + * @size: image size + * Return: pointer to the UCLASS_BLK udevice, NULL if failed + */ +static struct udevice *mount_image(u16 *lo_label, ulong addr, int 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, addr, 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 err; + int uri_len; + efi_status_t ret; + + s = env_get("loadaddr"); + if (!s) { + log_err("Error: loadaddr is not set\n"); + return EFI_INVALID_PARAMETER; + } + image_addr = hextoul(s, NULL); + err = wget_with_dns(image_addr, uridp->uri); + if (err < 0) + return EFI_INVALID_PARAMETER; + image_size = env_get_hex("filesize", 0); + if (!image_size) + 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); + 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_LOAD_ERROR; + + ret = load_default_file_from_blk_dev(blk, handle); + if (ret != EFI_SUCCESS) + return ret; + + ramdisk_blk_dev = blk; + + /* + * TODO: expose the ramdisk to OS. + * Need to pass the ramdisk information by the architecture-specific + * methods such as 'pmem' device-tree node. + */ + ret = efi_add_memory_map(image_addr, image_size, + EFI_RESERVED_MEMORY_TYPE); + if (ret != EFI_SUCCESS) + efi_bootmgr_release_ramdisk(); + } 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; + + 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 ret; + + 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_UNSUPPORTED; + } + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +410,14 @@ 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_EFI_HTTP_BOOT)) + ret = try_load_from_uri_path( + (struct efi_device_path_uri *) + lo.file_path, + lo.label, handle); + else + ret = EFI_LOAD_ERROR; } else { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, @@ -345,6 +552,28 @@ error: return ret; } +/** + * efi_bootmgr_release_ramdisk() - release ramdisk resource + * + * Return: status code + */ +efi_status_t efi_bootmgr_release_ramdisk(void) +{ + efi_status_t ret = EFI_SUCCESS; + + if (ramdisk_blk_dev) { + ret = efi_add_memory_map(image_addr, image_size, + EFI_CONVENTIONAL_MEMORY); + + if (blkmap_destroy(ramdisk_blk_dev->parent)) + ret = EFI_DEVICE_ERROR; + + ramdisk_blk_dev = NULL; + } + + return ret; +} + /** * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media * From patchwork Wed Oct 25 06:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737810 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131563wrq; Tue, 24 Oct 2023 23:31:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8fA9PhNQ0VhanTM10M9KwOC4wIhqPgtThedYcUpxI+7GHF3+5o1oQYddimyPXX1P9Q9Px X-Received: by 2002:adf:fa4f:0:b0:319:67ac:4191 with SMTP id y15-20020adffa4f000000b0031967ac4191mr10872135wrr.37.1698215511652; Tue, 24 Oct 2023 23:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215511; cv=none; d=google.com; s=arc-20160816; b=hnxRNE4Qu1lBDWwjLw5Rq7pzbGFXrIIT9kuA5Ui+nbS6HjTLnZW8Oi5bTOpwPhXqnt hJW/rZt/cm4XIwKRmrOu+WAOQbYThdE81sZbvXNapxusVe4ApXJ4aZ4Sm/CtmTj0zMc6 ON+KjGKJWaEwvk9LzJPTMLUxH0tBouE6BNgOQ/ZYyhiwdE860pN2N3K7Ui/jaPxcOOLJ BR5JqDD+nCbt0z71TyY3iGoar4gaNuS86NFzDT8fvEMx7KNbRKFHpO93DL4w8p5ECeG7 fVoIdmW049lSQByxBa+kGhefsBXleSFok/XfaAt/IeBUfuhv4+M98UTLUSi3cfNJ1cvM d1tw== 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=v5TVLbar7J9pOoah1wLfcnqqWHtmagxHEMGlbcOsaKE=; fh=UwEaQaZSKscgV8VKorL4WxKMlykH7WzwOcMeBrHkxSs=; b=XX5yxnh+O0TyXcF70ukUWi7+TOh5ot6IQpi7IilA3wgyyQ8KaSBmAOz+S2COVDVLkt sWasyLaYzETeK0q8bnspO4hwMmPhUTxE5Q51uXoAPzXXx6fvDVK6ofvfpvgtDnhQxs4+ kGiatwXFh+ki8VkAJ6xjCdIEeQw/O9WO7ZfNDTGBzTJ5H1h+dYrerHHEWnLaPtrTF3/H gAEFCgc+zFNLiFGAY/q86pSHHti13+UB0HMLYhB60e1nYZ/McmwcCCC/h6UAzjFWGNuG bo3ricAXZNecdS/wCPNW+2YacB6tXEus50XhLC3BRwH8TEJxhFnvzKKceZ7SuKGGTL5o kFvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FZa2zhrW; 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 v4-20020a5d4b04000000b0032d9d0205d3si6959272wrq.579.2023.10.24.23.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:31:51 -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=FZa2zhrW; 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 412CB87A67; Wed, 25 Oct 2023 08:30:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="FZa2zhrW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E88D87A60; Wed, 25 Oct 2023 08:30:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 18C6587A58 for ; Wed, 25 Oct 2023 08:30:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c9d922c039so44948355ad.3 for ; Tue, 24 Oct 2023 23:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215429; x=1698820229; 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=v5TVLbar7J9pOoah1wLfcnqqWHtmagxHEMGlbcOsaKE=; b=FZa2zhrWxD7iaNfx+KnpN6UarsvlE/Z0RcZaR3HnA6YKvVPUEzZndTIWP5DrKdyYWY dw7Uw8rZtNcr1CqGsunlvF6IeiHbr0RVLVYlZXNOQNzDrZJTdPFfrNHTp4fiZ/vggOt9 3ASiUgu2Pez2xkGgzi2n86ICGFNGfnSb0fr0CdRVeJNjv8T0mDLvZq332+BUNCjqt/FH OJe/E7pe6Llt5heXQwveqsPvdZbZWdcQEoU/4zgEgROvAIODAH4aqjYzOYlcKUtQ9zHN eEimrQIXoA/j7mfjuptsEUU7c9ruwB2e2cHP2hE4FGe58rl2xnuYgspqRVMIyYHobTSD +kGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215429; x=1698820229; 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=v5TVLbar7J9pOoah1wLfcnqqWHtmagxHEMGlbcOsaKE=; b=LIVmkuE4Osy0q1hpLLAKYcV0Zi+gA2yb9dwZ7vVPaOPD4mPWiAQtzgGku0AxF4Zjsk XQilhjkaLFFjAXOYkgZPLgn9HT+2laoU6utOndvmxmcuLLP+IP5+q1Pss3XIEkgLisLG SNsFygMyADPR28Q2UuZPoAu8C4zbOV1K2/HjpboeeEyUdLQ40vtIF4hKsVrCffNAmquA zPoGDwiXRJLJU2QeWLsY3tg3OG/HcAcV65ceXYSThX4AdAgwx/tI6huCy2vcXUsBcrmm IczKvjRaneWSYbgDZqaxb1Zy6G6wauM/rHtK5J2+mKP96wTNSzHn6/t/z+C3L6N6E0+A tnvQ== X-Gm-Message-State: AOJu0YzyZRGoNRmWydr0G23DJTdYBXRnl3xXjGG0ZtvF5LvF4T+xMfVy jRh8RpbpJbd/qWzRE+EbQbJjF5H+YdstWbXeZF8= X-Received: by 2002:a17:902:d34b:b0:1ca:7ec3:f4f9 with SMTP id l11-20020a170902d34b00b001ca7ec3f4f9mr16977044plk.32.1698215429699; Tue, 24 Oct 2023 23:30:29 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id x14-20020a170902ec8e00b001c62d63b817sm8467816plg.179.2023.10.24.23.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:29 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v8 6/7] cmd: efidebug: add uri device path Date: Wed, 25 Oct 2023 15:28:44 +0900 Message-Id: <20231025062845.3100964-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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 Acked-by: Ilias Apalodimas --- cmd/efidebug.c | 51 ++++++++++++++++++++++++++++++++++++ include/net.h | 8 ++++++ net/wget.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 201531ac19..42b306e708 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -829,6 +830,53 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, argc -= 1; argv += 1; break; +#if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) + 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; + + label = efi_convert_string(argv[2]); + if (!label) + return CMD_RET_FAILURE; + + if (!wget_validate_uri(argv[3])) { + printf("ERROR: invalid URI\n"); + r = CMD_RET_FAILURE; + goto out; + } + + efi_create_indexed_name(var_name16, sizeof(var_name16), + "Boot", id); + lo.label = label; + + uridp_len = sizeof(struct efi_device_path) + strlen(argv[3]) + 1; + fp_size += uridp_len + sizeof(END); + fp_free = efi_alloc(fp_size); + 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; + strcpy(uridp->uri, argv[3]); + pos = (char *)uridp + uridp_len; + memcpy(pos, &END, sizeof(END)); + file_path = (struct efi_device_path *)uridp; + argc -= 3; + argv += 3; + break; + } +#endif + default: r = CMD_RET_USAGE; goto out; @@ -1491,6 +1539,9 @@ U_BOOT_LONGHELP(efidebug, " -b|-B