From: Xiaotian Wu Date: Thu, 16 Nov 2023 12:01:50 +0000 (+0800) Subject: uki: Support zboot efistub kernel X-Git-Tag: v256-rc1~684 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=96069e57a0f9d0d080c2f2743a169eddcf41ea0e;p=thirdparty%2Fsystemd.git uki: Support zboot efistub kernel Generic EFI zboot added since kernel 6.1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/Makefile.zboot?h=v6.1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/efi/libstub/zboot-header.S?h=v6.1 --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 1d6ad15383d..8ca93543b5d 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -40,6 +40,7 @@ import subprocess import sys import tempfile import textwrap +import struct from hashlib import sha256 from typing import (Any, Callable, @@ -128,6 +129,45 @@ def try_import(modname, name=None): except ImportError as e: raise ValueError(f'Kernel is compressed with {name or modname}, but module unavailable') from e +def get_zboot_kernel(f): + """Decompress zboot efistub kernel if compressed. Return contents.""" + # See linux/drivers/firmware/efi/libstub/Makefile.zboot + # and linux/drivers/firmware/efi/libstub/zboot-header.S + + # 4 bytes at offset 0x08 contain the starting offset of compressed data + f.seek(8) + _start = f.read(4) + start = struct.unpack('