From 59a05bdf354d7c3caf5f249f55b1496ac1324270 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 22 Apr 2019 18:40:24 +0000 Subject: [PATCH] Create boot_img as a global variable Get the information from the image that we're booting and store it in a global variable. Prefer using this to passing it around. Remove the special case for zfs that set the preferred boot handle by having it uses this global variable diretly. Reviewed by: kevans@ Differential Revision: https://reviews.freebsd.org/D20015 --- stand/efi/include/efi.h | 5 +++++ stand/efi/include/efizfs.h | 2 -- stand/efi/libefi/efizfs.c | 10 +--------- stand/efi/loader/main.c | 27 ++++++++++++++------------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/stand/efi/include/efi.h b/stand/efi/include/efi.h index 0a48218f3664..fe8d78286529 100644 --- a/stand/efi/include/efi.h +++ b/stand/efi/include/efi.h @@ -61,6 +61,11 @@ Revision History #include "efipoint.h" #include "efiuga.h" +/* + * Global variables + */ +extern EFI_LOADED_IMAGE *boot_img; + /* * FreeBSD UUID */ diff --git a/stand/efi/include/efizfs.h b/stand/efi/include/efizfs.h index 80f12302352a..97f28097b2a1 100644 --- a/stand/efi/include/efizfs.h +++ b/stand/efi/include/efizfs.h @@ -50,10 +50,8 @@ void efi_zfs_probe(void); EFI_HANDLE efizfs_get_handle_by_guid(uint64_t); bool efizfs_get_guid_by_handle(EFI_HANDLE, uint64_t *); zfsinfo_list_t *efizfs_get_zfsinfo_list(void); -void efizfs_set_preferred(EFI_HANDLE); #else -#define efizfs_set_preferred(x) #define efi_zfs_probe NULL #endif diff --git a/stand/efi/libefi/efizfs.c b/stand/efi/libefi/efizfs.c index 7cbb5fecfaa3..8b28250f109b 100644 --- a/stand/efi/libefi/efizfs.c +++ b/stand/efi/libefi/efizfs.c @@ -45,14 +45,6 @@ static zfsinfo_list_t zfsinfo; uint64_t pool_guid; -static EFI_HANDLE preferred; - -void -efizfs_set_preferred(EFI_HANDLE h) -{ - preferred = h; -} - zfsinfo_list_t * efizfs_get_zfsinfo_list(void) { @@ -122,7 +114,7 @@ efi_zfs_probe(void) 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 == preferred) + if (pd->pd_handle == boot_img->DeviceHandle) pool_guid = guid; } diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 1d7c3d551a38..a3469aa0a080 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -88,6 +88,11 @@ static int fail_timeout = 5; */ UINT16 boot_current; +/* + * Image that we booted from. + */ +EFI_LOADED_IMAGE *boot_img; + static bool has_keyboard(void) { @@ -300,7 +305,7 @@ fix_dosisms(char *p) enum { BOOT_INFO_OK = 0, BAD_CHOICE = 1, NOT_SPECIFIC = 2 }; static int -match_boot_info(EFI_LOADED_IMAGE *img __unused, char *boot_info, size_t bisz) +match_boot_info(char *boot_info, size_t bisz) { uint32_t attr; uint16_t fplen; @@ -448,7 +453,7 @@ match_boot_info(EFI_LOADED_IMAGE *img __unused, char *boot_info, size_t bisz) * a drop to the OK boot loader prompt is possible. */ static int -find_currdev(EFI_LOADED_IMAGE *img, bool do_bootmgr, bool is_last, +find_currdev(bool do_bootmgr, bool is_last, char *boot_info, size_t boot_info_sz) { pdinfo_t *dp, *pp; @@ -481,7 +486,7 @@ find_currdev(EFI_LOADED_IMAGE *img, bool do_bootmgr, bool is_last, * loader.conf. */ if (do_bootmgr) { - rv = match_boot_info(img, boot_info, boot_info_sz); + rv = match_boot_info(boot_info, boot_info_sz); switch (rv) { case BOOT_INFO_OK: /* We found it */ return (0); @@ -514,7 +519,7 @@ find_currdev(EFI_LOADED_IMAGE *img, bool do_bootmgr, bool is_last, * boot protocol to do so. We fail and let UEFI go on to * the next candidate. */ - dp = efiblk_get_pdinfo_by_handle(img->DeviceHandle); + dp = efiblk_get_pdinfo_by_handle(boot_img->DeviceHandle); if (dp != NULL) { text = efi_devpath_name(dp->pd_devpath); if (text != NULL) { @@ -553,7 +558,7 @@ find_currdev(EFI_LOADED_IMAGE *img, bool do_bootmgr, bool is_last, * any of the nodes in that path match one of the enumerated * handles. Currently, this handle list is only for netboot. */ - if (efi_handle_lookup(img->DeviceHandle, &dev, &unit, &extra) == 0) { + if (efi_handle_lookup(boot_img->DeviceHandle, &dev, &unit, &extra) == 0) { set_currdev_devsw(dev, unit); if (sanity_check_currdev()) return (0); @@ -751,7 +756,6 @@ main(int argc, CHAR16 *argv[]) size_t sz, bosz = 0, bisz = 0; UINT16 boot_order[100]; char boot_info[4096]; - EFI_LOADED_IMAGE *img; char buf[32]; bool uefi_boot_mgr; @@ -763,7 +767,7 @@ main(int argc, CHAR16 *argv[]) archsw.arch_zfs_probe = efi_zfs_probe; /* Get our loaded image protocol interface structure. */ - BS->HandleProtocol(IH, &imgid, (VOID**)&img); + BS->HandleProtocol(IH, &imgid, (VOID**)&boot_img); /* * Chicken-and-egg problem; we want to have console output early, but @@ -776,9 +780,6 @@ main(int argc, CHAR16 *argv[]) setenv("console", "efi", 1); cons_probe(); - /* Tell ZFS probe code where we booted from, if zfs configured */ - efizfs_set_preferred(img->DeviceHandle); - /* Init the time source */ efi_time_init(); @@ -880,14 +881,14 @@ main(int argc, CHAR16 *argv[]) /* Determine the devpath of our image so we can prefer it. */ - text = efi_devpath_name(img->FilePath); + text = efi_devpath_name(boot_img->FilePath); if (text != NULL) { printf(" Load Path: %S\n", text); efi_setenv_freebsd_wcs("LoaderPath", text); efi_free_devpath_name(text); } - rv = BS->HandleProtocol(img->DeviceHandle, &devid, (void **)&imgpath); + rv = BS->HandleProtocol(boot_img->DeviceHandle, &devid, (void **)&imgpath); if (rv == EFI_SUCCESS) { text = efi_devpath_name(imgpath); if (text != NULL) { @@ -974,7 +975,7 @@ main(int argc, CHAR16 *argv[]) * the boot protocol and also allow an escape hatch for users wishing * to try something different. */ - if (find_currdev(img, uefi_boot_mgr, is_last, boot_info, bisz) != 0) + if (find_currdev(uefi_boot_mgr, is_last, boot_info, bisz) != 0) if (!interactive_interrupt("Failed to find bootable partition")) return (EFI_NOT_FOUND);