boot1.efi: use malloc family from libsa

The zfs reader development did reach to the point where linking boot1,
we will get errors about duplicate symbols Malloc, Free, Calloc.

We can just use libsa version, just as loader.efi does. The only concern is,
libsa zalloc is using fixed size heap region, I did pick 64MB as other
stage instances are using, but this size is likely not optimal. In any case,
with limited memory setups, we should boot loader.efi directly.

Sponsored by:	Netflix, Klara Inc.
This commit is contained in:
Toomas Soome 2020-06-30 21:48:58 +00:00
parent ebc22d0495
commit 12c470af75
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=362812

View File

@ -53,42 +53,8 @@ static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
/*
* Provide Malloc / Free / Calloc backed by EFIs AllocatePool / FreePool which ensures
* memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from
* EFI methods.
*/
void *
Malloc(size_t len, const char *file __unused, int line __unused)
{
void *out;
if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
return (out);
return (NULL);
}
void
Free(void *buf, const char *file __unused, int line __unused)
{
if (buf != NULL)
(void)BS->FreePool(buf);
}
void *
Calloc(size_t n1, size_t n2, const char *file, int line)
{
size_t bytes;
void *res;
bytes = n1 * n2;
if ((res = Malloc(bytes, file, line)) != NULL)
bzero(res, bytes);
return (res);
}
static EFI_PHYSICAL_ADDRESS heap;
static UINTN heapsize;
/*
* try_boot only returns if it fails to load the loader. If it succeeds
@ -201,6 +167,18 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
BS = ST->BootServices;
RS = ST->RuntimeServices;
heapsize = 64 * 1024 * 1024;
status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(heapsize), &heap);
if (status != EFI_SUCCESS) {
ST->ConOut->OutputString(ST->ConOut,
__DECONST(CHAR16 *,
L"Failed to allocate memory for heap.\r\n"));
BS->Exit(IH, status, 0, NULL);
}
setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize));
/* Set up the console, so printf works. */
status = BS->LocateProtocol(&ConsoleControlGUID, NULL,
(VOID **)&ConsoleControl);
@ -296,6 +274,8 @@ add_device(dev_info_t **devinfop, dev_info_t *devinfo)
void
efi_exit(EFI_STATUS s)
{
BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
BS->Exit(IH, s, 0, NULL);
}