Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Feb 2018 20:51:28 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r329183 - in stable/11: . stand stand/arm/uboot stand/common stand/efi/boot1 stand/efi/fdt stand/efi/include stand/efi/libefi stand/efi/loader stand/efi/loader/arch/arm stand/efi/loader...
Message-ID:  <201802122051.w1CKpSxw072122@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Feb 12 20:51:28 2018
New Revision: 329183
URL: https://svnweb.freebsd.org/changeset/base/329183

Log:
  MFC Loader Fixes Final: r327612,r327703,r327704,r327878,r327879,r327881,
  r328007,r328029,r328030,r328031,r328061,r328156,r328169,r328288,r328289,
  r328290,r328291,r328292,r328411,r328536,r328603,r328614,r328642,r328769,
  r328779,r328780,r328781,r328782,r328783,r328806,r328808,r328826,r328835,
  r328911,r328986,r328987,r328990,r328999,r329000,r329019,r329050,r329054,
  r329060
  
  r327612: Invent new #defines for the biospci_{read,write}_config function
  
  r327703: Define __dmadat after #include'ing ufsread.c.
  
  r327704: Fix printf missing format variables warnings.
  
  r327878: Add GUID for UEFI boot manager variables.
  
  r327879: Report the boot order and where we are in that boot order.
  
  r327881: Allow this file to be included
  
  r328007: Fix booting on some arm64 systems after r327879 by fixing the call
  to utf8_to_ucs2
  
  r328029: When returning an error and freeing allocated memory from
  ucs2_to_utf8, NULL the return pointer.
  
  r328030: Check the return value from utf8_to_ucs2 instead of whether or not
  uv is NULL.
  
  r328031: Need to free uv after we're done using it.
  
  r328061: utf8_to_ucs2() should check for malloc failure
  
  r328156: stand: Move sections around to fix stand/ build with ld.lld on
  armv7
  
  r328169: Remove extra copy of bootinfo.c. It's a bit rotted copy of the one
  in efi/loader.
  
  r328288: Fix some resource leaks.
  
  r328289: Don't leak memory when displaying help.
  
  r328290: On malloc failure, be sure to close the include file that triggered
  it.
  
  r328291: getenv does not return tainted data in the boot loader. Attempt to
  clue Coverity into that fact.
  
  r328292: There's no tainted data here, tag it as such to avoid false
  positives.
  
  r328411: loader.efi: add missing EFI GUIDs
  
  r328536: loader: support for mixed-endianness ELF/loader and POWER8
  
  r328603: Add missing non-POWERPC case to give the scr value something
  non-zero.
  
  r328614: Move libstand.3 to libsa.3. Update libsa.3 to include functions
  
  r328642: Break out the interpreters (simple and forth) w/o ifdefs.
  
  r328769: Centralize several variables.
  
  r328779: Retire pnp.4th and the code needed only for 4th words used here.
  
  r328780: These 4th words were an attempt to allow integration into the boot
  loader scripts. However, that path won't be taken after all it
  seems.
  
  r328781: Remove pcibios forth support.
  
  r328782: Now that we no longer conditionally compile some files outside of
  ficl
  
  r328783: Invent new LDR_INTERP for the loader interpreter to use.
  
  r328806: We need more heap space to properly load newer powerpc kernels.
  
  r328808: Implement strcoll as strcmp.
  
  r328826: Make cross-endian loader changes apply only to powerpc
  
  r328835: Fix regression introduced in r328806, preventing boot on many
  platforms.
  
  r328911: Ignore relocation tables for non-memory-resident sections.
  
  r328986: Fix relative location of USB sources after recent move.
  
  r328987: A more definitions to kernel emulation shim in order to build
  stand/usb.
  
  r328990: Move the stand/usb test loader into its own directory.
  
  r328999: Fix indentation to FreeBSD standard for interp files
  
  r329000: Move simple interpreter 'perform' into interp.c and call it
  
  r329019: Move to tabs for indentation and to 8-space notches, per style(9).
  
  r329050: Fix build of userboot.so
  
  r329054: Set script.lang in the environment to either 'forth' or 'simple' to
  reflect what scripting language was compiled into the loader.
  
  r329060: loader: fix endianness conversion
  
  PR:		225323

Added:
  stable/11/stand/common/interp_simple.c
     - copied, changed from r328642, head/stand/common/interp_simple.c
  stable/11/stand/libsa/libsa.3
     - copied, changed from r329182, stable/11/stand/libsa/libstand.3
  stable/11/stand/usb/test/
     - copied from r328990, head/stand/usb/test/
Deleted:
  stable/11/stand/efi/loader/arch/i386/bootinfo.c
  stable/11/stand/forth/pcibios.4th
  stable/11/stand/forth/pnp.4th
  stable/11/stand/libsa/libstand.3
  stable/11/stand/usb/Makefile.test
  stable/11/stand/usb/bsd_usbloader_test.c
Modified:
  stable/11/ObsoleteFiles.inc
  stable/11/stand/arm/uboot/Makefile
  stable/11/stand/arm/uboot/ldscript.arm
  stable/11/stand/common/boot.c
  stable/11/stand/common/bootstrap.h
  stable/11/stand/common/commands.c
  stable/11/stand/common/install.c
  stable/11/stand/common/interp.c
  stable/11/stand/common/interp_backslash.c
  stable/11/stand/common/interp_forth.c
  stable/11/stand/common/interp_parse.c
  stable/11/stand/common/load_elf.c
  stable/11/stand/common/load_elf_obj.c
  stable/11/stand/common/misc.c
  stable/11/stand/common/pnp.c
  stable/11/stand/defs.mk
  stable/11/stand/efi/boot1/Makefile
  stable/11/stand/efi/boot1/boot1.c
  stable/11/stand/efi/fdt/Makefile
  stable/11/stand/efi/include/efi.h
  stable/11/stand/efi/include/efiapi.h
  stable/11/stand/efi/libefi/Makefile
  stable/11/stand/efi/libefi/efichar.c
  stable/11/stand/efi/libefi/env.c
  stable/11/stand/efi/loader/Makefile
  stable/11/stand/efi/loader/arch/arm/ldscript.arm
  stable/11/stand/efi/loader/main.c
  stable/11/stand/fdt/Makefile
  stable/11/stand/ficl.mk
  stable/11/stand/ficl/Makefile
  stable/11/stand/forth/Makefile
  stable/11/stand/forth/loader.4th
  stable/11/stand/geli/Makefile
  stable/11/stand/i386/boot0/Makefile
  stable/11/stand/i386/btx/btx/Makefile
  stable/11/stand/i386/btx/btxldr/Makefile
  stable/11/stand/i386/btx/lib/Makefile
  stable/11/stand/i386/cdboot/Makefile
  stable/11/stand/i386/kgzldr/Makefile
  stable/11/stand/i386/libfirewire/Makefile
  stable/11/stand/i386/libfirewire/firewire.c
  stable/11/stand/i386/libi386/Makefile
  stable/11/stand/i386/libi386/biospci.c
  stable/11/stand/i386/libi386/comconsole.c
  stable/11/stand/i386/libi386/libi386.h
  stable/11/stand/i386/loader/Makefile
  stable/11/stand/i386/mbr/Makefile
  stable/11/stand/i386/pmbr/Makefile
  stable/11/stand/kshim/bsd_kernel.h
  stable/11/stand/libsa/Makefile
  stable/11/stand/libsa/environment.c
  stable/11/stand/libsa/stand.h
  stable/11/stand/loader.mk
  stable/11/stand/mips/beri/boot2/Makefile
  stable/11/stand/mips/beri/boot2/boot2.c
  stable/11/stand/mips/beri/loader/Makefile
  stable/11/stand/mips/beri/loader/exec.c
  stable/11/stand/mips/uboot/Makefile
  stable/11/stand/ofw/common/main.c
  stable/11/stand/ofw/libofw/Makefile
  stable/11/stand/ofw/libofw/elf_freebsd.c
  stable/11/stand/ofw/libofw/libofw.h
  stable/11/stand/ofw/libofw/ofw_copy.c
  stable/11/stand/ofw/libofw/ofw_memory.c
  stable/11/stand/ofw/libofw/ppc64_elf_freebsd.c
  stable/11/stand/powerpc/boot1.chrp/Makefile
  stable/11/stand/powerpc/kboot/Makefile
  stable/11/stand/powerpc/kboot/conf.c
  stable/11/stand/powerpc/kboot/host_syscall.S
  stable/11/stand/powerpc/kboot/host_syscall.h
  stable/11/stand/powerpc/kboot/hostdisk.c
  stable/11/stand/powerpc/kboot/kerneltramp.S
  stable/11/stand/powerpc/kboot/main.c
  stable/11/stand/powerpc/kboot/metadata.c
  stable/11/stand/powerpc/kboot/ppc64_elf_freebsd.c
  stable/11/stand/powerpc/ofw/Makefile
  stable/11/stand/powerpc/ofw/ldscript.powerpc
  stable/11/stand/powerpc/uboot/Makefile
  stable/11/stand/sparc64/boot1/Makefile
  stable/11/stand/sparc64/loader/Makefile
  stable/11/stand/uboot/fdt/Makefile
  stable/11/stand/uboot/lib/Makefile
  stable/11/stand/usb/usbcore.mk
  stable/11/stand/userboot/test/Makefile
  stable/11/stand/userboot/userboot/Makefile
  stable/11/stand/zfs/Makefile
  stable/11/sys/kern/link_elf_obj.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/ObsoleteFiles.inc
==============================================================================
--- stable/11/ObsoleteFiles.inc	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/ObsoleteFiles.inc	Mon Feb 12 20:51:28 2018	(r329183)
@@ -38,6 +38,9 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20180212: Obsolete forth files
+OLD_FILES+=boot/efi.4th
+OLD_FILES+=boot/pcibios.4th
 # 20180212: Remove libstand
 OLD_FILES+=usr/lib/libstand.a
 OLD_FILES+=usr/lib/libstand_p.a

Modified: stable/11/stand/arm/uboot/Makefile
==============================================================================
--- stable/11/stand/arm/uboot/Makefile	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/arm/uboot/Makefile	Mon Feb 12 20:51:28 2018	(r329183)
@@ -41,8 +41,8 @@ LDFLAGS+=	-Wl,-znotext
 
 CFLAGS+=	-fPIC
 
-DPADD=		${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} ${LIBSA}
-LDADD=		${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} ${LIBSA}
+DPADD=		${LDR_INTERP} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} ${LIBSA}
+LDADD=		${LDR_INTERP} ${LIBUBOOT} ${LIBFDT} ${LIBUBOOT_FDT} ${LIBSA}
 
 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
 

Modified: stable/11/stand/arm/uboot/ldscript.arm
==============================================================================
--- stable/11/stand/arm/uboot/ldscript.arm	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/arm/uboot/ldscript.arm	Mon Feb 12 20:51:28 2018	(r329183)
@@ -32,6 +32,11 @@ SECTIONS
   .rela.got      : { *(.rela.got)		}
   .rela.got1     : { *(.rela.got1)		}
   .rela.got2     : { *(.rela.got2)		}
+  .dynamic        : { *(.dynamic) }
+                PROVIDE (_GOT_START_ = .);
+  .got            : { *(.got) }
+  .got.plt        : { *(.got.plt) }
+                PROVIDE (_GOT_END_ = .);
   .rela.ctors    : { *(.rela.ctors)	}
   .rela.dtors    : { *(.rela.dtors)	}
   .rela.init     : { *(.rela.init)	}
@@ -58,7 +63,6 @@ SECTIONS
   }
   .data1   : { *(.data1) }
   .got1           : { *(.got1) }
-  .dynamic        : { *(.dynamic) }
   /* Put .ctors and .dtors next to the .got2 section, so that the pointers
      get relocated with -mrelocatable. Also put in the .fixup pointers.
      The current compiler no longer needs this, but keep it around for 2.7.2  */
@@ -74,10 +78,6 @@ SECTIONS
   .fixup          : { *(.fixup) }
                 PROVIDE (_FIXUP_END_ = .);
                 PROVIDE (_GOT2_END_ = .);
-                PROVIDE (_GOT_START_ = .);
-  .got            : { *(.got) }
-  .got.plt        : { *(.got.plt) }
-                PROVIDE (_GOT_END_ = .);
   /* We want the small data sections together, so single-instruction offsets
      can access them all, and initialized data all before uninitialized, so
      we can shorten the on-disk segment size.  */

