]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Replace dd with pefile's get_data() method
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 9 Aug 2023 12:24:07 +0000 (14:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 9 Aug 2023 15:15:23 +0000 (17:15 +0200)
mkosi/__init__.py
pyproject.toml

index 611c9ca717b0d7b7bd7e8dfc41e09ab6f5b58f80..887434b04713a8ec4ff45245487da4051e1ba1b5 100644 (file)
@@ -779,13 +779,8 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None:
                 import pefile  # type: ignore
                 pe = pefile.PE(boot_binary, fast_load=True)
                 linux = {s.Name.decode().strip("\0"): s for s in pe.sections}[".linux"]
-                run(["dd",
-                     f"if={boot_binary}",
-                     f"of={state.staging / state.config.output_split_kernel}",
-                     f"skip={linux.PointerToRawData}",
-                     # Get the actual size using Misc_VirtualSize instead of the aligned size from SizeOfRawData.
-                     f"count={linux.Misc_VirtualSize}",
-                     "iflag=skip_bytes,count_bytes"])
+                # TODO: Use ignore_padding=True instead of length once we can depend on a newer pefile.
+                (state.root / state.config.output_split_kernel).write_bytes(linux.get_data(length=linux.Misc_VirtualSize))
 
             print_output_size(boot_binary)
 
index 4530d8387a20a4aaa488db2da0a0ba7ac2e51fe3..4eb5d8cd7880dc0583c03e0c303ee5f2d3df0e4d 100644 (file)
@@ -13,6 +13,11 @@ readme = "README.md"
 requires-python = ">=3.9"
 license = {file = "LICENSE"}
 
+[project.optional-dependencies]
+bootable = [
+  "pefile >= 2021.9.3",
+]
+
 [project.scripts]
 mkosi = "mkosi.__main__:main"