From 076279854381bfc21cec460e3262a9e1cbbd60d3 Mon Sep 17 00:00:00 2001 From: "Zheng, Gen" Date: Fri, 30 Mar 2018 12:32:38 +0800 Subject: [PATCH] UEFI: cleanup functions in boot.c file Remove the useless function named get_path(). Remove the useless function named print_ch(). Remove the useless function named isspace(). Move the function memory_map() from boot.c to malloc.c Signed-off-by: Zheng, Gen --- bsp/uefi/efi/boot.c | 128 ------------------------------------------ bsp/uefi/efi/malloc.c | 57 +++++++++++++++++++ 2 files changed, 57 insertions(+), 128 deletions(-) diff --git a/bsp/uefi/efi/boot.c b/bsp/uefi/efi/boot.c index dc9f1f83e..1fad3e01b 100644 --- a/bsp/uefi/efi/boot.c +++ b/bsp/uefi/efi/boot.c @@ -41,84 +41,6 @@ EFI_SYSTEM_TABLE *sys_table; EFI_BOOT_SERVICES *boot; EFI_RUNTIME_SERVICES *runtime; -/** - * memory_map - Allocate and fill out an array of memory descriptors - * @map_buf: buffer containing the memory map - * @map_size: size of the buffer containing the memory map - * @map_key: key for the current memory map - * @desc_size: size of the desc - * @desc_version: memory descriptor version - * - * On success, @map_size contains the size of the memory map pointed - * to by @map_buf and @map_key, @desc_size and @desc_version are - * updated. - */ -EFI_STATUS -memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size, - UINTN *map_key, UINTN *desc_size, UINT32 *desc_version) -{ - EFI_STATUS err; - - *map_size = sizeof(**map_buf) * 31; -get_map: - - /* - * Because we're about to allocate memory, we may - * potentially create a new memory descriptor, thereby - * increasing the size of the memory map. So increase - * the buffer size by the size of one memory - * descriptor, just in case. - */ - *map_size += sizeof(**map_buf); - - err = allocate_pool(EfiLoaderData, *map_size, - (void **)map_buf); - if (err != EFI_SUCCESS) { - Print(L"Failed to allocate pool for memory map"); - goto failed; - } - - err = get_memory_map(map_size, *map_buf, map_key, - desc_size, desc_version); - if (err != EFI_SUCCESS) { - if (err == EFI_BUFFER_TOO_SMALL) { - /* - * 'map_size' has been updated to reflect the - * required size of a map buffer. - */ - free_pool((void *)*map_buf); - goto get_map; - } - - Print(L"Failed to get memory map"); - goto failed; - } - -failed: - return err; -} - -static inline BOOLEAN isspace(CHAR8 ch) -{ - return ((unsigned char)ch <= ' '); -} - -#if 0 -static void print_ch(char *str) -{ - int j; - CHAR16 *buf; - int len = strlen(str); - - buf = malloc((strlen(str) + 1)* 2); - for (j=0; jFilePath); - for (i = 0; i < StrLen(pathstr); i++) { - if (pathstr[i] == '/') - pathstr[i] = '\\'; - } - - pathlen = StrLen(pathstr); - - if (name[0] == '\\') { - *path = FileDevicePath(info->DeviceHandle, name); - goto out; - } - - for (i=pathlen - 1; i > 0; i--) { - if (pathstr[i] == '\\') break; - } - pathstr[i] = '\0'; - - pathlen = StrLen(pathstr); - - pathlen++; - pathname = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16)); - if (!pathname) { - Print(L"Failed to allocate memory for pathname\n"); - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } - StrCpy(pathname, pathstr); - StrCat(pathname, L"\\"); - StrCat(pathname, name); - - *path = FileDevicePath(info->DeviceHandle, pathname); - -out: - FreePool(pathstr); - return efi_status; -} - static EFI_STATUS switch_to_guest_mode(EFI_HANDLE image) { diff --git a/bsp/uefi/efi/malloc.c b/bsp/uefi/efi/malloc.c index 5c3297de8..6e90bfd81 100644 --- a/bsp/uefi/efi/malloc.c +++ b/bsp/uefi/efi/malloc.c @@ -36,6 +36,63 @@ #include "efilinux.h" #include "stdlib.h" +/** + * memory_map - Allocate and fill out an array of memory descriptors + * @map_buf: buffer containing the memory map + * @map_size: size of the buffer containing the memory map + * @map_key: key for the current memory map + * @desc_size: size of the desc + * @desc_version: memory descriptor version + * + * On success, @map_size contains the size of the memory map pointed + * to by @map_buf and @map_key, @desc_size and @desc_version are + * updated. + */ +EFI_STATUS +memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size, + UINTN *map_key, UINTN *desc_size, UINT32 *desc_version) +{ + EFI_STATUS err; + + *map_size = sizeof(**map_buf) * 31; +get_map: + + /* + * Because we're about to allocate memory, we may + * potentially create a new memory descriptor, thereby + * increasing the size of the memory map. So increase + * the buffer size by the size of one memory + * descriptor, just in case. + */ + *map_size += sizeof(**map_buf); + + err = allocate_pool(EfiLoaderData, *map_size, + (void **)map_buf); + if (err != EFI_SUCCESS) { + Print(L"Failed to allocate pool for memory map"); + goto failed; + } + + err = get_memory_map(map_size, *map_buf, map_key, + desc_size, desc_version); + if (err != EFI_SUCCESS) { + if (err == EFI_BUFFER_TOO_SMALL) { + /* + * 'map_size' has been updated to reflect the + * required size of a map buffer. + */ + free_pool((void *)*map_buf); + goto get_map; + } + + Print(L"Failed to get memory map"); + goto failed; + } + +failed: + return err; +} + /** * emalloc - Allocate memory with a strict alignment requirement * @size: size in bytes of the requested allocation