Modified: stable/11/stand/common/boot.c
==============================================================================
--- stable/11/stand/common/boot.c	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/common/boot.c	Mon Feb 12 20:51:28 2018	(r329183)
@@ -52,60 +52,60 @@ COMMAND_SET(boot, "boot", "boot a file or loaded kerne
 static int
 command_boot(int argc, char *argv[])
 {
-    struct preloaded_file	*fp;
+	struct preloaded_file	*fp;
 
-    /*
-     * See if the user has specified an explicit kernel to boot.
-     */
-    if ((argc > 1) && (argv[1][0] != '-')) {
+	/*
+	 * See if the user has specified an explicit kernel to boot.
+	 */
+	if ((argc > 1) && (argv[1][0] != '-')) {
 
-	/* XXX maybe we should discard everything and start again? */
-	if (file_findfile(NULL, NULL) != NULL) {
-	    snprintf(command_errbuf, sizeof(command_errbuf),
-		"can't boot '%s', kernel module already loaded", argv[1]);
-	    return(CMD_ERROR);
+		/* XXX maybe we should discard everything and start again? */
+		if (file_findfile(NULL, NULL) != NULL) {
+			snprintf(command_errbuf, sizeof(command_errbuf),
+			    "can't boot '%s', kernel module already loaded", argv[1]);
+			return(CMD_ERROR);
+		}
+
+		/* find/load the kernel module */
+		if (mod_loadkld(argv[1], argc - 2, argv + 2) != 0)
+			return(CMD_ERROR);
+		/* we have consumed all arguments */
+		argc = 1;
 	}
 
-	/* find/load the kernel module */
-	if (mod_loadkld(argv[1], argc - 2, argv + 2) != 0)
-	    return(CMD_ERROR);
-	/* we have consumed all arguments */
-	argc = 1;
-    }
+	/*
+	 * See if there is a kernel module already loaded
+	 */
+	if (file_findfile(NULL, NULL) == NULL)
+		if (loadakernel(0, argc - 1, argv + 1))
+			/* we have consumed all arguments */
+			argc = 1;
 
-    /*
-     * See if there is a kernel module already loaded
-     */
-    if (file_findfile(NULL, NULL) == NULL)
-	if (loadakernel(0, argc - 1, argv + 1))
-	    /* we have consumed all arguments */
-	    argc = 1;
+	/*
+	 * Loaded anything yet?
+	 */
+	if ((fp = file_findfile(NULL, NULL)) == NULL) {
+		command_errmsg = "no bootable kernel";
+		return(CMD_ERROR);
+	}
 
-    /*
-     * Loaded anything yet?
-     */
-    if ((fp = file_findfile(NULL, NULL)) == NULL) {
-	command_errmsg = "no bootable kernel";
-	return(CMD_ERROR);
-    }
+	/*
+	 * If we were given arguments, discard any previous.
+	 * XXX should we merge arguments?  Hard to DWIM.
+	 */
+	if (argc > 1) {
+		if (fp->f_args != NULL)
+			free(fp->f_args);
+		fp->f_args = unargv(argc - 1, argv + 1);
+	}
 
-    /*
-     * If we were given arguments, discard any previous.
-     * XXX should we merge arguments?  Hard to DWIM.
-     */
-    if (argc > 1) {
-	if (fp->f_args != NULL)
-	    free(fp->f_args);
-	fp->f_args = unargv(argc - 1, argv + 1);
-    }
+	/* Hook for platform-specific autoloading of modules */
+	if (archsw.arch_autoload() != 0)
+		return(CMD_ERROR);
 
-    /* Hook for platform-specific autoloading of modules */
-    if (archsw.arch_autoload() != 0)
+	/* Call the exec handler from the loader matching the kernel */
+	file_formats[fp->f_loader]->l_exec(fp);
 	return(CMD_ERROR);
-
-    /* Call the exec handler from the loader matching the kernel */
-    file_formats[fp->f_loader]->l_exec(fp);
-    return(CMD_ERROR);
 }
 
 
@@ -118,29 +118,29 @@ COMMAND_SET(autoboot, "autoboot", "boot automatically 
 static int
 command_autoboot(int argc, char *argv[])
 {
-    int		howlong;
-    char	*cp, *prompt;
+	int		howlong;
+	char	*cp, *prompt;
 
-    prompt = NULL;
-    howlong = -1;
-    switch(argc) {
-    case 3:
-	prompt = argv[2];
-	/* FALLTHROUGH */
-    case 2:
-	howlong = strtol(argv[1], &cp, 0);
-	if (*cp != 0) {
-	    snprintf(command_errbuf, sizeof(command_errbuf),
-		"bad delay '%s'", argv[1]);
-	    return(CMD_ERROR);
+	prompt = NULL;
+	howlong = -1;
+	switch(argc) {
+	case 3:
+		prompt = argv[2];
+		/* FALLTHROUGH */
+	case 2:
+		howlong = strtol(argv[1], &cp, 0);
+		if (*cp != 0) {
+			snprintf(command_errbuf, sizeof(command_errbuf),
+			    "bad delay '%s'", argv[1]);
+			return(CMD_ERROR);
+		}
+		/* FALLTHROUGH */
+	case 1:
+		return(autoboot(howlong, prompt));
 	}
-	/* FALLTHROUGH */
-    case 1:
-	return(autoboot(howlong, prompt));
-    }
 
-    command_errmsg = "too many arguments";
-    return(CMD_ERROR);
+	command_errmsg = "too many arguments";
+	return(CMD_ERROR);
 }
 
 /*
@@ -150,103 +150,103 @@ command_autoboot(int argc, char *argv[])
 void
 autoboot_maybe()
 {
-    char	*cp;
+	char	*cp;
 
-    cp = getenv("autoboot_delay");
-    if ((autoboot_tried == 0) && ((cp == NULL) || strcasecmp(cp, "NO")))
-	autoboot(-1, NULL);		/* try to boot automatically */
+	cp = getenv("autoboot_delay");
+	if ((autoboot_tried == 0) && ((cp == NULL) || strcasecmp(cp, "NO")))
+		autoboot(-1, NULL);		/* try to boot automatically */
 }
 
 int
 autoboot(int timeout, char *prompt)
 {
-    time_t	when, otime, ntime;
-    int		c, yes;
-    char	*argv[2], *cp, *ep;
-    char	*kernelname;
+	time_t	when, otime, ntime;
+	int		c, yes;
+	char	*argv[2], *cp, *ep;
+	char	*kernelname;
 #ifdef BOOT_PROMPT_123
-    const char	*seq = "123", *p = seq;
+	const char	*seq = "123", *p = seq;
 #endif
 
-    autoboot_tried = 1;
+	autoboot_tried = 1;
 
-    if (timeout == -1) {
-        timeout = 10;
-	/* try to get a delay from the environment */
-	if ((cp = getenv("autoboot_delay"))) {
-	    timeout = strtol(cp, &ep, 0);
-	    if (cp == ep)
-		timeout = 10;		/* Unparseable? Set default! */
+	if (timeout == -1) {
+		timeout = 10;
+		/* try to get a delay from the environment */
+		if ((cp = getenv("autoboot_delay"))) {
+			timeout = strtol(cp, &ep, 0);
+			if (cp == ep)
+				timeout = 10;		/* Unparseable? Set default! */
+		}
 	}
-    }
 
-    kernelname = getenv("kernelname");
-    if (kernelname == NULL) {
-	argv[0] = NULL;
-	loadakernel(0, 0, argv);
 	kernelname = getenv("kernelname");
 	if (kernelname == NULL) {
-	    command_errmsg = "no valid kernel found";
-	    return(CMD_ERROR);
+		argv[0] = NULL;
+		loadakernel(0, 0, argv);
+		kernelname = getenv("kernelname");
+		if (kernelname == NULL) {
+			command_errmsg = "no valid kernel found";
+			return(CMD_ERROR);
+		}
 	}
-    }
 
-    if (timeout >= 0) {
-        otime = time(NULL);
-        when = otime + timeout;	/* when to boot */
+	if (timeout >= 0) {
+		otime = time(NULL);
+		when = otime + timeout;	/* when to boot */
 
-        yes = 0;
+		yes = 0;
 
 #ifdef BOOT_PROMPT_123
-        printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or "
-	    "1 2 3 sequence for command prompt." : prompt);
+		printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or "
+		    "1 2 3 sequence for command prompt." : prompt);
 #else
-        printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt);
+		printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt);
 #endif
 
-        for (;;) {
-	    if (ischar()) {
-	        c = getchar();
+		for (;;) {
+			if (ischar()) {
+				c = getchar();
 #ifdef BOOT_PROMPT_123
-		if ((c == '\r') || (c == '\n')) {
-			yes = 1;
-			break;
-		} else if (c != *p++)
-			p = seq;
-		if (*p == 0)
-			break;
+				if ((c == '\r') || (c == '\n')) {
+					yes = 1;
+					break;
+				} else if (c != *p++)
+					p = seq;
+				if (*p == 0)
+					break;
 #else
-	        if ((c == '\r') || (c == '\n'))
-		    yes = 1;
-	        break;
+				if ((c == '\r') || (c == '\n'))
+					yes = 1;
+				break;
 #endif
-	    }
-	    ntime = time(NULL);
-	    if (ntime >= when) {
-	        yes = 1;
-	        break;
-	    }
+			}
+			ntime = time(NULL);
+			if (ntime >= when) {
+				yes = 1;
+				break;
+			}
 
-	    if (ntime != otime) {
-	        printf("\rBooting [%s] in %d second%s... ",
-	    		    kernelname, (int)(when - ntime),
-			    (when-ntime)==1?"":"s");
-	        otime = ntime;
-	    }
-        }
-    } else {
-        yes = 1;
-    }
+			if (ntime != otime) {
+				printf("\rBooting [%s] in %d second%s... ",
+				    kernelname, (int)(when - ntime),
+				    (when-ntime)==1?"":"s");
+				otime = ntime;
+			}
+		}
+	} else {
+		yes = 1;
+	}
 
-    if (yes)
-	printf("\rBooting [%s]...               ", kernelname);
-    putchar('\n');
-    if (yes) {
-	argv[0] = "boot";
-	argv[1] = NULL;
-	return(command_boot(1, argv));
-    }
-    return(CMD_OK);
+	if (yes)
+		printf("\rBooting [%s]...               ", kernelname);
+	putchar('\n');
+	if (yes) {
+		argv[0] = "boot";
+		argv[1] = NULL;
+		return(command_boot(1, argv));
+	}
+	return(CMD_OK);
 }
 
 /*
@@ -255,43 +255,43 @@ autoboot(int timeout, char *prompt)
 static char *
 getbootfile(int try)
 {
-    static char *name = NULL;
-    const char	*spec, *ep;
-    size_t	len;
+	static char *name = NULL;
+	const char	*spec, *ep;
+	size_t	len;
 
-    /* we use dynamic storage */
-    if (name != NULL) {
-	free(name);
-	name = NULL;
-    }
+	/* we use dynamic storage */
+	if (name != NULL) {
+		free(name);
+		name = NULL;
+	}
 
