Commit fde4b167 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Richard Hughes
Browse files

uefi: Rewrite generate_binary.sh script in Python

The generate_binary.sh is a script that calls the objcopy tool and
genpeimg in the case of Windows, to generate a PE binary file.

But doesn't have to be a shell script and could be rewritten as a
python script. This will make this code to generate a PE binary
easier to extend if needed.

Also, the only reason that's a template is to define the objcopy
tool used, but this can also be passed as a positional argument.
parent b2a1d974
......@@ -357,8 +357,6 @@ if build_standalone and get_option('plugin_uefi_capsule')
efi_app_location = join_paths(libexecdir, 'fwupd', 'efi')
conf.set_quoted ('EFI_APP_LOCATION', efi_app_location)
conf.set('EFI_OBJCOPY', get_option('efi-objcopy'))
if host_cpu == 'x86'
EFI_MACHINE_TYPE_NAME = 'ia32'
gnu_efi_arch = 'ia32'
......
#!/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",
".sdata",
"-j",
".dynamic",
"-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)
#!/bin/sh
output=$2
objcopy_cmd=$(command -v @EFI_OBJCOPY@)
genpeimg_cmd=$(command -v genpeimg)
"$objcopy_cmd" -j .text \
-j .sdata \
-j .data \
-j .dynamic \
-j .dynsym \
-j '.rel*' \
"$@"
if [ -n "${genpeimg_cmd}" ]; then
$genpeimg_cmd -d \
+d \
-d \
+n \
-d \
+s \
"$output"
fi
......@@ -154,17 +154,15 @@ so = custom_target('fwup.so',
efi_ldflags + ['@INPUT@'] +
['-lefi', '-lgnuefi', libgcc_file_name])
configure_file(
input : 'generate_binary.sh.in',
output : 'generate_binary.sh',
configuration : conf
)
build_tool = join_paths(meson.current_build_dir(), 'generate_binary.sh')
app = custom_target(efi_name,
input : so,
output : efi_name,
command : [build_tool, '@INPUT@', '@OUTPUT@', efi_format],
command : [
join_paths(meson.current_source_dir(), 'generate_binary.py'),
'@INPUT@', '@OUTPUT@',
'--arch', gnu_efi_arch,
'--objcopy', efi_objcopy,
],
install : true,
install_dir : efi_app_location)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment