summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_memory.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-07-03 08:25:38 -0600
committerTom Rini <trini@konsulko.com>2025-07-03 08:25:38 -0600
commit218db7bdbd0ea115c166f8bf18e1292c588beb10 (patch)
treec724c584750b3f0d1d6e786bc9c0243557c847e3 /lib/efi_loader/efi_memory.c
parentc405bab7661dd60420e97a4edeb3162e9d7e02c5 (diff)
parent95732f2bf8700f9ec17983b419073b6a16b79aef (diff)
Merge tag 'efi-next-03072025' of https://source.denx.de/u-boot/custodians/u-boot-tpm into next
Sughosh added EFI HTTP(s) support into our eficonfig application. Up to now we could only enable that via our efidebug command. Users now get that option on the eficonfig menu. Javier implemented support for the EFI_PARTITION_INFO_PROTOCOL, to provide cached partition information for GPT partition types. The protocol describes legacy MBR partition types, but that's for backward compatibility and not implemented by this series. The protocol is needed by [0], an implementation of a UEFI based A/B boot protocol for the root filesystem. Paul added support for EFI_DEBUG_IMAGE_INFO_TABLE. This is part of the EFI spec and is defining a debug protocol that Google currently uses to debug their Generic Bootloader project [1][2], using EFI to load Android. Heinrich contributed a test EFI application for it as well. The efi_realloc() function he added will realloc any type of memory to BootServicesData, but keeping in mind the new protocol is the only consumer he will fix that on a followup patch. Finally another round of smatch fixes from Andrew cleans up coding errors. The CI https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/26935 seems happy [0] https://gitlab.com/CentOS/automotive/src/ukiboot [1] https://lpc.events/event/18/contributions/1704/attachments/1550/3231/Android%20Generic%20Boot%20Loader.pdf [2] https://source.android.com/docs/core/architecture/bootloader/generic-bootloader
Diffstat (limited to 'lib/efi_loader/efi_memory.c')
-rw-r--r--lib/efi_loader/efi_memory.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 0828a47da61..6dfc698a247 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -669,6 +669,64 @@ void *efi_alloc(size_t size)
}
/**
+ * efi_realloc() - reallocate boot services data pool memory
+ *
+ * Reallocate memory from pool for a new size and copy the data from old one.
+ *
+ * @ptr: pointer to old buffer
+ * @size: number of bytes to allocate
+ * Return: EFI status to indicate success or not
+ */
+efi_status_t efi_realloc(void **ptr, size_t size)
+{
+ efi_status_t ret;
+ void *new_ptr;
+ struct efi_pool_allocation *alloc;
+ u64 num_pages = efi_size_in_pages(size +
+ sizeof(struct efi_pool_allocation));
+ size_t old_size;
+
+ if (!*ptr) {
+ *ptr = efi_alloc(size);
+ if (*ptr)
+ return EFI_SUCCESS;
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ ret = efi_check_allocated((uintptr_t)*ptr, true);
+ if (ret != EFI_SUCCESS)
+ return ret;
+
+ alloc = container_of(*ptr, struct efi_pool_allocation, data);
+
+ /* Check that this memory was allocated by efi_allocate_pool() */
+ if (((uintptr_t)alloc & EFI_PAGE_MASK) ||
+ alloc->checksum != checksum(alloc)) {
+ printf("%s: illegal realloc 0x%p\n", __func__, *ptr);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ /* Don't realloc. The actual size in pages is the same. */
+ if (alloc->num_pages == num_pages)
+ return EFI_SUCCESS;
+
+ old_size = alloc->num_pages * EFI_PAGE_SIZE -
+ sizeof(struct efi_pool_allocation);
+
+ new_ptr = efi_alloc(size);
+
+ /* copy old data to new alloced buffer */
+ memcpy(new_ptr, *ptr, min(size, old_size));
+
+ /* free the old buffer */
+ efi_free_pool(*ptr);
+
+ *ptr = new_ptr;
+
+ return EFI_SUCCESS;
+}
+
+/**
* efi_free_pool() - free memory from pool
*
* @buffer: start of memory to be freed