-    /*
-     * Try $bootfile, then try our builtin default
-     */
-    if ((spec = getenv("bootfile")) == NULL)
-	spec = default_bootfiles;
+	/*
+	 * Try $bootfile, then try our builtin default
+	 */
+	if ((spec = getenv("bootfile")) == NULL)
+		spec = default_bootfiles;
 
-    while ((try > 0) && (spec != NULL)) {
-	spec = strchr(spec, ';');
-	if (spec)
-	    spec++;	/* skip over the leading ';' */
-	try--;
-    }
-    if (spec != NULL) {
-	if ((ep = strchr(spec, ';')) != NULL) {
-	    len = ep - spec;
-	} else {
-	    len = strlen(spec);
+	while ((try > 0) && (spec != NULL)) {
+		spec = strchr(spec, ';');
+		if (spec)
+			spec++;	/* skip over the leading ';' */
+		try--;
 	}
-	name = malloc(len + 1);
-	strncpy(name, spec, len);
-	name[len] = 0;
-    }
-    if (name && name[0] == 0) {
-	free(name);
-	name = NULL;
-    }
-    return(name);
+	if (spec != NULL) {
+		if ((ep = strchr(spec, ';')) != NULL) {
+			len = ep - spec;
+		} else {
+			len = strlen(spec);
+		}
+		name = malloc(len + 1);
+		strncpy(name, spec, len);
+		name[len] = 0;
+	}
+	if (name && name[0] == 0) {
+		free(name);
+		name = NULL;
+	}
+	return(name);
 }
 
 /*
@@ -307,104 +307,109 @@ getbootfile(int try)
 int
 getrootmount(char *rootdev)
 {
-    char	lbuf[128], *cp, *ep, *dev, *fstyp, *options;
-    int		fd, error;
+	char	lbuf[128], *cp, *ep, *dev, *fstyp, *options;
+	int		fd, error;
 
-    if (getenv("vfs.root.mountfrom") != NULL)
-	return(0);
+	if (getenv("vfs.root.mountfrom") != NULL)
+		return(0);
 
-    error = 1;
-    sprintf(lbuf, "%s/etc/fstab", rootdev);
-    if ((fd = open(lbuf, O_RDONLY)) < 0)
-	goto notfound;
+	error = 1;
+	sprintf(lbuf, "%s/etc/fstab", rootdev);
+	if ((fd = open(lbuf, O_RDONLY)) < 0)
+		goto notfound;
 
-    /* loop reading lines from /etc/fstab    What was that about sscanf again? */
-    while (fgetstr(lbuf, sizeof(lbuf), fd) >= 0) {
-	if ((lbuf[0] == 0) || (lbuf[0] == '#'))
-	    continue;
+	/* loop reading lines from /etc/fstab    What was that about sscanf again? */
+	fstyp = NULL;
+	dev = NULL;
+	while (fgetstr(lbuf, sizeof(lbuf), fd) >= 0) {
+		if ((lbuf[0] == 0) || (lbuf[0] == '#'))
+			continue;
 
-	/* skip device name */
-	for (cp = lbuf; (*cp != 0) && !isspace(*cp); cp++)
-	    ;
-	if (*cp == 0)		/* misformatted */
-	    continue;
-	/* delimit and save */
-	*cp++ = 0;
-	dev = strdup(lbuf);
+		/* skip device name */
+		for (cp = lbuf; (*cp != 0) && !isspace(*cp); cp++)
+			;
+		if (*cp == 0)		/* misformatted */
+			continue;
+		/* delimit and save */
+		*cp++ = 0;
+		free(dev);
+		dev = strdup(lbuf);
 
-	/* skip whitespace up to mountpoint */
-	while ((*cp != 0) && isspace(*cp))
-	    cp++;
-	/* must have /<space> to be root */
-	if ((*cp == 0) || (*cp != '/') || !isspace(*(cp + 1)))
-	    continue;
-	/* skip whitespace up to fstype */
-	cp += 2;
-	while ((*cp != 0) && isspace(*cp))
-	    cp++;
-	if (*cp == 0)		/* misformatted */
-	    continue;
-	/* skip text to end of fstype and delimit */
-	ep = cp;
-	while ((*cp != 0) && !isspace(*cp))
-	    cp++;
-	*cp = 0;
-	fstyp = strdup(ep);
+		/* skip whitespace up to mountpoint */
+		while ((*cp != 0) && isspace(*cp))
+			cp++;
+		/* must have /<space> to be root */
+		if ((*cp == 0) || (*cp != '/') || !isspace(*(cp + 1)))
+			continue;
+		/* skip whitespace up to fstype */
+		cp += 2;
+		while ((*cp != 0) && isspace(*cp))
+			cp++;
+		if (*cp == 0)		/* misformatted */
+			continue;
+		/* skip text to end of fstype and delimit */
+		ep = cp;
+		while ((*cp != 0) && !isspace(*cp))
+			cp++;
+		*cp = 0;
+		free(fstyp);
+		fstyp = strdup(ep);
 
-	/* skip whitespace up to mount options */
-	cp += 1;
-	while ((*cp != 0) && isspace(*cp))
-		cp++;
-	if (*cp == 0)           /* misformatted */
-		continue;
-	/* skip text to end of mount options and delimit */
-	ep = cp;
-	while ((*cp != 0) && !isspace(*cp))
-		cp++;
-	*cp = 0;
-	options = strdup(ep);
-	/* Build the <fstype>:<device> and save it in vfs.root.mountfrom */
-	sprintf(lbuf, "%s:%s", fstyp, dev);
+		/* skip whitespace up to mount options */
+		cp += 1;
+		while ((*cp != 0) && isspace(*cp))
+			cp++;
+		if (*cp == 0)           /* misformatted */
+			continue;
+		/* skip text to end of mount options and delimit */
+		ep = cp;
+		while ((*cp != 0) && !isspace(*cp))
+			cp++;
+		*cp = 0;
+		options = strdup(ep);
+		/* Build the <fstype>:<device> and save it in vfs.root.mountfrom */
+		sprintf(lbuf, "%s:%s", fstyp, dev);
+		setenv("vfs.root.mountfrom", lbuf, 0);
+
+		/* Don't override vfs.root.mountfrom.options if it is already set */
+		if (getenv("vfs.root.mountfrom.options") == NULL) {
+			/* save mount options */
+			setenv("vfs.root.mountfrom.options", options, 0);
+		}
+		free(options);
+		error = 0;
+		break;
+	}
+	close(fd);
 	free(dev);
 	free(fstyp);
-	setenv("vfs.root.mountfrom", lbuf, 0);
 
-	/* Don't override vfs.root.mountfrom.options if it is already set */
-	if (getenv("vfs.root.mountfrom.options") == NULL) {
-		/* save mount options */
-		setenv("vfs.root.mountfrom.options", options, 0);
-	}
-	free(options);
-	error = 0;
-	break;
-    }
-    close(fd);
-
 notfound:
