svn commit: r329114 - in stable/11: . lib/libstand sbin/geom/class/eli share/mk sys/boot sys/boot/arm/uboot sys/boot/common sys/boot/efi/boot1 sys/boot/efi/include sys/boot/efi/libefi sys/boot/efi/...

Kyle Evans kevans at FreeBSD.org
Sun Feb 11 02:27:53 UTC 2018


Author: kevans
Date: Sun Feb 11 02:27:50 2018
New Revision: 329114
URL: https://svnweb.freebsd.org/changeset/base/329114

Log:
  MFC Loader Fixes 2017q3: r320547,r320553,r321621,r321844,r321969,r321991,
  r322037,r322038,r322039,r322040,r322056,r322074,r322542,r322592,r322593,
  r322896,r322923,r323671,r322930,r322931,r322932,r322933,r322934,r322935,
  r322936,r322937,r322938,r322939,r322941,r323062,r323063,r323064,r323065,
  r323100,r323131,r323174,r323258,r323261,r323272,r323367,r323379,r323389,
  r323407,r323428,r323436,r323494,r323496,r323497,r323541,r323554,r323589,
  r323707,r323867,r323885,r323886,r323895,r323896,r323897,r323905,r323906,
  r323907,r323908,r323909,r323952,r323991,r324099,r324558,r326445,r326609,
  r326610
  
  This batch includes a special kludge to fix powerpc loader build; <stdlib.h>
  was included after <stand.h> there, causing problems with DEBUG_MALLOC bits.
  Include <stdlib.h> a little bit earlier to fix the build with the intention
  of removing this when eventually libsa silently replaces stdlib.h with
  stand.h.
  
  r320547: Link EFI/uboot loaders with -znotext
  
  r320553: Integer underflow in efipart_realstrategy when I/O starts after end
  of disk
  
  r321621: Always set the receive mask in loader.efi.
  
  r321844: Clean up style in print_state(..) and pager_printf(..)
  
  r321969: Fix the return types for printf and putchar to match their libc
  
  r321991: Revert r321969
  
  r322037: Add stpcpy and stpncpy to libstand
  
  r322038: Add definitions and utilities for EFI drivers
  
  r322039: Move EFI ZFS functions to libefi
  
  r322040: Add EFI utility functions to libefi
  
  r322056: Move EFI fmtdev functionality to libefi
  
  r322074: libefi/time.c cstyle cleanup
  
  r322542: loader.efi: repace XXX with real comments in trap.c
  
  r322592: Remove unused defines.
  
  r322593: Define proposed GUID for FreeBSD boot loader variables.
  
  r322896: Make spinconsole platform independent and hook it up into EFI
  loader
  
  r322923: Hide length of geli passphrase during boot.
  
  r323671: Fix language used in the r322923.
  
  r322930: Move efi_main into efi/loader
  
  r322931: Cleanup efi_main return type
  
  r322932: Use the loader.efi conventions for the various EFI tables.
  
  r322933: No need for MK_ZFS around these: they are by their nature only
  active when MK_ZFS is true.
  
  r322934: _STAND is sometimes defined on the command line. Make the define
  here match.
  
  r322935: Fix warnings due to type mismatch.
  
  r322936: Remove useless 'static' for an enum definition.
  
  r322937: Forward declare struct dsk to avoid warnings when building libi386.
  
  r322938: Link in libefi for boot1
  
  r322939: Use efi_devpath_str for debug path info.
  
  r322941: Eliminate redunant device path matching.
  
  r323062: Make efichar.c routines available to libefi.
  
  r323063: boot1.efi: print more info about where boot1.efi is loaded from
  
  r323064: Exit rather than panic for most errors.
  
  r323065: Save where we're booted from
  
  r323100: libstand: nfs_readlink() should return proper return code
  
  r323131: Revert r322941: Eliminate redundant device matching functions
  
  r323174: Fix loader bug causing too many pages allocation when bootloader
  is U-Boot
  
  r323258: ucs2len
  
  r323261: Fix armv6 build
  
  r323272: Be consistent and do return (1);
  
  r323367: Mark init_chroot and init_script variables as deprecated.
  
  r323379: It's been pointed out that init_script at least is useful w/o
  
  r323389: loader.efi: chain loader should provide proper device handle
  
  r323407: boot1 generate-fat: generate all templates at once
  
  r323428: r323389 breaks the kernel build when WITHOUT_ZFS is defined in
  src.conf
  
  r323436: boot1: remove BOOT1_MAXSIZE default value
  
  r323494: loader should support large_dnode
  
  r323496: libstand: tftp_open() can leak pkt on error
  
  r323497: libefi: efipart_open should check the status from disk_open
  
  r323541: libefi: efipart_realstrategy rsize pointer may be NULL
  
  r323554: Increase EFI boot file size frok 128k to 384k
  
  r323589: loader: biosmem.c cstyle cleanup
  
  r323707: loader: biosmem allocate heap just below 4GB
  
  r323867: libefi: devicename.c cleanups
  
  r323885: libefi: efi_devpath_match() should return bool
  
  r323886: libefi: efipart.c should use calloc()
  
  r323895: libefi: efi_devpath_match local len should be unsigned
  
  r323896: r323885 did miss efilib.h update
  
  r323897: efilib.h: typo in structure member description
  
  r323905: libefi: pdinfo_t pd_unit and pd_open should be unsigned
  
  r323906: libefi: efipart_strategy() should return ENXIO when there is no
  media
  
  r323907: libefi: efipart.c cstyle fix for efipart_print_common()
  
  r323908: libefi: efipart_hdinfo_add_filepath should check strtol result
  
  r323909: libefi: define EISA PNP constants
  
  r323952: After the r317886 support for TFTP and NFS can be enable
  simultaneously.
  
  r323991: libefi: efipart_floppy() will should not pass acpi pointer if the
  HID test fails
  
  r324099: Compile loader as Little-Endian on PPC64/POWER8
  
  r324558: Define prototype for exit and ensure references
  
  r326445: Fix random() and srandom() prototypes to match the standard.
  
  r326609: Make putenv and getenv match the userland definition
  
  r326610: Fix random() prototype to match the system.
  
  PR:		219000 221001 222215
  Relnotes:	yes ("The length of the geli passphrase is hidden during boot")

