Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Infrastructure for putting kernel+modules in /netbsd/kernel and



details:   https://anonhg.NetBSD.org/src/rev/eb3a1131848f
branches:  trunk
changeset: 850450:eb3a1131848f
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 04 19:50:53 2020 +0000

description:
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.

diffstat:

 distrib/common/Makefile.minirootkmod   |   6 ++++-
 distrib/sets/lists/base/mi             |   3 +-
 distrib/sets/lists/modules/mi          |   7 +++--
 distrib/sets/mkvars.mk                 |   3 +-
 distrib/sets/sets.subr                 |  10 ++++++--
 etc/Makefile                           |  35 +++++++++++++++++++++++++++++----
 share/mk/bsd.kmodule.mk                |   9 +++++++-
 sys/arch/i386/stand/boot/Makefile.boot |   6 ++++-
 sys/arch/i386/stand/boot/boot2.c       |   8 ++++++-
 sys/arch/i386/stand/lib/exec.c         |  16 +++++++++++---
 sys/arch/x86/x86/x86_machdep.c         |  11 ++++++++-
 sys/conf/Makefile.kern.inc             |  12 ++++++++++-
 sys/kern/kern_module.c                 |  17 ++++++++++++++-
 sys/sys/systm.h                        |   4 ++-
 14 files changed, 120 insertions(+), 27 deletions(-)

diffs (truncated from 421 to 300 lines):

diff -r 730d2f55e68e -r eb3a1131848f distrib/common/Makefile.minirootkmod
--- a/distrib/common/Makefile.minirootkmod      Sat Apr 04 19:46:01 2020 +0000
+++ b/distrib/common/Makefile.minirootkmod      Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
 # 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}
diff -r 730d2f55e68e -r eb3a1131848f distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sat Apr 04 19:46:01 2020 +0000
+++ b/distrib/sets/lists/base/mi        Sat Apr 04 19:50:53 2020 +0000
@@ -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
diff -r 730d2f55e68e -r eb3a1131848f distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Sat Apr 04 19:46:01 2020 +0000
+++ b/distrib/sets/lists/modules/mi     Sat Apr 04 19:50:53 2020 +0000
@@ -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
diff -r 730d2f55e68e -r eb3a1131848f distrib/sets/mkvars.mk
--- a/distrib/sets/mkvars.mk    Sat Apr 04 19:46:01 2020 +0000
+++ b/distrib/sets/mkvars.mk    Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
        OBJECT_FMT \
        TOOLCHAIN_MISSING \
        EXTSRCS \
+       KERNEL_DIR \
        MKMANZ \
        MKBFD \
        MKCOMPAT \
diff -r 730d2f55e68e -r eb3a1131848f distrib/sets/sets.subr
--- a/distrib/sets/sets.subr    Sat Apr 04 19:46:01 2020 +0000
+++ b/distrib/sets/sets.subr    Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
 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 @@
 # 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
diff -r 730d2f55e68e -r eb3a1131848f etc/Makefile
--- a/etc/Makefile      Sat Apr 04 19:46:01 2020 +0000
+++ b/etc/Makefile      Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
                                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
diff -r 730d2f55e68e -r eb3a1131848f share/mk/bsd.kmodule.mk
--- a/share/mk/bsd.kmodule.mk   Sat Apr 04 19:46:01 2020 +0000
+++ b/share/mk/bsd.kmodule.mk   Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
 ##### 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/${KMODULEARCHDIR}/${_OSRELEASE}/modules
 KMODULEDIR=    ${DESTDIR}/stand/${KMODULEARCHDIR}/${_OSRELEASE}/modules/${KMOD}
 .endif
+.endif
 _PROG:=                ${KMODULEDIR}/${PROG} # installed path
 
 .if ${MKUPDATE} == "no"
diff -r 730d2f55e68e -r eb3a1131848f sys/arch/i386/stand/boot/Makefile.boot
--- a/sys/arch/i386/stand/boot/Makefile.boot    Sat Apr 04 19:46:01 2020 +0000
+++ b/sys/arch/i386/stand/boot/Makefile.boot    Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
 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
diff -r 730d2f55e68e -r eb3a1131848f sys/arch/i386/stand/boot/boot2.c
--- a/sys/arch/i386/stand/boot/boot2.c  Sat Apr 04 19:46:01 2020 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c  Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
        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),
diff -r 730d2f55e68e -r eb3a1131848f sys/arch/i386/stand/lib/exec.c
--- a/sys/arch/i386/stand/lib/exec.c    Sat Apr 04 19:46:01 2020 +0000
+++ b/sys/arch/i386/stand/lib/exec.c    Sat Apr 04 19:50:53 2020 +0000
@@ -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    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 @@
 }
 
 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 @@
                    netbsd_version / 100000000,
                    netbsd_version / 1000000 % 100);
        }
+#endif
 }
 
 static void
@@ -697,7 +705,7 @@
        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);
diff -r 730d2f55e68e -r eb3a1131848f sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Sat Apr 04 19:46:01 2020 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Sat Apr 04 19:50:53 2020 +0000
@@ -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 @@
  */



Home | Main Index | Thread Index | Old Index