Index: distrib/common/Makefile.minirootkmod =================================================================== RCS file: /cvsroot/src/distrib/common/Makefile.minirootkmod,v retrieving revision 1.3 diff -u -p -u -r1.3 Makefile.minirootkmod --- distrib/common/Makefile.minirootkmod 5 Aug 2014 15:40:58 -0000 1.3 +++ distrib/common/Makefile.minirootkmod 4 Apr 2020 19:35:33 -0000 @@ -36,7 +36,11 @@ PROG= ${MINIROOT}.kmod # RAMDISKFS is the ramdisk image to be included inside DSTMOD. It should # already have been created by the Makefile in RAMDISKSRCDIR. # +.if ${KERNEL_DIR:U*no} == "yes" +SRCMOD= ${DESTDIR}/netbsd/modules/miniroot/miniroot.kmod +.else SRCMOD= ${DESTDIR}/stand/${MACHINE}/${MODULEVER}/modules/miniroot/miniroot.kmod +.endif DSTMOD= ${.OBJDIR}/${MINIROOT}.kmod RAMDISKSRCDIR= ${.CURDIR}/../ramdisks/${RAMDISK} RAMDISKOBJDIR!= cd ${RAMDISKSRCDIR} && ${PRINTOBJDIR} Index: distrib/sets/mkvars.mk =================================================================== RCS file: /cvsroot/src/distrib/sets/mkvars.mk,v retrieving revision 1.37 diff -u -p -u -r1.37 mkvars.mk --- distrib/sets/mkvars.mk 16 Apr 2019 21:20:51 -0000 1.37 +++ distrib/sets/mkvars.mk 4 Apr 2020 19:35:33 -0000 @@ -16,6 +16,7 @@ MKEXTRAVARS= \ OBJECT_FMT \ TOOLCHAIN_MISSING \ EXTSRCS \ + KERNEL_DIR \ MKMANZ \ MKBFD \ MKCOMPAT \ Index: distrib/sets/sets.subr =================================================================== RCS file: /cvsroot/src/distrib/sets/sets.subr,v retrieving revision 1.187 diff -u -p -u -r1.187 sets.subr --- distrib/sets/sets.subr 2 Oct 2019 11:16:00 -0000 1.187 +++ distrib/sets/sets.subr 4 Apr 2020 19:35:33 -0000 @@ -168,7 +168,11 @@ xlists="xbase xcomp $xdebugset xetc xfon extlists="extbase extcomp extetc" OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k) -MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" +if [ "${KERNEL_DIR}" = "yes" ]; then + MODULEDIR="netbsd/modules" +else + MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules" +fi SUBST="s#@MODULEDIR@#${MODULEDIR}#g" SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g" SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g" Index: distrib/sets/lists/base/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/base/mi,v retrieving revision 1.1238 diff -u -p -u -r1.1238 mi --- distrib/sets/lists/base/mi 4 Apr 2020 15:39:15 -0000 1.1238 +++ distrib/sets/lists/base/mi 4 Apr 2020 19:35:34 -0000 @@ -660,6 +660,7 @@ ./sbin/zfs base-zfs-bin zfs ./sbin/zpool base-zfs-bin zfs ./stand base-sys-root +./netbsd base-sys-root kernel_dir ./tmp base-sys-root ./usr base-sys-root ./usr/bin base-sys-usr Index: distrib/sets/lists/modules/mi =================================================================== RCS file: /cvsroot/src/distrib/sets/lists/modules/mi,v retrieving revision 1.135 diff -u -p -u -r1.135 mi --- distrib/sets/lists/modules/mi 4 Apr 2020 15:39:16 -0000 1.135 +++ distrib/sets/lists/modules/mi 4 Apr 2020 19:35:34 -0000 @@ -481,5 +481,6 @@ ./@MODULEDIR@/zlib modules-base-kernel kmod ./@MODULEDIR@/zlib/zlib.kmod modules-base-kernel kmod ./etc/mtree/set.modules modules-sys-root kmod -./stand/@MACHINE@ modules-base-kernel kmod -./stand/@MACHINE@/@OSRELEASE@ modules-base-kernel kmod +./stand/@MACHINE@ modules-base-kernel kmod,!kernel_dir +./stand/@MACHINE@/@OSRELEASE@ modules-base-kernel kmod,!kernel_dir +./netbsd kmod,kernel_dir Index: etc/Makefile =================================================================== RCS file: /cvsroot/src/etc/Makefile,v retrieving revision 1.441 diff -u -p -u -r1.441 Makefile --- etc/Makefile 2 Oct 2019 11:16:00 -0000 1.441 +++ etc/Makefile 4 Apr 2020 19:35:34 -0000 @@ -621,21 +621,46 @@ kernset-${configfile}: .PHONY build_kern ks="$${kernel}$${s}"; \ [ -f $${ks} ] || continue; \ kernels="$${kernels} $${ks}"; \ - [ -z "$${newest}" -o $${ks} -nt "$${newest}" ] && \ - newest=$${ks}; \ + [ -z "$${newest}" -o $${ks} \ + -nt "$${newest}" ] && newest=$${ks}; \ done; \ done; \ [ $${kern_tgz} -nt "$${newest}" ] || { \ echo "echo $${kernels} | $${pax_cmd}"; \ + if [ ${KERNELDIR} = "yes" ]; them \ + tmpdir=kernel$$; \ + trap "rm -fr $${tmpdir}" 0 1 2 3 15; \ + mkdir -p $${tmpdir}/netbsd; \ + d=./netbsd; \ + cd $${tmpdir}; \ + else \ + d=.; \ + fi; \ ( echo "/set uname=${BINOWN} gname=${BINGRP}"; \ echo ". type=dir optional"; \ + if [ ${KERNEL_DIR} = "yes" ]; then \ + echo "./netbsd type=dir optional"; \ + fi; \ dtblist=$$(${MAKE} -v DTB); \ for dtb in $${dtblist}; do \ - echo "./$${dtb} type=file"; \ + if [ ${KERNEL_DIR} = "yes" ]; then \ + ln ../$${dtb} ./netbsd/$${dtb}; \ + fi; \ + echo "$${d}/$${dtb} type=file"; \ done; \ for kernel in $${kernels}; do \ - echo "./$${kernel} type=file"; \ + if [ ${KERNEL_DIR} = "yes" ]; then \ + newname=$$(echo $${kernel} | \ + ${TOOL_SED} -e s/netbsd/kernel/); \ + ln ../$${kernel} ./netbsd/$${newname}; \ + else \ + newname=$${kernel}; \ + fi; \ + echo "$${d}/$${newname} type=file"; \ done ) | eval $${pax_cmd}; \ + if [ ${KERNEL_DIR} = "yes" ]; then \ + mv $${kern_tgz} ..; \ + fi; \ } \ } .endif Index: share/mk/bsd.kmodule.mk =================================================================== RCS file: /cvsroot/src/share/mk/bsd.kmodule.mk,v retrieving revision 1.63 diff -u -p -u -r1.63 bsd.kmodule.mk --- share/mk/bsd.kmodule.mk 1 Dec 2019 20:24:47 -0000 1.63 +++ share/mk/bsd.kmodule.mk 4 Apr 2020 19:35:34 -0000 @@ -172,7 +172,13 @@ ${PROG}: ${OBJS} ${DPADD} ${KMODSCRIPT} ##### Install rules .if !target(kmodinstall) .if !defined(KMODULEDIR) +.if ${KERNEL_DIR:Uno} == "yes" +KMODULEDIR= ${DESTDIR}/netbsd/modules/${KMOD} +_INST_DIRS= ${DESTDIR}/netbsd +_INST_DIRS+= ${DESTDIR}/netbsd/modules +_INST_DIRS+= ${DESTDIR}/netbsd/modules/${KMOD} _OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh -k +.else # Ensure these are recorded properly in METALOG on unprived installes: KMODULEARCHDIR?= ${MACHINE} _INST_DIRS= ${DESTDIR}/stand/${KMODULEARCHDIR} @@ -180,6 +186,7 @@ _INST_DIRS+= ${DESTDIR}/stand/${KMODULEA _INST_DIRS+= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules KMODULEDIR= ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD} .endif +.endif _PROG:= ${KMODULEDIR}/${PROG} # installed path .if ${MKUPDATE} == "no" Index: sys/arch/i386/stand/boot/Makefile.boot =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/boot/Makefile.boot,v retrieving revision 1.73 diff -u -p -u -r1.73 Makefile.boot --- sys/arch/i386/stand/boot/Makefile.boot 13 Sep 2019 02:19:45 -0000 1.73 +++ sys/arch/i386/stand/boot/Makefile.boot 4 Apr 2020 19:35:34 -0000 @@ -53,6 +53,10 @@ CFLAGS+= -Wall -Wmissing-prototypes -Wst CPPFLAGS+= -nostdinc -D_STANDALONE CPPFLAGS+= -I$S +.if ${KERNEL_DIR:Uno} == "yes" +CPPFLAGS+= -DKERNEL_DIR +.endif + CPPFLAGS+= -DSUPPORT_PS2 CPPFLAGS+= -DDIRECT_SERIAL CPPFLAGS+= -DSUPPORT_SERIAL=boot_params.bp_consdev Index: sys/arch/i386/stand/boot/boot2.c =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/boot/boot2.c,v retrieving revision 1.72 diff -u -p -u -r1.72 boot2.c --- sys/arch/i386/stand/boot/boot2.c 2 Sep 2019 06:10:24 -0000 1.72 +++ sys/arch/i386/stand/boot/boot2.c 4 Apr 2020 19:35:34 -0000 @@ -279,6 +279,12 @@ bootit(const char *filename, int howto) if (howto & AB_VERBOSE) printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename), howto); +#ifdef KERNEL_DIR + char path[512]; + strcpy(path, filename); + strcat(path, "/kernel"); + (void)exec_netbsd(path, 0, howto, boot_biosdev < 0x80, clearit); +#endif if (exec_netbsd(filename, 0, howto, boot_biosdev < 0x80, clearit) < 0) printf("boot: %s: %s\n", sprint_bootsel(filename), Index: sys/arch/i386/stand/lib/exec.c =================================================================== RCS file: /cvsroot/src/sys/arch/i386/stand/lib/exec.c,v retrieving revision 1.75 diff -u -p -u -r1.75 exec.c --- sys/arch/i386/stand/lib/exec.c 7 Dec 2019 02:29:03 -0000 1.75 +++ sys/arch/i386/stand/lib/exec.c 4 Apr 2020 19:35:34 -0000 @@ -151,7 +151,7 @@ static void module_add_common(const char static void userconf_init(void); static void extract_device(const char *, char *, size_t); -static void module_base_path(char *, size_t); +static void module_base_path(char *, size_t, const char *); static int module_open(boot_module_t *, int, const char *, const char *, bool); @@ -653,8 +653,15 @@ module_open(boot_module_t *bm, int mode, } static void -module_base_path(char *buf, size_t bufsize) +module_base_path(char *buf, size_t bufsize, const char *kernel_path) { +#ifdef KERNEL_DIR + /* we cheat here, because %.* does not work with the mini printf */ + char *ptr = strrchr(kernel_path, '/'); + if (ptr) *ptr = '\0'; + snprintf(buf, bufsize, "%s/modules", kernel_path); + if (ptr) *ptr = '/'; +#else const char *machine; switch (netbsd_elf_class) { @@ -682,6 +689,7 @@ module_base_path(char *buf, size_t bufsi netbsd_version / 100000000, netbsd_version / 1000000 % 100); } +#endif } static void @@ -697,7 +705,7 @@ module_init(const char *kernel_path) int err, fd, nfail = 0; extract_device(kernel_path, kdev, sizeof(kdev)); - module_base_path(module_base, sizeof(module_base)); + module_base_path(module_base, sizeof(module_base), kernel_path); /* First, see which modules are valid and calculate btinfo size */ len = sizeof(struct btinfo_modulelist); Index: sys/arch/x86/x86/x86_machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/x86/x86_machdep.c,v retrieving revision 1.136 diff -u -p -u -r1.136 x86_machdep.c --- sys/arch/x86/x86/x86_machdep.c 4 Apr 2020 14:49:35 -0000 1.136 +++ sys/arch/x86/x86/x86_machdep.c 4 Apr 2020 19:35:34 -0000 @@ -1160,6 +1160,13 @@ x86_startup(void) #endif } +const char * +get_booted_kernel(void) +{ + const struct btinfo_bootpath *bibp = lookup_bootinfo(BTINFO_BOOTPATH); + return bibp ? bibp->bootpath : NULL; +} + /* * machine dependent system variables. */ Index: sys/conf/Makefile.kern.inc =================================================================== RCS file: /cvsroot/src/sys/conf/Makefile.kern.inc,v retrieving revision 1.268 diff -u -p -u -r1.268 Makefile.kern.inc --- sys/conf/Makefile.kern.inc 5 Feb 2019 08:33:25 -0000 1.268 +++ sys/conf/Makefile.kern.inc 4 Apr 2020 19:35:34 -0000 @@ -66,6 +66,9 @@ CPPFLAGS+= ${INCLUDES} ${IDENT} -D_KERNE .if !defined(COVERITY_TOP_CONFIG) CPPFLAGS+= -std=gnu99 .endif +.if ${KERNEL_DIR:Uno} == "yes" +CPPFLAGS+= -DKERNEL_DIR +.endif DEFCOPTS?= -O2 COPTS?= ${DEFCOPTS} DBG= # might contain unwanted -Ofoo @@ -413,10 +416,17 @@ install: install-kernel-${MACHINE_NAME} .if !target(install-kernel-${MACHINE_NAME}) install-kernel-${MACHINE_NAME}: .for _K in ${KERNIMAGES} +.if ${KERNEL_DIR:Uno} == "yes" + rm -fr ${DESTDIR}/o${_K} + mv ${DESTDIR}/${_K} ${DESTDIR}/o${_K} + mkdir -p ${DESTDIR}/${_K} + cp ${_K} ${DESTDIR}/${_K}/kernel +.else rm -f ${DESTDIR}/o${_K} ln ${DESTDIR}/${_K} ${DESTDIR}/o${_K} cp ${_K} ${DESTDIR}/n${_K} mv ${DESTDIR}/n${_K} ${DESTDIR}/${_K} +.endif .endfor .endif .endif Index: sys/kern/kern_module.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_module.c,v retrieving revision 1.148 diff -u -p -u -r1.148 kern_module.c --- sys/kern/kern_module.c 20 Mar 2020 23:09:01 -0000 1.148 +++ sys/kern/kern_module.c 4 Apr 2020 19:35:34 -0000 @@ -421,6 +421,12 @@ module_init(void) module_init_md(); #endif +#ifdef KERNEL_DIR + const char *booted_kernel = get_booted_kernel(); + char *ptr = strrchr(booted_kernel, '/'); + snprintf(module_base, sizeof(module_base), "/%.*s/modules", + (int)(ptr - booted_kernel), booted_kernel); +#else if (!module_machine) module_machine = machine; #if __NetBSD_Version__ / 1000000 % 100 == 99 /* -current */ @@ -431,6 +437,7 @@ module_init(void) module_machine, __NetBSD_Version__ / 100000000, __NetBSD_Version__ / 1000000 % 100); #endif +#endif module_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM, module_listener_cb, NULL); Index: sys/sys/systm.h =================================================================== RCS file: /cvsroot/src/sys/sys/systm.h,v retrieving revision 1.293 diff -u -p -u -r1.293 systm.h --- sys/sys/systm.h 8 Feb 2020 07:07:07 -0000 1.293 +++ sys/sys/systm.h 4 Apr 2020 19:35:34 -0000 @@ -166,6 +166,8 @@ extern int boothowto; /* reboot flags, #define bootverbose (boothowto & AB_VERBOSE) #define bootquiet (boothowto & AB_QUIET) +extern const char *get_booted_kernel(void); + extern void (*v_putc)(int); /* Virtual console putc routine */ /*