From 380fe3ed0618430ecab804cb78e0e22774e8936a Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Fri, 21 Jun 2024 14:14:49 -0600 Subject: [PATCH 1/5] configkernel: config comment cosmetics This alters the "# comment lines" in _GENERIC_CONFIG_OPTIONAL, etc by changing "# " to "##: ". This purely cosmetic change allowed me to trivially confirm the misbehavior addressed in the next patch. Signed-off-by: Jim Cromie --- virtme/commands/configkernel.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/virtme/commands/configkernel.py b/virtme/commands/configkernel.py index d6ed70d..f58eee7 100644 --- a/virtme/commands/configkernel.py +++ b/virtme/commands/configkernel.py @@ -103,7 +103,7 @@ def arg_fail(message): _GENERIC_CONFIG = [ - "# Generic", + "##: Generic", "CONFIG_UEVENT_HELPER=n", # Obsolete and slow "CONFIG_VIRTIO=y", "CONFIG_VIRTIO_PCI=y", @@ -131,25 +131,25 @@ def arg_fail(message): "CONFIG_EARLY_PRINTK=y", "CONFIG_INOTIFY_USER=y", "", - "# virtio-scsi support", + "##: virtio-scsi support", "CONFIG_BLOCK=y", "CONFIG_SCSI_LOWLEVEL=y", "CONFIG_SCSI=y", "CONFIG_SCSI_VIRTIO=y", "CONFIG_BLK_DEV_SD=y", "", - "# virt-serial support", + "##: virt-serial support", "CONFIG_VIRTIO_CONSOLE=y", "", - "# watchdog (useful for test scripts)", + "##: watchdog (useful for test scripts)", "CONFIG_WATCHDOG=y", "CONFIG_WATCHDOG_CORE=y", "CONFIG_I6300ESB_WDT=y", - "# Make sure debuginfo are available", + "##: Make sure debuginfo are available", "CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y", - "# Enable overlayfs", + "##: Enable overlayfs", "CONFIG_OVERLAY_FS=y", - "# virtio-fs support", + "##: virtio-fs support", "CONFIG_DAX=y", "CONFIG_DAX_DRIVER=y", "CONFIG_FS_DAX=y", @@ -161,9 +161,9 @@ def arg_fail(message): ] _GENERIC_CONFIG_OPTIONAL = [ - "# initramfs support", + "##: initramfs support", "CONFIG_BLK_DEV_INITRD=y", - "# BPF stuff & useful debugging features", + "##: BPF stuff & useful debugging features", "CONFIG_BPF=y", "CONFIG_BPF_SYSCALL=y", "CONFIG_BPF_JIT=y", @@ -180,16 +180,16 @@ def arg_fail(message): "CONFIG_UPROBES=y", "CONFIG_UPROBE_EVENTS=y", "CONFIG_DEBUG_FS=y", - "# Required to generate memory dumps for drgn", + "##: Required to generate memory dumps for drgn", "CONFIG_FW_CFG_SYSFS=y", "CONFIG_FW_CFG_SYSFS_CMDLINE=y", - "# Graphics support", + "##: Graphics support", "CONFIG_DRM=y", "CONFIG_DRM_VIRTIO_GPU=y", "CONFIG_DRM_VIRTIO_GPU_KMS=y", "CONFIG_DRM_BOCHS=y", "CONFIG_VIRTIO_IOMMU=y", - "# Sound support", + "##: Sound support", "CONFIG_SOUND=y", "CONFIG_SND=y", "CONFIG_SND_SEQUENCER=y", @@ -296,7 +296,7 @@ def do_it(): mod_conf = [] if args.configitem: - mod_conf += ["# final config-item mods"] + mod_conf += ["##: final config-item mods"] for conf_item in args.configitem: if not conf_item.startswith("CONFIG_"): conf_item = "CONFIG_" + conf_item @@ -307,7 +307,7 @@ def do_it(): conf = ( _GENERIC_CONFIG_OPTIONAL - + ["# Arch-specific options"] + + ["##: Arch-specific options"] + arch.config_base() + custom_conf + mod_conf From 5091389b25e644dfd0375bc8ffcc98c3e3ff80ed Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Sat, 22 Jun 2024 09:07:11 -0600 Subject: [PATCH 2/5] configkernel: act more like kernel's make O=outdir ``make O=outdir defconfig`` will: a. create the outdir as needed b. write a 1-line outdir/Makefile: "include $srcdir/Makefile" (+1 comment line) c. write outdir/.config This insures that (cd outdir; make) works. Its arguably a bug that virtme-configkernel doesnt do this. In fact, it is necessary, to fix this build error: [jimc@frodo linux.git]$ rm -r builds/t1 .config [jimc@frodo linux.git]$ virtme-configkernel --defconfig --custom ../kfrag.dyndbg O=builds/t1 make[1]: Entering directory '/home/jimc/projects/lx/linux.git/builds/t1' GEN Makefile HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.[ch] HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/menu.o HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTCC scripts/kconfig/util.o HOSTLD scripts/kconfig/conf # # configuration written to .config # make[1]: Leaving directory '/home/jimc/projects/lx/linux.git/builds/t1' make[1]: Entering directory '/home/jimc/projects/lx/linux.git/builds/t1' *** *** The source tree is not clean, please run 'make ARCH=x86 mrproper' *** in /home/jimc/projects/lx/linux.git *** make[2]: *** [/home/jimc/projects/lx/linux.git/Makefile:642: outputmakefile] Error 1 make[1]: *** [/home/jimc/projects/lx/linux.git/Makefile:240: __sub-make] Error 2 make[1]: Leaving directory '/home/jimc/projects/lx/linux.git/builds/t1' make: *** [Makefile:240: __sub-make] Error 2 The trouble is that 2 configs get written: [jimc@frodo linux.git]$ wc .config builds/t1/.config 210 533 4765 .config 5298 16766 141371 builds/t1/.config 5508 17299 146136 total The .config polluting the srcdir has the _GENERIC_CONFIG_* comments; the open "ab" is just opening an empty file, rather than the outdir/.config file, and appending its contents. If this hadn't broken the make (perhaps by writing its .config elsewhere, where the mrproper error is not triggered), it would be worse, because the proper .config isnt written, and make produces an unbootable "we are stuck" kernel. The fix is to add '-f $srcdir/Makefile' to the make-invocation, then the kernel build will write the 2-liner makefile itself. Signed-off-by: Jim Cromie --- virtme/commands/configkernel.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/virtme/commands/configkernel.py b/virtme/commands/configkernel.py index f58eee7..adc3042 100644 --- a/virtme/commands/configkernel.py +++ b/virtme/commands/configkernel.py @@ -355,11 +355,13 @@ def do_it(): # Determine if an initial config is present config = ".config" + makef = "Makefile" # Check if KBUILD_OUTPUT is defined and if it's a directory config_dir = os.environ.get("KBUILD_OUTPUT", "") if config_dir and os.path.isdir(config_dir): config = os.path.join(config_dir, config) + makef = os.path.join(config_dir, makef) if os.path.exists(config): if args.no_update: @@ -371,12 +373,23 @@ def do_it(): return 1 if maketarget is not None: + make_args = [] + if not os.path.exists(makef): + if args.verbose: + sys.stderr.write(f"missing {makef}, adding -f $src/Makefile\n") + if os.path.exists("Makefile"): + # assuming we're in linux srcdir + make_args = ["-f", str(os.path.abspath("Makefile"))] + if args.verbose: + sys.stderr.write(f"adding make_args: {make_args}\n") try: - subprocess.check_call(["make"] + archargs + [maketarget]) + subprocess.check_call(["make"] + make_args + archargs + [maketarget]) except Exception as exc: raise SilentError() from exc # Append virtme configs + if args.verbose: + sys.stderr.write(f"appending to config: {config}\n") with open(config, "ab") as conffile: conffile.write("\n".join(conf).encode("utf-8")) From afbec3758051b32f1e5e30cac57546ee6bfbb3ac Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Fri, 21 Jun 2024 10:02:40 -0600 Subject: [PATCH 3/5] vng-run: get kdir from O=outdir If O=outdir is given as an arg to vng -b, it will build the whole kernel in outdir. Then a following vng O=outdir will boot, but cannot find the modules, and lsmod shows the empty set. So for ``vng O=outdir -r``, adjust the qemu --kdir arg from the default: ./ to ./outdir. TBD: this is currently not done for -r , since the value may be a version-tag to be downloaded. This would need separate consideration. NB: outdir is path relative, and would break if given an absolute path. This likely means that O=jimc@remote:/data/kerneldump/foo would break badly. I don't forsee a practical usability problem with this limitation, but Im not that kind of user. Signed-off-by: Jim Cromie --- virtme_ng/run.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/virtme_ng/run.py b/virtme_ng/run.py index ba40ee8..cec4caa 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -873,7 +873,11 @@ def _get_virtme_run(self, args): else: self.virtme_param["kdir"] = "--kimg " + args.run else: - self.virtme_param["kdir"] = "--kdir ./" + for var in args.envs: + if var.startswith("O="): + self.virtme_param["kdir"] = "--kdir ./" + var[2:] + if self.virtme_param.get("kdir") is None: + self.virtme_param["kdir"] = "--kdir ./" def _get_virtme_mods(self, args): if args.skip_modules: From 274263dd8ec7ef81f585b3a970ea61ee8d252dc3 Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Sun, 7 Jul 2024 20:24:38 -0600 Subject: [PATCH 4/5] vng: propagate --verbose to configkernel When vng/run.py gets --verbose: pass that down to configkernel too. and print make-cmd before running it. TBD: maybe convert verbose to incremental, and to propagate down it when verbose > 1 Signed-off-by: Jim Cromie --- virtme_ng/run.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/virtme_ng/run.py b/virtme_ng/run.py index cec4caa..403d331 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -611,6 +611,8 @@ def config(self, args): """Perform a make config operation on a kernel source directory.""" arch = args.arch cmd = "virtme-configkernel --defconfig" + if args.verbose: + cmd += " --verbose" if not args.force and not args.kconfig: cmd += " --no-update" if arch is not None: @@ -630,6 +632,8 @@ def config(self, args): # Propagate additional Makefile variables for var in args.envs: cmd += f" {var} " + if args.verbose: + print(f"cmd: {cmd}") check_call_cmd( self._format_cmd(cmd), quiet=not args.verbose, dry_run=args.dry_run ) From 9d3e88aa0aa1eed7dec2a0422a05ce13146e75bb Mon Sep 17 00:00:00 2001 From: Jim Cromie Date: Sun, 23 Jun 2024 22:15:26 -0600 Subject: [PATCH 5/5] vng: alias --custom to --config vng's --config is passed thru to virtme-configkernel as --custom , so they are synonymous. Alias it. This should simplify users migrating to use vng. Signed-off-by: Jim Cromie --- virtme_ng/run.py | 1 + 1 file changed, 1 insertion(+) diff --git a/virtme_ng/run.py b/virtme_ng/run.py index 403d331..13e2ef2 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -207,6 +207,7 @@ def make_parser(): parser.add_argument( "--config", + "--custom", "-f", action="append", help="Use one (or more) specific kernel .config snippet "