arch: x86: zefi: support multiple include paths

When legacy mode is enabled, Zephyr includes both include/ and
include/zephyr. Allow the zefi.py script to accept multiple include
paths to cover this scenario.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-05-05 16:37:30 +02:00 committed by Maureen Helm
commit bad523d1aa
4 changed files with 14 additions and 13 deletions

View file

@ -13,7 +13,7 @@ def verbose(msg):
if args.verbose: if args.verbose:
print(msg) print(msg)
def build_elf(elf_file, include_dir): def build_elf(elf_file, include_dirs):
base_dir = os.path.dirname(os.path.abspath(__file__)) base_dir = os.path.dirname(os.path.abspath(__file__))
cfile = os.path.join(base_dir, "zefi.c") cfile = os.path.join(base_dir, "zefi.c")
@ -106,9 +106,12 @@ def build_elf(elf_file, include_dir):
# + We need pic to enforce that the linker adds no relocations # + We need pic to enforce that the linker adds no relocations
# + UEFI can take interrupts on our stack, so no red zone # + UEFI can take interrupts on our stack, so no red zone
# + UEFI API assumes 16-bit wchar_t # + UEFI API assumes 16-bit wchar_t
cmd = [args.compiler, "-shared", "-Wall", "-Werror", "-I.", includes = []
"-I", include_dir, "-fno-stack-protector", "-fpic", "-mno-red-zone", for include_dir in include_dirs:
"-fshort-wchar", "-Wl,-nostdlib", "-T", ldscript, "-o", "zefi.elf", cfile] includes.extend(["-I", include_dir])
cmd = ([args.compiler, "-shared", "-Wall", "-Werror", "-I."] + includes +
["-fno-stack-protector", "-fpic", "-mno-red-zone", "-fshort-wchar",
"-Wl,-nostdlib", "-T", ldscript, "-o", "zefi.elf", cfile])
verbose(" ".join(cmd)) verbose(" ".join(cmd))
subprocess.run(cmd, check = True) subprocess.run(cmd, check = True)
@ -145,12 +148,13 @@ def parse_args():
parser.add_argument("-o", "--objcopy", required=True, help="objcopy 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("-f", "--elf-file", required=True, help="Input file")
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
parser.add_argument("-i", "--include", required=True,help="Zephyr base include directory") parser.add_argument("-i", "--includes", required=True, nargs="+",
help="Zephyr base include directories")
return parser.parse_args() return parser.parse_args()
if __name__ == "__main__": if __name__ == "__main__":
args = parse_args() args = parse_args()
verbose(f"Working on {args.elf_file} with {args.include}...") verbose(f"Working on {args.elf_file} with {args.includes}...")
build_elf(args.elf_file, args.include) build_elf(args.elf_file, args.includes)

View file

@ -5,7 +5,6 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
-c ${CMAKE_C_COMPILER} -c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY} -o ${CMAKE_OBJCOPY}
-i ${ZEPHYR_BASE}/include -i ${ZEPHYR_BASE}/include
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr> $<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf -f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>

View file

@ -3,7 +3,6 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/arch/x86/zefi/zefi.py
-c ${CMAKE_C_COMPILER} -c ${CMAKE_C_COMPILER}
-i ${ZEPHYR_BASE}/include -i ${ZEPHYR_BASE}/include
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr> $<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-o ${CMAKE_OBJCOPY} -o ${CMAKE_OBJCOPY}
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf -f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf

View file

@ -5,7 +5,6 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
-c ${CMAKE_C_COMPILER} -c ${CMAKE_C_COMPILER}
-o ${CMAKE_OBJCOPY} -o ${CMAKE_OBJCOPY}
-i ${ZEPHYR_BASE}/include -i ${ZEPHYR_BASE}/include
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:-i>
$<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr> $<$<BOOL:${CONFIG_LEGACY_INCLUDE_PATH}>:${ZEPHYR_BASE}/include/zephyr>
-f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf -f ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.elf
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>