From: Daan De Meyer Date: Wed, 9 Aug 2023 12:24:07 +0000 (+0200) Subject: Replace dd with pefile's get_data() method X-Git-Tag: v15~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ffcdac128c66935aa5d5a98633fa7498bce92d1;p=thirdparty%2Fmkosi.git Replace dd with pefile's get_data() method --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 611c9ca71..887434b04 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 4530d8387..4eb5d8cd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"