Use the loader.efi conventions for the various EFI tables.

Sponsored by: Netflix
This commit is contained in:
Warner Losh 2017-08-26 18:29:43 +00:00
parent 194748f6a3
commit 0414cb13ec
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=322932
4 changed files with 35 additions and 36 deletions

View File

@ -47,9 +47,10 @@ static const boot_module_t *boot_modules[] =
/* The initial number of handles used to query EFI for partitions. */
#define NUM_HANDLES_INIT 24
EFI_SYSTEM_TABLE *systab;
EFI_BOOT_SERVICES *bs;
static EFI_HANDLE *image;
EFI_HANDLE IH;
EFI_SYSTEM_TABLE *ST;
EFI_BOOT_SERVICES *BS;
EFI_RUNTIME_SERVICES *RS;
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
@ -66,7 +67,7 @@ Malloc(size_t len, const char *file __unused, int line __unused)
{
void *out;
if (bs->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
return (out);
return (NULL);
@ -76,7 +77,7 @@ void
Free(void *buf, const char *file __unused, int line __unused)
{
if (buf != NULL)
(void)bs->FreePool(buf);
(void)BS->FreePool(buf);
}
/*
@ -398,14 +399,14 @@ try_boot(void)
buf = NULL;
}
if ((status = bs->LoadImage(TRUE, image, devpath_last(dev->devpath),
if ((status = BS->LoadImage(TRUE, IH, devpath_last(dev->devpath),
loaderbuf, loadersize, &loaderhandle)) != EFI_SUCCESS) {
printf("Failed to load image provided by %s, size: %zu, (%lu)\n",
mod->name, loadersize, EFI_ERROR_CODE(status));
goto errout;
}
if ((status = bs->HandleProtocol(loaderhandle, &LoadedImageGUID,
if ((status = BS->HandleProtocol(loaderhandle, &LoadedImageGUID,
(VOID**)&loaded_image)) != EFI_SUCCESS) {
printf("Failed to query LoadedImage provided by %s (%lu)\n",
mod->name, EFI_ERROR_CODE(status));
@ -431,7 +432,7 @@ try_boot(void)
DSTALL(1000000);
DPRINTF(".\n");
if ((status = bs->StartImage(loaderhandle, NULL, NULL)) !=
if ((status = BS->StartImage(loaderhandle, NULL, NULL)) !=
EFI_SUCCESS) {
printf("Failed to start image provided by %s (%lu)\n",
mod->name, EFI_ERROR_CODE(status));
@ -465,7 +466,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred)
UINTN i;
/* Figure out if we're dealing with an actual partition. */
status = bs->HandleProtocol(h, &DevicePathGUID, (void **)&devpath);
status = BS->HandleProtocol(h, &DevicePathGUID, (void **)&devpath);
if (status == EFI_UNSUPPORTED)
return (status);
@ -477,7 +478,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred)
DPRINTF("probing: %s\n", devpath_str(devpath));
status = bs->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
status = BS->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
if (status == EFI_UNSUPPORTED)
return (status);
@ -494,7 +495,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred)
/* Run through each module, see if it can load this partition */
for (i = 0; i < NUM_BOOT_MODULES; i++) {
if ((status = bs->AllocatePool(EfiLoaderData,
if ((status = BS->AllocatePool(EfiLoaderData,
sizeof(*devinfo), (void **)&devinfo)) !=
EFI_SUCCESS) {
DPRINTF("\nFailed to allocate devinfo (%lu)\n",
@ -511,7 +512,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred)
status = boot_modules[i]->probe(devinfo);
if (status == EFI_SUCCESS)
return (EFI_SUCCESS);
(void)bs->FreePool(devinfo);
(void)BS->FreePool(devinfo);
}
return (EFI_UNSUPPORTED);
@ -565,12 +566,13 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
UINTN i, max_dim, best_mode, cols, rows, hsize, nhandles;
/* Basic initialization*/
systab = Xsystab;
image = Ximage;
bs = Xsystab->BootServices;
ST = Xsystab;
IH = Ximage;
BS = ST->BootServices;
RS = ST->RuntimeServices;
/* Set up the console, so printf works. */
status = bs->LocateProtocol(&ConsoleControlGUID, NULL,
status = BS->LocateProtocol(&ConsoleControlGUID, NULL,
(VOID **)&ConsoleControl);
if (status == EFI_SUCCESS)
(void)ConsoleControl->SetMode(ConsoleControl,
@ -578,7 +580,7 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
/*
* Reset the console and find the best text mode.
*/
conout = systab->ConOut;
conout = ST->ConOut;
conout->Reset(conout, TRUE);
max_dim = best_mode = 0;
for (i = 0; ; i++) {
@ -607,24 +609,24 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
/* Get all the device handles */
hsize = (UINTN)NUM_HANDLES_INIT * sizeof(EFI_HANDLE);
if ((status = bs->AllocatePool(EfiLoaderData, hsize, (void **)&handles))
if ((status = BS->AllocatePool(EfiLoaderData, hsize, (void **)&handles))
!= EFI_SUCCESS)
panic("Failed to allocate %d handles (%lu)", NUM_HANDLES_INIT,
EFI_ERROR_CODE(status));
status = bs->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL,
status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL,
&hsize, handles);
switch (status) {
case EFI_SUCCESS:
break;
case EFI_BUFFER_TOO_SMALL:
(void)bs->FreePool(handles);
if ((status = bs->AllocatePool(EfiLoaderData, hsize,
(void)BS->FreePool(handles);
if ((status = BS->AllocatePool(EfiLoaderData, hsize,
(void **)&handles)) != EFI_SUCCESS) {
panic("Failed to allocate %zu handles (%lu)", hsize /
sizeof(*handles), EFI_ERROR_CODE(status));
}
status = bs->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
NULL, &hsize, handles);
if (status != EFI_SUCCESS)
panic("Failed to get device handles (%lu)\n",
@ -641,10 +643,10 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
DPRINTF("\n");
/* Determine the devpath of our image so we can prefer it. */
status = bs->HandleProtocol(image, &LoadedImageGUID, (VOID**)&img);
status = BS->HandleProtocol(IH, &LoadedImageGUID, (VOID**)&img);
imgpath = NULL;
if (status == EFI_SUCCESS) {
status = bs->HandleProtocol(img->DeviceHandle, &DevicePathGUID,
status = BS->HandleProtocol(img->DeviceHandle, &DevicePathGUID,
(void **)&imgpath);
if (status != EFI_SUCCESS)
DPRINTF("Failed to get image DevicePath (%lu)\n",
@ -709,9 +711,9 @@ putchar(int c)
if (c == '\n') {
buf[0] = '\r';
buf[1] = 0;
systab->ConOut->OutputString(systab->ConOut, buf);
ST->ConOut->OutputString(ST->ConOut, buf);
}
buf[0] = c;
buf[1] = 0;
systab->ConOut->OutputString(systab->ConOut, buf);
ST->ConOut->OutputString(ST->ConOut, buf);
}

View File

@ -37,7 +37,7 @@
#ifdef EFI_DEBUG
#define DPRINTF(fmt, args...) printf(fmt, ##args)
#define DSTALL(d) bs->Stall(d)
#define DSTALL(d) BS->Stall(d)
#else
#define DPRINTF(fmt, ...) {}
#define DSTALL(d) {}
@ -107,9 +107,6 @@ extern const boot_module_t zfs_module;
extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
extern int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap);
extern EFI_SYSTEM_TABLE *systab;
extern EFI_BOOT_SERVICES *bs;
extern int devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath);
extern char *devpath_str(EFI_DEVICE_PATH *devpath);
#endif

View File

@ -118,7 +118,7 @@ load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
return (EFI_INVALID_PARAMETER);
}
if ((status = bs->AllocatePool(EfiLoaderData, size, &buf)) !=
if ((status = BS->AllocatePool(EfiLoaderData, size, &buf)) !=
EFI_SUCCESS) {
printf("Failed to allocate read buffer %zu for '%s' (%lu)\n",
size, filepath, EFI_ERROR_CODE(status));
@ -129,7 +129,7 @@ load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
if ((size_t)read != size) {
printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
size);
(void)bs->FreePool(buf);
(void)BS->FreePool(buf);
return (EFI_INVALID_PARAMETER);
}

View File

@ -118,7 +118,7 @@ probe(dev_info_t *dev)
EFI_STATUS status;
/* ZFS consumes the dev on success so we need a copy. */
if ((status = bs->AllocatePool(EfiLoaderData, sizeof(*dev),
if ((status = BS->AllocatePool(EfiLoaderData, sizeof(*dev),
(void**)&tdev)) != EFI_SUCCESS) {
DPRINTF("Failed to allocate tdev (%lu)\n",
EFI_ERROR_CODE(status));
@ -127,7 +127,7 @@ probe(dev_info_t *dev)
memcpy(tdev, dev, sizeof(*dev));
if (vdev_probe(vdev_read, tdev, &spa) != 0) {
(void)bs->FreePool(tdev);
(void)BS->FreePool(tdev);
return (EFI_UNSUPPORTED);
}
@ -180,7 +180,7 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize)
return (EFI_INVALID_PARAMETER);
}
if ((status = bs->AllocatePool(EfiLoaderData, (UINTN)st.st_size, &buf))
if ((status = BS->AllocatePool(EfiLoaderData, (UINTN)st.st_size, &buf))
!= EFI_SUCCESS) {
printf("Failed to allocate load buffer %jd for pool '%s' for '%s' "
"(%lu)\n", (intmax_t)st.st_size, spa->spa_name, filepath, EFI_ERROR_CODE(status));
@ -190,7 +190,7 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize)
if ((err = dnode_read(spa, &dn, 0, buf, st.st_size)) != 0) {
printf("Failed to read node from %s (%d)\n", spa->spa_name,
err);
(void)bs->FreePool(buf);
(void)BS->FreePool(buf);
return (EFI_INVALID_PARAMETER);
}