From patchwork Mon Nov 6 11:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741368 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1035595wrr; Mon, 6 Nov 2023 03:40:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcxuyhj9y3lOVYLpoN+ur8WihIj5FVaoWyvfzU5wb2W/lakACthdfiXFnNhqzRH8rhL0FH X-Received: by 2002:a50:8a9c:0:b0:543:5116:b55c with SMTP id j28-20020a508a9c000000b005435116b55cmr16995561edj.16.1699270837389; Mon, 06 Nov 2023 03:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270837; cv=none; d=google.com; s=arc-20160816; b=I3FIj3OtAgNTWAjTDnXvXL4W0/VscHAPawy0NQqFNhp5ngpHWELXa8hFhgl4gsJ+9b 0RSKPk5ckDhJTd0dJ9I9y+TJbfoJ9avVokwfV9tXfEGGBO0eIxrlAIW303Kp+ZAIr1f0 iVOhYiT0YmVTOtw+zgoJJFJYj4dMGOXRYrwQCDXwHEgH7SurNTXROSdJ18joCR/gFLK9 Bu4dFUHCGUwF+T2VNiJxkr1C5agWQp82DAWYr1Bq7cSIO2GbFstJ50LefYN9i3hJKYP8 vmD1OvNdPnrse7GXayoLcIVRy8u5ZtEd2pKaDM6NJywN142Ird73N5P4ADfmk48yFo8D 5XJA== 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=TH5NSl0WgtdqavzX2Xt70vLIVsZ2LqoJ7DX+2al0C0r9o45W/eUB60Mht9AZaymJu1 Alyai7v/k7KYp7x9+lA8sizvOn29Z3mLu0D+zerlOZamiuaKZ3nvms0KVMYCLdLVa+Q4 h76jWqEanpS9/uV4vcfqhagCU7BkYYBS8MWCWcxgX/NKX9iWb0jD4cesEz25NWbm3ggp qHWVdQO6UOl3PLqTeyEwh2bbvNagQT3aYPe9y6x++MWe6m7g9VHoM5o393oul5GXok5K o5CYPmFM+thbENFaEmxwYsaPsrfomChegNAqqcZf6/ia1plAcLiQEF7VRUHaiuCgdMyS iAbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wqV2mED6; 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 u24-20020a50a418000000b0053daf001684si4494766edb.311.2023.11.06.03.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:37 -0800 (PST) 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=wqV2mED6; 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 3C38786BA9; Mon, 6 Nov 2023 12:40:36 +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="wqV2mED6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8759A86C33; Mon, 6 Nov 2023 12:40:35 +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 A511086E40 for ; Mon, 6 Nov 2023 12:40:29 +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-1cc53d0030fso34813975ad.0 for ; Mon, 06 Nov 2023 03:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270827; x=1699875627; 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=wqV2mED6QcTF/lhs9g6o+xBbpdeLqE8z8ZMX5aJGp/o7FTinqlnEKmixEZEgnSUmrH PY4T8X7QlRMKJhu5WSvG73zz2ynxB9/qKB/n6AuhXBJc/fE/0vy6GKbn7/jVWEIgX8ED b+2zwZheMSwAtQnh/uDNWu6QBByLf5/+vgxI1Pq6MtjCc53WEWAJRVPgvm4vgCbfRgHv U2EFZtHcgxPtPRB+EYEmTG6optuaLbhmbBW+Nfcl/SVAmJRLqoDrWldpwdu3N49cTT0b KDmnOBuNhTvkLovpzT3c43niaqpuugLnprFbcs7N7t8kkYU6EPsYZ1yBKPREch0rSIMI krOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270827; x=1699875627; 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=QDHcyjQ51ZGKfeD7ttYWX424wmTxd3HNsiF0F1VXYX6h2Ek/tpNrvT4oKVG03vhJqd FLRYlaDPKejZvrxBtUsv104ni/Kuu7zaSuJzDbpdNJL6mrSWhtu43I0FX81R1RxaAieN L4Uvj8AWCBO6WJGPGtKJNeMGXytC6ZxwOKIqBEJsee+u+7p1Ic5gXiaShEACmnEojSMj FCgvp1eep4BEU7liuUGBATxYhuks76eQIuHm/t2CMPoX1tRSH6Nc2pczem3FPTngN3pD 84bnLHyVeIfYXy3RThkZGQvGXRAUbSq+TAqdMWoCTFrkA86eZJxDmuuskQdc3gwC7AXL TWpw== X-Gm-Message-State: AOJu0YzMzKrJht6EjJGAZU2dnFI2hggirTUSDfDu48qJHcEMHcBc7H4l XZHdywVMuXpkAD/NF6O4AWwnDxgymFKqGQ9U/XA= X-Received: by 2002:a17:903:120c:b0:1cc:467a:338f with SMTP id l12-20020a170903120c00b001cc467a338fmr15655173plh.4.1699270827119; Mon, 06 Nov 2023 03:40:27 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b2-20020a170902d50200b001c60c8d6b4asm5730856plg.149.2023.11.06.03.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:26 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [RESEND PATCH v10 1/9] net: wget: prevent overwriting reserved memory Date: Mon, 6 Nov 2023 20:39:12 +0900 Message-Id: <20231106113920.3631591-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This introduces the valid range check to store the received blocks using lmb. The same logic is implemented in tftp. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Ramon Fried --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 8bb4d72db1..6f97eb1d12 100644 --- a/net/wget.c +++ b/net/wget.c @@ -4,16 +4,20 @@ * Copyright Duncan Hare 2017 */ +#include #include #include #include #include #include +#include #include #include #include #include +DECLARE_GLOBAL_DATA_PTR; + static const char bootfile1[] = "GET "; static const char bootfile3[] = " HTTP/1.0\r\n\r\n"; static const char http_eom[] = "\r\n\r\n"; @@ -56,6 +60,29 @@ static unsigned int retry_tcp_ack_num; /* TCP retry acknowledge number*/ static unsigned int retry_tcp_seq_num; /* TCP retry sequence number */ static int retry_len; /* TCP retry length */ +static ulong wget_load_size; + +/** + * wget_init_max_size() - initialize maximum load size + * + * Return: 0 if success, -1 if fails + */ +static int wget_init_load_size(void) +{ + struct lmb lmb; + phys_size_t max_size; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + + max_size = lmb_get_free_size(&lmb, image_load_addr); + if (!max_size) + return -1; + + wget_load_size = max_size; + + return 0; +} + /** * store_block() - store block in memory * @src: source of data @@ -64,10 +91,25 @@ static int retry_len; /* TCP retry length */ */ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) { + ulong store_addr = image_load_addr + offset; ulong newsize = offset + len; uchar *ptr; - ptr = map_sysmem(image_load_addr + offset, len); + if (IS_ENABLED(CONFIG_LMB)) { + ulong end_addr = image_load_addr + wget_load_size; + + if (!end_addr) + end_addr = ULONG_MAX; + + if (store_addr < image_load_addr || + store_addr + len > end_addr) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); memcpy(ptr, src, len); unmap_sysmem(ptr); @@ -248,25 +290,39 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, net_boot_file_size = 0; - if (len > hlen) - store_block(pkt + hlen, 0, len - hlen); + if (len > hlen) { + if (store_block(pkt + hlen, 0, len - hlen) != 0) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } + } debug_cond(DEBUG_WGET, "wget: Connected Pkt %p hlen %x\n", pkt, hlen); for (i = 0; i < pkt_q_idx; i++) { + int err; + ptr1 = map_sysmem( (phys_addr_t)(pkt_q[i].pkt), pkt_q[i].len); - store_block(ptr1, - pkt_q[i].tcp_seq_num - - initial_data_seq_num, - pkt_q[i].len); + err = store_block(ptr1, + pkt_q[i].tcp_seq_num - + initial_data_seq_num, + pkt_q[i].len); unmap_sysmem(ptr1); debug_cond(DEBUG_WGET, "wget: Connctd pkt Q %p len %x\n", pkt_q[i].pkt, pkt_q[i].len); + if (err) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } } } } @@ -338,6 +394,7 @@ static void wget_handler(uchar *pkt, u16 dport, len) != 0) { wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); return; } @@ -428,6 +485,15 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (IS_ENABLED(CONFIG_LMB)) { + if (wget_init_load_size()) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + net_set_state(NETLOOP_FAIL); + return; + } + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Mon Nov 6 11:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741371 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1035991wrr; Mon, 6 Nov 2023 03:41:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IECZ8rm8wc8/d3kkLdfUZcbXeoP1Du7/giMWN5Lhz44gL2t8wBXpLxN/LsQArPaGLoHGVwp X-Received: by 2002:a17:906:6d0c:b0:9df:254d:3e45 with SMTP id m12-20020a1709066d0c00b009df254d3e45mr3090446ejr.24.1699270898388; Mon, 06 Nov 2023 03:41:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270898; cv=none; d=google.com; s=arc-20160816; b=G39vTHASiDIJYxk/6IWYsGA7eNrJwzyPGUKI6L8tlOuJPz6RPYYo85twDgep6ruKKn pAWBFC+NNW6FYdCmqybE6wA1W1wZtQsh5TYBTe8YOzg+ZC1WMvTSbA88bqM6CK1zISUY FkHIPr1xEeDQo47siDtBXQVqAjn2OOsaDIXt9W+rDu09jmfDNHyLL+yd//zSCggKrqFP IX7y/5HarvcOgHQUrmjPpBi0Ly44iD3E+9YphMikENH8RDgNSfu61zrRnmt8WQLyIkdI Fh6VzACnYN8di8vGbmBHrhm4JBo3iBrGe4h1l7n9lOazuEIhWX+n1JD2yw/wB1BnPRlv e7rQ== 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=LnR1lmEWLbIPMBrPMcn771ZhaSViLrQUp2Qr0ElRaz46WOZT820WBtZ3nk3OPRbZh+ Sf8dkxKUdqwd2+RUOqzyEIecIeuTYwU/Caf9XcMgVxbZ5I+X71lXk8K3K1v0L0CX87RS sea2R7qTwXXledZps9bN4CNC5gDjEJGL6Y3b2yE872m0Ky54PAnAlfIVsiUAwKM/R33n n6kjmb9SAZW01rRhxvdio7lckkyo9voP0Sa6jXnxNgM+e2Y9IQC6Nn/WjVMdaj6Fzagn xsYQEThv8QbHzo+Yc/ZuynAnVW+4+JwgKq9DfKJBxnNyZtVFarV80Q+hc7sX2NM0/+WR vYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZM4fmkxa; 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 e25-20020a170906749900b009922cdfaf62si4087027ejl.42.2023.11.06.03.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:41:38 -0800 (PST) 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=ZM4fmkxa; 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 63F4086FF7; Mon, 6 Nov 2023 12:40:37 +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="ZM4fmkxa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B6AE38653E; Mon, 6 Nov 2023 12:40:35 +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-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 69C1786BA9 for ; Mon, 6 Nov 2023 12:40:33 +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-x62d.google.com with SMTP id d9443c01a7336-1cc29f39e7aso27453935ad.0 for ; Mon, 06 Nov 2023 03:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270831; x=1699875631; 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=ZM4fmkxat6q5m3uZNmDecL6N31sTNVUG+Hoax2bC9Plhx6o2+f3hb0/GcxsFAqAixG 1V+SxNpPhYrSgDf72Hl2/Dum75NivHAODdJQSsDFhJSvuKqNGTzFdnD13rEPz5XTluj+ Jq+olNoF7xGHUaV97nI4LkIFptHZUlwKholXv61yKNiP5IWc0wU2cy1+e6EbgN6R13Jv +HRgX/ryjQbB7DL744VjEYoAgC4UwvMYhuNoEV5LzkTzZUHmBta+mXMn5SnO6+hvi+41 TC1R1NNhQ6GRQqyfR4CJxwBUXBEoxv+jXf0lKSWJuX5MzXcZCDTkLaK1R4kKg5bC70Yr Mx9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270831; x=1699875631; 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=sdS4nTSG+F1im16v3vS8hTctYhOeOfYqX/3WIY2m5jPll25+XvggV/6CipqTXeXUO7 o4D/cLnvJBGsIBMN1BUbSXVSFJJP/BsYtXRKzW94nYOqxC8HsDlD+ipLR934k0O4esGM xGeNkGOxZRZlbfowqxVrHAwaXTqjpTeo4iRrCXi4KxkgEFXD7ygNAZEMboP6+VbgiWAW Jgvcu9bHpW4TnpAQBpdNnybkvHKWLZb3j1ar+AF5XIX5sU9Ul43evXBPzyjDgbX6Y+WZ jhnPVLvF7fbIe6q7jUiDncGwZXX7mVkpJgejXHdfAVhhjApod/2JmTKEIUy5gDs0BMQ7 KmMw== X-Gm-Message-State: AOJu0YxmA3wTwKd6M2v80IjCWa+DWCGJM4nL3BDqJbX55Lj4U7tl3aTD uagzA2R6kYSLSi3zewohh+uzLohWnoFs18muCDk= X-Received: by 2002:a17:902:db0f:b0:1cc:5ef7:e3dd with SMTP id m15-20020a170902db0f00b001cc5ef7e3ddmr18197030plx.47.1699270831326; Mon, 06 Nov 2023 03:40:31 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id e19-20020a170902f1d300b001b9da42cd7dsm5745534plc.279.2023.11.06.03.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:30 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [RESEND PATCH v10 2/9] net: wget: add wget with dns utility function Date: Mon, 6 Nov 2023 20:39:13 +0900 Message-Id: <20231106113920.3631591-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Mon Nov 6 11:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741373 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036057wrr; Mon, 6 Nov 2023 03:41:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGF1l0y0l6ZO6bA/0ujfWAYySTtHNat0+ixpHJ/X9F6tQ51PCK8A42t22i6UF5e09cHmLFi X-Received: by 2002:a17:907:c16:b0:9c7:4dab:20ea with SMTP id ga22-20020a1709070c1600b009c74dab20eamr14036616ejc.67.1699270910504; Mon, 06 Nov 2023 03:41:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270910; cv=none; d=google.com; s=arc-20160816; b=E4XVtJMghc2yvLMAQ2tfFjs9oUmA8nZpLNvGZ2cp7si2BdaHWgkBtdHhtp0ZJOy164 ecN9mSMv+1EiSN+5x2CI8+B6t6qqeHJ8qKywLy3lfFK7eAvAhWh2V5cpkbJUbs8sRD0R kGMzTLFaGE9Oiluwmoc8gWWuvBEE35ejsCLy3Z5xv1aDtrU7lKtJjS0eN6YWbUYUZSrc 9jaPGU1oPMOUpPHSDJ2Vn5WDuIZp+mQvl7LLjs1anRA1LEYVJ3fKy7xOj6vB0gGmYCuz hs7fculdsZ3NGfS1GM0t1GKXlsITB1zSiF7ms7O9+aScnZdBBRsLPyNds6Qcp2cFYj8j XguA== 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; fh=zqO2vTczeIKx1OTsr8uErpGVOeopTGT8suxWOXUGpbQ=; b=eVeoX2iAZ6+ylqYCeu6kJAbZcwP/Jp4i6TMGQxenfpWTtamaB0rR/aQkbhnyD4dmvc Fakjj2qi5S+Ux7+Ipd/1yPdEt/B5wA3P+O7t2z8g/SUNYuXlO+5iwjOK9FElBvelrj7Z TX19RC1f9DXSspi3CHnZlHgCxGnRyiNeA4iIQpI5KdhQeZm8wJOq1uJLlBFNUS08mRcT dw7rgjVSPmxURq8GRYY09CYRDPR+RG7r+Z/b251DprUMS0F9WGXq0mvm+VmB71OMqstx isZzS0MR/wlP4/P+3eSRO4XnJ3YjnaRd/4WZjUMfpCPFioQ26ofoodM4ZhZ3Rx2Z37yq u3Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jhIMNfAU; 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 i7-20020a1709064fc700b009cc6c92cb8asi4709266ejw.35.2023.11.06.03.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:41:50 -0800 (PST) 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=jhIMNfAU; 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 E648D86FE5; Mon, 6 Nov 2023 12:40: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=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="jhIMNfAU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 019268653E; Mon, 6 Nov 2023 12:40: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-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 6BBE686FE5 for ; Mon, 6 Nov 2023 12:40: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-pg1-x536.google.com with SMTP id 41be03b00d2f7-5b7f3f470a9so2789783a12.0 for ; Mon, 06 Nov 2023 03:40:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270836; x=1699875636; 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; b=jhIMNfAUZuLf1o38Vk28yN5tEbDftIBrqpwh06GdIT8mVaSrsM/VxGqihb6CeCWeMy fQPdfQZZMrHwUdtTAffoabl6ajf3h3Xf3iOUMOre5nrd4fTIC5zdVOEE8SekxtWJuzur /htXkcCfimSXl3Rayurin/sgQ8oEOq29hvF6xXTEfrtVoDgYVp2U748SKWa+rD3x8p9u VGOFY6CkE5r7tvLgkYCJW5auRZeuMmpR8VjJl2/X3wnH1+UypIRm0a+8umFuGU84dSNQ l1I31de/ff43sSxH47qFZZzj16CYqqclyhSUI54pFMlor5+pgHxPAsAzX60HtJc03Dxz 37Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270836; x=1699875636; 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; b=fG68d9NsoDzPIBdT5mwjld6ySVsRE9F5Hf/uXRJknNo6x4q7btxBMeE/7wdS1Vc7H5 r2zpG7rPAqOAF47dWyswYOSS+itkT363AXuU/d53ebDdGqC0c73ZEtrnbfPqCaecqp3v D3y0ucY8wpChy2oUMkiR4mUh5mFCvsAFezX+Ouu2Hib9F4Sq7njbEHCKclrcZENqgyab xMoYJD/gyzvabk58aRat7w9eGi1rS1QrQOjECYm9FxuHrKYXKJ4cIWcaA8xCzD6jIdUA 4lKYds+fIyvDV5aobIo+ylp6z3JEz+E+vl3kG49B2SYw5orYVZxZ2tG/OyEW512YoRwR lHdw== X-Gm-Message-State: AOJu0YxQ/8QDEEcQ0q3I+rg7uOg0Bt24lyY8dvI0geiw/4UJ4NFz4LaR f62qSm1ZfqOln5ZhxSlYi2IdV8NAMONwv68d3s8= X-Received: by 2002:a05:6a21:99a2:b0:151:7d4c:899c with SMTP id ve34-20020a056a2199a200b001517d4c899cmr27607993pzb.25.1699270836455; Mon, 06 Nov 2023 03:40:36 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id iz7-20020a170902ef8700b001ca82a4a9c0sm5736266plb.309.2023.11.06.03.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:35 -0800 (PST) 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: [RESEND PATCH v10 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 6 Nov 2023 20:39:14 +0900 Message-Id: <20231106113920.3631591-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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..bfba14110d --- /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, ulong 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..30dc84a7da 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, ulong image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Mon Nov 6 11:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741374 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036144wrr; Mon, 6 Nov 2023 03:42:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/dLFbmWvf6tRfuxJ6n+2lY5jBo42zNNz+iVXsOjS5hd4K8bNi1M8nlzXk04WDGQ2xSNrz X-Received: by 2002:a17:907:9309:b0:9d4:2003:78dd with SMTP id bu9-20020a170907930900b009d4200378ddmr13142503ejc.70.1699270922476; Mon, 06 Nov 2023 03:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270922; cv=none; d=google.com; s=arc-20160816; b=X5H45yjt56Vvfx5R0CJokkEAZBEF/CeIA+XU0qgm15Jmizm5+HqmmCZVKuC3rwqhQ7 JrzAk9xJTaTgD1/9IHsWqeCsVmcL6Dm2XnVWsKbx7iMhgEEfuSfx6LZj/r+Q0Mj0HMpB aeSg5TRHjfRKN1LfKSytTGCjNoPK1WNh8fLFn2gI5yB4+xQtAGzyl4qczFKQz9xNCc3X awoSpL5vCZ7Fi2YCEAfIyqLw5EcOA6CHlyKo8B5M2hUe8714eqecb0CSF4dfEI8raNau D4hgDTRfBB0+kJ6Qs/L8WaRJiMLEUXxWOuO0D3ujsako7eqq/J+gQfgJ2ZNehkAfVbpg lGlQ== 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=TMp02tF2/jn50c0fdB6OUXNmWJ9Af2C5T6zhn2D5BPI=; fh=WkbrBhoSjxPIMjJ+K/VLBijITlZ/V0UU3jICrPirUsc=; b=ivVbqQcOr0n9Ankq6z6gCBVjN4nlmG9gW0PYU7vYWU3WLzntOpN4S19EQhynz1GICx sinRa7nVi94XhuZYfqKDWWNtFMukSWUiXslux06UdtftAlZq1H3qKi4N3NNnqT63zyNK NhCgvMyJHOM1DIF2uqRftk3b2HmzqaLgbj5i0tVuV3ZZKHwaVMdiCf+qgIM/37ilUSzG UBkUHYsOdpHQ1As3J9iZUqUoMU3CqFvtiU/UTtMNcwcGnJ/toa5fWIyvUAiUhXfJ5fbe YLINY1JORQD2KkwcOlcdBgFTk62HbhuJb5CGpipvOjqk5xjkQkcA/IPxDs6nPH1QWi4Q 568g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sr1JhnSd; 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 dk4-20020a170907940400b009bfa6d05373si4428392ejc.719.2023.11.06.03.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:42:02 -0800 (PST) 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=sr1JhnSd; 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 E285F87005; Mon, 6 Nov 2023 12:40: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="sr1JhnSd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF0128701C; Mon, 6 Nov 2023 12:40: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-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (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 B0B4A86E40 for ; Mon, 6 Nov 2023 12:40:43 +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-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5bcec7a304bso3379445a12.3 for ; Mon, 06 Nov 2023 03:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270841; x=1699875641; 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=TMp02tF2/jn50c0fdB6OUXNmWJ9Af2C5T6zhn2D5BPI=; b=sr1JhnSdvTrXxdy89nsWTktdhNGDL5O67QBsWxy38P6KXvE6wH/bDjwvw7ZM86y0Ro 1edOZjOCKK8wNECJpO67uPP9Ygsr44/J77rlrNgzAtBVB9zw5e5YIGWUFzQnpESaCgb8 4mikX/dNECnRVgIU74IGgbUhGYOen+GpIHRmji1abjFDBahugkB3tPDpjVpmlim3rgZD +Ka2oGEN9x0/2mBEsoBmwEYWoPgONPLXPFQgQXc8fblsuKYNY5vOmSMfmyRpZeiS4f8y b1c6LTSZhGjO1Y1ob3cVycou7T2WG9jejzz4TeCm0V84i3zuKeu2V+kuZqnCIsMjDdPT DGTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270841; x=1699875641; 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=TMp02tF2/jn50c0fdB6OUXNmWJ9Af2C5T6zhn2D5BPI=; b=CCJQeRfdvSNbEmoqLLXP7ZyQrMoHjB+kh6tjFNfNRHY0kkCHiUr+4SVGUJyLp7xJxY ktmI7PtFGjWAEiI+meUx4Oki14rRbOzsC9zgF6a+PxK3Vv2S7DrH+TqGVoj0NluTyQZj 0Tsj1j2hFAOMpGBibrlIsayID+dnwjfyzcb+SW4EqOJ9jySaYsPoYwUeOzZUqVYhrigh f1FtxzRjC6TCA+Zb2HTlZtoc2xhI/NIIQ7U4DlnhqnoMvVBDp8bGIU4yp3LLjy8ykOFf AO6pL1F0ePkkAbQTETt1967qhS8Qjdo5KuxWguz+SbmGBGfCoBeuaFKUQlzpOsRfg4eM Y25A== X-Gm-Message-State: AOJu0YwQ45hwgJ5cTA5KDyrwinJougbMQeYV6QLZHpQUuOhlIjhV3/6N auN2zOC57lUPe3zeLTEFQtOkY0+k9o/1MLjj8DM= X-Received: by 2002:a05:6a20:12c4:b0:181:275f:3b4f with SMTP id v4-20020a056a2012c400b00181275f3b4fmr16503100pzg.11.1699270841495; Mon, 06 Nov 2023 03:40:41 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id j8-20020a170903024800b001c9d968563csm5700803plh.79.2023.11.06.03.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:40 -0800 (PST) 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 , Huang Jianan , Thomas Petazzoni , Miquel Raynal , linux-erofs@lists.ozlabs.org Subject: [RESEND PATCH v10 4/9] efi_loader: Boot var automatic management Date: Mon, 6 Nov 2023 20:39:15 +0900 Message-Id: <20231106113920.3631591-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 and erofs ls tests are 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/py/tests/test_fs/test_erofs.py | 9 ++++ .../test_fs/test_squashfs/test_sqfs_ls.py | 9 ++++ 7 files changed, 78 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_erofs.py b/test/py/tests/test_fs/test_erofs.py index 458a52ba79..87ad8f2d5f 100644 --- a/test/py/tests/test_fs/test_erofs.py +++ b/test/py/tests/test_fs/test_erofs.py @@ -196,6 +196,15 @@ def test_erofs(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled and initialized, EFI subsystem tries to + # add EFI boot option when the new disk is detected. If there is no EFI + # System Partition exists, EFI subsystem outputs error messages and + # it ends up with test failure. + # Restart U-Boot to clear the previous state. + # TODO: Ideally EFI test cases need to be fixed, but it will + # increase the number of system reset. + u_boot_console.restart_uboot() + try: # setup test environment make_erofs_image(build_dir) 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..a20a7d1a66 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,15 @@ def test_sqfs_ls(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled and initialized, EFI subsystem tries to + # add EFI boot option when the new disk is detected. If there is no EFI + # System Partition exists, EFI subsystem outputs error messages and + # it ends up with test failure. + # Restart U-Boot to clear the previous state. + # TODO: Ideally EFI test cases need to be fixed, but it will + # increase the number of system reset. + u_boot_console.restart_uboot() + # setup test environment check_mksquashfs_version() generate_sqfs_src_dir(build_dir) From patchwork Mon Nov 6 11:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741375 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036207wrr; Mon, 6 Nov 2023 03:42:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGK3FdmZWKz3bmrCgOmCtiHrMRpLFbSrRut6BJfpwe6UCHUEJws+LsyMMr184bNkyuA9WaG X-Received: by 2002:aa7:c68f:0:b0:53d:b59c:8f91 with SMTP id n15-20020aa7c68f000000b0053db59c8f91mr23515957edq.27.1699270934688; Mon, 06 Nov 2023 03:42:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270934; cv=none; d=google.com; s=arc-20160816; b=DM72/5IBtMrrKlcsQqg3KhzdYR72ZUA04bZxUMqlvfVTfuUbwzZwYkGJ8nBHFJVC+7 BJAtSTtyDZB6Wy31zLWg+C+WaHytOgJxb0NUa483D+7g3OpS3FCJAaQRRANRfahoU3HQ a9lCd+EEBX2IiK7WOL+BR13n9BUZGrQBXTqD7a+sWWd0c504JVEbQy2Dcj68ATPS7/4S L2laovmc36UqPxO0Nm4OsGKcJhb9BD0aY1DgjulL3Lv0VOOLF6uUzkhvA1oewZIzxdvP RhUK2tW9SFWNx+Az9f5aub907Qq9vcb9mrlOlHOeGVJnz1HYhRPvDlJPEVsR9DpWLGW5 QM/A== 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=AkOk14+cUkmTCLZdgvgP050yc2BoHQLrc88kjtUwoA0=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=QDHeJSp1cmRHRjCpKmPU00PBct5tdNNxsQ8VX26UNJPiMWzNItGAvbn31UQmHI4nBH WgNNBmfrRCGyup2VDyukminXkw02xCEV8PM0LnDjMEw8MLisSQqFfRNHpcLNnm7sWsYY GpsAsaBy4VYAPBaoP7uRcIgXRcNoNhxXmv7CO0Rz/JSAL3YDnvYK5WNo4yrpD6gof1j0 W2inLQZZvvwfE1TGXxMMlAshDmL5s2CbgdSriahGj8Tt+FT0HhwM78YQEBO0/ZtsPVTJ aIViTysb9OwvPSHha4566k9CE507QFErz7XHEfm4sfGArw5/C2Fy+pJCMc4gv3eY2QiJ m3Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k00+xSLK; 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 p29-20020a50cd9d000000b0054365df4eb7si4190818edi.487.2023.11.06.03.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:42:14 -0800 (PST) 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=k00+xSLK; 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 71A2087073; Mon, 6 Nov 2023 12:41:01 +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="k00+xSLK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDB1587030; Mon, 6 Nov 2023 12:41:00 +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-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3DD9687026 for ; Mon, 6 Nov 2023 12:40:48 +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-x42f.google.com with SMTP id d2e1a72fcca58-6b2018a11efso4514785b3a.0 for ; Mon, 06 Nov 2023 03:40:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270846; x=1699875646; 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=AkOk14+cUkmTCLZdgvgP050yc2BoHQLrc88kjtUwoA0=; b=k00+xSLKQTnfMc64iB0eaK5BwIgE3sw/asvxdVlJ7kdq6nLedwE6cExcDp/qXwEQ0Y 6tS7eANlib/RSSxxDN7QZMCgXOwKV4gvP1VnOf7i236M+iKs438YiNRD4F0R3i68hZTd BSDdBj/nMF0llvnU4pLYuEz3M49bQPUk10Tuq8UDo9DuOMOi1FXe+FcQ3StZg9jquaE5 VIwad/8N+9ZMwb1y4mpJACO19VQaz++rrQipO9QUrv5NafIlVsDJjlNUfLSLsZjPAXDM dscE9cpb12583C01UXgUgTVo64qEY8OmcKRFvrWi2kTvEMR0y5yD8qLGAob0OOd1dn3n YNcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270846; x=1699875646; 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=AkOk14+cUkmTCLZdgvgP050yc2BoHQLrc88kjtUwoA0=; b=g+Uy8dP3ZXueXSxJW2cyB+Mcxjl/MB4JZQbtZ96wB25DOPfVXAulWmtOyaXbzofKmc dL5vUdJeQvYGYIZGXJp+LJFo/yKsuXX654QfSKDBYwu2MPz3fZ2LJ3J31vjGHyHC0I3Q zTXDlUZ6JzWyh7D7nuwZmHFBL/xrLW1e14Y+lS4fSLooNMfdK/bRzxXWQn/r/cJCI9y5 IhvzAdVl/DGP2sL0xbrZdZ3QHDSD3LYY1JxtSQtiiQTBkwjnnYXlsc4jD6OYT3BzuiLT T9DAX0VGZDb4DMlaOiWqrzd1wP8jIjWlc/FOR+C9Y3cjsf5Sn/m2XudXKKDFUZFQdMgj A1UQ== X-Gm-Message-State: AOJu0YzVTbEciZR5mL4QOoGbmZ2I/p6gS0GpZv8Jq9duuojKEAd85BBk be4k9SrJ0h9WVyo48foFMPyxLmNLDypwM88v700= X-Received: by 2002:a05:6a20:7348:b0:17a:eddb:ac6a with SMTP id v8-20020a056a20734800b0017aeddbac6amr38052000pzc.6.1699270845877; Mon, 06 Nov 2023 03:40:45 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 6-20020a17090a018600b0028009de5c65sm5836999pjc.39.2023.11.06.03.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:45 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [RESEND PATCH v10 5/9] efi_loader: add missing const classifier for event service Date: Mon, 6 Nov 2023 20:39:16 +0900 Message-Id: <20231106113920.3631591-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 Mon Nov 6 11:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741377 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036348wrr; Mon, 6 Nov 2023 03:42:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyrHdPdpKO26v3XWyGcGygkEnMJbatv5SloO8gaZKiZ115AkPdVMxSs9nqKYA+qGePyFsO X-Received: by 2002:a17:907:3f08:b0:9a5:9f3c:961e with SMTP id hq8-20020a1709073f0800b009a59f3c961emr9139304ejc.18.1699270957534; Mon, 06 Nov 2023 03:42:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270957; cv=none; d=google.com; s=arc-20160816; b=cK2qOmKi7SvO1KoHhbCnlcF3Nt2ODf2hKCzbfFNBYHeavNpfTqf2hZAMtLFa/poUUK eeEl1eCc3zAmG+WO0o2a4IueI3SKaSGt1wd1uCPfnrP040eQVIW38VhkM438IMDB6gC+ 3Rof+4EJIdIVk/uj2PjfM1o+h28+cVWxZMlcdJGBmeBIVrrJgPC8ODWz4XEPVL04bHa7 5fWS+Lfro91m9iD42CPyKHOtHCPY6o7IAdlVm9a5/PgkpEkg1cJMom3YeTMwUNouvLFF dDnEstqam7BLGFrcUNWXA6LXAygwukctBo0JxAdYpOez9eKPijPbVp+PEUncv3Hu2XpT NV5g== 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=bKRfTkXsyxHbAbfC2fDvqXQoTddGeOCmf5imGSOro/k=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=apDCSpqDTjkf+AqbfCKbJvMdu1ficZAjlJZHyZBHtkQ+sW+QNSxCnyWz2cAe3ci7hi w3OMcH4/eVo+6B6o9BhncNkhlsuv5nbkDBj9UbeO3zMXZhIvn7lu5oa55uBSMZmHk54y Uc3UHoVeK4xuzmhmVfimlsZ3n44ui3RKUF3mroVmo/91dVme44CO31Wo9GlYqLSXeG/Y KNr/mCYqI1nueCXzCWYiqAUjkLpmPYUqxK2G+q+jG1YORnsv+HDZUyTYx9Nb5GJLTHV5 0nTZaiiEQ/muwM1Rr+Vyg+yk/L4zVfVc2cMc609fgomCkDTfSTPN4ey4I3zvJ0EkemOT WIwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wcu2jIAo; 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 gn25-20020a1709070d1900b0099381745ba0si4765324ejc.156.2023.11.06.03.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:42:37 -0800 (PST) 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=wcu2jIAo; 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 6244887026; Mon, 6 Nov 2023 12:41:29 +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="wcu2jIAo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E65FC8653E; Mon, 6 Nov 2023 12:41:15 +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-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 82AAB87049 for ; Mon, 6 Nov 2023 12:40:53 +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-x42d.google.com with SMTP id d2e1a72fcca58-6b497c8575aso4691255b3a.1 for ; Mon, 06 Nov 2023 03:40:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270849; x=1699875649; 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=bKRfTkXsyxHbAbfC2fDvqXQoTddGeOCmf5imGSOro/k=; b=wcu2jIAo6rwE+z/OHSYaViKp3+9gsAIXFMqzqIwvjylTtamp799QA0q0vrjZJM0Mke ucUM1fjsQo5Jzs89JYx/BwdX5UK4B5rHDiGT1mAUpKPjcEURaCqfSds+Ju/3IkYivuUS +nRJb6YTRcxiJqFJqh/3UvEHtZC5Xj/sQXIjtgncdlQWBc7chaHGMUTfBLh4E6o+nMoD hw/lPWKkOLga3hJ2bAc/FgsMt3YYbM6TkLRl2nCJHpA24egaLRrDE1Gu4rKmYNknMXcV qiJo/7r98NoUiYybDrb7x59qgMyJJINxv/sLFKilJQBb1EqtJSdaQiu3cTfct5onPCy6 /9QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270849; x=1699875649; 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=bKRfTkXsyxHbAbfC2fDvqXQoTddGeOCmf5imGSOro/k=; b=euLCokc52HUh66L07n4p5Lth4kOrUvytej1cJi5+Jiz8xmz6aA6JvhiUiMJvc2zaJq E/PI6fQz1B5iqTjGf4cZUn1II2iqCxrVBgBJec7QiSOmIeOdno6JT6VWmQxtZk3lv1oo S9NyYk8uBrAgTSGxYa3EO7d4zFGDwEWHWijnQ46l67dLS8baFtsXv8mEpQHOMw/oy2UR Qodpc0RZ/uwYuws50PvaHuDEoD5rgX++DQ0bvki9nMOf3vT9uk/h81HqOk+tdWuqsWeW fXUyYdZ1C/BwjgpO1QZU8i2rwSToYWi7rU6Gj73Y2Q0y4SM1UQxi7uysb/I3U5wh5uqT 3wlw== X-Gm-Message-State: AOJu0YzvSxWAurik4roGR5okprxcePEfAcCu3fLnbZW2YpaFAUQqOH0p FG9s1TqmO1SleVwqy+Yqz3JVunyxnBxmn1Izq/k= X-Received: by 2002:a05:6a20:c1aa:b0:17b:7505:8ab7 with SMTP id bg42-20020a056a20c1aa00b0017b75058ab7mr38922034pzb.46.1699270849227; Mon, 06 Nov 2023 03:40:49 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id iy10-20020a170903130a00b001cc3a8af18dsm5740147plb.60.2023.11.06.03.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:48 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [RESEND PATCH v10 6/9] efi_loader: add return to efibootmgr event group Date: Mon, 6 Nov 2023 20:39:17 +0900 Message-Id: <20231106113920.3631591-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 Mon Nov 6 11:39:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741376 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036278wrr; Mon, 6 Nov 2023 03:42:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZslHHr+d1Syl4c/Y0HPQVhY5aVIYxJYvfLEhhQwW+9+rHl4YlJD51ljSL8PECwrXKRJ9f X-Received: by 2002:a05:6402:b52:b0:53d:b71d:34a7 with SMTP id bx18-20020a0564020b5200b0053db71d34a7mr21797818edb.6.1699270945965; Mon, 06 Nov 2023 03:42:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270945; cv=none; d=google.com; s=arc-20160816; b=XJKc65qahhRFVlUkE1RO1mQFKqzCItE43WulcPoag4tVsasYgGcAKUfNln2g1e+M6A YDE5ce+Hp/SmEFPYy8qg8GQzrmk+tF/ueArRQRZ8aSX5Djj8+9fcCKuDIGbh4K5W4NuP rvnf1fIUXAvIdHUoeRQxeOvNEF9nLBYGMlh/fuil900yZQYQp5bY6uHK7UAYmq1pSf1I +gHb12QafyugRgOQZkOJKodIur7MYhdQy5sCcsQtcv6VE675qMiegH/XyWectP6A3znn F2nM9O5S0WUoSRjid0j4TAeWJCYX6oAG4EZj4WCsPjxP0LYbvLxwvrdtXO1V8nHAh8fQ g6iA== 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=onIZJ3mvBTOQ+ZhpQNWBJbHURkxZJ0aUS8gAA43ajI8=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=p7PXevJMmdh8huf/f4IzGT8RjZUciUov6LsVbky5gVxoyszstx1r3xy+W6o+O865ON PBXqrznxmK1088z0Y/o2pyuLyp9XI9Rusoazwtn5iFhoOw+0p0bPWbGVe320RZJh6eit VC7EO7cKf81U+aOapU4STsDL2y4kZ6bjkOp7ie67LmMQL/G9SLhZbYh+xtTTYqqoMLfC Z/W+kBr20uwAnugiEVz4aw7pIJDaScJmEAbaNHbv9Gv/O4xbvrx0JbpJp7uV/3tlRryp /QhBpE4i+MHZoQwwlkilb4BP353AJqAtSJyp/itLYbcsN72CLU/12qdIUQG13s0ZQRor EubQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dp+z8Gti; 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 q6-20020a50c346000000b00542ecfc2aa2si4240831edb.360.2023.11.06.03.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:42:25 -0800 (PST) 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=dp+z8Gti; 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 029C28700D; Mon, 6 Nov 2023 12:41:16 +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="dp+z8Gti"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 48C3987036; Mon, 6 Nov 2023 12:41:07 +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-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) (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 AF1C387056 for ; Mon, 6 Nov 2023 12:40:54 +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-x22d.google.com with SMTP id 5614622812f47-3b2e72fe47fso2823193b6e.1 for ; Mon, 06 Nov 2023 03:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270853; x=1699875653; 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=onIZJ3mvBTOQ+ZhpQNWBJbHURkxZJ0aUS8gAA43ajI8=; b=dp+z8Gti8k1SlJUNRGUVz+tt5V+hD+ywOrP7R7MAyN+R4vD9WFusDUXO1UXPofBCy7 moX2b1p3O6rdQ5a1voARglVGD02NKI5dzXWmHlcyXnEXGiat+nMxZB09dlF34VV/QZcB gbkALqc9SMMgzmk3IMF6TPx0A1tAj65d73OUNmPeSKSbWe8YnhCG53jRbvHnP/3Rxc8C 0u4IVFqt/mEYwasyd/R9KQtVENFCZCin6rhgPFCNfxbiyw2KGN4qmR91eOvS2lUD9r4U zqRFey/9upzfBkff2YdrR0aT8bd6nV8bJPcYLBs4jrnH54L1/HVDUDy1RxteDLMCd2Sb Vmlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270853; x=1699875653; 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=onIZJ3mvBTOQ+ZhpQNWBJbHURkxZJ0aUS8gAA43ajI8=; b=kWBIFLMosVHRiwGLk2wYu4EvaJ4V0IWZdO4lW/Xr5jYUGNxzjBaw+oP4uVgHoGhbdE XipHCDeEcM1/zubZy/mUisYxWUWyGlQsNn29VU2jYNOmMssHA097LDpLqrdbifiIsZwH g/CImIebD8FuDXLMkAS5Dpq+SxhigHHov99sIvMj7DurCxjFjzhgv5RI03mKufCxvgwI dTr7/Z0QOc7UuBV9UIp4waWLSu+ynnd2o63bZjmxxcUruXQVpdkjuN7GfDl18Bp+X9kW IpfhjUly3oaMoswYH6qFm3+dn6/YQj3g6UVYc2RxS29NTPpQK8hbC/YME/R97bFI8aPE HHiQ== X-Gm-Message-State: AOJu0YyemxjHOOzaLiBRg3E3Gaw2gkmho3UT7K4UZSz5piRm+y45wVFG JjSJMzXzMDB2GGTSn9dBao+Zj2nJqVmOYjQc7+o= X-Received: by 2002:a05:6808:308c:b0:3af:709c:1b2b with SMTP id bl12-20020a056808308c00b003af709c1b2bmr35471986oib.32.1699270852783; Mon, 06 Nov 2023 03:40:52 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id fk12-20020a056a003a8c00b0066a31111cc5sm5435004pfb.152.2023.11.06.03.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:52 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [RESEND PATCH v10 7/9] efi_loader: support boot from URI device path Date: Mon, 6 Nov 2023 20:39:18 +0900 Message-Id: <20231106113920.3631591-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 | 337 +++++++++++++++++++++++++++++++++++ 2 files changed, 346 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..e24c18215a 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,11 @@ static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; +static ulong image_size; +static ulong image_addr; +struct efi_device_path *loaded_dp; +static struct udevice *ramdisk_blk_dev; + const efi_guid_t efi_guid_bootmenu_auto_generated = EFICONFIG_AUTO_GENERATED_ENTRY_GUID; @@ -168,6 +177,327 @@ 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, ulong 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; +} + +/** + * search_default_file() - search default file + * + * @dev: pointer to the UCLASS_BLK or UCLASS_PARTITION udevice + * @dp: pointer to default file device path + * Return: status code + */ +static efi_status_t search_default_file(struct udevice *dev, + struct efi_device_path **dp) +{ + efi_status_t ret; + efi_handle_t handle; + u16 *default_file_name = NULL; + struct efi_file_handle *root, *f; + struct efi_device_path *full_path; + struct efi_device_path *device_path; + struct efi_device_path *file_path = NULL; + struct efi_simple_file_system_protocol *file_system; + + 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_CALL(bs->open_protocol(handle, &efi_simple_file_system_protocol_guid, + (void **)&file_system, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL)); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(file_system->open_volume(file_system, &root)); + if (ret != EFI_SUCCESS) + return ret; + + file_path = efi_dp_from_file(NULL, "/EFI/BOOT/" BOOTEFI_NAME); + default_file_name = efi_dp_str(file_path); + if (!default_file_name) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + + ret = EFI_CALL(root->open(root, &f, default_file_name, + EFI_FILE_MODE_READ, 0)); + efi_free_pool(default_file_name); + if (ret != EFI_SUCCESS) + goto err; + + EFI_CALL(f->close(f)); + + 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) + goto err; + + full_path = efi_dp_append(device_path, file_path); + if (!full_path) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + + *dp = full_path; +err: + efi_free_pool(file_path); + + return ret; +} + +/** + * check_disk_has_default_file() - load the default file + * + * @blk: pointer to the UCLASS_BLK udevice + * @dp: pointer to default file device path + * Return: status code + */ +static efi_status_t check_disk_has_default_file(struct udevice *blk, + struct efi_device_path **dp) +{ + efi_status_t ret; + struct udevice *partition; + + /* image that has no partition table but a file system */ + ret = search_default_file(blk, dp); + 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 = search_default_file(partition, dp); + if (ret == EFI_SUCCESS) + return ret; + } + + return EFI_NOT_FOUND; +} + +/** + * prepare_loaded_image() - prepare ramdisk for downloaded image + * + * @label: label of load option + * @addr: image address + * @size: image size + * @dp: pointer to default file device path + * Return: status code + */ +static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size, + struct efi_device_path **dp) +{ + efi_status_t ret; + struct udevice *blk; + + blk = mount_image(label, addr, size); + if (!blk) + return EFI_LOAD_ERROR; + + ret = check_disk_has_default_file(blk, dp); + if (ret != EFI_SUCCESS) { + log_info("Cannot boot from downloaded image\n"); + goto err; + } + + /* + * 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(addr, size, EFI_RESERVED_MEMORY_TYPE); + if (ret != EFI_SUCCESS) { + log_err("Memory reservation failed\n"); + goto err; + } + + ramdisk_blk_dev = blk; + + return EFI_SUCCESS; + +err: + if (blkmap_destroy(blk->parent)) + log_err("Destroying blkmap failed\n"); + + return ret; +} + +/** + * efi_bootmgr_release_uridp_resource() - cleanup uri device path resource + * + * Return: status code + */ +efi_status_t efi_bootmgr_release_uridp_resource(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; + } + + efi_free_pool(loaded_dp); + loaded_dp = 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_uridp_resource(); + 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; + void *source_buffer; + efi_uintn_t source_size; + struct efi_event *event = NULL; + + loaded_dp = NULL; + ramdisk_blk_dev = 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)) { + ret = prepare_loaded_image(lo_label, image_addr, image_size, &loaded_dp); + if (ret != EFI_SUCCESS) + goto err; + + source_buffer = NULL; + source_size = 0; + } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) { + efi_handle_t mem_handle = NULL; + + /* + * loaded_dp must exist until efi application returns, + * will be freed in return_to_efibootmgr event callback. + */ + loaded_dp = 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, loaded_dp, NULL); + if (ret != EFI_SUCCESS) + goto err; + + source_buffer = (void *)image_addr; + source_size = image_size; + } else { + log_err("Error: file type is not supported\n"); + return EFI_UNSUPPORTED; + } + + ret = EFI_CALL(efi_load_image(false, efi_root, loaded_dp, source_buffer, + source_size, handle)); + if (ret != EFI_SUCCESS) + goto err; + + /* create event for cleanup when the image returns or error occurs */ + 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 err; + } + + return ret; + +err: + efi_bootmgr_release_uridp_resource(); + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +541,13 @@ 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 Mon Nov 6 11:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741378 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036408wrr; Mon, 6 Nov 2023 03:42:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbcSwsgS9H3GcUizN99ru16yowYyjiurJf7QQJGHpHiz/tXXx5qvAKCkQYObPpsXusd9sf X-Received: by 2002:a17:906:794d:b0:9b2:b2ad:2a76 with SMTP id l13-20020a170906794d00b009b2b2ad2a76mr12498303ejo.16.1699270967633; Mon, 06 Nov 2023 03:42:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270967; cv=none; d=google.com; s=arc-20160816; b=Hm+sn3A8/pvSPRhRhVLlEcjt5Dgc8C7P4hlt3ByALBt4soV8qHUUH6OR78xcVqMTkH bNEoxpL9kb8KNIAEaKaq3o4p5iTWAbM1JUzZcZNlX2YMi0bjTyFOEcrkjOYUvkz53Ikq 4p0PtKuaxzT/WXwQ7NTAJ94DXYYvgsTSiZEvyRfTmW0Xh3OHA6ek0ZpiCbrbXYG5SKQA xj3mRtqPKkQ7S/cTfNVHkvhV25sSW+hzDIjNp5WJEmqgsRmyQPyxXyhMkzVsLxrQpPkq 9MgqUhe6Hf2ZeQL3m+XP6llx20FqkbXKJPyBr705a6l6z+/03fZ53UEn6M/Hj7yvWpq7 YWQg== 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=NRTsxwjx6uyxrzBkByQmAcAmnN6eXCzsBhcbAfmc9rakYdbEpXyjPnV/tPU4BQgkAy ldqzLhZbMsDpwCPLuwsk5Fw14fO+AfGsoLREWCYjKF/wJnjYN+eY4dm1aTKetOWdl2Sj EjUoNJ01CkOuT5AC6JaxHbeGfNrmjcBNJk3iJzx+mEuolMS7XdIwCfUfXnprIeLUhPLQ erIGy5Bpb7gfAaW2BaBgWwEtNPrJbFdH49tRok1a7Jlo+foDSak8L2UZVeA1bv72by2U AGOxJojCGwwEbOebqayjuBq57MIdmI1/H1lYzadJcvaI8vVlJqEefqO0xYH8AK9z6yzK wyUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gbN6LObX; 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 i13-20020a1709064fcd00b009ad87fd04dasi4197708ejw.105.2023.11.06.03.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:42:47 -0800 (PST) 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=gbN6LObX; 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 B786087061; Mon, 6 Nov 2023 12:41:30 +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="gbN6LObX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F17068702F; Mon, 6 Nov 2023 12:41:19 +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-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8E78886E40 for ; Mon, 6 Nov 2023 12:40:58 +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-pg1-x529.google.com with SMTP id 41be03b00d2f7-5aa7172bafdso2769231a12.1 for ; Mon, 06 Nov 2023 03:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270856; x=1699875656; 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=gbN6LObXXHttAbZ4c6o1uBUasAD5mcTw4DnqJWSjKB+oY8wx5IZSAk2/gHHMYq4knG MrXMcVe07TXyiQ+ZGl7vzOWcPfaQ1/cLYwhFxqijXX4AuK1Q3muTuSWqsh0q3zfUEov+ OSpha8+/YQyq2u744OQUYvERdJ9Zvm4gwRkkbWXhWhpd4KPDrLUI90gC733yWMPsnKoW ZXVWPqsOqxFRutUr9Qs0bCsW4BlP0ebrHFL13myOza8T+e3/rOs8IiDbQ+4AKOiSv/oG 2Pn/9/vcY/pO5f+fwc/we3wT9b9ZbbEaKFClOnJKO3FeqpedFvBtu/hg0gCT+NAsmKhw gbQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270856; x=1699875656; 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=ZgRAFNKzIzlCmysQp5DIe9tlJpKgTzZg8mpzsEcv3gw9bn7Sih1F7I92yc8aKttcff NL0ef2F/FKM13LI/UwJMYuIHqyq1AhiP19/pygwGpKM6ajB+ZWsnPMo0/9ONuaEWhkAG me/Mc0YOhSsLczhMQx+i/GpXjttmzHN15wuatwec3n3OdMGBj+wEvZEGthNA0sG7dnoq fx/2vMpocapK5TpqqAb3zPX47sJ+/c2U71BmsNn9wyUJhQw1fU+MTIUm3T0sWGacorRi 61nj4r0d06+Ls74DIR9iqJZh2jPm7a0T5ULR5H1CvecWSphbCOJfgZZxqaa0RiU66qBp sUTA== X-Gm-Message-State: AOJu0YxUP0i2HtfxINcF5B8eo0SqudycuglS17GrbCyvQCJ9Exbs8o1m rA+ZvY+DgOEqasiSV8ywPqOKRhyNC3cRcnE19Rw= X-Received: by 2002:a05:6a21:7802:b0:181:44c:d59 with SMTP id be2-20020a056a21780200b00181044c0d59mr15855508pzc.31.1699270856197; Mon, 06 Nov 2023 03:40:56 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jw5-20020a170903278500b001bbb7af4963sm5736137plb.68.2023.11.06.03.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:55 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [RESEND PATCH v10 8/9] cmd: efidebug: add uri device path Date: Mon, 6 Nov 2023 20:39:19 +0900 Message-Id: <20231106113920.3631591-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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