-    if (error) {
-	const char *currdev;
+	if (error) {
+		const char *currdev;
 
-	currdev = getenv("currdev");
-	if (currdev != NULL && strncmp("zfs:", currdev, 4) == 0) {
-	    cp = strdup(currdev);
-	    cp[strlen(cp) - 1] = '\0';
-	    setenv("vfs.root.mountfrom", cp, 0);
-	    error = 0;
+		currdev = getenv("currdev");
+		if (currdev != NULL && strncmp("zfs:", currdev, 4) == 0) {
+			cp = strdup(currdev);
+			cp[strlen(cp) - 1] = '\0';
+			setenv("vfs.root.mountfrom", cp, 0);
+			error = 0;
+			free(cp);
+		}
 	}
-    }
 
-    return(error);
+	return(error);
 }
 
 static int
 loadakernel(int try, int argc, char* argv[])
 {
-    char *cp;
+	char *cp;
 
 	for (try = 0; (cp = getbootfile(try)) != NULL; try++)
-	    if (mod_loadkld(cp, argc - 1, argv + 1) != 0)
-		printf("can't load '%s'\n", cp);
-	    else
-		return 1;
+		if (mod_loadkld(cp, argc - 1, argv + 1) != 0)
+			printf("can't load '%s'\n", cp);
+		else
+			return 1;
 	return 0;
 }

