mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 19:21:35 +01:00
run: add --quit-after-boot, handle rdinit= vs init= there
This commit is contained in:
10
README.adoc
10
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 <<linux-kernel-build-variants>> if you need to switch between initramfs and non initramfs often.
|
||||
Alternatively, consider using <<linux-kernel-build-variants>> 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.
|
||||
|
||||
|
||||
10
common.py
10
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'])
|
||||
|
||||
15
run
15
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])
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user