CMake: Remove references of APP_TARGET

This needs to be removed as there should not be a
name requirement for application CMake variable name.
Furthermore, in certain uses cases it prevents
successful builds for some Mbed targets. For instance
when building Greentea test applications for Mbed
targets that require post build operations as they do
not define APP_TARGET.
pull/14334/head
Hugues Kamba 2021-02-23 17:24:31 +00:00
parent 8340ea2d2b
commit 03914d1875
4 changed files with 47 additions and 19 deletions

View File

@ -17,6 +17,7 @@
# #
import argparse import argparse
import pathlib
import logging import logging
import os import os
import sys import sys
@ -59,6 +60,12 @@ class AddSignatureError(Exception):
adding signature to Secure Boot image adding signature to Secure Boot image
""" """
class ArtefactsError(Exception):
"""An exception to indicate that the artefact(s) needed for processing
ave not been found."""
# Base class for all configuration exceptions # Base class for all configuration exceptions
class ConfigException(Exception): class ConfigException(Exception):
"""Config system only exception. Makes it easier to distinguish config """Config system only exception. Makes it easier to distinguish config
@ -306,13 +313,29 @@ def complete(message_func, elf0, hexf0, hexf1=None):
def merge_action(args): def merge_action(args):
"""Entry point for the "merge" CLI command.""" """Entry point for the "merge" CLI command."""
try:
elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0]
m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0]
except IndexError:
raise ArtefactsError(
f"Could not find elf and/or hex file in {args.artefacts_location}"
)
complete_func( complete_func(
print, args.elf, args.m4hex, args.m0hex print, elf_file, m4hex_file, args.m0hex
) )
def sign_action(args): def sign_action(args):
"""Entry point for the "sign" CLI command.""" """Entry point for the "sign" CLI command."""
try:
elf_file = list(pathlib.Path(args.artefacts_location).glob("*.elf"))[0]
m4hex_file = list(pathlib.Path(args.artefacts_location).glob("*.hex"))[0]
except IndexError:
raise ArtefactsError(
f"Could not find elf and/or hex file in {args.artefacts_location}"
)
sign_hex( sign_hex(
args.build_dir, args.build_dir,
args.m0hex_filename, args.m0hex_filename,
@ -322,8 +345,8 @@ def sign_action(args):
args.boot_scheme, args.boot_scheme,
args.cm0_img_id, args.cm0_img_id,
args.cm4_img_id, args.cm4_img_id,
args.elf, elf_file,
args.m4hex, m4hex_file,
args.m0hex args.m0hex
) )
@ -340,10 +363,7 @@ def parse_args():
"merge", help="Merge Cortex-M4 and Cortex-M0 HEX files." "merge", help="Merge Cortex-M4 and Cortex-M0 HEX files."
) )
merge_subcommand.add_argument( merge_subcommand.add_argument(
"--elf", required=True, help="the application ELF file." "--artefacts-location", required=True, help="the path to the application artefacts."
)
merge_subcommand.add_argument(
"--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge."
) )
merge_subcommand.add_argument( merge_subcommand.add_argument(
"--m0hex", help="the path to the Cortex-M0 HEX to merge." "--m0hex", help="the path to the Cortex-M0 HEX to merge."
@ -375,10 +395,7 @@ def parse_args():
"--cm4-img-id", help="the Cortex-M4 image ID." "--cm4-img-id", help="the Cortex-M4 image ID."
) )
sign_subcommand.add_argument( sign_subcommand.add_argument(
"--elf", required=True, help="the application ELF file." "--artefacts-location", required=True, help="the path to the application artefacts."
)
sign_subcommand.add_argument(
"--m4hex", required=True, help="the path to the Cortex-M4 HEX to merge."
) )
sign_subcommand.add_argument( sign_subcommand.add_argument(
"--m0hex", help="the path to the Cortex-M0 HEX to merge." "--m0hex", help="the path to the Cortex-M0 HEX to merge."

View File

@ -22,16 +22,14 @@ function(mbed_post_build_psoc6_merge_hex mbed_target_name)
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
merge merge
--elf $<TARGET_FILE:${APP_TARGET}> --artefacts-location ${CMAKE_BINARY_DIR}
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
--m0hex ${cortex_m0_hex} --m0hex ${cortex_m0_hex}
) )
else() else()
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py
merge merge
--elf $<TARGET_FILE:${APP_TARGET}> --artefacts-location ${CMAKE_BINARY_DIR}
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
) )
endif() endif()
@ -63,8 +61,7 @@ function(mbed_post_build_psoc6_sign_image
--boot-scheme ${boot_scheme} --boot-scheme ${boot_scheme}
--cm0-img-id ${cm0_img_id} --cm0-img-id ${cm0_img_id}
--cm4-img-id ${cm4_img_id} --cm4-img-id ${cm4_img_id}
--elf $<TARGET_FILE:${APP_TARGET}> --artefacts-location ${CMAKE_BINARY_DIR}
--m4hex ${CMAKE_BINARY_DIR}/${APP_TARGET}.hex
--m0hex ${cortex_m0_hex} --m0hex ${cortex_m0_hex}
) )

View File

@ -24,11 +24,17 @@ causes the checksum of the first 8 table entries to be 0. The boot loader code c
the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is
transferred to the user code. transferred to the user code.
""" """
import pathlib
import os import os
import sys import sys
from struct import unpack, pack from struct import unpack, pack
class ArtefactsError(Exception):
"""An exception to indicate that the artefact(s) needed for processing
ave not been found."""
def patch(bin_path): def patch(bin_path):
with open(bin_path, 'r+b') as bin: with open(bin_path, 'r+b') as bin:
# Read entries 0 through 6 (Little Endian 32bits words) # Read entries 0 through 6 (Little Endian 32bits words)
@ -47,6 +53,14 @@ def is_patched(bin_path):
if __name__ == "__main__": if __name__ == "__main__":
binary = sys.argv[1] artefacts_location = sys.argv[1]
try:
binary = list(pathlib.Path(artefacts_location).glob("*.bin"))[0]
except IndexError:
raise ArtefactsError(
f"Could not find binary file in {artefacts_location}"
)
print("LPC Patch: %s" % os.path.split(binary)[1]) print("LPC Patch: %s" % os.path.split(binary)[1])
patch(binary) patch(binary)

View File

@ -11,7 +11,7 @@ function(mbed_post_build_lpc_patch_vtable mbed_target_name)
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_NXP/scripts/LPC.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_NXP/scripts/LPC.py
${CMAKE_BINARY_DIR}/${APP_TARGET}.bin ${CMAKE_BINARY_DIR}
) )
mbed_set_post_build_operation() mbed_set_post_build_operation()