From patchwork Mon Oct 16 06:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734021 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69698wrx; Sun, 15 Oct 2023 23:46:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHE8Qn3+qoIJwFu2gg/ehNGcVK3MFANOA2CTCIERWqESYyOt8Ls1g+tTngy33BTDVk4Dff7 X-Received: by 2002:a5d:4487:0:b0:32d:87c8:b548 with SMTP id j7-20020a5d4487000000b0032d87c8b548mr9630708wrq.21.1697438809858; Sun, 15 Oct 2023 23:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438809; cv=none; d=google.com; s=arc-20160816; b=WQ4MgUxdC84g7IgyAZjGTggPqc0340Onw0y59xm2N43FBjYUgik7oxqHygZugwl2RI sUfQf0sDkPztIyaEAcWC6JtXb2t65RO8uOsq97XPOgK0DBL2vIkfjB/+D0iV2vbgQuGW 48Kuod65X2kKs+htv3fbhIIlm/TuH8sutbVqPOi21bpQbnPS7z1jn1FxOAIlE/4AeVgT Pbz8QTVufZu71knUEt2k9CQfQbXh8MaGQJR/FwtcdgtW2cYPKt2CgN+Y/cSsXvVpndbR CYDZCwt+rtrnUsuL5aYpMqCRnP5LnY5u3BS8o6/JrZ4Y0ztuwyDT4FrnsdKoYUQgj+NC zkUQ== 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=rJgraZNtSTqiRDbKGXGRoX89DnV2i0OwHl6eUvMwsd+C6K2/0NcWt7+gkLvGDAL3iv WDeTVgZ2ezNMWCP/trV2RlucpiyMGXVMJuYyAgB16iE0dM3/RBXYGxRku3gzMsDwTtD3 4hYEi8Xt+2OCKzrkUPvomSHD4cJyaRUE5RiwL0et/aTRkt+MKK5hauSRNTvCcI64eSMd +24qcoUDnR8VU+ggTs4bCNOxOyJ1kNmuKIh/sHB75/ZsQe7esEx5knMKshp6hxMq5S0D 7KP6GI5lCHqOyJF968GxuX6epjQ8BT4R0dLgau/vYkhvwojOMlt9OEghgJhTh45QrqcU sLfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SFNTNslc; 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 d16-20020a056000115000b0031ffe1596e3si10980745wrx.702.2023.10.15.23.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:49 -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=SFNTNslc; 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 529F086B79; Mon, 16 Oct 2023 08:46:48 +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="SFNTNslc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BDC68869AC; Mon, 16 Oct 2023 08:46:46 +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-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (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 DF660868C0 for ; Mon, 16 Oct 2023 08:46:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6b3c2607d9bso1821401b3a.1 for ; Sun, 15 Oct 2023 23:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438793; x=1698043593; 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=SFNTNslc9eAvZACHOHg12R1rh+Rs0OEtk0ia7pWnWJmIPKrBfuD27Uuk3AVXZCxJ7s mmehnlQnzId9UE5GdF29KUXGhwcVF3Dd/7FJuGZuqe78I8fUfUZStj54+mqdiwT/KY8n cZnYgiIwg8a9qPRT9s0r3NbSeU4olLrp3E5crNMqKwtkwOMPnYLbWXtwxV5T+4+ve0u9 dXnIE3lpq9YVpEy5CIV3QMSeicKOnW4PiIlVCZVl2A65hSB/xW3YiEsC2PR1ILgQOdjK RgaWt/2IOu8r1OXrHz1jnGIk+8r2Y9A1PGOjNagl8oL+Qe40/dgPoNReqUcrzpvOsYUA xglA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438793; x=1698043593; 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=atooYxvPHfB6/8dKbUga8uLOewpcAjSm2defT844Pp7IQarhE3RAYgVgeWuC+PTUYR 1FTo4XRRKigOG1GqiR+r/z2KP357X5nl5Ovo50Yj3S6KAJNClegXx5kumYfxFAnEdbgm JZMB71ZbYRzxCSfHWOlKoa2xMbBcfhhijov3PvAQdpvUB6LoOFfPJa/7JtNgyl6SVZrP UnnxmIww51fl5KPEt1iLzlUNLfuqdfoJL9EnrbaduL+tv107PDhwILsO3pZDrYPi9rj9 F0OI1aeL1x9eyQ7FpZi/fUQWfMuFfVNBBlykL5pcQWqdImC71dqHQ8tvDGnBRprXUjuB 2vCA== X-Gm-Message-State: AOJu0YyejDJ6SOD2QitwK/SrZRuaN7M3EBcnAakkW3ejCnr76KocL3aL zWDP8q+Ad4+p9r3skKGwAVcEliRpMqDXhhfLYLc= X-Received: by 2002:a05:6a20:258d:b0:14d:e075:fc5d with SMTP id k13-20020a056a20258d00b0014de075fc5dmr33112772pzd.40.1697438793512; Sun, 15 Oct 2023 23:46:33 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b4-20020a170902ed0400b001c60d0a6d84sm7744481pld.127.2023.10.15.23.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:32 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Ramon Fried , Joe Hershberger Subject: [PATCH v7 1/9] net: wget: prevent overwriting reserved memory Date: Mon, 16 Oct 2023 15:45:18 +0900 Message-Id: <20231016064526.2410856-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This introduces the valid range check to store the received blocks using lmb. The same logic is implemented in tftp. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas Reviewed-by: Simon Glass Reviewed-by: Ramon Fried --- net/wget.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/net/wget.c b/net/wget.c index 8bb4d72db1..6f97eb1d12 100644 --- a/net/wget.c +++ b/net/wget.c @@ -4,16 +4,20 @@ * Copyright Duncan Hare 2017 */ +#include #include #include #include #include #include +#include #include #include #include #include +DECLARE_GLOBAL_DATA_PTR; + static const char bootfile1[] = "GET "; static const char bootfile3[] = " HTTP/1.0\r\n\r\n"; static const char http_eom[] = "\r\n\r\n"; @@ -56,6 +60,29 @@ static unsigned int retry_tcp_ack_num; /* TCP retry acknowledge number*/ static unsigned int retry_tcp_seq_num; /* TCP retry sequence number */ static int retry_len; /* TCP retry length */ +static ulong wget_load_size; + +/** + * wget_init_max_size() - initialize maximum load size + * + * Return: 0 if success, -1 if fails + */ +static int wget_init_load_size(void) +{ + struct lmb lmb; + phys_size_t max_size; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + + max_size = lmb_get_free_size(&lmb, image_load_addr); + if (!max_size) + return -1; + + wget_load_size = max_size; + + return 0; +} + /** * store_block() - store block in memory * @src: source of data @@ -64,10 +91,25 @@ static int retry_len; /* TCP retry length */ */ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) { + ulong store_addr = image_load_addr + offset; ulong newsize = offset + len; uchar *ptr; - ptr = map_sysmem(image_load_addr + offset, len); + if (IS_ENABLED(CONFIG_LMB)) { + ulong end_addr = image_load_addr + wget_load_size; + + if (!end_addr) + end_addr = ULONG_MAX; + + if (store_addr < image_load_addr || + store_addr + len > end_addr) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); memcpy(ptr, src, len); unmap_sysmem(ptr); @@ -248,25 +290,39 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, net_boot_file_size = 0; - if (len > hlen) - store_block(pkt + hlen, 0, len - hlen); + if (len > hlen) { + if (store_block(pkt + hlen, 0, len - hlen) != 0) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } + } debug_cond(DEBUG_WGET, "wget: Connected Pkt %p hlen %x\n", pkt, hlen); for (i = 0; i < pkt_q_idx; i++) { + int err; + ptr1 = map_sysmem( (phys_addr_t)(pkt_q[i].pkt), pkt_q[i].len); - store_block(ptr1, - pkt_q[i].tcp_seq_num - - initial_data_seq_num, - pkt_q[i].len); + err = store_block(ptr1, + pkt_q[i].tcp_seq_num - + initial_data_seq_num, + pkt_q[i].len); unmap_sysmem(ptr1); debug_cond(DEBUG_WGET, "wget: Connctd pkt Q %p len %x\n", pkt_q[i].pkt, pkt_q[i].len); + if (err) { + wget_loop_state = NETLOOP_FAIL; + wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); + return; + } } } } @@ -338,6 +394,7 @@ static void wget_handler(uchar *pkt, u16 dport, len) != 0) { wget_fail("wget: store error\n", tcp_seq_num, tcp_ack_num, action); + net_set_state(NETLOOP_FAIL); return; } @@ -428,6 +485,15 @@ void wget_start(void) debug_cond(DEBUG_WGET, "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); + if (IS_ENABLED(CONFIG_LMB)) { + if (wget_init_load_size()) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory...\n"); + net_set_state(NETLOOP_FAIL); + return; + } + } + net_set_timeout_handler(wget_timeout, wget_timeout_handler); tcp_set_tcp_handler(wget_handler); From patchwork Mon Oct 16 06:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734022 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69761wrx; Sun, 15 Oct 2023 23:47:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzOlDxi6IeuBzmsMws5kY2Gr6iJDDapzjGPACkitPcmlNikn4bRyLLA6SDwKekl6SiNvRm X-Received: by 2002:a5d:630b:0:b0:32d:a4c9:8ab4 with SMTP id i11-20020a5d630b000000b0032da4c98ab4mr3933505wru.65.1697438820521; Sun, 15 Oct 2023 23:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438820; cv=none; d=google.com; s=arc-20160816; b=zxsmhWTwOeCjMgGqo/qZYT4qDSsCKjiXcEDiLbf1wJWabYe48vMiKnf/H8zaQWqeYM u+j+5yH2N+MAM3tsfAXYrkyI5WGLHQtUJlES1Qywd2t7s/mQnTVVWejYNUEbyfoP5X7t 4Lr+qaQonKvsPksUACaV4+JdhYa4Wj92dK5N7TIvD5W9RJF2jIyooar+uC4x/IpAS0Fr ggOdIEgb1vLQQDx27hoFwYq3k2T7Y0yGItrKvuTUzB+18HC8EfBg8Kfm+R8f62lBmdDw B7scyJ+liGE1SlBPNelmKtYc2BJn0I53l8g4aXJfvCaZG6gijVnAfMOib7SPLvjhQaRC W3fA== 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=yAyjoTUmsh18Ent79oc1JDfSJoogTyS352HOYZItu/I8x3iG1rllHHrAJBxFDTCGHN 4ngxevJhneDvkwM/eRsBUp4xBGgWlfGGEUEFXfpzGfIUFDiXkq5zrZPpRfdRnBU2KaAM 0vquM9xCzq5dl+KjWsVeqWOLKboxBXtfoPwcIWr9Ch1NO+J9wzN9vCgtsgR/x+3m0diA p7r7+oPNyJsga3caD2pMa8NKXhZiKBm3hb0MPcyFRGMQGXPAWhiHMGZTeNX/7uf9VptF TPja2QgtY4VePgIrNxOgCvZi3DUJ86o4VAp1DT+wOEv9blr2ZgTqdIV4dnnIu4H8P5rc zrkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VA32gHTf; 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 v21-20020a05600c12d500b00405133d6957si2258803wmd.160.2023.10.15.23.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:00 -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=VA32gHTf; 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 06A1886E37; Mon, 16 Oct 2023 08:46:55 +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="VA32gHTf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 88A7D86DB3; Mon, 16 Oct 2023 08:46:52 +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-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6FCB086D2D for ; Mon, 16 Oct 2023 08:46:40 +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-x42a.google.com with SMTP id d2e1a72fcca58-6b1d1099a84so2621561b3a.1 for ; Sun, 15 Oct 2023 23:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438798; x=1698043598; 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=VA32gHTfefOXB/3wNx8ackzzen2X1lnFXDyQ8WUKPS6HqXHUfvSFKReNkTiSGZdUUa ksdZbpPcP+pUtw0Ap59MooW4zXBPe81LIoNDjvuLkAzdudoRA1rMX/UewQXnBwPVnNKY cd2DgtcQ4GcFU3RRp7JnmZwTT8VVsr1SF9uuY0UZ+M6Q/alAcA4R1Y6Yt/xv23Y4VXPG ETCQS5X1Zcyv7JgyK5k4npKtLWVV3VwfEKAhVlulPqhzmcthcLahALIKkbbTDirb7KIg 4rOQJJjF+gcj2+AWgO+v8ih879ZceeKsIcDNS1TBv98KdbSG80bnmWlDi3cJMkLJaxw6 BV2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438798; x=1698043598; 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=RQ06uQ7YcM/HcqzzlonRcFE6xasaztY0hf3kpYwb0m8yb/H3lQ0GHD1RleUSDkf+RH 48iaVV3B1F4ktyEJSCD0EJ2Epnctn4whPg8oRF1x/S9v4umujhediqAunnd/eW0i3mBs YWfTZakTnraZePiZoMUxToAfUafxsEFEQXTDRjDo+uJsANckAjPxDpF7S4U7GFbzahJ9 oDY5bsxylWMHtKoebVUxv2t3qlwleTwenmKh9Eb8jl4l8PMicvicMVSU6eK3jEipklMV yW4j67cs63/a4N7nDW6NOTHilKSKrao5Koo/chN3G8jhwEszO2Fy8HpHzvbmm9HU83tq y86A== X-Gm-Message-State: AOJu0Yyc5MtNVFerQMGspxXLm5QwI1y8AWiHfd/ypJ5UMIT1s8hrenj6 UP9mpnh3aNYJp0SmdQz4p4sEwPJcEa5qL2SRKMs= X-Received: by 2002:a05:6a20:ce89:b0:15d:5f9a:3921 with SMTP id if9-20020a056a20ce8900b0015d5f9a3921mr31163257pzb.27.1697438798556; Sun, 15 Oct 2023 23:46:38 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id m12-20020a170902db0c00b001ca21c8abf7sm3714721plx.188.2023.10.15.23.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:37 -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 v7 2/9] net: wget: add wget with dns utility function Date: Mon, 16 Oct 2023 15:45:19 +0900 Message-Id: <20231016064526.2410856-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current wget takes the target uri in this format: ":" e.g.) 192.168.1.1:/bar The http server ip address must be resolved before calling wget. This commit adds the utility function runs wget with dhs. User can call wget with the uri like "http://foo/bar". Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas Reviewed-by: Ramon Fried --- include/net.h | 9 +++++++++ net/wget.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/net.h b/include/net.h index e254df7d7f..57889d8b7a 100644 --- a/include/net.h +++ b/include/net.h @@ -926,4 +926,13 @@ void eth_set_enable_bootdevs(bool enable); static inline void eth_set_enable_bootdevs(bool enable) {} #endif +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); + #endif /* __NET_H__ */ diff --git a/net/wget.c b/net/wget.c index 6f97eb1d12..2087146b37 100644 --- a/net/wget.c +++ b/net/wget.c @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -512,3 +513,56 @@ void wget_start(void) wget_send(TCP_SYN, 0, 0, 0); } + +#if (IS_ENABLED(CONFIG_CMD_DNS)) +int wget_with_dns(ulong dst_addr, char *uri) +{ + int ret; + char *s, *host_name, *file_name, *str_copy; + + /* + * Download file using wget. + * + * U-Boot wget takes the target uri in this format. + * ":" e.g.) 192.168.1.1:/sample/test.iso + * Need to resolve the http server ip address before starting wget. + */ + str_copy = strdup(uri); + if (!str_copy) + return -ENOMEM; + + s = str_copy + strlen("http://"); + host_name = strsep(&s, "/"); + if (!s) { + log_err("Error: invalied uri, no file path\n"); + ret = -EINVAL; + goto out; + } + file_name = s; + + /* TODO: If the given uri has ip address for the http server, skip dns */ + net_dns_resolve = host_name; + net_dns_env_var = "httpserverip"; + if (net_loop(DNS) < 0) { + log_err("Error: dns lookup of %s failed, check setup\n", net_dns_resolve); + ret = -EINVAL; + goto out; + } + s = env_get("httpserverip"); + if (!s) { + ret = -EINVAL; + goto out; + } + + strlcpy(net_boot_file_name, s, sizeof(net_boot_file_name)); + strlcat(net_boot_file_name, ":/", sizeof(net_boot_file_name)); /* append '/' which is removed by strsep() */ + strlcat(net_boot_file_name, file_name, sizeof(net_boot_file_name)); + image_load_addr = dst_addr; + ret = net_loop(WGET); + +out: + free(str_copy); + + return ret; +} +#endif From patchwork Mon Oct 16 06:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734024 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69907wrx; Sun, 15 Oct 2023 23:47:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2HIj3qG6wWYvgBntPnJAH21dSajeTp46Mexwd0m8T6qC6mJn6+eGKN+UaQbwZKfOIYIVX X-Received: by 2002:adf:f348:0:b0:32d:9b80:e2c6 with SMTP id e8-20020adff348000000b0032d9b80e2c6mr6091530wrp.26.1697438859700; Sun, 15 Oct 2023 23:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438859; cv=none; d=google.com; s=arc-20160816; b=qAJeoT6ZTyIz/RGdhn85VRp2IxDIZREE43pHbNp0KKMr/RdhcOHFdxjmdu5VpzsOLo slYq8x13fiGZpH5fCKZGPDcag16Wv4jHPzA1lh9S1vAgxh4RIqaFD/bwIqbsyYJ/5qMi mtVRwhy0HiVB5UkYQoSP0Wl2GJGmvEh9W2sUSW2EPo/pVC/Jsf4EFqZaL4YT57zcGMho 0k5xmFltP3X/wPin+UTgX1dnvc5fmPNPW/t1A7CCr7sn5cTdmOWTzmyNE5PXmfLZ4Pjw IS8xHK5H2NuQbeDFGJKd6lrEQ0TKsx5qdI+N3eBNKFNmJ6wiJ+CNvJttUYVhtru7pN8+ SB/w== 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=xaxoNW/0J8bQhkhGDI+bOKMg7KYyd11GDPyKmVd7UHnIJxu1fkFpp0IhFe1uqJDNrc G/b6sO0kEBj+gVXS5BUBmqsLILt6U+5c4vh131UD5WYD5b0I/wCwo00WXyMXvPghkSsh ljcbyuTgnFtEk6120aV6Zt4BVr3cd/AJZjojWna7FmdgSB6BoT3buDS9LsTXyplYSDRL AVvquShJI1kfxgnEN9etRblfvMDO7roqne2xGbT1mweYTR5uhMmWn7+feTubZRrSJcgg 4A2WBSnRDh9ns0Sb0CRWgGs/WGvrVFS/ClFZ8H4HwxYIPWK/Es76dV2Kzm5KdEEfFYDL Ft6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uxJZkQGi; 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 t7-20020a0560001a4700b0032dae6f547esi1128732wry.402.2023.10.15.23.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:39 -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=uxJZkQGi; 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 7ACF186DC6; Mon, 16 Oct 2023 08:47:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="uxJZkQGi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 189C786DE8; Mon, 16 Oct 2023 08:47:08 +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-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 191118477A for ; Mon, 16 Oct 2023 08:46:47 +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-x42d.google.com with SMTP id d2e1a72fcca58-6b201a93c9cso2045296b3a.0 for ; Sun, 15 Oct 2023 23:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438805; x=1698043605; 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=uxJZkQGiINWYoTBGvoAKQauFg6+NdfGhiu7AqNf7qPzTX+ag2Mssau2GW+oVY+PKTQ k6DnTnVK85Ui2xAbTaO6h96KmJnpd9V1sVf1MQpj+ExuXM9IzW/UuP8IVcaaeqmNtz/e VRQxZYFVn5/sOEM6sA4y/1y8Buh8+hANXDwP/zeUYQSNfaPeTy5nggA2+JxGLqrBm9Ts 9VNO/rih96UsUig1hz/4rrNANUFEOsZniMOEmZpRaWiw0jP65cXjkRfZ1LkMo60NYBI3 S+8TJHyDMhwDSXAFOFqh8TlLtQr5OEU9HKqiWO1sm7kcEbR3J0rPgP6oQnzxozpFCW47 RiIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438805; x=1698043605; 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=NXTGzQtf04g9ZIdkTc3z71lH3mzeoZl2FvILvOoWI+LlFVqctYWcbsPG8z6kfX8h/F VdJY5GJd/mK+3ljgomzflcKvKrZVYvCkTcA4Yp8gXvbCEN06aypQtVAbYwvbaSmG5f6R NEoaM0+c0LopIfd9oPCd12du80scg2zE113DJUk3U4Hoaa1TybJMLva8snlUnNksMqi8 38iJAq3JHPMK49OVLNGbzjT5eAms9ULJV6gqCzKiXsi24Bh+2nS1e1Jo03Myu5uhZHu0 k5e2t+sE1xmeY64YaLoEJyIFXuIYqvO2h613a47VTnYfzun5xHHA96YkQWNKjhSM186E P6qw== X-Gm-Message-State: AOJu0YwxqoUYy6rDDb7a0ToFmzH3Al+EmGtNbWh3wmBTBf0cz4cmDumW 62XnzUy7O9dyQ6/kwYRHfrWrAb2akSXoxS1TdZ0= X-Received: by 2002:a05:6a20:d41e:b0:16b:74bb:e57e with SMTP id il30-20020a056a20d41e00b0016b74bbe57emr21518838pzb.12.1697438805210; Sun, 15 Oct 2023 23:46:45 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h24-20020a170902ac9800b001c3be750900sm7760826plr.163.2023.10.15.23.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:44 -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 v7 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 16 Oct 2023 15:45:20 +0900 Message-Id: <20231016064526.2410856-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean User needs to call several functions to create the ramdisk with blkmap. This adds the utility function to create blkmap device and mount the ramdisk. Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- drivers/block/Makefile | 3 +- drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..ec0575d135 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_IDE) += ide.o endif obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o -obj-$(CONFIG_BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap_helper.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 149a4cac3e..21201409ed 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */ From patchwork Mon Oct 16 06:45:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734023 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69865wrx; Sun, 15 Oct 2023 23:47:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaHk7CyEY/yoIHBf03nFbBadGLL5NwgTejV9NkYDz920zzrKpoSsUNgrfzBTUuDnom7bG4 X-Received: by 2002:a05:600c:1c96:b0:401:c944:a4d6 with SMTP id k22-20020a05600c1c9600b00401c944a4d6mr17528726wms.28.1697438849699; Sun, 15 Oct 2023 23:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438849; cv=none; d=google.com; s=arc-20160816; b=NOMY6Ns6AgwjaKg0mo66d60arqMP6Eai3RgZwnOmXah6cqaO4fmibib6tBNpraG1uu phtpeiysaZ5izlyQhCw3mOM17E0QECswGTjIqvDNvjlqMSQ2F4OazNZ5KJckAibOHwVJ G9wEi17F32hRttOEgpocTOknai2SS6w/c9ZaKguLas3v7mf0/4mdk/nbBcVqpjc/guEx wK2SvYoNnvXsDwHX7Aw7r9iC+e+JB9ee539jY5Jc7i2XLSyVMDaZgnBiril9380U2n5t KfuLzi+Wm7or9/IDush8swFrZlRrx8YuPmlOD2so2Wxa1zZEsEo/a4hEqGdxXGm+/FCB SNHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=sN5ETqvTpXzu5fxnJkiZK1913gsg68zSCrPknmkplcBXzIESEWu6JUcn+WAom3M8S6 ws2v6qkFSOAVew4aaoODYA94pN8lcmHqlymBY5XAiqZ/f4JLj3PVJuqc8S34KQNRXo1m xJHD/OanLUMykMpqsav4KJo8NGihqzaNN76UAG9ihCkjkAMhzA02Alzz3gqyzQOF6USm ncnCsXOiE17cE1dM3GD/ItBHu/BxSH1W0Mb6+CgD1tZ6TV1Em08K+8N0HBCXqeJSfyAT 4HQGh5wcggjqljX7EtyMrPmnp/PoeNenavPWg4aYb2HFFRgaPVQ66F70Q0YLk3rfE0mN JJwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UNla7tw0; 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 t27-20020a05600c329b00b004063e3cdf17si2294081wmp.150.2023.10.15.23.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:29 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UNla7tw0; 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 224178477A; Mon, 16 Oct 2023 08:47:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="UNla7tw0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF86286DB3; Mon, 16 Oct 2023 08:47:10 +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 D7B5386D2D for ; Mon, 16 Oct 2023 08:46:52 +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-1c5c91bec75so26083685ad.3 for ; Sun, 15 Oct 2023 23:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438811; x=1698043611; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; b=UNla7tw0hZ9ESUAJmU4pProgivs4StZ5YAmWTT8guiKWSld1Fcb17ofpZ4nQMr5UPY dljy95GdUcCpK9K8uubH3zGvDkTdzZsa9804hbb22sPmzhUI3V6FT4vH2CablNAfrH3O KaFUe6fYTAJCViUXg5BnHKSVb07HkzvU32g5NH58KNB3d4OV4WiW7dOofuNOWiUOR4Wo lnTDuzm/+689lIdQRHQ5N5bpnTK8cEUcaLPYAbe2m/QocCSftSATE9SiyydU5s/BPhOX nPH7Z6pJNHDUBOtY2MtMw+90xaPzwH6EcRypB/wWmscgMMTJW0X9Qfe5rrtfMzETbowo /7og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438811; x=1698043611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iAmFUGgEnR04lMoIFR98JXoRfIMyvt0aJ08PywRnLXU=; b=DwmgkDp4jI/VTRxwhjp0I6xWjTFCpkRRx1qikMnN3h/KrsEdg1XRF0Va4Tog9oUo0V gbMuBYAMz4i04wdjSky/c6bqwGiVz21dr+q6swZteD5Kkhe+2F0TlFI8u4tD1fQ2FRHs DQrg+U58l/Uf+5pXobvbHyUGFdF4+I8DaPJPNFeHe8+z2cHhT2TPlDCvH1kn//suTKFh IumVJ6n3WV6FWzF5peP/JMpqHU40c0CyPi4oRsclt4cRml1LHRAt1O1zi0pKdcGt+5lj w8WeRWSsDF7Zn5DL3rXflUfLlLMFa+S5VY/jjmZx9Gkru7qOIhaQf8zEtMeh4S+Dakc4 BW8g== X-Gm-Message-State: AOJu0YweLYhwQrPJlJk2ukmMPldQr5heYzgvGnlv05xD1ykIhhpDqyz2 bKBqy680XgvGFFYDz9QUxOtdxIpfywBs5/rGZoU= X-Received: by 2002:a17:902:b48b:b0:1c4:4462:f1bd with SMTP id y11-20020a170902b48b00b001c44462f1bdmr24988052plr.35.1697438810714; Sun, 15 Oct 2023 23:46:50 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b2-20020a170902650200b001b898595be7sm7904538plk.291.2023.10.15.23.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:50 -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 v7 4/9] efi_loader: create default file boot option Date: Mon, 16 Oct 2023 15:45:21 +0900 Message-Id: <20231016064526.2410856-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Current efibootmgr automatically creates the boot options of all disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. Some of the automatically created boot options are useless if the disk and partition does not have the default file(e.g. EFI/BOOT/BOOTAA64.EFI). This commit only creates the boot option if the disk and partition have the default file so that system can directly boot from it. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 86 ++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a40762c74c..c8cf1c5506 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -355,40 +355,70 @@ error: */ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boot_option *opt, efi_handle_t *volume_handles, - efi_status_t count) + efi_uintn_t *count) { - u32 i; + u32 i, num = 0; struct efi_handler *handler; efi_status_t ret = EFI_SUCCESS; - for (i = 0; i < count; i++) { + for (i = 0; i < *count; i++) { u16 *p; u16 dev_name[BOOTMENU_DEVICE_NAME_MAX]; char *optional_data; struct efi_load_option lo; char buf[BOOTMENU_DEVICE_NAME_MAX]; - struct efi_device_path *device_path; + struct efi_device_path *device_path, *full_path, *dp, *fp; struct efi_device_path *short_dp; + struct efi_file_handle *root, *f; + struct efi_simple_file_system_protocol *file_system; + u16 *default_file_path = NULL; - ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); + ret = efi_search_protocol(volume_handles[i], + &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) continue; - ret = efi_protocol_open(handler, (void **)&device_path, - efi_root, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + + device_path = handler->protocol_interface; + full_path = efi_dp_from_file(device_path, + "/EFI/BOOT/" BOOTEFI_NAME); + + /* check whether the partition or disk have the default file */ + ret = efi_dp_split_file_path(full_path, &dp, &fp); + if (ret != EFI_SUCCESS || !fp) + goto next_entry; + + default_file_path = efi_dp_str(fp); + if (!default_file_path) + goto next_entry; + + ret = efi_search_protocol(volume_handles[i], + &efi_simple_file_system_protocol_guid, + &handler); if (ret != EFI_SUCCESS) - continue; + goto next_entry; + + file_system = handler->protocol_interface; + ret = EFI_CALL(file_system->open_volume(file_system, &root)); + if (ret != EFI_SUCCESS) + goto next_entry; + + ret = EFI_CALL(root->open(root, &f, default_file_path, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) + goto next_entry; + + EFI_CALL(f->close(f)); ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); if (ret != EFI_SUCCESS) - continue; + goto next_entry; p = dev_name; utf8_utf16_strncpy(&p, buf, strlen(buf)); /* prefer to short form device path */ - short_dp = efi_dp_shorten(device_path); - if (short_dp) - device_path = short_dp; + short_dp = efi_dp_shorten(full_path); + device_path = short_dp ? short_dp : full_path; lo.label = dev_name; lo.attributes = LOAD_OPTION_ACTIVE; @@ -396,24 +426,35 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo lo.file_path_length = efi_dp_size(device_path) + sizeof(END); /* * Set the dedicated guid to optional_data, it is used to identify - * the boot option that automatically generated by the bootmenu. + * the boot option that automatically generated by the efibootmgr. * efi_serialize_load_option() expects optional_data is null-terminated * utf8 string, so set the "1234567" string to allocate enough space * to store guid, instead of realloc the load_option. */ lo.optional_data = "1234567"; - opt[i].size = efi_serialize_load_option(&lo, (u8 **)&opt[i].lo); - if (!opt[i].size) { - ret = EFI_OUT_OF_RESOURCES; - goto out; + opt[num].size = efi_serialize_load_option(&lo, (u8 **)&opt[num].lo); + if (!opt[num].size) { + efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); + efi_free_pool(default_file_path); + return EFI_OUT_OF_RESOURCES; } /* set the guid */ - optional_data = (char *)opt[i].lo + (opt[i].size - u16_strsize(u"1234567")); + optional_data = (char *)opt[num].lo + (opt[num].size - u16_strsize(u"1234567")); memcpy(optional_data, &efi_guid_bootmenu_auto_generated, sizeof(efi_guid_t)); + num++; + +next_entry: + efi_free_pool(full_path); + efi_free_pool(dp); + efi_free_pool(fp); + efi_free_pool(default_file_path); } -out: - return ret; + *count = num; + + return EFI_SUCCESS; } /** @@ -642,7 +683,7 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index) * efi_bootmgr_update_media_device_boot_option() - generate the media device boot option * * This function enumerates all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL - * and generate the bootmenu entries. + * and create the boot option with default file if the file exists. * This function also provide the BOOT#### variable maintenance for * the media device entries. * - Automatically create the BOOT#### variable for the newly detected device, @@ -674,8 +715,7 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) goto out; } - /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */ - ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, count); + ret = efi_bootmgr_enumerate_boot_option(opt, volume_handles, &count); if (ret != EFI_SUCCESS) goto out; From patchwork Mon Oct 16 06:45:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734026 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp70017wrx; Sun, 15 Oct 2023 23:48:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERkixW00gPvnITPPvd6kKPb3FnTt3HOzkIkKO3SGqB6rj40jmW18GlUSebfHm9mBgkEUtt X-Received: by 2002:a5d:5a0d:0:b0:32d:a8aa:4d01 with SMTP id bq13-20020a5d5a0d000000b0032da8aa4d01mr4306866wrb.20.1697438882691; Sun, 15 Oct 2023 23:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438882; cv=none; d=google.com; s=arc-20160816; b=nfnOftHTjPuEXYsdY2RdkOWHPVlRV3BQbwiwbXmUyrRAIhKNxE7JEY9kzFOwkUmDxw lbdPehKgIRzcDrHulC9OS+UbyvevsVp86btE8pwvrznQAxG1DgR3MQ1AaJA2TGK90Prd kNQRs/wjmWbWiQnWSrA7KIBFi4NR4CjgZq3aOIw1eg262tN4Pmkr+oSXzasasQxE98EH jUaddH5g6wnrpiIt6zI/aaTACDGVQCNtZ0JixSPXIGLakdc3Xg6McZlAtmf+H6y/lM9S f9p2tPq7V7whqZ3pet3QJ5M+WDpkoLM5aiW2CXOrDJtDUVHOjNT5jD7LPEatYWd8YbMU iZ2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; fh=I7E+BwgHMByijVVN/pPHsLSpz7oP4y4e73noHEekrEE=; b=hER1Gv39JfiPyCn6MbC40ubrN2Z9xfMvEc20h8+jSHdLM6q/HVFvK7y/UqK35E8zub 99FI1cJfV0iDHGZsXk5sMSIddTAJpdqpF5y3pwIH2FhoZFyUQ3ycqMz3IQSDp2wrSFpO 0tUg8b4P2XOeiBsj3+Edozep65mE+qzQMBI4pH1OiMwYShC/qIvGSHz1KVjtBdW3ykwk 2eMUY+cLoWW0fupUdM5QQhFE62BI30GIM2xY2/4yWhpvT7+0qBImj4aQNeS7zo8gj8uE QGfpFvj2+XGoE7aBK1Nj0MWDU9B1H1sw4g3GuECCFSZbPi1JQb2rQWX0/9bM/mFlkLsB 3wQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CzPV9jxC; 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 az9-20020adfe189000000b0032d939c96b6si4130563wrb.765.2023.10.15.23.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CzPV9jxC; 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 60F7386ECA; Mon, 16 Oct 2023 08:47: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=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="CzPV9jxC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66F7186B79; Mon, 16 Oct 2023 08:47:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 DE55B869D1 for ; Mon, 16 Oct 2023 08:46:59 +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-x52b.google.com with SMTP id 41be03b00d2f7-5ac865d1358so1419874a12.3 for ; Sun, 15 Oct 2023 23:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438816; x=1698043616; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; b=CzPV9jxC1rR1WOtTYPCXp0dQjq5z5kx4ZRrNUKgKiNBKhRTq40qcqTi8rRrtpFGAZ1 ycc8bg0N2IEOYyEqTg/0AhIh07ZPM1EpeDWkZcQC9npwL2YdwizWpcRybxVV0lKrT8sF 676tiaCJXHsuZR4MlAS3w+btwyeRGcRWkKY/NYDfWzEk0lLQuCtGnNzdqMruvRmlOM1Y EumzmFHhz5/7r9felxtKVfnQ96haQMVG0OQVZEkVYwLsWy2WTFQSjM3t/5fOUKlXW3pL YGgarRwiFhufHkyvL8l0oMKeQhj4JgqbbetikNWnHGMFhKVCsV7UflnLSQqNaziqFnRT AFLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438816; x=1698043616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZXMf5UfRwHPQlXmTbVkSjKS7ARR6qG8bcLjzqlF2Al8=; b=FF+w0EWFNWkXfc8Pg44cT/+FpdlToefZDpbEOkHVjOGavH/e9K2mvo0Q68D45+ui3y GKqab9KuLImmQ3chdpTtIKQzm3CmaS8ev8b+wpW/Z4OGpwGtwVWQ39bzbM7hYgTxfpQm sp72IM86tRtucJUSlc2a371JV1aGhTagDTfJcLVyDwSeKZfYNCg91/DHfhF/p4NOF7Px DQx4vHb8e9hHF8KgQuStPKCiPOHXIHR2a9btBmNDvQujrcQkyiRaytmbQhOJECZ1XpE4 XamTEqm7ckuaai9z77/ybmE+lNyv1H7oRGF+NQL4c0OLD746HoqRHIZB8rkoSxIm8Cnt zckg== X-Gm-Message-State: AOJu0YwDwG8MN8GIY8MaN3y527Rz30irx9lnXirGYEk5bVeIy4Y6Q3cG 6Da+9QYwjFQTr9bOFfatpEnqI5yXzqAiO7Cng/Y= X-Received: by 2002:a17:90a:bf16:b0:27d:198:fcc2 with SMTP id c22-20020a17090abf1600b0027d0198fcc2mr11571586pjs.33.1697438816212; Sun, 15 Oct 2023 23:46:56 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id iy6-20020a170903130600b001c877f27d1fsm7737299plb.11.2023.10.15.23.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:55 -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 v7 5/9] efi_loader: support boot from URI device path Date: Mon, 16 Oct 2023 15:45:22 +0900 Message-Id: <20231016064526.2410856-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This supports to boot from the URI device path. When user selects the URI device path, bootmgr downloads the file using wget into the address specified by loadaddr env variable. If the file is .iso or .img file, mount the image with blkmap then try to boot with the default file(e.g. EFI/BOOT/BOOTAA64.EFI). Since boot option indicating the default file is automatically created when new disk is detected, system can boot by selecting the automatically created blkmap boot option. If the file is PE-COFF file, load and start the downloaded file. The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image. For PE-COFF file case, this memory reservation is done in LoadImage Boot Service. Signed-off-by: Masahisa Kojima --- include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 9 ++ lib/efi_loader/efi_bootmgr.c | 198 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_dt_fixup.c | 2 +- 4 files changed, 210 insertions(+), 1 deletion(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index e24410505f..106006127b 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -554,6 +554,8 @@ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition, void **address); +/* add reserved memory to memory map */ +void efi_reserve_memory(u64 addr, u64 size, bool nomap); /* Carve out DT reserved memory ranges */ void efi_carve_out_dt_rsv(void *fdt); /* Purge unused kaslr-seed */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index d20aaab6db..5d99206dc3 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -479,4 +479,13 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_HTTP_BOOT + bool "EFI HTTP Boot support" + depends on CMD_DNS + depends on CMD_WGET + depends on BLKMAP + help + Enabling this option adds EFI HTTP Boot support. It allows to + directly boot from network. + endif diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index c8cf1c5506..c90b68f783 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -7,10 +7,14 @@ #define LOG_CATEGORY LOGC_EFI +#include +#include #include #include +#include #include #include +#include #include #include #include @@ -168,6 +172,192 @@ out: return ret; } +/** + * mount_image() - mount the image with blkmap + * + * @lo_label: u16 label string of load option + * @image_addr: image address + * @image_size: image size + * Return: pointer to the UCLASS_BLK udevice, NULL if failed + */ +static struct udevice *mount_image(u16 *lo_label, ulong image_addr, int image_size) +{ + int err; + struct blkmap *bm; + struct udevice *bm_dev; + char *label = NULL, *p; + + label = efi_alloc(utf16_utf8_strlen(lo_label) + 1); + if (!label) + return NULL; + + p = label; + utf16_utf8_strcpy(&p, lo_label); + err = blkmap_create_ramdisk(label, image_addr, image_size, &bm_dev); + if (err) { + efi_free_pool(label); + return NULL; + } + bm = dev_get_plat(bm_dev); + + efi_free_pool(label); + + return bm->blk; +} + +/** + * load_mounted_image() - load mounted image with default file + * + * @devnum: target blkmap device + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t load_mounted_image(int devnum, efi_handle_t *handle) +{ + u32 i; + u16 *bm_label, *p; + char device_name[12]; + u16 *bootorder = NULL; + efi_uintn_t num, size; + void *load_option = NULL; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + efi_status_t ret = EFI_NOT_FOUND; + + snprintf(device_name, 12, "blkmap %d", devnum); + bm_label = calloc(1, (strlen(device_name) + 1) * sizeof(u16)); + if (!bm_label) + return EFI_OUT_OF_RESOURCES; + + p = bm_label; + utf8_utf16_strcpy(&p, device_name); + + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) + goto out; + + num = size / sizeof(u16); + for (i = 0; i < num; i++) { + efi_create_indexed_name(varname, sizeof(varname), "Boot", + bootorder[i]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + free(load_option); + continue; + } + + /* check whether the label indicates the target blkmap device */ + if (u16_strncmp(bm_label, lo.label, u16_strlen(bm_label))) { + free(load_option); + continue; + } + + /* check whether the boot option is automatically generated */ + if (guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + free(load_option); + continue; + } + + ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, + NULL, 0, handle)); + free(load_option); + goto out; + } + + if (i == num) + ret = EFI_NOT_FOUND; +out: + free(bm_label); + free(bootorder); + + return ret; +} + +/** + * try_load_from_uri_path() - Handle the URI device path + * + * @uridp: uri device path + * @lo_label: label of load option + * @handle: pointer to handle for newly installed image + * Return: status code + */ +static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, + u16 *lo_label, + efi_handle_t *handle) +{ + char *s; + int err; + int uri_len; + u32 image_size; + efi_status_t ret; + ulong image_addr; + + s = env_get("loadaddr"); + if (!s) { + log_err("Error: loadaddr is not set\n"); + return EFI_INVALID_PARAMETER; + } + image_addr = hextoul(s, NULL); + err = wget_with_dns(image_addr, uridp->uri); + if (err < 0) + return EFI_INVALID_PARAMETER; + image_size = env_get_hex("filesize", 0); + if (!image_size) + return EFI_INVALID_PARAMETER; + + /* + * If the file extension is ".iso" or ".img", mount it and try to load + * the default file. + * If the file is PE-COFF image, load the downloaded file. + */ + uri_len = strlen(uridp->uri); + if (!strncmp(&uridp->uri[uri_len - 4], ".iso", 4) || + !strncmp(&uridp->uri[uri_len - 4], ".img", 4)) { + struct udevice *blk; + struct blk_desc *desc; + + blk = mount_image(lo_label, image_addr, image_size); + if (!blk) + return EFI_LOAD_ERROR; + + /* + * When the new disk is detected, boot option is automatically + * created if it has a default file. + * Let's load the automatically created boot option. + */ + desc = dev_get_uclass_plat(blk); + ret = load_mounted_image(desc->devnum, handle); + if (ret != EFI_SUCCESS) + return ret; + + /* whole ramdisk must be reserved */ + efi_reserve_memory(image_addr, image_size, true); + } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) { + efi_handle_t mem_handle = NULL; + struct efi_device_path *file_path; + + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_addr, image_size); + ret = efi_install_multiple_protocol_interfaces( + &mem_handle, &efi_guid_device_path, file_path, NULL); + if (ret != EFI_SUCCESS) + return ret; + + ret = EFI_CALL(efi_load_image(false, efi_root, file_path, + (void *)image_addr, image_size, + handle)); + } else { + log_err("Error: file type is not supported\n"); + return EFI_UNSUPPORTED; + } + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -211,6 +401,14 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) { /* file_path doesn't contain a device path */ ret = try_load_from_short_path(lo.file_path, handle); + } else if (EFI_DP_TYPE(lo.file_path, MESSAGING_DEVICE, MSG_URI)) { + if (IS_ENABLED(CONFIG_EFI_HTTP_BOOT)) + ret = try_load_from_uri_path( + (struct efi_device_path_uri *) + lo.file_path, + lo.label, handle); + else + ret = EFI_LOAD_ERROR; } else { file_path = expand_media_path(lo.file_path); ret = EFI_CALL(efi_load_image(true, efi_root, file_path, diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 838023c78f..edc515b9ff 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -22,7 +22,7 @@ const efi_guid_t efi_guid_dt_fixup_protocol = EFI_DT_FIXUP_PROTOCOL_GUID; * @nomap: indicates that the memory range shall not be accessed by the * UEFI payload */ -static void efi_reserve_memory(u64 addr, u64 size, bool nomap) +void efi_reserve_memory(u64 addr, u64 size, bool nomap) { int type; efi_uintn_t ret; From patchwork Mon Oct 16 06:45:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734025 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69966wrx; Sun, 15 Oct 2023 23:47:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZ9IIxK7NWqSnP/8erNrKlVpI1mzaOFRmCgXu9Cb3ma1FG/Fy2hhOfmzkJBtkjBgyuwQfD X-Received: by 2002:adf:efd0:0:b0:32d:a0d9:2124 with SMTP id i16-20020adfefd0000000b0032da0d92124mr5884833wrp.35.1697438873220; Sun, 15 Oct 2023 23:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438873; cv=none; d=google.com; s=arc-20160816; b=tNpAb31OrHXIMJ6DpeXHKQD7dZHoS3NXvhO1RKsxHH6GO7hKqlCgPgZRB+qEdu+eaL S0jcxkvaIlMUiDBAGY60PsNpgfWXb2x77XpJo1EPj6AyNJiQG3x/MVMQtij+wnXlA2ST qQQ8biNF2KFH/J1W6X/Qsj2jX345uGy/gUl2HetqrIefZltt05QzWu2RcSxvDKUNhq2b KMNkm8d3bWgBX1g96ktMuM6hNO12p6dSS1CaX2Z++soqjcGamoCJqaCf5VtFHizSZaxu IPi2Q2jatPqNmIQ6RgpsbC21KV3msbXEh64BRNxUoq6zzHHdepjAKx0epRvPHOvwkKr2 R/CQ== 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=ryi0X21PUmEfIPUyO7zyD8fZiHB7jyyGE0uikDxTkxJ9z9ciTPlpesY0VhXPIbKxoQ PGgWLG0FRp/2mPAYIMxFnFKAw6Uq3e3pmRFrTmKG1dEX4FdPj0VpL00zjRN4gFSm92WX DTe3PShjdtWpEimt33PIETxGkke5nac2hzok68gd0TSK0RyqvQhVC7tr44g5DuszqN0u +XgS6C30hdDpNMiV//e1kBZvBlYCHVrhqAlfcH9mlGu4kIBPkDIibssWqSNyLcsxIQwt mGiqenoWQ04lrGc5TelhS40YTOqUwPlqnRXC81F/iWCfk8yPq9rdtx0BgC0JtpUqiKb5 vRDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=njHdpbnb; 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 m2-20020a5d56c2000000b0032cbaaac65bsi5917175wrw.739.2023.10.15.23.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:53 -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=njHdpbnb; 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 0D30786E2F; Mon, 16 Oct 2023 08:47: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=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="njHdpbnb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3B7486BCE; Mon, 16 Oct 2023 08:47:20 +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-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F9F486C3F for ; Mon, 16 Oct 2023 08:47: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=masahisa.kojima@linaro.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c9e95aa02dso24115975ad.0 for ; Sun, 15 Oct 2023 23:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438821; x=1698043621; 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=njHdpbnbY+LTFADNYMHstJBpLXGayXKh8mEGx4CNOism+mpYWqVkjW+4MP7xnaStQV SpM3roSbcBUn/GJxzBjEG7yeNpDmjb6b/RkIPgIAzxiNtNs6aP7XhH6p8fFMh06QMT/a SiiznhAklFVVxSxuA14c2dkGHtvIhXIdi6VPbyMsn7tiH+4g697ieqdSckLtPEnHehnW aHyP/PzQZyo+z2f7bioFUyq6fsM0vdU9vjYwifYusIrXCdd1bnNVubE/a5fwuqUFtWAI WZtFKanTtL/XNujilxz6RJM9eSw+aL6JU1ftHnW6MT87lx9cZo2C2zJKWqFPxeOmnw9X LSTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438821; x=1698043621; 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=XDpDSxuRNnhMflFqzlcImzSRh01ViKR+8dwcS179DNSTROwQgu6ghLri1XXRh6tMrW N2sHnd69L+QUOcvKHtVWzTiPKThHp9VDLB5eH7YwUPf2g7JRuVIuZJW7kLU8R3ZuksmV pbz9aSTvkafWPQd7m9XZN30Jezpo8asf1DrOYRGCXe/QY4lN2rF9jyp8bYVRPED3X7IB HZeji9ZSeIxl3jM6/M3tyNS/Frl8oQvC0GRUEhKQ+Uvvo90uxEIPoFtsz4oss6oU74yf Y+7fV0LLbFB+o67aZxJaTRWtSGkK3lh/edgYOy2UCOvqcd/iReyRIDhia0wsI60Yl+8V M4ow== X-Gm-Message-State: AOJu0YwOaHukmn07wTyzpCTLDuw3vj06xlh36Mmt4DVFr5F99RSRTOJm 1VFsBj8VPxGtmOIYUenqZu70xFbuSh04zDQTadY= X-Received: by 2002:a17:902:f54b:b0:1c6:e1d:8be0 with SMTP id h11-20020a170902f54b00b001c60e1d8be0mr10683006plf.2.1697438821439; Sun, 15 Oct 2023 23:47:01 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id i18-20020a170902eb5200b001bdeedd8579sm7687534pli.252.2023.10.15.23.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:00 -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 v7 6/9] efi_loader: add CDROM short-form device path Date: Mon, 16 Oct 2023 15:45:23 +0900 Message-Id: <20231016064526.2410856-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean UEFI specification does not mandate to support the short-form of the CDROM media device path. Fedora installation ISO image is identified as CDROM media device path, supporting short-form CDROM media device path is required to automatically add the boot option having default file of Fedora installation image. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_device_path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index ed7214f3a3..ac673ab117 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -110,7 +110,8 @@ struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp) while (dp) { if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_WWI) || EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) || - EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH)) + EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH) || + EFI_DP_TYPE(dp, MEDIA_DEVICE, CDROM_PATH)) return dp; dp = efi_dp_next(dp); From patchwork Mon Oct 16 06:45:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734029 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp70213wrx; Sun, 15 Oct 2023 23:48:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH3x4APzW7Szx1f5Khyjmt8bQOaVbg4S2Z2cy+kZL/kVL7lRjSzTDYY/TG66CCHBaBUQwN X-Received: by 2002:a7b:cc8f:0:b0:403:7b2:6d8f with SMTP id p15-20020a7bcc8f000000b0040307b26d8fmr28505516wma.2.1697438928007; Sun, 15 Oct 2023 23:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438927; cv=none; d=google.com; s=arc-20160816; b=LUhy7ybNRJEFWjFu0ZNdr1rLkt9ECB4RpA7j8ChPP4/Pg/2b56qhvGD8xKPHxMJcEq fT6CazWd6aaWHsba4WWmKpCtby2B/fPj4vPbBar0OAkpK3T254mF2UX9BdFoEmhxG5VC lXYZBCc3hW4+tlm9zWmmK98w/fmwWzNKrOS/nhSzUzpeCxyh7bDEHKkj7tU8u4wkWM99 wdrEckrTPdyY++t4KR+VnwXEenBFr1I8yi7AwQRpjg8FwgMpablvu/l52MDkBKrmH9Xs SLnkwXb/IS4SYPrqV1IiT0bMWPEYPujMcagj0fi8VLCtH0WgQxHyzVeZ6ZIoEC3QQPkg nTnw== 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=C53VP5KtEs4Fs4eRmFKLhqdcXCU8NAILPtSvATquHqXwMwlGCwXX6hnMR1L2G0l+vR uAE0ZgGPchkBYaNHMCfOCcgNkX1Y0gJGc64PJ0toJzg75I53xjqoEf2V3jQYhshyRAFu dy1iNCml9v8nb81pt9PJ3xllrPtsYsx/2S6NMHlhJ2OrCtuQiDPnkC5aLogrIbQlB68T 8+tnbMR7Qmqq0REMicGDIeVg6+btHDz1+WrVz0rONKgy0v+uDn0UzhEX7Odpkbet9Web 6qHTBSmsTx6gjdMWK1mhAIVvUW7jJsau0q0NJ8yNxmp98y5QGtXHzU0JMlu14xAEduNg C8rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ul1XEHOs; 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 c5-20020a5d4cc5000000b0032db012cdf0si1033960wrt.621.2023.10.15.23.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:48:47 -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=Ul1XEHOs; 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 CEAE986C65; Mon, 16 Oct 2023 08:47:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="Ul1XEHOs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D53786DB3; Mon, 16 Oct 2023 08:47: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-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 CDE3A86E17 for ; Mon, 16 Oct 2023 08:47:09 +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-x42e.google.com with SMTP id d2e1a72fcca58-6b9af7d41d2so1095255b3a.0 for ; Sun, 15 Oct 2023 23:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438827; x=1698043627; 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=Ul1XEHOsGM4s5ZXhl8izVuRgdzwBvimAZkXuoqhECUyzZ5Ez0xE4L1Hg3jaebkJtT4 Obo7iWdiOztGGXAQsCc6aArrMkn5aWaxldZj3Pk7wiMXDQQwkaTGjRCvrTsNYEXGqaYa lgGsDUHQY9XV9evUyGDM53AoPvEQpMUn6Ise6OpLox6UUZP1F50ibABAcCqCaWEz+1nq 4lVN8G9iVN+cmBLHgyABIM/ySQviS1kOYG+YTltUb5HvVaMxir4vqsa4+x6vd/tTxXMk 56wvCrB5HMNqfSgdipSasXwMLCFgHXkBq93i2kbuzMIQ7Ysvv3C8BVI0G+1f6oLwENLk e/CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438827; x=1698043627; 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=OcOEUqe358XOG7Zc6Hy+FF1rfaLYWmEF0A8OizdzAhGDLivYKjNd4BoOEHO4KvOACh FZMZ1CB92hAiYJu1Ndf90dBBML5rNhQNU2W7UeXtS71umYvHozHLjFpF1yhECni/jQQU 4oOX+5SMFsICbIbh7s4rTv7wQiw9WfipvTiPbJAhIlFiWT90CFt3hyN8/9KlKbl0Sclz gllfdag+B/kpFHp53cH9u/zyihobAX9mjV7UWzK5LavAIv6z62RlsRMaICfqqhzWdiCQ HVNQr2zZEmvsRXg8I0bE1n51DSkTLQ3tXeACm5nhLyxgtyqWwailoFeacOUsF7GMlCcD qEbw== X-Gm-Message-State: AOJu0YzjJEUEStoUb3N4IXyZxHifoMSiHxGU6B4mx7PQowC7gzvn1TnE xTthn5FBg1s44Z9M4SsWxKIzkdvcmlpYkXlx7zA= X-Received: by 2002:a05:6a00:1511:b0:690:4362:7011 with SMTP id q17-20020a056a00151100b0069043627011mr35009133pfu.24.1697438827170; Sun, 15 Oct 2023 23:47:07 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id fa13-20020a056a002d0d00b006b1c14a493fsm5242447pfb.71.2023.10.15.23.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:06 -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 v7 7/9] Boot var automatic management for removable medias Date: Mon, 16 Oct 2023 15:45:24 +0900 Message-Id: <20231016064526.2410856-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-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 Signed-off-by: Joao Marcos Costa Reviewed-by: Joao Marcos Costa --- lib/efi_loader/efi_disk.c | 18 ++++++++ lib/efi_loader/efi_setup.c | 7 ++++ test/py/tests/test_efi_secboot/test_signed.py | 42 +++++++++---------- .../test_efi_secboot/test_signed_intca.py | 14 +++---- .../tests/test_efi_secboot/test_unsigned.py | 14 +++---- .../test_fs/test_squashfs/test_sqfs_ls.py | 6 +++ 6 files changed, 66 insertions(+), 35 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index f0d76113b0..b808a7fe62 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -690,6 +690,13 @@ int efi_disk_probe(void *ctx, struct event *event) return -1; } + /* only do the boot option management when UEFI sub-system is initialized */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + return -1; + } + return 0; } @@ -742,6 +749,17 @@ int efi_disk_remove(void *ctx, struct event *event) dev_tag_del(dev, DM_TAG_EFI); return 0; + + /* + * TODO A flag to distinguish below 2 different scenarios of this + * function call is needed: + * a) Unplugging of a removable media under U-Boot + * b) U-Boot exiting and booting an OS + * In case of scenario a), efi_bootmgr_update_media_device_boot_option() + * needs to be invoked here to update the boot options and remove the + * unnecessary ones. + */ + } /** diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index e6de685e87..37359a77bb 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -245,6 +245,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { + /* update boot option after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py index ca52e853d8..2f862a259a 100644 --- a/test/py/tests/test_efi_secboot/test_signed.py +++ b/test/py/tests/test_efi_secboot/test_signed.py @@ -29,7 +29,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -37,7 +37,7 @@ class TestEfiSignedImage(object): # Test Case 1b, run unsigned image if no PK output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -59,13 +59,13 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('\'HELLO1\' failed' in ''.join(output)) assert('efi_start_image() returned: 26' in ''.join(output)) output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -77,12 +77,12 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 2', + 'efidebug boot order 2', 'efidebug test bootmgr']) assert '\'HELLO2\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -105,7 +105,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -143,7 +143,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -170,7 +170,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -181,7 +181,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -193,7 +193,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -205,7 +205,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -230,7 +230,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -254,7 +254,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -265,7 +265,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -279,7 +279,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -307,7 +307,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -330,7 +330,7 @@ class TestEfiSignedImage(object): assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -349,7 +349,7 @@ class TestEfiSignedImage(object): output = u_boot_console.run_command_list([ 'host bind 0 %s' % disk_img, 'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld_forged.efi.signed -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert('hELLO, world!' in ''.join(output)) @@ -364,7 +364,7 @@ class TestEfiSignedImage(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK']) assert 'Failed to set EFI variable' not in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert(not 'hELLO, world!' in ''.join(output)) assert('\'HELLO1\' failed' in ''.join(output)) diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py index d8d599d22f..8d9a5f3e7f 100644 --- a/test/py/tests/test_efi_secboot/test_signed_intca.py +++ b/test/py/tests/test_efi_secboot/test_signed_intca.py @@ -40,7 +40,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_a host 0:1 /helloworld.efi.signed_a -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_a\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -49,7 +49,7 @@ class TestEfiSignedImageIntca(object): # Test Case 1b, signed and authenticated by root CA output = u_boot_console.run_command_list([ 'efidebug boot add -b 2 HELLO_ab host 0:1 /helloworld.efi.signed_ab -s ""', - 'efidebug boot next 2', + 'efidebug boot order 2', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -71,7 +71,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -81,7 +81,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_b.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) @@ -91,7 +91,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 db_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -117,7 +117,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'Hello, world!' in ''.join(output) # Or, @@ -129,7 +129,7 @@ class TestEfiSignedImageIntca(object): output = u_boot_console.run_command_list([ 'fatload host 0:1 4000000 dbx_c.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert '\'HELLO_abc\' failed' in ''.join(output) assert 'efi_start_image() returned: 26' in ''.join(output) diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py index df63f0df08..7c078f220d 100644 --- a/test/py/tests/test_efi_secboot/test_unsigned.py +++ b/test/py/tests/test_efi_secboot/test_unsigned.py @@ -36,11 +36,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -65,7 +65,7 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert 'Hello, world!' in ''.join(output) @@ -89,11 +89,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) @@ -107,11 +107,11 @@ class TestEfiUnsignedImage(object): output = u_boot_console.run_command_list([ 'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""', - 'efidebug boot next 1', + 'efidebug boot order 1', 'bootefi bootmgr']) assert '\'HELLO\' failed' in ''.join(output) output = u_boot_console.run_command_list([ - 'efidebug boot next 1', + 'efidebug boot order 1', 'efidebug test bootmgr']) assert 'efi_start_image() returned: 26' in ''.join(output) assert 'Hello, world!' not in ''.join(output) diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py index 527a556ed8..3b8118104f 100644 --- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py +++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py @@ -118,6 +118,12 @@ def test_sqfs_ls(u_boot_console): """ build_dir = u_boot_console.config.build_dir + # If the EFI subsystem is enabled, default file(e.g. EFI/BOOT/BOOTAA64.EFI) + # is scanned when the new disk is detected. This ends up with the unexpected + # output at the first 'sqfsls' command. + # Clear the previous state. + u_boot_console.restart_uboot() + # setup test environment check_mksquashfs_version() generate_sqfs_src_dir(build_dir) From patchwork Mon Oct 16 06:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734028 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp70205wrx; Sun, 15 Oct 2023 23:48:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWiwVj0sB6pfmQ6ewXf2jmjZe9bhWl8x0psgRk7lsuzwSjfcU7sU+YaXcoFT0juT2C0IHB X-Received: by 2002:a5d:4bd0:0:b0:32c:f8cb:f908 with SMTP id l16-20020a5d4bd0000000b0032cf8cbf908mr13650016wrt.59.1697438926474; Sun, 15 Oct 2023 23:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438926; cv=none; d=google.com; s=arc-20160816; b=A4+ZpLIxi5L+aMXOPJaiaWyzzCmUfxDCDAM1aURiy9JAXX9mA4fcj1iqYWbNp8Dq8Z 71RnTe2kvL+My67FgiCcQLXXq4zqo+I56s1CSUhjqoz0xvJ+nCX2TWpe9f8HcQX96GVF u5meWQwkaKV9nVg1DDPR3uZLhigA3b4btJFfQBcSUHarl41W7XBBIhO0DNovw3vpM8ZS 7nxtmPMw8XBE9UA0M84zugxfD8GeRuP+AYujKmjmFVpH3YYW/QUckpXLyz7cqm20hR4e L9kR3ljc+zTyxcj3NhwPsdcKACB/Q4toXKIBlw8vzJq3Ow7PXi7JShpBNrTUDbMrhX9q TDHg== 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=Ikv98LRO57+4GHfoyhxpJF70KLe7lLX7dQLvzIA+zV+c+5uqWHkZv+Ait4bAnMtPqM LJqzS4uWph5E4AZt8hh7v6j6KUxTyC638NnQmwY3ood5Mh77lWBSNOgN5XiND6OrksEK RtecgRXp4nacuqXFCwbPP/UXFsgYfgpIMXV8sqI4YFScUIosCvFENEbhzQTFXVmZyHrF gl8kv50a3xeAWxOw16ApDle5hcogPgEgsnXrwjfx5MppqRhNf2gGoJXuOVf0MMZAw2Zy kd0VZRsMjG7OkORf01iFCQjar0ZzyN3s8ziSP4iLcvMtTxWQ3HETsKUTL1QFzNSYfd2O do0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZTzy6iDY; 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 i15-20020adff30f000000b0032488913d60si2421623wro.405.2023.10.15.23.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:48:46 -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=ZTzy6iDY; 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 BA38C86EDB; Mon, 16 Oct 2023 08:47: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=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="ZTzy6iDY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AD07486B79; Mon, 16 Oct 2023 08:47:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) (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 6D1398477A for ; Mon, 16 Oct 2023 08:47:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-57bca5b9b0aso2229492eaf.3 for ; Sun, 15 Oct 2023 23:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438832; x=1698043632; 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=ZTzy6iDYOui4sEWY6hpRWhQzatIPAN3YiQYImg+zwsiFAPqyAcGinQpoTINNgVRtFR y6sL2FZfa1NXf0kjaw3NlinFcXYx6LwBLB0SrorBFl5Qq+AUPwGwsBalPzXj+7lFrb3l KYH+AtF2JElIS5bfgQQWilAL9YBL05EBPAcjNGHdnB7ktmZqYObiSVLnwGHU7rimAuF6 P/zb5ROjJcr4uUbZFK5A3jzadzjE09N0bFK+Xw74iJI7EasWnXj5q+g4/nswxneIJ0WI JUM2haKM0temvPh6iyVOyD2vbHBbLftaicN7FZUcLW1lmoaaAV7k3Alj45lNA13nqoz4 Pqag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438832; x=1698043632; 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=wTfn/RcX/Mb9c92JKZGCICSug5hsi6nNbez7PXn7qoChTAa0Ec3RKvYM4Fo9sROnfN 95raTAgu7fsWR5Mull2XBdbsgCxqta+2lI3sxV956Zi+iEZr+ztA/ZbtghQbsNvSEWPo fv1uQ5Se3NcJZDE1IOeVXrvLed62ojbimPs/SEiN1UP+XnjZCF6fDjlJiFbuDZf8zSEH sDPvrWVeVf0WwmYAjykgrkYJcfsCt0/r+sH9KecAa2o9SzGpK5Q253+SHhFTel/DaVkt MqIn+i5/bNo+3jLj1j0KuEnQg2VFahwht+NnXSV4meDELmEorKZDl8V8EvuuLk5Wis24 Wh8Q== X-Gm-Message-State: AOJu0YyJxpCzhnxR8Ws+ymyTp85UdPf28uguc+M/FScn0uBJA1xo8XBr jUqLMGaf3rM5/Q0hlCg2p7cJt5KVcLEaf92xWVE= X-Received: by 2002:a05:6358:2820:b0:13a:a85b:a4ce with SMTP id k32-20020a056358282000b0013aa85ba4cemr34758613rwb.16.1697438832532; Sun, 15 Oct 2023 23:47:12 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id b12-20020aa7950c000000b006bd26bdc909sm2417569pfp.72.2023.10.15.23.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:11 -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 v7 8/9] cmd: efidebug: add uri device path Date: Mon, 16 Oct 2023 15:45:25 +0900 Message-Id: <20231016064526.2410856-9-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-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