run: add --quit-after-boot, handle rdinit= vs init= there

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-01-22 00:00:00 +00:00
parent 54ef7d52f9
commit d2cd2d6100
5 changed files with 28 additions and 13 deletions

View File

@@ -2700,14 +2700,20 @@ ls -lh "$(./getvar linux_image)"
before and after using initramfs, since the `.cpio` is now glued to the kernel 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 ./build-linux
./run ./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. Setting up initramfs is very easy: our scripts just set `CONFIG_INITRAMFS_SOURCE` to point to the CPIO path.

View File

@@ -482,7 +482,7 @@ Valid emulators: {}
env['buildroot_images_dir'] = join(env['buildroot_build_dir'], 'images') env['buildroot_images_dir'] = join(env['buildroot_build_dir'], 'images')
env['buildroot_rootfs_raw_file'] = join(env['buildroot_images_dir'], 'rootfs.ext2') env['buildroot_rootfs_raw_file'] = join(env['buildroot_images_dir'], 'rootfs.ext2')
env['buildroot_qcow2_file'] = env['buildroot_rootfs_raw_file'] + '.qcow2' 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['staging_dir'] = join(env['out_dir'], 'staging', env['arch'])
env['buildroot_staging_dir'] = join(env['buildroot_build_dir'], 'staging') env['buildroot_staging_dir'] = join(env['buildroot_build_dir'], 'staging')
env['target_dir'] = join(env['buildroot_build_dir'], 'target') env['target_dir'] = join(env['buildroot_build_dir'], 'target')
@@ -606,8 +606,12 @@ Valid emulators: {}
env['userland_quit_cmd'] = '/gem5_exit.sh' env['userland_quit_cmd'] = '/gem5_exit.sh'
else: else:
env['userland_quit_cmd'] = '/poweroff.out' env['userland_quit_cmd'] = '/poweroff.out'
env['quit_init'] = 'init={}'.format(env['userland_quit_cmd']) env['ramfs'] = env['initrd'] or env['initramfs']
self.env['ramfs'] = self.env['initrd'] or self.env['initramfs'] if env['ramfs']:
env['initarg'] = 'rdinit'
else:
env['initarg'] = 'init'
env['quit_init'] = '{}={}'.format(env['initarg'], env['userland_quit_cmd'])
# Kernel modules. # Kernel modules.
env['kernel_modules_build_dir'] = join(env['kernel_modules_build_base_dir'], env['arch']) env['kernel_modules_build_dir'] = join(env['kernel_modules_build_base_dir'], env['arch'])

15
run
View File

@@ -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 at the minimal ammount amount that boots all archs. Anything lower could lead
some arch to fail to boot. some arch to fail to boot.
Default: %(default)s 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( 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' 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: if self.env['kernel_cli'] is not None:
kernel_cli += ' {}'.format(self.env['kernel_cli']) kernel_cli += ' {}'.format(self.env['kernel_cli'])
if self.env['quit_after_boot']:
kernel_cli += ' {}'.format(self.env['quit_init'])
kernel_cli_after_dash = '' kernel_cli_after_dash = ''
extra_emulator_args = [] extra_emulator_args = []
extra_qemu_args = [] extra_qemu_args = []
@@ -232,11 +241,7 @@ Run QEMU with VNC instead of the default SDL. Connect to it with:
else: else:
vnc = [] vnc = []
if self.env['eval'] is not None: if self.env['eval'] is not None:
if self.env['ramfs']: kernel_cli += ' {}=/eval_base64.sh'.format(self.env['initarg'])
initarg = 'rdinit'
else:
initarg = 'init'
kernel_cli += ' {}=/eval_base64.sh'.format(initarg)
kernel_cli_after_dash += ' lkmc_eval="{}"'.format(self.base64_encode(self.env['eval'])) kernel_cli_after_dash += ' lkmc_eval="{}"'.format(self.base64_encode(self.env['eval']))
if not self.env['graphic']: if not self.env['graphic']:
extra_qemu_args.extend(['-nographic', LF]) extra_qemu_args.extend(['-nographic', LF])

View File

@@ -48,7 +48,7 @@ See ./test --help for --size.
self.run = self.import_path_main('run') self.run = self.import_path_main('run')
self.common_args = self.get_common_args() self.common_args = self.get_common_args()
self.common_args['ctrl_c_host'] = True 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 if (self.env['emulator'] == 'qemu' or
(self.env['emulator'] == 'gem5' and self.env['size'] >= 2)): (self.env['emulator'] == 'gem5' and self.env['size'] >= 2)):
self._bench() self._bench()

View File

@@ -15,13 +15,13 @@ More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#t
def timed_main(self): def timed_main(self):
args = self.get_common_args() args = self.get_common_args()
run = self.import_path_main('run') run = self.import_path_main('run')
self.common_args['kernel_cli'] = self.env['quit_init']
if self.env['emulator'] == 'gem5': if self.env['emulator'] == 'gem5':
args['trace'] = 'Exec,-ExecSymbol,-ExecMicro' args['trace'] = 'Exec,-ExecSymbol,-ExecMicro'
run.main(**args) run.main(**args)
elif self.env['emulator'] == 'qemu': elif self.env['emulator'] == 'qemu':
run_args = args.copy() run_args = args.copy()
args['trace'] = 'exec_tb' run_args['trace'] = 'exec_tb'
run_args['quit_after_boot'] = True
run.main(**run_args) run.main(**run_args)
qemu_trace2txt = self.import_path_main('qemu-trace2txt') qemu_trace2txt = self.import_path_main('qemu-trace2txt')
qemu_trace2txt.main(**args) qemu_trace2txt.main(**args)