Skip to content

Commit 9ef7866

Browse files
authored
Merge pull request #78 from nathanchance/use-tuples-for-versions
boot-qemu.py: Use tuples for Linux and QEMU versions
2 parents 79d07bb + 6e80b3b commit 9ef7866

1 file changed

Lines changed: 10 additions & 29 deletions

File tree

boot-qemu.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,6 @@ def setup_cfg(args):
244244
}
245245

246246

247-
def create_version_code(version):
248-
"""
249-
Turns a version list with three values (major, minor, and patch level) into
250-
an integer with at least six digits:
251-
* major: as is
252-
* minor: with a minimum length of two ("1" becomes "01")
253-
* patch level: with a minimum length of three ("1" becomes "001")
254-
255-
Parameters:
256-
version (list): A list with three integer values (major, minor, and
257-
patch level).
258-
259-
Returns:
260-
An integer with at least six digits.
261-
"""
262-
major, minor, patch = [int(version[i]) for i in (0, 1, 2)]
263-
return int(f"{major:d}{minor:02d}{patch:03d}")
264-
265-
266247
def get_qemu_ver_string(qemu):
267248
"""
268249
Prints the first line of QEMU's version output.
@@ -281,7 +262,7 @@ def get_qemu_ver_string(qemu):
281262
return qemu_version_call.stdout.decode("UTF-8").split("\n")[0]
282263

283264

284-
def get_qemu_ver_code(qemu):
265+
def get_qemu_ver_tuple(qemu):
285266
"""
286267
Prints QEMU's version as an integer with at least six digits.
287268
@@ -297,10 +278,10 @@ def get_qemu_ver_code(qemu):
297278
# "QEMU emulator version x.y.z (...)" -> x.y.z -> ['x', 'y', 'z']
298279
qemu_version = qemu_version_string.split(" ")[3].split(".")
299280

300-
return create_version_code(qemu_version)
281+
return tuple(int(x) for x in qemu_version)
301282

302283

303-
def get_linux_ver_code(decomp_cmd):
284+
def get_linux_ver_tuple(decomp_cmd):
304285
"""
305286
Searches the Linux kernel binary for the version string using 'strings'
306287
then prints it as an integer with at least six digits.
@@ -334,7 +315,7 @@ def get_linux_ver_code(decomp_cmd):
334315
utils.die(
335316
f"Linux version string could not be found in '{kernel_path}'")
336317

337-
return create_version_code(linux_version)
318+
return tuple(int(x) for x in linux_version)
338319

339320

340321
def get_and_decomp_rootfs(cfg):
@@ -440,21 +421,21 @@ def get_qemu_args(cfg):
440421
cpu = "max"
441422
kernel = utils.get_full_kernel_path(kernel_location, kernel_image,
442423
kernel_arch)
443-
qemu_ver_code = get_qemu_ver_code(qemu)
424+
qemu_ver = get_qemu_ver_tuple(qemu)
444425

445-
if qemu_ver_code >= 602050:
426+
if qemu_ver >= (6, 2, 50):
446427
gzip_kernel_cmd = ["gzip", "-c", "-d", kernel]
447-
linux_ver_code = get_linux_ver_code(gzip_kernel_cmd)
428+
linux_ver = get_linux_ver_tuple(gzip_kernel_cmd)
448429

449430
# https://gitlab.com/qemu-project/qemu/-/issues/964
450-
if linux_ver_code < 416000:
431+
if linux_ver < (4, 16, 0):
451432
cpu = "cortex-a72"
452433
# https://gitlab.com/qemu-project/qemu/-/commit/69b2265d5fe8e0f401d75e175e0a243a7d505e53
453-
elif linux_ver_code < 512000:
434+
elif linux_ver < (5, 12, 0):
454435
cpu += ",lpa2=off"
455436

456437
# https://lore.kernel.org/YlgVa+AP0g4IYvzN@lakrids/
457-
if "max" in cpu and qemu_ver_code >= 600000:
438+
if "max" in cpu and qemu_ver >= (6, 0, 0):
458439
cpu += ",pauth-impdef=true"
459440

460441
qemu_args += ["-cpu", cpu]

0 commit comments

Comments
 (0)