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 18 Feb 2020 01:08:16 -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 18 Feb 2020 01:08:17 -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 18 Feb 2020 01:08:17 -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 18 Feb 2020 01:08:17 -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.135 diff -u -p -u -r1.135 x86_machdep.c --- sys/arch/x86/x86/x86_machdep.c 29 Jan 2020 01:54:34 -0000 1.135 +++ sys/arch/x86/x86/x86_machdep.c 18 Feb 2020 01:08:17 -0000 @@ -1161,6 +1161,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 18 Feb 2020 01:08:18 -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.146 diff -u -p -u -r1.146 kern_module.c --- sys/kern/kern_module.c 22 Jan 2020 22:39:27 -0000 1.146 +++ sys/kern/kern_module.c 18 Feb 2020 01:08:19 -0000 @@ -420,6 +420,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 */ @@ -430,6 +436,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 18 Feb 2020 01:08:20 -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 */ /* 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 18 Feb 2020 01:15:22 -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 18 Feb 2020 01:15:22 -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.1229 diff -u -p -u -r1.1229 mi --- distrib/sets/lists/base/mi 11 Feb 2020 11:36:52 -0000 1.1229 +++ distrib/sets/lists/base/mi 18 Feb 2020 01:12:28 -0000 @@ -652,6 +652,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.132 diff -u -p -u -r1.132 mi --- distrib/sets/lists/modules/mi 11 Feb 2020 11:36:53 -0000 1.132 +++ distrib/sets/lists/modules/mi 18 Feb 2020 01:08:23 -0000 @@ -483,5 +483,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