Added:
  stable/11/sys/boot/efi/boot1/fat-amd64.tmpl.xz
     - copied unchanged from r323554, head/sys/boot/efi/boot1/fat-amd64.tmpl.xz
  stable/11/sys/boot/efi/boot1/fat-arm.tmpl.xz
     - copied unchanged from r323554, head/sys/boot/efi/boot1/fat-arm.tmpl.xz
  stable/11/sys/boot/efi/boot1/fat-arm64.tmpl.xz
     - copied unchanged from r323554, head/sys/boot/efi/boot1/fat-arm64.tmpl.xz
  stable/11/sys/boot/efi/boot1/fat-i386.tmpl.xz
     - copied unchanged from r323554, head/sys/boot/efi/boot1/fat-i386.tmpl.xz
  stable/11/sys/boot/efi/include/efi_driver_utils.h
     - copied unchanged from r322038, head/sys/boot/efi/include/efi_driver_utils.h
  stable/11/sys/boot/efi/include/efi_drivers.h
     - copied unchanged from r322038, head/sys/boot/efi/include/efi_drivers.h
  stable/11/sys/boot/efi/include/efizfs.h
     - copied, changed from r322039, head/sys/boot/efi/include/efizfs.h
  stable/11/sys/boot/efi/libefi/devicename.c
     - copied, changed from r322056, head/sys/boot/efi/libefi/devicename.c
  stable/11/sys/boot/efi/libefi/efi_driver_utils.c
     - copied unchanged from r322038, head/sys/boot/efi/libefi/efi_driver_utils.c
  stable/11/sys/boot/efi/libefi/efizfs.c
     - copied, changed from r322039, head/sys/boot/efi/libefi/efizfs.c
  stable/11/sys/boot/efi/loader/efi_main.c
     - copied, changed from r322930, head/sys/boot/efi/loader/efi_main.c
Deleted:
  stable/11/sys/boot/efi/boot1/fat-amd64.tmpl.bz2.uu
  stable/11/sys/boot/efi/boot1/fat-arm.tmpl.bz2.uu
  stable/11/sys/boot/efi/boot1/fat-arm64.tmpl.bz2.uu
  stable/11/sys/boot/efi/boot1/fat-i386.tmpl.bz2.uu
  stable/11/sys/boot/efi/loader/devicename.c
Modified:
  stable/11/UPDATING
  stable/11/lib/libstand/Makefile
  stable/11/lib/libstand/environment.c
  stable/11/lib/libstand/libstand.3
  stable/11/lib/libstand/nfs.c
  stable/11/lib/libstand/random.c
  stable/11/lib/libstand/stand.h
  stable/11/lib/libstand/tftp.c
  stable/11/sbin/geom/class/eli/geli.8
  stable/11/sbin/geom/class/eli/geom_eli.c
  stable/11/share/mk/src.opts.mk
  stable/11/sys/boot/Makefile.inc
  stable/11/sys/boot/arm/uboot/Makefile
  stable/11/sys/boot/arm/uboot/conf.c
  stable/11/sys/boot/common/loader.8
  stable/11/sys/boot/efi/boot1/Makefile
  stable/11/sys/boot/efi/boot1/Makefile.fat
  stable/11/sys/boot/efi/boot1/boot1.c
  stable/11/sys/boot/efi/boot1/boot_module.h
  stable/11/sys/boot/efi/boot1/generate-fat.sh
  stable/11/sys/boot/efi/boot1/ufs_module.c
  stable/11/sys/boot/efi/boot1/zfs_module.c
  stable/11/sys/boot/efi/include/efi.h
  stable/11/sys/boot/efi/include/efiapi.h
  stable/11/sys/boot/efi/include/efichar.h
  stable/11/sys/boot/efi/include/efidevp.h
  stable/11/sys/boot/efi/include/efilib.h
  stable/11/sys/boot/efi/include/efiprot.h
  stable/11/sys/boot/efi/libefi/Makefile
  stable/11/sys/boot/efi/libefi/devpath.c
  stable/11/sys/boot/efi/libefi/efichar.c
  stable/11/sys/boot/efi/libefi/efinet.c
  stable/11/sys/boot/efi/libefi/efipart.c
  stable/11/sys/boot/efi/libefi/errno.c
  stable/11/sys/boot/efi/libefi/libefi.c
  stable/11/sys/boot/efi/libefi/time.c
  stable/11/sys/boot/efi/loader/Makefile
  stable/11/sys/boot/efi/loader/arch/amd64/Makefile.inc
  stable/11/sys/boot/efi/loader/arch/amd64/trap.c
  stable/11/sys/boot/efi/loader/arch/i386/Makefile.inc
  stable/11/sys/boot/efi/loader/bootinfo.c
  stable/11/sys/boot/efi/loader/conf.c
  stable/11/sys/boot/efi/loader/loader_efi.h
  stable/11/sys/boot/efi/loader/main.c
  stable/11/sys/boot/geli/geliboot.c
  stable/11/sys/boot/geli/geliboot.h
  stable/11/sys/boot/geli/geliboot_crypto.c
  stable/11/sys/boot/geli/geliboot_internal.h
  stable/11/sys/boot/geli/pwgets.c
  stable/11/sys/boot/i386/libi386/Makefile
  stable/11/sys/boot/i386/libi386/biosdisk.c
  stable/11/sys/boot/i386/libi386/biosmem.c
  stable/11/sys/boot/i386/libi386/spinconsole.c
  stable/11/sys/boot/mips/uboot/conf.c
  stable/11/sys/boot/powerpc/ofw/conf.c
  stable/11/sys/boot/powerpc/ofw/ofwfdt.c
  stable/11/sys/boot/powerpc/uboot/conf.c
  stable/11/sys/boot/userboot/test/test.c
  stable/11/sys/boot/userboot/userboot.h
  stable/11/sys/boot/userboot/userboot/main.c
  stable/11/sys/boot/zfs/zfsimpl.c
  stable/11/sys/cddl/boot/zfs/zfsimpl.h
  stable/11/sys/geom/eli/g_eli.c
  stable/11/sys/geom/eli/g_eli.h
  stable/11/sys/geom/eli/g_eli_ctl.c
  stable/11/usr.sbin/bhyveload/bhyveload.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/UPDATING
