summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2017-12-12 13:47:20 +0200
committerDan McDonald <danmcd@joyent.com>2018-01-10 09:31:38 -0500
commiteb9c32327f4caf584b309530acc3df1b67f1d286 (patch)
tree588b395cc5d0ae68120aa6ba4200a7f08d8e3519
parent1adc3ffcd976ec0a34010cc7db08037a14c3ea4c (diff)
downloadillumos-joyent-eb9c32327f4caf584b309530acc3df1b67f1d286.tar.gz
8925 boot1.efi: link with libefi
Reviewed by: C Fraire <cfraire@me.com> Reviewed by: Jason King <jason.king@joyent.com> Reviewed by: Yuri Pankov <yuripv@gmx.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/boot/sys/boot/efi/Makefile6
-rw-r--r--usr/src/boot/sys/boot/efi/boot1/Makefile7
-rw-r--r--usr/src/boot/sys/boot/efi/boot1/boot1.c57
-rw-r--r--usr/src/boot/sys/boot/efi/boot1/boot_module.h5
-rw-r--r--usr/src/boot/sys/boot/efi/boot1/ufs_module.c4
-rw-r--r--usr/src/boot/sys/boot/efi/boot1/zfs_module.c8
6 files changed, 44 insertions, 43 deletions
diff --git a/usr/src/boot/sys/boot/efi/Makefile b/usr/src/boot/sys/boot/efi/Makefile
index e22e8615e0..da61badebf 100644
--- a/usr/src/boot/sys/boot/efi/Makefile
+++ b/usr/src/boot/sys/boot/efi/Makefile
@@ -17,7 +17,7 @@
include $(SRC)/Makefile.master
-SUBDIRS = boot1 libefi loader
+SUBDIRS = libefi boot1 loader
#.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "arm"
#.if ${MK_FDT} != "no"
@@ -33,6 +33,10 @@ clean := TARGET = clean
clobber := TARGET = clobber
install := TARGET = install
+# boot1 and loader both link against libefi
+boot1: libefi
+loader: libefi
+
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET)
diff --git a/usr/src/boot/sys/boot/efi/boot1/Makefile b/usr/src/boot/sys/boot/efi/boot1/Makefile
index ac32e257c4..b027bdc845 100644
--- a/usr/src/boot/sys/boot/efi/boot1/Makefile
+++ b/usr/src/boot/sys/boot/efi/boot1/Makefile
@@ -66,6 +66,7 @@ all: boot1.efi
install: all $(ROOTBOOTFILES)
+LIBEFI= ../libefi/libefi.a
#
# Add libstand for the runtime functions used by the compiler - for example
# __aeabi_* (arm) or __divdi3 (i386).
@@ -73,8 +74,10 @@ install: all $(ROOTBOOTFILES)
#
LIBSTAND= ../../libstand/$(MACH64)/libstand.a
LIBZFSBOOT= ../../zfs/$(MACH64)/libzfsboot.a
-DPADD= ${LIBSTAND} ${LIBZFSBOOT}
-LDADD= -L../../zfs/$(MACH64) -lzfsboot -L../../libstand/$(MACH64) -lstand
+DPADD= $(LIBEFI) $(LIBZFSBOOT) $(LIBSTAND)
+LDADD= -L../libefi -lefi
+LDADD += -L../../zfs/$(MACH64) -lzfsboot
+LDADD += -L../../libstand/$(MACH64) -lstand
DPADD += ${LDSCRIPT}
diff --git a/usr/src/boot/sys/boot/efi/boot1/boot1.c b/usr/src/boot/sys/boot/efi/boot1/boot1.c
index 37529a9912..23d4c22b80 100644
--- a/usr/src/boot/sys/boot/efi/boot1/boot1.c
+++ b/usr/src/boot/sys/boot/efi/boot1/boot1.c
@@ -52,10 +52,6 @@ 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;
-
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
@@ -71,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);
@@ -81,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);
}
/*
@@ -403,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));
@@ -436,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));
@@ -470,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);
@@ -482,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);
@@ -499,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",
@@ -516,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);
@@ -569,12 +565,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 = Xsystab->BootServices;
+ RS = Xsystab->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,
@@ -582,7 +579,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++) {
@@ -611,24 +608,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",
@@ -645,10 +642,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",
@@ -713,11 +710,11 @@ 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);
}
int
@@ -727,10 +724,10 @@ getchar(void)
EFI_STATUS status;
UINTN junk;
- status = systab->ConIn->ReadKeyStroke(systab->ConIn, &key);
+ status = ST->ConIn->ReadKeyStroke(ST->ConIn, &key);
if (status == EFI_NOT_READY) {
- bs->WaitForEvent(1, &systab->ConIn->WaitForKey, &junk);
- status = systab->ConIn->ReadKeyStroke(systab->ConIn, &key);
+ BS->WaitForEvent(1, &ST->ConIn->WaitForKey, &junk);
+ status = ST->ConIn->ReadKeyStroke(ST->ConIn, &key);
}
return (key.UnicodeChar);
}
diff --git a/usr/src/boot/sys/boot/efi/boot1/boot_module.h b/usr/src/boot/sys/boot/efi/boot1/boot_module.h
index 0f1fc089c8..59d1a7ea4a 100644
--- a/usr/src/boot/sys/boot/efi/boot1/boot_module.h
+++ b/usr/src/boot/sys/boot/efi/boot1/boot_module.h
@@ -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) {}
@@ -106,9 +106,6 @@ extern const boot_module_t zfs_module;
/* Functions available to modules. */
extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
-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
diff --git a/usr/src/boot/sys/boot/efi/boot1/ufs_module.c b/usr/src/boot/sys/boot/efi/boot1/ufs_module.c
index 060c012ef9..571e9514de 100644
--- a/usr/src/boot/sys/boot/efi/boot1/ufs_module.c
+++ b/usr/src/boot/sys/boot/efi/boot1/ufs_module.c
@@ -116,7 +116,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));
@@ -127,7 +127,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);
}
diff --git a/usr/src/boot/sys/boot/efi/boot1/zfs_module.c b/usr/src/boot/sys/boot/efi/boot1/zfs_module.c
index c81f759876..a60e4432d7 100644
--- a/usr/src/boot/sys/boot/efi/boot1/zfs_module.c
+++ b/usr/src/boot/sys/boot/efi/boot1/zfs_module.c
@@ -116,7 +116,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));
@@ -125,7 +125,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);
}
@@ -178,7 +178,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 %zd for pool '%s' for '%s' "
"(%lu)\n", st.st_size, spa->spa_name, filepath, EFI_ERROR_CODE(status));
@@ -188,7 +188,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);
}