From patchwork Fri Jul 14 05:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 702718 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp906649wrj; Thu, 13 Jul 2023 22:47:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGfFm0wsh7U6F6hij1CXK6xc0QnZ61XcqTo3FPtMcLjqIVGZ1OuPtzja9iPE71BuNKZRI8y X-Received: by 2002:aa7:cd52:0:b0:51e:1927:6ade with SMTP id v18-20020aa7cd52000000b0051e19276ademr3502241edw.11.1689313675106; Thu, 13 Jul 2023 22:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689313675; cv=none; d=google.com; s=arc-20160816; b=njnfLPGYOXSNQp8ZzZV+KaLJihtSh07NZbkqcMhNpUn1XjvhRS1rN4F2oVn/Kl2X77 k6GZwAROvcCdc1ViY5uV5R+7QUPvT5RXhCMe7NLeBlZDPD4JTGeAeWAxl/XYgQIbqydO 9vQ5flOOqLYIBh2xYrife3g5ytEFIPdIeX65LOZWP2X091haKiO5MbRWPD9lpmXvp6mf 1ix/bm2Y1zTiN177d2CScZSSevbPTSzqpKDQk48ukFAfkOF6KrSdYL2fRf6JYbYkiwme UNAagsNG5T/nAKEY9j4Z3ImbJwHhDTPghJdp4Fm3Ca9qETAny1/67fe2BeRqA8hmWl4i YijQ== 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; fh=2Cgl+3Z0VvBZsINoafPcrCuvHpnrKYJDE1GTVTHRCXA=; b=N4qtoielqUZawegW37vWKcKUxAQA9WBqeOEa53sh5JCA8GcvcEzFsc77qBMvEU75tN LX5DwfKfpRAusYb+CXlzie8q3WxhEbRKMSopdK4IfoVZJSm4xQwq+n+MpqXj5VAYtQ8p qtv8EmZr5lUrfDfk4t5jHF+UHGSrkvUm4hX5KJeTTsPzxr/ZRy0T7CZA3FosMMl4abHA gBjTStw7sekNXMn9Xx0Gsf+1vjGqCx3pVJMQdFMj/mVn4qHUtBCEcCAOQKuvTB4SHlvk 01SsNb0Qcfq9AQRZFJlGM4mzkXUYdzGyY1swpP5BZmT0BuzlxdpGbAsjLx0QmAAqAk72 I6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KxF+Lzz2; 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 p4-20020aa7d304000000b0051e0e38a950si9425796edq.637.2023.07.13.22.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:55 -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=KxF+Lzz2; 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 B218186D2A; Fri, 14 Jul 2023 07: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="KxF+Lzz2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FE0A86D2C; Fri, 14 Jul 2023 07:47:34 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 200AA86D34 for ; Fri, 14 Jul 2023 07: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=masahisa.kojima@linaro.org Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-668711086f4so951564b3a.1 for ; Thu, 13 Jul 2023 22:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689313648; x=1691905648; 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; b=KxF+Lzz2So5mYDruYwUAQqWYf1DEBgjQfW026mYyfSxwG3JfFI9SlFTEqVZKurxBYH 0Qx3CIP0lOiJJYCmhgrJFUPiwuXnSBsqx7eqZdL1QjmIj17DIIEzvEAodG9dV7dOMAa3 vH++OTFGJFk+8MT+4kMvjIhZuL+yNTWPiJhfB9tJWL1psuzqZZex2YhOubSN8bS4xSok wdlUCbdGrJxYqMiXC4spqa5GgIU48DLTNRVdUWYeyxaNdpqY4HgmSPzk/W4lhoCxhpxd 7E2ENK6d/kJgfLLL3dQqwQdJsvRFEN9RuUc6QBTFbun6ql6VM7cLdrQtQRmRsOaQJpbE HZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689313648; x=1691905648; 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=fuBtsKKs6Xscb6hShrpv0FUiQQVc8uUxScLU2PrgXlc=; b=D18Iad8CdR33akhW0YC1LhFcTcHkaeOi9Yp/qObf96Id+nNkxN/LL1w/oii7NZAmGF 914I7WlQ9A1s8vasmhuU5zVhfnGyfQ7D6yH0bPt0LnGiDbQgTSO3AsJE8hN/JzL4SnXz LdKmYdhg1utKzRbAb1ljpdK2kYrVR5ZNDKeL0//MGy90gA2oR27nUzPUKcViss0fiDuO qNkBj5zRw+Ar8imL6+60JTwO8lA6U/VO/UbDtyF3tXczWV8McOSh5IOKK++PWPrpi0ss Xa4rIXOGjmbN3y0Eaw8ZaeCJJo2hCb1eec4mH51Q65yKWn3V36BTVlkxAo42dM+6TTy1 MaXw== X-Gm-Message-State: ABy/qLYtON4dpZItZoM9PWBoyz9M/r4Nxh2UcpanAJHTXFo6lvk2QZXS PYJrxWq4+SH6oGraNd+u1DeluKdDxODWehjgHSc= X-Received: by 2002:a05:6a00:392a:b0:67a:52a7:b278 with SMTP id fh42-20020a056a00392a00b0067a52a7b278mr2483666pfb.9.1689313648217; Thu, 13 Jul 2023 22:47:28 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id q7-20020a63ae07000000b004fab4455748sm6625263pgf.75.2023.07.13.22.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 22:47:27 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Jose Marinho Subject: [PATCH v2 4/6] efi_loader: add EFI_RAM_DISK_PROTOCOL implementation Date: Fri, 14 Jul 2023 14:44:04 +0900 Message-Id: <20230714054406.761508-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230714054406.761508-1-masahisa.kojima@linaro.org> References: <20230714054406.761508-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 adds the EFI_RAM_DISK_PROTOCOL implementation. User can mount the distro installer by registering the memory mapped ISO image through EFI_RAM_DISK_PROTOCOL. Note that the installation process may not proceed after the distro installer calls ExitBootServices() since there is no hand-off process for the block device of memory mapped ISO image. Signed-off-by: Masahisa Kojima --- Changes in v2: - implement EFI_RAM_DISK_PROTOCOL based on the ramdisk uclass include/efi_api.h | 13 ++++ include/efi_loader.h | 4 + lib/efi_loader/Kconfig | 7 ++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_ram_disk.c | 142 ++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 ++ lib/uuid.c | 4 + 7 files changed, 177 insertions(+) create mode 100644 lib/efi_loader/efi_ram_disk.c diff --git a/include/efi_api.h b/include/efi_api.h index 4ee4a1b5e9..3982ab89bc 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -764,6 +764,19 @@ struct efi_block_io { efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this); }; +#define EFI_RAM_DISK_PROTOCOL_GUID \ + EFI_GUID(0xab38a0df, 0x6873, 0x44a9, \ + 0x87, 0xe6, 0xd4, 0xeb, 0x56, 0x14, 0x84, 0x49) + +struct efi_ram_disk_protocol { + /* "register" is a reserved keyword in C, use "disk_register" instead */ + efi_status_t(EFIAPI *disk_register)( + u64 ram_disk_base, u64 ram_disk_size, efi_guid_t *ram_disk_type, + struct efi_device_path *parent_device_path, + struct efi_device_path **device_path); + efi_status_t (EFIAPI *unregister)(struct efi_device_path *device_path); +}; + struct simple_text_output_mode { s32 max_mode; s32 mode; diff --git a/include/efi_loader.h b/include/efi_loader.h index 604fd765f7..70c8c83099 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -333,6 +333,8 @@ extern const efi_guid_t smbios_guid; /*GUID of console */ extern const efi_guid_t efi_guid_text_input_protocol; extern const efi_guid_t efi_guid_text_output_protocol; +/* GUID of Ram Disk protocol */ +extern const efi_guid_t efi_guid_ram_disk_protocol; extern char __efi_runtime_start[], __efi_runtime_stop[]; extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[]; @@ -1159,4 +1161,6 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int */ void efi_add_known_memory(void); +efi_status_t efi_ram_disk_register(void); + #endif /* _EFI_LOADER_H */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index c5835e6ef6..ff0559e8c4 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -433,4 +433,11 @@ config EFI_RISCV_BOOT_PROTOCOL replace the transfer via the device-tree. The latter is not possible on systems using ACPI. +config EFI_RAM_DISK_PROTOCOL + bool "EFI_RAM_DISK_PROTOCOL support" + depends on PARTITIONS + depends on RAM_DISK + help + Provide a EFI_RAM_DISK_PROTOCOL implementation to register the + RAM disk and create the block device. endif diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 1a8c8d7cab..4197f594a2 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -86,6 +86,7 @@ obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o obj-$(CONFIG_EFI_ECPT) += efi_conformance.o +obj-$(CONFIG_EFI_RAM_DISK_PROTOCOL) += efi_ram_disk.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE) diff --git a/lib/efi_loader/efi_ram_disk.c b/lib/efi_loader/efi_ram_disk.c new file mode 100644 index 0000000000..a261d93963 --- /dev/null +++ b/lib/efi_loader/efi_ram_disk.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * RAM Disk Protocol + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +const efi_guid_t efi_guid_ram_disk_protocol = EFI_RAM_DISK_PROTOCOL_GUID; + +/* + * ram_disk_register - Register service of the RAM disk protocol + * + * @ram_disk_base: The base address of registered RAM disk + * @ram_disk_size: The size of registered RAM disk + * @ram_disk_type: The type of registered RAM disk + * @parent_device_path: Pointer to the parent device path + * @device_path: Pointer to the device path + * Return: status code + */ +static efi_status_t EFIAPI +ram_disk_register(u64 ram_disk_base, u64 ram_disk_size, + efi_guid_t *ram_disk_type, + struct efi_device_path *parent_device_path, + struct efi_device_path **device_path) +{ + efi_status_t ret; + struct udevice *bdev; + efi_handle_t disk_handle; + struct efi_handler *handler; + struct efi_device_path *dp; + + EFI_ENTRY("%llu %llu %pUs %p, %p", ram_disk_base, ram_disk_size, + ram_disk_type, parent_device_path, device_path); + + if (!ram_disk_size || !ram_disk_type || !device_path) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + *device_path = NULL; + + /* TODO: Add parent_device_path */ + bdev = ramdisk_mount(ram_disk_base, ram_disk_size, ram_disk_type); + if (!bdev) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + if (dev_tag_get_ptr(bdev, DM_TAG_EFI, (void **)&disk_handle)) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = efi_search_protocol(disk_handle, &efi_guid_device_path, &handler); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_protocol_open(handler, (void **)&dp, NULL, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + goto out; + + log_debug("EFI_RAM_DISK_PROTOCOL register %pD\n", dp); + + *device_path = efi_dp_dup(dp); + if (!(*device_path)) + ret = EFI_OUT_OF_RESOURCES; + +out: + return EFI_EXIT(ret); +} + +/* + * ram_disk_unregister - Unregister service of the RAM disk protocol + * + * @device_path: Pointer to the device path + * Return: status code + */ +static efi_status_t EFIAPI +ram_disk_unregister(struct efi_device_path *device_path) +{ + int ret; + efi_status_t status = EFI_SUCCESS; + enum uclass_id id; + efi_handle_t disk_handle; + + EFI_ENTRY("%pD", device_path); + + if (!device_path) { + status = EFI_INVALID_PARAMETER; + goto out; + } + + disk_handle = efi_dp_find_obj(device_path, &efi_block_io_guid, NULL); + if (!disk_handle) { + status = EFI_NOT_FOUND; + goto out; + } + + id = device_get_uclass_id(disk_handle->dev); + if (id != UCLASS_BLK) { + status = EFI_INVALID_PARAMETER; + goto out; + } + + ret = ramdisk_unmount(disk_handle->dev); + if (ret) { + log_err("EFI_RAM_DISK_PROTOCOL unregister failed(%d)\n", ret); + status = EFI_INVALID_PARAMETER; + goto out; + } + +out: + return EFI_EXIT(status); +} + +static const struct efi_ram_disk_protocol efi_ram_disk_protocol = { + .disk_register = ram_disk_register, + .unregister = ram_disk_unregister, +}; + +/** + * efi_ram_disk_register() - register EFI_RAM_DISK_PROTOCOL + * + * Return: status code + */ +efi_status_t efi_ram_disk_register(void) +{ + efi_status_t ret; + + ret = efi_add_protocol(efi_root, &efi_guid_ram_disk_protocol, + (void *)&efi_ram_disk_protocol); + if (ret != EFI_SUCCESS) + log_err("Cannot install EFI_RAM_DISK_PROTOCOL\n"); + + return ret; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 877f3878d6..8c430d4a9c 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -344,6 +344,12 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_EFI_RAM_DISK_PROTOCOL)) { + ret = efi_ram_disk_register(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Initialize EFI runtime services */ ret = efi_reset_system_init(); if (ret != EFI_SUCCESS) diff --git a/lib/uuid.c b/lib/uuid.c index 96e1af3c8b..9827588186 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -195,6 +195,10 @@ static const struct { "Firmware Management", EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID }, + { + "Ram Disk", + EFI_RAM_DISK_PROTOCOL_GUID + }, /* Configuration table GUIDs */ { "ACPI table",