ClangBuiltLinux / boot-utils

Collection of files for booting Linux kernels
26 stars 7 forks source link

boot-utils.py: Fix searching for Linux kernel version numbers #69

Closed nathanchance closed 2 years ago

nathanchance commented 2 years ago

CI reported a crash when attempting to boot arm64 kernels:

  Traceback (most recent call last):
    File ".../boot-qemu.py", line 727, in <module>
      cfg = get_qemu_args(cfg)
    File ".../boot-qemu.py", line 451, in get_qemu_args
      linux_ver_code = get_linux_ver_code(gzip_kernel_cmd)
    File ".../boot-qemu.py", line 338, in get_linux_ver_code
      return create_version_code(linux_version)
    File ".../boot-qemu.py", line 262, in create_version_code
      major, minor, patch = [int(version[i]) for i in (0, 1, 2)]
    File ".../boot-qemu.py", line 262, in <listcomp>
      major, minor, patch = [int(version[i]) for i in (0, 1, 2)]
  ValueError: invalid literal for int() with base 10: '%s'

Looking at the strings output reveals:

  $ gzip -d -c Image.gz &| strings &| grep "Linux version "
  Linux version %s (%s)
  Linux version 4.19.254 (tuxmake@tuxmake) (Debian clang version 14.0.6-++20220622053050+f28c006a5895-1~exp1~20220622173135.152, Debian LLD 14.0.6) #1 SMP PREEMPT @1659593940

Use re.search() plus a regular expression for a more precise match. I had originally tried to do this but I could not get it to work for some reason. I tested this against all the kernels that had issues in CI with no further issues.

nathanchance commented 2 years ago

Thanks for the review!