Module Name: src Committed By: christos Date: Sat Apr 4 19:50:54 UTC 2020
Modified Files: src/distrib/common: Makefile.minirootkmod src/distrib/sets: mkvars.mk sets.subr src/distrib/sets/lists/base: mi src/distrib/sets/lists/modules: mi src/etc: Makefile src/share/mk: bsd.kmodule.mk src/sys/arch/i386/stand/boot: Makefile.boot boot2.c src/sys/arch/i386/stand/lib: exec.c src/sys/arch/x86/x86: x86_machdep.c src/sys/conf: Makefile.kern.inc src/sys/kern: kern_module.c src/sys/sys: systm.h Log Message: Infrastructure for putting kernel+modules in /netbsd/kernel and /netbsd/modules respectively instead of /netbsd and /stand/<arch>/<version>/modules. This is only supported for x86, and is turned off by default. To try it, add KERNEL_DIR=yes in your /mk.conf and install a system from that build. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/distrib/common/Makefile.minirootkmod cvs rdiff -u -r1.37 -r1.38 src/distrib/sets/mkvars.mk cvs rdiff -u -r1.187 -r1.188 src/distrib/sets/sets.subr cvs rdiff -u -r1.1238 -r1.1239 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.135 -r1.136 src/distrib/sets/lists/modules/mi cvs rdiff -u -r1.441 -r1.442 src/etc/Makefile cvs rdiff -u -r1.63 -r1.64 src/share/mk/bsd.kmodule.mk cvs rdiff -u -r1.73 -r1.74 src/sys/arch/i386/stand/boot/Makefile.boot cvs rdiff -u -r1.72 -r1.73 src/sys/arch/i386/stand/boot/boot2.c cvs rdiff -u -r1.75 -r1.76 src/sys/arch/i386/stand/lib/exec.c cvs rdiff -u -r1.136 -r1.137 src/sys/arch/x86/x86/x86_machdep.c cvs rdiff -u -r1.268 -r1.269 src/sys/conf/Makefile.kern.inc cvs rdiff -u -r1.148 -r1.149 src/sys/kern/kern_module.c cvs rdiff -u -r1.293 -r1.294 src/sys/sys/systm.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/common/Makefile.minirootkmod diff -u src/distrib/common/Makefile.minirootkmod:1.3 src/distrib/common/Makefile.minirootkmod:1.4 --- src/distrib/common/Makefile.minirootkmod:1.3 Tue Aug 5 11:40:58 2014 +++ src/distrib/common/Makefile.minirootkmod Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.minirootkmod,v 1.3 2014/08/05 15:40:58 apb Exp $ +# $NetBSD: Makefile.minirootkmod,v 1.4 2020/04/04 19:50:53 christos Exp $ # # Makefile snippet to build a miniroot kernel module (e.g. miniroot.kmod) # @@ -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: src/distrib/sets/mkvars.mk diff -u src/distrib/sets/mkvars.mk:1.37 src/distrib/sets/mkvars.mk:1.38 --- src/distrib/sets/mkvars.mk:1.37 Tue Apr 16 17:20:51 2019 +++ src/distrib/sets/mkvars.mk Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mkvars.mk,v 1.37 2019/04/16 21:20:51 mrg Exp $ +# $NetBSD: mkvars.mk,v 1.38 2020/04/04 19:50:53 christos Exp $ MKEXTRAVARS= \ MACHINE \ @@ -16,6 +16,7 @@ MKEXTRAVARS= \ OBJECT_FMT \ TOOLCHAIN_MISSING \ EXTSRCS \ + KERNEL_DIR \ MKMANZ \ MKBFD \ MKCOMPAT \ Index: src/distrib/sets/sets.subr diff -u src/distrib/sets/sets.subr:1.187 src/distrib/sets/sets.subr:1.188 --- src/distrib/sets/sets.subr:1.187 Wed Oct 2 07:16:00 2019 +++ src/distrib/sets/sets.subr Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: sets.subr,v 1.187 2019/10/02 11:16:00 maya Exp $ +# $NetBSD: sets.subr,v 1.188 2020/04/04 19:50:53 christos Exp $ # # @@ -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" @@ -180,7 +184,7 @@ SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g # In each file, a record consists of a path and a System Package name, # separated by whitespace. E.g., # -# # $NetBSD: sets.subr,v 1.187 2019/10/02 11:16:00 maya Exp $ +# # $NetBSD: sets.subr,v 1.188 2020/04/04 19:50:53 christos Exp $ # . base-sys-root [keyword[,...]] # ./altroot base-sys-root # ./bin base-sys-root Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1238 src/distrib/sets/lists/base/mi:1.1239 --- src/distrib/sets/lists/base/mi:1.1238 Sat Apr 4 11:39:15 2020 +++ src/distrib/sets/lists/base/mi Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1238 2020/04/04 15:39:15 jdolecek Exp $ +# $NetBSD: mi,v 1.1239 2020/04/04 19:50:53 christos Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -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: src/distrib/sets/lists/modules/mi diff -u src/distrib/sets/lists/modules/mi:1.135 src/distrib/sets/lists/modules/mi:1.136 --- src/distrib/sets/lists/modules/mi:1.135 Sat Apr 4 11:39:16 2020 +++ src/distrib/sets/lists/modules/mi Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.135 2020/04/04 15:39:16 jdolecek Exp $ +# $NetBSD: mi,v 1.136 2020/04/04 19:50:53 christos Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -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: src/etc/Makefile diff -u src/etc/Makefile:1.441 src/etc/Makefile:1.442 --- src/etc/Makefile:1.441 Wed Oct 2 07:16:00 2019 +++ src/etc/Makefile Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.441 2019/10/02 11:16:00 maya Exp $ +# $NetBSD: Makefile,v 1.442 2020/04/04 19:50:53 christos Exp $ # from: @(#)Makefile 8.7 (Berkeley) 5/25/95 # Environment variables without default values: @@ -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: src/share/mk/bsd.kmodule.mk diff -u src/share/mk/bsd.kmodule.mk:1.63 src/share/mk/bsd.kmodule.mk:1.64 --- src/share/mk/bsd.kmodule.mk:1.63 Sun Dec 1 15:24:47 2019 +++ src/share/mk/bsd.kmodule.mk Sat Apr 4 15:50:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: bsd.kmodule.mk,v 1.63 2019/12/01 20:24:47 jmcneill Exp $ +# $NetBSD: bsd.kmodule.mk,v 1.64 2020/04/04 19:50:53 christos Exp $ # We are not building this with PIE MKPIE=no @@ -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: src/sys/arch/i386/stand/boot/Makefile.boot diff -u src/sys/arch/i386/stand/boot/Makefile.boot:1.73 src/sys/arch/i386/stand/boot/Makefile.boot:1.74 --- src/sys/arch/i386/stand/boot/Makefile.boot:1.73 Thu Sep 12 22:19:45 2019 +++ src/sys/arch/i386/stand/boot/Makefile.boot Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.boot,v 1.73 2019/09/13 02:19:45 manu Exp $ +# $NetBSD: Makefile.boot,v 1.74 2020/04/04 19:50:54 christos Exp $ S= ${.CURDIR}/../../../../.. @@ -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: src/sys/arch/i386/stand/boot/boot2.c diff -u src/sys/arch/i386/stand/boot/boot2.c:1.72 src/sys/arch/i386/stand/boot/boot2.c:1.73 --- src/sys/arch/i386/stand/boot/boot2.c:1.72 Mon Sep 2 02:10:24 2019 +++ src/sys/arch/i386/stand/boot/boot2.c Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: boot2.c,v 1.72 2019/09/02 06:10:24 manu Exp $ */ +/* $NetBSD: boot2.c,v 1.73 2020/04/04 19:50:54 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -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: src/sys/arch/i386/stand/lib/exec.c diff -u src/sys/arch/i386/stand/lib/exec.c:1.75 src/sys/arch/i386/stand/lib/exec.c:1.76 --- src/sys/arch/i386/stand/lib/exec.c:1.75 Fri Dec 6 21:29:03 2019 +++ src/sys/arch/i386/stand/lib/exec.c Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.75 2019/12/07 02:29:03 christos Exp $ */ +/* $NetBSD: exec.c,v 1.76 2020/04/04 19:50:54 christos Exp $ */ /* * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -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: src/sys/arch/x86/x86/x86_machdep.c diff -u src/sys/arch/x86/x86/x86_machdep.c:1.136 src/sys/arch/x86/x86/x86_machdep.c:1.137 --- src/sys/arch/x86/x86/x86_machdep.c:1.136 Sat Apr 4 10:49:35 2020 +++ src/sys/arch/x86/x86/x86_machdep.c Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: x86_machdep.c,v 1.136 2020/04/04 14:49:35 ad Exp $ */ +/* $NetBSD: x86_machdep.c,v 1.137 2020/04/04 19:50:54 christos Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.136 2020/04/04 14:49:35 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.137 2020/04/04 19:50:54 christos Exp $"); #include "opt_modular.h" #include "opt_physmem.h" @@ -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: src/sys/conf/Makefile.kern.inc diff -u src/sys/conf/Makefile.kern.inc:1.268 src/sys/conf/Makefile.kern.inc:1.269 --- src/sys/conf/Makefile.kern.inc:1.268 Tue Feb 5 03:33:25 2019 +++ src/sys/conf/Makefile.kern.inc Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.kern.inc,v 1.268 2019/02/05 08:33:25 mrg Exp $ +# $NetBSD: Makefile.kern.inc,v 1.269 2020/04/04 19:50:54 christos Exp $ # # This file contains common `MI' targets and definitions and it is included # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}. @@ -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: src/sys/kern/kern_module.c diff -u src/sys/kern/kern_module.c:1.148 src/sys/kern/kern_module.c:1.149 --- src/sys/kern/kern_module.c:1.148 Fri Mar 20 19:09:01 2020 +++ src/sys/kern/kern_module.c Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.148 2020/03/20 23:09:01 pgoyette Exp $ */ +/* $NetBSD: kern_module.c,v 1.149 2020/04/04 19:50:54 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.148 2020/03/20 23:09:01 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.149 2020/04/04 19:50:54 christos Exp $"); #define _MODULE_INTERNAL @@ -421,6 +421,18 @@ module_init(void) module_init_md(); #endif +#ifdef KERNEL_DIR + const char *booted_kernel = get_booted_kernel(); + if (booted_kernel) { + char *ptr = strrchr(booted_kernel, '/'); + snprintf(module_base, sizeof(module_base), "/%.*s/modules", + (int)(ptr - booted_kernel), booted_kernel); + } else { + strlcpy(module_base, "/netbsd/modules", sizeof(module_base)); + printf("Cannot find kernel name, loading modules from \"%s\"\n", + module_base); + } +#else if (!module_machine) module_machine = machine; #if __NetBSD_Version__ / 1000000 % 100 == 99 /* -current */ @@ -431,6 +443,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: src/sys/sys/systm.h diff -u src/sys/sys/systm.h:1.293 src/sys/sys/systm.h:1.294 --- src/sys/sys/systm.h:1.293 Sat Feb 8 02:07:07 2020 +++ src/sys/sys/systm.h Sat Apr 4 15:50:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: systm.h,v 1.293 2020/02/08 07:07:07 maxv Exp $ */ +/* $NetBSD: systm.h,v 1.294 2020/04/04 19:50:54 christos Exp $ */ /*- * Copyright (c) 1982, 1988, 1991, 1993 @@ -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 */ /*