From patchwork Tue Dec 26 06:28: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: 758372 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp2930872wrw; Mon, 25 Dec 2023 22:30:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3JW+WzmMS5SnrvqvqEkh4KmtIEe7poydVa87ktUA+LSvT+/JVz+fdNMXio+2Mqa3jgawF X-Received: by 2002:a05:600c:3201:b0:40b:5e1e:fb9c with SMTP id r1-20020a05600c320100b0040b5e1efb9cmr2606664wmp.81.1703572237666; Mon, 25 Dec 2023 22:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703572237; cv=none; d=google.com; s=arc-20160816; b=v4850H+Ku6yFA5jdk39UJMxddMrLXD3MuPVm+Co8CGNd/Wkw5wA03rRkt46NHnWqCF 48/FIt3fZA8cJEofuKWOUgFlZYANSwQBq74uwxm0LTfe6XIt4coZdA/ugWmdi2qTBIAo 73momrgh/v+rPygUmMHdWfPOdrVH03PB0xpgp9miSeTWCYxK4CGMylB35S4+V3tOh/DH lBi374/ff8QGV/VSbU0KsU5+Seny6KXl2UtO9XbR5zWoWWulk16NAY2xnFGhWa4w7cLM +cGfMh7cgXHDWSm51cRJXdmAdR5V42kJd86WDm5uZySuvpHddUGJPPT82B8HAIYrFq+s bAVQ== 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=QPJwZhn+T7BYMDoLmE72/jYPNeVUTTMnXmX4tvGC9B8=; fh=YtnCJplQ1DA0Rz8c1dg8CfrVxTgSI4BIXB9JUZxV1zk=; b=xMsWxLrj1W9Yxsr5m0V7DtwqaZZNPe8IGFbWNMe50GhkooJOKlMKQTD4LmtlLsEFM3 u9+6fIM16ieU32IxLGtepzwtQUOtCgSIpBEXFokRuXc+OIGk5lssOCFxXP5NPCorrZPG vr2QKmKci5KSXBA60u4KSy5Wg0UWq6D8yghE5f/riswNuBIgDHB8UYF8B/bgFH9ydl6+ 04CAlrsk180BqL9tbYHA6aKOw/jT5kVgxvwIm2okOfgB54bdTI9DngBcy4X1lgBe8tHE 0ly583E9nKMuMuF8ZIWR4rC3+getELPpaq6QrxEpxoCYwwyq7ReDS2yFJibqarqw6Zlw aOLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GVMeLlrY; 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 p35-20020a05600c1da300b0040d1b6438c2si8026060wms.37.2023.12.25.22.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 22:30:37 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GVMeLlrY; 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 2F3378786E; Tue, 26 Dec 2023 07:30:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GVMeLlrY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BE9E8786A; Tue, 26 Dec 2023 07:30:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 B7F4D87852 for ; Tue, 26 Dec 2023 07:30:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-35fd04ede25so19345195ab.0 for ; Mon, 25 Dec 2023 22:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703572224; x=1704177024; 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=QPJwZhn+T7BYMDoLmE72/jYPNeVUTTMnXmX4tvGC9B8=; b=GVMeLlrY6fG8l2SMbBEGaf2hlccTHo/5m1U25ZTb4GbvaOVim2CFHrtG1vLRF/YMa/ kpxXo2i2RicZr+lsscxG0l4iN4N3abIlV8t8mYWbYqL/sGW+81KxZZH7/BdGUqVDWUsD PfEAFrNErbG+OCvIuTxvHjMByIPoiYVB3OSiBlaGWl6VMKQiv6VUiT0TrY015jf5F0Cz wQPjfNTCWqNZ/uoN+mTwe9QMauSIKvFPww5oU48StyO1C3RwFVfh/fBSsRPby9l1Xquy hHo/d+06Te8BbuaWwILMkLDJ2hijp6vNqo0q2gwf1o4ioOjMxwQCP3TJGEzZzb4Az1yw T4gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703572224; x=1704177024; 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=QPJwZhn+T7BYMDoLmE72/jYPNeVUTTMnXmX4tvGC9B8=; b=nrlWKqlqjqmSGGYCV1SaFvgXvr517cNnxbtJ3SNsBZV4x5vrhGExCzz+0eglfF8Sw8 5qRpl3DYATEbPSBvNKVLqc6Zyv1hQFaGuEl3esGu6GFvaNWVbcEPDj8+kkoIqwYpsXGN Hy0CijEM2iZ7hzoe6NaWChE0E6Ad2hrzrBvflIi/W7dDt7jZ5685wxDV8qTvl9czYtXn GevWuscaWK/+cHnirS1ZaAt8PEOAIG/DOtTVZgZiIMTRJlgLQ0YU8diSXJ25FID9tfF5 EVtU1dwmSjkp79vjkg7a8h9dQTspBg67k6o7cIp/+cHUVv5hF9C3FmfHuJrFQrSBgpK6 jCgg== X-Gm-Message-State: AOJu0Yw2U10vZ9bZ1t8zOZcGO7rTu7U4Az/raYBag7qsgEi94bjYRwPA ejtvxe8HJoUklWnbceJxIS/KTFWZSDlUADsfg82DEtd0V8M= X-Received: by 2002:a05:6e02:194e:b0:35f:754d:fed9 with SMTP id x14-20020a056e02194e00b0035f754dfed9mr10398552ilu.37.1703572224279; Mon, 25 Dec 2023 22:30:24 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id p23-20020a635b17000000b005c66b54476bsm8469212pgb.63.2023.12.25.22.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 22:30:22 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2 1/2] efi_loader: auto-generate boot option for each blkio device Date: Tue, 26 Dec 2023 15:28:19 +0900 Message-Id: <20231226062820.722358-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231226062820.722358-1-masahisa.kojima@linaro.org> References: <20231226062820.722358-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 auto-generates the boot option for all disks and partitions installing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, while EDK II reference implementation auto-generates the boot option for all devices installing EFI_BLOCK_IO_PROTOCOL with eliminating logical partitions. This commit modifies the efibootmgr to get aligned to EDK II. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 94 +++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 56d97f2382..747f75ee82 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -560,6 +560,50 @@ err: return ret; } +/** + * try_load_from_media() - load file from media + * + * @file_path: file path + * @handle: pointer to handle for newly installed image + * + * If @file_path contains a file name, load the file. + * If @file_path does not have a file name, search the architecture-specific + * default file and load it. + * TODO: If the FilePathList[0] device does not support + * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but supports EFI_BLOCK_IO_PROTOCOL, + * call EFI_BOOT_SERVICES.ConnectController() + * TODO: FilePathList[0] device supports EFI_SIMPLE_FILE_SYSTEM_PROTOCOL + * not based on EFI_BLOCK_IO_PROTOCOL + * + * Return: status code + */ +static efi_status_t try_load_from_media(struct efi_device_path *file_path, + efi_handle_t *handle) +{ + efi_handle_t h; + efi_status_t ret = EFI_SUCCESS; + struct efi_device_path *rem, *dp = NULL; + struct efi_device_path *final_dp = file_path; + + h = efi_dp_find_obj(file_path, &efi_block_io_guid, &rem); + if (h) { + if (rem->type == DEVICE_PATH_TYPE_END) { + /* no file name present, try default file */ + ret = check_disk_has_default_file(h->dev, &dp); + if (ret != EFI_SUCCESS) + return ret; + + final_dp = dp; + } + } + + ret = EFI_CALL(efi_load_image(true, efi_root, final_dp, NULL, 0, handle)); + + efi_free_pool(dp); + + return ret; +} + /** * try_load_entry() - try to load image for boot option * @@ -594,7 +638,6 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, } if (lo.attributes & LOAD_OPTION_ACTIVE) { - struct efi_device_path *file_path; u32 attributes; log_debug("trying to load \"%ls\" from %pD\n", lo.label, @@ -611,10 +654,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *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, - NULL, 0, handle)); - efi_free_pool(file_path); + ret = try_load_from_media(lo.file_path, handle); } if (ret != EFI_SUCCESS) { log_warning("Loading %ls '%ls' failed\n", @@ -748,19 +788,19 @@ error: * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media * * @opt: pointer to the media boot option structure - * @volume_handles: pointer to the efi handles + * @handles: pointer to the efi handles * @count: number of efi handle * Return: status code */ 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_handle_t *handles, + 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; @@ -768,8 +808,15 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo char buf[BOOTMENU_DEVICE_NAME_MAX]; struct efi_device_path *device_path; struct efi_device_path *short_dp; + struct efi_block_io *blkio; + + ret = efi_search_protocol(handles[i], &efi_block_io_guid, &handler); + blkio = handler->protocol_interface; - ret = efi_search_protocol(volume_handles[i], &efi_guid_device_path, &handler); + if (blkio->media->logical_partition) + continue; + + ret = efi_search_protocol(handles[i], &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) continue; ret = efi_protocol_open(handler, (void **)&device_path, @@ -777,7 +824,7 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo if (ret != EFI_SUCCESS) continue; - ret = efi_disk_get_device_name(volume_handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); + ret = efi_disk_get_device_name(handles[i], buf, BOOTMENU_DEVICE_NAME_MAX); if (ret != EFI_SUCCESS) continue; @@ -801,17 +848,20 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo * 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) { + opt[num].size = efi_serialize_load_option(&lo, (u8 **)&opt[num].lo); + if (!opt[num].size) { ret = EFI_OUT_OF_RESOURCES; goto out; } /* 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++; } out: + *count = num; + return ret; } @@ -1040,8 +1090,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. + * This function enumerates all BlockIo devices and add the boot option for it. * This function also provide the BOOT#### variable maintenance for * the media device entries. * - Automatically create the BOOT#### variable for the newly detected device, @@ -1057,13 +1106,13 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) u32 i; efi_status_t ret; efi_uintn_t count; - efi_handle_t *volume_handles = NULL; + efi_handle_t *handles = NULL; struct eficonfig_media_boot_option *opt = NULL; ret = efi_locate_handle_buffer_int(BY_PROTOCOL, - &efi_simple_file_system_protocol_guid, + &efi_block_io_guid, NULL, &count, - (efi_handle_t **)&volume_handles); + (efi_handle_t **)&handles); if (ret != EFI_SUCCESS) goto out; @@ -1073,8 +1122,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, handles, &count); if (ret != EFI_SUCCESS) goto out; @@ -1122,7 +1170,7 @@ out: free(opt[i].lo); } free(opt); - efi_free_pool(volume_handles); + efi_free_pool(handles); if (ret == EFI_NOT_FOUND) return EFI_SUCCESS; From patchwork Tue Dec 26 06:28: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: 758373 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp2930931wrw; Mon, 25 Dec 2023 22:30:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXYNrWVorq1pxkxk+27rqq7iSjX/eZEyC19GsAdouUtYBJBAM0F221CSWaXwi4H8bv7Zvg X-Received: by 2002:a5d:5f8a:0:b0:336:c9e0:4371 with SMTP id dr10-20020a5d5f8a000000b00336c9e04371mr852588wrb.148.1703572246766; Mon, 25 Dec 2023 22:30:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703572246; cv=none; d=google.com; s=arc-20160816; b=S2aMSz1nUziIQku5AD4m7zLAcWYufy5OF6TyQaVi5JzGemTweljshgb7E/R5nfmt/g IPwXDWPLB7821LYRQUAcmDutDVWqroCHq+PNFRb+M+Pyg99XuLIwGs/X4U4RblLgot7c 0EXHD93eSKhHB1Hjhi2/Otw7VwV/O2YvErqF6OOGPw70iWZ3vhzW8uQHM8VJyvOCs8hl PpwcRxLWanbC2e5G4Uxs5+yaUEWZ3iR0HCMI+6KAxD7kIXqrfskX/i+E+6mlVqhkxxr1 977j+qruVuG26GEUQJPr82F1aCrr658Dt00JMctbfsG8UQmlaQw2UidkGbEG8EKmojho AYfg== 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=4ZoGUBhmva+pKMScAdXfCrlEl8CcJBZ2lyTChBOAbeg=; fh=YtnCJplQ1DA0Rz8c1dg8CfrVxTgSI4BIXB9JUZxV1zk=; b=oYJ064Z/Tv7n1fNz9K41KzZDd7aQIvJCG4bnrdbrFTJh8e/dYx8LU1of5dYYKTLCT7 8trUi1g+fc7lDKxDZljve5vxznzMhPmKqujFPY6ijaXMIBbRQxiJAI1gHHbxVv4ciPQn YYrGwhw7sUlyQuOeZNoRJTTilh5JO0TwYn6yA4EpF9W3h77p/XYP0o7OvVRuaWrdQS3R CdcBNesxi7itbxce75O3eooiWvFPNLE0pXQqUOhQ5D9LEhyhoEiRZSNPVK/ifWJn/T7J 3neHVZ+vOKRlciqkiEaY3aBkyx6ZkvsN2A/VDAZtXCXPaSa30FrcEThLeqUExL33oZvQ jcvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="el4Bzf/f"; 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 d3-20020a5d5383000000b003367798d625si5168672wrv.482.2023.12.25.22.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 22:30:46 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="el4Bzf/f"; 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 A5CB687876; Tue, 26 Dec 2023 07:30:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="el4Bzf/f"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5ECDB874CC; Tue, 26 Dec 2023 07:30:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) (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 1519887852 for ; Tue, 26 Dec 2023 07:30:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3bbb9f39e30so84117b6e.3 for ; Mon, 25 Dec 2023 22:30:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703572232; x=1704177032; 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=4ZoGUBhmva+pKMScAdXfCrlEl8CcJBZ2lyTChBOAbeg=; b=el4Bzf/fp0eyzeksYekHnaSflPzgc9Bqdq4QHGeXOpZKYdLLPMBkQZUc6n9xj0VT45 w4O0gRKhKJIIWy4T4+YjpD/jvtSv8nOb4EdzBKrrFDok3DeYvqOXJrdjy307stM9O4Sc OTKBf/e4+2TdEpigDxZPE60o9PT1er+8i2zDtxJG1eCg/9b2xjAyWJjb5aBr94CfqGaR jscVA9hKrgeGqW2IBqexD3hoLhIHPNOqjtD5ZVz2R14lvYxMwXzze9dS1QS7tqJfbzzt AeTV1sE5rwXgMUVzMejP+OSVWQmvQEFoTERJ9UZBAJNP+jZNPrI7xdhdYvht17rQSH5B M6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703572232; x=1704177032; 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=4ZoGUBhmva+pKMScAdXfCrlEl8CcJBZ2lyTChBOAbeg=; b=IeOHi7xzmt4lZK93t/oTBDGHKFHnQU1/TzbTycc+MeDsgiW+ui/p9mtumc3f1jiDox sMPpyOrsuiukZwGcxlrFHPC3m3sup/c6c8Ir4xMl7CrDaCDtzRYAmlFB+7Dhj60tQXi8 mDhWXA7ZsVbj+9bgupktLN/fadwdJZzpU4nhhjewMdg4EC8uvZ1DNej/IVqakUaMn/8D GSRwoEBF3aAZZ+XjfqClcKwulT0tZ9F31MTKlz3jYLvG0Vz/J3tMA1sVZcP5cszdVcaQ ROf+pMhYl22ZnZYScDeY2zqjE+CutKr9NxmMj/+w5yYHA0w6AxaRZlmu221W1PKOwfL2 ztig== X-Gm-Message-State: AOJu0YwunAldAmCW2Rm9l6Zej56u5agg97vr8DThUbsp2GrzIZpkaORc 2A0MX/LehxHCxGFu7HCAA6CNnEDyIbZonfPVw+QNoOs9y9c= X-Received: by 2002:a05:6808:444a:b0:3bb:b9e6:a156 with SMTP id ep10-20020a056808444a00b003bbb9e6a156mr564298oib.6.1703572231840; Mon, 25 Dec 2023 22:30:31 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id o6-20020a056a001b4600b006d98e42d5desm6636989pfv.193.2023.12.25.22.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 22:30:30 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2 2/2] efi_loader: auto-generate removable media boot option first Date: Tue, 26 Dec 2023 15:28:20 +0900 Message-Id: <20231226062820.722358-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231226062820.722358-1-masahisa.kojima@linaro.org> References: <20231226062820.722358-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 commit auto-generates the boot option for removable block io devices followed by fixed block io devices. This is what EDK II reference implementation does. Signed-off-by: Masahisa Kojima --- lib/efi_loader/efi_bootmgr.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 747f75ee82..a146428a65 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -584,7 +584,6 @@ static efi_status_t try_load_from_media(struct efi_device_path *file_path, efi_status_t ret = EFI_SUCCESS; struct efi_device_path *rem, *dp = NULL; struct efi_device_path *final_dp = file_path; - h = efi_dp_find_obj(file_path, &efi_block_io_guid, &rem); if (h) { if (rem->type == DEVICE_PATH_TYPE_END) { @@ -788,15 +787,19 @@ error: * efi_bootmgr_enumerate_boot_option() - enumerate the possible bootable media * * @opt: pointer to the media boot option structure + * @index: index of the opt array to store the boot option * @handles: pointer to the efi handles * @count: number of efi handle + * @removable: flag to parse removable only * Return: status code */ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boot_option *opt, + efi_uintn_t index, efi_handle_t *handles, - efi_uintn_t *count) + efi_uintn_t *count, + bool removable) { - u32 i, num = 0; + u32 i, num = index; struct efi_handler *handler; efi_status_t ret = EFI_SUCCESS; @@ -816,6 +819,9 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo if (blkio->media->logical_partition) continue; + if (removable != (blkio->media->removable_media != 0)) + continue; + ret = efi_search_protocol(handles[i], &efi_guid_device_path, &handler); if (ret != EFI_SUCCESS) continue; @@ -857,6 +863,9 @@ static efi_status_t efi_bootmgr_enumerate_boot_option(struct eficonfig_media_boo 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++; + + if (num >= *count) + break; } out: @@ -1105,7 +1114,7 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) { u32 i; efi_status_t ret; - efi_uintn_t count; + efi_uintn_t count, num, total; efi_handle_t *handles = NULL; struct eficonfig_media_boot_option *opt = NULL; @@ -1122,22 +1131,32 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) goto out; } - ret = efi_bootmgr_enumerate_boot_option(opt, handles, &count); + /* parse removable block io followed by fixed block io */ + num = count; + ret = efi_bootmgr_enumerate_boot_option(opt, 0, handles, &num, true); if (ret != EFI_SUCCESS) goto out; + total = num; + num = count; + ret = efi_bootmgr_enumerate_boot_option(opt, total, handles, &num, false); + if (ret != EFI_SUCCESS) + goto out; + + total = num; + /* * System hardware configuration may vary depending on the user setup. * The boot option is automatically added by the bootmenu. * If the device is not attached to the system, the boot option needs * to be deleted. */ - ret = efi_bootmgr_delete_invalid_boot_option(opt, count); + ret = efi_bootmgr_delete_invalid_boot_option(opt, total); if (ret != EFI_SUCCESS) goto out; /* add non-existent boot option */ - for (i = 0; i < count; i++) { + for (i = 0; i < total; i++) { u32 boot_index; u16 var_name[9]; @@ -1166,7 +1185,7 @@ efi_status_t efi_bootmgr_update_media_device_boot_option(void) out: if (opt) { - for (i = 0; i < count; i++) + for (i = 0; i < total; i++) free(opt[i].lo); } free(opt);