==============================================================================
--- stable/11/UPDATING	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/UPDATING	Sun Feb 11 02:27:50 2018	(r329114)
@@ -16,6 +16,10 @@ from older versions of FreeBSD, try WITHOUT_CLANG and 
 the tip of head, and then rebuild without this option. The bootstrap process
 from older version of current across the gcc/clang cutover is a bit fragile.
 
+20180210:
+	The geli password typed at boot is now hidden.  To restore the previous
+	behavior, see geli(8) for configuration options.
+
 20180113:
 	The SW_WATCHDOG option is no longer necessary to enable the
 	hardclock-based software watchdog if no hardware watchdog is

Modified: stable/11/lib/libstand/Makefile
==============================================================================
--- stable/11/lib/libstand/Makefile	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/Makefile	Sun Feb 11 02:27:50 2018	(r329114)
@@ -41,7 +41,7 @@ SRCS+= ntoh.c
 .PATH: ${LIBC_SRC}/string
 SRCS+=	bcmp.c bcopy.c bzero.c ffs.c fls.c \
 	memccpy.c memchr.c memcmp.c memcpy.c memmove.c memset.c \
-	qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
+	qdivrem.c strcat.c strchr.c strcmp.c strcpy.c stpcpy.c stpncpy.c \
 	strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \
 	strnlen.c strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
 .if ${MACHINE_CPUARCH} == "arm"

Modified: stable/11/lib/libstand/environment.c
==============================================================================
--- stable/11/lib/libstand/environment.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/environment.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -162,7 +162,7 @@ setenv(const char *name, const char *value, int overwr
 }
 
 int
-putenv(const char *string)
+putenv(char *string)
 {
     char	*value, *copy;
     int		result;

Modified: stable/11/lib/libstand/libstand.3
==============================================================================
--- stable/11/lib/libstand/libstand.3	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/libstand.3	Sun Feb 11 02:27:50 2018	(r329114)
@@ -110,7 +110,7 @@ for set/unset hook functions.
 .Xc
 .It Xo
 .Ft int
-.Fn putenv "const char *string"
+.Fn putenv "char *string"
 .Xc
 .It Xo
 .Ft int
@@ -172,7 +172,7 @@ may be used to prevent a variable being unset.
 .Fn srandom "unsigned long seed"
 .Xc
 .It Xo
-.Ft "unsigned long"
+.Ft "long"
 .Fn random void
 .Xc
 .It Xo

Modified: stable/11/lib/libstand/nfs.c
==============================================================================
--- stable/11/lib/libstand/nfs.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/nfs.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -382,7 +382,7 @@ nfs_readlink(struct nfs_iodesc *d, char *buf)
 	buf[repl->len] = 0;
 done:
 	free(pkt);
-	return (0);
+	return (rc);
 }
 #endif
 

Modified: stable/11/lib/libstand/random.c
==============================================================================
--- stable/11/lib/libstand/random.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/random.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -48,8 +48,8 @@ srandom(seed)
  * and whatever else we might use it for.  The result is uniform on
  * [0, 2^31 - 1].
  */