Modified: stable/11/stand/common/bootstrap.h
==============================================================================
--- stable/11/stand/common/bootstrap.h	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/common/bootstrap.h	Mon Feb 12 20:51:28 2018	(r329183)
@@ -46,18 +46,20 @@ extern char	command_errbuf[COMMAND_ERRBUFSZ];
 
 /* interp.c */
 void	interact(void);
-int	include(const char *filename);
+void	interp_emit_prompt(void);
+int	interp_builtin_cmd(int argc, char *argv[]);
 
+/* Called by interp.c for interp_*.c embedded interpreters */
+int	interp_include(const char *filename);	/* Execute commands from filename */
+void	interp_init(void);			/* Initialize interpreater */
+int	interp_run(const char *line);		/* Run a single command */
+
 /* interp_backslash.c */
 char	*backslash(const char *str);
 
 /* interp_parse.c */
 int	parse(int *argc, char ***argv, const char *str);
 
-/* interp_forth.c */
-void	bf_init(void);
-int	bf_run(char *line);
-
 /* boot.c */
 int	autoboot(int timeout, char *prompt);
 void	autoboot_maybe(void);
@@ -315,6 +317,9 @@ struct arch_switch
 
     /* Probe ZFS pool(s), if needed. */
     void	(*arch_zfs_probe)(void);
+
+    /* For kexec-type loaders, get ksegment structure */
+    void	(*arch_kexec_kseg_get)(int *nseg, void **kseg);
 };
 extern struct arch_switch archsw;
 

Modified: stable/11/stand/common/commands.c
==============================================================================
--- stable/11/stand/common/commands.c	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/common/commands.c	Mon Feb 12 20:51:28 2018	(r329183)
@@ -91,10 +91,8 @@ help_getnext(int fd, char **topic, char **subtopic, ch
 	    cp = ep;
 	}
 	if (*topic == NULL) {
-	    if (*subtopic != NULL)
-		free(*subtopic);
-	    if (*desc != NULL)
-		free(*desc);
+	    free(*subtopic);
+	    free(*desc);
 	    continue;
 	}
 	return(1);
