mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-29 02:43:08 +00:00

Due the lack of pei-aarch64 support in binutils, the gnu-efi crt0 harcodes
the PE32+ sections among other things. These crt0 aren't aware of the SBAT
section and so custom ones have to be used.
In the same vein as commit cfd1f2f42a
("uefi-capsule: Ensure SBAT metadata
is added correctly") included custom linker scripts, this change add a set
of crt0 for arm and aarch64 that hardcode a SBAT section in the PE headers.
These are the crt0 from gnu-efi plus the following fixes from Peter Jones:
* Include .sbat in section headers
* Fix some PE headers
* Calculate the VirtualSize of .sbat separately
* Put .rel* and .dyn* in .rodata
94 lines
1.8 KiB
Python
Executable File
94 lines
1.8 KiB
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# Copyright (C) 2021 Javier Martinez Canillas <javierm@redhat.com>
|
|
# Copyright (C) 2021 Richard Hughes <richard@hughsie.com>
|
|
#
|
|
# SPDX-License-Identifier: LGPL-2.1+
|
|
#
|
|
# pylint: disable=missing-docstring, invalid-name
|
|
|
|
import subprocess
|
|
import sys
|
|
import argparse
|
|
|
|
|
|
def _run_objcopy(args):
|
|
|
|
argv = [
|
|
args.objcopy,
|
|
"-j",
|
|
".text",
|
|
"-j",
|
|
".sbat",
|
|
"-j",
|
|
".sdata",
|
|
"-j",
|
|
".data",
|
|
"-j",
|
|
".dynamic",
|
|
"-j",
|
|
".rodata",
|
|
"-j",
|
|
".rel*",
|
|
args.infile,
|
|
args.outfile,
|
|
]
|
|
|
|
# aarch64 and arm32 don't have an EFI capable objcopy
|
|
# Use 'binary' instead, and add required symbols manually
|
|
if args.arch in ["aarch64", "arm"]:
|
|
argv.extend(["-O", "binary"])
|
|
else:
|
|
argv.extend(["--target", "efi-app-{}".format(args.arch)])
|
|
try:
|
|
subprocess.run(argv, check=True)
|
|
except FileNotFoundError as e:
|
|
print(str(e))
|
|
sys.exit(1)
|
|
|
|
|
|
def _run_genpeimg(args):
|
|
|
|
# this is okay if it does not exist
|
|
argv = [
|
|
"genpeimg",
|
|
"-d",
|
|
"+d",
|
|
"+n",
|
|
"-d",
|
|
"+s",
|
|
args.outfile,
|
|
]
|
|
try:
|
|
subprocess.run(argv, check=True)
|
|
except FileNotFoundError as _:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"--objcopy",
|
|
default="objcopy",
|
|
help="Binary file to use for objcopy",
|
|
)
|
|
parser.add_argument(
|
|
"--arch",
|
|
default="x86_64",
|
|
help="EFI architecture",
|
|
)
|
|
parser.add_argument(
|
|
"infile",
|
|
help="Input file",
|
|
)
|
|
parser.add_argument(
|
|
"outfile",
|
|
help="Output file",
|
|
)
|
|
_args = parser.parse_args()
|
|
_run_objcopy(_args)
|
|
_run_genpeimg(_args)
|
|
|
|
sys.exit(0)
|