From patchwork Sun Oct 15 23:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733891 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2465624wrv; Sun, 15 Oct 2023 16:51:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOG3s87+06FiSNjMZ20VWcnODyVgUUPmackAqQO7rOw0nPBXk7ZmR4LsHAFZ7IIH5TBfuV X-Received: by 2002:a5d:5052:0:b0:31f:fc6c:8b75 with SMTP id h18-20020a5d5052000000b0031ffc6c8b75mr26886291wrt.7.1697413877042; Sun, 15 Oct 2023 16:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697413877; cv=none; d=google.com; s=arc-20160816; b=V4c2sukp0RTdb5KSfn7P/S5OVTWgSJ5EF7anBbKgafuoJ7MXAeFuKksaf00iWQi3x0 6/glJDyRyq+INpY9Wx6nKaLq4XtYVQFAF1siKtNQIb6zVCpJjklAmOGJwVoFZfZ8FZYL hzoQGikDAhs/JiQWMBvBvDKJcuem1J7IQ9eEH2WdbvknCO61LWKqxYv6QnF4NIDRaZa+ MBCtZExOOU9LcycYj+kb2wBd+c/f9hxeXScT5Ekxu3t71ySfj3dEnwjafoJwwDWZs5rI Gs2Pr6imCb6ieZTZJiQ8lXQKiVUrxJRk5CJn//sI9Aj0PLNURXsBxZ/cuOSIme/ufwrZ vGHQ== 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=R58nKEFyB3l4t3Fwl5S1VRMsRdJHBYigotfbrE3kHL/Mb6AenS6IuqASClzOm6E4if qGarmFxxGrgtWjnB+6pWzzbFF73DB5eT7uGmOZtzjwfrTdMI70PcwD4uZsZe2TQox0PF w023cDW29gROFXqq16JVIMVF83C+VEQiHff/SzRN3EP51rkPVD0Yct06/CLnJucCvWb+ WJTPZD1AcBJ75Aijo2MgSrfU3sj4X+SBkJQanUtT80lrUuIIQFiMIy9DmG8dPSsTo9bF btpp32pe3f6pM77nU36CQN572gsdO4MJrz/QHAPglT2rB1nkkxtQqoRyw908EqPMRoQw 3KVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kywo59Xk; 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 bp12-20020a5d5a8c000000b0032c82d0c7bcsi6983852wrb.866.2023.10.15.16.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:51:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kywo59Xk; 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 64CAB86BB3; Mon, 16 Oct 2023 01:50:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Kywo59Xk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCC84869D1; Mon, 16 Oct 2023 01:50:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 7914F864AA for ; Mon, 16 Oct 2023 01:50:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c9daca2b85so28348975ad.1 for ; Sun, 15 Oct 2023 16:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413822; x=1698018622; 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=Kywo59XkoQawqB0zqsC+iQN9L7+/9jWTWWGxZ9dZ7vE3lFFFZo0QZ3al3k2Th7mm9z kib0cDme/qi8pZaq0d1aMQuUDaB5PdgpkBKryHIyvNU/iV9O23I7OvOygoLmA3v3nAYv ZrtRHxALTTSZ83qCr7zhEY5kqc7W93Kt236oLjdmW8sWFix0u0cn2wjwQRbyisQXSW8Q TMoAnmHS1u1mr6kFNuQSLrkSxZE4Au7EXEDPXv3VWTONteGGygK7BX+c/vwLARLM3n/4 wLfEmLwNsCCfGY9DSTy+9aGXPs5etM8BvCoAXDRDsFDDVLHfnMaRHGYBfm2pkodhUf0/ EdBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413822; x=1698018622; 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=XIs8qaQuXJF9o7a1nM8v8PKSpPx7pbflxvqsAl778bEa+qWbmoLsHJZQuwQz3j32z7 FHiijaGQ5OdyTXh95K3CRXci4koKjQlE5Gd82e3uDCEO3J1dsQdc7fCuIZ/AUL5gFeit KWPx6ScY7uPaPxvBB8B5D4wy0jZe7+a6HHDL6XFh79MLAOtuDBJ8lg9cRyl46mCLi/Ah BlLpBUauK+oedkwFsn9yBWboufqFuZI2AmxxJepCPvbRxaKpfUs2WLqeXJikbKydlU4B Nf0UX6DAVWcLdL4PHwRjoNcHK25ukTEMGtDx5OLavxjf9Pg0PnL76UsDrWK5LuZorPd3 xVlA== X-Gm-Message-State: AOJu0YykhhYxNkZX1az8hbIr5OZEoSvn+dEkUtdaCj7FhG5N1yghvKG2 ZZdJvdt07+Lht1+Ha/KbLmdqzqeu492e8Dc+qZI= X-Received: by 2002:a17:903:2347:b0:1bc:edd:e891 with SMTP id c7-20020a170903234700b001bc0edde891mr9063971plh.1.1697413821941; Sun, 15 Oct 2023 16:50:21 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id y10-20020a170902b48a00b001c60e7bf5besm7208228plr.281.2023.10.15.16.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:21 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v6 1/9] net: wget: prevent overwriting reserved memory Date: Mon, 16 Oct 2023 08:48:59 +0900 Message-Id: <20231015234907.2362717-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-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 Sun Oct 15 23:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733895 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466430wrv; Sun, 15 Oct 2023 16:55:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELFMiukJFD7rRlMCsx7mokESJaj2F7QV+XNZLoMvWzU412Y648hepZEELQ9jJjVaP1aeNJ X-Received: by 2002:adf:ed52:0:b0:32d:9a17:2a72 with SMTP id u18-20020adfed52000000b0032d9a172a72mr6257365wro.55.1697414122891; Sun, 15 Oct 2023 16:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414122; cv=none; d=google.com; s=arc-20160816; b=IT091MbynxVgI4iVAUdHvKE8IMSTit4c5oqvlrd/pS58aw+zJR0AWYqJ5w5/PcWjjS i5zw8QroBU7IhodZS2h6hONrPDUQ46LZX3TPAQlJoIC6h5xPI+kbU32VTWNQeumHY8yw qu0WCeIwNq1tqSx12GwCzyDfflKW9VTrYAC/m7ur3yruv/1eSfCo4jygj2FLbnpvy5Wm g4gxcdYVO8XjPOZLf0WLjX/k2NGyIiisxGDAZYisHsSy3Z8kq2kBph2/luJgqyVl9yp+ iBshUd4RdNhgOdsr0rQP5sHULm6nZtTmnU7WwgFI2bakEiMjjENADskGXCSMEAr5Kj2B 9F3g== 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=LsFL2XfoUIFU6f0RR/RdbWmwhM/OKW8DMTl2JBiDp7OEdSiUPmyuwc1ydIjJUZiIo4 gxHGHsP9UHVldrD/ecqmc2B5OLiIKq9WVNRVv4SFgDCeB20y8lzNseMFvU4efCRFygXf uHZdiwi/COh1wTrv9bkhqpAVFaymogKwkS2oVDzyksgZ4eWRV1u0G11dIsercWtvfuaC MHbi/6zwkDJWjZ1T2Mm3tu/jfr+BtcnmoRFpeU54gWPkyQksLzS6Z0BzUr/dq39tzo7y gf47qYj/hZzhgTm2E8UBnTztUa7vDDO3F9dTFy7LkqVt81usAPH85k98Dl48NehlK5Rq 536w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dqYxhg9B; 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 d14-20020a5d6dce000000b003216a203a0bsi10057149wrz.139.2023.10.15.16.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dqYxhg9B; 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 4D2AF869D1; Mon, 16 Oct 2023 01:52:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dqYxhg9B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BD04864A9; Mon, 16 Oct 2023 01:50:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B954786AE9 for ; Mon, 16 Oct 2023 01:50:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-694ed84c981so2930724b3a.3 for ; Sun, 15 Oct 2023 16:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413829; x=1698018629; 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=dqYxhg9BOIH80XS97PCcAehRYUyiELEAzvAKUZvJrSnun3TnB2wis8il1fPDQDxy5A /TxHwRgVnWIV6OoRBodx+E51Ur0lpeJGoM3AHtL8z3JatuINct8FUSFfTohWqdhLsd3p v8HoleekWCsEGsAtcPJukmwkOUtcsGbzJSXABuKG9HpuBvbJl4yvi6eBG4xnjKtK4YrZ uyVvI0A/QBIaP+Uqc39TcAoqCgSrVn9XzXmmMdSEwBzynyxVoe849KtM4BSrTwOqngZv pijWmxiuhry1UrmlJnAr01W6OU3ObT4uEHGRe0QH5NGG9DX6DzALl3WsCWy12OACmnZw ShUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413829; x=1698018629; 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=qQSL66JPlWGDiZf5qDf81g+uZkSF/EM6WI2TvWxNs/C+2HWmACIo6IlPIv+XK2C4xu jjDjkevP6XkZmgTPmyntsVffF663IcXhqfQ1cUuCoBNW0dthBi28RUL1Vr4dLsM1fnJk WXJjQH+8H+dDwccRehSutqRwthGa1DkOAkdFvDPCXTFiGCJ9QgNpoOUhRdiM39t6cmg6 jiKY8KnBX0sB3egOxjhN3ofGZ3D6h68+ourTtDD5dQVhIqcSCPPjG+IwRcBFbCWGqG1c kxs60am2dlDXx9eGWJaNUfUorMevEmgd9GDzt7EqaFieBmBKjI603PYHgErMmA2YXqEm 5Cug== X-Gm-Message-State: AOJu0YzLNmgP396w/50aItr7SKAoaxz6pjKW4rVU8qt4yckq5VXbZjiT Sllk86vqUUSO2hciPTyDyzabPNHKEa//y1zUoE4= X-Received: by 2002:a05:6a00:885:b0:68f:e810:e86f with SMTP id q5-20020a056a00088500b0068fe810e86fmr33717470pfj.28.1697413828915; Sun, 15 Oct 2023 16:50:28 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id r13-20020aa7962d000000b006be1dc1537csm651926pfg.59.2023.10.15.16.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:28 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v6 2/9] net: wget: add wget with dns utility function Date: Mon, 16 Oct 2023 08:49:00 +0900 Message-Id: <20231015234907.2362717-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Sun Oct 15 23:49:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733892 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2465910wrv; Sun, 15 Oct 2023 16:52:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAtRHsA63DySt5I2lqrQDKWe90AzUDbkj2/rm6iWds/n3dnMksp+ldYfKng46J8tjUmN4v X-Received: by 2002:a05:600c:211:b0:405:3dbc:8823 with SMTP id 17-20020a05600c021100b004053dbc8823mr28544164wmi.12.1697413970508; Sun, 15 Oct 2023 16:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697413970; cv=none; d=google.com; s=arc-20160816; b=Zy3Epb0c55bSDLmS+PKoxdWBEY6B7KIrj5cQrTK3poYGmjMqyMmJ5wusgbhSRS1/my 4DrIt6B7PZqL6xo0lF3B2RBEcha+u0ByUpjJB9ZyVMdClYS2DOSxZVLpeC6rtYOlZqpn BGBHzr6STjgsqPVyq+FMXSafUCYvPDTZiChFb2aV5rm7Pc0WdKNYgij9EMj3mgFV0W/V +O0cRlm/RnWiNHRMWBadZH2+yhHLnLtGc1GnhMAx6SWKAexnjaeva/qDlK6URhpa0K3L 0nBXgNJNtbUa+WnkLDEKEJM5X8GDLk6IhhlOe9WzffTiaRzTbdgBgPWcg9VUBmvYKdUI RJ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; fh=nGxKOXCACQSu1eN/ZPnZQwsIMUpKToCCLMDjTFnWWa4=; b=fLczE3uE3dEoFbHYiA/qfq4gBiYprb5vPaiIc6d4AV+avaJ2aPF3Bd2Kk1iXms6W3U LN081Jn4vxewWJgsB981DUUQu1lyLVBNqZtpjOmyBzMMgqEFGdtrrDL0yM4m/sX3RBjI MHrqA0/KsIHAfm3rx23APDyBOQ20uXVE771yGMTPJrdt737gn2hx1iqUgYDHhVurX9jr AQ+zjA8i90qNcGDWq3vyu7QkVl48CNyhsLzoiXybq13vW0frN7uL1hJliYFRgA+myKDx lFf8PY2SrywQFgjn52kfFs69vFz+RxeBjvgm0Fshhj78i+dwX9clLLlOsDg52AJkzpoi s8yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JJcnXuDv; 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 jg5-20020a05600ca00500b0040472cb9a74si2078256wmb.124.2023.10.15.16.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JJcnXuDv; 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 DFE4986AE9; Mon, 16 Oct 2023 01:52:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JJcnXuDv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E295986BCF; Mon, 16 Oct 2023 01:50:58 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E00AB868AE for ; Mon, 16 Oct 2023 01:50:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1ca82f015e4so751325ad.1 for ; Sun, 15 Oct 2023 16:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413834; x=1698018634; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=JJcnXuDvDgMUJR2msvAFK4RvfvusrNf07/+Aai/jTQ3egXrMBRttgYDlbvOSRfkDKj DxBwXkZ6TBmS22CLPfpy7JExWvurYZOqx9wFfzfoZ7UdsL/YhS5B91sx2uG9i4mcYnp1 BTBYdkKKR5TvjcP6XsvmLBb7oSJzUxTZdvwMI6AuL3Rh41scKlpzbsBRsuJFqW4q0B1e uyrhqmofwbWgJv7AMWc5TZdB91om5rGEuT4ynIzv+6KRWPuM56iL6qbapcOu/ENSGXP7 vsSpfuCEKJ+uw2Z5YGdkmlmXPbLZePkZNGZ5u4qBNuKTb4mOUotQtUbfZGV8Kp9xAABU StUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413834; x=1698018634; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=FzuRhpVp1RIFKXime177pK13H/gYvZUdFDh9xc98k+/FabpvfmGGhW66WZFplONjqv jQZ2H2ZVy7erBsgNfqCvykpLlsXPjNF4PaWKQzzKfwT7Hln/q+oL92CaH1QRlG5p1SL6 /qCrbJ9nwLtpY1ujE1a362a8YRr6L/kX9fSFViwhORgqGBveZj+04Vdz7fGfP5omTAxv MnYVcTrnRNHK83IZtVouplJdFaQttVn1Yj4SPSgMi25C83zQLn35rJfAcnlWVxPayKjz eyfboMHh+3q3q7Yh0g08McNnmuWhrBjKDbzSrgoD1YUx+XrcZbThC1e02T5Vq7XoDqMy 1Y+g== X-Gm-Message-State: AOJu0YwV6gjGSV4qL0E5UCnRCD12s9RDnHq1mmvbkybav+1R69V5aXRc MH7QufKnLPiIdy2tIe8hkd55egnUQcsPEEB4W2w= X-Received: by 2002:a17:903:41c1:b0:1c6:30d1:7214 with SMTP id u1-20020a17090341c100b001c630d17214mr31839834ple.55.1697413834264; Sun, 15 Oct 2023 16:50:34 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c21500b001c771740da4sm6045570pll.195.2023.10.15.16.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:33 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Tobias Waldekranz , Jaehoon Chung Subject: [PATCH v6 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 16 Oct 2023 08:49:01 +0900 Message-Id: <20231015234907.2362717-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean User needs to call several functions to create the ramdisk with blkmap. This adds the utility function to create blkmap device and mount the ramdisk. Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- drivers/block/Makefile | 3 +- drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..ec0575d135 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_IDE) += ide.o endif obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o -obj-$(CONFIG_BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap_helper.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 149a4cac3e..21201409ed 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Sun Oct 15 23:49:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733894 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466393wrv; Sun, 15 Oct 2023 16:55:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUMu9gqQ08BxBZY+of5DrX1DBlfJ4cLayBG/VknMawt8sYVGOp2LVITwLMxCVymHyMCEOF X-Received: by 2002:a05:6000:22b:b0:32d:9a8f:6245 with SMTP id l11-20020a056000022b00b0032d9a8f6245mr6501967wrz.68.1697414115631; Sun, 15 Oct 2023 16:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414115; cv=none; d=google.com; s=arc-20160816; b=HEh/Eq2RG35Fbixf2Ls8o6n/Vlk+r7w3RdQVW0YOreeQDXCClwr6kCBxq5KNT09lhc YTFsUGfqbkEKh1ZgVlYCji8YFI1Y17v8yuQXpYYUgbIq/Q7ANMcCLkgheShPHi2KC2j+ gcdnc1In8u0C/tVN19pNOsSKHUdu9aIFR8Of/0KhIAN7XBLypWhGXVXI2sp+njFqqsPZ Fz/9AXsxr5LvbGiAO9S/IdzJ1ycjonLfvSImPc0YKXnbXEipG0eV4phAn0kUjUTbDcXO LbJSoOewbbANG2/JTpaY9csoJ+RVADybUyKqJ7r3FMSpNdg7MMIIv6b6Ud/wCD2zhtd1 P38w== 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=94LsV6NL1ZNFhkqVQDSTT44O3isY0X8vZDJ6qg+lBCo=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=juF203cmtq+P75+4aQrskE6RTpQS0MZBLM1+bYze9dQx2w4ZllmZIlt/vUpuQbxhDs +b0SpWWQuffh7MdWSOKKLnYDxk8mCJAgHESQo2IOdpacXXTWYRpm7t7wZgA+xN7BDUdk EjqEDzeaZvvX8x3S7WkR7zLMhfPI5MM//imsEn2aqB/9BIevHIKgWqbMUNhF5yd7HGej IOg49kXsMVSdywk5UG7rUpLv6+hrluGzzeNdCkwT+SsEWWe+vpB2iExsJ11AygfkN+JP r0Lo61Ge+EUIFGUwt8PcYgEOi2pzf1U10PcJz43o2zA+/KIwboh9pL6CB1VCPr5DbKnJ 0zzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mekc6FVE; 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 x8-20020a5d54c8000000b00327174cf8b3si3857629wrv.311.2023.10.15.16.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Mekc6FVE; 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 027A286C3E; Mon, 16 Oct 2023 01:53:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Mekc6FVE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D203868AE; Mon, 16 Oct 2023 01:51:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 5BB4886B71 for ; Mon, 16 Oct 2023 01:50:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c9daca2b85so28349915ad.1 for ; Sun, 15 Oct 2023 16:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413839; x=1698018639; 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=94LsV6NL1ZNFhkqVQDSTT44O3isY0X8vZDJ6qg+lBCo=; b=Mekc6FVEgSX7y49Kylw8NyCvS5GAO2wtXKjEYtXUuLdYSgU0dAUf4s1Qn+m43bNEk+ l4l63NKJMff9PEyYqP5D3ErYTXeM+hBIXdZLQhWOMM+DZWStMB3203LvKGQnQriRP67b aE6VpzyxkEB7yo37tNYEUASmjTb54PeC/J78WmwD8QqcmnA4fm2MROHS9w74iXwe9dnN rw6TIrNRZ3qM4gWY5gYeAVP6cJOcTwfZiRwTNReWm1qmspU+htYSe9jttflGJK4ZBOOY kfGwE/6AGKQMV6tR+4XDhpBjpG72klPCmJM9KDgbzxKQQ7ZkOt7ag2O614+PH+fWKu2y bkqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413839; x=1698018639; 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=94LsV6NL1ZNFhkqVQDSTT44O3isY0X8vZDJ6qg+lBCo=; b=FEt4IOiqqyUSJxGmVBURHgKbeIX/0GcH/Cka3VGJVhpF3eRTCeRa+Z1ypZioKqQFq3 dgMksNoKtgmgh4APfyVI79UbNba0NxjylNDCVi8vhyGjUFGgEA2uuemdB2lpjRfIg5m/ JMTYolaY+WBbNyZZEZN9R5ZhI3VXuCXj+QgbWg5/TyTuXuq3bhYpV/a0RJSAcoEyu4/o 2wS7rWXqb/uGUzVXII9fv0emFvNWdPhjsGo8cnA9AfYAi/O6gPS3WU1Y9pksvk5ZpV+A mj3TXDStSjuiehwCatSwWJF9Zgce9plabAp9VFwCveCmPWDahLe/ULHmiM+zAnMBkWJy ElJw== X-Gm-Message-State: AOJu0Yw+UgESqSDTV6OQzoZOzERZdY/g3abAeiK0yJ73iRu9OSWSv1z1 n0wQbJBnGbfJB8Cob00AH4HODEqv1sDnrmkD3RQ= X-Received: by 2002:a17:902:fac7:b0:1c9:dece:4c4c with SMTP id ld7-20020a170902fac700b001c9dece4c4cmr7899388plb.15.1697413839397; Sun, 15 Oct 2023 16:50:39 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id f9-20020a170902ce8900b001c75a07f62esm7219635plg.34.2023.10.15.16.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:38 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v6 4/9] efi_loader: create default file boot option Date: Mon, 16 Oct 2023 08:49:02 +0900 Message-Id: <20231015234907.2362717-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current efibootmgr automatically creates the boot options of all disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. Some of the automatically created boot options are useless if the disk and partition does not have the default file(e.g. EFI/BOOT/BOOTAA64.EFI). This commit only creates the boot option if the disk and partition have the default file so that system can directly boot from it. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 53 +++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..a197127cdd 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -355,20 +355,21 @@ error: */ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boot_option *opt, efi_handle_t *volume_handles, - efi_status_t count) + efi_uintn_t *count) { - u32 i; + u32 i, num = 0; struct efi_handler *handler; efi_status_t ret = EFI_SUCCESS; - for (i = 0; i < count; i++) { + for (i = 0; i < *count; i++) { u16 *p; u16 dev_name[BOOTMENU_DEVICE_NAME_MAX]; char *optional_data; struct efi_load_option lo; char buf[BOOTMENU_DEVICE_NAME_MAX]; - struct efi_device_path *device_path; + struct efi_device_path *device_path, *full_path; struct efi_device_path *short_dp; + efi_handle_t image_handle; ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) @@ -378,17 +379,27 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo if (ret != EFI_SUCCESS) continue; + /* check whether the partition or disk have the default file */ + full_path = efi_dp_from_file(device_path, + "/EFI/BOOT/" BOOTEFI_NAME); + ret = EFI_CALL(efi_load_image(true, efi_root, full_path, NULL, + 0, &image_handle)); + if (ret != EFI_SUCCESS) + goto next; + ret = EFI_CALL(efi_unload_image(image_handle)); + if (ret != EFI_SUCCESS) + goto next; + ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); if (ret != EFI_SUCCESS) - continue; + goto next; p = dev_name; utf8_utf16_strncpy(&p, buf, strlen(buf)); /* prefer to short form device path */ - short_dp = efi_dp_shorten(device_path); - if (short_dp) - device_path = short_dp; + short_dp = efi_dp_shorten(full_path); + device_path = short_dp ? short_dp : full_path; lo.label = dev_name; lo.attributes = LOAD_OPTION_ACTIVE; @@ -396,24 +407,29 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo lo.file_path_length = efi_dp_size(device_path) + sizeof(END); /* * Set the dedicated guid to optional_data, it is used to identify - * the boot option that automatically generated by the bootmenu. + * the boot option that automatically generated by the efibootmgr. * efi_serialize_load_option() expects optional_data is null-terminated * utf8 string, so set the "1234567" string to allocate enough space * to store guid, instead of realloc the load_option. */ lo.optional_data = "1234567"; - opt[i].size = efi_serialize_load_option(&lo, (u8 **)&opt[i].lo); - if (!opt[i].size) { - ret = EFI_OUT_OF_RESOURCES; - goto out; + opt[num].size = efi_serialize_load_option(&lo, (u8 **)&opt[num].lo); + if (!opt[num].size) { + efi_free_pool(full_path); + return EFI_OUT_OF_RESOURCES; } /* set the guid */ - optional_data = (char *)opt[i].lo + (opt[i].size - u16_strsize(u"1234567")); + optional_data = (char *)opt[num].lo + (opt[num].size - u16_strsize(u"1234567")); memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); + num++; + +next: + efi_free_pool(full_path); } -out: - return ret; + *count = num; + + return EFI_SUCCESS; } /** @@ -642,7 +658,7 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index) * efi_bootmgr_update_media_device_boot_option() - generate the media device boot option * * This function enumerates all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL - * and generate the bootmenu entries. + * and create the boot option with default file if the file exists. * This function also provide the BOOT#### variable maintenance for * the media device entries. * - Automatically create the BOOT#### variable for the newly detected device, @@ -674,8 +690,7 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) goto out; } - /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */ - ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, count); + ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, &count); if (ret != EFI_SUCCESS) goto out; From patchwork Sun Oct 15 23:49:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733893 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466361wrv; Sun, 15 Oct 2023 16:55:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5u7EVkmuMI0qwQRw5QFsGdcdWaFmvsko4rS3jFZJiAbD7vICIJAMcgn0n4PlRJAky62VM X-Received: by 2002:adf:f103:0:b0:32d:9cd3:6a9d with SMTP id r3-20020adff103000000b0032d9cd36a9dmr6175678wro.25.1697414106085; Sun, 15 Oct 2023 16:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414106; cv=none; d=google.com; s=arc-20160816; b=UqPqqMe+pRqjLMIq9nIrWMnA7X94b5CWyFOSrbH3TbhbsdqW8PsM3eg5EfV7kSuc0F nT2jD2gyf1yFz73tuQHcGTC1ACAMIai/QJokUGbtV3DkZ7vdh8NlOOF5Ad8LDe6sz+kc JYTXtaSL2sxvxUuCOxtCG2NRRJxJErBFzNCtbsmGytBWS1oHC9YhdJ1mwP8MyISTepIl VAzB/1yRzsz+/Xo/gxW/Gm5S8RP7htC2z03tSSjc/EGMl4CtEpV2+XyVGn3me34FveCk 9XaQAy+4LIt4B+BDsF390q5yqcpHTmJrB3DJlTjpemF7+yYys1xTwUFBYOSPN7N76hrD KTog== 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=Sem+HHX0VXCT9ALLt5h9piqxM6bOFDSHojQAIvVFoWY=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=NGua+2JfdmSx4xi1jUYKFCM0kW0FMV/+Kui1+9RFkYeXd9NBQVqTYvb2+hLIdey66B Nb8f7R+uTpKmdeLGs1LzclVk3qPlVcMD5Jk2eyLTJt5iEFed59cWQQ4K2rhJuIo54Nkk wNxR178hiv57kdrOlnOcIqW63FOp5Xf44DWnOiUmJu1jn5XeN7EWP/LfIx1kxrTMLTnu uZIapEQQrxmFvqMA5VCFbY/42AR/LMpUk6q7y4rhrJRGgIbJgM1mFh8EaaT9sfLXz+wA JrnAPOrUL9pTvMVVGOU5j+M0X/HQh+FEhEERBW8Q2JEVNcs8jWlrdnWS1tEoGWWhWzmt 1Npg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tAzs1zXC; 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 o21-20020a5d58d5000000b0032d845e3b90si5234803wrf.638.2023.10.15.16.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:55:06 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tAzs1zXC; 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 7DB4086BD3; Mon, 16 Oct 2023 01:53:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="tAzs1zXC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBBD1864AA; Mon, 16 Oct 2023 01:50:58 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 38DB086BCD for ; Mon, 16 Oct 2023 01:50:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso1278307b3a.1 for ; Sun, 15 Oct 2023 16:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413844; x=1698018644; 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=Sem+HHX0VXCT9ALLt5h9piqxM6bOFDSHojQAIvVFoWY=; b=tAzs1zXCasBo+eUf+gm1KTqNmb1PoN7ragArEOS9aiFxJgJb3tyTNfXwwKAXhKIGec 5IrBCwRx108SjnwO8+FafRYxMZ63Z91PLCYHK0hp9xxDqkL903QU5d3tM8TgfhdHGDVJ 3Z8enn96Et760u6o5E1KZXxk8VeMeIGriEQSDy63MVbxhCi8LkGCRiaNFcD6WlxpIJFO YpCXzlF8n7UsEdTsDDtX6sakMB5MKEoAW99soak/tU6EEtEHfiOaENnRrMvWWBC1XWii /Zmdia6zHtrl55REBTJDC5i3mzkwJc9qGVqBaCEut0ge0WFxI75OJYDvKHjeh55lW7ID 7F8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413844; x=1698018644; 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=Sem+HHX0VXCT9ALLt5h9piqxM6bOFDSHojQAIvVFoWY=; b=ADaISMNXLr9CxLeWKTonVf4P6g0JdKf9hgHc7TwB8fiaHfMfrpAz+YANpgL7oteNCC oEp9K0LbCY8JwS8vRxh/KDFsg1x2rqN6kSOco9n42hryBEucy8gPYS5ZaT9oruZJe4FA apCMrOivqVA9Ue2KuqYVlmeqbsHk8R0hAMLC4xSqawHe/eOAu34jqH+I+7Y6YPQykAtu CWlz5cU5YLJrpK+0HK5G270ACiKF3t0T3LgwOwojPTvaDtUuTQIDUZDkOY+199NCvRU9 Mi7vnz1yu0rrGwacProS7AWNmpeUQAicRMC3q0cpJDB4ImZrrZWYyuxdFEo69DgOh+8k Y7Ug== X-Gm-Message-State: AOJu0YzYze5OUZfZoel/Eo5ykt5l+IPmpGZM4Ap0Nq9LukXdhyCOFE0A hXQqYwWHtiSBr8dRS6Y+eHP5juEbS7xolMZ7p4A= X-Received: by 2002:a05:6a20:6a03:b0:15a:6733:24e2 with SMTP id p3-20020a056a206a0300b0015a673324e2mr9015843pzk.25.1697413844259; Sun, 15 Oct 2023 16:50:44 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id p6-20020a631e46000000b0059b782e8541sm1640014pgm.28.2023.10.15.16.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:43 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v6 5/9] efi_loader: support boot from URI device path Date: Mon, 16 Oct 2023 08:49:03 +0900 Message-Id: <20231015234907.2362717-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This supports to boot from the URI device path. When user selects the URI device path, bootmgr downloads the file using wget into the address specified by loadaddr env variable. If the file is .iso or .img file, mount the image with blkmap then try to boot with the default file(e.g. EFI/BOOT/BOOTAA64.EFI). Since boot option indicating the default file is automatically created when new disk is detected, system can boot by selecting the automatically created blkmap boot option. If the file is PE-COFF file, load and start the downloaded file. The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image. For PE-COFF file case, this memory reservation is done Signed-off-by: Masahisa Kojima --- include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 9 ++ lib/efi_loader/efi_bootmgr.c | 251 ++++++++++++++++++++++++++++++++-- lib/efi_loader/efi_dt_fixup.c | 2 +- 4 files changed, 248 insertions(+), 16 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index e24410505f..106006127b 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -554,6 +554,8 @@ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition, void **address); +/* add reserved memory to memory map */ +void efi_reserve_memory(u64 addr, u64 size, bool nomap); /* Carve out DT reserved memory ranges */ void efi_carve_out_dt_rsv(void *fdt); /* Purge unused kaslr-seed */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index d20aaab6db..5d99206dc3 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -479,4 +479,13 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_HTTP_BOOT + bool "EFI HTTP Boot support" + depends on CMD_DNS + depends on CMD_WGET + depends on BLKMAP + help + Enabling this option adds EFI HTTP Boot support. It allows to + directly boot from network. + endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a197127cdd..b71a303f58 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -7,10 +7,14 @@ #define LOG_CATEGORY LOGC_EFI +#include +#include #include #include +#include #include #include +#include #include #include #include @@ -168,6 +172,192 @@ out: return ret; } +/** + * mount_image() - mount the image with blkmap + * + * @lo_label: u16 label string of load option + * @image_addr: image address + * @image_size: image size + * Return: pointer to the UCLASS_BLK udevice, NULL if failed + */ +static struct udevice *mount_image(u16 *lo_label, ulong image_addr, int image_size) +{ + int err; + struct blkmap *bm; + struct udevice *bm_dev; + char *label = NULL, *p; + + label = efi_alloc(utf16_utf8_strlen(lo_label) + 1); + if (!label) + return NULL; + + p = label; + utf16_utf8_strcpy(&p, lo_label); + err = blkmap_create_ramdisk(label, image_addr, image_size, &bm_dev); + if (err) { + efi_free_pool(label); + return NULL; + } + bm = dev_get_plat(bm_dev); + + efi_free_pool(label); + + return bm->blk; +} + +/** + * load_default_file_boot_option() - load default file boot option + * + * @devnum: target blkmap device + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t load_default_file_boot_option(int devnum, efi_handle_t *handle) +{ + u32 i; + u16 *bm_label, *p; + char device_name[12]; + u16 *bootorder = NULL; + efi_uintn_t num, size; + void *load_option = NULL; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + efi_status_t ret = EFI_NOT_FOUND; + + snprintf(device_name, 12, "blkmap %d", devnum); + bm_label = calloc(1, (strlen(device_name) + 1) * sizeof(u16)); + if (!bm_label) + return EFI_OUT_OF_RESOURCES; + + p = bm_label; + utf8_utf16_strcpy(&p, device_name); + + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) + goto out; + + num = size / sizeof(u16); + for (i = 0; i < num; i++) { + efi_create_indexed_name(varname, sizeof(varname), "Boot", + bootorder[i]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + free(load_option); + continue; + } + + /* check whether the label indicates the target blkmap device */ + if (u16_strncmp(bm_label, lo.label, u16_strlen(bm_label))) { + free(load_option); + continue; + } + + /* check whether the boot option is automatically generated */ + if (guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + free(load_option); + continue; + } + + ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, + NULL, 0, handle)); + free(load_option); + goto out; + } + + if (i == num) + ret = EFI_NOT_FOUND; +out: + free(bm_label); + free(bootorder); + + return ret; +} + +/** + * try_load_from_uri_path() - Handle the URI device path + * + * @uridp: uri device path + * @lo_label: label of load option + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, + u16 *lo_label, + efi_handle_t *handle) +{ + char *s; + int err; + int uri_len; + u32 image_size; + efi_status_t ret; + ulong image_addr; + + s = env_get("loadaddr"); + if (!s) { + log_err("Error: loadaddr is not set\n"); + return EFI_INVALID_PARAMETER; + } + image_addr = hextoul(s, NULL); + err = wget_with_dns(image_addr, uridp->uri); + if (err < 0) + return EFI_INVALID_PARAMETER; + image_size = env_get_hex("filesize", 0); + if (!image_size) + return EFI_INVALID_PARAMETER; + + /* + * If the file extension is ".iso" or ".img", mount it and try to load + * the default file. + * If the file is PE-COFF image, load the downloaded file. + */ + uri_len = strlen(uridp->uri); + if (!strncmp(&uridp->uri[uri_len - 4], ".iso", 4) || + !strncmp(&uridp->uri[uri_len - 4], ".img", 4)) { + struct udevice *blk; + struct blk_desc *desc; + + blk = mount_image(lo_label, image_addr, image_size); + if (!blk) + return EFI_LOAD_ERROR; + + /* + * When the new disk is detected, boot option is automatically + * created if it has a default file. + * Let's load the automatically created boot option. + */ + desc = dev_get_uclass_plat(blk); + ret = load_default_file_boot_option(desc->devnum, handle); + if (ret != EFI_SUCCESS) + return ret; + + /* whole ramdisk must be reserved */ + efi_reserve_memory(image_addr, image_size, true); + } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) { + efi_handle_t mem_handle = NULL; + struct efi_device_path *file_path; + + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_addr, image_size); + ret = efi_install_multiple_protocol_interfaces( + &mem_handle, &efi_guid_device_path, file_path, NULL); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, + (void *)image_addr, image_size, + handle)); + } else { + log_err("Error: file type is not supported\n"); + return EFI_UNSUPPORTED; + } + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +401,14 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) { /* file_path doesn't contain a device path */ ret = try_load_from_short_path(lo.file_path, handle); + } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) { + if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) + ret = try_load_from_uri_path( + (struct efi_device_path_uri *) + lo.file_path, + lo.label, handle); + else + ret = EFI_LOAD_ERROR; } else { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, @@ -367,32 +565,51 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo char *optional_data; struct efi_load_option lo; char buf[BOOTMENU_DEVICE_NAME_MAX]; - struct efi_device_path *device_path, *full_path; + struct efi_device_path *device_path, *full_path, *dp, *fp; struct efi_device_path *short_dp; - efi_handle_t image_handle; + struct efi_file_handle *root, *f; + struct efi_simple_file_system_protocol *file_system; + u16 *default_file_path = NULL; - ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); - if (ret != EFI_SUCCESS) - continue; - ret = efi_protocol_open(handler, (void **)&device_path, - efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + ret = efi_search_protocol(volume_handles[i], + &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) continue; - /* check whether the partition or disk have the default file */ + device_path = handler->protocol_interface; full_path = efi_dp_from_file(device_path, "/EFI/BOOT/" BOOTEFI_NAME); - ret = EFI_CALL(efi_load_image(true, efi_root, full_path, NULL, - 0, &image_handle)); + + /* check whether the partition or disk have the default file */ + ret = efi_dp_split_file_path(full_path, &dp, &fp); + if (ret != EFI_SUCCESS || !fp) + goto next_entry; + + default_file_path = efi_dp_str(fp); + if (!default_file_path) + goto next_entry; + + ret = efi_search_protocol(volume_handles[i], + &efi_simple_file_system_protocol_guid, + &handler); if (ret != EFI_SUCCESS) - goto next; - ret = EFI_CALL(efi_unload_image(image_handle)); + goto next_entry; + + file_system = handler->protocol_interface; + ret = EFI_CALL(file_system->open_volume(file_system, &root)); if (ret != EFI_SUCCESS) - goto next; + goto next_entry; + + ret = EFI_CALL(root->open(root, &f, default_file_path, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) + goto next_entry; + + EFI_CALL(f->close(f)); ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); if (ret != EFI_SUCCESS) - goto next; + goto next_entry; p = dev_name; utf8_utf16_strncpy(&p, buf, strlen(buf)); @@ -416,6 +633,8 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo opt[num].size = efi_serialize_load_option(&lo, (u8 **)&opt[num].lo); if (!opt[num].size) { efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); return EFI_OUT_OF_RESOURCES; } /* set the guid */ @@ -423,8 +642,10 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); num++; -next: +next_entry: efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); } *count = num; diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 838023c78f..edc515b9ff 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -22,7 +22,7 @@ const efi_guid_t efi_guid_dt_fixup_protocol = EFI_DT_FIXUP_PROTOCOL_GUID; * @nomap: indicates that the memory range shall not be accessed by the * UEFI payload */ -static void efi_reserve_memory(u64 addr, u64 size, bool nomap) +void efi_reserve_memory(u64 addr, u64 size, bool nomap) { int type; efi_uintn_t ret; From patchwork Sun Oct 15 23:49:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733897 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466639wrv; Sun, 15 Oct 2023 16:56:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZasvbDuhiqHo2Dq2Cu1se/8JKqHZ6vCmG7qxdnBrZEA8OuuFtrLJev9hGt3QYdk7sjrzS X-Received: by 2002:a05:6000:1f02:b0:32c:d7e6:4054 with SMTP id bv2-20020a0560001f0200b0032cd7e64054mr16090701wrb.53.1697414179148; Sun, 15 Oct 2023 16:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414179; cv=none; d=google.com; s=arc-20160816; b=Pj2/0oU8rFe1gmDGyXxjuLbDpgp8SNS08Vv8bXwlvKDpX+ZOpjFj4AyKsZ24yIkIhb 7yBwi8ZqdNunCiWefz7X7e6CXpI6JrcNrO0RCr9DHSTIimUi1ut7ZymJhJXNbeUkiAuJ YeqpttLG8Y+W1azEmoKY/YVtPeww3tX8kcrY+3HyJVVd0djckeQjg8Iu0XJ323V3aN/X r1EWjpWAJuLbFpepKsvbJ9HY3ik19ZL6k9C63j/9Ssqn8IOIrVky0dzn6k8q+KyRRzGy G0hfWl4QR+DYT4k9jyxI0lxCk1BsyCvFfI4pA58Llb0FJl+sCbV0BFOQEZ8NQ7e5fp5J oaYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=k7anxKb30wdVaRnWFoCvTPqX24uQfe+iZeVBosy4L+8xCNV7k54Hj2M5hj8Y0PR2VT PvyucLZWL1Oqpr0vUWSoZDaluvUsBDXrHdzmdu0Izb8qDPOAF7ef+Q1FLM9efhQef6wu MPMMlqc7Kt/becdHgyGeVaVpUrBFAXHU5nQpEIJk8gZ0yLZiIK8zSlLA1lQCBc9VTdib EvrOesuvSHtIUnHDEo2oGZ0btEsvkiik1a1WyTS1J5uirXW3rf4fTVe3oBca/bBa4j0s OA4YVn9FkVoXD2Fnz9ZMo9wHNqv6VZaIoiqCSSV/1/BsgS66ti63jmiiicL4fxURbyeT pRYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFIMQoZP; 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 x11-20020adfec0b000000b0032daac65e3asi1168675wrn.28.2023.10.15.16.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFIMQoZP; 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 B53E186DBC; Mon, 16 Oct 2023 01:53:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="CFIMQoZP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D19D869D1; Mon, 16 Oct 2023 01:51:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (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 62F5586C3E for ; Mon, 16 Oct 2023 01:50:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5a9bc2ec556so1526425a12.0 for ; Sun, 15 Oct 2023 16:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413849; x=1698018649; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; b=CFIMQoZPp4uiYg1GR+JJPzgLPaAFdc+iagiMmJ3Z5ho/xCr8wl3LihPruR0KaVuSrO SdPGK17ymCcZwQfWP8ClKZeQoClZa28haRj41ficNdKSY6xgmbc6Eq+3/vYHn/fdelfd N7J3AMi7t8UxOmne2MnFM6N96ihmpAPZgXZnUfSr652iE+s0izzVkfwpzT67+fe68TfQ WqZOZWXp14kjRoTbe93O31TJpT16AK2WXKam+UDO3O8h+QmeyECTFQnxem1QiJzGDA1p GrD5KTkG7AwRgm3EAmTgcxHOp00FpZLJ9/yAKL5XmQCZvd7Je33nSNX4AFvQvHSwMf5Y gA9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413849; x=1698018649; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1yClAL1OyfbKc6TszWmib6hvyd044g2R3J1uiGAvAPE=; b=kONRyH/mbK/d3wUhREJSVGJVgMZVza4b7cv+DjuWxI7AntYC6I43SVwFJgu9t96KLD 0xff0v7kJCYZjPZ3roiYPuYehbrrLi1pKlSyDnAQMRs1iVTP6defV+pjc7YXynZlzuM8 3jtNTvxcxBxvt18SXTlm3liqxgPi2s453EQhIbgaj8zTv5RaoAr+UGNUiVDtem6TsmZs d4idgOv7GdM226aR1TeAsQkyrogy94QumSkco/zk7N18HUA68Yj1oDDFdms5YDSxqmhZ /2BoW1XHakthXvR50lgZ8WLBfwdGzbMQvke+Z7E58SwHWyD8keA24iDDx/rT5H5WqJ6X tu0w== X-Gm-Message-State: AOJu0YyjGXWG9R8S5/E9C0VwVk7FspNmMU81VkX5OcwoH3Rz1Cifvwik Rub4GEyXM/y+GMgpoYv9ncyC1Hq9d5Ct9t0GzxU= X-Received: by 2002:a17:902:db0e:b0:1ca:20a0:7b14 with SMTP id m14-20020a170902db0e00b001ca20a07b14mr4204117plx.55.1697413849538; Sun, 15 Oct 2023 16:50:49 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ix12-20020a170902f80c00b001bb9bc8d232sm7278363plb.61.2023.10.15.16.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:49 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima Subject: [PATCH v6 6/9] efi_loader: add CDROM short-form device path Date: Mon, 16 Oct 2023 08:49:04 +0900 Message-Id: <20231015234907.2362717-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean UEFI specification does not mandate to support the short-form of the CDROM media device path. Fedora installation ISO image is identified as CDROM media device path, supporting short-form CDROM media device path is required to automatically add the boot option having default file of Fedora installation image. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_device_path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index ed7214f3a3..ac673ab117 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -110,7 +110,8 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) while (dp) { if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_WWI) || EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) || - EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH)) + EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH) || + EFI_DP_TYPE(dp, MEDIA_DEVICE, CDROM_PATH)) return dp; dp = efi_dp_next(dp); From patchwork Sun Oct 15 23:49:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733896 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466476wrv; Sun, 15 Oct 2023 16:55:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGncwsRHy8+DDRPr2DTSsrItXOl1FdTIe8bFC7FqDO1dWsPakUn1gr6dftwlpy+oGyj63Dy X-Received: by 2002:a5d:6648:0:b0:32d:b6a2:8de2 with SMTP id f8-20020a5d6648000000b0032db6a28de2mr603655wrw.39.1697414133931; Sun, 15 Oct 2023 16:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414133; cv=none; d=google.com; s=arc-20160816; b=Btms6q4lyOqHwVHRO41ZivnV8Rk/TXZppzMwxh5lbLsXCPGXAeFQClBbIY0l1kSk3z GYtl3ugoMHI1hJ8erBsPLA3KC00NG+pNpPTn69RhiB5IAaE7dCu14DahMJaL2pGSwrJ7 aTygnQro6TTTkPqWNfQxvR6WAatTHNbRsIaNDO2pMiTp03KOG4//qAp1ZY1RaF9piD6N Y0VP4sffGP4POjBWG0LIQrvPOYDFIELnZiDeZ0hEUfuM+6DUe80NxjORHJcEYgYSltsQ Ax02d+0sOsU0sMVH2//Rlfq1Diyc4DzAuWZUSC2FS3IINWo+YWy/q0K3ZUXD6Zd/yFOu vhrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; fh=OwlxGVC9rLycV+uRQL8XB4l1CrABnLtF7cR6HzvdRxs=; b=htlyC4wpDU3AIGnLcsimpT1QOimebAu1nXo/TjcuXSzFnGGEuvF1gjJCOOizNlG0r6 szMan/m2/cRo1r8rRC2ZmUvw/UnN8mowGSyHtVdq4LbyS0WHlf7i1aHtMAXF53Lr4qk+ jMU/c1rsgqtB87EA0WafuX+VSrP6pa9EUyjeA3H/0c5f9h5X9zgVSkb3FbQMvQMYyWh0 bxYPa9EbKiyo/wEFYTC27y8zCqp+eJyEU6GHqiHB/J/Tg31SPHdHltJWTp+0d4vu8QCZ vU6hlrOFkKSZKwTrStP509jVhYSmxS0pzsXv8egAaPcBVz4Bm7jVo9XeJFiXSVMSZCIK Gvcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=faKfFgLJ; 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 h3-20020a5d6e03000000b003216486d00bsi10254893wrz.628.2023.10.15.16.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=faKfFgLJ; 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 C67ED86D2D; Mon, 16 Oct 2023 01:53:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="faKfFgLJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 689C486C58; Mon, 16 Oct 2023 01:51:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (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 9B276867F6 for ; Mon, 16 Oct 2023 01:50:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6c644a1845cso2766100a34.2 for ; Sun, 15 Oct 2023 16:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413854; x=1698018654; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; b=faKfFgLJddbF/z+5wNnStABNoqdAKK57ezL03eUuzBQElAzOOISCTUy6vJqj8EfkCB Uvw4wwwdO/H5OAwsTdYZHrLqpz4fts0J9EOkTKrLaYQtDAxuNkVfbD4Uu+IhDo1WpctB I8ltb0bbdA6rTbvoRPWqoV2GzWvvm0lAueUPItmvB0xV4lzxiBDdLfd9cVYCGdF/VNiP k4lCzPB6Zk4DbPO5WdeuAAMfuj7py2xg/PtchCQ7AFhGYYSNgNmmYOPt85cNHomhIzGC 6LH5W7QQK4wXLCj9C2mEqhNT7Tf836r8d0ULCFxiFrl94oJkqsZNPKkx7kfdSoYHWx/Z XFDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413854; x=1698018654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a4zZ4HlSkK/oY3qfyV9r1nYVhNuROFuLhRstgf1Rv2c=; b=VXCuC/lDuvPcbNbspLZzSr+ttwn8O20MbniXrT9jrm0HLex5eojcYJZrtw1pMQRi+2 vtY/5WyVP5v5O+d2diScv75giIUgqXAZZK5Hf/q9Ax1ySkQCkVKfrJvavheUWj00mowV QOWQNfXj1pdPwNdZ1ugwQ1Vop+FNDAe7K+kddyeC4pGQ/12JWs0F1O9XQiPGJoLAUkxJ NGbfSagTV7p4bY/WhNleq30rY7bOz6r8WyM9MZGM6K4d2veBrlYDz9yhia5HwLzzU1DD SnfinpgAQ1/krBrB+aHzlQtzK2SHyPAUewby9SVAQjDmDw4O3AVQDiuD+BHy7egzKFt4 4X3g== X-Gm-Message-State: AOJu0YwKHCAyYalLD6FgWrK1YGj6RBoQ7YVFfPzNB6Bmyt7TUl9o0B1k 0ZTlnSH/CFmsBRDVq+9MJ1lFlAPaTyDf2sGxo6E= X-Received: by 2002:a05:6830:16:b0:6c0:abdd:a875 with SMTP id c22-20020a056830001600b006c0abdda875mr35616789otp.18.1697413854434; Sun, 15 Oct 2023 16:50:54 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id x11-20020aa7956b000000b0068fb8e18971sm4518109pfq.130.2023.10.15.16.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:53 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Raymond Mao , Masahisa Kojima , Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal Subject: [PATCH v6 7/9] Boot var automatic management for removable medias Date: Mon, 16 Oct 2023 08:49:05 +0900 Message-Id: <20231015234907.2362717-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Raymond Mao Changes for complying to EFI spec ยง3.5.1.1 'Removable Media Boot Behavior'. Boot variables can be automatically generated during a removable media is probed. At the same time, unused boot variables will be detected and removed. Please note that currently the function 'efi_disk_remove' has no ability to distinguish below two scenarios a) Unplugging of a removable media under U-Boot b) U-Boot exiting and booting an OS Thus currently the boot variables management is not added into 'efi_disk_remove' to avoid boot options being added/erased repeatedly under scenario b) during power cycles See TODO comments under function 'efi_disk_remove' for more details The original efi_secboot tests expect that BootOrder EFI variable is not defined. With this commit, the BootOrder EFI variable is automatically added when the disk is detected. The original efi_secboot tests end up with unexpected failure. The efi_secboot tests need to be modified to explicitly set the BootOrder EFI variable. squashfs ls test is also affected by this modification, need to clear the previous state before squashfs ls test starts. Co-developed-by: Masahisa Kojima Signed-off-by: Masahisa Kojima Signed-off-by: Raymond Mao Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_disk.c | 18 ++++++++ lib/efi_loader/efi_setup.c | 7 ++++ test/py/tests/test_efi_secboot/test_signed.py | 42 +++++++++---------- .../test_efi_secboot/test_signed_intca.py | 14 +++---- .../tests/test_efi_secboot/test_unsigned.py | 14 +++---- .../test_fs/test_squashfs/test_sqfs_ls.py | 6 +++ 6 files changed, 66 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index f0d76113b0..b808a7fe62 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -690,6 +690,13 @@ int efi_disk_probe(void *ctx, struct event *event) return -1; } + /* only do the boot option management when UEFI sub-system is initialized */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + return -1; + } + return 0; } @@ -742,6 +749,17 @@ int efi_disk_remove(void *ctx, struct event *event) dev_tag_del(dev, DM_TAG_EFI); return 0; + + /* + * TODO A flag to distinguish below 2 different scenarios of this + * function call is needed: + * a) Unplugging of a removable media under U-Boot + * b) U-Boot exiting and booting an OS + * In case of scenario a), efi_bootmgr_update_media_device_boot_option() + * needs to be invoked here to update the boot options and remove the + * unnecessary ones. + */ + } /** diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index e6de685e87..37359a77bb 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -245,6 +245,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { + /* update boot option after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py index ca52e853d8..2f862a259a 100644 --- a/test/py/tests/test_efi_secboot/test_signed.py +++ b/test/py/tests/test_efi_secboot/test_signed.py @@ -29,7 +29,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -37,7 +37,7 @@ class TestEfiSignedImage(object): # Test Case 1b, run unsigned image if no PK output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -59,13 +59,13 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('\'HELLO1\' failed' in ''.join(output)) assert('efi_start_image() returned: 26' in ''.join(output)) output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -77,12 +77,12 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -105,7 +105,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -143,7 +143,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -170,7 +170,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -181,7 +181,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -193,7 +193,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -205,7 +205,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -230,7 +230,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -254,7 +254,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -265,7 +265,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -279,7 +279,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -307,7 +307,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -330,7 +330,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -349,7 +349,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld_forged.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('hELLO, world!' in ''.join(output)) @@ -364,7 +364,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert(not 'hELLO, world!' in ''.join(output)) assert('\'HELLO1\' failed' in ''.join(output)) diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py index d8d599d22f..8d9a5f3e7f 100644 --- a/test/py/tests/test_efi_secboot/test_signed_intca.py +++ b/test/py/tests/test_efi_secboot/test_signed_intca.py @@ -40,7 +40,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_a host 0:1 /helloworld.efi.signed_a -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_a\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -49,7 +49,7 @@ class TestEfiSignedImageIntca(object): # Test Case 1b, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO_ab host 0:1 /helloworld.efi.signed_ab -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -71,7 +71,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -81,7 +81,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_b.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -91,7 +91,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) # Or, @@ -129,7 +129,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py index df63f0df08..7c078f220d 100644 --- a/test/py/tests/test_efi_secboot/test_unsigned.py +++ b/test/py/tests/test_efi_secboot/test_unsigned.py @@ -36,11 +36,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -65,7 +65,7 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -89,11 +89,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -107,11 +107,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index 527a556ed8..3b8118104f 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -118,6 +118,12 @@ def test_sqfs_ls(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled, default file(e.g. EFI/BOOT/BOOTAA64.EFI) + # is scanned when the new disk is detected. This ends up with the unexpected + # output at the first 'sqfsls' command. + # Clear the previous state. + u_boot_console.restart_uboot() + # setup test environment check_mksquashfs_version() generate_sqfs_src_dir(build_dir) From patchwork Sun Oct 15 23:49:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 733898 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp2466698wrv; Sun, 15 Oct 2023 16:56:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzWJw/iX26xK9NJBi9BwVgNhoeGrRwUN65M9GhIIUVfvUYtwRXeiPViqPkZjCeHbp62NNN X-Received: by 2002:adf:e744:0:b0:32d:9541:b1e3 with SMTP id c4-20020adfe744000000b0032d9541b1e3mr7697283wrn.26.1697414198853; Sun, 15 Oct 2023 16:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697414198; cv=none; d=google.com; s=arc-20160816; b=IbRS7TgfKlxAbd0fGTa1YserXFQQYtBt38EaXFuuK0BCVqXC8TRg48u2x2y3pP1Y1k wXBAYjASECrQBY43k8C9hzeG8BgQLlLw6ds0CrEcfEaG2VmaTPFBTmBq2qL0dLWcq6Mz +vZDpI54dPGH29wdiwJUTf+ITZOqXGo+bGcFEUu3nGDW2bun5xL3/quGuds+847SmTjT QxF0gP26T5q6wOHzHtxHTz+pIf4ne4fKohBovyxeB6P/YsW7/hAm8la6RWlAuaqGJ9ur CXcSMulQVgZC7k+t2C+rNsGQAkpAU12zZdOVhI8gIuksyn5QCxGP4UNfG8SuHkiYZT9S Qt7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; fh=UwEaQaZSKscgV8VKorL4WxKMlykH7WzwOcMeBrHkxSs=; b=x3xTSfIxyewXlWhVgfMGGwQODoyEg0NJYkCNytUquyMzJIWyHe40H1IJ0cpxKCKYBR cBr/AXr/1OpWMULORV+2CbIfu+/U5WUmAtKtgVRGa0lGJdlqHfHHSVzK2CX8KntdnKeG 82Nd4WuLCKLL69ftyzo3zedT8lrrV5/yq7hvxGAUA9ccvtQRzvffnA+xlxn+/+VE014K RrbnKFerKzPsIbNPQq59+BmgyoYHoEMO6TbKtAnj2d7+4pZrH+GczXzWHsRjNAockG11 Ii4oYZ8Pa1GvLuY6h7/YUbzyTWsBDAtRf+IxYHwNu2Iw4Tbjug65vM8X5Wt0LCYa33dm qo2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PhvjuYgJ; 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 a9-20020a5d4569000000b0032d4835245asi5657443wrc.940.2023.10.15.16.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:56:38 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PhvjuYgJ; 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 4E78D86DE8; Mon, 16 Oct 2023 01:53:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PhvjuYgJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C9E6867F6; Mon, 16 Oct 2023 01:51:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CE80086AE9 for ; Mon, 16 Oct 2023 01:51:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c88b467ef8so26463245ad.0 for ; Sun, 15 Oct 2023 16:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697413859; x=1698018659; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; b=PhvjuYgJLU2ytdZOqlM+5TCppOA3hSTebD0bpENYOEjAcOIgJiQEhtv8aXsnrIaKIh 5UOYsvu77ir3mLWdZmFq5cXGqsrL+QRPS01cM3XRdgbSVgdb53iEWyVSY7OQmHydzqf/ lhyBQOgNkta6EFmaVIwfRFH8D+TVCjcwJoV8ThUOM46lBs6VV9sRVLUZ24jwhpnQk/D+ iqlo5TPzuelTfuTdGEo1x60ytNX/f7d4ItrtZp3JG2bOIqWpKQrOCcjuuX2tPr3NUG3f uBavR5b2l6mbFsyt4+Qp2P85/KkZGMLIhdC5v9I80nKTCOyHcA1ihm6Pm+JgJeOAVLpn uTeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697413859; x=1698018659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ix7OkLuT2UMlsZ+CYDlpWbnES/L/lF+FUZtbgDuoIRo=; b=FivuVcnBC/wvVIUHdJkfeAFR+VLO4aM4vofYMTj2380vbWCoLHCGNtTF7VbIY3yjJn oAMzTLxuynrX9f4xc7tcAG6aHNHP+qLXzG2Y+aL6IOzBDI5FzxYLPcuY9ax03c/darji Dsk5YNzZy32x0aBAk5pjf03/KjWJiWBt8/8Zj2uPiwOJBdTjoR1sP7NLIegGOaMy+pvi LNumXfYxX3A9QbjbtfU8tDTdpHv0p98J1OuYqD+yeN879oinbCJf3fewH4xc0+VeWvqP znD2U4oPzDkhDAyVfzsizpncLdV/vWbC0TZ9XLmP1CrqHyI7q3wTTRzW7Cow5zmnkxkU kO7Q== X-Gm-Message-State: AOJu0Yy+lrgDsC8EdHWFIG2KjrhEGbSfy5MtHC1z0kRz03XdzITIisIV 9ef4rlYjtI92plv1+v9Y+tKaIBKNS68P7abeFn0= X-Received: by 2002:a17:903:cb:b0:1ca:7dcf:a74 with SMTP id x11-20020a17090300cb00b001ca7dcf0a74mr836146plc.22.1697413859187; Sun, 15 Oct 2023 16:50:59 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id i18-20020a170902eb5200b001bdeedd8579sm7206879pli.252.2023.10.15.16.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 16:50:58 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Joe Hershberger , Ramon Fried Subject: [PATCH v6 8/9] cmd: efidebug: add uri device path Date: Mon, 16 Oct 2023 08:49:06 +0900 Message-Id: <20231015234907.2362717-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231015234907.2362717-1-masahisa.kojima@linaro.org> References: <20231015234907.2362717-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This adds the URI device path option for 'boot add' subcommand. User can add the URI load option for downloading ISO image file or EFI application through network. Currently HTTP is only supported. Signed-off-by: Masahisa Kojima --- cmd/efidebug.c | 50 +++++++++++++++++++++++++++++++++++ include/net.h | 8 ++++++ net/wget.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 0be3af3e76..5f392d2ffd 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -829,6 +830,52 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, argc -= 1; argv += 1; break; +#if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) + case 'u': + { + char *pos; + int uridp_len; + struct efi_device_path_uri *uridp; + + if (argc < 3 || lo.label) { + r = CMD_RET_USAGE; + goto out; + } + id = (int)hextoul(argv[1], &endp); + if (*endp != '\0' || id > 0xffff) + return CMD_RET_USAGE; + + efi_create_indexed_name(var_name16, sizeof(var_name16), + "Boot", id); + + label = efi_convert_string(argv[2]); + if (!label) + return CMD_RET_FAILURE; + lo.label = label; + + uridp_len = sizeof(struct efi_device_path) + strlen(argv[3]) + 1; + fp_free = efi_alloc(uridp_len + sizeof(END)); + uridp = (struct efi_device_path_uri *)fp_free; + uridp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; + uridp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_URI; + uridp->dp.length = uridp_len; + if (!wget_validate_uri(argv[3])) { + printf("ERROR: invalid URI\n"); + r = CMD_RET_FAILURE; + goto out; + } + + strcpy(uridp->uri, argv[3]); + pos = (char *)uridp + uridp_len; + memcpy(pos, &END, sizeof(END)); + fp_size += uridp_len + sizeof(END); + file_path = (struct efi_device_path *)uridp; + argc -= 3; + argv += 3; + break; + } +#endif + default: r = CMD_RET_USAGE; goto out; @@ -1492,6 +1539,9 @@ static char efidebug_help_text[] = " -b|-B