From d2cd2d6100e312ac62581204849a8f5f7573a777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 22 Jan 2019 00:00:00 +0000 Subject: [PATCH] run: add --quit-after-boot, handle rdinit= vs init= there --- README.adoc | 10 ++++++++-- common.py | 10 +++++++--- run | 15 ++++++++++----- test-boot | 2 +- trace-boot | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index 50181f0..0cb472d 100644 --- a/README.adoc +++ b/README.adoc @@ -2700,14 +2700,20 @@ ls -lh "$(./getvar linux_image)" before and after using initramfs, since the `.cpio` is now glued to the kernel image. -Don't forget that to stop using initramfs, you must rebuild the kernel without `--initramfs`: +Don't forget that to stop using initramfs, you must rebuild the kernel without `--initramfs` to get rid of the attached CPIO image: .... ./build-linux ./run .... -Also consider using <> if you need to switch between initramfs and non initramfs often. +Alternatively, consider using <> if you need to switch between initramfs and non initramfs often: + +.... +./build-buildroot --initramfs +./build-linux --initramfs --linux-build-id initramfs +./run --initramfs --linux-build-id +.... Setting up initramfs is very easy: our scripts just set `CONFIG_INITRAMFS_SOURCE` to point to the CPIO path. diff --git a/common.py b/common.py index 5136116..e597cef 100644 --- a/common.py +++ b/common.py @@ -482,7 +482,7 @@ Valid emulators: {} env['buildroot_images_dir'] = join(env['buildroot_build_dir'], 'images') env['buildroot_rootfs_raw_file'] = join(env['buildroot_images_dir'], 'rootfs.ext2') env['buildroot_qcow2_file'] = env['buildroot_rootfs_raw_file'] + '.qcow2' - env['buildroot_cpio'] = join(self.env['buildroot_images_dir'], 'rootfs.cpio') + env['buildroot_cpio'] = join(env['buildroot_images_dir'], 'rootfs.cpio') env['staging_dir'] = join(env['out_dir'], 'staging', env['arch']) env['buildroot_staging_dir'] = join(env['buildroot_build_dir'], 'staging') env['target_dir'] = join(env['buildroot_build_dir'], 'target') @@ -606,8 +606,12 @@ Valid emulators: {} env['userland_quit_cmd'] = '/gem5_exit.sh' else: env['userland_quit_cmd'] = '/poweroff.out' - env['quit_init'] = 'init={}'.format(env['userland_quit_cmd']) - self.env['ramfs'] = self.env['initrd'] or self.env['initramfs'] + env['ramfs'] = env['initrd'] or env['initramfs'] + if env['ramfs']: + env['initarg'] = 'rdinit' + else: + env['initarg'] = 'init' + env['quit_init'] = '{}={}'.format(env['initarg'], env['userland_quit_cmd']) # Kernel modules. env['kernel_modules_build_dir'] = join(env['kernel_modules_build_base_dir'], env['arch']) diff --git a/run b/run index cd18014..0a55788 100755 --- a/run +++ b/run @@ -130,6 +130,13 @@ Set the memory size of the guest. E.g.: `-m 512M`. We try to keep the default at the minimal ammount amount that boots all archs. Anything lower could lead some arch to fail to boot. Default: %(default)s +''' + ) + self.add_argument( + '--quit-after-boot', + default=False, + help='''\ +Setup a kernel init parameter that makes the emulator quit immediately after boot. ''' ) self.add_argument( @@ -212,6 +219,8 @@ Run QEMU with VNC instead of the default SDL. Connect to it with: kernel_cli = 'console_msg_format=syslog nokaslr norandmaps panic=-1 printk.devkmsg=on printk.time=y rw' if self.env['kernel_cli'] is not None: kernel_cli += ' {}'.format(self.env['kernel_cli']) + if self.env['quit_after_boot']: + kernel_cli += ' {}'.format(self.env['quit_init']) kernel_cli_after_dash = '' extra_emulator_args = [] extra_qemu_args = [] @@ -232,11 +241,7 @@ Run QEMU with VNC instead of the default SDL. Connect to it with: else: vnc = [] if self.env['eval'] is not None: - if self.env['ramfs']: - initarg = 'rdinit' - else: - initarg = 'init' - kernel_cli += ' {}=/eval_base64.sh'.format(initarg) + kernel_cli += ' {}=/eval_base64.sh'.format(self.env['initarg']) kernel_cli_after_dash += ' lkmc_eval="{}"'.format(self.base64_encode(self.env['eval'])) if not self.env['graphic']: extra_qemu_args.extend(['-nographic', LF]) diff --git a/test-boot b/test-boot index 33cdf9d..d373277 100755 --- a/test-boot +++ b/test-boot @@ -48,7 +48,7 @@ See ./test --help for --size. self.run = self.import_path_main('run') self.common_args = self.get_common_args() self.common_args['ctrl_c_host'] = True - self.common_args['kernel_cli'] = self.env['quit_init'] + self.common_args['quit_after_boot'] = True if (self.env['emulator'] == 'qemu' or (self.env['emulator'] == 'gem5' and self.env['size'] >= 2)): self._bench() diff --git a/trace-boot b/trace-boot index cd80517..4336979 100755 --- a/trace-boot +++ b/trace-boot @@ -15,13 +15,13 @@ More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#t def timed_main(self): args = self.get_common_args() run = self.import_path_main('run') - self.common_args['kernel_cli'] = self.env['quit_init'] if self.env['emulator'] == 'gem5': args['trace'] = 'Exec,-ExecSymbol,-ExecMicro' run.main(**args) elif self.env['emulator'] == 'qemu': run_args = args.copy() - args['trace'] = 'exec_tb' + run_args['trace'] = 'exec_tb' + run_args['quit_after_boot'] = True run.main(**run_args) qemu_trace2txt = self.import_path_main('qemu-trace2txt') qemu_trace2txt.main(**args)