Mercurial > unleashed > prev-conversion
changeset 18809:4d483ddfc2b1
libefi: Move EFI ZFS functions to libefi
illumos issue #9071
author | Toomas Soome <tsoome@me.com> |
---|---|
date | Tue, 12 Dec 2017 15:23:09 +0200 |
parents | 5e5ff5e89b63 |
children | 4c0b161579af |
files | usr/src/boot/sys/boot/efi/boot1/Makefile usr/src/boot/sys/boot/efi/boot1/boot1.c usr/src/boot/sys/boot/efi/boot1/boot_module.h usr/src/boot/sys/boot/efi/include/efizfs.h usr/src/boot/sys/boot/efi/libefi/Makefile usr/src/boot/sys/boot/efi/libefi/efizfs.c usr/src/boot/sys/boot/efi/loader/Makefile usr/src/boot/sys/boot/efi/loader/conf.c usr/src/boot/sys/boot/efi/loader/main.c |
diffstat | 9 files changed, 186 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/boot/sys/boot/efi/boot1/Makefile Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/boot1/Makefile Tue Dec 12 15:23:09 2017 +0200 @@ -40,12 +40,11 @@ CPPFLAGS += -I./../../../sys CPPFLAGS += -I./../../.. CPPFLAGS += -I../../../../lib/libstand -CPPFLAGS += -DEFI_UFS_BOOT -DUFS1_ONLY +CPPFLAGS += -DUFS1_ONLY # CPPFLAGS += -DEFI_DEBUG CPPFLAGS += -I./../../zfs/ CPPFLAGS += -I./../../../cddl/boot/zfs/ -CPPFLAGS += -DEFI_ZFS_BOOT # Always add MI sources and REGULAR efi loader bits CPPFLAGS += -I./../../common
--- a/usr/src/boot/sys/boot/efi/boot1/boot1.c Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/boot1/boot1.c Tue Dec 12 15:23:09 2017 +0200 @@ -40,12 +40,8 @@ static const boot_module_t *boot_modules[] = { -#ifdef EFI_ZFS_BOOT &zfs_module, -#endif -#ifdef EFI_UFS_BOOT &ufs_module -#endif }; #define NUM_BOOT_MODULES nitems(boot_modules)
--- a/usr/src/boot/sys/boot/efi/boot1/boot_module.h Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/boot1/boot_module.h Tue Dec 12 15:23:09 2017 +0200 @@ -96,12 +96,8 @@ } boot_module_t; /* Standard boot modules. */ -#ifdef EFI_UFS_BOOT extern const boot_module_t ufs_module; -#endif -#ifdef EFI_ZFS_BOOT extern const boot_module_t zfs_module; -#endif /* Functions available to modules. */ extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/boot/sys/boot/efi/include/efizfs.h Tue Dec 12 15:23:09 2017 +0200 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Eric McCorkle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stdbool.h> + +#ifndef _EFIZFS_H_ +#define _EFIZFS_H_ + +typedef STAILQ_HEAD(zfsinfo_list, zfsinfo) zfsinfo_list_t; + +typedef struct zfsinfo +{ + STAILQ_ENTRY(zfsinfo) zi_link; + EFI_HANDLE zi_handle; + uint64_t zi_pool_guid; +} zfsinfo_t; + +extern uint64_t pool_guid; + +extern void efi_zfs_probe(void); +extern zfsinfo_list_t *efizfs_get_zfsinfo_list(void); +extern bool efi_zfs_is_preferred(EFI_HANDLE *h); +extern EFI_HANDLE efizfs_get_handle_by_guid(uint64_t); + +#endif
--- a/usr/src/boot/sys/boot/efi/libefi/Makefile Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/libefi/Makefile Tue Dec 12 15:23:09 2017 +0200 @@ -25,7 +25,8 @@ install: SRCS= delay.c devpath.c efi_console.c efi_driver_utils.c efichar.c \ - efinet.c efipart.c env.c errno.c handles.c libefi.c time.c wchar.c + efinet.c efipart.c efizfs.c env.c errno.c handles.c libefi.c \ + time.c wchar.c #.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" #SRCS += time.c @@ -35,7 +36,7 @@ OBJS= $(SRCS:%.c=%.o) -CPPFLAGS= -DTERM_EMU -D_STANDALONE +CPPFLAGS= -D_STANDALONE CFLAGS = -O2 #.if ${MACHINE_CPUARCH} == "aarch64" @@ -50,6 +51,8 @@ CFLAGS += -I../include CFLAGS += -I../include/${MACH64} CFLAGS += -I../../../../lib/libstand +CFLAGS += -I./../../zfs +CFLAGS += -I./../../../cddl/boot/zfs # Pick up the bootstrap header for some interface items CFLAGS += -I../../common @@ -57,7 +60,7 @@ # Handle FreeBSD specific %b and %D printf format specifiers # CFLAGS+= ${FORMAT_EXTENSIONS} # CFLAGS += -D__printf__=__freebsd_kprintf__ -CFLAGS+= -DTERM_EMU +CFLAGS += -DTERM_EMU include ../Makefile.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/boot/sys/boot/efi/libefi/efizfs.c Tue Dec 12 15:23:09 2017 +0200 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2008-2010 Rui Paulo + * Copyright (c) 2006 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <sys/param.h> +#include <sys/disk.h> + +#include <libzfs.h> + +#include <efi.h> +#include <efilib.h> + +#include "efizfs.h" + +static zfsinfo_list_t zfsinfo; + +uint64_t pool_guid; + +zfsinfo_list_t * +efizfs_get_zfsinfo_list(void) +{ + return (&zfsinfo); +} + +EFI_HANDLE +efizfs_get_handle_by_guid(uint64_t guid) +{ + zfsinfo_t *zi; + + STAILQ_FOREACH(zi, &zfsinfo, zi_link) { + if (zi->zi_pool_guid == guid) { + return (zi->zi_handle); + } + } + return (NULL); +} + +static void +insert_zfs(EFI_HANDLE handle, uint64_t guid) +{ + zfsinfo_t *zi; + + zi = malloc(sizeof(zfsinfo_t)); + zi->zi_handle = handle; + zi->zi_pool_guid = guid; + STAILQ_INSERT_TAIL(&zfsinfo, zi, zi_link); +} + +void +efi_zfs_probe(void) +{ + pdinfo_list_t *hdi; + pdinfo_t *hd, *pd = NULL; + char devname[SPECNAMELEN + 1]; + uint64_t guid; + + hdi = efiblk_get_pdinfo_list(&efipart_hddev); + STAILQ_INIT(&zfsinfo); + + /* + * Find the handle for the boot device. The boot1 did find the + * device with loader binary, now we need to search for the + * same device and if it is part of the zfs pool, we record the + * pool GUID for currdev setup. + */ + STAILQ_FOREACH(hd, hdi, pd_link) { + STAILQ_FOREACH(pd, &hd->pd_part, pd_link) { + + snprintf(devname, sizeof(devname), "%s%dp%d:", + efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); + + if (zfs_probe_dev(devname, &guid) == 0) { + insert_zfs(pd->pd_handle, guid); + + if (efi_zfs_is_preferred(pd->pd_handle)) + pool_guid = guid; + } + + } + } +} + +uint64_t +ldi_get_size(void *priv) +{ + int fd = (uintptr_t) priv; + uint64_t size; + + ioctl(fd, DIOCGMEDIASIZE, &size); + return (size); +}
--- a/usr/src/boot/sys/boot/efi/loader/Makefile Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/loader/Makefile Tue Dec 12 15:23:09 2017 +0200 @@ -49,7 +49,6 @@ CPPFLAGS += -I./../../i386/libi386 CPPFLAGS += -I./../../zfs CPPFLAGS += -I./../../../cddl/boot/zfs -CPPFLAGS += -DEFI_ZFS_BOOT CPPFLAGS += -DNO_PCI -DEFI -DTERM_EMU # Export serial numbers, UUID, and asset tag from loader.
--- a/usr/src/boot/sys/boot/efi/loader/conf.c Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/loader/conf.c Tue Dec 12 15:23:09 2017 +0200 @@ -25,32 +25,25 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); #include <stand.h> #include <bootstrap.h> #include <efi.h> #include <efilib.h> -#ifdef EFI_ZFS_BOOT #include <libzfs.h> -#endif struct devsw *devsw[] = { &efipart_fddev, &efipart_cddev, &efipart_hddev, &efinet_dev, -#ifdef EFI_ZFS_BOOT &zfs_dev, -#endif NULL }; struct fs_ops *file_system[] = { &gzipfs_fsops, -#ifdef EFI_ZFS_BOOT &zfs_fsops, -#endif &dosfs_fsops, &ufs_fsops, &cd9660_fsops,
--- a/usr/src/boot/sys/boot/efi/loader/main.c Sun Feb 11 18:06:12 2018 +0200 +++ b/usr/src/boot/sys/boot/efi/loader/main.c Tue Dec 12 15:23:09 2017 +0200 @@ -1,4 +1,4 @@ -/*- +/* * Copyright (c) 2008-2010 Rui Paulo * Copyright (c) 2006 Marcel Moolenaar * All rights reserved. @@ -46,9 +46,8 @@ #include <bootstrap.h> #include <smbios.h> -#ifdef EFI_ZFS_BOOT #include <libzfs.h> -#endif +#include <efizfs.h> #include "loader_efi.h" @@ -64,10 +63,14 @@ extern void acpi_detect(void); extern void efi_getsmap(void); -#ifdef EFI_ZFS_BOOT -static void efi_zfs_probe(void); -static uint64_t pool_guid; -#endif + +static EFI_LOADED_IMAGE *img; + +bool +efi_zfs_is_preferred(EFI_HANDLE *h) +{ + return (h == img->DeviceHandle); +} static int has_keyboard(void) @@ -77,7 +80,7 @@ EFI_HANDLE *hin, *hin_end, *walker; UINTN sz; int retval = 0; - + /* * Find all the handles that support the SIMPLE_TEXT_INPUT_PROTOCOL and * do the typical dance to get the right sized buffer. @@ -134,7 +137,7 @@ } else if (DevicePathType(path) == MESSAGING_DEVICE_PATH && DevicePathSubType(path) == MSG_USB_CLASS_DP) { USB_CLASS_DEVICE_PATH *usb; - + usb = (USB_CLASS_DEVICE_PATH *)(void *)path; if (usb->DeviceClass == 3 && /* HID */ usb->DeviceSubClass == 1 && /* Boot devices */ @@ -294,7 +297,6 @@ main(int argc, CHAR16 *argv[]) { char var[128]; - EFI_LOADED_IMAGE *img; EFI_GUID *guid; int i, j, vargood, howto; void *ptr; @@ -308,10 +310,11 @@ archsw.arch_readin = efi_readin; archsw.arch_loadaddr = efi_loadaddr; archsw.arch_free_loadaddr = efi_free_loadaddr; -#ifdef EFI_ZFS_BOOT /* Note this needs to be set before ZFS init. */ archsw.arch_zfs_probe = efi_zfs_probe; -#endif + + /* Get our loaded image protocol interface structure. */ + BS->HandleProtocol(IH, &imgid, (VOID**)&img); /* Init the time source */ efi_time_init(); @@ -438,9 +441,6 @@ if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); - /* Get our loaded image protocol interface structure. */ - BS->HandleProtocol(IH, &imgid, (VOID**)&img); - printf("Command line arguments:"); for (i = 0; i < argc; i++) { printf(" %S", argv[i]); @@ -902,46 +902,3 @@ } COMMAND_SET(chain, "chain", "chain load file", command_chain); - -#ifdef EFI_ZFS_BOOT -static void -efi_zfs_probe(void) -{ - pdinfo_list_t *hdi; - pdinfo_t *hd, *pd = NULL; - EFI_GUID imgid = LOADED_IMAGE_PROTOCOL; - EFI_LOADED_IMAGE *img; - char devname[SPECNAMELEN + 1]; - - BS->HandleProtocol(IH, &imgid, (VOID**)&img); - hdi = efiblk_get_pdinfo_list(&efipart_hddev); - - /* - * Find the handle for the boot device. The boot1 did find the - * device with loader binary, now we need to search for the - * same device and if it is part of the zfs pool, we record the - * pool GUID for currdev setup. - */ - STAILQ_FOREACH(hd, hdi, pd_link) { - STAILQ_FOREACH(pd, &hd->pd_part, pd_link) { - - snprintf(devname, sizeof(devname), "%s%dp%d:", - efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); - if (pd->pd_handle == img->DeviceHandle) - (void) zfs_probe_dev(devname, &pool_guid); - else - (void) zfs_probe_dev(devname, NULL); - } - } -} - -uint64_t -ldi_get_size(void *priv) -{ - int fd = (uintptr_t) priv; - uint64_t size; - - ioctl(fd, DIOCGMEDIASIZE, &size); - return (size); -} -#endif