From patchwork Mon Oct 16 04:23:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734006 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp33793wrx; Sun, 15 Oct 2023 21:24:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWh+/0KfBsjv6vPp9qChrGM8NlueSJSD8Yocc5XK8uDbydstC/J76fMHS8r1/GUPr5YaqO X-Received: by 2002:a05:600c:1c1d:b0:406:5a14:5c1e with SMTP id j29-20020a05600c1c1d00b004065a145c1emr4803074wms.1.1697430290695; Sun, 15 Oct 2023 21:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430290; cv=none; d=google.com; s=arc-20160816; b=GvvujCTXS0Ot/jbvDrVMZTJnjXu+/rKY5fdtsujWJ77iCQIUXThx/MMgfi7urtHunk DmJdEAZOSB8IVTxJTlL7G1TD5PeffvpcOoIQ16e/eduEkGNejv7bmUFar5TIj+YX/sIf 2XcVf6yAfDyI4fM7Nij0UJ51ltkSjBcXEhfh8Cmlt1ugS21FBQUQsR43ttdLyRTOG3Fn 78xyyTWctGBolkcnsbWTLJT1b5HTlQJ6926tvCe4hsuWELvOiArkeBgboPXJ0xxcxQcU RI67zZ/bg5MSdc/cODs62ydXqomQZD4jZKwadmb0vLKuGgRfa5OcHP1wMuDhknNewT3/ GjMw== 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=XjA5VBV2Z7ueS0coj4rZo1LlbuWXRcWZpPbSDpdfmDuZFFEeIkcrSswFTSf3yQJOKY vcWD3oDFd4ElYyekogDugkSErBWIJ30pj8cmVBf4y8Vl7nmWUxBc9qY9xL4pEfm8q+x0 8UL+LaD7W/UJQeRRIfRSZbYUt7T7ZzSnWx/2vk2gmBeXI/s3Q59qPqNODqIFCxwdYmMI xceHcxk24VCU7hiLHjvqhuQxL8Q7uvQAkWxQetERxf5FRptyP/RpP4oFftFv3U5RaIEC Fu4Ox2wTRUeLCjEPd6xCaSyh1G8mJ3PILPuSKhR7onNIYO8fdZ7qeZhKFzaodomzlJ3H QkRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OceMo3n8; 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 d17-20020a05600c4c1100b004050f26342dsi2217312wmp.181.2023.10.15.21.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24: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=OceMo3n8; 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 1B08A86BB4; Mon, 16 Oct 2023 06:24: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="OceMo3n8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6203E85423; Mon, 16 Oct 2023 06:24:35 +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-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 9E21986524 for ; Mon, 16 Oct 2023 06:24:18 +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-x235.google.com with SMTP id 5614622812f47-3af5fd13004so2766908b6e.0 for ; Sun, 15 Oct 2023 21:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430256; x=1698035056; 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=OceMo3n8g8sKe+GgZN/6677bOVQnLnkZCt6HnomzD8jZnsb44RJzwrlWr8uboXThW+ 4PnFOH37ZjPDlqqFq27+NJO1D/CqCEV+wJd39RILf9WatX+t+e/8r2ABp0xmCx8xDPxP 2VGebPHI8YXCrCAa8t4AFrYXW2JE4PWoP0gJ6VzTdUnBI0aKt5tf5NIZ1wy0rs+1pJRY yb7Yc6gfQAkZoslP+SNo8NVo+hlQKV3Rqk349sG/azCtWSwB0D6lDgaQlApNBf/mdvxU m1pRSUfh2eoqjKAwuTX7SZ50l/y1zHtaUy/yxzjogUGG9gXCmU9pQ860p0xiZ8Pq2K7x J18Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430256; x=1698035056; 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=SG1AeDZeUXkLRYJHlItVi1aoOJrfCYelzf/wiX3/Agqf8dVS/ltlP7a0BkpmBSj+l8 HPF2IFTF0OuyyS8YuWKFthlh47LbuLYw4NTFBiLfddFuQr1iLM0bnQL6wUzzWTSdQBwO poriU8X3qiAhFhHouSHHhzoLHug+wTzo/jkJn1u5p7rFUP0Q1USV/9HaoNua0uZzEbmI 6EcUuuqb2W/YRpdVi5rR+pCtWGCOQmioC09WpQbPjgWe4xwFifDS5ZwN7qx1AQhbsGrw 3MQEMfQmbseqvJusDzyhHsT0dLVGb08SciDIZcyly/1YIkbDDDlukYlu/iMzLu6DLTjf dm/Q== X-Gm-Message-State: AOJu0YxPTr29rh9Di3IyiHVLP5bmhZ2ScTH2wfbMaSlKzsqKbU+Oo/5p 2eVexGE/CP6zoPNzrV8blhkL+2G1EDImhzIFFi0= X-Received: by 2002:a05:6808:1b1f:b0:3ae:2877:9b31 with SMTP id bx31-20020a0568081b1f00b003ae28779b31mr38513671oib.20.1697430256688; Sun, 15 Oct 2023 21:24:16 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id u69-20020a638548000000b005b0b7ede830sm3254326pgd.50.2023.10.15.21.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:16 -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: [RESEND PATCH v6 1/9] net: wget: prevent overwriting reserved memory Date: Mon, 16 Oct 2023 13:23:00 +0900 Message-Id: <20231016042309.2386387-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 Mon Oct 16 04:23:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734007 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp33960wrx; Sun, 15 Oct 2023 21:25:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWLxCYNVUVk6xuPgvNWBE8oy8ygOPOFjZ64b4W38hQl6mAkk6t/2NE4BaOx5EeVf8EEpSi X-Received: by 2002:a05:600c:2189:b0:405:315f:e681 with SMTP id e9-20020a05600c218900b00405315fe681mr28400090wme.40.1697430326511; Sun, 15 Oct 2023 21:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430326; cv=none; d=google.com; s=arc-20160816; b=y3tfm52pZOxHsashlaxy6jtYNp0+k6vQAgNREg5CmGWIEObxiL+9DQoxMoxBPYWsPG sjs9Dtgu9rzCU61u56fkBAb2zPZbZYIK4oaHC1CzA4mY/iSDgTxZRNhzM2Y1WeNg0cbF 1WfDTN1tpOfZQyr3uOzl9LtftC98tvbHMbaMbhaQdamrJ0q0VfRQdv5f0kZNUexDbfK8 9/QAkHY6m+dOqVx23D7KVrAIu775SsFJHqPn3Vv8cgkP4AEDXTWxVK/djm7ACWsfWHDW WNrdGKz16AXB4jj6/9+LFz4uRvVCCHPfZD3OIQkbT4s5YMbsizQsejtTCkYsMBbjO0ZO fn3Q== 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=AxQfk1AQMYeRDW5jVbxxua6uHdqN+0OHX6QmDQqNybu/ddozvk4mw4oDwdCnL0cE2t cKaz1WZ/vRFmRXCRD4CijgNRR9wJq++sV6y6GhBa8R4E9dr9T8vpxoU7NHbFnViCoqb8 Z2UjCEFdXMM30Sf1u29VpiFkx8gyfah1YypEIIS6J31zenFSi/iDin3VKYsDytLprpNX Q3pjTu/wffl1P+PmSzzm9WpUOAnQRhHqxqMPyTB8Ku7+SS71TqmN196n54jW5lDo/6Qb Y5dsSAHLFr8kGtubGSNczx+UMtf3KbzxWVo8dSmdjRIkxwb7qoyzkm3BFenTMxloWYlP BV5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="g/HmHsnZ"; 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 o8-20020a05600c510800b0040745fefdf6si2215169wms.131.2023.10.15.21.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:25:26 -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="g/HmHsnZ"; 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 B118586C3F; Mon, 16 Oct 2023 06:24: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="g/HmHsnZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A0B6185423; Mon, 16 Oct 2023 06:24:45 +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-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (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 1009086940 for ; Mon, 16 Oct 2023 06:24:25 +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-x436.google.com with SMTP id d2e1a72fcca58-6ba172c5f3dso968187b3a.0 for ; Sun, 15 Oct 2023 21:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430261; x=1698035061; 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=g/HmHsnZuaeQd/8VbXQdJFJuRpg37dw66ubWleKVPdK8ms6DxiWIOqalVyVwbmTcmZ iszy9aUpC8mdL0pJTQgZz25iyJm9VS0DOGNO4l/wZ/PbAB58ZJjGGkctjqzjC23SHYV6 Y/i8TEzxoLvyfF8HKK3Z5oGVnCgpnRgvIfIvMX5RBCM+0SBe5+TZxaFP4558Yna4J6mJ XNftIjj5oruSUD86BPUoOUvYtqEpplse4fsOUv0/amgJw6Xj/OGOK4ZNxxp+7ruI1gdc MRLQH+WHfPeNxg3DIc7SaqSdsatOjGz3/qyISrN95xXLDUxa5TSskEcDNC5TUqq80p0v ILrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430261; x=1698035061; 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=NcyXyRUk87HvpjXwSuz8NtZGbUFzOrTo4jr3u3wc3pu2pYpP4OBXYHPZWR/bENwPsd xfPvJuNbEaReY0ssP3n6i8c6go81sKW2l1NNJ4baUvj7CwJNDgeorsP2XL5/rLMMYKrU zATke/ZAUxUSagFvxyCheY2IWtG6yPLUwateZ0gihpjE7BViyia8SzkQyixmPuQS4R+V FV1SJmBRo5Ozsu4pKvQPMeVByEMdtuYt5Q3civn5it61wDHQGwjleGdo0xd/irWtxMaW VQsnVfx8X/aXN3f7+OPSvOR3dQfRj+DH88o+M3kvz0+0vg+Jb4NCED2JHkVf0kAnaX+c Fktw== X-Gm-Message-State: AOJu0Yzs12k08ScTmfew2Nh7LGLMYc7HSjdjwLA2FvquBnEXiJH1OLV4 ldQWKZeqZANM1mu47HAAWTneuz6O9mjKam2CMtk= X-Received: by 2002:a05:6a00:21c5:b0:692:af9c:d96a with SMTP id t5-20020a056a0021c500b00692af9cd96amr31095618pfj.5.1697430261579; Sun, 15 Oct 2023 21:24:21 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id f6-20020a637546000000b0057c29fec795sm6993559pgn.37.2023.10.15.21.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:21 -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: [RESEND PATCH v6 2/9] net: wget: add wget with dns utility function Date: Mon, 16 Oct 2023 13:23:01 +0900 Message-Id: <20231016042309.2386387-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 Mon Oct 16 04:23:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734009 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp34395wrx; Sun, 15 Oct 2023 21:27:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5IPgu6Z/2C/sVS3WH7tr8+0MnLk4StHEN9c7Ytok0IR7HdoWBatoLV8vDgypei6KS8sGl X-Received: by 2002:adf:e808:0:b0:32d:aabf:1db3 with SMTP id o8-20020adfe808000000b0032daabf1db3mr2314444wrm.24.1697430451746; Sun, 15 Oct 2023 21:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430451; cv=none; d=google.com; s=arc-20160816; b=L8zbEiKtFuiv4GTvo18szuCO6oQN/sVCm3269GE0zIt67Op+T2u0YnpTvmz3U9XXVQ rTcJ1O0E/xCYPr7pkKMq0+mMgPezwYHdBsA7V+PLh0qmATA8o8hi9gtRVB8wOt5HiS3K yz88PqQXPOUQCMDXBRmKr8I0BxeXEcQQElvDx2t00np2syhjT9C2usSR4NpHo5pqUOI7 Twkguy5dsn+rCBnTIeogCP36dlWHzMfqN1nm/ju14zgXAVyTQQTMoQ7bW1o9nvbbyDSu jbrQt2PY33vImItOesH4FKhDLGbfKKYmPZhRIG9Q8cQFVhLTH6LkfnXweaVIW71Le5C+ 2UWA== 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=UA9aOUfytc/cpIWnlSwFpWikPy9GHOvq6mff3duLGBeET9HN+RXv5oUg3+37N3TgUC V4qhM3DiVndeBddLaSOFPYNEpWiSkV5dTe1S6bZw3Nn2z96W4jWZu6ARZnzw9eJUUPVl drrtVQGX/jozW3vCTFpmSi/HkwI0pBMiuYtMeet7eoFZntHPCZr1unHFs9EslA91Ryhj guNFqxqfEPKWGbP1x59okCixayBt3afFjRDERQnILtHTQpAm1fWRAUR9XQsBJD9OlZ3Z oaMeCZn0rB3THMJUVC5dUU9ZOiND9JpbxEWjfam8ftci+UCv2CM85ncSqZ+wpYX2fatA ArEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WtkLRp9u; 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 dl6-20020a0560000b8600b0031f85d91bc0si2155821wrb.834.2023.10.15.21.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:27:31 -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=WtkLRp9u; 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 B5ABA86DDE; Mon, 16 Oct 2023 06:25:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="WtkLRp9u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0E44086DCB; Mon, 16 Oct 2023 06:24:58 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) (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 35ACC86B97 for ; Mon, 16 Oct 2023 06:24: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-oo1-xc2d.google.com with SMTP id 006d021491bc7-57b5f0d658dso2487078eaf.0 for ; Sun, 15 Oct 2023 21:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430267; x=1698035067; 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=WtkLRp9uvJlTiYK9pk2SFm9Hh0aKNinoodwwP/ouRwA+j0aUPAhN5lFTAilgJs7XPV WVIle7aNxm484Ja1H4YpQJM36bAYZaWZwCJCQ4abbU1bJkAsGOeLN+5F29PVoJ2hkIr4 YhVgKulNa5tNQSKSsZv2YymJJmeR2K/QeQ9SiamjdW8cuFaAxFFfhjsAcj0iyQeXg99O IY0ome+GqsHBL8mmGzbVOWUpqcr6MR5TCYy0xwabjFvuhUzxIXGBjNqfp8rOyi07HMUK fsv0WEiZgNVAF+n3g9ELes7DNxKAM3QbPe6932iN6bBc84xC4jB714LrKnkuvknuBUCE zdDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430267; x=1698035067; 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=bCuTRpq49JpVFZCjFKYeyczrdO6GDjwPgV/YrkwzAqMS1oM6tiQ6yAYBRuc9M7wZ7w QtOqvuLFEINSu3QP+US51QL9H4q1iYn01/VhcxxaJnQCSV7jghZQ5zXrLyn4h90BPl5B uTAuSIsUTJUyd2kI1Ur79ktMyWCf/CVzz6wO7CSz1/hGsNftoTi7U4RJyM2TigBz+t59 7Sh6isZmwOAL4H+v5lPjCCtVElxXh7NMEoMzCq6uWvNhF5MBIU8QQk+R1vlrclX53QUX rmPyU+WSct0+VrJ/o0CA9ZIr/KK2Hhv89/815DW8mAlWd8qIUlaNRSgduT3P6TQWCSFi 15xQ== X-Gm-Message-State: AOJu0Yy8zOcQ8PN+Js1SrAHcSmXzakZOd4Ff8KxRnFTe6BKOBWkHQuTh 6Dim8DK16TRgTu+RZ7eoF2FfisoCzJRZm/Vob4s= X-Received: by 2002:a05:6358:99a8:b0:141:d2d:6da7 with SMTP id j40-20020a05635899a800b001410d2d6da7mr36421816rwb.17.1697430267537; Sun, 15 Oct 2023 21:24:27 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b17-20020aa78ed1000000b006bae6eea9d0sm3046763pfr.49.2023.10.15.21.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:26 -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: [RESEND PATCH v6 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 16 Oct 2023 13:23:02 +0900 Message-Id: <20231016042309.2386387-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 Mon Oct 16 04:23:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734008 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp34296wrx; Sun, 15 Oct 2023 21:27:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEb43nmGNl+1FkyIWnOMlUyklFPnP/cvp721+fqQbGIuhIl/IYTHje7U/78C2k7UZM+o6pl X-Received: by 2002:adf:e808:0:b0:32d:aabf:1db3 with SMTP id o8-20020adfe808000000b0032daabf1db3mr2313827wrm.24.1697430422161; Sun, 15 Oct 2023 21:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430422; cv=none; d=google.com; s=arc-20160816; b=neq0k1KtISkp9RmzdiDAK11KABV5Ec7C/t1vwmzYXxugqZGIx7MWfDwko/hTgcQWnp B2ZrpUH/wFFacMfuM3h3+eGzvOMXzrnWuyZE5x7ae41oa8MGR6IyrjN8KsxxyY6XV8yS 1QJt6L0rqAmR4CXiOSPP8V+lz/e515Os9kHCxVSeSCVCJ4XYOAiXWlJvjI/ewncW/41Z GF2s49sbGZ5sa8nJpfIUsU8+7sIOUNFhMhZ4S2inIzniXuzItpXq+g6oa0bd7Rxkl5j+ xp8bpoAK+7waiaHOXxqZHAeYEZGTKN1bdjuq12pTYUSHMzHyHsNMf/t7SAfjYqISDjpG pjyQ== 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=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=DOZwc4XubQGsMfHDR8o4xz2U9UEvNFI6tEc2n9yG2AelP2RmYe6w9W23Q/nQUoeHnT ZW49JTBenFzQ8TMcEId12Xo4++R/Kgb2oOK+Zq94A+wj5c+m0+eoyHJR0FwWySN4rpN2 LZVbCtC9bJm3Z+mEChnKD4/Ewn0rbt8VlKLVG8ezV4dNh+ohBEj/5GgEyz3Mjlt0D2+a IIPLVtTxwIPNWAtncLi3nkWSls/MdkpmYD+cFxw1jB5855ONUIjunBMJGV3sJgBQ5YM9 2KBpxyLv26SgQDrpPsfCEDM/BtUDS2WOJcygQO9PscUjblqMCrWwzkTZ7H71K4DArTRN VuTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O14pn0bH; 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 j16-20020adff010000000b0032d9756f644si3596677wro.148.2023.10.15.21.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:27: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=O14pn0bH; 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 554D186DE8; Mon, 16 Oct 2023 06:25:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="O14pn0bH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 751BA8657B; Mon, 16 Oct 2023 06:25:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) (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 7B36086958 for ; Mon, 16 Oct 2023 06:24:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5a9bc2ec556so1628209a12.0 for ; Sun, 15 Oct 2023 21:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430273; x=1698035073; 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=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; b=O14pn0bH477aWMlLHky3UJt+GV/1oHWvIyXy3sVwwAVR0q3pQGZwkCkhy0Zj2Horen MX1N7nb9SKZqi4KfHtwrSpCdjErKp1i7IFAjvdNm4E/2uzwdM4zxqdi03hWGoYZzh65l Q+Rl7MTVpnaGtX0CYk63V3gIFnxDqADRcmFHlNLxd5HgY7vwI1sKlQeESqowvI+2biw0 PL8gO+ehPhglgBs5BvVCRW1RJ11SNEoLkZi+ZFhqtN2sNJaK5EfcEwaDPnRts1ZFrYpI UVv63iXrA9wbGvlIiyPzx0gY2YXrcugPmPJXQz84VdcbFlF+YLZaHi76dwgVXsltChit Vq+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430273; x=1698035073; 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=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; b=oLMjmos72wt1sHczVWdiOzmE+zgvotwR9Hegi7lMZwhZIxJlfbT2pr0EjdW8pZnc+d FNpFRHahCKcTnoOK3exBCm6wwNZ3vl1VNcWfWNa7SKNjqnV7LovYVp3cM2eRvphxOOON CPFVj4EFYGIdoq5DaRp1YiDDKigytOBrSwbiYCqY+HNbzTGagEBLDE/pPRBGrDWvRykK +IhnKvqH1zA5+fNLYSY35ris1aAtqInut27Hentf8v3PPoVTsKH84V659dywijzNEvfC cpE26+BOwBL4F/BX4rkjefQlxIZuZ474dRlxFi0TwZ5jczXgIP1yGBasUCAN+Qj3gNup /gCg== X-Gm-Message-State: AOJu0YzTEXrurNan8qWvtQL8J+IE1S0rdHGo0ppYNY4jolZPx07pk1ib o4g6ejLjRt+etwLoP66GmjCcoX1IlqidQNUCqQo= X-Received: by 2002:a05:6a20:7485:b0:161:536d:a13b with SMTP id p5-20020a056a20748500b00161536da13bmr32847899pzd.18.1697430273118; Sun, 15 Oct 2023 21:24:33 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id a6-20020a170902ee8600b001c6187f2875sm7459722pld.225.2023.10.15.21.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:32 -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: [RESEND PATCH v6 4/9] efi_loader: create default file boot option Date: Mon, 16 Oct 2023 13:23:03 +0900 Message-Id: <20231016042309.2386387-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 efibootmgr automatically creates the boot options of all disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. Some of the automatically created boot options are useless if the disk and partition does not have the default file(e.g. EFI/BOOT/BOOTAA64.EFI). This commit only creates the boot option if the disk and partition have the default file so that system can directly boot from it. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 86 ++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..c8cf1c5506 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -355,40 +355,70 @@ error: */ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boot_option *opt, efi_handle_t *volume_handles, - efi_status_t count) + efi_uintn_t *count) { - u32 i; + u32 i, num = 0; struct efi_handler *handler; efi_status_t ret = EFI_SUCCESS; - for (i = 0; i < count; i++) { + for (i = 0; i < *count; i++) { u16 *p; u16 dev_name[BOOTMENU_DEVICE_NAME_MAX]; char *optional_data; struct efi_load_option lo; char buf[BOOTMENU_DEVICE_NAME_MAX]; - struct efi_device_path *device_path; + struct efi_device_path *device_path, *full_path, *dp, *fp; struct efi_device_path *short_dp; + struct efi_file_handle *root, *f; + struct efi_simple_file_system_protocol *file_system; + u16 *default_file_path = NULL; - ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); + ret = efi_search_protocol(volume_handles[i], + &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) continue; - ret = efi_protocol_open(handler, (void **)&device_path, - efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + + device_path = handler->protocol_interface; + full_path = efi_dp_from_file(device_path, + "/EFI/BOOT/" BOOTEFI_NAME); + + /* check whether the partition or disk have the default file */ + ret = efi_dp_split_file_path(full_path, &dp, &fp); + if (ret != EFI_SUCCESS || !fp) + goto next_entry; + + default_file_path = efi_dp_str(fp); + if (!default_file_path) + goto next_entry; + + ret = efi_search_protocol(volume_handles[i], + &efi_simple_file_system_protocol_guid, + &handler); if (ret != EFI_SUCCESS) - continue; + goto next_entry; + + file_system = handler->protocol_interface; + ret = EFI_CALL(file_system->open_volume(file_system, &root)); + if (ret != EFI_SUCCESS) + goto next_entry; + + ret = EFI_CALL(root->open(root, &f, default_file_path, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) + goto next_entry; + + EFI_CALL(f->close(f)); ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); if (ret != EFI_SUCCESS) - continue; + goto next_entry; p = dev_name; utf8_utf16_strncpy(&p, buf, strlen(buf)); /* prefer to short form device path */ - short_dp = efi_dp_shorten(device_path); - if (short_dp) - device_path = short_dp; + short_dp = efi_dp_shorten(full_path); + device_path = short_dp ? short_dp : full_path; lo.label = dev_name; lo.attributes = LOAD_OPTION_ACTIVE; @@ -396,24 +426,35 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo lo.file_path_length = efi_dp_size(device_path) + sizeof(END); /* * Set the dedicated guid to optional_data, it is used to identify - * the boot option that automatically generated by the bootmenu. + * the boot option that automatically generated by the efibootmgr. * efi_serialize_load_option() expects optional_data is null-terminated * utf8 string, so set the "1234567" string to allocate enough space * to store guid, instead of realloc the load_option. */ lo.optional_data = "1234567"; - opt[i].size = efi_serialize_load_option(&lo, (u8 **)&opt[i].lo); - if (!opt[i].size) { - ret = EFI_OUT_OF_RESOURCES; - goto out; + opt[num].size = efi_serialize_load_option(&lo, (u8 **)&opt[num].lo); + if (!opt[num].size) { + efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); + efi_free_pool(default_file_path); + return EFI_OUT_OF_RESOURCES; } /* set the guid */ - optional_data = (char *)opt[i].lo + (opt[i].size - u16_strsize(u"1234567")); + optional_data = (char *)opt[num].lo + (opt[num].size - u16_strsize(u"1234567")); memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); + num++; + +next_entry: + efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); + efi_free_pool(default_file_path); } -out: - return ret; + *count = num; + + return EFI_SUCCESS; } /** @@ -642,7 +683,7 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index) * efi_bootmgr_update_media_device_boot_option() - generate the media device boot option * * This function enumerates all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL - * and generate the bootmenu entries. + * and create the boot option with default file if the file exists. * This function also provide the BOOT#### variable maintenance for * the media device entries. * - Automatically create the BOOT#### variable for the newly detected device, @@ -674,8 +715,7 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) goto out; } - /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */ - ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, count); + ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, &count); if (ret != EFI_SUCCESS) goto out; From patchwork Mon Oct 16 04:23:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734013 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp34775wrx; Sun, 15 Oct 2023 21:29:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHNDBjOmUf2Q+KuEiSeDtU6S+ume08Pa5CwaiWBhkAM3Y7DBiIqm4h8AcGQN6EdXifKz4m X-Received: by 2002:a05:600c:b4b:b0:405:3b1f:968b with SMTP id k11-20020a05600c0b4b00b004053b1f968bmr29131098wmr.21.1697430573365; Sun, 15 Oct 2023 21:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430573; cv=none; d=google.com; s=arc-20160816; b=E16MKWWZNYluezlSgVdmSkk4c5Jr6+B+t/TGJ91SopPgrzeZH6QlJrFzRxq8+B0DzU DQQUpuGw1eqMkzniXEsspxWuBQtB8azWI8+aX8DTCx8+NZ7n+JDneBUGLyPpmn7izRPb T80zGt69eFyEgk/aB+3P7H+9Mk0Sm4gtwlmcjzY+2J/7quPkc6mNjHBeHVkumabhD0qf r52KrT3XLsgD5HFz6kVrSs+EUoD2SsaBHmAS2UbSOghMUN4LE+p+z7C73atgchca4fQT SS9TZaeK9Xc7bypqIqjnLaekrw7JysMdvf7tm+nXkpD3FzLQAQP2AsVfgE7ptqyy8ew0 8bRA== 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=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=a4e77Uy8Dt+2TY+AKvGsT13bA3rfPltG/bF/cE7wiPKw0o/PaxXcHaWq07YI0M6cHs aT0+epgBH7oe5wC8+N78wZkyF6uOzPtq7wjOJGSy8Rj287Hvp/Rja/BwAknb8WIzTxA4 Q+ttQDJjIn1ksJaGlAxETherCdvBeKwHt0ImRF4GOdCjN3uOKNBk9vEQBdUDmUkaoJ/J /0PU/Wg37b+W5C/3tTDy6Sfd+GCfXwVz5OStdgqFm6oSDaUnB8Ojd5yZKKID0wyuhmqj vMNBvJz+gz1MMJVFLr1Kl7ZjqhwPEtDx9gcw3CHER4eOcjz6MxleBvPA5C4CzrGoQrmC lZ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xZY0bhf4; 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 dl9-20020a0560000b8900b003232c21f3fcsi2006522wrb.374.2023.10.15.21.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:29:33 -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=xZY0bhf4; 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 9126986BAC; Mon, 16 Oct 2023 06:27:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xZY0bhf4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DADB86EC4; Mon, 16 Oct 2023 06:25:33 +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=unavailable 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 83D3A86DDE for ; Mon, 16 Oct 2023 06:24:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c9de3f66e5so22315205ad.3 for ; Sun, 15 Oct 2023 21:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430279; x=1698035079; 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=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; b=xZY0bhf4LCSJSGihEDY99NRkG0wp51U7TjC9wCEASSmlTyZzGQZ5g/rW1TxiETB1wd QPffbidqQwfRHOyLPu+SW48PFUetN0dPAkUcUGB/593t5fhln2K3WpZTbdaWU2OY9Xmj tRwCeFhi+ildFQG6PY04nEj/UyS4rWy7ExPZ221uMci1MJt6X6G6RHnT03VhvU9v+ucE y7qPCEUXRa+klcNgtTpzT0DUegP6ujUKunrVfsuwBwoUKK+/914IBnWFTPq1zzGWRqBP pTmm607p/6Wu4tHegxn+Gcysbmn88bAEWKZL5KA7GOSw532vOv4YzBIsnkLFeu/+FUgN 3ENw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430279; x=1698035079; 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=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; b=udUv5WeLBW0zNQvbcNOew01fU7Ie/YrhiJAqIwzZt5mRXulxjXJeVZV66cPu/SN9Tu rGGkzy/rEw8M9RfA4fYdY9NidlapZp5v/iOs9NJCOQLDESE34Ifw6Qf/FMggFbGA+oKt Gzj9TT9wnw1QFBxQhFM0mkZBwoap9pXhuSjqHhZIseMwkz+JisfOnoN3QZSEw8XMlP7r MiXgaXnhIUv1C/QWLGaw0YvYcrZexpVAwGNkUG5NWCG3TcY3xYZo31tl75QTYXH+6NK7 cr6KcNbknl6naDVMKctj7mtDAReFfro4NzzL4s8rCHs7dyowcB3V0fOxOK7f6aT5ArVs 4UAw== X-Gm-Message-State: AOJu0Yw7vt14KYS68qzut1pTh0qDXiLqqyBPMYnJ2cTg9FlBlswTMmsl kNsHpRj0td2GGqALJdIWSWoi/l6fi1vjsao73SQ= X-Received: by 2002:a17:902:c949:b0:1ca:79b6:ce38 with SMTP id i9-20020a170902c94900b001ca79b6ce38mr1430981pla.17.1697430279019; Sun, 15 Oct 2023 21:24:39 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ju2-20020a170903428200b001c619fbd5fbsm7504367plb.298.2023.10.15.21.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:38 -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: [RESEND PATCH v6 5/9] efi_loader: support boot from URI device path Date: Mon, 16 Oct 2023 13:23:04 +0900 Message-Id: <20231016042309.2386387-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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. 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/Kconfig | 9 ++ lib/efi_loader/efi_bootmgr.c | 198 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_dt_fixup.c | 2 +- 4 files changed, 210 insertions(+), 1 deletion(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index e24410505f..106006127b 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/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 c8cf1c5506..c90b68f783 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,192 @@ 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; +} + +/** + * load_mounted_image() - load mounted image with default file + * + * @devnum: target blkmap device + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t load_mounted_image(int devnum, efi_handle_t *handle) +{ + u32 i; + u16 *bm_label, *p; + char device_name[12]; + u16 *bootorder = NULL; + efi_uintn_t num, size; + void *load_option = NULL; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + efi_status_t ret = EFI_NOT_FOUND; + + snprintf(device_name, 12, "blkmap %d", devnum); + bm_label = calloc(1, (strlen(device_name) + 1) * sizeof(u16)); + if (!bm_label) + return EFI_OUT_OF_RESOURCES; + + p = bm_label; + utf8_utf16_strcpy(&p, device_name); + + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) + goto out; + + num = size / sizeof(u16); + for (i = 0; i < num; i++) { + efi_create_indexed_name(varname, sizeof(varname), "Boot", + bootorder[i]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + free(load_option); + continue; + } + + /* check whether the label indicates the target blkmap device */ + if (u16_strncmp(bm_label, lo.label, u16_strlen(bm_label))) { + free(load_option); + continue; + } + + /* check whether the boot option is automatically generated */ + if (guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + free(load_option); + continue; + } + + ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, + NULL, 0, handle)); + free(load_option); + goto out; + } + + if (i == num) + ret = EFI_NOT_FOUND; +out: + free(bm_label); + free(bootorder); + + return ret; +} + +/** + * 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; + u32 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); + 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; + struct blk_desc *desc; + + blk = mount_image(lo_label, image_addr, image_size); + if (!blk) + return EFI_LOAD_ERROR; + + /* + * When the new disk is detected, boot option is automatically + * created if it has a default file. + * Let's load the automatically created boot option. + */ + desc = dev_get_uclass_plat(blk); + ret = load_mounted_image(desc->devnum, 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; + + 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 +401,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, 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 Mon Oct 16 04:23:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734010 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp34574wrx; Sun, 15 Oct 2023 21:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFL2MIMyko8o8QJDHsh0sekr47lx8iIgt11TEt2KJCmoCA3lKM2uELC5k/p/z1GkGvBMn6M X-Received: by 2002:a5d:6681:0:b0:317:618a:c72 with SMTP id l1-20020a5d6681000000b00317618a0c72mr27422461wru.64.1697430508208; Sun, 15 Oct 2023 21:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430508; cv=none; d=google.com; s=arc-20160816; b=FGXAbcaMJMYwB1c3832edreeCL06uQpiFJ+uhfoj1cuEaGCG62fHkUSFJNsrxeo0B4 LzzTP9UHpNCYHSBvc/SHtrsaP/AXuGfCAa4hg/j3VpuPt03jmyS5M5NE1zG+MnjnrqrF 4g5vb+dfoNmDD/b83wS0nxtbs9/GsU4INrPOGJDmB3qXGSIfbZDrKhKyn2nO14+0mp4k d0xMIC8f7TZOAmzgZsGGUT8j77Px9gqo07PALyxK1z/qI0+ijHRkie1+1dRVqVlZkpQ+ Y6/DUSBla4IpbGx2k/8o1s1Wmi7CuYwSGlj1WfNACse2iJ3QwIOrCezKI+6UJ/E7vY65 8V9Q== 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=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=P8j/ULIon3quay1uZmw3dwr9Z4TrgVBFG/awnNVMoX2dAgsD2cloTmoyg54qWRbiVQ s45kzJ2B+xgNDp2Uuzfr2yxhyS0wFtkRHmBoooVZzRy1zladQETJIyzuI5cylDi9YTV3 mbGC3iOn135M5KD0bwaPd+6mDNOJqzRbVBzVjjUkgsohOmmWM3qvm/RhT0mW2ApW09GB x3K+T9d0e2EjdrUrBhR3G4CsO26kNBsNiHRVzQHrxyGEHOU//XtWwsE5Tp96HgHzZHwM 8CO8ghngBv9DefvdJ3tC1ZB2TrC3gV0iAFvQWqmX/BZRvqXCva6LtVhAUFi5UVej5VFU jGhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jhk2V98s; 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 fm19-20020a05600c0c1300b00406559e2bb1si2232358wmb.86.2023.10.15.21.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:28:28 -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=Jhk2V98s; 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 3259A86DD5; Mon, 16 Oct 2023 06:25:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="Jhk2V98s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A39EA86DE8; Mon, 16 Oct 2023 06:25:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 4D83586BD6 for ; Mon, 16 Oct 2023 06:24:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-694ed847889so3104395b3a.2 for ; Sun, 15 Oct 2023 21:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430284; x=1698035084; 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=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; b=Jhk2V98sM2eNWoPg0CN88JQ8QEr8HCN1jxRdEIOetvvhsc1GhUzIqT4qPT6DoaHjYf 2R1lhg3WnaxO3G1oO5vTrZLA+k/DUX3/6Z13kBuB+ofRy2EumpqEj2hX151imvC57ujK doRuhV+Qk6xOhU0b5mqI0VGZ7FiAYmpMCK9HRcvFGNkjw9BvYuxvirh7MHTZpQw2+15p ZEy8MUHEIRIAGTmsnswe7KrF/sOKhdo9ydpWh9YbI+Q20LgOC5T18MlN0qmtpOhVcLi5 vYC5k6wbNJQqn5iw+muOaNE+blrTLgXDN3iqEbX0SlpbGrM+o4fMCBCDka0Ve0yxCGCA GhmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430284; x=1698035084; 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=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; b=Clk9LRx16KMTdyoi8zoRiF+P2J4nS6WoALBf3xH/U4Lw2mknGKbt/jxIlHIILwM0GG wWbCiQYllsR3PLX8gDWdM6IV/TzTHP5FujqnOAG/JiZMpvroFMTfXArXNk1Bny1cDhl7 IQXCT/jkq465eeMy2EMzmC2V5NuKff6I69rCOa8VPyQW5h8McK5mVttwfsJ+n2WILq0P 3JE8C6K/AthzuGYjKcrm6E+jJ1CVAetHQqQWjIDwyxzr8inwpoQh5oFwP23ezmEUnJ2R F/uVAErmK6O/kqEh6J/UD2MtTCRzFztWFnNYyhCkLJN5l6pZ+kdyZL2ptHHNRY31wAdL wr9A== X-Gm-Message-State: AOJu0YzoCS5AZsfihtBROctP6JqPMEn0cNikr2K+y3x+rYcGalNMlP3n q0iisBkPFCjAHrFeEJw93/HuVVHx0DGK1Dh6dSo= X-Received: by 2002:a62:f211:0:b0:6bd:ca1d:c51e with SMTP id m17-20020a62f211000000b006bdca1dc51emr1288353pfh.16.1697430284248; Sun, 15 Oct 2023 21:24:44 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id x20-20020a62fb14000000b006889081281bsm17014568pfm.138.2023.10.15.21.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:43 -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: [RESEND PATCH v6 6/9] efi_loader: add CDROM short-form device path Date: Mon, 16 Oct 2023 13:23:05 +0900 Message-Id: <20231016042309.2386387-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 UEFI specification does not mandate to support the short-form of the CDROM media device path. Fedora installation ISO image is identified as CDROM media device path, supporting short-form CDROM media device path is required to automatically add the boot option having default file of Fedora installation image. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_device_path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index ed7214f3a3..ac673ab117 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -110,7 +110,8 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) while (dp) { if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_WWI) || EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) || - EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH)) + EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH) || + EFI_DP_TYPE(dp, MEDIA_DEVICE, CDROM_PATH)) return dp; dp = efi_dp_next(dp); From patchwork Mon Oct 16 04:23:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734011 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp34645wrx; Sun, 15 Oct 2023 21:28:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6VYm4bmg1NMRCM7IUZu3u5sKs+n0eQ7w+VH9a0YMc6oli7jj7yB+t5uRYO+uHgxzrVI9J X-Received: by 2002:a05:6000:cce:b0:32d:2489:911f with SMTP id dq14-20020a0560000cce00b0032d2489911fmr13515638wrb.15.1697430532156; Sun, 15 Oct 2023 21:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430532; cv=none; d=google.com; s=arc-20160816; b=0Ox4dX6+b2Ee16mKJwNVTKZXXlnTqFvj5MzfSaldA2cdhX7RRHbPQFwvCGXiY3WKqs Rk1+8tbWU3UjuApU/RdL/hko3lvMZUTfZoDpWDWi4RcAlkc1ie00S0gZYLz+AzUib06l utzPmFKmki5hphrlQ2Ew9LbcKjIPFsIeQAJx3Q3QcimwloNNQQyhGy9Rqf84gruyjPuh FQWsb2ez09/xogzCJTEvfzpSpQE3oexzpZkN1nh6XmW6/OrJmtzYt64IvT5aXmpG7wZW YIoqEZF/ZEQsl/XUCXKNLE1CIUyFX2dFBeleKU2AgD+aMcaUif3tjtNVCKfCBd5Y3ezg I6sA== 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=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; fh=OwlxGVC9rLycV+uRQL8XB4l1CrABnLtF7cR6HzvdRxs=; b=cGKECYaqjEZv0Sz41YKSiKpHsW0+jXsnsX+ZDuC4n7qExsJG5f1VG6QzKLjGlW9Thd WpMnE/1DQ7TX6rHxhDrRyO7jcDuVXiMFCKucmlRbLd71/aZyzR2ssuY9Cw5A+chcuX6C HU+7e0NTWI5TaSz0tr2iMqsYUwSj8W/238mEvylIXqGuA0Un4Ggx+X/L6AzGJMtWcWx7 PyHg+ytBeOozo/w8x0DX4CiEOv8WhyyCKyv+N4F20cpnvoaumAOBdvGkX+081voMnzkx HaBmJ73wD9/FoZtqlfVpXMhkVicFrThgC7oGAxWLKg6PDDoOxg9Q5dS3SXhvvdpk5YYU T4Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ij8e2A6A; 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 g18-20020adffc92000000b0031413d88ae3si4562748wrr.665.2023.10.15.21.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:28:52 -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=Ij8e2A6A; 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 AB37F86ECB; Mon, 16 Oct 2023 06:25:58 +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="Ij8e2A6A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BE648642E; Mon, 16 Oct 2023 06:25:30 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BDD0F86D4A for ; Mon, 16 Oct 2023 06:24:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b2018a11efso2470935b3a.0 for ; Sun, 15 Oct 2023 21:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430290; x=1698035090; 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=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; b=Ij8e2A6AKO17Kq0UOTT/UO6TyY+BHTf3RReZ93xOl/swXHpddWL2bUNGmC9AS1AwhF ei4Cs0cH9FKIbzavCTYC4wtGxpmTLSS+KnYtE3yMEjXkonsnVx9je41xMc8aG/MFCVhR hrfj64YNcvhr2FDMb4yvZmW8rSLiu/c/yu5OiK99JhkRpvqKDZr0o836jSGweMQduanf ciA7CEvaMFhWdzBS7fdru6ncCEJognxU90jNwoz+HK9tsIXfnl/DJ6gDKoDdU4beIGSm ddOg1IKxx/dPREuJhrV8FXsSeGRvOHy/bm9phIX/5R5f2GZ7lb61/4pX+23duKEaKUKe RqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430290; x=1698035090; 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=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; b=EZbjQ/ONCynowUyYSlh8fmfootLlOido4W1KU8Gnw5QrJdo0m2ZqJcEoi7RZK0jfYT KScUyAw2DGjtd1ak6e5Z1R72ojq3EtdXqSB4Kq7vl9jVFJgx0PZYB7+tuo++PtyODdne 21GVyM2uxLpNYl5UvZ1WYP6acJf3nSvAb06xi5dVfOnUmIdJbILsRr6CQdswqHiSkEmd T1z08dk/CJzcr7KgAtzQR8Z3NIS2A5n5e1y7qBzKezyST3siQK/g+nFa/aWRU+L4aZkE x26arS+l8A+uYfi7rhikno+S7XiiTV7Fgq+NlluTdflaUc1FBnsfAEYE5hQCO5gBrfLC g3+A== X-Gm-Message-State: AOJu0YwnkOFfmE0WqLM7feL/IZvrQ9TQreIvvvHgVAtcjNRQib5DG8Hb SMdyTQ4nabyJZhtfhnjgaSzfr8Eq7WRv6B3qIzE= X-Received: by 2002:a05:6a00:9a1:b0:6be:130a:22a0 with SMTP id u33-20020a056a0009a100b006be130a22a0mr2815229pfg.14.1697430289636; Sun, 15 Oct 2023 21:24:49 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h15-20020a056a00000f00b006bb5ff51177sm2937428pfk.194.2023.10.15.21.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:48 -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: [RESEND PATCH v6 7/9] Boot var automatic management for removable medias Date: Mon, 16 Oct 2023 13:23:06 +0900 Message-Id: <20231016042309.2386387-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-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 --- 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 e6de685e87..37359a77bb 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 Mon Oct 16 04:23:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734014 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp35011wrx; Sun, 15 Oct 2023 21:30:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuKnHpaizfSHLWeVFJiG7nPOA67NNlT2E+YwREUKEciVyD0NbjKi8SePB2lYGi363WgvBq X-Received: by 2002:a5d:46c1:0:b0:32d:87c8:b54e with SMTP id g1-20020a5d46c1000000b0032d87c8b54emr11018634wrs.1.1697430629187; Sun, 15 Oct 2023 21:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697430629; cv=none; d=google.com; s=arc-20160816; b=0nW1HeET/RKQ85r2nhylVKx4xQO/GxH9B8b+NK83G43AolffZfkzODkF2F2bhrcBap xp6uz9oL/V4giVaR/MSoYRVC+Nd2rD2vMBRJbH9uJxVThU1R+hmiHNOgzZFZz9e+L7HH uS0XWu7WF1g7UU5EM6COqeVdOjkiVDe8RIY+RZZuAqAgvNpRNjcPTYDbQgFBa+dEeGfG QXlFZnJjigQS0QzBYK8os+vfPJRBosPCY+Z7zmCIIpgufZ7T+p2iiowOVGY7OR5pV4Eo f43xnlAfR94JNXcIrbte28nGJOx8m6a3Qhar+mMDxBY9DeNvaIC6UHFiAMZdS5cuNIo1 00kg== 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=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; fh=UwEaQaZSKscgV8VKorL4WxKMlykH7WzwOcMeBrHkxSs=; b=HxYWG2IUR4hdo1kglN9y0+zSpVCikjM1OXe79pVViwZNALR1Zyp3tmGCR80jXPFRTF sBRkYqM37gCFPlToBTaj8x5PhbOrRJZQsCtSa7g+gGZzvf782tcNeFxsYv0DK0uHaou7 +FVpbknBhnbHntuL3W+qp3dAyFio9lAKtmioZDpxbuuc2l0EskA3Z5MNfFHY5Fx+HvLu PiQFZHfFcBbARXZH2obwSU81Dm8Ksc40vKHeBdLzowoaCa/gV3x7IcMZzhermwz0T37G Zx9N/SNtTfu4MvvJEdPoEbrl9hko7wPLxjI6X5m5SuBl8vW8vOV4ykCLWNClKb9Mg9g8 NvcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RP2uyRU4; 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 e18-20020adffc52000000b0031fe20d6a39si3572636wrs.220.2023.10.15.21.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:30:29 -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=RP2uyRU4; 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 82F2486DD5; Mon, 16 Oct 2023 06:30:21 +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="RP2uyRU4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BEA586524; Mon, 16 Oct 2023 06:25: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=unavailable autolearn_force=no version=3.4.2 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 5141D86E22 for ; Mon, 16 Oct 2023 06:24:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-58e119bb28eso3877170a12.1 for ; Sun, 15 Oct 2023 21:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697430295; x=1698035095; 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=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; b=RP2uyRU4WNmviYjpjtKrJLYWiPxo3MqM5ekqaMJMEyPGMbVTaU6a98WD8/SBvQhOar H+I5Vholo7PmrYdNjfVfWu8CxKtT+BFKQ5y+5QBo6Dk3MKxHJoFa7KZYjLvPEh/gxPRK kEzFO5VQuYzkd3VIkJPb9mPiC2D/Vg0VRUOpJC541F5XOdaEaSa75mAZKN5tsjNL6bNy 982bAPx9hIzK0eJNi9+cGcuBCUb4q5x4R3ZuCy6RFndQYI0fB9mgP6/W9nH+77Ka16yR o84MtPVWOkJONAfHWWBw4Zg1kVoXtVNnC2vK3LgzdIQW0KrijD9HExzAGAzSvq6Cc+CY HfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697430295; x=1698035095; 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=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; b=APnRJ2omboQkiOEJbMg+gJLUPl4cswLKlisjE85SgB3uPcvs8Gf6lvI6/7gckJy3fp HKFcUfNxunhDlWn51rdTSdWpVbhfolzjz6wnvAUrH+nFSlHoSo5xFv0XetXSnO0JJkPX RrwCLiFagHbc3RcT6MpzWye3GVIvokXE1nD3/OPTSicfbfoztrAFJj2p/mRdxP8R/R4V LBhwH9F+0BnXYajR7mMXIYUCJlK9z09fq2gXaNAxgZ8c2jdo/FNuFKHIVET4WSOv+xH6 9jT5FU6JNovmO0XPchvkbJHUWoaZxd+KdcuvAIY1MFv7+qf3GQswtBa3VzCZWyNGtMzb gaPA== X-Gm-Message-State: AOJu0YwtoPJKxtshUw91wf9K+F4KQ7hem9PXpNK/R4FF1lWBpyemRw3j 7n9DZpeM01wR4PV725yWjVWGdAlNMS/sUjR3Ssw= X-Received: by 2002:a05:6a20:9150:b0:140:d536:d434 with SMTP id x16-20020a056a20915000b00140d536d434mr9432129pzc.10.1697430295444; Sun, 15 Oct 2023 21:24:55 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id y123-20020a636481000000b005b628aa2a8dsm1769166pgb.69.2023.10.15.21.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 21:24:54 -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: [RESEND PATCH v6 8/9] cmd: efidebug: add uri device path Date: Mon, 16 Oct 2023 13:23:07 +0900 Message-Id: <20231016042309.2386387-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016042309.2386387-1-masahisa.kojima@linaro.org> References: <20231016042309.2386387-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This adds the URI device path option for 'boot add' subcommand. User can add the URI load option for downloading ISO image file or EFI application through network. Currently HTTP is only supported. Signed-off-by: Masahisa Kojima --- cmd/efidebug.c | 50 +++++++++++++++++++++++++++++++++++ include/net.h | 8 ++++++ net/wget.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 0be3af3e76..5f392d2ffd 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_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; + + 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