From patchwork Mon Feb 3 10:59:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 861546 Delivered-To: patch@linaro.org Received: by 2002:adf:fb05:0:b0:385:e875:8a9e with SMTP id c5csp1955713wrr; Mon, 3 Feb 2025 02:59:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVLoGC2ozLeRRSNUFCUwYglfENU4/wxOLPGHp2p2mjw0F8TiIH+di1nJFABoL4FCeNAmWKW4Q==@linaro.org X-Google-Smtp-Source: AGHT+IHkU4XempGM5EgnHCMUpNzAltsyBRCO7dIWKneGTg7lQcf2abM8FeG732AcS7OX7SC71Bgl X-Received: by 2002:a05:6402:3594:b0:5dc:893d:6df1 with SMTP id 4fb4d7f45d1cf-5dc893d6f32mr13097977a12.0.1738580384081; Mon, 03 Feb 2025 02:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738580384; cv=none; d=google.com; s=arc-20240605; b=bEQkA39ATGrPXUJO9OB22cuaX80R9s18EOZvX8+IgLeosaYuaYmgeHwVQZ/jULl5T+ Foo2TezXT7blvIfchmsOXu2Wu5j6kU07tFAguqBw8sQG/1tE23WnCnBFygdvuQx4XTQR whjPV7EEAzfpsZ+s0lbYvbHoREDaMhBvGlJPDm/7prQ0EUz+wl5UEqPqqVYMbx/iKOaZ xq1aLjmdUs4v0LCpyx0HxxBgc5NTN6pglBbZuaQu3CcG0ssWMZR/MkxDRq9u1R03O41W HVx55Ny+7bN2+MIQ1gafCr8wg5vsIe5nW5SgfwoXjxXa7dcNnoJnXkr1TA8ygazxjOuQ ZEAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=eaGfQ4bTS6oKaTU9UqYQM7LX2VM/o9Ofyq2k9sXNuXs=; fh=qwTeYblSfJH8EkpqfAolY4+rWH9eBQROJxw0JuMnPkc=; b=FteglemZivdJXbsQNUAV8JX4r6j+M97FRtbrFnVGJzkIM5IkxRQA03MQuTr9VAJKSr 82S31ZAlSt3i6km18mlAdIr0j/AC7tuT8GH+zCTyvXjg+5rn0q1QNL0vJZ83/aR6euwf qq7zBkBUevEHgAT2O7CSEJOPBMov1UW4oIBarYWLps9Zp1M801cAtw3f8bKGq3YGYEa8 sOBswbvgOs4+iylZWk619yH0FriC7TCGnxS7QIBcZ9THC+/Ps5ipM/diRRAlynx9GJ85 BzP5TkrOTbZTkks9/O4v/ZaiRM9wNY0Zm466oFy3QPW7ULSG+yHUAzKbbTHzv58xdIpN guXg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 4fb4d7f45d1cf-5dc723e357fsi8438306a12.145.2025.02.03.02.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 02:59:44 -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; 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=fail (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 28BBF80207; Mon, 3 Feb 2025 11:59:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C133180207; Mon, 3 Feb 2025 11:59:37 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id E562780107 for ; Mon, 3 Feb 2025 11:59:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B2B561476; Mon, 3 Feb 2025 02:59:58 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CF5173F5A1; Mon, 3 Feb 2025 02:59:30 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Masahisa Kojima , Sughosh Ganu Subject: [PATCH v4 1/5] fdt: add support for adding pmem nodes Date: Mon, 3 Feb 2025 16:29:08 +0530 Message-Id: <20250203105912.196654-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203105912.196654-1-sughosh.ganu@linaro.org> References: <20250203105912.196654-1-sughosh.ganu@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: Masahisa Kojima One of the problems OS installers face, when running in EFI, is that the mounted ISO after calling ExitBootServices goes away. For some distros this is a problem since they rely on finding some core packages before continuing the installation. Distros have works around this -- e.g Fedora has a special kernel command line parameter called inst.stage2 [0]. ACPI has NFIT and NVDIMM support to provide ramdisks to the OS, but we don't have anything in place for DTs. Linux and device trees have support for persistent memory devices. So add a function that can inject a pmem node in a DT, so we can use it when launhing OS installers with EFI. [0] https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/installation_guide/chap-anaconda-boot-options#sect-boot-options-installer Signed-off-by: Masahisa Kojima Signed-off-by: Sughosh Ganu --- Changes since V3: * Rephrased the 2MiB alignment error message as suggested by Heinrich * Rephrased the description of fdt_fixup_pmem_region() function as suggested by Heinrich boot/fdt_support.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/fdt_support.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 49efeec3681..e20b9759138 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -464,7 +465,6 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, do_fixup_by_compat(fdt, compat, prop, &tmp, 4, create); } -#ifdef CONFIG_ARCH_FIXUP_FDT_MEMORY /* * fdt_pack_reg - pack address and size array into the "reg"-suitable stream */ @@ -493,6 +493,7 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, return p - (char *)buf; } +#ifdef CONFIG_ARCH_FIXUP_FDT_MEMORY #if CONFIG_NR_DRAM_BANKS > 4 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS #else @@ -2222,3 +2223,41 @@ int fdt_valid(struct fdt_header **blobp) } return 1; } + +int fdt_fixup_pmem_region(void *blob, ulong addr, u32 size) +{ + u64 pmem_start[2] = { 0 }; + u64 pmem_size[2] = { 0 }; + char pmem_node[32] = {0}; + int nodeoffset, len; + int err; + u8 tmp[4 * 16]; /* Up to 64-bit address + 64-bit size */ + + if (!IS_ALIGNED(addr, SZ_2M) || !IS_ALIGNED(addr + size, SZ_2M)) { + printf("Start and end address must be 2MiB aligned\n"); + return -1; + } + + snprintf(pmem_node, sizeof(pmem_node), "pmem@%lx", addr); + nodeoffset = fdt_find_or_add_subnode(blob, 0, pmem_node); + if (nodeoffset < 0) + return nodeoffset; + + err = fdt_setprop_string(blob, nodeoffset, "compatible", "pmem-region"); + if (err) + return err; + err = fdt_setprop_empty(blob, nodeoffset, "volatile"); + if (err) + return err; + pmem_start[0] = addr; + pmem_size[0] = size; + len = fdt_pack_reg(blob, tmp, pmem_start, pmem_size, 1); + err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); + if (err < 0) { + printf("WARNING: could not set pmem %s %s.\n", "reg", + fdt_strerror(err)); + return err; + } + + return 0; +} diff --git a/include/fdt_support.h b/include/fdt_support.h index f0ad2e6b365..b72cd2920de 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -507,4 +507,18 @@ void fdt_fixup_pstore(void *blob); */ int fdt_kaslrseed(void *blob, bool overwrite); +/** + * fdt_fixup_pmem_region() - add a pmem node on the device tree + * + * This functions adds/updates a pmem node to the device tree. + * Usually used with EFI installers to preserve installer + * images + * + * @blob: device tree provided by caller + * @addr: start address of the pmem node + * @size: size of the memory of the pmem node + * Return: 0 on success or < 0 on failure + */ +int fdt_fixup_pmem_region(void *blob, ulong addr, u32 size); + #endif /* ifndef __FDT_SUPPORT_H */ From patchwork Mon Feb 3 10:59:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 861547 Delivered-To: patch@linaro.org Received: by 2002:adf:fb05:0:b0:385:e875:8a9e with SMTP id c5csp1955782wrr; Mon, 3 Feb 2025 02:59:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXkT0HQm2mGGD+8q64ptp8J7jcb7BuP1luKZW/0Kd+Dls0ER/9azN0L4ce6qQ/Zfs6blV5v8A==@linaro.org X-Google-Smtp-Source: AGHT+IGgHzyJ2U85H7kbpFzV22rvHFEHLS+PVkNGQ7sd2fOoLMOvNzFwmf/ph7HPjn5Yd4ICHNLC X-Received: by 2002:a05:6402:1e93:b0:5db:f5e9:6745 with SMTP id 4fb4d7f45d1cf-5dc5e6ce200mr23809366a12.0.1738580392922; Mon, 03 Feb 2025 02:59:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738580392; cv=none; d=google.com; s=arc-20240605; b=i4AHGyvh4xQ2xgy0b4UcrqvBqQYx6xtHSgnogsDeMa6dVr/iYTu1RZMZ1YcBwCumUc S5ovpD+9wCYe5/MhaEOodHbkhdEBFxQqIBi0MlXlpNXYXyfHr+UnEqD556DwWrhlwE/U PpVNEoQjTGN4k+3DeqetX3QmVD81RJ8muNfjBKx1Div6X1tZ1D/6x5a7QZfPx2/GHKQG wV3fWOjIjDeKm9FiWdXuFDyfDVu4xItalc8P35NxzkUb5e8ocNkLkjRKk7CWwY4aO/+E Rf9L40NxRomg8GxKsu88IPGu4IvxTR2xy7vYOONhqSuvJtartWT8Bbuer86pf1Iv5I+K A0vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=7BSmAMvHNOjRH3uv2lX4kZxcbn10FHXbiYg7ymlbcdw=; fh=YztAvNK/sr+8F45uFKQI49AUhmfh/leUUwFnn5QUXFw=; b=L78SMH8c8z4GTomXOq7iYuHKVO27PjVgJvcNCRugmnQFYKY3gdl8UJyOe8fHgRbxcz uQRPv8KJ1jUL2LVvWG2yD+iwWAu/fAYii4cshquqQnaBZVwX3UlJp/tTnB91pXVThLWy YjL4+ouXaBRnEjMQ2/N/6khHqarJ2mYVSCssuTDYNZ3LOv18lQr9HiQCDr0AB+448meR 8FsETr4HpsjhpZyo4O1EwHPO5jHaLNYsTIlhh3MKzEYzP+ese6r04xO+36Oa6qmqgw9f bkKkKrGzKrYec/XuRExZ4cit937hLiVrdGCJ+3ZWRiyfeL7jGWAX9MSc4UHU7c7n+Atk erhQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 4fb4d7f45d1cf-5dc725601ebsi8488301a12.577.2025.02.03.02.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 02:59:52 -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; 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=fail (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 7F78380243; Mon, 3 Feb 2025 11:59:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id A22FF80214; Mon, 3 Feb 2025 11:59:42 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id C925F805D7 for ; Mon, 3 Feb 2025 11:59:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 88E9111FB; Mon, 3 Feb 2025 03:00:02 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E576C3F5A1; Mon, 3 Feb 2025 02:59:34 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v4 2/5] efi_loader: add a function to remove memory from the EFI map Date: Mon, 3 Feb 2025 16:29:09 +0530 Message-Id: <20250203105912.196654-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203105912.196654-1-sughosh.ganu@linaro.org> References: <20250203105912.196654-1-sughosh.ganu@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: Ilias Apalodimas With upcoming changes supporting pmem nodes, we need to remove the pmem area from the EFI memory map. Add a function to do that. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt Signed-off-by: Sughosh Ganu --- Changes since V3: None include/efi_loader.h | 11 +++++--- lib/efi_loader/efi_memory.c | 51 +++++++++++++++++++++++++++---------- lib/lmb.c | 4 +-- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index dcae6a731a0..d10e3ca4895 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -853,7 +853,7 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type); /** - * efi_add_memory_map_pg() - add pages to the memory map + * efi_update_memory_map() - update the memory map by adding/removing pages * * @start: start address, must be a multiple of * EFI_PAGE_SIZE @@ -861,11 +861,14 @@ efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type); * @memory_type: type of memory added * @overlap_conventional: region may only overlap free(conventional) * memory + * @remove: remove memory map * Return: status code */ -efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, - int memory_type, - bool overlap_conventional); +efi_status_t efi_update_memory_map(u64 start, u64 pages, int memory_type, + bool overlap_conventional, bool remove); + +/* Remove memory from the EFI memory map */ +efi_status_t efi_remove_memory_map(u64 start, u64 size, int memory_type); /* Called by board init to initialize the EFI drivers */ efi_status_t efi_driver_init(void); diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 1212772471e..2362995abf6 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -258,7 +258,7 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, } /** - * efi_add_memory_map_pg() - add pages to the memory map + * efi_update_memory_map() - update the memory map by adding/removing pages * * @start: start address, must be a multiple of * EFI_PAGE_SIZE @@ -266,11 +266,11 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, * @memory_type: type of memory added * @overlap_conventional: region may only overlap free(conventional) * memory + * @remove: remove memory map * Return: status code */ -efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, - int memory_type, - bool overlap_conventional) +efi_status_t efi_update_memory_map(u64 start, u64 pages, int memory_type, + bool overlap_conventional, bool remove) { struct efi_mem_list *lmem; struct efi_mem_list *newlist; @@ -278,9 +278,9 @@ efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, uint64_t carved_pages = 0; struct efi_event *evt; - EFI_PRINT("%s: 0x%llx 0x%llx %d %s\n", __func__, + EFI_PRINT("%s: 0x%llx 0x%llx %d %s %s\n", __func__, start, pages, memory_type, overlap_conventional ? - "yes" : "no"); + "yes" : "no", remove ? "remove" : "add"); if (memory_type >= EFI_MAX_MEMORY_TYPE) return EFI_INVALID_PARAMETER; @@ -363,7 +363,10 @@ efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, } /* Add our new map */ - list_add_tail(&newlist->link, &efi_mem); + if (!remove) + list_add_tail(&newlist->link, &efi_mem); + else + free(newlist); /* And make sure memory is listed in descending order */ efi_mem_sort(); @@ -400,7 +403,29 @@ efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type) pages = efi_size_in_pages(size + (start & EFI_PAGE_MASK)); start &= ~EFI_PAGE_MASK; - return efi_add_memory_map_pg(start, pages, memory_type, false); + return efi_update_memory_map(start, pages, memory_type, false, false); +} + +/** + * efi_remove_memory_map() - remove memory area to the memory map + * + * @start: start address of the memory area + * @size: length in bytes of the memory area + * @memory_type: type of memory removed + * + * Return: status code + * + * This function automatically aligns the start and size of the memory area + * to EFI_PAGE_SIZE. + */ +efi_status_t efi_remove_memory_map(u64 start, u64 size, int memory_type) +{ + u64 pages; + + pages = efi_size_in_pages(size + (start & EFI_PAGE_MASK)); + start &= ~EFI_PAGE_MASK; + + return efi_update_memory_map(start, pages, memory_type, false, true); } /** @@ -501,7 +526,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, efi_addr = (u64)(uintptr_t)map_sysmem(addr, 0); /* Reserve that map in our memory maps */ - ret = efi_add_memory_map_pg(efi_addr, pages, memory_type, true); + ret = efi_update_memory_map(efi_addr, pages, memory_type, true, false); if (ret != EFI_SUCCESS) { /* Map would overlap, bail out */ lmb_free_flags(addr, (u64)pages << EFI_PAGE_SHIFT, flags); @@ -822,8 +847,8 @@ static void add_u_boot_and_runtime(void) uboot_stack_size) & ~EFI_PAGE_MASK; uboot_pages = ((uintptr_t)map_sysmem(gd->ram_top - 1, 0) - uboot_start + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; - efi_add_memory_map_pg(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE, - false); + efi_update_memory_map(uboot_start, uboot_pages, EFI_BOOT_SERVICES_CODE, + false, false); #if defined(__aarch64__) /* * Runtime Services must be 64KiB aligned according to the @@ -841,8 +866,8 @@ static void add_u_boot_and_runtime(void) runtime_end = (uintptr_t)__efi_runtime_stop; runtime_end = (runtime_end + runtime_mask) & ~runtime_mask; runtime_pages = (runtime_end - runtime_start) >> EFI_PAGE_SHIFT; - efi_add_memory_map_pg(runtime_start, runtime_pages, - EFI_RUNTIME_SERVICES_CODE, false); + efi_update_memory_map(runtime_start, runtime_pages, + EFI_RUNTIME_SERVICES_CODE, false, false); } int efi_memory_init(void) diff --git a/lib/lmb.c b/lib/lmb.c index 7ca44591e1d..d5aea1ed8fe 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -455,11 +455,11 @@ static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size, u8 op, pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK)); efi_addr &= ~EFI_PAGE_MASK; - status = efi_add_memory_map_pg(efi_addr, pages, + status = efi_update_memory_map(efi_addr, pages, op == MAP_OP_RESERVE ? EFI_BOOT_SERVICES_DATA : EFI_CONVENTIONAL_MEMORY, - false); + false, false); if (status != EFI_SUCCESS) { log_err("%s: LMB Map notify failure %lu\n", __func__, status & ~EFI_ERROR_MASK); From patchwork Mon Feb 3 10:59:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 861548 Delivered-To: patch@linaro.org Received: by 2002:adf:fb05:0:b0:385:e875:8a9e with SMTP id c5csp1955826wrr; Mon, 3 Feb 2025 03:00:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXm5xE1QOAmE1RJu1z29UaqB8n+/5bwSjrTMvXtWMIw6Q2hiTxfipe/fC/QjqyD960TS6yABQ==@linaro.org X-Google-Smtp-Source: AGHT+IH+48tNxwgnbINXvcg0zX4W6s59SU1tB5tX8KsOo07DivWX2qRcmkFvG0xXMvzAkjOzJtTx X-Received: by 2002:a17:907:6d1f:b0:ab6:f06b:4a26 with SMTP id a640c23a62f3a-ab6f06b4c6fmr1690469966b.34.1738580401758; Mon, 03 Feb 2025 03:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738580401; cv=none; d=google.com; s=arc-20240605; b=OsceeIyC5E5d9IfsMQfbjOy9TnH644l44lSp7+MCCHAIM2Wknh0MT8KP9vBG35oywD vsaN1EcS8xF5CBvcVCvIRL0sVwruBuduHy5CIhDmn3qr3CpFTyYopI3Ejj+SjeQLK/Me tSwqYlirgRejRh6R9dtU51h2rNiioeQBfDKzm7WjVd1sRha/A3khA9G9QzFaldBoLood 4rQAtjv1H7Q1s4MKxAh2Nx47epjVNr4bxEemGhj0PmSp90tg0+JS5P6wRf5Jn9vfJDsq gTony8MHTzgujgdGswfU5gB1CzgpsVhGe/FC/N3nw3FDs2lQrHeZNwB4VZZhtiBFLHXp O7PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=z60xDbLt7iRvgWYhh3xt9xygV/3WrJZ1jK126XjqhvU=; fh=YztAvNK/sr+8F45uFKQI49AUhmfh/leUUwFnn5QUXFw=; b=HpnVPb6ltwSRGda5oAwOlnJ0EE8cNXM9V49qgYK6Kb1PdQABY+em59zTKt5qd6YWM+ sdHAY0/uNEihAPGPbj75RvOXtvl13fM+F35WSKnLWsPUJA2PGHnMoACbNMzphy7ny7ra 2NQfoLLAqIm3SCD9LLNchCSeFagLoWV7opv+vFCHvaoP9hxVpNE5iPzp6HMzV3qQs0ZN JX8/yIvSEwdKtwhGED+vUqIX9KOogcYVFeG3DVco9LUO2Q3QRQ95Lh9eawCUncbD9L2g 188ZTK5lOsqB+jliOsXDVZUEYJ1bnGp2kNLmuzwaOKSEog8vOsQeTRRx6mNSuqTv09JH +iRg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 a640c23a62f3a-ab6e4803a3esi822368866b.181.2025.02.03.03.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 03:00:01 -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; 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=fail (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 CEE1E801DE; Mon, 3 Feb 2025 11:59:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C0E4F801DE; Mon, 3 Feb 2025 11:59:44 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 79FC8801DE for ; Mon, 3 Feb 2025 11:59:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F6A811FB; Mon, 3 Feb 2025 03:00:06 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B3E213F5A1; Mon, 3 Feb 2025 02:59:38 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v4 3/5] efi_loader: preserve installer images in pmem Date: Mon, 3 Feb 2025 16:29:10 +0530 Message-Id: <20250203105912.196654-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203105912.196654-1-sughosh.ganu@linaro.org> References: <20250203105912.196654-1-sughosh.ganu@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: Ilias Apalodimas One of the problems OS installers face, when running in EFI, is that the mounted ISO after calling ExitBootServices goes away. For some distros this is a problem since they rely on finding some core packages before continuing the installation. Distros have works around this -- e.g Fedora has a special kernel command line parameter called inst.stage2 [0]. ACPI has NFIT and NVDIMM support to provide ramdisks to the OS, but we don't have anything in place for DTs. Linux and device trees have support for persistent memory devices. It's worth noting that for linux to instantiate the /dev/pmemX device, the memory described in the pmem node has to be omitted from the EFI memory map we hand over to the OS if ZONE_DEVICES and SPARSEMEM is enabled. With those enabled the pmem driver ends up calling devm_memremap_pages() instead of devm_memremap(). The latter works whether the memory is omitted or marked as reserved, but mapping pages only works if the memory is omitted. On top of that, depending on how the kernel is configured, that memory area must be page aligned or 2MB aligned. PowerPC is an exception here and requires 16MB alignment, but since we don't have EFI support for it, limit the alignment to 2MB. Ensure that the ISO image is 2MB aligned and remove the region occupied by the image from the EFI memory map. Signed-off-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu --- Changes since V3: None lib/efi_loader/efi_bootmgr.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index c6124c590d9..081eff057f4 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include static const struct efi_boot_services *bs; static const struct efi_runtime_services *rs; @@ -362,13 +364,16 @@ static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size, } /* - * TODO: expose the ramdisk to OS. - * Need to pass the ramdisk information by the architecture-specific - * methods such as 'pmem' device-tree node. + * Linux supports 'pmem' which allows OS installers to find, reclaim + * the mounted images and continue the installation since the contents + * of the pmem region are treated as local media. + * + * The memory regions used for it needs to be carved out of the EFI + * memory map. */ - ret = efi_add_memory_map(addr, size, EFI_RESERVED_MEMORY_TYPE); + ret = efi_remove_memory_map(addr, size, EFI_CONVENTIONAL_MEMORY); if (ret != EFI_SUCCESS) { - log_err("Memory reservation failed\n"); + log_err("Failed to reserve memory\n"); goto err; } @@ -490,6 +495,13 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, ret = EFI_INVALID_PARAMETER; goto err; } + /* + * Depending on the kernel configuration, pmem memory area must be page + * aligned or 2MB aligned. PowerPC is an exception here and requires + * 16MB alignment, but since we don't have EFI support for it, limit + * the alignment to 2MB. + */ + image_size = ALIGN(image_size, SZ_2M); /* * If the file extension is ".iso" or ".img", mount it and try to load From patchwork Mon Feb 3 10:59:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 861549 Delivered-To: patch@linaro.org Received: by 2002:adf:fb05:0:b0:385:e875:8a9e with SMTP id c5csp1955937wrr; Mon, 3 Feb 2025 03:00:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUyqwGr94UJNTB2rW3oqdmZZorDWhdpYkWQPw0hNxihTRjxWJ2Z3/uUu4j1k2J3NQhAoVEMbw==@linaro.org X-Google-Smtp-Source: AGHT+IGAoS8lT4gamlwbh/OBpsxYi99PjDrRA87HWNpaFgfTgQkok5ipZvkGDqaTQQCBChXZD1ey X-Received: by 2002:a17:907:da8:b0:ab3:61e2:8aaf with SMTP id a640c23a62f3a-ab6f760e28fmr1432990766b.25.1738580413990; Mon, 03 Feb 2025 03:00:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738580413; cv=none; d=google.com; s=arc-20240605; b=Qn97AJpHUa2R3rBmRa53GxPMWhpOostyGC2vk200ZEdwrWvV2410qRiBItuFd7by9Q km2CTaXrUpnAMsko+VaJ2QKdcy0he8ZDRph1YkaL6Omn9jcZlbjscPY5lXvoouaLzinK n1SQdTXEBkYC7Aw9KttQX+6sOFW9iN5IjV9Xh/ipvbPU2e0h/2xIqCfnUeJt/2D5JWHn iEwA2RWpVc1KZ6N/1f+E0AXhxeIq26hYuUddnznfiNgEWKSMP0HdNiuOQvlwFfTd5xKw TVqtILeP0GZEbH6eO8LW+vO00xuNNLMBCwfOkQr6aaz/TA2LBSo3KISGe181bf8BwudO voGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=ABXe8h+xOL7GZLupgJFaUOTDveHecxHqaY0JHqoTisM=; fh=YztAvNK/sr+8F45uFKQI49AUhmfh/leUUwFnn5QUXFw=; b=A1FxlkTM08vzXfCim/wRNIKdSNXs9LVxQ9jw4f9ufWiPYkCZQCfbSC7kOwEypUcGxw 6WaLde/BvLp3+B6I7rg1qw9etPsqgjzqDWjQ8PyVeDyVfyKuwhlfCiGLlOqmY4WVlsyV NqdkliYXKYNb0pO7+mnBvwG2SnoLcciHCNrPwonVf6UDFyuTDbs7mcvW3Fz8kWBxbJGi wkN2dhRJIxwonTP3Bp9IUw/bma7U3zfsLXoM1IKfhUZib+66UoKmej4EwPM093rBzfdk DbsQ+mkV4yKm7xcGINGrWXfI3mPcNxMeYPInucCFvapIqnMroeafxNqEMyubcsNo9slp C/ww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 a640c23a62f3a-ab6e4806b08si865932466b.206.2025.02.03.03.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 03:00:13 -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; 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=fail (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 24D10805D7; Mon, 3 Feb 2025 11:59:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7139E806C9; Mon, 3 Feb 2025 11:59:48 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 65F7C80087 for ; Mon, 3 Feb 2025 11:59:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 366AC11FB; Mon, 3 Feb 2025 03:00:10 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 822E03F5A1; Mon, 3 Feb 2025 02:59:42 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v4 4/5] blkmap: store type of blkmap slice in corresponding structure Date: Mon, 3 Feb 2025 16:29:11 +0530 Message-Id: <20250203105912.196654-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203105912.196654-1-sughosh.ganu@linaro.org> References: <20250203105912.196654-1-sughosh.ganu@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 Add information about the type of blkmap slice in the corresponding slice structure. Put information in the blkmap slice structure to identify if it is associated with a memory or linear mapped device. Which can then be used to take specific action based on the type of the blkmap slice. Signed-off-by: Sughosh Ganu --- Changes since V3: * Add the map type to the blkmap slice instead of the entire blkmap device drivers/block/blkmap.c | 4 ++++ include/blkmap.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 34eed1380dc..4c71ec784e0 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -25,12 +25,14 @@ struct blkmap; * @node: List node used to associate this slice with a blkmap * @blknr: Start block number of the mapping * @blkcnt: Number of blocks covered by this mapping + * @type: Type of blkmap slice */ struct blkmap_slice { struct list_head node; lbaint_t blknr; lbaint_t blkcnt; + enum blkmap_slice_type type; /** * @read: - Read from slice @@ -169,6 +171,7 @@ int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, .slice = { .blknr = blknr, .blkcnt = blkcnt, + .type = BLKMAP_SLICE_LINEAR, .read = blkmap_linear_read, .write = blkmap_linear_write, @@ -248,6 +251,7 @@ int __blkmap_map_mem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, .slice = { .blknr = blknr, .blkcnt = blkcnt, + .type = BLKMAP_SLICE_MEM, .read = blkmap_mem_read, .write = blkmap_mem_write, diff --git a/include/blkmap.h b/include/blkmap.h index d53095437fa..c7b4bf13c4e 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -9,6 +9,12 @@ #include +/* Type of blkmap slice, Linear or Memory */ +enum blkmap_slice_type { + BLKMAP_SLICE_LINEAR = 1, + BLKMAP_SLICE_MEM, +}; + /** * struct blkmap - Block map * From patchwork Mon Feb 3 10:59:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 861550 Delivered-To: patch@linaro.org Received: by 2002:adf:fb05:0:b0:385:e875:8a9e with SMTP id c5csp1956013wrr; Mon, 3 Feb 2025 03:00:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVlpac+exXj9KtoNwzDePknIiALJNedznH+xGG38iKfSzIoJIJruQwr8bJudhiwdSDq7I3z9Q==@linaro.org X-Google-Smtp-Source: AGHT+IGKTdc38QTHak45eVjVUKPSdtJbfCa8qmws13s+VXGlPx/zqNyN9PmZQfbSURYnYDlJBUVb X-Received: by 2002:a05:6402:2390:b0:5dc:71f6:9723 with SMTP id 4fb4d7f45d1cf-5dc71f698bemr12129073a12.21.1738580423916; Mon, 03 Feb 2025 03:00:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738580423; cv=none; d=google.com; s=arc-20240605; b=Vk04Xgh3yXC7U4iLlBoFKUEjSoLJq0ZoLzBMNdDYkNRbkg62RD3FX5RvjYQVmbigJD VgltatDPrZ4/qthK8SLiXIVFk/yTBpnZu5Q4aTUjwWtT8nwpfzlFksfGVBPDEK8zBdTc X2riyOi77VPzruwt2AUpIRowBwF4bs3Yp20qbJDasPcQ2u8Pai0Ij8ChbCbIGHpJfcX0 JKhP5Rhpfh4Gc0kQnhnFmhi1+4qfhf/Jj6mvQKGHuATTz+FUwPs6hEA/9RMQp4F7a4ny wnosawtyCec7ARx8dn5jgrEFyCu+mq8dC+lA8EiA8ejfPShl5TQTuUaQ7tm9FiXKQJqf 5oYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=C8e0MQIGJ5BX/z+Eda8I/ZetqRSOTh9G2NH8mtahW7c=; fh=YztAvNK/sr+8F45uFKQI49AUhmfh/leUUwFnn5QUXFw=; b=ILB9/B7JF/+UYJgBtH8ZyKzVUt/z3P2kW20BUKLg87OZZ8FlRmGBrBSX0hFMxxWwhF T2y0Lmlq4lAsTs43w3/0eXdSrCJnCyfdZzpXebN2BZQGLMoYvONerTNJCEuvXbTFKEFq J2tP2F6SOVAWKaMYcwjB6YsVXJh/oPAjCQhJEm+ziZ0n1fvfviJ3UIEgMU8z2gCU4dqA wBu+BTkD0gf41v7qSA54cgz9O8L6u3O/VnSCqGeFMB+i7GwKKDpDg6CQhGa3V3aNQ1A1 6Md3N7Ny8ONZ7/c5xNQFEIuVmQ0gqtZhbGP6K5JoQYbDJuPtH2hhQ5tWe2gJQqPTemoy FULw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 4fb4d7f45d1cf-5dc723e13fbsi8447022a12.130.2025.02.03.03.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2025 03:00:23 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; 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=fail (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 71DC380107; Mon, 3 Feb 2025 11:59:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id DED1980568; Mon, 3 Feb 2025 11:59:52 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7C95080711 for ; Mon, 3 Feb 2025 11:59:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C81711FB; Mon, 3 Feb 2025 03:00:14 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 507F83F5A1; Mon, 3 Feb 2025 02:59:46 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Anton Antonov , Tobias Waldekranz , Bin Meng , Sughosh Ganu Subject: [PATCH v4 5/5] blkmap: add pmem nodes for blkmap memory mapped slices Date: Mon, 3 Feb 2025 16:29:12 +0530 Message-Id: <20250203105912.196654-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250203105912.196654-1-sughosh.ganu@linaro.org> References: <20250203105912.196654-1-sughosh.ganu@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 The EFI HTTP boot puts the ISO installer image at some location in memory which needs to be added to the devicetree as persistent memory (pmem) node. The OS installer then gets information about the presence of this ISO image through the pmem node and proceeds with the installation. In U-Boot, this ISO image gets mounted as a blkmap device, with a memory mapped slice. Add a helper function which iterates through all such memory mapped blkmap slices, and calls the FDT fixup function to add the pmem node. Invoke this helper function as part of the DT fixup which happens before booting the OS. Signed-off-by: Sughosh Ganu --- Changes since V3: * Move the definition of the helper function to the efi_helper.c * Remove the region of the blkmap mem map device from the EFI memory map along with adding the pmem node boot/image-fdt.c | 9 ++++ drivers/block/blkmap.c | 82 ------------------------------------- include/blkmap.h | 81 ++++++++++++++++++++++++++++++++++++ include/efi.h | 13 ++++++ lib/efi_loader/efi_helper.c | 52 +++++++++++++++++++++++ 5 files changed, 155 insertions(+), 82 deletions(-) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 9d1598b1a93..e64243af88e 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -8,6 +8,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */ +#include #include #include #include @@ -649,6 +650,14 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) if (!ft_verify_fdt(blob)) goto err; + if (CONFIG_IS_ENABLED(BLKMAP) && CONFIG_IS_ENABLED(EFI_LOADER)) { + fdt_ret = fdt_efi_pmem_setup(blob); + if (fdt_ret) { + log_err("pmem node fixup failed\n"); + goto err; + } + } + /* after here we are using a livetree */ if (!of_live_active() && CONFIG_IS_ENABLED(EVENT)) { struct event_ft_fixup fixup; diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 4c71ec784e0..2c7f4966ae9 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -14,59 +14,6 @@ #include #include -struct blkmap; - -/** - * struct blkmap_slice - Region mapped to a blkmap - * - * Common data for a region mapped to a blkmap, specialized by each - * map type. - * - * @node: List node used to associate this slice with a blkmap - * @blknr: Start block number of the mapping - * @blkcnt: Number of blocks covered by this mapping - * @type: Type of blkmap slice - */ -struct blkmap_slice { - struct list_head node; - - lbaint_t blknr; - lbaint_t blkcnt; - enum blkmap_slice_type type; - - /** - * @read: - Read from slice - * - * @read.bm: Blkmap to which this slice belongs - * @read.bms: This slice - * @read.blknr: Start block number to read from - * @read.blkcnt: Number of blocks to read - * @read.buffer: Buffer to store read data to - */ - ulong (*read)(struct blkmap *bm, struct blkmap_slice *bms, - lbaint_t blknr, lbaint_t blkcnt, void *buffer); - - /** - * @write: - Write to slice - * - * @write.bm: Blkmap to which this slice belongs - * @write.bms: This slice - * @write.blknr: Start block number to write to - * @write.blkcnt: Number of blocks to write - * @write.buffer: Data to be written - */ - ulong (*write)(struct blkmap *bm, struct blkmap_slice *bms, - lbaint_t blknr, lbaint_t blkcnt, const void *buffer); - - /** - * @destroy: - Tear down slice - * - * @read.bm: Blkmap to which this slice belongs - * @read.bms: This slice - */ - void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); @@ -116,20 +63,6 @@ static int blkmap_slice_add(struct blkmap *bm, struct blkmap_slice *new) return 0; } -/** - * struct blkmap_linear - Linear mapping to other block device - * - * @slice: Common map data - * @blk: Target block device of this mapping - * @blknr: Start block number of the target device - */ -struct blkmap_linear { - struct blkmap_slice slice; - - struct udevice *blk; - lbaint_t blknr; -}; - static ulong blkmap_linear_read(struct blkmap *bm, struct blkmap_slice *bms, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { @@ -188,21 +121,6 @@ int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, return err; } -/** - * struct blkmap_mem - Memory mapping - * - * @slice: Common map data - * @addr: Target memory region of this mapping - * @remapped: True if @addr is backed by a physical to virtual memory - * mapping that must be torn down at the end of this mapping's - * lifetime. - */ -struct blkmap_mem { - struct blkmap_slice slice; - void *addr; - bool remapped; -}; - static ulong blkmap_mem_read(struct blkmap *bm, struct blkmap_slice *bms, lbaint_t blknr, lbaint_t blkcnt, void *buffer) { diff --git a/include/blkmap.h b/include/blkmap.h index c7b4bf13c4e..e5e2d971548 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,7 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include #include /* Type of blkmap slice, Linear or Memory */ @@ -30,6 +31,86 @@ struct blkmap { struct list_head slices; }; +/** + * struct blkmap_slice - Region mapped to a blkmap + * + * Common data for a region mapped to a blkmap, specialized by each + * map type. + * + * @node: List node used to associate this slice with a blkmap + * @blknr: Start block number of the mapping + * @blkcnt: Number of blocks covered by this mapping + * @type: Type of blkmap slice + */ +struct blkmap_slice { + struct list_head node; + + lbaint_t blknr; + lbaint_t blkcnt; + enum blkmap_slice_type type; + + /** + * @read: - Read from slice + * + * @read.bm: Blkmap to which this slice belongs + * @read.bms: This slice + * @read.blknr: Start block number to read from + * @read.blkcnt: Number of blocks to read + * @read.buffer: Buffer to store read data to + */ + ulong (*read)(struct blkmap *bm, struct blkmap_slice *bms, + lbaint_t blknr, lbaint_t blkcnt, void *buffer); + + /** + * @write: - Write to slice + * + * @write.bm: Blkmap to which this slice belongs + * @write.bms: This slice + * @write.blknr: Start block number to write to + * @write.blkcnt: Number of blocks to write + * @write.buffer: Data to be written + */ + ulong (*write)(struct blkmap *bm, struct blkmap_slice *bms, + lbaint_t blknr, lbaint_t blkcnt, const void *buffer); + + /** + * @destroy: - Tear down slice + * + * @read.bm: Blkmap to which this slice belongs + * @read.bms: This slice + */ + void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); +}; + +/** + * struct blkmap_mem - Memory mapping + * + * @slice: Common map data + * @addr: Target memory region of this mapping + * @remapped: True if @addr is backed by a physical to virtual memory + * mapping that must be torn down at the end of this mapping's + * lifetime. + */ +struct blkmap_mem { + struct blkmap_slice slice; + void *addr; + bool remapped; +}; + +/** + * struct blkmap_linear - Linear mapping to other block device + * + * @slice: Common map data + * @blk: Target block device of this mapping + * @blknr: Start block number of the target device + */ +struct blkmap_linear { + struct blkmap_slice slice; + + struct udevice *blk; + lbaint_t blknr; +}; + /** * blkmap_map_linear() - Map region of other block device * diff --git a/include/efi.h b/include/efi.h index d005cb6181e..f9bbb175c3a 100644 --- a/include/efi.h +++ b/include/efi.h @@ -705,4 +705,17 @@ static inline bool efi_use_host_arch(void) */ int efi_get_pxe_arch(void); +/** + * fdt_efi_pmem_setup() - Pmem setup in DT and EFI memory map + * @fdt: Devicetree to add the pmem nodes to + * + * Iterate through all the blkmap devices, look for BLKMAP_MEM devices, + * and add pmem nodes corresponding to the blkmap slice to the + * devicetree along with removing the corresponding region from the + * EFI memory map. + * + * Returns: 0 on success, negative error on failure + */ +int fdt_efi_pmem_setup(void *fdt); + #endif /* _LINUX_EFI_H */ diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 04b2efc4a3b..1050ed1f952 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -5,6 +5,7 @@ #define LOG_CATEGORY LOGC_EFI +#include #include #include #include @@ -19,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -680,3 +683,52 @@ out: return ret; } + +static int add_blkmap_pmem_nodes(void *fdt, struct blkmap *bm) +{ + int ret; + u32 size; + ulong addr; + efi_status_t status; + struct blkmap_mem *bmm; + struct blkmap_slice *bms; + struct blk_desc *bd = dev_get_uclass_plat(bm->blk); + + list_for_each_entry(bms, &bm->slices, node) { + if (bms->type != BLKMAP_SLICE_MEM) + continue; + + bmm = container_of(bms, struct blkmap_mem, slice); + + addr = (ulong)(uintptr_t)bmm->addr; + size = (u32)bms->blkcnt << bd->log2blksz; + + ret = fdt_fixup_pmem_region(fdt, addr, size); + if (ret) + return ret; + + status = efi_remove_memory_map(addr, size, + EFI_CONVENTIONAL_MEMORY); + if (status != EFI_SUCCESS) + return -1; + } + + return 0; +} + +int fdt_efi_pmem_setup(void *fdt) +{ + int ret; + struct udevice *dev; + struct uclass *uc; + struct blkmap *bm; + + uclass_id_foreach_dev(UCLASS_BLKMAP, dev, uc) { + bm = dev_get_plat(dev); + ret = add_blkmap_pmem_nodes(fdt, bm); + if (ret) + return ret; + } + + return 0; +}