Skip to content

Commit

Permalink
zefi.py: Use cross compiler while building zephyr
Browse files Browse the repository at this point in the history
Currently, zefi.py takes host GCC OBJCOPY as
default. Fixing the script to use CMAKE_C_COMPILER
and CMAKE_OBJCOPY.

Fixes: #27047

Signed-off-by: Spoorthy Priya Yerabolu <[email protected]>
  • Loading branch information
yerabolu committed Jan 21, 2021
1 parent 041c807 commit affef97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions arch/x86/zefi/zefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import argparse

ENTRY_SYM = "__start64"
GCC = "gcc"
OBJCOPY = "objcopy"

def verbose(msg):
if args.verbose:
Expand Down Expand Up @@ -108,14 +106,14 @@ def build_elf(elf_file):
# + We need pic to enforce that the linker adds no relocations
# + UEFI can take interrupts on our stack, so no red zone
# + UEFI API assumes 16-bit wchar_t
cmd = [GCC, "-shared", "-Wall", "-Werror", "-I.",
cmd = [args.compiler, "-shared", "-Wall", "-Werror", "-I.",
"-fno-stack-protector", "-fpic", "-mno-red-zone", "-fshort-wchar",
"-Wl,-nostdlib", "-T", ldscript, "-o", "zefi.elf", cfile]
verbose(" ".join(cmd))
subprocess.run(cmd, check = True)

# Extract the .data segment and append our extra blob
cmd = [OBJCOPY, "-O", "binary", "-j", ".data", "zefi.elf", "data.dat"]
cmd = [args.objcopy, "-O", "binary", "-j", ".data", "zefi.elf", "data.dat"]
verbose(" ".join(cmd))
subprocess.run(cmd, check = True)

Expand All @@ -125,11 +123,11 @@ def build_elf(elf_file):
df.close()

# FIXME: this generates warnings about our unused trash section having to be moved to make room. Set its address far away...
subprocess.run([OBJCOPY, "--update-section", ".data=data.dat",
subprocess.run([args.objcopy, "--update-section", ".data=data.dat",
"zefi.elf"], check = True)

# Convert it to a PE-COFF DLL.
cmd = [OBJCOPY, "--target=efi-app-x86_64",
cmd = [args.objcopy,
"-j", ".text", "-j", ".reloc", "-j", ".data",
"zefi.elf", "zephyr.efi"]
verbose(" ".join(cmd))
Expand All @@ -143,6 +141,8 @@ def parse_args():
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)

parser.add_argument("-c", "--compiler", required=True, help="Compiler to be used")
parser.add_argument("-o", "--objcopy", required=True, help="objcopy to be used")
parser.add_argument("-f", "--elf-file", required=True, help="Input file")
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")

Expand Down
2 changes: 2 additions & 0 deletions boards/x86/ehl_crb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
if(CONFIG_BOARD_EHL_CRB)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py
-c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY}
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
Expand Down
2 changes: 2 additions & 0 deletions boards/x86/up_squared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
if(CONFIG_BOARD_UP_SQUARED)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py
-c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY}
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
Expand Down

0 comments on commit affef97

Please sign in to comment.