From patchwork Tue Dec 3 16:36:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846964 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp595584wrr; Tue, 3 Dec 2024 08:36:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUlW7Ti4Gmuh/5vyqEa966luKYPn+5f7dF6UNtNan1psYqGBqIIv3HeqNMvydM7wHzKxpOXeQ==@linaro.org X-Google-Smtp-Source: AGHT+IG638UoCURdBUPzH0bPYo7gu1dyN/pnJBj69sevZf+o1iVkaF0rNNndJpi+Bj59AtsOABfD X-Received: by 2002:a17:906:3094:b0:aa1:f9dc:f9bf with SMTP id a640c23a62f3a-aa5f7ca9faemr219495866b.10.1733243788079; Tue, 03 Dec 2024 08:36:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733243788; cv=none; d=google.com; s=arc-20240605; b=N/MCqp4StU2pSnuTpHeyDwLZEuyWluE+zQL2wnHOnzVwfK0VlTed0X3Hzlj2Z6dSuo sMpBJP2K5xp5FjRRu8+0vYQIoK3E0jgwlxpPuCiR60tyR1DnqyxYhHlaWecxiRr8PEZp n/6ny30UVD/ZXlqd9qUrGaVt8vtqvBaJkQfv2/04/vmF+P5LSkEY+iv3/k+1mPtroRFt zYwLENqq3K9WSdBqbtB4o3UcQm1jJLmjq0iJQBUZhtMOBx8lZ8r8BpVbn0jyMnX8VNUd PskGZrtSC83CG+BIBA8WxPwWnm/EsIEZZ688Gep0UXo4eD12s5QLxtE9hQ1JZSkjWs7k RkiQ== 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=tXhXiVey6oODYtbZQNwf8Oa/teP3I6sBDm9cZK6Ud/A=; fh=rPmMTArAbwoOFNVFb2co+289VhVVNzBHoPR9c3uaLKo=; b=H57QWLajdUgBmpEfpztUpdkUqhktPUIWHCINnHflbfo/dFy6SXUJOnCGXzx9hf0fNa nlcmzCzvkdf5im7yBbO7of2e1MhavZ5CHyn66+NK2U4hO3GrCgR0FCn6QvrTVvp1JY0F mdKNi3F5T913FDQUP643C1zKY11VxuQ/6TF8NNhfQflyDcYioxd/neeHAmAhkW5p7/6X l6ZKqkMtfl0xfaUqDsY1Ra04jGXsbnIb/qRg1TIKavmaZBtjfDEkeBtBlSp8cNeMnUzp jPhybgxXjraYQ8hD6JEbLNKk53ocMIAcI1jnmzSJTL3sWHb9DeoILxyijNDOdz99G6v4 J2gA==; 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-aa599943741si841534066b.701.2024.12.03.08.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 08:36:28 -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 B387B8964B; Tue, 3 Dec 2024 17:36:24 +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 E248C89588; Tue, 3 Dec 2024 17:36:22 +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_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_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 03EE2893A9 for ; Tue, 3 Dec 2024 17:36:20 +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 69A72FEC; Tue, 3 Dec 2024 08:36:47 -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 1DCB03F71E; Tue, 3 Dec 2024 08:36:16 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Anton Antonov , Tom Rini , Sughosh Ganu Subject: [PATCH v2 1/4] fdt: add support for adding pmem nodes Date: Tue, 3 Dec 2024 22:06:02 +0530 Message-Id: <20241203163605.1482152-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203163605.1482152-1-sughosh.ganu@linaro.org> References: <20241203163605.1482152-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 V1: None boot/fdt_support.c | 41 +++++++++++++++++++++++++++++++++++++++-- include/fdt_support.h | 13 +++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 2392027d40b..61f725389b7 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -463,7 +464,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 */ @@ -491,7 +491,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 @@ -2221,3 +2221,40 @@ 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 needs at 2MB alignment\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 9447a64e060..980feb27d27 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -474,4 +474,17 @@ 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 injects 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 Tue Dec 3 16:36:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846965 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp595662wrr; Tue, 3 Dec 2024 08:36:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVYhYNhVaXdq2FYBrZP/4PP/ocrz2A6vgUPvsQWzsA72aGm0erki6j0n4/tVv8NnTeWfngxLA==@linaro.org X-Google-Smtp-Source: AGHT+IG34Ds//Exbqi/j7XgPfFWwAkZuhI5Xr1bbJIjP7NMIaIsDkJfXzlN59E5iJU68kCF586up X-Received: by 2002:a17:906:328a:b0:a9a:14fc:9868 with SMTP id a640c23a62f3a-aa5f7cce47amr315692366b.4.1733243796013; Tue, 03 Dec 2024 08:36:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733243795; cv=none; d=google.com; s=arc-20240605; b=Tyqz5qhai+nlhXPc8nJ2VJ4YlDtEv1tqH8tien/mDkB8GSJwaACPVR4fUuq3lZ32kq iuMy1OPrV8MSbJNgSY/5Tt0sXTetG1gcjg5XFlFu5uJFicggN/e8CaIaw60nPoCKiowK KWArMC2bbTR/+YSvT4A54D780dTXfqy1/9sCd7KGa6LLFLrmzu769C/aZEXilGizCMhA Ki5rP6M50II5HMhYr3HhAT9lQieqiRrctbf3SJdWGm/zZyPCPGpvcvYnK135M7L3GD5t 8I7KGFZOMyzp+Bq0wDgoZnNUVIOSB87E21A3LK1KNCRjgGhp2RjDiZkA8L4AbpUd0o/H CPpA== 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=zTfDQZzfogJ2k43ET3KCSdNgRkUObIkongmLYCrkI+M=; fh=rPmMTArAbwoOFNVFb2co+289VhVVNzBHoPR9c3uaLKo=; b=LcZM0gj8uu9acEqnuyzePfaPkUGo69xBDknmGxLDzmmRTV4IXSlAALFqfg64kbYE3A /RlYDr1OREbiZf2XdxaEAgSdIgKZ9R3IMsOsU+8fHLHyCJO0qzkEsFboLq58Y2f1+hKd qH4UZX+IzdB1QCiLru7IhjNCOuNidaZC1Y3nb7IRI7omSeUoGyi7evIHAGxXZPX8DP4c 0iz//f48tzVIbO8TMXKr4xN5b65MwGB45y+erhEcvCBzqt4WJToMi3dVLPblr0Ln3BDp DgLV8mLQqTrS0jsrRNtGu3Zn1p/9qx169KgjVXt+dngpB6vc7UZdUke08MBtrnCkD4i9 xoXw==; 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-aa5999bc129si921996966b.876.2024.12.03.08.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 08:36:35 -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 143DE893DE; Tue, 3 Dec 2024 17:36:26 +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 3CB5F89538; Tue, 3 Dec 2024 17:36:25 +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_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_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 D6C1B89538 for ; Tue, 3 Dec 2024 17:36:22 +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 4A6CC143D; Tue, 3 Dec 2024 08:36:50 -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 F2B223F71E; Tue, 3 Dec 2024 08:36:19 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Anton Antonov , Tom Rini , Sughosh Ganu Subject: [PATCH v2 2/4] efi_loader: add a function to remove memory from the EFI map Date: Tue, 3 Dec 2024 22:06:03 +0530 Message-Id: <20241203163605.1482152-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203163605.1482152-1-sughosh.ganu@linaro.org> References: <20241203163605.1482152-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 Signed-off-by: Sughosh Ganu --- Changes since V1: * s/ommit/remove in the commit message * s/rfom/from in the commit message * Add a period at the end of the sentence in the commit message 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 39809eac1bc..24e40799eee 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -786,7 +786,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 @@ -794,11 +794,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 edd7da7d8c6..fe0e570059d 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 14b9b8466ff..d1d7e64b339 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -464,11 +464,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 Tue Dec 3 16:36:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846966 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp595729wrr; Tue, 3 Dec 2024 08:36:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhVRvpJVRxaRzm4qMuKWnNw14l6IwRaSz8D66lWCh7YwNwUm66PcT8FCiziASJtcEP612XOQ==@linaro.org X-Google-Smtp-Source: AGHT+IFr/0kJ+Kc4p0VNekq8wajJsgo1Ozrxvy91MWr2pUTLO6Kgtd2aLzmBfzhETwwnI5KWV4Zz X-Received: by 2002:a05:6402:27c6:b0:5d0:f6ed:4cb0 with SMTP id 4fb4d7f45d1cf-5d10cb4f110mr2782173a12.1.1733243803815; Tue, 03 Dec 2024 08:36:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733243803; cv=none; d=google.com; s=arc-20240605; b=H7a9jNMuNRZ/O62gtEoFAdHe6GBTikZGSRvK2pnVoZHELojgigqEzfee4jUe84kmlv 7Omj2Yn8GgR4EOBKOGHR9RJPy8/LwalD+EsIVKzdeU6h0bNY+pF1iBfEQvcbS/6pUzYh lkqjZkfvzhgsmo2Erqy1+StVN1B8Ums82CT4D7y2asGCejSCnGZihMpk2a4uA8Bxh9E5 TmTy5pI8zlv0jhFK7stzUKxiDYhEDouUBqrVDip1kciaADNaonWL/Fjz9T+0/G5sRV+f 7fxAwxo3mlBxxy9GnjlpAlqPCL/g0uBC3crgSnTZLSCWASqXAYGmeEO5M2wbagXyVtFf Nbzg== 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=R8h4+2Y4eSwEWKvG99XvMP+TcMX7RjLPwHwlojRAodg=; fh=rPmMTArAbwoOFNVFb2co+289VhVVNzBHoPR9c3uaLKo=; b=a7i/jL2I39655E2rw2rcX8JOah1VcY3/75BjH26GxPN6cWdiE0l9T84IocN/SBkXwS ayvwQlvulE/oTyzRX5bU6acWGE2pN7FZ3QKeWIo6Lwp5BmF7qEHOHszil3kA8QoPgVuL kYts5IBpw3Ehswz88BMFk9j4T2iMFsWb752QByNdKbG4TCr7o2pT5I4JGUxqxzX3H+Ur 1YftLyaJenD0FamfI4wqr1BLFnqymKXnXiPtYvH/uOXWq4EMP8rVUZk5D4eaip6EOpe2 lSC6SeaUrIVkhdCvuLFXTl4pG2A5rftP1DZ3kuP54+P/+7jPi2nPFfvNuA2SwIxK40pH bOSQ==; 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-5d0c6818029si6483523a12.186.2024.12.03.08.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 08:36:43 -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 73A6B89588; Tue, 3 Dec 2024 17:36:29 +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 0B966893A9; Tue, 3 Dec 2024 17:36:28 +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_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_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 B729389538 for ; Tue, 3 Dec 2024 17:36:25 +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 2B183FEC; Tue, 3 Dec 2024 08:36:53 -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 D35AD3F71E; Tue, 3 Dec 2024 08:36:22 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Anton Antonov , Tom Rini , Sughosh Ganu Subject: [PATCH v2 3/4] efi_loader: preserve installer images in pmem Date: Tue, 3 Dec 2024 22:06:04 +0530 Message-Id: <20241203163605.1482152-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203163605.1482152-1-sughosh.ganu@linaro.org> References: <20241203163605.1482152-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 Reviewed-by: Heinrich Schuchardt --- Changes since V1: 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 8c51a6ef2ed..b906e53e26e 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 Tue Dec 3 16:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846967 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp595803wrr; Tue, 3 Dec 2024 08:36:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVDpRBeZ7EO7H7zYBOcs4vrwbLG6Q2Hm89t2L3vQEP/CfGsImQrC63DTkCCcon4NRFcYYDwqA==@linaro.org X-Google-Smtp-Source: AGHT+IFWl/NyjYdJYJK9JZMbwt7BDSGJIghEyyUyuH98Z4tlaSXot8pL+gMs+oE7ASYaOskIc/5M X-Received: by 2002:a05:6512:1387:b0:53d:d0f0:ad0d with SMTP id 2adb3069b0e04-53e12a21851mr1803655e87.46.1733243812024; Tue, 03 Dec 2024 08:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733243811; cv=none; d=google.com; s=arc-20240605; b=Lb2aRTZYPzKGuxzsbMrmvgCL+iZuPWTAxbmgIgBqTz5q9xqcrzaKtdYP+fUkFWr4ls xrSRHoMO30YLbCJr1AcHtGDJfFRdBxiTnr77dKa839omOxtSplVbL63HW8zLKiEQc61u k7qsumh6mRVlBvkdvnVHweL0B6lw8CFxjiayWdcpjkM85s55r4exgB/c+0l7yy1YniGk L0/uxJdzwIkL/1Lyc0bWOvzvShkoKbhQZKdYWX9uls8k8o4+RiU64M3WMqeYq3Q/76Qg FEp9pGdmZowATXwJjLEfYZBppnM8BvotovRlkejZQrPW1gu9ABpl/EOx+fKimChoqaP6 vSVw== 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=Ecda4JxLib6wLH7IRs6FUKkU4y5/3veBJDyjIucVhBE=; fh=rPmMTArAbwoOFNVFb2co+289VhVVNzBHoPR9c3uaLKo=; b=b3lzZqC8i/lfeG0FSn1M0b/10m1P8V958jnFwy81zYh/TKjkap+CS71sR6oTnVBYoB 42PF3LEZO0bE4BaFHi64PcclQuMPPKS5DRU6bKDIgbNfczLCSlcqWtupPtoniOtTIqOi lHLmquqXYSP8EujO4NKG56swlDJ+D/jHIma7Rj9R43YiXojAIY58Oc+iDUir2Bde3T7B k/a7tb956Bw8x0ryJAL8H7jd/Z3H7fepEJUHXEbzBrfuhYbcRm8YGgYVKsbz5PhYG2+F +9GEQrroYOyOqLvspC5/C2akXPlJZurDyp4m7JStxwCT81OwgxXBuSTZzUfPDN1Lo74N S9Dg==; 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-aa5998e5f10si893056166b.370.2024.12.03.08.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 08:36:51 -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 C8BC889677; Tue, 3 Dec 2024 17:36:32 +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 E4D1489651; Tue, 3 Dec 2024 17:36: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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_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 A2AEA893A9 for ; Tue, 3 Dec 2024 17:36:28 +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 0DC70143D; Tue, 3 Dec 2024 08:36:56 -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 B3EDC3F71E; Tue, 3 Dec 2024 08:36:25 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Anton Antonov , Tom Rini , Sughosh Ganu Subject: [PATCH v2 4/4] efi: add helper functions to insert pmem node for DT fixup Date: Tue, 3 Dec 2024 22:06:05 +0530 Message-Id: <20241203163605.1482152-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203163605.1482152-1-sughosh.ganu@linaro.org> References: <20241203163605.1482152-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 reserved in the devicetree as persistent memory (pmem). Add helper functions which add this pmem node when the EFI_DT_FIXUP protocol's fixup callback is invoked. Signed-off-by: Sughosh Ganu --- Changes since V1: * Use log_err() to print the error message in image_setup_libfdt() * Remove "ERROR:" from the error print in image_setup_libfdt() boot/image-fdt.c | 9 +++++++++ include/efi_loader.h | 17 +++++++++++++++++ lib/efi_loader/efi_bootmgr.c | 21 +++++++++++++++++++++ lib/efi_loader/efi_helper.c | 12 ++++++++++++ 4 files changed, 59 insertions(+) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 3d5b6f9e2dc..de479d3ffa0 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -648,6 +649,14 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb) if (!ft_verify_fdt(blob)) goto err; + if (CONFIG_IS_ENABLED(EFI_HTTP_BOOT)) { + fdt_ret = fdt_efi_pmem_setup(blob); + if (fdt_ret) { + log_err("HTTP boot pmem 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/include/efi_loader.h b/include/efi_loader.h index 24e40799eee..87b9a6e4da0 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -748,6 +748,15 @@ bool efi_varname_is_load_option(u16 *var_name16, int *index); efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, efi_guid_t *guid); +/** + * fdt_efi_pmem_setup() - Setup the pmem node in the devicetree + * + * @fdt: Pointer to the devicetree + * + * Return: 0 on success, negative on failure + */ +int fdt_efi_pmem_setup(void *fdt); + /** * efi_size_in_pages() - convert size in bytes to size in pages * @@ -964,6 +973,14 @@ efi_status_t efi_set_load_options(efi_handle_t handle, void *load_options); efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options); +/** + * efi_bootmgr_pmem_setup() - Put a pmem node for UEFI HTTP installers + * + * @fdt: Pointer to the DT blob + * Return: status code + */ +efi_status_t efi_bootmgr_pmem_setup(void *fdt); + /** * struct efi_image_regions - A list of memory regions * diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index b906e53e26e..db4eb6a7376 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -41,6 +41,8 @@ struct uridp_context { efi_handle_t mem_handle; }; +static struct uridp_context *uctx; + const efi_guid_t efi_guid_bootmenu_auto_generated = EFICONFIG_AUTO_GENERATED_ENTRY_GUID; @@ -427,6 +429,7 @@ static efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx) efi_free_pool(ctx->loaded_dp); free(ctx); + uctx = NULL; return ret == EFI_SUCCESS ? ret2 : ret; } @@ -447,6 +450,23 @@ static void EFIAPI efi_bootmgr_http_return(struct efi_event *event, EFI_EXIT(ret); } +/** + * efi_bootmgr_pmem_setup() - Put a pmem node for UEFI HTTP installers + * + * @fdt: Pointer to the DT blob + * Return: status code + */ +efi_status_t efi_bootmgr_pmem_setup(void *fdt) +{ + if (!uctx) { + log_warning("No EFI HTTP boot context found\n"); + return EFI_SUCCESS; + } + + return !fdt_fixup_pmem_region(fdt, uctx->image_addr, uctx->image_size) ? + EFI_SUCCESS : EFI_INVALID_PARAMETER; +} + /** * try_load_from_uri_path() - Handle the URI device path * @@ -476,6 +496,7 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, if (!ctx) return EFI_OUT_OF_RESOURCES; + uctx = ctx; s = env_get("loadaddr"); if (!s) { log_err("Error: loadaddr is not set\n"); diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index bf96f61d3d0..6fae37ad617 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -313,6 +313,18 @@ int efi_unlink_dev(efi_handle_t handle) return 0; } +/** + * fdt_efi_pmem_setup() - Setup the pmem node in the devicetree + * + * @fdt: Pointer to the devicetree + * + * Return: 0 on success, negative on failure + */ +int fdt_efi_pmem_setup(void *fdt) +{ + return efi_bootmgr_pmem_setup(fdt) == EFI_SUCCESS ? 0 : -1; +} + static int u16_tohex(u16 c) { if (c >= '0' && c <= '9')