Date: Fri, 4 Aug 2017 04:20:06 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322039 - in head/sys/boot/efi: include libefi loader Message-ID: <201708040420.v744K60R018982@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: imp Date: Fri Aug 4 04:20:06 2017 New Revision: 322039 URL: https://svnweb.freebsd.org/changeset/base/322039 Log: Move EFI ZFS functions to libefi This patch moves some EFI ZFS functions from loader to libefi, allowing them to be used by anything that links against libefi. Submitted by: Eric McCorkle Differential Revision: https://reviews.freebsd.org/D11855 Added: head/sys/boot/efi/include/efizfs.h (contents, props changed) head/sys/boot/efi/libefi/efizfs.c (contents, props changed) Modified: head/sys/boot/efi/libefi/Makefile head/sys/boot/efi/loader/main.c Added: head/sys/boot/efi/include/efizfs.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/boot/efi/include/efizfs.h Fri Aug 4 04:20:06 2017 (r322039) @@ -0,0 +1,51 @@ +/*- + * 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. + * + * $FreeBSD$ + */ + +#include <stdint.h> + +#ifndef _EFIZFS_H_ +#define _EFIZFS_H_ + +#ifdef EFI_ZFS_BOOT +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); + +#endif + +#endif Modified: head/sys/boot/efi/libefi/Makefile ============================================================================== --- head/sys/boot/efi/libefi/Makefile Fri Aug 4 04:16:41 2017 (r322038) +++ head/sys/boot/efi/libefi/Makefile Fri Aug 4 04:20:06 2017 (r322039) @@ -12,7 +12,7 @@ INTERNALLIB= WARNS?= 2 SRCS= delay.c devpath.c efi_console.c efinet.c efipart.c env.c errno.c \ - handles.c wchar.c libefi.c efi_driver_utils.c + handles.c wchar.c libefi.c efi_driver_utils.c efizfs.c .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" SRCS+= time.c @@ -38,6 +38,12 @@ CFLAGS+= -fPIC -mno-red-zone CFLAGS+= -I${.CURDIR}/../include CFLAGS+= -I${.CURDIR}/../include/${MACHINE} CFLAGS+= -I${.CURDIR}/../../../../lib/libstand +.if ${MK_ZFS} != "no" +CFLAGS+= -I${.CURDIR}/../../zfs +CFLAGS+= -I${.CURDIR}/../../../cddl/boot/zfs +CFLAGS+= -I${.CURDIR}/../../../crypto/skein +CFLAGS+= -DEFI_ZFS_BOOT +.endif # Pick up the bootstrap header for some interface items CFLAGS+= -I${.CURDIR}/../../common Added: head/sys/boot/efi/libefi/efizfs.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/boot/efi/libefi/efizfs.c Fri Aug 4 04:20:06 2017 (r322039) @@ -0,0 +1,112 @@ +/*- + * 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> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/disk.h> +#include <stdint.h> + +#ifdef EFI_ZFS_BOOT +#include <libzfs.h> +#endif + +#include <efi.h> +#include <efilib.h> + +#include "efizfs.h" + +#ifdef EFI_ZFS_BOOT +static zfsinfo_list_t zfsinfo; + +uint64_t pool_guid; + +zfsinfo_list_t * +efizfs_get_zfsinfo_list(void) +{ + return (&zfsinfo); +} + +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; + EFI_GUID imgid = LOADED_IMAGE_PROTOCOL; + EFI_LOADED_IMAGE *img; + char devname[SPECNAMELEN + 1]; + uint64_t guid; + + BS->HandleProtocol(IH, &imgid, (VOID**)&img); + 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 (pd->pd_handle == img->DeviceHandle) + pool_guid = guid; + } + + } + } +} + +uint64_t +ldi_get_size(void *priv) +{ + int fd = (uintptr_t) priv; + uint64_t size; + + ioctl(fd, DIOCGMEDIASIZE, &size); + return (size); +} +#endif Modified: head/sys/boot/efi/loader/main.c ============================================================================== --- head/sys/boot/efi/loader/main.c Fri Aug 4 04:16:41 2017 (r322038) +++ head/sys/boot/efi/loader/main.c Fri Aug 4 04:20:06 2017 (r322039) @@ -48,6 +48,8 @@ __FBSDID("$FreeBSD$"); #ifdef EFI_ZFS_BOOT #include <libzfs.h> + +#include "efizfs.h" #endif #include "loader_efi.h" @@ -70,11 +72,6 @@ EFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID; EFI_GUID fdtdtb = FDT_TABLE_GUID; EFI_GUID inputid = SIMPLE_TEXT_INPUT_PROTOCOL; -#ifdef EFI_ZFS_BOOT -static void efi_zfs_probe(void); -static uint64_t pool_guid; -#endif - static int has_keyboard(void) { @@ -83,7 +80,7 @@ has_keyboard(void) 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. @@ -140,7 +137,7 @@ has_keyboard(void) } 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 */ @@ -892,46 +889,3 @@ command_chain(int argc, char *argv[]) } 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708040420.v744K60R018982>