From patchwork Thu Nov 2 06:44:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740427 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672243wrv; Wed, 1 Nov 2023 23:46:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXdOdlMg+b+QI7jfCSjTlIn2wDJar12xNo5vg7iMj+Y5HdAbIm9av8lH0snGPwK5I+ASGx X-Received: by 2002:a05:651c:1310:b0:2c5:98b:8bdb with SMTP id u16-20020a05651c131000b002c5098b8bdbmr11232612lja.49.1698907597791; Wed, 01 Nov 2023 23:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907597; cv=none; d=google.com; s=arc-20160816; b=r/gc4RZ8PHPEoTfFgZuP7UA0Zs2vcMhYAjh3sQJQVAUaMcRWDqX8QvEm7kgwf84DeD ZO/IUr5OmTP9kGZZi5GzyBNHTlpqcaDtidIlex2phRCDMAeZx9t+NDsjEovejT0Ee3dD fglagi9/7NoV3W+aXjGtxc7VJde5NKUaouAt6bIEIwbT93kgeobRje+UxYgBdkawi0LS ILdVI3iQqrRp6NXFfkv9/h8VJk5JvcXkkx679Z5fZCHd5A3Z6EkYQDnQLACYVJmQMRZD aiGuVhNn4KqrqeIK5pQU+urPvaQEd2+3PA9tzxlLlP4ywHTlNrJz39JIz1/igICC6elL I8BQ== 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=d0W2MGmEJza2Hbp1rcOpQ/8NcuYDOOFB7fiGu1wXWmNK1grP8Ni+CDrnh89wCGZ+0i FsuPfWRuUPDcCgOasdMQs0dHdychiRcllY4g6/VDC2KOfvDcQepxE49YthxW1QeWi1Ja ykkNf5wberPUqQN+M3IIzEYGuAHkzUV9HLDd2QTZOvRm7/EdRJkHbh8+C94kOzVBiDxl OJx7kC1X3ARRT0XGzMNn73ezQs/DZr334HobO/sO5a3FAs4I0Mjn7AxhgloNKs7jVy+/ awfQE7QqJV2BkLSuAs6NpudMWkOYYrfNXatP2+AbrLersibbBw5P3UDEQcoicI3TZMbW 5qrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UcaeOXlP; 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 e2-20020a05600c218200b0040749d9f09bsi938536wme.85.2023.11.01.23.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:37 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UcaeOXlP; 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 AA275876C7; Thu, 2 Nov 2023 07:46:27 +0100 (CET) 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="UcaeOXlP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 50C1C876CF; Thu, 2 Nov 2023 07:46:26 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9C1D3870C9 for ; Thu, 2 Nov 2023 07:46:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1cc316ccc38so4538155ad.1 for ; Wed, 01 Nov 2023 23:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907576; x=1699512376; 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=UcaeOXlPFgCgWtrUYXGYqnFMwSDwIKh/n3xggK+HtNoRuvPbRwLFo2KeVX9qtJDO/Q KdEmZ7QO4CAiJn4fA9Z44jvOjB+8+36Z82CD4cvR6f2uYleYm5t0/evikVKEv9BIbka+ 8yRv/Gcm5Ya1eITLVeAIWQ5TIHTV63dU4wulTCvXK4iIoScT0I3WzFab832x+V78rpLx OIr/YwJaRUUG1KCEhCdPiCdYP7X029puoJTfvRH4PMa9CSIW6p2z4U/8oFpVO/uk//+w 0RlJRDH6X7hsvCIvJPv6i3zukbSGWYZZaaqLfCyZXg5gO3oEr4Zu/2oWXS58j1xEDVKn ARLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907576; x=1699512376; 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=wKXhaaJ2kk9rvf4N1c9FeQBEZ6RmNXHdM/dXk1QWwRrA/zYvkDvBYTEULIZsXLHli9 GuqM45e3d0hFtv+gaP0t8VVvR7SKemZXYE77DKyrKh/qHN6XjAGxE/z2J2mRdvYNOQMI h5uTs7BvWn4LmRnvBcbZU8o+OSatCGoddavFbjP8KxxgaH6Hzb6a7Qg6F+hhur8gJThp B5ohOxEi5A03y3H9Togv8ucSv+WSLYzE2defhitShQRZUCDxe+IeP/UEvcLg5fYNSPwh rRT1Q7EDZI1KZ95bFQf6MlnGay4quuR7b0S8P4m8nHyclUQG8slzdJQj0f1Vi6rc7Rql C0WA== X-Gm-Message-State: AOJu0YyNxgRQKdFSSjU6tA7t/7ori4rrIB/RqHIWOjHxrnNtr7ZP9KMX MYw+Fd9ka190q0pNnpLWJlDvcrtrcn+Zhc46HMc= X-Received: by 2002:a17:902:ce88:b0:1cc:636f:f37c with SMTP id f8-20020a170902ce8800b001cc636ff37cmr9161192plg.13.1698907576467; Wed, 01 Nov 2023 23:46:16 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id s9-20020a170902ea0900b001c9c47d6cb9sm2330152plg.99.2023.11.01.23.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:15 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v9 1/9] net: wget: prevent overwriting reserved memory Date: Thu, 2 Nov 2023 15:44:51 +0900 Message-Id: <20231102064459.3466953-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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 Thu Nov 2 06:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740428 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672304wrv; Wed, 1 Nov 2023 23:46:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPUvq4rB003lbIRx+OK/zKCB65BoasAbgIxkDLPkuL0C0RAwPrxKMN9Yx0gqavQlQ83uAh X-Received: by 2002:a5d:64c5:0:b0:32f:952f:c524 with SMTP id f5-20020a5d64c5000000b0032f952fc524mr5700266wri.10.1698907610584; Wed, 01 Nov 2023 23:46:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907610; cv=none; d=google.com; s=arc-20160816; b=Qb3tyvr95h6SiYeIweplCHOQ+mxmQb11R26R9vr+GvsQ2qJ1pGPtMPdIwK4IJW53l4 Kq4n43wUSJYWEy45dLok/pYTAr2R++mFJjDBEEOqUgZZcG8nMPK1KOVze9auFpuEeLw1 EO+UkTwDP5cq6D+8tJG5+nwXFCnVHj4Q9t+faCJH7PMxe4mDmcnahOA5eeQ3TKi+Ezv6 I2PwSgsqruauq/GFO8mP3GmKjr8Hz7JTvwsAro5wu8kqSBJXimfy2O49rwKWgRqTQEJP +o1tzKGyONuqzql/lL2i5/rTc/qInfr1uYQRjaS8n3GXiNq4pSKDCwzWTh5uU5Y/D7Hi qvXw== 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=A4qEfI1sO1WejJzJQ+Itg7oNJsuGBM1eF79uFdT0LV4ADc+86iE/fYS1/aMvqLOmKh 9ucmtwYRFFhU7CY8YpU4HzRMd1FpxYQ46Dkb2pLV+fwtASn+AZSWxuthtj/IYh/xi/F/ jud9o8e5P7E5Uf5+nK8hjbMjGcwcloWupqr9Nh+1cWKltKwvEvjfUN9buP3NYNGVz0Ur 3mTO0YE8rKTSINtyopDVjuzlYe63bapyJvOHHMJa96ilB9dzFTsxssX7PKt1sPARb5OG 2iSE+en/zgeNjc+2s1UHNz4fBlaV7SM3grUOu3DzzUbfsFEzqCb00YNp54M8xAiIuK1x qZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uBzK6W+9; 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 b4-20020adfd1c4000000b0032f982cc6dcsi968084wrd.85.2023.11.01.23.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:50 -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=uBzK6W+9; 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 281FC876E2; Thu, 2 Nov 2023 07:46:28 +0100 (CET) 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="uBzK6W+9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A7FDF870C9; Thu, 2 Nov 2023 07:46:26 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B8A4D87467 for ; Thu, 2 Nov 2023 07:46:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6c3077984e8so613575b3a.0 for ; Wed, 01 Nov 2023 23:46:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907580; x=1699512380; 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=uBzK6W+9W8WYBjvUTOKgzthbcpbUx0Rz0NpJeNI1dd5r9OSCSnQN2alBWxfDu8GSoA 3tky37zNqQFNWfpbdr4FMvZIzqqvt2YKlikO4yNfdVBvDbFrINhmsrUKrZyFa7dHBDNv tvSrUaVN8C0wAFEptDlU8Zek9QwdZSm/P/i0apfUrDJHR/NfKuFx5nMdmpSdi7ckwBVb C/46zf7ddlL6n1haiEOlIigi6f7kbLGaguExbWkVnTp6vMEcxjlnItrCbq2vFL+ehi0t WPAvqVj9WtRL5J0WBCOyPM5vG2ZSVvsDiLnJxQ1hH0r4P0Y0/VStSue4mOS8skGMb/sJ oSgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907580; x=1699512380; 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=dTkcR+F9M6n/39/3P9X9Ey/W2RRScggKw1YsXQiHgPutVb8m/ItSimP58mspuJ3KL8 pgq0irNNXMC65ixNquQeKFjhFgaoXEIJST+peT9L6YjWsBj02jRwtAHZXqlFRGU6jKnm HycFmzzsuokR3xBEKNh0WT1eCsXYYLITUwTvajvW85PjHaezuAt4oSP/y18pS3XNyMxU iqLuBktJe2H1WiqjPlRKWIvx2Id8G3wdFl1+C4FFEEcR/TSTWK1inHLs7vY7UaW+27Ga fanbtBtwg2aFm3xddHSD05Mv2bPz6bHqK3+553Fy1wKGA04M0mcM5blSVn0PBMkMqXsX WMrg== X-Gm-Message-State: AOJu0YyCg/09Uv0CpZw4k+Qo/ZHUSCCu1ey9dT06fhRH56ZIcETEqq+g mX+MjM9zILGpBCJKs1Bh9Zz/Lu8MPUcL/H5Syfw= X-Received: by 2002:a05:6a00:cc8:b0:68f:dd50:aef8 with SMTP id b8-20020a056a000cc800b0068fdd50aef8mr19372182pfv.4.1698907580587; Wed, 01 Nov 2023 23:46:20 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h13-20020aa786cd000000b0069309cbc220sm2170329pfo.121.2023.11.01.23.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:20 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v9 2/9] net: wget: add wget with dns utility function Date: Thu, 2 Nov 2023 15:44:52 +0900 Message-Id: <20231102064459.3466953-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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 Thu Nov 2 06:44:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740429 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672382wrv; Wed, 1 Nov 2023 23:47:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQLSWnWvgB5pUguU8YyFMtdoP3rSeWgph9RSQA878p+wM7o733f0MYR2lDZ1xX8G4d9wjB X-Received: by 2002:a5d:6d0f:0:b0:32f:91d2:6f1b with SMTP id e15-20020a5d6d0f000000b0032f91d26f1bmr8225811wrq.5.1698907627935; Wed, 01 Nov 2023 23:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907627; cv=none; d=google.com; s=arc-20160816; b=suCgbw9uQy6GQThVm1SpfgHB+5kHsD6mb1GOFYgCbBAskHAbpN5KQ8kqFe+0+Up0yR RAuUz5AOD90ksWXlonLgSWR4vb6J4Kty6OAB4h8rE6gvPVXD25PJbOk7l29V55JKgYEy vSWfKFU43Tuhf7rti30BYG0xfFDiW+wl6uOHLhct9BnbLQpyN4Z7M+pAvcBFAcaM3TFw 9TQWG5qZxLgX/veycoTX0zIjZmNFQrwawGGb9IAx+rtGOxUzsJIuxLN/ileX/krovf0J jEYirmRShVM/NyPMKpZOqbPRl+q3XQRHwS8SAnctMARoJnVisU4LLQixodD37ay8AmWu +3Sg== 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=zqO2vTczeIKx1OTsr8uErpGVOeopTGT8suxWOXUGpbQ=; b=dSZuzvFqzU/k+EPix6XnPQfvUAdykwmEjU3iRz8iJRNnfA1vPSiX4VDEuISLWVLv5v HfRRootxkogLJkqNIQAQ8et3IPZTS2abkBQx3RPTp2LF60Q0WhPUW5vOHCwBNCGlqIt4 jPAybvBxPX4jmJDbYZIK7LU1UfVutQyKQRlm5ELCNqE1uBQvOS3EQGIg+u4Jp/XFVSNN MWrvPtraFjg7uwBTmF+rUSWi79Apew4dVbpniTdpTgnoCcaXRglM4sPHLdVEtUQaZQS/ 3NpF2iR9KK4/XUta3RVLtyUIsGh8m8jaqgdFdP/F4LhI9fwTJvRq0oZLReC9cV6c72lM p0IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bNO/MzUN"; 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 g8-20020a5d46c8000000b0032dd84270d9si926904wrs.409.2023.11.01.23.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:47:07 -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="bNO/MzUN"; 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 9CB9787467; Thu, 2 Nov 2023 07:46:32 +0100 (CET) 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="bNO/MzUN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31F58874D1; Thu, 2 Nov 2023 07:46:31 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 E00EE870C9 for ; Thu, 2 Nov 2023 07:46:26 +0100 (CET) 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-x62c.google.com with SMTP id d9443c01a7336-1cc4f777ab9so4919335ad.0 for ; Wed, 01 Nov 2023 23:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907585; x=1699512385; 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=bNO/MzUNV7QX7zbFkayeBeZDrs9HjktrOh4Ij6i7IvIC0XI5wy9ly5HGncmpgv+Tr+ nqVpYIMo6FhGkJOPGbv4AyBvwaauMwrd2gCRT7vog0LTyF1XdwDPqkCoaIK6/1Cc/Tfn mb984nTw4CMXSYSmtuatZM/gwtUlmNU1snrcff+HB9hlHefmpedvM2+FfgQrtpiKYsnk 8uARHI5yJeOZXINwCOy72/u7CsVgD05++b3wzhTM8uhCTkOQvrzGbh4+JBI2Td2wAl3t brsxeUjfuknPArdn0dc/0SsOwYV7FcifU/3Z3wYyaEjSHD6Epj9ZFIEr5u9DFvBfNOq2 GO2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907585; x=1699512385; 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=dI3lTSegQssGjTXF+Bh4NG7YWkf7/yx8EZF9Im7CBu44HRF73EA4YU2ixj5DjjWUI6 ZnYK0jgUZytwGoC3PkV3kEDiy31DYO7wVXEiQwNRE4iTTyVJ0t14to/e5l2ubng2qcNI eqTlLyfwIyJB8NZ477Yjygwj4Gx6TIgtjRou7T23HDRz7zYOeTYIIRjFKvAsz2jmLLab EB+ZYcz9XARV8aKsOJELxKv6QqOQiH5LtPkOR6/q4I9e4eRUz5mlt7S2opbcw6a8921G bQ+KSJa3WaGQIPQtBK8fNOryp41Fjbzb3Ylq0u7/4afhmMFgNVuYaldmOj8x25o67Sgr oRiA== X-Gm-Message-State: AOJu0YxIJhbGeiypwQkaF2dtPvlFstKfDnZ2kHVZK25lFarTbZ6Qjofg bus+SaaD+Br2JQs0OyoenAPM2dhWCLZWWbwrNOc= X-Received: by 2002:a17:902:cec1:b0:1cc:345b:c7f5 with SMTP id d1-20020a170902cec100b001cc345bc7f5mr10984204plg.23.1698907584994; Wed, 01 Nov 2023 23:46:24 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id p2-20020a170902eac200b001cc2c7a30ddsm2331737pld.148.2023.11.01.23.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:24 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Tobias Waldekranz Subject: [PATCH v9 3/9] blk: blkmap: add ramdisk creation utility function Date: Thu, 2 Nov 2023 15:44:53 +0900 Message-Id: <20231102064459.3466953-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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 Thu Nov 2 06:44:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740430 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672478wrv; Wed, 1 Nov 2023 23:47:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzQgN735eBJNOfhxyctFOTu5qEndceLNAz6c8Xo08jQohqgOIqVvvRtBHhmXFNv5PZv3ts X-Received: by 2002:ac2:47fa:0:b0:506:899d:1994 with SMTP id b26-20020ac247fa000000b00506899d1994mr11950265lfp.52.1698907646215; Wed, 01 Nov 2023 23:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907646; cv=none; d=google.com; s=arc-20160816; b=egSEGpHtM5EGS5NFc+Tblr+8ZqZntW3CbNSvfXrZRDEPgZgQKhWcIlJmbPd3X1Yd8M jn+5sXyl6/wrdImysvLYsulrAyDCMzGD9kDcH4f+KKsKegeqWhkEzSHbACenZeHlXqT+ //roiuQtic2PX61jgffOIsfEEu4sGqWmugwtUXH8zqn6YrnPB2oHvHpBVUHNrYwzwRei 0h3n2S+xTk7SA9wqjYJ8zwF5rhSN6Hodue8COjHh8pSQ43wK/x0TgIeBSS39fqZZk3RY Q6G2UE+yov2hKmF6v3o1+Vay6hUpXyWwjvQGsGhE+jPW2PbrTjvhVjWzcRGzRipnoPFW /Y+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; fh=OwlxGVC9rLycV+uRQL8XB4l1CrABnLtF7cR6HzvdRxs=; b=nAxPrJWrskJUZc/XSRCmdJPoemoSfgDrBTpol8okiesMH2tU1nbsuFzqG9OszzWec5 ulWo+Xx3cJUK1kOSpqBGFglFvzIV7VSPWC9jCwBgtO/AgsXcUAvOIkO36sO9Z9tsOi2U UZW9MS0sAez7XHsShOLvD/BlQiTg8lEUmgOtEn7NjGiWelOY91kBiozuJM35d8iuE1YA 8+P8/4Shvs+Fs+iVOI1AcK7J728//ApnItFGDqOrhNRnBey4UbsQPBOi1r9uJgrPIPMj kpapFwToqC1j+eXsE5OnZ5YFvWqR+DfoxBcfMH7H2HJsBQs8+X12s3b+FdlYRGCXFOv3 fWKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b1uPlrzf; 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 bu29-20020a056000079d00b003296b60f843si1030796wrb.812.2023.11.01.23.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:47:26 -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=b1uPlrzf; 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 39D30869DA; Thu, 2 Nov 2023 07:46:39 +0100 (CET) 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="b1uPlrzf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E316687706; Thu, 2 Nov 2023 07:46:37 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) (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 E0D0F876D0 for ; Thu, 2 Nov 2023 07:46:32 +0100 (CET) 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-x22c.google.com with SMTP id 5614622812f47-3b3ec45d6e9so367813b6e.0 for ; Wed, 01 Nov 2023 23:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907589; x=1699512389; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; b=b1uPlrzf+IxQLW7FhztZ1GgvrZlKfl6ogH0EGE+YN47UpZ4I8FH8xUpSY4rce81mOy knRE3vAfz+SgyZ6OZTeJl4z3KRWpTaV1jBZtgL1p6DMbVWcwj0STI1FvgDKzjaVCCS8o ejf9zV4rcjZ7iTBB3mgf6ZIKZzN8xb1ZnVCdbSKFoFNNX/MoNWBV0cpYYgjLvt3MPbt6 pMem2nWAN4zZrAdCA+LjxmSpiGD9ACCksuvdxXIcIj0N0F76pN+MabW6Q50OlTwVNCh1 fwZUHIqIPzZHMuarmtkajS51l50S7L+OMtvmUj1dSJZK+cEW/4fjMh5v2Q0yYqMUHuTb lH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907589; x=1699512389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o64OkjB0jwzD+AXro90PDVuRRGIba/iuGMNcmQLgUEs=; b=aZM1boePQkONnaato37VEpC+NlcZgXh644cDsnHLRO4rVSHzNKGkqSz4+oroKBiJ1t XUBNt3PCRjoU2OSxYYM4IPm57sia43Tt9jVcu+L1qrzTz6qwCMx0j0b3Cyehnc5LGqBa WfZjmWyT90l5YmPXPYhWjdZRBGDLULr0xUaAwTtMLDR50+gZif4HUcpsq108bBN8z9Tb IyCOlvEgfXFDkX5DRvPwXti6gpIiACgWq3XM7Vs/jOhw5TYAnHHk6nFJw5+zrJSVox7J iXOOhmz37T/elooEJ8okdcWWZapfd1cAJqIRMHsI0kMGwfl/QR5wTvnl16S5FZU0fXoG N/2Q== X-Gm-Message-State: AOJu0YydtVL7N/kB8odlkzD5aJbOD5F/FLR8y/hzXc1WS4+DKFl6Z3Gk GvOPN2NE8x7iktRQ+PuaRwA9EpRoWjcaL0v5/V8= X-Received: by 2002:a05:6808:4199:b0:3ae:16b6:6338 with SMTP id dj25-20020a056808419900b003ae16b66338mr19498669oib.3.1698907589044; Wed, 01 Nov 2023 23:46:29 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id s17-20020a63af51000000b0056b27af8715sm832740pgo.43.2023.11.01.23.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:28 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Raymond Mao , Masahisa Kojima , Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal Subject: [PATCH v9 4/9] efi_loader: Boot var automatic management Date: Thu, 2 Nov 2023 15:44:54 +0900 Message-Id: <20231102064459.3466953-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Raymond Mao Changes for complying to EFI spec ยง3.5.1.1 'Removable Media Boot Behavior'. Boot variables can be automatically generated during a removable media is probed. At the same time, unused boot variables will be detected and removed. Please note that currently the function 'efi_disk_remove' has no ability to distinguish below two scenarios a) Unplugging of a removable media under U-Boot b) U-Boot exiting and booting an OS Thus currently the boot variables management is not added into 'efi_disk_remove' to avoid boot options being added/erased repeatedly under scenario b) during power cycles See TODO comments under function 'efi_disk_remove' for more details The original efi_secboot tests expect that BootOrder EFI variable is not defined. With this commit, the BootOrder EFI variable is automatically added when the disk is detected. The original efi_secboot tests end up with unexpected failure. The efi_secboot tests need to be modified to explicitly set the BootOrder EFI variable. squashfs ls test is also affected by this modification, need to clear the previous state before squashfs ls test starts. Co-developed-by: Masahisa Kojima Signed-off-by: Masahisa Kojima Signed-off-by: Raymond Mao Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas Reviewed-by: Joao Marcos Costa --- lib/efi_loader/efi_disk.c | 18 ++++++++ lib/efi_loader/efi_setup.c | 7 ++++ test/py/tests/test_efi_secboot/test_signed.py | 42 +++++++++---------- .../test_efi_secboot/test_signed_intca.py | 14 +++---- .../tests/test_efi_secboot/test_unsigned.py | 14 +++---- .../test_fs/test_squashfs/test_sqfs_ls.py | 6 +++ 6 files changed, 66 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index f0d76113b0..b808a7fe62 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -690,6 +690,13 @@ int efi_disk_probe(void *ctx, struct event *event) return -1; } + /* only do the boot option management when UEFI sub-system is initialized */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + return -1; + } + return 0; } @@ -742,6 +749,17 @@ int efi_disk_remove(void *ctx, struct event *event) dev_tag_del(dev, DM_TAG_EFI); return 0; + + /* + * TODO A flag to distinguish below 2 different scenarios of this + * function call is needed: + * a) Unplugging of a removable media under U-Boot + * b) U-Boot exiting and booting an OS + * In case of scenario a), efi_bootmgr_update_media_device_boot_option() + * needs to be invoked here to update the boot options and remove the + * unnecessary ones. + */ + } /** diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index ad719afd63..c02569cb6d 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -245,6 +245,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { + /* update boot option after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py index ca52e853d8..2f862a259a 100644 --- a/test/py/tests/test_efi_secboot/test_signed.py +++ b/test/py/tests/test_efi_secboot/test_signed.py @@ -29,7 +29,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -37,7 +37,7 @@ class TestEfiSignedImage(object): # Test Case 1b, run unsigned image if no PK output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -59,13 +59,13 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('\'HELLO1\' failed' in ''.join(output)) assert('efi_start_image() returned: 26' in ''.join(output)) output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -77,12 +77,12 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -105,7 +105,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -143,7 +143,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -170,7 +170,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -181,7 +181,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -193,7 +193,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -205,7 +205,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -230,7 +230,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -254,7 +254,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -265,7 +265,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -279,7 +279,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -307,7 +307,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -330,7 +330,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -349,7 +349,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld_forged.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('hELLO, world!' in ''.join(output)) @@ -364,7 +364,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert(not 'hELLO, world!' in ''.join(output)) assert('\'HELLO1\' failed' in ''.join(output)) diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py index d8d599d22f..8d9a5f3e7f 100644 --- a/test/py/tests/test_efi_secboot/test_signed_intca.py +++ b/test/py/tests/test_efi_secboot/test_signed_intca.py @@ -40,7 +40,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_a host 0:1 /helloworld.efi.signed_a -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_a\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -49,7 +49,7 @@ class TestEfiSignedImageIntca(object): # Test Case 1b, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO_ab host 0:1 /helloworld.efi.signed_ab -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -71,7 +71,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -81,7 +81,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_b.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -91,7 +91,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) # Or, @@ -129,7 +129,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py index df63f0df08..7c078f220d 100644 --- a/test/py/tests/test_efi_secboot/test_unsigned.py +++ b/test/py/tests/test_efi_secboot/test_unsigned.py @@ -36,11 +36,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -65,7 +65,7 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -89,11 +89,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -107,11 +107,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index 527a556ed8..3b8118104f 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -118,6 +118,12 @@ def test_sqfs_ls(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled, default file(e.g. EFI/BOOT/BOOTAA64.EFI) + # is scanned when the new disk is detected. This ends up with the unexpected + # output at the first 'sqfsls' command. + # Clear the previous state. + u_boot_console.restart_uboot() + # setup test environment check_mksquashfs_version() generate_sqfs_src_dir(build_dir) From patchwork Thu Nov 2 06:44:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740431 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672586wrv; Wed, 1 Nov 2023 23:47:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8J99EuaGd9NgUpKEBqIofP4AdAO1ul1dXz1OQ+EFqkTSjwbI4uGWBUwPW/FKStZDfGHNq X-Received: by 2002:a05:6000:1882:b0:32f:7f78:e29c with SMTP id a2-20020a056000188200b0032f7f78e29cmr11021758wri.38.1698907671101; Wed, 01 Nov 2023 23:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907671; cv=none; d=google.com; s=arc-20160816; b=EPhUC8k3RMMuH49dwCfi69ladUmWAgpCN/Qdi8RnOd8AmzNZvLgsjfxEBCP3uMQK2w x1NDh2nhr3iK9tPRQ3D8BoxgXExdSTfOZxjUZAiyWBUIpklwuO3ZBsVM9Onqlq1Rns+7 3YkRiYOMTtAkL9u3CUUBCIk4Vr8XHRZ0dAR1KYdPa5s9k11c/wTra5owbNDzEKNgB0dz /+XPNduHFcl/MjWjwqmEHaWQFk1dxPJGi6wYaP99/CKkxVzit1bu8SN6Y3Ukrs9LzhJ2 eJL5sy0KJF7xWkjyWUegj3kTV5aT6kSrj31QUxZNvycWnKD1QqEAXvZvcOR+qKbIagIl 9Hlg== 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=YJblxL503HrvYGakGMsGmRKvit2ltsCs9InMyBUP3XE=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=fIeG92BtVDc/f9PkhF3GL6eB7dS49Mttar8stVAC6Rahz0ZW1AVFVqrJhGeWieFRgi qVA831Ds6HRzqNlEOI62Oa+WHaZj7jhSdRl9SYSHhgxEz5doxFRiQkxF/cbxyPSF3XEL XAW36i8oFu12Uc/1cptxYmHT9KLd1jE/Seo/mhiEb+w881Et113aelUxyV2DSwLtFL/6 BwnuXNkVnqtLA2WArkwdo7ebS+LMiJ6pFOawGr3mQ9dInSFgGM94LDW5bqKVPh2EP4jH dhrOsZIaRuLnlZ5MJgPrM0AvtNEqkUdmOs5c0ETDJ37JirA51/Mgc0h+DIZvNLh/Ch3l yJwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="m99/jeRv"; 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 n15-20020a056000170f00b0032dba75e2dasi1072988wrc.436.2023.11.01.23.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:47:51 -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="m99/jeRv"; 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 98F9B87253; Thu, 2 Nov 2023 07:46:40 +0100 (CET) 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="m99/jeRv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD84786E88; Thu, 2 Nov 2023 07:46:39 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CE95D87703 for ; Thu, 2 Nov 2023 07:46:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1cc5fa0e4d5so5276095ad.0 for ; Wed, 01 Nov 2023 23:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907592; x=1699512392; 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=YJblxL503HrvYGakGMsGmRKvit2ltsCs9InMyBUP3XE=; b=m99/jeRvdAKBEp4IS/lTWcWeNxfYZD3zXU5egclx1h2ELttw579bLLc+VvDnT3G57F l6qeIZdhkTKt05lCWPTy/PJYUktA4pdfDPmLaBoergs+UFNLnB1JwQOH7O3UnxYt8Vhx eNAWJLhfR3oZZkAYC+obYI+OMdtSiVQPCGxaG1UKIdRkwkRsraxUoNqVFwUumeumz7OL DpLGn7soV5ZgG5cTSWNSntvUYOsr31Jah2A4B8HbDP1WMsA0ya+NL1W1sMWZIp/iCgi4 8+G50sVb1A+Vcei4tYosYFdlc+TScuEUdO+bKYBfgqffr54AEuiKiitahEGGHuWKHMEF L8dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907592; x=1699512392; 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=YJblxL503HrvYGakGMsGmRKvit2ltsCs9InMyBUP3XE=; b=obtMNAiFNVs1/yKPV7hokPQHYUsGnW8/J1uUZeKzwo+t+b5lLUsluSq3ECO26LVyu+ 2qRU5yN/XzfeNB7X3CAjrA1py7F6uQd42dYR3nRxuNy+6oOJp/bDMWWRuEBpRReGBzg/ LH4TqKNCvoxTIlfUxjkgsGjK/GtWq+Qk1hueikCvSzSFf1xYuApidbgWzkGC79snmTfg CEUVzsikbNBRqHrWRp6dYSqmL0tjXWyRrLV1ajtwFgwUYBYfpbD/EbRX/gtjUL57Votw 3E6rnwELF+1HiATT4LrZ1w0vxOKu8aQjZlthrAJZP0jbMRvhC3t9jfxv5gUKpM+zaF4I xmbg== X-Gm-Message-State: AOJu0Yx5BjwGQVTAvRKTGiHQ7Et0eAyavpydvwJP2xuHpGDFLRzgxC6j WgS4I344dUX8ByPxiPquJhxxmfuvBMqT/t+yq5U= X-Received: by 2002:a17:903:2346:b0:1cc:449b:41e2 with SMTP id c6-20020a170903234600b001cc449b41e2mr15777009plh.23.1698907592572; Wed, 01 Nov 2023 23:46:32 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id z18-20020a170902ee1200b001cc2bc10510sm2328349plb.128.2023.11.01.23.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:31 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v9 5/9] efi_loader: add missing const classifier for event service Date: Thu, 2 Nov 2023 15:44:55 +0900 Message-Id: <20231102064459.3466953-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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 const classifier is missing in EventGroup parameter of CreateEventEx(). Fix it to remove the compiler warning. NotifyContext parameter of CreateEventEx() is also defined with const in UEFI specification, but NotifyContext parameter of CreateEvent() is defined without const. Since current implementation calls the common efi_create_event() function from both CreateEventEx() and CreateEvent() services, NotifyContext parameter leaves as is. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- include/efi_api.h | 2 +- include/efi_loader.h | 2 +- lib/efi_loader/efi_boottime.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 8f5ef5f680..c2d6964467 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -192,7 +192,7 @@ struct efi_boot_services { struct efi_event *event, void *context), void *notify_context, - efi_guid_t *event_group, + const efi_guid_t *event_group, struct efi_event **event); }; diff --git a/include/efi_loader.h b/include/efi_loader.h index e24410505f..e164e6067d 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -685,7 +685,7 @@ efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl, void (EFIAPI *notify_function) ( struct efi_event *event, void *context), - void *notify_context, efi_guid_t *group, + void *notify_context, const efi_guid_t *group, struct efi_event **event); /* Call this to set a timer */ efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 0b7579cb5a..f9b10a9763 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -712,7 +712,7 @@ efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl, void (EFIAPI *notify_function) ( struct efi_event *event, void *context), - void *notify_context, efi_guid_t *group, + void *notify_context, const efi_guid_t *group, struct efi_event **event) { struct efi_event *evt; @@ -790,7 +790,7 @@ efi_status_t EFIAPI efi_create_event_ex(uint32_t type, efi_uintn_t notify_tpl, struct efi_event *event, void *context), void *notify_context, - efi_guid_t *event_group, + const efi_guid_t *event_group, struct efi_event **event) { efi_status_t ret; From patchwork Thu Nov 2 06:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740432 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672647wrv; Wed, 1 Nov 2023 23:48:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyHUkgZoYTIkaq50KDc7lJqUR3TxA5d5TQ7VHyVA92ks3L5TA/jFVyDSgkma6LlNOL3GQK X-Received: by 2002:a5d:5984:0:b0:32f:81f6:99ff with SMTP id n4-20020a5d5984000000b0032f81f699ffmr10223818wri.58.1698907684540; Wed, 01 Nov 2023 23:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907684; cv=none; d=google.com; s=arc-20160816; b=EH4X/XEEdiRmipN+exCLxFeHTdx7c3MImyjWqcsQxWG0ANNSmit2nGqlA+Wv9M9s29 TpeLlU3xXOLBYZqvp2dWoGfkU0BWl8xXDjq15iRQRhoUvo516ccwPpbxSbl9kioHvb2G uGV26HK7nXuyjzbaX143DzWbNYLm5HuVuM5ffLme5/1uBAOmyyR5vejEjj1O+Brrqxm2 M+l0HWxnzeO3jw80D7Ns+Y+nJvYtXfnIvsvw3xVKCAriE5fV6ZcTF3KKubl96yMC1iRf FzeT2WMuL17ILwam+S7LNU0wmPK67+hSjWmrtm2KQ4qBSkpFmhJxCuhqLGskvqG0qJ1j kbmg== 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=cib8KL/yfgl91t4t3wFdlqpTDFoTGfWf+CPOfiYxJw8=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=dkUYVBmLoUx4MRQhjGzrhX7s7+nmsqSaJQ+RzOMpA4TcZBHdrR86XvKMfoc9+zDd3J 1ErEdAmBEZC770Q52gywukX7vWEalPtpQpTX1Mlr6kDxRqc88tPq9n1kWDhXXKh9118H MKGhdC2waUTKDhw/WGp+9HGjVKi5sJIqhZJGnut9P+H0DbMeNMZ6DLvCl2qUq6Wa+mP3 qdfJDne0DqGenNftCOngetiP8QeOdhQQKXdJaSAg7YzkC7vQDKyCBh7dl3hS5cjLEK+G GgVzFcGJwDSwkP5eGjgugK7kl1/R3lGMbj/TubfoRnm1uIOi9B3ZiCqPjuKn91VX5jcO uGQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aqYgzIES; 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 p11-20020a5d59ab000000b0032d8f5dca6esi1029807wrr.233.2023.11.01.23.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:48:04 -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=aqYgzIES; 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 0B30187703; Thu, 2 Nov 2023 07:46:44 +0100 (CET) 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="aqYgzIES"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 86C0D876F5; Thu, 2 Nov 2023 07:46:42 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 620918037B for ; Thu, 2 Nov 2023 07:46:38 +0100 (CET) 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-x62b.google.com with SMTP id d9443c01a7336-1cc53d0030fso5273955ad.0 for ; Wed, 01 Nov 2023 23:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907596; x=1699512396; 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=cib8KL/yfgl91t4t3wFdlqpTDFoTGfWf+CPOfiYxJw8=; b=aqYgzIESv8IBj4XSuzsz03fWelB4hb09QTVWCfBs0l+ttb12ngPUJZQf295/xOnGf2 mhUwzNidKhuUkPr0AOlGtatD0XF6tYNlCuc0VQ7cCHXILs63IEDZdlbgaxVqRu3WIvvh 1XtaTL4Tx0dLQ5M+ce6CS6ac4c8/Jr0/P1b68HUyD/T4jA3fvrv2BU+MX83pZ1oaBGBp cCMvEax6eEMPchSwJoiR4jEfJVKs/DUBm6+UvNA+wjSN/WNbwDmlEGXnrmStXhGIj1Ec Xlc8Ku4X2E7n90mFTxqW2EBBR7QQBIlHPKjLPX3iCM9AOT0VAEYa/mQqJlVyFWcqkejX mfiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907596; x=1699512396; 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=cib8KL/yfgl91t4t3wFdlqpTDFoTGfWf+CPOfiYxJw8=; b=QU0CQ7zpKbZg0I6cAwk9+BCFlPfppV6aIHxwkUePHfiOiu1te/VgTxB/XvF0AT7jiR unEoOx1MflNmC5Axsr402JuR8LxL08W4ZHn8sHVWtDzGC7TbgHMIFRsU4UZlTP34XXT9 GuBBWnA4S2GwtF0Ygu3PiPm2Lxuj5HZZ5i2SrLbKBO79A0i+DCVR5+kk6sgrLsymawHb M+7RHPy/+6Ye7gNfL2Tz1HhbOPheb3XsyBQI2pXPj0Ka3fcbbxCI4jxRFImJPm1QMZ3M Y1CX5+Lc8PU/sfGiV2S3i/EqjLVzeL5JfZTBA3pE85DjwvnReddeVu/WRd35MaEidMJN SX0Q== X-Gm-Message-State: AOJu0YzWfx0WKzGJoEPNix8LRiRiLsM0NpovF63uBknOh8pNjpcyXRor +Z8gXXsbbS/fE4+QMBKKyPfukLlwUH6XN6fgQZs= X-Received: by 2002:a17:902:c948:b0:1cc:33e7:95f5 with SMTP id i8-20020a170902c94800b001cc33e795f5mr6620210pla.33.1698907596394; Wed, 01 Nov 2023 23:46:36 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ij6-20020a170902ab4600b001cc307bcdbdsm2389819plb.211.2023.11.01.23.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:35 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v9 6/9] efi_loader: add return to efibootmgr event group Date: Thu, 2 Nov 2023 15:44:56 +0900 Message-Id: <20231102064459.3466953-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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 When the image loaded by efibootmgr returns, efibootmgr needs to clean the resources. Adding the event of returning to efibootmgr is useful to simplify the implementation. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- cmd/bootefi.c | 12 ++++++++++++ include/efi_api.h | 3 +++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_boottime.c | 3 +++ 4 files changed, 20 insertions(+) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 20e5c94a33..4d74969ad6 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -356,6 +356,7 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) efi_status_t ret; efi_uintn_t exit_data_size = 0; u16 *exit_data = NULL; + struct efi_event *evt; /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ switch_to_non_secure_mode(); @@ -394,6 +395,17 @@ out: log_err("Failed to remove loadfile2 for initrd\n"); } + /* Notify EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR event group. */ + list_for_each_entry(evt, &efi_events, link) { + if (evt->group && + !guidcmp(evt->group, + &efi_guid_event_group_return_to_efibootmgr)) { + efi_signal_event(evt); + EFI_CALL(systab.boottime->close_event(evt)); + break; + } + } + /* Control is returned to U-Boot, disable EFI watchdog */ efi_set_watchdog(0); diff --git a/include/efi_api.h b/include/efi_api.h index c2d6964467..0e92cb8a7f 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -404,6 +404,9 @@ struct efi_runtime_services { #define EFI_EVENT_GROUP_RESET_SYSTEM \ EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \ 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b) +#define EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR \ + EFI_GUID(0xb4a40fe6, 0x9149, 0x4f29, 0x94, 0x47, \ + 0x49, 0x38, 0x7a, 0x7f, 0xab, 0x87) /* EFI Configuration Table and GUID definitions */ #define NULL_GUID \ diff --git a/include/efi_loader.h b/include/efi_loader.h index e164e6067d..31954e84c3 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -290,6 +290,8 @@ extern const efi_guid_t efi_guid_event_group_memory_map_change; extern const efi_guid_t efi_guid_event_group_ready_to_boot; /* event group ResetSystem() invoked (before ExitBootServices) */ extern const efi_guid_t efi_guid_event_group_reset_system; +/* event group return to efibootmgr */ +extern const efi_guid_t efi_guid_event_group_return_to_efibootmgr; /* GUID of the device tree table */ extern const efi_guid_t efi_guid_fdt; extern const efi_guid_t efi_guid_loaded_image; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index f9b10a9763..3767fa2db4 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -90,6 +90,9 @@ const efi_guid_t efi_guid_event_group_ready_to_boot = /* event group ResetSystem() invoked (before ExitBootServices) */ const efi_guid_t efi_guid_event_group_reset_system = EFI_EVENT_GROUP_RESET_SYSTEM; +/* event group return to efibootmgr */ +const efi_guid_t efi_guid_event_group_return_to_efibootmgr = + EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR; /* GUIDs of the Load File and Load File2 protocols */ const efi_guid_t efi_guid_load_file_protocol = EFI_LOAD_FILE_PROTOCOL_GUID; const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID; From patchwork Thu Nov 2 06:44:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740433 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672767wrv; Wed, 1 Nov 2023 23:48:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzyWuEpU6ZzwkKuZz7E3+iCQIzPxcUw1gl6Lze9YPgF98Vce6zlevEyHzw8ffSU/1s+AJp X-Received: by 2002:a05:600c:444d:b0:407:3e94:bcca with SMTP id v13-20020a05600c444d00b004073e94bccamr8686174wmn.1.1698907708231; Wed, 01 Nov 2023 23:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907708; cv=none; d=google.com; s=arc-20160816; b=zpe3rgsbAUnidN6ROKF8VtUE1U5c5XPbh7x4SZdfXTUgYbNA7ufZLioeGXcBewdnuk G3ydBB4C5nrR0XimP6sq+vzTx4j54MmhIahmdYwjSAy8saGPtEFMwz4Rsr+MIHs91cd6 yLum0kY7mNCPgkqHJXm2LDzCTFmmg77meUctypD3zG2rsvYWVCvphmyyhW5AH6mYkMYD MDIbuzV3pM7VTczm700Lqdi0ZGMHzdT5xgr8fbYM4Kluyetf/R5C4BSOZWcjcjZSuMMK X/WrRW59Yo1vND5g24JO6Gr9uoxyVx3H/kP4wJshi3JrcmGFNRnuqxV7mfrOZ4aZs4/2 5v6Q== 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=tp5pTOWuuUXNeQpz4jRFxwHC3MVnThhD9NnxijwxilQ=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=bM8OpvHTsqtHyezs+kgGpvS/wU0cQJVF5HosfX5ZPxHDtZ1M2wNQbtf6N6OoFnSN3I Gy9rmzWxZ5tyHAjKSZ2fPYdnyb00jMAqAbWGKyiwYckCl8MevinffZtymBGJc5ZOWJPv urvHEOQ5f+TZwfXkfQoxY4rtiTEli4aRFd+w6cmy/eOcR6iDiF0e6iC3BDaAXUEYee2B nojo/ZyfnHCPxSEkeGbaIwR+gwG+78yxR0qIf+WWVKwPa2HAa6ORs47ryqcMsKJ9Woqq lTtT7yuDKOgJwgecr+aHd7RMlr8N8unCevOcdH9xd1YqTnTqbfYy/h3C/JBJ7f2wlLUI atMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J5hitCay; 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 n17-20020a05600c465100b004051c85d769si947867wmo.152.2023.11.01.23.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:48:28 -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=J5hitCay; 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 7759B870C9; Thu, 2 Nov 2023 07:46:47 +0100 (CET) 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="J5hitCay"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C62A87710; Thu, 2 Nov 2023 07:46:46 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) (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 8A8388037B for ; Thu, 2 Nov 2023 07:46:42 +0100 (CET) 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-x22e.google.com with SMTP id 5614622812f47-3b2e72fe47fso380982b6e.1 for ; Wed, 01 Nov 2023 23:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907600; x=1699512400; 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=tp5pTOWuuUXNeQpz4jRFxwHC3MVnThhD9NnxijwxilQ=; b=J5hitCayIC5Zc2UeRLzGh4Z3xRU3ZQqMwM/4k9UgkEC3e07ZqFE94HJzdYCifscvOS CmHEvG7Sn4rQbyJiOJE78i/iqha1ZuC2sEAjokfB7/zxhUIZugaz2NOWhSh4ax3MaDE5 V0ibmH+lINYqsplwn/XuNrAWHnFNqrahlPq9BhAH0hrap7S8gQJaE8Uj1hf7Hqnsld55 +Jwlj7O8MgFxea2HZvRyfNbtldulSKUhLhFYfTtuytor5TJffS9VKW+w493OB2j0UCnF f3aHw2PBuw3TABLT4v9RITyA74jpTw6p+sgsmw7StM+/XMFJAUpPt/PcZXYYDITvqVsQ +DKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907600; x=1699512400; 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=tp5pTOWuuUXNeQpz4jRFxwHC3MVnThhD9NnxijwxilQ=; b=PDdnHkBqfvv+HpcpW34QTAGGvcdH/qmt5aX2h0FY714Gtmlr2QwyBSW4/fBK0avfF7 fFwAzRMCOVXU+qjZvqz+xnOaYmc1FYb6f2jEJeZdCooJQxmUgt3GvMJZ/8PRPORAJGa/ IchjKcxXIRYvetyWfsH9/0oO7E2ptARqqcVAzlk3ce+/+su5PV/AcQwWKW6iXmTC0gRe vKCcA+q14KGgIrxGNmsQl6lXFLhAF0cR505DTiqps7KS1zZxSdQgpPCPq4pR40vXRiRb fWaS2YgzDodyU2YReZUdvScuSbd3SQgq52WFTc1OUoJaTH58HGUlpwxzUesvBvxjyfd8 nVXA== X-Gm-Message-State: AOJu0YyQtKoQ8w9gZRiYEsFVAzJfnjcOJ/IcjHY/SLiE45XpCxc8+8+N IqM1+c1AvL2CIyb0cpgzzMuBsS1B0aaPU6F7t08= X-Received: by 2002:a54:4393:0:b0:3ad:f86a:878e with SMTP id u19-20020a544393000000b003adf86a878emr17212369oiv.13.1698907600299; Wed, 01 Nov 2023 23:46:40 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b13-20020a056a000ccd00b006c2fd6a7fe3sm2007251pfv.22.2023.11.01.23.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:39 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v9 7/9] efi_loader: support boot from URI device path Date: Thu, 2 Nov 2023 15:44:57 +0900 Message-Id: <20231102064459.3466953-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This supports to boot from the URI device path. When user selects the URI device path, bootmgr downloads the file using wget into the address specified by loadaddr env variable. If the file is .iso or .img file, mount the image with blkmap then try to boot with the default file(e.g. EFI/BOOT/BOOTAA64.EFI). Since boot option indicating the default file is automatically created when new disk is detected, system can boot by selecting the automatically created blkmap boot option. If the file is PE-COFF file, load and start the downloaded file. The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image and expose the ramdisk to the OS. For PE-COFF file case, this memory reservation is done in LoadImage Boot Service. Signed-off-by: Masahisa Kojima --- lib/efi_loader/Kconfig | 9 ++ lib/efi_loader/efi_bootmgr.c | 268 +++++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index d20aaab6db..5d99206dc3 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -479,4 +479,13 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_HTTP_BOOT + bool "EFI HTTP Boot support" + depends on CMD_DNS + depends on CMD_WGET + depends on BLKMAP + help + Enabling this option adds EFI HTTP Boot support. It allows to + directly boot from network. + endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..7b23b2dbf7 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -7,10 +7,14 @@ #define LOG_CATEGORY LOGC_EFI +#include +#include #include #include +#include #include #include +#include #include #include #include @@ -19,6 +23,10 @@ static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; +static u32 image_size; +static ulong image_addr; +static struct udevice *ramdisk_blk_dev = NULL; + const efi_guid_t efi_guid_bootmenu_auto_generated = EFICONFIG_AUTO_GENERATED_ENTRY_GUID; @@ -168,6 +176,258 @@ out: return ret; } +/** + * mount_image() - mount the image with blkmap + * + * @lo_label: u16 label string of load option + * @addr: image address + * @size: image size + * Return: pointer to the UCLASS_BLK udevice, NULL if failed + */ +static struct udevice *mount_image(u16 *lo_label, ulong addr, int size) +{ + int err; + struct blkmap *bm; + struct udevice *bm_dev; + char *label = NULL, *p; + + label = efi_alloc(utf16_utf8_strlen(lo_label) + 1); + if (!label) + return NULL; + + p = label; + utf16_utf8_strcpy(&p, lo_label); + err = blkmap_create_ramdisk(label, addr, size, &bm_dev); + if (err) { + efi_free_pool(label); + return NULL; + } + bm = dev_get_plat(bm_dev); + + efi_free_pool(label); + + return bm->blk; +} + +/** + * try_load_default_file() - try to load the default file + * + * Search the device having EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, + * then try to load with the default boot file(e.g. EFI/BOOT/BOOTAA64.EFI). + * + * @dev pointer to the UCLASS_BLK or UCLASS_PARTITION udevice + * @image_handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t try_load_default_file(struct udevice *dev, + efi_handle_t *image_handle) +{ + efi_status_t ret; + efi_handle_t handle; + struct efi_handler *handler; + struct efi_device_path *file_path; + struct efi_device_path *device_path; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) { + log_warning("DM_TAG_EFI not found\n"); + return EFI_INVALID_PARAMETER; + } + + ret = efi_search_protocol(handle, + &efi_simple_file_system_protocol_guid, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(bs->open_protocol(handle, &efi_guid_device_path, + (void **)&device_path, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL)); + if (ret != EFI_SUCCESS) + return ret; + + file_path = expand_media_path(device_path); + ret = EFI_CALL(efi_load_image(true, efi_root, file_path, NULL, 0, + image_handle)); + efi_free_pool(file_path); + + return ret; +} + +/** + * load_default_file_from_blk_dev() - load the default file + * + * @blk pointer to the UCLASS_BLK udevice + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t load_default_file_from_blk_dev(struct udevice *blk, + efi_handle_t *handle) +{ + efi_status_t ret; + struct udevice *partition; + + /* image that has no partition table but a file system */ + ret = try_load_default_file(blk, handle); + if (ret == EFI_SUCCESS) + return ret; + + /* try the partitions */ + device_foreach_child(partition, blk) { + enum uclass_id id; + + id = device_get_uclass_id(partition); + if (id != UCLASS_PARTITION) + continue; + + ret = try_load_default_file(partition, handle); + if (ret == EFI_SUCCESS) + return ret; + } + + return EFI_NOT_FOUND; +} + +/** + * efi_bootmgr_release_ramdisk() - release ramdisk resource + * + * Return: status code + */ +efi_status_t efi_bootmgr_release_ramdisk(void) +{ + efi_status_t ret = EFI_SUCCESS; + + if (ramdisk_blk_dev) { + ret = efi_add_memory_map(image_addr, image_size, + EFI_CONVENTIONAL_MEMORY); + if (ret != EFI_SUCCESS) + log_err("Reclaiming memory failed\n"); + + if (blkmap_destroy(ramdisk_blk_dev->parent)) { + log_err("Destroying blkmap failed\n"); + ret = EFI_DEVICE_ERROR; + } + + ramdisk_blk_dev = NULL; + } + + return ret; +} + +/** + * efi_bootmgr_image_return_notify() - return to efibootmgr callback + * + * @event: the event for which this notification function is registered + * @context: event context - not used in this function + */ +static void EFIAPI efi_bootmgr_image_return_notify(struct efi_event *event, + void *context) +{ + efi_status_t ret; + + EFI_ENTRY("%p, %p", event, context); + ret = efi_bootmgr_release_ramdisk(); + EFI_EXIT(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; + efi_status_t ret; + struct udevice *blk; + struct efi_event *event = NULL; + + 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)) { + blk = mount_image(lo_label, image_addr, image_size); + if (!blk) + return EFI_LOAD_ERROR; + + ret = load_default_file_from_blk_dev(blk, handle); + if (ret != EFI_SUCCESS) { + log_info("Cannot boot from downloaded image\n"); + goto iso_error; + } + + ret = efi_create_event(EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + efi_bootmgr_image_return_notify, NULL, + &efi_guid_event_group_return_to_efibootmgr, &event); + if (ret != EFI_SUCCESS) { + log_err("Creating event failed\n"); + goto iso_error; + } + + /* + * TODO: expose the ramdisk to OS. + * Need to pass the ramdisk information by the architecture-specific + * methods such as 'pmem' device-tree node. + */ + ret = efi_add_memory_map(image_addr, image_size, + EFI_RESERVED_MEMORY_TYPE); + if (ret != EFI_SUCCESS) { + log_err("Memory reservation failed\n"); + goto iso_error; + } + + ramdisk_blk_dev = blk; + } 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; + +iso_error: + if (blkmap_destroy(blk->parent)) + log_err("Destroying blkmap failed\n"); + if (event) + EFI_CALL(bs->close_event(event)); + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +471,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, From patchwork Thu Nov 2 06:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740434 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672822wrv; Wed, 1 Nov 2023 23:48:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNh/G4CBDSFy8EbDWoTWIxrrGSI4Znflv/CGKSV6fcRZWwYvcaIr4JlIL8Pttr21A7dlV2 X-Received: by 2002:adf:fb90:0:b0:32d:bc6e:7f0e with SMTP id a16-20020adffb90000000b0032dbc6e7f0emr13556850wrr.3.1698907718087; Wed, 01 Nov 2023 23:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907718; cv=none; d=google.com; s=arc-20160816; b=oUqqji9RTTJaK0LKLrsaQWHQE4+OSuYOpT9Pd1WnTiiVKQIw208sQJMSvrBcR80u4z SYAvrtP/L+z+3dXXrFroA/LJZVvJNdzGleVUCAMlSCzGXpKdd7mb9Vud1txvFOK/5ptJ ZQhC24r/BaNgsUIbBG9rGOftINBk/b66YmvKg5oBYN9heE5lnwyfpVBh5RijuyIGZRsH WuypaXxLds1dNHhc67Bg/ax6+wihjpAlfXAA5pA2cf78uOD/1+bcyyDzlQBPquR+KW3w Tpdn/erEkX81wI6JL/hJyDFGjSlH2OkkiLS+TmwgX7kjC8H/AP/6FCaxoZ4AfIp8+zq8 BBVw== 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=x3tGXQ7IJXQZQ/S0nkhUtkKMN2OsrFTTbgmtRgH9/3w=; fh=UwEaQaZSKscgV8VKorL4WxKMlykH7WzwOcMeBrHkxSs=; b=dscxJ256AkHeavCaHCd68+r4ZQTQoJ60Mt8bM6f9HvGxOgCT0RLXbt5hfjay4wSoft ylS2jyXTvTtCfKbIJYujPQxNuv7LY44jvA60bF6t9lnnaSKbreKY9MPw5CdIVnZ+W0w4 38nJFRDLYQaju4kbFgeVr0YWI86X7ps4CaTWFl/P9OF5Nlr6OTEZ3SDmb6gNab/0G0NR oMqvbgu4rmutK/i6XzciJ3kGUpuoRihfZylEKFixqCDmD2ird8NiwJpprtqp9FXUy+03 REjQdAEGKLehsxHTbQnfZjgS+8YAzL+QlEPMsUr2lXv0DS8ATmWWbXeO526tCgDHeTBa ptbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CJ2Ferjw; 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 u8-20020a5d5148000000b003231d835794si988268wrt.624.2023.11.01.23.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:48:38 -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=CJ2Ferjw; 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 D8F4B86E88; Thu, 2 Nov 2023 07:46:49 +0100 (CET) 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="CJ2Ferjw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3BA3876FC; Thu, 2 Nov 2023 07:46:48 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 54D6D8770D for ; Thu, 2 Nov 2023 07:46:46 +0100 (CET) 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-x229.google.com with SMTP id 5614622812f47-3add37de892so337618b6e.1 for ; Wed, 01 Nov 2023 23:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907604; x=1699512404; 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=x3tGXQ7IJXQZQ/S0nkhUtkKMN2OsrFTTbgmtRgH9/3w=; b=CJ2FerjwOd3eZi7TJNkogf35MD5KdL/YjkUNLLP14VhrwjQwrClL2+fhHJAAa3esIK J6jqF9Dv63r0LrjlodEhXfviffzPDpLO359SmQSwKRcOwP2VnxtGo7x8IUU7uxYi5QyJ Oh4FD26+iVBJT5Z6JCPzuIRuNxuCs10Sip6sweQBzZp8rKiP3IUKokPj2iBcLdjPMsrr 2Md21CX5w9HiycjhzSVTaUR3PZUUM5yEltUh0PXu9+PWp+A3RtdVNoI5vdz9vSnR/0cr qstSezulRTDn0mfV4n4IdU/hLMZ3yRVKW7CEHjRFt4iFc9q6El1zeSX8rf3P+xbbrXtC noHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907604; x=1699512404; 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=x3tGXQ7IJXQZQ/S0nkhUtkKMN2OsrFTTbgmtRgH9/3w=; b=j0YcYVo3AtQIISNIgOJagcfqJ79prY1Q+ssmu7NBBSkZiyYONZp9j++eW2s4VjcwYX Z1rd+WYxMn6PjJTBxyJAByCjYfvksjvPlktPQmCOq/cQv0keZfGOMk/zE5meVWm+JYtj 7rD7MbmxQub47EsNvwn7XC1s8aKxrGcAnRULZ62GW2wy3yFHkQ3Fs909KIOplUZMDK4Z GM47lAjifDKLYgNbH2WP5RetdHHs0xgpxVvdt9JByQr8zSAiojyQSu0+hgEv318Q3b8u Sj1AFpuNyVSfRYMOTeb0D/jxW1mKZOcG/iU33LOppo8j1W4AJmPXxCzd33e2X9CrtSQi ynng== X-Gm-Message-State: AOJu0YylBXA9Jf1kGfiJPUnKUeE5bXf8Q1I0fqJu+tilWTAosB9tKuF+ IU0rLWfVVx+2L1VjpHMb053Hbk/vnxVeKOn3UnU= X-Received: by 2002:a05:6808:14d1:b0:3ab:8956:ada4 with SMTP id f17-20020a05680814d100b003ab8956ada4mr19819338oiw.10.1698907604408; Wed, 01 Nov 2023 23:46:44 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id q17-20020a62ae11000000b006b4ca26f3c9sm2196052pff.74.2023.11.01.23.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46: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 , Joe Hershberger , Ramon Fried Subject: [PATCH v9 8/9] cmd: efidebug: add uri device path Date: Thu, 2 Nov 2023 15:44:58 +0900 Message-Id: <20231102064459.3466953-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This adds the URI device path option for 'boot add' subcommand. User can add the URI load option for downloading ISO image file or EFI application through network. Currently HTTP is only supported. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas --- cmd/efidebug.c | 51 ++++++++++++++++++++++++++++++++++++ include/net.h | 8 ++++++ net/wget.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 201531ac19..42b306e708 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -829,6 +830,53 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, argc -= 1; argv += 1; break; +#if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) + case 'u': + { + char *pos; + int uridp_len; + struct efi_device_path_uri *uridp; + + if (argc < 3 || lo.label) { + r = CMD_RET_USAGE; + goto out; + } + + id = (int)hextoul(argv[1], &endp); + if (*endp != '\0' || id > 0xffff) + return CMD_RET_USAGE; + + label = efi_convert_string(argv[2]); + if (!label) + return CMD_RET_FAILURE; + + if (!wget_validate_uri(argv[3])) { + printf("ERROR: invalid URI\n"); + r = CMD_RET_FAILURE; + goto out; + } + + efi_create_indexed_name(var_name16, sizeof(var_name16), + "Boot", id); + lo.label = label; + + uridp_len = sizeof(struct efi_device_path) + strlen(argv[3]) + 1; + fp_size += uridp_len + sizeof(END); + fp_free = efi_alloc(fp_size); + uridp = (struct efi_device_path_uri *)fp_free; + uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; + uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; + uridp->dp.length = uridp_len; + strcpy(uridp->uri, argv[3]); + pos = (char *)uridp + uridp_len; + memcpy(pos, &END, sizeof(END)); + file_path = (struct efi_device_path *)uridp; + argc -= 3; + argv += 3; + break; + } +#endif + default: r = CMD_RET_USAGE; goto out; @@ -1491,6 +1539,9 @@ U_BOOT_LONGHELP(efidebug, " -b|-B