Skip to content

Commit d612edb

Browse files
committed
qemu: Add support for loading modules into the guest
1 parent 6587836 commit d612edb

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

lib/qemu.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def machine_is(self, needle):
5050
def configure_from_env(self):
5151
self.expected_release = get_expected_release()
5252
self.vmlinux = get_vmlinux()
53+
self.modules_tarball = get_modules_tarball()
5354
self.cpuinfo = None
5455

5556
def configure_from_args(self, orig_args):
@@ -74,6 +75,7 @@ def configure_from_args(self, orig_args):
7475
parser.add_argument('--cmdline', type=str, help='Kernel command line arguments')
7576
parser.add_argument('--release-path', type=str, help='Path to kernel.release')
7677
parser.add_argument('--kernel-path', type=str, help='Path to kernel (vmlinux)')
78+
parser.add_argument('--modules-path', type=str, help='Path to modules tarball')
7779
parser.add_argument('--cap', dest='machine_caps', type=str, default=[], action='append', help='Machine caps')
7880
args = parser.parse_args(orig_args)
7981

@@ -120,6 +122,9 @@ def configure_from_args(self, orig_args):
120122
if args.kernel_path:
121123
self.vmlinux = args.kernel_path
122124

125+
if args.modules_path:
126+
self.modules_tarball = args.modules_path
127+
123128
self.compat_rootfs = args.compat_rootfs
124129
self.use_vof = args.use_vof
125130
self.quiet = args.quiet
@@ -271,6 +276,9 @@ def boot(p, timeout, qconf):
271276

272277
self.boot_func = boot
273278

279+
if self.modules_tarball:
280+
self.modules_drive = self.add_drive(f'file={self.modules_tarball},format=raw,readonly=on')
281+
274282
def add_drive(self, args):
275283
drive_id = self.next_drive
276284
self.next_drive += 1
@@ -514,6 +522,11 @@ def qemu_main(qconf):
514522
p.expect(s)
515523
p.expect_prompt()
516524

525+
if qconf.modules_tarball:
526+
p.cmd('mkdir -p /lib/modules')
527+
p.send(f'cd /lib/modules; cat /dev/vd{qconf.modules_drive} | zcat | tar --strip-components=2 -xf -; cd -')
528+
p.expect_prompt(timeout=boot_timeout)
529+
517530
if qconf.net_tests:
518531
qemu_net_setup(p)
519532
ping_test(p)

lib/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ def get_vmlinux():
7474
return None
7575

7676

77+
def get_tarball(basename):
78+
dirs = ['.']
79+
env = get_env_var('KBUILD_OUTPUT', None)
80+
if env:
81+
dirs.append(env)
82+
83+
for base in dirs:
84+
for suffix in ['gz', 'bz2', 'xz']:
85+
name = f'{base}/{basename}.tar.{suffix}'
86+
if os.path.isfile(name):
87+
return name
88+
89+
return None
90+
91+
92+
def get_modules_tarball():
93+
return get_tarball('modules')
94+
95+
7796
def read_expected_release(path):
7897
expected_release = open(path).read().strip()
7998
return expected_release

0 commit comments

Comments
 (0)