@@ -169,7 +167,7 @@ command_help(int argc, char *argv[]) 
 
 	} else if (strcmp(topic, t)) {
 	    /* topic mismatch */
-	    if(matched)		/* nothing more on this topic, stop scanning */
+	    if (matched)	/* nothing more on this topic, stop scanning */
 		break;
 
 	} else {
@@ -178,7 +176,7 @@ command_help(int argc, char *argv[]) 
 	    if (((subtopic == NULL) && (s == NULL)) ||
 		((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) {
 		/* exact match, print text */
-		while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
+		while ((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
 		    if (pager_output(buf))
 			break;
 		    if (pager_output("\n"))
@@ -193,23 +191,24 @@ command_help(int argc, char *argv[]) 
 	free(t);
 	free(s);
 	free(d);
+	t = s = d = NULL;
     }
+    free(t);
+    free(s);
+    free(d);
     pager_close();
     close(hfd);
     if (!matched) {
 	snprintf(command_errbuf, sizeof(command_errbuf),
 	    "no help available for '%s'", topic);
 	free(topic);
-	if (subtopic)
-	    free(subtopic);
+	free(subtopic);
 	return(CMD_ERROR);
     }
     free(topic);
-    if (subtopic)
-	free(subtopic);
+    free(subtopic);
     return(CMD_OK);
 }
-
 
 COMMAND_SET(commandlist, "?", "list commands", command_commandlist);
 

Modified: stable/11/stand/common/install.c
==============================================================================
--- stable/11/stand/common/install.c	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/common/install.c	Mon Feb 12 20:51:28 2018	(r329183)
@@ -286,7 +286,7 @@ install(char *pkgname)
 	fd = open(s, O_RDONLY);
 	if (fd != -1) {
 		close(fd);
-		error = include(s);
+		error = inter_include(s);
 		if (error == CMD_ERROR)
 			goto fail;
 	}

Modified: stable/11/stand/common/interp.c
==============================================================================
--- stable/11/stand/common/interp.c	Mon Feb 12 19:50:43 2018	(r329182)
+++ stable/11/stand/common/interp.c	Mon Feb 12 20:51:28 2018	(r329183)
@@ -37,102 +37,40 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include "bootstrap.h"
 
-#ifdef BOOT_FORTH
-#include "ficl.h"
-extern FICL_VM *bf_vm;
-#endif
-
 #define	MAXARGS	20			/* maximum number of arguments allowed */
 
-static void	prompt(void);
-
-#ifndef BOOT_FORTH
 /*
- * Perform the command
- */
-static int
-perform(int argc, char *argv[])
-{
-    int				result;
-    struct bootblk_command	**cmdp;
-    bootblk_cmd_t		*cmd;
-
-    if (argc < 1)
-	return(CMD_OK);
-
-    /* set return defaults; a successful command will override these */
-    command_errmsg = command_errbuf;
-    strcpy(command_errbuf, "no error message");
-    cmd = NULL;
-    result = CMD_ERROR;
-
-    /* search the command set for the command */
-    SET_FOREACH(cmdp, Xcommand_set) {
-	if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
-	    cmd = (*cmdp)->c_fn;
-    }
-    if (cmd != NULL) {
-	result = (cmd)(argc, argv);
-    } else {
-	command_errmsg = "unknown command";
-    }
-    return(result);
-}
-#endif	/* ! BOOT_FORTH */
-
-/*
  * Interactive mode
  */
 void
 interact(void)
 {
-    static char	input[256];			/* big enough? */
-#ifndef BOOT_FORTH
-    int		argc;
-    char	**argv;
-#endif
+	static char	input[256];			/* big enough? */
 
-#ifdef BOOT_FORTH
-    bf_init();
-#endif
+	interp_init();
 
-    /* Read our default configuration. */
-    include("/boot/loader.rc");
+	printf("\n");
 
-    printf("\n");
+	/*
+	 * Before interacting, we might want to autoboot.
+	 */
+	autoboot_maybe();
 
-    /*
-     * Before interacting, we might want to autoboot.
-     */
-    autoboot_maybe();
-    
-    /*
-     * Not autobooting, go manual
-     */
-    printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
-    if (getenv("prompt") == NULL)
-	setenv("prompt", "${interpret}", 1);
-    if (getenv("interpret") == NULL)
-        setenv("interpret", "OK", 1);
-    
+	/*
+	 * Not autobooting, go manual
+	 */
+	printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
+	if (getenv("prompt") == NULL)
+		setenv("prompt", "${interpret}", 1);
+	if (getenv("interpret") == NULL)
+		setenv("interpret", "OK", 1);
 
-    for (;;) {
-	input[0] = '\0';
-	prompt();
-	ngets(input, sizeof(input));
-#ifdef BOOT_FORTH
-	bf_vm->sourceID.i = 0;
-	bf_run(input);
-#else
-	if (!parse(&argc, &argv, input)) {
-	    if (perform(argc, argv))
-		printf("%s: %s\n", argv[0], command_errmsg);
-	    free(argv);
-	} else {
-	    printf("parse error\n");
+	for (;;) {
+		input[0] = '\0';
+		interp_emit_prompt();
+		ngets(input, sizeof(input));
+		interp_run(input);
 	}
-#endif
-    }
 }
 
 /*
@@ -149,214 +87,87 @@ COMMAND_SET(include, "include", "read commands from a 
 static int
 command_include(int argc, char *argv[])
 {
-    int		i;
-    int		res;
-    char	**argvbuf;
+	int		i;
+	int		res;
+	char		**argvbuf;
 
-    /* 
-     * Since argv is static, we need to save it here.
-     */
-    argvbuf = (char**) calloc((u_int)argc, sizeof(char*));
-    for (i = 0; i < argc; i++)
-	argvbuf[i] = strdup(argv[i]);
+	/*
+	 * Since argv is static, we need to save it here.
+	 */
+	argvbuf = (char**) calloc((u_int)argc, sizeof(char*));
+	for (i = 0; i < argc; i++)
+		argvbuf[i] = strdup(argv[i]);
 
-    res=CMD_OK;
-    for (i = 1; (i < argc) && (res == CMD_OK); i++)
-	res = include(argvbuf[i]);
+	res=CMD_OK;
+	for (i = 1; (i < argc) && (res == CMD_OK); i++)
+		res = interp_include(argvbuf[i]);
 
-    for (i = 0; i < argc; i++)
-	free(argvbuf[i]);
-    free(argvbuf);
+	for (i = 0; i < argc; i++)
+		free(argvbuf[i]);
+	free(argvbuf);
 
-    return(res);
+	return(res);
 }
 
 /*
- * Header prepended to each line. The text immediately follows the header.
- * We try to make this short in order to save memory -- the loader has
- * limited memory available, and some of the forth files are very long.
+ * Emit the current prompt; use the same syntax as the parser
+ * for embedding environment variables. Does not accept input.
  */
-struct includeline 
+void
+interp_emit_prompt(void)
 {
-    struct includeline	*next;
-#ifndef BOOT_FORTH
-    int			flags;
-    int			line;
-#define SL_QUIET	(1<<0)
-#define SL_IGNOREERR	(1<<1)
-#endif
-    char		text[0];
-};
+	char		*pr, *p, *cp, *ev;
 
-int
-include(const char *filename)
-{
-    struct includeline	*script, *se, *sp;
-    char		input[256];			/* big enough? */
-#ifdef BOOT_FORTH
-    int			res;
-    char		*cp;
-    int			prevsrcid, fd, line;
-#else
-    int			argc,res;
-    char		**argv, *cp;
-    int			fd, flags, line;
-#endif
+	if ((cp = getenv("prompt")) == NULL)
+		cp = ">";
+	pr = p = strdup(cp);
 
-    if (((fd = open(filename, O_RDONLY)) == -1)) {
-	snprintf(command_errbuf, sizeof(command_errbuf),
-	    "can't open '%s': %s", filename, strerror(errno));
-	return(CMD_ERROR);
-    }
+	while (*p != 0) {
+		if ((*p == '$') && (*(p+1) == '{')) {
+			for (cp = p + 2; (*cp != 0) && (*cp != '}'); cp++)
+				;
+			*cp = 0;
+			ev = getenv(p + 2);
 
-    /*
-     * Read the script into memory.
-     */
-    script = se = NULL;
-    line = 0;
-	
-    while (fgetstr(input, sizeof(input), fd) >= 0) {
-	line++;
-#ifdef BOOT_FORTH
-	cp = input;
-#else
-	flags = 0;
-	/* Discard comments */

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802122051.w1CKpSxw072122>