From owner-svn-src-all@FreeBSD.ORG Sun Jul 27 16:12:54 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A7606BE5; Sun, 27 Jul 2014 16:12:54 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8850129BA; Sun, 27 Jul 2014 16:12:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6RGCsEu086320; Sun, 27 Jul 2014 16:12:54 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6RGCpeY086298; Sun, 27 Jul 2014 16:12:51 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201407271612.s6RGCpeY086298@svn.freebsd.org> From: Marcel Moolenaar Date: Sun, 27 Jul 2014 16:12:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269153 - in head/sys/boot: amd64/efi common i386/libi386 i386/loader mips/beri/loader ofw/common pc98/loader powerpc/ps3 sparc64/loader uboot/common userboot/userboot X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Jul 2014 16:12:54 -0000 Author: marcel Date: Sun Jul 27 16:12:51 2014 New Revision: 269153 URL: http://svnweb.freebsd.org/changeset/base/269153 Log: Give loaders more control over the Forth initialization process. In particular, allow loaders to define the name of the RC script the interpreter needs to use. Use this new-found control to have the PXE loader (when compiled with TFTP support and not NFS support) read from ${bootfile}.4th, where ${bootfile} is the name of the file fetched by the PXE firmware. The normal startup process involves reading the following files: 1. /boot/boot.4th 2. /boot/loader.rc or alternatively /boot/boot.conf When these come from a FreeBSD-defined file system, this is all good. But when we boot over the network, subdirectories and fixed file names are often painful to administrators and there's really no way for them to change the behaviour of the loader. Obtained from: Juniper Networks, Inc. Modified: head/sys/boot/amd64/efi/main.c head/sys/boot/common/bootstrap.h head/sys/boot/common/interp.c head/sys/boot/common/interp_forth.c head/sys/boot/i386/libi386/libi386.h head/sys/boot/i386/libi386/pxe.c head/sys/boot/i386/loader/main.c head/sys/boot/mips/beri/loader/main.c head/sys/boot/ofw/common/main.c head/sys/boot/pc98/loader/main.c head/sys/boot/powerpc/ps3/main.c head/sys/boot/sparc64/loader/main.c head/sys/boot/uboot/common/main.c head/sys/boot/userboot/userboot/main.c Modified: head/sys/boot/amd64/efi/main.c ============================================================================== --- head/sys/boot/amd64/efi/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/amd64/efi/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -124,7 +124,7 @@ main(int argc, CHAR16 *argv[]) archsw.arch_copyout = x86_efi_copyout; archsw.arch_readin = x86_efi_readin; - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ return (EFI_SUCCESS); /* keep compiler happy */ } Modified: head/sys/boot/common/bootstrap.h ============================================================================== --- head/sys/boot/common/bootstrap.h Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/common/bootstrap.h Sun Jul 27 16:12:51 2014 (r269153) @@ -59,7 +59,7 @@ extern char command_errbuf[]; /* XXX bla #define CMD_ERROR 1 /* interp.c */ -void interact(void); +void interact(const char *rc); int include(const char *filename); /* interp_backslash.c */ @@ -69,7 +69,7 @@ char *backslash(char *str); int parse(int *argc, char ***argv, char *str); /* interp_forth.c */ -void bf_init(void); +void bf_init(const char *rc); int bf_run(char *line); /* boot.c */ Modified: head/sys/boot/common/interp.c ============================================================================== --- head/sys/boot/common/interp.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/common/interp.c Sun Jul 27 16:12:51 2014 (r269153) @@ -90,7 +90,7 @@ perform(int argc, char *argv[]) * Interactive mode */ void -interact(void) +interact(const char *rc) { static char input[256]; /* big enough? */ #ifndef BOOT_FORTH @@ -99,15 +99,18 @@ interact(void) #endif #ifdef BOOT_FORTH - bf_init(); + bf_init((rc) ? "" : NULL); #endif - /* - * Read our default configuration - */ - if (include("/boot/loader.rc") != CMD_OK) - include("/boot/boot.conf"); + if (rc == NULL) { + /* Read our default configuration. */ + if (include("/boot/loader.rc") != CMD_OK) + include("/boot/boot.conf"); + } else if (*rc != '\0') + include(rc); + printf("\n"); + /* * Before interacting, we might want to autoboot. */ Modified: head/sys/boot/common/interp_forth.c ============================================================================== --- head/sys/boot/common/interp_forth.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/common/interp_forth.c Sun Jul 27 16:12:51 2014 (r269153) @@ -241,7 +241,7 @@ bf_command(FICL_VM *vm) * Initialise the Forth interpreter, create all our commands as words. */ void -bf_init(void) +bf_init(const char *rc) { struct bootblk_command **cmdp; char create_buf[41]; /* 31 characters-long builtins */ @@ -271,13 +271,20 @@ bf_init(void) ficlSetEnv(bf_sys, "loader_version", (bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0')); + pInterp = ficlLookup(bf_sys, "interpret"); + /* try to load and run init file if present */ - if ((fd = open("/boot/boot.4th", O_RDONLY)) != -1) { - (void)ficlExecFD(bf_vm, fd); - close(fd); + if (rc == NULL) + rc = "/boot/boot.4th"; + if (*rc != '\0') { + fd = open(rc, O_RDONLY); + if (fd != -1) { + (void)ficlExecFD(bf_vm, fd); + close(fd); + } } - /* Do this last, so /boot/boot.4th can change it */ + /* Do this again, so that interpret can be redefined. */ pInterp = ficlLookup(bf_sys, "interpret"); } Modified: head/sys/boot/i386/libi386/libi386.h ============================================================================== --- head/sys/boot/i386/libi386/libi386.h Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/i386/libi386/libi386.h Sun Jul 27 16:12:51 2014 (r269153) @@ -121,4 +121,5 @@ int bi_load32(char *args, int *howtop, i vm_offset_t *modulep, vm_offset_t *kernend); int bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernend); +char *pxe_default_rc(void); void pxe_enable(void *pxeinfo); Modified: head/sys/boot/i386/libi386/pxe.c ============================================================================== --- head/sys/boot/i386/libi386/pxe.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/i386/libi386/pxe.c Sun Jul 27 16:12:51 2014 (r269153) @@ -694,3 +694,26 @@ readudp(struct iodesc *h, void *pkt, siz uh->uh_sport = udpread_p->s_port; return udpread_p->buffer_size; } + +char * +pxe_default_rc(void) +{ + char *rc; + size_t count, rcsz; + + /* XXX It may not be a good idea to modify the PXE boot file. */ + rc = (char *)bootplayer.bootfile; + rcsz = sizeof(bootplayer.bootfile); + + /* Ignore how we define rc and rcsz above -- it can change. */ + if (rcsz < 6) + return (NULL); + if (*rc == '\0') { + strncpy(rc, "pxeboot", rcsz); + rc[rcsz - 1] = '\0'; + } + count = strlen(rc); + strncat(rc, ".4th", rcsz - count - 1); + printf("PXE: loading Forth from %s\n", rc); + return (rc); +} Modified: head/sys/boot/i386/loader/main.c ============================================================================== --- head/sys/boot/i386/loader/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/i386/loader/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -192,7 +192,12 @@ main(void) bios_getsmap(); - interact(); /* doesn't return */ +#ifdef LOADER_TFTP_SUPPORT + if (kargs->bootflags & KARGS_FLAGS_PXE) + interact(pxe_default_rc()); + else +#endif + interact(NULL); /* if we ever get here, it is an error */ return (1); Modified: head/sys/boot/mips/beri/loader/main.c ============================================================================== --- head/sys/boot/mips/beri/loader/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/mips/beri/loader/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -151,7 +151,7 @@ main(int argc, char *argv[], char *envv[ printf("bootpath=\"%s\"\n", bootpath); #endif - interact(); + interact(NULL); return (0); } Modified: head/sys/boot/ofw/common/main.c ============================================================================== --- head/sys/boot/ofw/common/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/ofw/common/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -162,7 +162,7 @@ main(int (*openfirm)(void *)) archsw.arch_readin = ofw_readin; archsw.arch_autoload = ofw_autoload; - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ OF_exit(); Modified: head/sys/boot/pc98/loader/main.c ============================================================================== --- head/sys/boot/pc98/loader/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/pc98/loader/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -193,7 +193,7 @@ main(void) extract_currdev(); /* set $currdev and $loaddev */ setenv("LINES", "24", 1); /* optional */ - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ /* if we ever get here, it is an error */ return (1); Modified: head/sys/boot/powerpc/ps3/main.c ============================================================================== --- head/sys/boot/powerpc/ps3/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/powerpc/ps3/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -145,7 +145,7 @@ main(void) setenv("LINES", "24", 1); setenv("hw.platform", "ps3", 1); - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ return (0); } Modified: head/sys/boot/sparc64/loader/main.c ============================================================================== --- head/sys/boot/sparc64/loader/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/sparc64/loader/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -897,7 +897,7 @@ main(int (*openfirm)(void *)) printf("bootpath=\"%s\"\n", bootpath); /* Give control to the machine independent loader code. */ - interact(); + interact(NULL); return (1); } Modified: head/sys/boot/uboot/common/main.c ============================================================================== --- head/sys/boot/uboot/common/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/uboot/common/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -492,7 +492,7 @@ main(void) archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ return (0); } Modified: head/sys/boot/userboot/userboot/main.c ============================================================================== --- head/sys/boot/userboot/userboot/main.c Sun Jul 27 08:44:15 2014 (r269152) +++ head/sys/boot/userboot/userboot/main.c Sun Jul 27 16:12:51 2014 (r269153) @@ -141,7 +141,7 @@ loader_main(struct loader_callbacks *cb, if (setjmp(jb)) return; - interact(); /* doesn't return */ + interact(NULL); /* doesn't return */ exit(0); }