From patchwork Wed Nov 8 11:06:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742222 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227386wrw; Wed, 8 Nov 2023 03:07:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlaM3r3zeK0Dt7I6NWhk17tj9xbJDblFCZaXsvb9U/JOn8NKdp2JYs2aD8vSPm3FAqCfux X-Received: by 2002:a17:906:f74c:b0:9ae:5a56:be32 with SMTP id jp12-20020a170906f74c00b009ae5a56be32mr4294576ejb.38.1699441678178; Wed, 08 Nov 2023 03:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441678; cv=none; d=google.com; s=arc-20160816; b=oPCT6xN9HpNHdHvyQihx5ZfU4G7eRysOg/WgbZhlu0i0b+1IfwZbA1eIod977HStoh xzYM3fKUK9302RZSKV0nBNmZu/Jq6KRttcbqNPvka+sHLGQC+ylG4Q13DqE7XPsZ4quY yObKso9qIcwnBlDvs7FlLh6PoxF9E2+wpg425dcEa75e5VudTasQOQtTEri7b2E7cb5a IB78TLlK27OGVWTGxz2ZL1HF98GkftCoeMhiB1oK3qoU8Qs+iVQD33KJU3vErs/thfOV P6znDauz5HJuNeOLYJV1dHakExzVCa4Z6s2MPLoOSBEX2EdQmVE8NT8XTdl/9jk0E2if OuCw== 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=pkhzyYQRk5QmF55uLbwM6zHdjbg6egBMDjfWYvvujav2W0W7IShgEw3tXp0lW1asDe CB4BsjnPH1WPFopcSkmKZKHTbtadJRcddQjoqjvthoZYq1f5i11DP4g+JofM7+Urf3iS A4BJUsE/3uHcv7RIWr0BrUiqQcjqnwCNlfUua+43yi7I9Nin7l0rHehB2MQEe8O6/tH3 vG1MMKYaLiAiaCqNJcey/SZKwkAtJRPhaXUjaea2qWLazWWDRVYOMIV/OTOSnWVXrCmd p4g6AnlEy3zKLk/wF4ObsGmSvlXoBbYtIt+J++pC9Y0hH6GCUD50otl/o46kX1mXw4ml +87g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PgYPJipZ; 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 ga41-20020a1709070c2900b009be5c079196si2016989ejc.461.2023.11.08.03.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:58 -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=PgYPJipZ; 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 9E9FF8746A; Wed, 8 Nov 2023 12:07:50 +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="PgYPJipZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1937A8752D; Wed, 8 Nov 2023 12:07:49 +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-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 66CA987525 for ; Wed, 8 Nov 2023 12:07:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1cc5916d578so60939285ad.2 for ; Wed, 08 Nov 2023 03:07:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441664; x=1700046464; 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=PgYPJipZ0WDFzwYQcdqvG7afUVGquvlDQzbkPyuHCmajlP1VoRXGXZFSaoUapSQ7XS aJuTo/iEBf87tpri5spqNKkB6OGK/5HOXW558Dj3E+b/0w6m+wlaKy56O2D71Hw6+ULl xZNH0rnc5WyH7QKG7SjH9I/XpQBL78qKFxkz6tKwjdS8Meazrby6TbkPsLMQvlvp2r1N 5RgRW7UBsexx6qVxebFccFQAWIhZfMM1evfHQ7pQ/ROKql4NqdPDsuNYtb6sTU6O0aba WSAhct4Pg9ygaJNPmBolZRN32H00hKjldwnJUbJRzEoEKZxTk3guf/T0UfgCUtyNJnig 5iuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441664; x=1700046464; 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=VA0OQDiD/vKwB02MH8MVBFRx2L/BGsbl6IscUab+8nxnjTiZPQmYiAqbNJDr9c2RAU bzcdkFLGJ8Iopudg8pEqIjq37bbAzTSI0KkDC2uTw1eQtZG55dS41gr29wWYoKjZl0xj 9IT1uYd6E4/soGj+iVoxviCF4E3YhFVqK9jFz4lroZ2nAMf+o2XmF+/K4ycF0sClhZVa NlAj3qRf5BNENNDksL20DD8cb9qAPSvoJ8zkpRSdUVW+l4pICLjfrHDJM6xro2/u/ke8 QI2ILvxWQtGPTUxkY8qD8DxjNLi9J0ibJAgojSFf1PCsNzswwhpknoxOYG0ZK/3V4hsw /qDA== X-Gm-Message-State: AOJu0YxAYOXI2+RFk4Y0psuhioKl+WBJxv/w8H/ENZTmFxx3cl7Ooz/D uIuY0GgLo1CNPwpVR2Zh1G4bFmRUTuUwtLC3M3c= X-Received: by 2002:a17:903:244e:b0:1cc:4e81:36a4 with SMTP id l14-20020a170903244e00b001cc4e8136a4mr1907881pls.5.1699441664401; Wed, 08 Nov 2023 03:07:44 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id d3-20020a170902cec300b001c57aac6e5esm1496956plg.23.2023.11.08.03.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:43 -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: [PATCH v11 1/9] net: wget: prevent overwriting reserved memory Date: Wed, 8 Nov 2023 20:06:28 +0900 Message-Id: <20231108110637.3691441-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This introduces the valid range check to store the received blocks using lmb. The same logic is implemented in tftp. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Ramon Fried --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 8bb4d72db1..6f97eb1d12 100644 --- a/net/wget.c +++ b/net/wget.c @@ -4,16 +4,20 @@ * Copyright Duncan Hare 2017 */ +#include #include #include #include #include #include +#include #include #include #include #include +DECLARE_GLOBAL_DATA_PTR; + static const char bootfile1[] = "GET "; static const char bootfile3[] = " HTTP/1.0\r\n\r\n"; static const char http_eom[] = "\r\n\r\n"; @@ -56,6 +60,29 @@ static unsigned int retry_tcp_ack_num; /* TCP retry acknowledge number*/ static unsigned int retry_tcp_seq_num; /* TCP retry sequence number */ static int retry_len; /* TCP retry length */ +static ulong wget_load_size; + +/** + * wget_init_max_size() - initialize maximum load size + * + * Return: 0 if success, -1 if fails + */ +static int wget_init_load_size(void) +{ + struct lmb lmb; + phys_size_t max_size; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + + max_size = lmb_get_free_size(&lmb, image_load_addr); + if (!max_size) + return -1; + + wget_load_size = max_size; + + return 0; +} + /** * store_block() - store block in memory * @src: source of data @@ -64,10 +91,25 @@ static int retry_len; /* TCP retry length */ */ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) { + ulong store_addr = image_load_addr + offset; ulong newsize = offset + len; uchar *ptr; - ptr = map_sysmem(image_load_addr + offset, len); + if (IS_ENABLED(CONFIG_LMB)) { + ulong end_addr = image_load_addr + wget_load_size; + + if (!end_addr) + end_addr = ULONG_MAX; + + if (store_addr < image_load_addr || + store_addr + len > end_addr) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); memcpy(ptr, src, len); unmap_sysmem(ptr); @@ -248,25 +290,39 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, net_boot_file_size = 0; - if (len > hlen) - store_block(pkt + hlen, 0, len - hlen); + if (len > hlen) { + if (store_block(pkt + hlen, 0, len - hlen) != 0) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } + } debug_cond(DEBUG_WGET, "wget: Connected Pkt %p hlen %x\n", pkt, hlen); for (i = 0; i < pkt_q_idx; i++) { + int err; + ptr1 = map_sysmem( (phys_addr_t)(pkt_q[i].pkt), pkt_q[i].len); - store_block(ptr1, - pkt_q[i].tcp_seq_num - - initial_data_seq_num, - pkt_q[i].len); + err = store_block(ptr1, + pkt_q[i].tcp_seq_num - + initial_data_seq_num, + pkt_q[i].len); unmap_sysmem(ptr1); debug_cond(DEBUG_WGET, "wget: Connctd pkt Q %p len %x\n", pkt_q[i].pkt, pkt_q[i].len); + if (err) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } } } } @@ -338,6 +394,7 @@ static void wget_handler(uchar *pkt, u16 dport, len) != 0) { wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); return; } @@ -428,6 +485,15 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (IS_ENABLED(CONFIG_LMB)) { + if (wget_init_load_size()) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + net_set_state(NETLOOP_FAIL); + return; + } + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Wed Nov 8 11:06:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742223 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227477wrw; Wed, 8 Nov 2023 03:08:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJKPfMwFLVWVdEjvRbgg7IuT07RvNWIS6FRJjmbIHcN4EGPPxm70oSOs5Q0iiW4H94Wwir X-Received: by 2002:a17:906:c142:b0:9d2:20ee:b1d0 with SMTP id dp2-20020a170906c14200b009d220eeb1d0mr1014321ejc.53.1699441690927; Wed, 08 Nov 2023 03:08:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441690; cv=none; d=google.com; s=arc-20160816; b=sMyHcCqDuk2964YmiGx/3NDm2gdPf7gJmOQvBta5B+2+MCLhGPHmazBjYV8WS7i6nH QwvE3nZC0ZOVq+gvrMXIZSShrZRTM+N1rfyJdBZhJp8w8S4BZ6qcMcS9dblvjsI7gPu9 Jp5LfAkUl4J4bp0ssevPtjxOaqUX3EPFhN4740LU8W15wIhv2eGamxm44hwAoUNoRm/g vMlRYDSBypQsYs6hClumjOx2+++YHzIQ7gpZ0n8VEhie8eZPVWTLGYwLYKitdVZCheBC dR8h0Y3KWh9HmAqiWbyXH2csDZMYVpct8Rt80gx6Gq8yh9fYm1hI+GT4ALDQqcbzScoJ Uh8g== 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=S+AWbgL/HUQZQnqFDt9ybn/w6PgW+fMI1r188M4/139SElNxWKKaaUKJISW2snvavV 4bXWeC4HCsuu2hoMza4YkzcuwESSw8XItBLPh1wFiRsOU7Nzk9TqZgENBEvxDHhAjVVu 7xCodY5nLVc+JR9z1a1GN9UWpxS5YPiUKbkJVx1uYBNJNo/Jrwp2TwG6QYSNKC3w2iM+ AQ7thdxGgn/Od6NvdlQ+qq0qm3LMdOp6PQyN6F0aFh3oc91y1dHd/Q8gQvHQmu2aHdcS nwDqw/GywIKa+y/tY2if/BB3LjHMLYFR5QfnK0AZIZp5YfaTNv8LccDJRU2JZoCG+5NL dY1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XdrcCPJe; 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 17-20020a508751000000b005360a551c4csi6674431edv.74.2023.11.08.03.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:10 -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=XdrcCPJe; 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 9372187703; Wed, 8 Nov 2023 12:08:04 +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="XdrcCPJe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A8968754B; Wed, 8 Nov 2023 12:08:04 +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-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (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 EDB18875DB for ; Wed, 8 Nov 2023 12:07:50 +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-x230.google.com with SMTP id 5614622812f47-3b52360cdf0so3223063b6e.2 for ; Wed, 08 Nov 2023 03:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441669; x=1700046469; 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=XdrcCPJeUA9V2Ggn6UqA591AXAwvtYnO5IzNZ96EYTJPUBu8xy+mo0lPp+N7MN5psf aE2tRBgPyRTnn7Re2SlDeXSazAOPTskcqFLvKjUC8fAWu8ynmLSs8Q4SEDzSzJAmJ+jR mC7X1+cgnyR2oAccQ+n+UCU90KtO8hEwGpqsjUrjKGZoWJnpRGRrbwXI8vJ38R475t5k TBdlV3zyEi51VQBl+t8b4u/iVfjWPhvWyoHkVMrxuXMda5ZWo3XjDhm10FUei9PJWfOV XRo6JLRvCjuw/lJIPqkA/kVPvYtJ5/6JEky8XvwAUgLYQOuexPAcMzUgHFhRqE4hjNnn 95cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441669; x=1700046469; 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=RPSVaYrsao5mMkTDshE+b8ddi9NWd1Ts6TUsGYs/N4QzAD9IO08CTRH3iAMkZ3Q9mx TcsLbdmtLjcALj5UXHf8KDiym8cEQYFGZjgPXJw/edLIQTOotE/ls7u+frW/alHPR7fC 0usvM/mSSJeLLhI7q11olOAZ65ZJC0lm8Zh318c4OLTBy3+TyoHsVLe0V8vw3gGnAKkH 4vXdnH7M2Km0gah0D8lhRRIlQK1B04V46HbBbv/CoxBRk1sRTRlvJ4lNp49tSwXQSyRW V7K+FplBW1qe0wWtH2hUTEIJvQBCniGJvWMK0mkYGeuIHWK2hHU+R54Xgv20YF9Z4xFE HYUw== X-Gm-Message-State: AOJu0YwvNfeMrI6pxwWpUf3DliOH9t6Z3LjvwoP41FhKLOOhqGZqMeL4 2uTpgaK6mJJL429ptkbKg0ULqSQXfi4nqzvC5Is= X-Received: by 2002:a05:6808:1154:b0:3ac:b73a:757f with SMTP id u20-20020a056808115400b003acb73a757fmr1974618oiu.39.1699441668851; Wed, 08 Nov 2023 03:07:48 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id m29-20020a634c5d000000b005bd2b3a03eesm2916497pgl.6.2023.11.08.03.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:47 -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: [PATCH v11 2/9] net: wget: add wget with dns utility function Date: Wed, 8 Nov 2023 20:06:29 +0900 Message-Id: <20231108110637.3691441-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Reviewed-by: Simon Glass --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Wed Nov 8 11:06:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742224 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227546wrw; Wed, 8 Nov 2023 03:08:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMuWJ6LbxHuLAuprwai+gEtWTgnoq5YKf98gsETzraeIEQ3Mre9xoh1CidMSGguYVmt+K2 X-Received: by 2002:a50:d5c1:0:b0:543:56d8:eb26 with SMTP id g1-20020a50d5c1000000b0054356d8eb26mr1226194edj.35.1699441703781; Wed, 08 Nov 2023 03:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441703; cv=none; d=google.com; s=arc-20160816; b=a4kq5vB0Z3N9IVoQl++A1vsgZRePoC4Ab3lcbIafyfi6a9haKCeXoevnoKA0JTm1f0 6RYPq0A96Ww5+56udzzLzyLKXVh45Sf6kgK0pYrCv3eC3xgoCvtHYZ/q0R1O4I1Bd8Or A9+at6u/095VAg2oQfe6YfqkUiSiGHUtyMfz1R2vqIsheq0eoL5nbcaDr7NYxzLlSPcb gt4R+9t+cwNRl4CFUAovL296Of7ijeRJ0iSOIq923KauJCxm1V4mVoGz9uREKzmulHhe r3sHSv9qb6De5UK8rT5sLujmkIryztWMmB566lLOtbmYcwiKuMHymX9Z5mngOvu/EGBB s+OA== 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=HGWc3MmfU6IGuN2lAs1xlSuklmYjlSsUvw4VE+MfmqOZBAT+Bek434ashlA39SCVMF D90ivr6NK6ISHHr7n6rnLu7fG22sURMl4B98rzndNtUXKviByOv05Og/gh4Y2O6YZFg7 PXJr1G1hxSBlOlT+cdBvoRHh9bMq6X1RVqwaC+AOfu5vGrxPncbCOGu7TnzygfThIpqc mfzmo4xyu+cjurcyDjxepIkYsV5aw81kaqRY154c3nS2XclpzsavQ9iTwys5xNNBsDbH 1mPKviglSoI2NtnFa3NPKLbLEYypeg1jcad4uKC3ZbirrYO/zWevtIOr0dsqZxljMKWc BxSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nDapdNSp; 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 s26-20020a50ab1a000000b005435556d922si6211366edc.301.2023.11.08.03.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:23 -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=nDapdNSp; 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 510A38754B; Wed, 8 Nov 2023 12:08:11 +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="nDapdNSp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CCFF8755B; Wed, 8 Nov 2023 12:08:08 +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-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F08588752D for ; Wed, 8 Nov 2023 12:07:55 +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-x631.google.com with SMTP id d9443c01a7336-1cc921a4632so56514485ad.1 for ; Wed, 08 Nov 2023 03:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441674; x=1700046474; 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=nDapdNSp06iLuNQa0m73zvzwiAEEmahc+hFseoCkjorzbAZ828obDrrUyLeDceKfiW Zb01duP3QLdZCglS5vpmjLd8KcJQSA2C83YGji8A4Mi2jX5o2Tkjf0BB7i84NjvJfUsa AHdDd6omVgBVK/9aHCDt1dn0qWqPlzzgZ97NVyNUp8aXI4HDL6aW4yisUK9nYq8yOVcr FuayAI+S6Af0xpgZP7tTsmw5Jw2qMrYlzyFbikHH3UseT7STUz9GbFbNs6USwEFcLe1W oPYshJWI3MlW50zv6MC/IKnA2WHSJWb4hjb3NON5JOg1hBW2DJHXfeYJjie1NB2USBcM 4wKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441674; x=1700046474; 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=eEeUDBN2ShywDA5f061bSlpazNCWhh95lVZlpAcy1qcjcG/VQbvhyrtfmCpxKBwmeA TrrJOptxSLQI27BMcSVuxmHiT3tNFat0K7GziqcVtnZX4Cp8GaOWqTT5XZ7i1Az2caOT sjvdR61O/Fvn7ntHZxv4EF9U/nOLWpN+piN5mSCuoLa8gaETXj8/MWMwKLBtSAW8eIYr a1jq7o9oI2SRpVL53MGXaYL9oi6e1MIje0vx7Hwixb8J6ccc1Uft8fncLirzR1WldCyL 0iU9linu3fr2DzMusptciRZVqS9v52FJOJulKxj+12idhWK4l/ylaA7JxF2cxrWHqu3z usDQ== X-Gm-Message-State: AOJu0YwLOQVfIhIQOaLWUvK/ffPCNmvxEMTeLjMdFGgqdYW7Pn0HH9v9 EILye5KwmSV1LTuYZvOP6wsNEFGU9KtL/JIzPQ8= X-Received: by 2002:a17:903:2a84:b0:1cc:617e:9c25 with SMTP id lv4-20020a1709032a8400b001cc617e9c25mr2076768plb.53.1699441673969; Wed, 08 Nov 2023 03:07:53 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id kx14-20020a170902f94e00b001c6187f2875sm1486269plb.225.2023.11.08.03.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:53 -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: [PATCH v11 3/9] blk: blkmap: add ramdisk creation utility function Date: Wed, 8 Nov 2023 20:06:30 +0900 Message-Id: <20231108110637.3691441-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Wed Nov 8 11:06:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742226 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227769wrw; Wed, 8 Nov 2023 03:08:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUBLdrSIMCkIikzh5axd5+yMcLkrv6KPqzRGSFJeC1MVoNS2FnyaVfmPA02p0mTw7OM5fy X-Received: by 2002:a50:d583:0:b0:540:31dc:ff8b with SMTP id v3-20020a50d583000000b0054031dcff8bmr1074725edi.13.1699441731501; Wed, 08 Nov 2023 03:08:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441731; cv=none; d=google.com; s=arc-20160816; b=FiDbVA2h6aVfRi4zpX1vjk1FxA9pQ6PQRh2pUGL4c62T12KhLvRzXDdT1RxbUFUO6T 3iy06eQyLbfT1HccCnUVuaf2K2yGrGvrvOSzG8/ROZn0MKW8MO9zc6jRSUKYoCJ+wK5m 0UQ8cypm/4T7Fo43yt2t59pTkRmJ/T0ETfGvR1CBlnjubYRGO4FAQ3x3/d1A9iXOvMSe pcsRumE7lcZ8bdb4WcaYnnvwZROgtRc0LWFwDmKoOz2aJBq1o5zcciZxnEnyTfOzotvq GNQRElQO7xwzn3Dh7C/9rbLaAx86fv7jO5k7skUt9cuCBGg068yo+I5DVeqxH6XFw0Tr LA7g== 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=SBtyzxmIYb8Yf/OkCZejVoIqnBb+ghY5PKZi3Rn/qNNAkL/EbkalraM5WHMc5pEirP XPGRGC2TKhTAtdGHq2fg9GiFsyDrZ1icFkcCv0cxj7/Ho4HetxlTX3VOqFsWT1i5jba1 pin2S8Fzp475FVXxVzt5+7PNMeNITopQVrQX2XtHRcF9z8N9sFqkh3LnhuDdbWFRWq54 WdJ7tqlLc01vwN2QwGDfg8+2yQNuYLXzZhHuobRVsUzseIuY1LxJ56bTJkMs9SBVfzzQ DGPPxU7kI5FGl1jY9p5Dq5RyUYrvURa2uqOoQDDUSAAXSOlSrqA0d4K+AMs9lsDLhKBz Bm1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="T0/cPauX"; 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 m13-20020a056402510d00b0053df6901da6si6344620edd.182.2023.11.08.03.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:51 -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="T0/cPauX"; 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 8BB968770E; Wed, 8 Nov 2023 12:08:13 +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="T0/cPauX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 90BD48752A; Wed, 8 Nov 2023 12:08:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 057168767F for ; Wed, 8 Nov 2023 12:08:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc316ccc38so55009385ad.1 for ; Wed, 08 Nov 2023 03:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441678; x=1700046478; 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=T0/cPauX4uTUoDmyjC/I651jq+d2FNNkeft3Q9C+mLWnlxKICuxZib0MAVwDPQqQFB w3Ea8fzO+GN4tfuwhKAhTBwelEPZNc2QOF35NTGVclM6k5iooFSxx/LYKDYwkqGGV/mb 9f+VJXiBA0dprqRZ3BEICOJwzm3dOYUYg+r8KKtuVrE8peCxn5C+triIi71VMSlnKsL5 u6gzZG+IwMUF465WNzLGNpGqcaG7bP4GLH0nTX2ABQHJgUTHGbbV9bVd/S+2yyEcwkMb O4VXm0cbpIjb8cVrbYTgFB7cA31ZKfZK48XYf1pFlnFO5x9FSQUtcOLmI7/ZRmoNxWgG e5mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441678; x=1700046478; 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=T/lCBh0gyCDTvz6XrbdHPUb+x4APNKiMVx9bbzLq822DFBPenOwUJIVyddU18HU1RJ BK3/BQRa80flwoCPPtnIS1ZzT+Zsn42UOUesK9KGa7NHQc7tvZLhqhqZgtmK+Ww5/N7R vaoT7lnxpVk5HizaX6ps6EeNVQzTJZ2t2lcnlfz938/Nd7SVnEgQB38BcHmWaw3Eki5J hQggoSW6CjGIFiyWvfXE2Q1bBAwwqqARKnEYB38Klj6W2c04Z9pX2wL0cp3vgxwec6aX k1dtQx3RnVk7t3GqBU1ixwShQpyCYKWiVO7rpKwQc6qfInGI9FHejDl2tLa54fvGNuWN LSSg== X-Gm-Message-State: AOJu0Yyqv8JONltlv8db7bB4NF9ZnORxEbyhDAv0nzIvgNmVy1d527zX BPDfbzkCI30ORmncvo9qLh5AYODOzT9sZi1nOhU= X-Received: by 2002:a17:903:230d:b0:1cc:5f51:b1ed with SMTP id d13-20020a170903230d00b001cc5f51b1edmr1813471plh.47.1699441678299; Wed, 08 Nov 2023 03:07:58 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id z19-20020a1709028f9300b001c9c47d6cb9sm1499834plo.99.2023.11.08.03.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:57 -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: [PATCH v11 4/9] efi_loader: Boot var automatic management Date: Wed, 8 Nov 2023 20:06:31 +0900 Message-Id: <20231108110637.3691441-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Wed Nov 8 11:06:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742225 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227653wrw; Wed, 8 Nov 2023 03:08:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRjy106cJi+NbLOPLO5rIJkrSSXyZm4tLFK+ffIwfqGiHOL029GxQnRpzzfrDjv4KDlHIN X-Received: by 2002:a50:9508:0:b0:543:8391:a19a with SMTP id u8-20020a509508000000b005438391a19amr1101624eda.40.1699441718038; Wed, 08 Nov 2023 03:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441718; cv=none; d=google.com; s=arc-20160816; b=saBgX+b04DBhbnpaCbS+QMRYYboJGRigEWzer9ooqkujhs/VCfrOvRrnqkCqwmLwFp lx+hxLjmIBJVUZKdUOfj5Mnut367e4P/ULz3dqnXxmV5YX4HfwB2iPxDBYO51rY4k4lr qpOiOLclLEUuHitR403IwnBpDsEFereZEhiqRNGSULYz5ExaAxmLbOD4Q8pF2z2WhRkT Qe3QPBIIWjJJu+KPvu1fwsvDG5OqOGC4R6kdHm5S+RiYSUsPqydgkfxQvBENMxP0Cu/4 SaqW90eE1dOpfeWM/xwxUV/Xwd9v/OKO45appN5/zAEpFiJsUczFleRz1yrbILaeWK0J MFZQ== 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=RQMd4dk3D6Mp2w6ovX/GvKDNW0TWf6E8GEbg4zhU3uTpK1+Zc71VZzyorK32/nnt6M 5esw5Cd8useVSQOxHfiOpU/pRH7igMBLg2R7nMxann4R0R9e5qLkj7oJdoWBkqwtHW3y tA2qYWtzeymA/PbCFEWrs3CzvIAa7uWf/5u2HgCdtZ7oeyNT1SCi4oM5JgTFIP+yJFTV gZJGMFidGgKLi7QrygcZMbGXcrdWgtrjpBxBlSAHzOKY32FWMS0R4/Whj0NG063C9dD1 iEbQKxpuX1lkLu2Gl9cfWzBNVYYfAzrSdoyBX0C5RaLiXf9W9rY8jVXdUQ+3+jLoLhXL 15qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KHigaRyE; 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 z94-20020a509e67000000b0053df6196ac4si6787745ede.397.2023.11.08.03.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:38 -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=KHigaRyE; 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 4FFAC876E7; Wed, 8 Nov 2023 12:08:12 +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="KHigaRyE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B95D58752A; Wed, 8 Nov 2023 12:08:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B4C687700 for ; Wed, 8 Nov 2023 12:08:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6b5cac99cfdso5621299b3a.2 for ; Wed, 08 Nov 2023 03:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441682; x=1700046482; 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=KHigaRyEeDqsj33sLvhXJNu9urb+J27led4qHWyCy1hWACiH2mjQDZ3CkBi0PIJf1T rJi4qC9dJY/jVfEj6uIcsMCHc87ySBxrbXwVXD/axYo+cHRL1ytn6AcSxXdx6GqpAJ7i CEk+NPeejqCuqovvvlkteaWr0K+Zh00p3B/6et/TSlA9P+mjKkQHRZFXEVlo1Cko0NDm NnBwyzo6bVhTrpg7/LVqwzhq6iZDoezuhpu2kYI0OcYBIkqo/Tf7Ab10jT5l/KcDeQhL 4TzCm46J6m/pp/KG4YqK/7EwV7puL/pauPbUUC+2pvWqlfv2XKYP5bIrkqPPkqkk+DiR qt5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441682; x=1700046482; 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=CzMeSR4GbCFwAc4ch53NcRKpVxeVp3qcY7UJVna/HIG74waV6+5+qwzoJSTlk5fLUI 1nsf1gRo1Wic5sOcDM9KFJ+tK1b9eB9DiiJ1GongUYtps95CZcKafld7iZV4naRiOxWR C8UudOyUt8QA6vb+Hm92s1WInKeDbwAiCzz51tR2n5SEq2TYbrn+AifwntKg70DlpPaU 0vsmNQzCAzQU56nfWx5d+1Faj5RIUl5VJDklQa/zYUIKrfWuvyaQNAyURlZRiEb8yAP2 nF9gLMq73hpvvCC9RCPBmY75/TLztVSmnWMQW+ph0cBthGihcGlVu5XDQFLDH9LQfM49 Rn2w== X-Gm-Message-State: AOJu0YzYf8D6oxGPpON4nBn+I30LZM3aGSGb8GSIVOMQqC+/Cbkkj9Xz BCXQljyx6SS9sTQHhbn+2XwyIv8jV0pvzYZBWjM= X-Received: by 2002:a05:6a20:160d:b0:17b:689e:c757 with SMTP id l13-20020a056a20160d00b0017b689ec757mr1658327pzj.11.1699441682510; Wed, 08 Nov 2023 03:08:02 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id y3-20020a170902ed4300b001c5b8087fe5sm1504513plb.94.2023.11.08.03.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:01 -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: [PATCH v11 5/9] efi_loader: add missing const classifier for event service Date: Wed, 8 Nov 2023 20:06:32 +0900 Message-Id: <20231108110637.3691441-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Wed Nov 8 11:06:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742227 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227825wrw; Wed, 8 Nov 2023 03:08:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRTGZkOZA/pGPbxySjweIKo+0icQCyoPio4uTvRX8YhyIrMoFrBRlZS1hwmjdMUMlxGrHp X-Received: by 2002:a17:906:7309:b0:9c2:4d0a:c568 with SMTP id di9-20020a170906730900b009c24d0ac568mr1190705ejc.64.1699441737937; Wed, 08 Nov 2023 03:08:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441737; cv=none; d=google.com; s=arc-20160816; b=PqZPcSCuG3xzZVdrvBI9sA5wB0DT2cYFIrVclXboG/usoS61pE8nEI1rcYWzBxloot zO1Isj4uwks1CG89/tO9NnlFhlmk/WwCkW7QHFZQOlYPEEk9hmM9hhmE/dRqkgVgB3sY XP/C68IWfL2qMRNjo+R0WnJiJWC8mEiIOLsMKxx7mD2yeq35+M+lwMOmx8YMtSHIeYrM PsSBmeH/hI0udr8wnzPf9qtZBuscBg7IiUemh0WyTaiDEkU1tCdzLMxTAOXZspFzZSnt HMPfVNT8udMLLZ/WALDuAq+/lQPnvzYhneF4diCVd58E1Wx9P+uj4XQrWAOTpY0VvP3z nO2Q== 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=VrYa38PZTFqk3xMmgqJhkLJ2fBFoYf2Etz+cRhJJVKZJrol+F3Jge38/v/JTXlgF8e JYeiN28rW6TOUwY2uUxtkwhPQkNR7UC//PDjvGnhEDQBYJLdXkUme0sD86GmsNOqpLv9 1I2+qkIOVvKZ/0qFXHrRqUkGseOwiRi6LoTmy1xvAIoxgao39ckYqKdwR9C63ZbMSzNg w15bcXHLun0Md3WYB4tDHPBo0eSawHUe/Imr7iSO3ashwbZefpkQ670NMAaGyWgUuIK2 vATNsOakRSh1cOEGQ1vKXMCP3+YvYcuLhN0cvi59SkMXuEBlfc+MHGElPypY8tq6zPqf gX5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DrEisMOY; 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 my37-20020a1709065a6500b009b28786382dsi1754464ejc.709.2023.11.08.03.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:57 -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=DrEisMOY; 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 232B18752D; Wed, 8 Nov 2023 12:08:17 +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="DrEisMOY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8C7038770F; Wed, 8 Nov 2023 12:08:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F338087546 for ; Wed, 8 Nov 2023 12:08:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3b5714439b3so3220820b6e.3 for ; Wed, 08 Nov 2023 03:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441687; x=1700046487; 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=DrEisMOYOWvsScqWdt4R8OprOTzlUu0TPmL37e3s53SYXwbdyCU0Uw6mK3PMe16VZh tgufPjITlYFJ9isWNBk0Ze999SfUTAdA25rwEb4IrS/5j6HYkql7gtG0gRpzuTvXDX+r +C9HTcXBqX13Xp3lC1f/MJP4KbYXALsdwK3j5/ciclnW6kN9xsMGXWRKTQC3UZRdLgLN f1JVMNsrYMIxGcwQu4QUj/qAv1sn1yeICEWa9WzGLW4wkEfeotH/kBdMOUEkEYpfge5a LQ1CHiSXM3UTzvZx3H3zaBsBjb3V1v2gewyp02psjxLE1ruEAP7QqvuABSXyZpXJQXti DTUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441687; x=1700046487; 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=W8lDT9npXEZBIhFtO35Dd3wDfEfAdPG7TDCOvTcv0dAsgH17pqm0RmI/9y/kkha4jN fInwt8UG5cH3asE9Cnb6kGYiB0p2gBTATYlR5pqxf/g6iu9z0wH0Z8Qv4kpypvhXRQg8 B0OjLXLaGcRxzVpHU6VXUnxc65YKt8pz/aWZAYjzSRn+Mel56tcxZKIHPJ6qXx2AS75j oHjFxNIm3IpeBa0ct45PNpbhrb4kK1Q2j4pwLf2rrMBDKeY8H7JkkAi1xHqgn9PL5PAE nQDVbB3OjUEBOVYgh1ZeiWmzNkQl2NI+72U42dXtkHn2X6tacBPlR2cz+69Dc/ykWZGj 2hfQ== X-Gm-Message-State: AOJu0YxpDE4wmYWaS/Q4A/XFJCJNiOEmBMfIw/SSVfhdjaQFefP3aUUe UGPM3+jhrHqVS91qHZzcATRxsXPBuSXdQ35NsTE= X-Received: by 2002:a05:6808:13d1:b0:3a9:e8e2:57a7 with SMTP id d17-20020a05680813d100b003a9e8e257a7mr1992907oiw.53.1699441686898; Wed, 08 Nov 2023 03:08:06 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id s1-20020aa78281000000b006b4a5569694sm8700646pfm.83.2023.11.08.03.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:06 -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: [PATCH v11 6/9] efi_loader: add return to efibootmgr event group Date: Wed, 8 Nov 2023 20:06:33 +0900 Message-Id: <20231108110637.3691441-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Wed Nov 8 11:06:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742228 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227916wrw; Wed, 8 Nov 2023 03:09:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFW+PPFgqUAzD60gBjRNeIlLLt1guJ03SNpPllZZdyr5MFcHj8ILFV4fHbll7BrOF//SYjM X-Received: by 2002:a17:906:7310:b0:99d:e617:abeb with SMTP id di16-20020a170906731000b0099de617abebmr1286175ejc.23.1699441750199; Wed, 08 Nov 2023 03:09:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441750; cv=none; d=google.com; s=arc-20160816; b=MVLtwm/bcUn1ZcqqHJdFF339a6RibP+mJjx8RvcNal2UlxxSrB0D9u2c8q2S9XT1J9 9rXd5eEN/91N/vKCj6CMUkkAZ0CYPeO3MqOEsPnrkU8jXCGoupGOEWt3UFUmU/quFBnm osDAqVNpT2frXh4EcPuPTuROIxVmAxBKu5ClxDx6OWWzaXhS1JnMt1JVcQGt3iM6UIYh BtrDNmtsjV8I4ruxSOjI+2YB/4ZOFmsHGaWxysX7EfWixU7QQjNV6MjGg2Vk9aaIRsAo K8ecX63JSkZ52PZ3+n0LFAcSmKkFuOGIm3S7X+H97rAm9RqSNQ4BmSED4jLvR5qk79Wq Pnxw== 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=wRHnQHDXMRhtK3CMXQvqlgnT16gM9yP4IqJzbQC6tUM=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=We29K1nW5G0Np3eW3Ua6kRNfCh8Q/NXsnnOuoQ/xxyzNOyKvMN5O8REIfyAOiDFuEK 8xiPG4Fe2hCVkiZ5x+a3HTjyiV1nQmnVAHIY+SRNFwOM/CemoGvCYMsGwogQFFf+c+Yl TClOHzrMB1HSaVDeNmZ+ScGVj1diu8WOLyuhR36SSky2mNNczcsSciwBZomX0AimH3Ox GNTkS/SD/y2tG6G3rHiKHJvWbe1gdGkNKujmBnUNhcloXcupBbqg44PLZR6ksidoF9pD AqbgebWm6zG4aTIUzAFyAIueMsSIIZN8+G578/ooclc6vj/9WZ8uET19ijxFNsMSQtG8 L34w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=coSDr+n4; 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 h24-20020a1709070b1800b0099bcd1fa5acsi2007750ejl.359.2023.11.08.03.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:09:10 -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=coSDr+n4; 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 E6D48875DB; Wed, 8 Nov 2023 12:08:20 +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="coSDr+n4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 975E5875DB; Wed, 8 Nov 2023 12:08: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-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 862358770C for ; Wed, 8 Nov 2023 12:08:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc4f777ab9so48963215ad.0 for ; Wed, 08 Nov 2023 03:08:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441691; x=1700046491; 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=wRHnQHDXMRhtK3CMXQvqlgnT16gM9yP4IqJzbQC6tUM=; b=coSDr+n4JfVpRoh2WePk/TuQDNuEIXDAXz7czdzI5lbLM6/rSIsvca24uFLHsqOY9+ 8uL1oXnKhmz2uvfNDildJ0Cwf/sDDvZ3HKiJMAbYoIeoNONTsaJpATH38x4sDmMMf4eW 4SfTo7kdSFZDS3biZmd5pcjiM1R+VqYpxwDNOaoeYt378o2bYVMQCNWFnG/azJhyf5KQ DEPSSHBxLLrsRMJcsQ9gRGelatNn/5koxIzeWvi5Tzxp97DiM31VyeRODHTORZFT9DRQ BmOoqGFD6YSBGQH6duCZbgPUUuyXxOBmibcO1Ge0dtvWATI7L5Vv4pQcN3R4y5xSX/sn CuUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441691; x=1700046491; 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=wRHnQHDXMRhtK3CMXQvqlgnT16gM9yP4IqJzbQC6tUM=; b=eOGvQH//b8MEmOcK57li+Xrn9WGJyPEZ1+DWymZYAiNcsHqA2nPbsmpKxA3NSZ+L/y Un3yJZ0wooqbqi4MZ6J1Qg4AGd1OHuATJ46M/pcsd7JLnRpbHG5pWZivnrhDWqGZ+FDy p6W77GzEXg44cl6vwF+qCpGmtGp8moK6g7vizSYhTPbIOjeChWH5+2chTU6+lvV5yzqF sCd6x8cBJRuQjJ1mna497qjZIaAfi/3TTn6dabH44y9eAlVzM8DoMPgFyBzgj+kZEDRC FfJLbNI4qwQljmsrSiA2nQ1SRKLgCQBuGUS56U3UDdjxWOrFNmEDmswb444k+czXF/NK 2E8Q== X-Gm-Message-State: AOJu0YynGZnAmNcfx6DOPUuRGmKogsxHgoTiACb3MQhuZQ9YxK1vkXHb I7PVA64PVwBQE+xSSJvm5SZPmSAnS3CXCugECm0= X-Received: by 2002:a17:903:22c3:b0:1cc:b20d:7ec3 with SMTP id y3-20020a17090322c300b001ccb20d7ec3mr2072220plg.45.1699441690923; Wed, 08 Nov 2023 03:08:10 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id c2-20020a170903234200b001c55e13bf2asm1469033plh.283.2023.11.08.03.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:10 -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: [PATCH v11 7/9] efi_loader: support boot from URI device path Date: Wed, 8 Nov 2023 20:06:34 +0900 Message-Id: <20231108110637.3691441-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Reviewed-by: Ilias Apalodimas --- lib/efi_loader/Kconfig | 9 + lib/efi_loader/efi_bootmgr.c | 376 +++++++++++++++++++++++++++++++++++ 2 files changed, 385 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..ebed3c0f13 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,23 @@ static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; +/** + * struct uridp_context - uri device path resource + * + * @image_size: image size + * @image_addr: image address + * @loaded_dp: pointer to loaded device path + * @ramdisk_blk_dev: pointer to the ramdisk blk device + * @mem_handle: efi_handle to the loaded PE-COFF image + */ +struct uridp_context { + ulong image_size; + ulong image_addr; + struct efi_device_path *loaded_dp; + struct udevice *ramdisk_blk_dev; + efi_handle_t mem_handle; +}; + const efi_guid_t efi_guid_bootmenu_auto_generated = EFICONFIG_AUTO_GENERATED_ENTRY_GUID; @@ -168,6 +189,354 @@ 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 + * @loaded_dp: pointer to default file device path + * Return: status code + */ +static efi_status_t search_default_file(struct udevice *dev, + struct efi_device_path **loaded_dp) +{ + efi_status_t ret; + efi_handle_t handle; + u16 *default_file_name = NULL; + struct efi_file_handle *root, *f; + struct efi_device_path *dp = NULL, *fp = NULL; + struct efi_simple_file_system_protocol *file_system; + struct efi_device_path *device_path, *full_path = NULL; + + 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; + + ret = EFI_CALL(bs->open_protocol(handle, &efi_guid_device_path, + (void **)&device_path, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL)); + if (ret != EFI_SUCCESS) + return ret; + + full_path = expand_media_path(device_path); + ret = efi_dp_split_file_path(full_path, &dp, &fp); + if (ret != EFI_SUCCESS) + goto err; + + default_file_name = efi_dp_str(fp); + efi_free_pool(dp); + efi_free_pool(fp); + 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)); + + *loaded_dp = full_path; + + return EFI_SUCCESS; + +err: + efi_free_pool(full_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 + * @blk: pointer to created blk udevice + * Return: status code + */ +static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size, + struct efi_device_path **dp, + struct udevice **blk) +{ + efi_status_t ret; + struct udevice *ramdisk_blk; + + ramdisk_blk = mount_image(label, addr, size); + if (!ramdisk_blk) + return EFI_LOAD_ERROR; + + ret = check_disk_has_default_file(ramdisk_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; + } + + *blk = ramdisk_blk; + + return EFI_SUCCESS; + +err: + if (blkmap_destroy(ramdisk_blk->parent)) + log_err("Destroying blkmap failed\n"); + + return ret; +} + +/** + * efi_bootmgr_release_uridp_resource() - cleanup uri device path resource + * + * @ctx: event context + * Return: status code + */ +efi_status_t efi_bootmgr_release_uridp_resource(struct uridp_context *ctx) +{ + efi_status_t ret = EFI_SUCCESS; + + if (!ctx) + return ret; + + /* cleanup for iso or img image */ + if (ctx->ramdisk_blk_dev) { + ret = efi_add_memory_map(ctx->image_addr, ctx->image_size, + EFI_CONVENTIONAL_MEMORY); + if (ret != EFI_SUCCESS) + log_err("Reclaiming memory failed\n"); + + if (blkmap_destroy(ctx->ramdisk_blk_dev->parent)) { + log_err("Destroying blkmap failed\n"); + ret = EFI_DEVICE_ERROR; + } + } + + /* cleanup for PE-COFF image */ + if (ctx->mem_handle) { + ret = efi_uninstall_multiple_protocol_interfaces( + ctx->mem_handle, &efi_guid_device_path, ctx->loaded_dp, + NULL); + if (ret != EFI_SUCCESS) + log_err("Uninstall device_path protocol failed\n"); + } + + efi_free_pool(ctx->loaded_dp); + free(ctx); + + return ret; +} + +/** + * efi_bootmgr_image_return_notify() - return to efibootmgr callback + * + * @event: the event for which this notification function is registered + * @context: event context + */ +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(context); + 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 uridp_context *ctx; + struct udevice *blk = NULL; + struct efi_event *event = NULL; + efi_handle_t mem_handle = NULL; + struct efi_device_path *loaded_dp; + static ulong image_size, image_addr; + + ctx = calloc(1, sizeof(struct uridp_context)); + if (!ctx) + return EFI_OUT_OF_RESOURCES; + + 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, &blk); + 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) { + /* + * 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; + } + + ctx->image_size = image_size; + ctx->image_addr = image_addr; + ctx->loaded_dp = loaded_dp; + ctx->ramdisk_blk_dev = blk; + ctx->mem_handle = mem_handle; + + 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, ctx, + &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(ctx); + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +580,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 Wed Nov 8 11:06:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742229 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp228024wrw; Wed, 8 Nov 2023 03:09:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHF70gEjKeUPQP+xB/6XpB+ME5U8+aYBPfsLaUjNFKg1jZtOBikY5xxFC4jkecGsGoqt9S+ X-Received: by 2002:a50:c31d:0:b0:544:fc51:cd9f with SMTP id a29-20020a50c31d000000b00544fc51cd9fmr1090886edb.42.1699441763720; Wed, 08 Nov 2023 03:09:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441763; cv=none; d=google.com; s=arc-20160816; b=X1wjM9XNOCdSIVlllFIxW04c6f5lvMPvUgeRZ99vzW5KevkNsXX3oYG34WW7K9pwsq 8V7CzHyz9+dibuYMkRgYaVLizvOovFQVSOPfV5HX2uDV3UZusWkkQxWEvfLUNGclcW/R 1HWTAa737aUGntiSh+2fTxPnHRdwp+JwYGMPVJYJ2/nEarIC9HJr425WILaV647mZ6Hy eB47kvRmHRGWfR3jlADpKONId4/g3KpoP/Mp2wRnTcu0a5tDK0HsrnAFhj9XLmVwKo82 zr7jOlFQhUpjExGqsJ2rWsB8wxm8/mPNSpzXbkNShISjvhaqz0/+GUwmGOOSnGUWeOT5 YcbA== 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=e/q5RnNpHo0mh2mX5liVLCSRoPcp1PxtquHpkB2Wte9CEpPrzG326oMy6ZCrX4OqMm v5vOWN82/2tqdlJUHejFDaLmfAmhQBdbiNjoa5xgUPKqdmx1O2fipa9xJpWEzeXcsQtf CCZyorM/EaAai2Duc90bV89abS8C7jBQGJsMBUjjKv+1IuOxc6ndk3fiiWKRFl3NxYdQ K+3JfPAvxoi8JYg6ook49RJk8EZvaIcrMCfHGL84ScukyCuCbGmG0nruZalqlxJzaSG4 D+rMl5F9c9yfE+Utc5VOu6iRDydiJmGHI68ymEzvPVK0bCVsVSj3wJoxT+AaAfV/Gbgs 3cNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y6XXOXSM; 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 v27-20020a50d59b000000b0053de7c28d98si5984361edi.620.2023.11.08.03.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:09:23 -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=Y6XXOXSM; 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 519BE8771E; Wed, 8 Nov 2023 12:08:21 +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="Y6XXOXSM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DA62E875DB; Wed, 8 Nov 2023 12:08: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-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 71EB187253 for ; Wed, 8 Nov 2023 12:08:17 +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-x432.google.com with SMTP id d2e1a72fcca58-6be1bc5aa1cso6810000b3a.3 for ; Wed, 08 Nov 2023 03:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441695; x=1700046495; 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=Y6XXOXSMfb7efGcPvoU+Hh/vMLLyCDiY/Sxx73TtXdFppFzjLj8N9gqLOxUQ0DQ2QA CgVcN45XZzd9lL1VfAiM8RsV50qjprd3eTa2SSWz+C5MdcXbJP7lyxu0IjWMAkiWbygv RrpNW729cmxkScPI+4wG6TRzW765SqjXiacBv0A8JBGIyOWYqcwxx3F60Pml+Vmlt0dh 8ImWMvfrIqrxkg7J5AwYL5VY0kPdjj+5/CtNFCQn+4DLx088qyPDO3/wQ0XfSHhSSWj/ qAaVpxCnJvhsp5a/Ftn0MRb8WcYniMZTzKkXXWSu66/UbujGKsq5iC7m+5aXW3loRo3A AQuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441695; x=1700046495; 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=ooOy7dyHvX1Dp7q56A8/XYarPAL+SPXN6+37bLxY4aVCz+IHtBJAQLWrFfGG22sZLc AdeHX6iX5rO3/TNTd2fQ8WUy/gKYdJobzQwKNEvzUBFb8mPXvtwkTwYQOKrNIJIQ6lkU 0qMgUXAvk/WJRaUDUbnrZRQayuig4Fs/czANftJbrEe1r6fJGnbK/afSU1F2YAAxa7XI b7/B1hpSzKzrmBwtbps2X7whTjsaeKp+f3LN2zlcoIHoZCWq4Y5+bVDjujxuTHj+eWXN GdVGL5qK5wyaty0RJ7dKu8S6YsdMw2im18bA3SFoAxhequOwv1OAVKOJzCkdkmSxZkKD VgRw== X-Gm-Message-State: AOJu0YxGTLjTNaBiYxoRtvra7FtLukgqmvSl1Ne7Bl/QlWPRrD8ENUc6 KUynwcCcocvCSwQuKlKgyipgfO4IrTZA611LbCg= X-Received: by 2002:a05:6a20:441f:b0:181:10ee:20ea with SMTP id ce31-20020a056a20441f00b0018110ee20eamr2071223pzb.49.1699441695108; Wed, 08 Nov 2023 03:08:15 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id d3-20020a170902cec300b001c57aac6e5esm1497956plg.23.2023.11.08.03.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:14 -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: [PATCH v11 8/9] cmd: efidebug: add uri device path Date: Wed, 8 Nov 2023 20:06:35 +0900 Message-Id: <20231108110637.3691441-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 Reviewed-by: Simon Glass --- 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