-u_long
-random()
+long
+random(void)
 {
 	long x, hi, lo, t;
 

Modified: stable/11/lib/libstand/stand.h
==============================================================================
--- stable/11/lib/libstand/stand.h	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/stand.h	Sun Feb 11 02:27:50 2018	(r329114)
@@ -282,7 +282,7 @@ extern ssize_t	write(int, void *, size_t);
 extern struct	dirent *readdirfd(int);
 
 extern void	srandom(u_long seed);
-extern u_long	random(void);
+extern long	random(void);
     
 /* imports from stdlib, locally modified */
 extern long	strtol(const char *, char **, int);
@@ -330,7 +330,7 @@ extern int		env_setenv(const char *name, int flags,
 extern char		*getenv(const char *name);
 extern int		setenv(const char *name, const char *value,
 			       int overwrite);
-extern int		putenv(const char *string);
+extern int		putenv(char *string);
 extern int		unsetenv(const char *name);
 
 extern ev_sethook_t	env_noset;		/* refuse set operation */
@@ -376,6 +376,7 @@ extern int	null_readdir(struct open_file *f, struct di
  * Machine dependent functions and data, must be provided or stubbed by 
  * the consumer 
  */
+extern void		exit(int);
 extern int		getchar(void);
 extern int		ischar(void);
 extern void		putchar(int);

Modified: stable/11/lib/libstand/tftp.c
==============================================================================
--- stable/11/lib/libstand/tftp.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/lib/libstand/tftp.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -467,6 +467,7 @@ tftp_open(const char *path, struct open_file *f)
 
 	if (res) {
 		free(tftpfile->path);
+		free(tftpfile->pkt);
 		free(tftpfile);
 		return (res);
 	}

Modified: stable/11/sbin/geom/class/eli/geli.8
==============================================================================
--- stable/11/sbin/geom/class/eli/geli.8	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sbin/geom/class/eli/geli.8	Sun Feb 11 02:27:50 2018	(r329114)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 3, 2016
+.Dd September 17, 2017
 .Dt GELI 8
 .Os
 .Sh NAME
@@ -51,7 +51,7 @@ utility:
 .Pp
 .Nm
 .Cm init
-.Op Fl bgPTv
+.Op Fl bdgPTv
 .Op Fl a Ar aalgo
 .Op Fl B Ar backupfile
 .Op Fl e Ar ealgo
@@ -88,7 +88,7 @@ utility:
 .Ar prov
 .Nm
 .Cm configure
-.Op Fl bBgGtT
+.Op Fl bBdDgGtT
 .Ar prov ...
 .Nm
 .Cm setkey
@@ -279,6 +279,11 @@ To inhibit backups, you can use
 .Pa none
 as the
 .Ar backupfile .
+.It Fl d
+When entering the passphrase to boot from this encrypted root filesystem, echo
+.Ql *
+characters.
+This makes the length of the passphrase visible.
 .It Fl e Ar ealgo
 Encryption algorithm to use.
 Currently supported algorithms are:
@@ -490,6 +495,15 @@ For more information, see the description of the
 subcommand.
 .It Fl B
 Remove the BOOT flag from the given providers.
+.It Fl d
+When entering the passphrase to boot from this encrypted root filesystem, echo
+.Ql *
+characters.
+This makes the length of the passphrase visible.
+.It Fl D
+Disable echoing of any characters when a passphrase is entered to boot from this
+encrypted root filesystem.
+This hides the passphrase length.
 .It Fl g
 Enable booting from this encrypted root filesystem.
 The boot loader prompts for the passphrase and loads

Modified: stable/11/sbin/geom/class/eli/geom_eli.c
==============================================================================
--- stable/11/sbin/geom/class/eli/geom_eli.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sbin/geom/class/eli/geom_eli.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -82,7 +82,7 @@ static int eli_backup_create(struct gctl_req *req, con
 /*
  * Available commands:
  *
- * init [-bgPTv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov
+ * init [-bdgPTv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov
  * label - alias for 'init'
  * attach [-dprv] [-j passfile] [-k keyfile] prov
  * detach [-fl] prov ...
@@ -107,6 +107,7 @@ struct g_command class_commands[] = {
 		{ 'a', "aalgo", "", G_TYPE_STRING },
 		{ 'b', "boot", NULL, G_TYPE_BOOL },
 		{ 'B', "backupfile", "", G_TYPE_STRING },
+		{ 'd', "displaypass", NULL, G_TYPE_BOOL },
 		{ 'e', "ealgo", "", G_TYPE_STRING },
 		{ 'g', "geliboot", NULL, G_TYPE_BOOL },
 		{ 'i', "iterations", "-1", G_TYPE_NUMBER },
@@ -119,13 +120,14 @@ struct g_command class_commands[] = {
 		{ 'V', "mdversion", "-1", G_TYPE_NUMBER },
 		G_OPT_SENTINEL
 	    },
-	    "[-bgPTv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov"
+	    "[-bdgPTv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov"
 	},
 	{ "label", G_FLAG_VERBOSE, eli_main,
 	    {
 		{ 'a', "aalgo", "", G_TYPE_STRING },
 		{ 'b', "boot", NULL, G_TYPE_BOOL },
 		{ 'B', "backupfile", "", G_TYPE_STRING },
+		{ 'd', "displaypass", NULL, G_TYPE_BOOL },
 		{ 'e', "ealgo", "", G_TYPE_STRING },
 		{ 'g', "geliboot", NULL, G_TYPE_BOOL },
 		{ 'i', "iterations", "-1", G_TYPE_NUMBER },
@@ -182,13 +184,15 @@ struct g_command class_commands[] = {
 	    {
 		{ 'b', "boot", NULL, G_TYPE_BOOL },
 		{ 'B', "noboot", NULL, G_TYPE_BOOL },
+		{ 'd', "displaypass", NULL, G_TYPE_BOOL },
+		{ 'D', "nodisplaypass", NULL, G_TYPE_BOOL },
 		{ 'g', "geliboot", NULL, G_TYPE_BOOL },
 		{ 'G', "nogeliboot", NULL, G_TYPE_BOOL },
 		{ 't', "trim", NULL, G_TYPE_BOOL },
 		{ 'T', "notrim", NULL, G_TYPE_BOOL },
 		G_OPT_SENTINEL
 	    },
-	    "[-bBgGtT] prov ..."
+	    "[-bBdDgGtT] prov ..."
 	},
 	{ "setkey", G_FLAG_VERBOSE, eli_main,
 	    {
@@ -708,6 +712,8 @@ eli_init(struct gctl_req *req)
 		md.md_flags |= G_ELI_FLAG_BOOT;
 	if (gctl_get_int(req, "geliboot"))
 		md.md_flags |= G_ELI_FLAG_GELIBOOT;
+	if (gctl_get_int(req, "displaypass"))
+		md.md_flags |= G_ELI_FLAG_GELIDISPLAYPASS;
 	if (gctl_get_int(req, "notrim"))
 		md.md_flags |= G_ELI_FLAG_NODELETE;
 	md.md_ealgo = CRYPTO_ALGORITHM_MIN - 1;
@@ -912,7 +918,7 @@ eli_attach(struct gctl_req *req)
 
 static void
 eli_configure_detached(struct gctl_req *req, const char *prov, int boot,
- int geliboot, int trim)
+    int geliboot, int displaypass, int trim)
 {
 	struct g_eli_metadata md;
 	bool changed = 0;
@@ -948,6 +954,21 @@ eli_configure_detached(struct gctl_req *req, const cha
 		changed = 1;
 	}
 
+	if (displaypass == 1 && (md.md_flags & G_ELI_FLAG_GELIDISPLAYPASS)) {
+		if (verbose)
+			printf("GELIDISPLAYPASS flag already configured for %s.\n", prov);
+	} else if (displaypass == 0 &&
+	    !(md.md_flags & G_ELI_FLAG_GELIDISPLAYPASS)) {
+		if (verbose)
+			printf("GELIDISPLAYPASS flag not configured for %s.\n", prov);
+	} else if (displaypass >= 0) {
+		if (displaypass)
+			md.md_flags |= G_ELI_FLAG_GELIDISPLAYPASS;
+		else
+			md.md_flags &= ~G_ELI_FLAG_GELIDISPLAYPASS;
+		changed = 1;
+	}
+
 	if (trim == 0 && (md.md_flags & G_ELI_FLAG_NODELETE)) {
 		if (verbose)
 			printf("TRIM disable flag already configured for %s.\n", prov);
@@ -971,8 +992,9 @@ static void
 eli_configure(struct gctl_req *req)
 {
 	const char *prov;
-	bool boot, noboot, geliboot, nogeliboot, trim, notrim;
-	int doboot, dogeliboot, dotrim;
+	bool boot, noboot, geliboot, nogeliboot, displaypass, nodisplaypass;
+	bool trim, notrim;
+	int doboot, dogeliboot, dodisplaypass, dotrim;
 	int i, nargs;
 
 	nargs = gctl_get_int(req, "nargs");
@@ -985,6 +1007,8 @@ eli_configure(struct gctl_req *req)
 	noboot = gctl_get_int(req, "noboot");
 	geliboot = gctl_get_int(req, "geliboot");
 	nogeliboot = gctl_get_int(req, "nogeliboot");
+	displaypass = gctl_get_int(req, "displaypass");
+	nodisplaypass = gctl_get_int(req, "nodisplaypass");
 	trim = gctl_get_int(req, "trim");
 	notrim = gctl_get_int(req, "notrim");
 
@@ -1008,6 +1032,16 @@ eli_configure(struct gctl_req *req)
 	else if (nogeliboot)
 		dogeliboot = 0;
 
+	dodisplaypass = -1;
+	if (displaypass && nodisplaypass) {
+		gctl_error(req, "Options -d and -D are mutually exclusive.");
+		return;
+	}
+	if (displaypass)
+		dodisplaypass = 1;
+	else if (nodisplaypass)
+		dodisplaypass = 0;
+
 	dotrim = -1;
 	if (trim && notrim) {
 		gctl_error(req, "Options -t and -T are mutually exclusive.");
@@ -1018,7 +1052,8 @@ eli_configure(struct gctl_req *req)
 	else if (notrim)
 		dotrim = 0;
 
-	if (doboot == -1 && dogeliboot == -1 && dotrim == -1) {
+	if (doboot == -1 && dogeliboot == -1 && dodisplaypass == -1 &&
+	    dotrim == -1) {
 		gctl_error(req, "No option given.");
 		return;
 	}
@@ -1028,8 +1063,10 @@ eli_configure(struct gctl_req *req)
 	/* Now the rest. */
 	for (i = 0; i < nargs; i++) {
 		prov = gctl_get_ascii(req, "arg%d", i);
-		if (!eli_is_attached(prov))
-			eli_configure_detached(req, prov, doboot, dogeliboot, dotrim);
+		if (!eli_is_attached(prov)) {
+			eli_configure_detached(req, prov, doboot, dogeliboot,
+			    dodisplaypass, dotrim);
+		}
 	}
 }
 

Modified: stable/11/share/mk/src.opts.mk
==============================================================================
--- stable/11/share/mk/src.opts.mk	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/share/mk/src.opts.mk	Sun Feb 11 02:27:50 2018	(r329114)
@@ -188,6 +188,7 @@ __DEFAULT_NO_OPTIONS = \
     HESIOD \
     LIBSOFT \
     LINT \
+    LOADER_FORCE_LE \
     NAND \
     OFED \
     OPENLDAP \

Modified: stable/11/sys/boot/Makefile.inc
==============================================================================
--- stable/11/sys/boot/Makefile.inc	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/Makefile.inc	Sun Feb 11 02:27:50 2018	(r329114)
@@ -1,6 +1,6 @@
 # $FreeBSD$
 
-.include <bsd.own.mk>
+.include <src.opts.mk>
 
 SSP_CFLAGS=
 
@@ -22,3 +22,11 @@ CFLAGS.clang+=  -mfpu=none
 # when this test succeeds rather than require dd to be a bootstrap tool.
 DD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true
 DD=dd ${DD_NOSTATUS}
+
+.if ${MK_LOADER_FORCE_LE} != "no"
+
+.if ${MACHINE_ARCH} == "powerpc64"
+CFLAGS+=	-mlittle-endian
+.endif
+
+.endif

Modified: stable/11/sys/boot/arm/uboot/Makefile
==============================================================================
--- stable/11/sys/boot/arm/uboot/Makefile	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/arm/uboot/Makefile	Sun Feb 11 02:27:50 2018	(r329114)
@@ -100,6 +100,7 @@ CLEANFILES+=	loader.help
 CFLAGS+=	-ffreestanding -msoft-float
 
 LDFLAGS=	-nostdlib -static -T ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
+LDFLAGS+=	-Wl,-znotext
 
 # Pull in common loader code
 .PATH:		${.CURDIR}/../../uboot/common

Modified: stable/11/sys/boot/arm/uboot/conf.c
==============================================================================
--- stable/11/sys/boot/arm/uboot/conf.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/arm/uboot/conf.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -36,6 +36,9 @@ __FBSDID("$FreeBSD$");
 #include "dev_net.h"
 #endif
 
+/* Make sure we have an explicit reference to exit so libsa's panic pulls in the MD exit */
+void (*exitfn)(int) = exit;
+
 struct devsw *devsw[] = {
 #if defined(LOADER_DISK_SUPPORT) || defined(LOADER_CD9660_SUPPORT)
 	&uboot_storage,

Modified: stable/11/sys/boot/common/loader.8
==============================================================================
--- stable/11/sys/boot/common/loader.8	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/common/loader.8	Sun Feb 11 02:27:50 2018	(r329114)
@@ -487,6 +487,11 @@ That happens before entering single-user mode or multi
 mode (but after executing the
 .Va init_script
 if enabled).
+This functionality has generally been eclipsed by rerooting.
+See
+.Xr reboot 8
+.Fl r
+for details.
 .It Va init_path
 Sets the list of binaries which the kernel will try to run as the initial
 process.
@@ -508,6 +513,11 @@ if the script terminates with a non-zero exit code,
 or if a SIGTERM is delivered to the
 .Xr init 8
 process (PID 1).
+This functionality has generally been eclipsed by rerooting.
+See
+.Xr reboot 8
+.Fl r
+for details.
 .It Va init_shell
 Defines the shell binary to be used for executing the various shell scripts.
 The default is

Modified: stable/11/sys/boot/efi/boot1/Makefile
==============================================================================
--- stable/11/sys/boot/efi/boot1/Makefile	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/efi/boot1/Makefile	Sun Feb 11 02:27:50 2018	(r329114)
@@ -10,7 +10,13 @@ PROG=		boot1.sym
 INTERNALPROG=
 WARNS?=		6
 
-.if ${MK_ZFS} != "no"
+# We implement a slightly non-standard %S in that it always takes a
+# CHAR16 that's common in UEFI-land instead of a wchar_t. This only
+# seems to matter on arm64 where wchar_t defaults to an int instead
+# of a short. There's no good cast to use here so just ignore the
+# warnings for now.
+CWARNFLAGS.boot1.c+=	-Wno-format
+
 # Disable warnings that are currently incompatible with the zfs boot code
 CWARNFLAGS.zfs_module.c += -Wno-array-bounds
 CWARNFLAGS.zfs_module.c += -Wno-cast-align
@@ -25,7 +31,6 @@ CWARNFLAGS.skein.c += -Wno-missing-variable-declaratio
 .else if ${COMPILER_TYPE} == "gcc"
 CWARNFLAGS.skein.c += -Wno-missing-declarations
 .endif
-.endif
 
 # architecture-specific loader code
 SRCS=	boot1.c self_reloc.c start.S ufs_module.c
@@ -68,7 +73,7 @@ FILES=	boot1.efi boot1.efifat
 FILESMODE_boot1.efi=	${BINMODE}
 
 LDSCRIPT=	${.CURDIR}/../loader/arch/${MACHINE}/ldscript.${MACHINE}
-LDFLAGS+=	-Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared
+LDFLAGS+=	-Wl,-T${LDSCRIPT},-Bsymbolic,-znotext -shared
 
 .if ${MACHINE_CPUARCH} == "aarch64"
 CFLAGS+=	-mgeneral-regs-only
@@ -78,13 +83,15 @@ CFLAGS+=	-fPIC
 LDFLAGS+=	-Wl,-znocombreloc
 .endif
 
+LIBEFI=		${.OBJDIR}/../libefi/libefi.a
+
 #
 # Add libstand for the runtime functions used by the compiler - for example
 # __aeabi_* (arm) or __divdi3 (i386).
 # as well as required string and memory functions for all platforms.
 #
-DPADD+=		${LIBSTAND}
-LDADD+=		-lstand
+DPADD+=		${LIBEFI} ${LIBSTAND}
+LDADD+=		${LIBEFI} -lstand
 
 DPADD+=		${LDSCRIPT}
 
@@ -119,7 +126,6 @@ boot1.o: ${.CURDIR}/../../common/ufsread.c
 # created by generate-fat.sh
 
 .include "${.CURDIR}/Makefile.fat"
-BOOT1_MAXSIZE?=	131072
 
 boot1.efifat: boot1.efi
 	@set -- `ls -l ${.ALLSRC}`; \
@@ -129,9 +135,7 @@ boot1.efifat: boot1.efi
 	    exit 1; \
 	fi
 	echo ${.OBJDIR}
-	uudecode ${.CURDIR}/fat-${MACHINE}.tmpl.bz2.uu
-	mv fat-${MACHINE}.tmpl.bz2 ${.TARGET}.bz2
-	bzip2 -f -d ${.TARGET}.bz2
+	xz -d -c ${.CURDIR}/fat-${MACHINE}.tmpl.xz > ${.TARGET}
 	${DD} if=${.ALLSRC} of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
 
 CLEANFILES= boot1.efi boot1.efifat

Modified: stable/11/sys/boot/efi/boot1/Makefile.fat
==============================================================================
--- stable/11/sys/boot/efi/boot1/Makefile.fat	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/efi/boot1/Makefile.fat	Sun Feb 11 02:27:50 2018	(r329114)
@@ -1,4 +1,4 @@
 # This file autogenerated by generate-fat.sh - DO NOT EDIT
 # $FreeBSD$
 BOOT1_OFFSET=0x2d
-BOOT1_MAXSIZE=131072
+BOOT1_MAXSIZE=393216

Modified: stable/11/sys/boot/efi/boot1/boot1.c
==============================================================================
--- stable/11/sys/boot/efi/boot1/boot1.c	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/efi/boot1/boot1.c	Sun Feb 11 02:27:50 2018	(r329114)
@@ -29,10 +29,14 @@ __FBSDID("$FreeBSD$");
 
 #include <efi.h>
 #include <eficonsctl.h>
+typedef CHAR16 efi_char;
+#include <efichar.h>
 
 #include "boot_module.h"
 #include "paths.h"
 
+static void efi_panic(EFI_STATUS s, const char *fmt, ...) __dead2 __printflike(2, 3);
+
 static const boot_module_t *boot_modules[] =
 {
 #ifdef EFI_ZFS_BOOT
@@ -47,16 +51,11 @@ static const boot_module_t *boot_modules[] =
 /* The initial number of handles used to query EFI for partitions. */
 #define NUM_HANDLES_INIT	24
 
-EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab);
-
-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;
 static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
+static EFI_GUID FreeBSDBootVarGUID = FREEBSD_BOOT_VAR_GUID;
 
 /*
  * Provide Malloc / Free backed by EFIs AllocatePool / FreePool which ensures
@@ -68,7 +67,7 @@ Malloc(size_t len, const char *file __unused, int line
 {
 	void *out;
 
-	if (bs->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
+	if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
 		return (out);
 
 	return (NULL);
@@ -78,9 +77,26 @@ void
 Free(void *buf, const char *file __unused, int line __unused)
 {
 	if (buf != NULL)
-		(void)bs->FreePool(buf);
+		(void)BS->FreePool(buf);
 }
 
+static EFI_STATUS
+efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr)
+{
+	CHAR16 *var = NULL;
+	size_t len;
+	EFI_STATUS rv;
+
+	utf8_to_ucs2(varname, &var, &len);
+	if (var == NULL)
+		return (EFI_OUT_OF_RESOURCES);
+	rv = RS->SetVariable(var, &FreeBSDBootVarGUID,
+	    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+	    (ucs2len(valstr) + 1) * sizeof(efi_char), valstr);
+	free(var);
+	return (rv);
+}
+
 /*
  * nodes_match returns TRUE if the imgpath isn't NULL and the nodes match,
  * FALSE otherwise.
@@ -88,7 +104,7 @@ Free(void *buf, const char *file __unused, int line __
 static BOOLEAN
 nodes_match(EFI_DEVICE_PATH *imgpath, EFI_DEVICE_PATH *devpath)
 {
-	int len;
+	size_t len;
 
 	if (imgpath == NULL || imgpath->Type != devpath->Type ||
 	    imgpath->SubType != devpath->SubType)
@@ -142,178 +158,6 @@ devpath_last(EFI_DEVICE_PATH *devpath)
 }
 
 /*
- * devpath_node_str is a basic output method for a devpath node which
- * only understands a subset of the available sub types.
- *
- * If we switch to UEFI 2.x then we should update it to use:
- * EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.
- */
-static int
-devpath_node_str(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
-{
-
-	switch (devpath->Type) {
-	case MESSAGING_DEVICE_PATH:
-		switch (devpath->SubType) {
-		case MSG_ATAPI_DP: {
-			ATAPI_DEVICE_PATH *atapi;
-
-			atapi = (ATAPI_DEVICE_PATH *)(void *)devpath;
-			return snprintf(buf, size, "ata(%s,%s,0x%x)",
-			    (atapi->PrimarySecondary == 1) ?  "Sec" : "Pri",
-			    (atapi->SlaveMaster == 1) ?  "Slave" : "Master",
-			    atapi->Lun);
-		}
-		case MSG_USB_DP: {
-			USB_DEVICE_PATH *usb;
-
-			usb = (USB_DEVICE_PATH *)devpath;
-			return snprintf(buf, size, "usb(0x%02x,0x%02x)",
-			    usb->ParentPortNumber, usb->InterfaceNumber);
-		}
-		case MSG_SCSI_DP: {
-			SCSI_DEVICE_PATH *scsi;
-
-			scsi = (SCSI_DEVICE_PATH *)(void *)devpath;
-			return snprintf(buf, size, "scsi(0x%02x,0x%02x)",
-			    scsi->Pun, scsi->Lun);
-		}
-		case MSG_SATA_DP: {
-			SATA_DEVICE_PATH *sata;
-
-			sata = (SATA_DEVICE_PATH *)(void *)devpath;
-			return snprintf(buf, size, "sata(0x%x,0x%x,0x%x)",
-			    sata->HBAPortNumber, sata->PortMultiplierPortNumber,
-			    sata->Lun);
-		}
-		default:
-			return snprintf(buf, size, "msg(0x%02x)",
-			    devpath->SubType);
-		}
-		break;
-	case HARDWARE_DEVICE_PATH:
-		switch (devpath->SubType) {
-		case HW_PCI_DP: {
-			PCI_DEVICE_PATH *pci;
-
-			pci = (PCI_DEVICE_PATH *)devpath;
-			return snprintf(buf, size, "pci(0x%02x,0x%02x)",
-			    pci->Device, pci->Function);
-		}
-		default:
-			return snprintf(buf, size, "hw(0x%02x)",
-			    devpath->SubType);
-		}
-		break;
-	case ACPI_DEVICE_PATH: {
-		ACPI_HID_DEVICE_PATH *acpi;
-
-		acpi = (ACPI_HID_DEVICE_PATH *)(void *)devpath;
-		if ((acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
-			switch (EISA_ID_TO_NUM(acpi->HID)) {
-			case 0x0a03:
-				return snprintf(buf, size, "pciroot(0x%x)",
-				    acpi->UID);
-			case 0x0a08:
-				return snprintf(buf, size, "pcieroot(0x%x)",
-				    acpi->UID);
-			case 0x0604:
-				return snprintf(buf, size, "floppy(0x%x)",
-				    acpi->UID);
-			case 0x0301:
-				return snprintf(buf, size, "keyboard(0x%x)",
-				    acpi->UID);
-			case 0x0501:
-				return snprintf(buf, size, "serial(0x%x)",
-				    acpi->UID);
-			case 0x0401:
-				return snprintf(buf, size, "parallelport(0x%x)",
-				    acpi->UID);
-			default:
-				return snprintf(buf, size, "acpi(pnp%04x,0x%x)",
-				    EISA_ID_TO_NUM(acpi->HID), acpi->UID);
-			}
-		}
-
-		return snprintf(buf, size, "acpi(0x%08x,0x%x)", acpi->HID,
-		    acpi->UID);
-	}
-	case MEDIA_DEVICE_PATH:
-		switch (devpath->SubType) {
-		case MEDIA_CDROM_DP: {
-			CDROM_DEVICE_PATH *cdrom;
-
-			cdrom = (CDROM_DEVICE_PATH *)(void *)devpath;
-			return snprintf(buf, size, "cdrom(%x)",
-			    cdrom->BootEntry);
-		}
-		case MEDIA_HARDDRIVE_DP: {
-			HARDDRIVE_DEVICE_PATH *hd;
-
-			hd = (HARDDRIVE_DEVICE_PATH *)(void *)devpath;
-			return snprintf(buf, size, "hd(%x)",
-			    hd->PartitionNumber);
-		}
-		default:
-			return snprintf(buf, size, "media(0x%02x)",
-			    devpath->SubType);
-		}
-	case BBS_DEVICE_PATH:
-		return snprintf(buf, size, "bbs(0x%02x)", devpath->SubType);
-	case END_DEVICE_PATH_TYPE:
-		return (0);
-	}
-
-	return snprintf(buf, size, "type(0x%02x, 0x%02x)", devpath->Type,
-	    devpath->SubType);
-}
-
-/*
- * devpath_strlcat appends a text description of devpath to buf but not more
- * than size - 1 characters followed by NUL-terminator.
- */
-int
-devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
-{
-	size_t len, used;
-	const char *sep;
-
-	sep = "";
-	used = 0;
-	while (!IsDevicePathEnd(devpath)) {
-		len = snprintf(buf, size - used, "%s", sep);
-		used += len;
-		if (used > size)
-			return (used);
-		buf += len;
-
-		len = devpath_node_str(buf, size - used, devpath);
-		used += len;
-		if (used > size)
-			return (used);
-		buf += len;
-		devpath = NextDevicePathNode(devpath);
-		sep = ":";
-	}
-
-	return (used);
-}
-
-/*
- * devpath_str is convenience method which returns the text description of
- * devpath using a static buffer, so it isn't thread safe!
- */
-char *
-devpath_str(EFI_DEVICE_PATH *devpath)
-{
-	static char buf[256];
-
-	devpath_strlcat(buf, sizeof(buf), devpath);
-
-	return buf;
-}
-
-/*
  * load_loader attempts to load the loader image data.
  *
  * It tries each module and its respective devices, identified by mod->probe,
@@ -400,14 +244,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));
@@ -433,7 +277,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));
@@ -467,7 +311,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B
 	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);
 
@@ -476,10 +320,14 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B
 		    EFI_ERROR_CODE(status));
 		return (status);
 	}
-
-	DPRINTF("probing: %s\n", devpath_str(devpath));
-
-	status = bs->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
+#ifdef EFI_DEBUG
+	{
+		CHAR16 *text = efi_devpath_name(devpath);
+		DPRINTF("probing: %S\n", text);
+		efi_free_devpath_name(text);
+	}
+#endif
+	status = BS->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
 	if (status == EFI_UNSUPPORTED)
 		return (status);
 
@@ -496,11 +344,9 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B
 
 	/* Run through each module, see if it can load this partition */
 	for (i = 0; i < NUM_BOOT_MODULES; i++) {
-		if ((status = bs->AllocatePool(EfiLoaderData,
-		    sizeof(*devinfo), (void **)&devinfo)) !=
-		    EFI_SUCCESS) {
-			DPRINTF("\nFailed to allocate devinfo (%lu)\n",
-			    EFI_ERROR_CODE(status));
+		devinfo = malloc(sizeof(*devinfo));
+		if (devinfo == NULL) {
+			DPRINTF("\nFailed to allocate devinfo\n");
 			continue;
 		}
 		devinfo->dev = blkio;
@@ -513,7 +359,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B
 		status = boot_modules[i]->probe(devinfo);
 		if (status == EFI_SUCCESS)
 			return (EFI_SUCCESS);
-		(void)bs->FreePool(devinfo);
+		free(devinfo);
 	}
 
 	return (EFI_UNSUPPORTED);
@@ -565,14 +411,16 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
 	EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
 	SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL;
 	UINTN i, max_dim, best_mode, cols, rows, hsize, nhandles;
+	CHAR16 *text;
 
 	/* 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,
@@ -580,7 +428,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,34 +455,55 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
 	}
 	putchar('\n');
 
+	/* Determine the devpath of our image so we can prefer it. */
+	status = BS->HandleProtocol(IH, &LoadedImageGUID, (VOID**)&img);
+	imgpath = NULL;
+	if (status == EFI_SUCCESS) {
+		text = efi_devpath_name(img->FilePath);
+		printf("   Load Path: %S\n", text);
+		efi_setenv_freebsd_wcs("Boot1Path", text);
+		efi_free_devpath_name(text);
+
+		status = BS->HandleProtocol(img->DeviceHandle, &DevicePathGUID,
+		    (void **)&imgpath);
+		if (status != EFI_SUCCESS) {
+			DPRINTF("Failed to get image DevicePath (%lu)\n",
+			    EFI_ERROR_CODE(status));
+		} else {
+			text = efi_devpath_name(imgpath);
+			printf("   Load Device: %S\n", text);
+			efi_setenv_freebsd_wcs("Boot1Dev", text);
+			efi_free_devpath_name(text);
+		}
+
+	}
+
 	/* Get all the device handles */
 	hsize = (UINTN)NUM_HANDLES_INIT * sizeof(EFI_HANDLE);
-	if ((status = bs->AllocatePool(EfiLoaderData, hsize, (void **)&handles))
-	    != EFI_SUCCESS)
-		panic("Failed to allocate %d handles (%lu)", NUM_HANDLES_INIT,
-		    EFI_ERROR_CODE(status));
+	handles = malloc(hsize);
+	if (handles == NULL) {
+		printf("Failed to allocate %d handles\n", NUM_HANDLES_INIT);
+	}
 
-	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 **)&handles)) != EFI_SUCCESS) {
-			panic("Failed to allocate %zu handles (%lu)", hsize /
-			    sizeof(*handles), EFI_ERROR_CODE(status));
-		}
-		status = bs->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
+		free(handles);
+		handles = malloc(hsize);
+		if (handles == NULL)
+			efi_panic(EFI_OUT_OF_RESOURCES, "Failed to allocate %d handles\n",
+			    NUM_HANDLES_INIT);
+		status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
 		    NULL, &hsize, handles);
 		if (status != EFI_SUCCESS)
-			panic("Failed to get device handles (%lu)\n",
-			    EFI_ERROR_CODE(status));
+			efi_panic(status, "Failed to get device handles\n");
 		break;
 	default:
-		panic("Failed to get device handles (%lu)",
-		    EFI_ERROR_CODE(status));
+		efi_panic(status, "Failed to get device handles\n");
+		break;
 	}
 
 	/* Scan all partitions, probing with all modules. */
@@ -642,18 +511,6 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
 	printf("   Probing %zu block devices...", nhandles);
 	DPRINTF("\n");
 
-	/* Determine the devpath of our image so we can prefer it. */
-	status = bs->HandleProtocol(image, &LoadedImageGUID, (VOID**)&img);
-	imgpath = NULL;
-	if (status == EFI_SUCCESS) {
-		status = bs->HandleProtocol(img->DeviceHandle, &DevicePathGUID,
-		    (void **)&imgpath);
-		if (status != EFI_SUCCESS)
-			DPRINTF("Failed to get image DevicePath (%lu)\n",
-			    EFI_ERROR_CODE(status));
-		DPRINTF("boot1 imagepath: %s\n", devpath_str(imgpath));
-	}
-
 	for (i = 0; i < nhandles; i++)
 		probe_handle_status(handles[i], imgpath);
 	printf(" done\n");
@@ -667,7 +524,7 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
 	try_boot();
 
 	/* If we get here, we're out of luck... */
-	panic("No bootable partitions found!");
+	efi_panic(EFI_LOAD_ERROR, "No bootable partitions found!");
 }
 
 /*
@@ -689,8 +546,12 @@ add_device(dev_info_t **devinfop, dev_info_t *devinfo)
 	dev->next = devinfo;
 }
 
-void
-panic(const char *fmt, ...)
+/*
+ * OK. We totally give up. Exit back to EFI with a sensible status so
+ * it can try the next option on the list.
+ */
+static void
+efi_panic(EFI_STATUS s, const char *fmt, ...)
 {
 	va_list ap;
 
@@ -700,7 +561,7 @@ panic(const char *fmt, ...)
 	va_end(ap);
 	printf("\n");
 
-	while (1) {}
+	BS->Exit(IH, s, 0, NULL);
 }
 
 void
@@ -711,9 +572,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);
 }

Modified: stable/11/sys/boot/efi/boot1/boot_module.h
==============================================================================
--- stable/11/sys/boot/efi/boot1/boot_module.h	Sat Feb 10 22:36:42 2018	(r329113)
+++ stable/11/sys/boot/efi/boot1/boot_module.h	Sun Feb 11 02:27:50 2018	(r329114)
@@ -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, ...) {}

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-all mailing list