From 937671ab0c3af88508f115c7e2750f240ff32535 Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Fri, 11 Jun 2021 14:42:19 +0100 Subject: [PATCH 1/2] cmake: Add post-build scripts requirements Some targets have post-build scripts which have additional Python library requirements. List out the possibly required dependencies in tools/cmake/requirements.txt. When all tools/cmake/requirements.txt are installed, it should be less common to run into difficult to understand error messages. --- tools/cmake/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/cmake/requirements.txt b/tools/cmake/requirements.txt index fce949fecbd..8e1962bd3bc 100644 --- a/tools/cmake/requirements.txt +++ b/tools/cmake/requirements.txt @@ -2,3 +2,5 @@ prettytable==0.7.2 future==0.16.0 Jinja2>=2.10.1,<2.11 intelhex>=2.3.0,<3.0.0 +cbor>=1.0.0 +Click>=7.0,<7.1 From ca0cac756bc9a26ca1783ec666df51d8361b94ea Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Fri, 7 May 2021 17:04:02 +0100 Subject: [PATCH 2/2] musca: Improve missing python dependencies error Previously, if intelhex, cbor, cryptography, or python3 weren't available, we'd see an error message like the following: [2/2] Running utility command for mbed-post-build-bin-ARM_MUSCA_B1 FAILED: mbed-os/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeFiles/mbed-post-build-bin-ARM_MUSCA_B1.util cd /Users/user/Code/mbed-os-example-blinky/cmake_build/ARM_MUSCA_B1/develop/GCC_ARM/mbed-os/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1 && /usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9 /Users/user/Code/mbed-os-example-blinky/mbed-os/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py --tfm-target musca_b1 --target-path /Users/user/Code/mbed-os-example-blinky/mbed-os/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1 --secure-bin /Users/user/Code/mbed-os-example-blinky/mbed-os/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/tfm_s.bin --non-secure-bin /Users/user/Code/mbed-os-example-blinky/cmake_build/ARM_MUSCA_B1/develop/GCC_ARM/mbed-os-example-blinky.bin Traceback (most recent call last): File "/Users/user/Code/mbed-os-example-blinky/mbed-os/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py", line 197, in sign_and_merge_tfm_bin(args.tfm_target, args.target_path, args.non_secure_bin, args.secure_bin) File "/Users/user/Code/mbed-os-example-blinky/mbed-os/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py", line 80, in sign_and_merge_tfm_bin raise Exception("Unable to sign " + target_name + Exception: Unable to sign musca_b1 secure binary, Error code: 1 ninja: build stopped: subcommand failed. ERROR: CMake invocation failed! More information may be available by using the command line option '-v'. "Error code 1" is not very helpful. To provide a more helpful error message, detect the dependencies and panic if the dependencies aren't available when building for the target. The new error message looks like so: CMake Error at mbed-os/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt:10 (message): Missing Python dependencies (python3, cbor, click, intelhex) so the binary cannot be signed. Please install requirements with: python3 -m pip install -r mbed-os/tools/cmake/requirements.txt This is better than before. --- targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt | 9 +++++++++ targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt b/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt index a0e87f6a5c5..c9bd44e0f35 100644 --- a/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt +++ b/targets/TARGET_ARM_SSG/TARGET_MUSCA_B1/CMakeLists.txt @@ -4,6 +4,15 @@ if("TFM" IN_LIST MBED_TARGET_LABELS) include(mbed_set_post_build_tfm) + # Check deps for image signing + if(NOT(Python3_FOUND AND HAVE_PYTHON_INTELHEX AND HAVE_PYTHON_CBOR AND + HAVE_PYTHON_CLICK AND HAVE_PYTHON_CRYPTOGRAPHY)) + message(FATAL_ERROR "Missing Python dependencies (python3, cbor, " + "click, intelhex) so the binary cannot be signed. Please install " + "requirements with:\n" + "\tpython3 -m pip install -r mbed-os/tools/cmake/requirements.txt") + endif() + mbed_post_build_tfm_sign_image( ARM_MUSCA_B1 musca_b1 diff --git a/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt b/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt index 559ba43a7bc..9ce75c2f9b5 100644 --- a/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt +++ b/targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/CMakeLists.txt @@ -4,6 +4,15 @@ if("TFM" IN_LIST MBED_TARGET_LABELS) include(mbed_set_post_build_tfm) + # Check deps for image signing + if(NOT(Python3_FOUND AND HAVE_PYTHON_INTELHEX AND HAVE_PYTHON_CBOR AND + HAVE_PYTHON_CLICK AND HAVE_PYTHON_CRYPTOGRAPHY)) + message(FATAL_ERROR "Missing Python dependencies (python3, cbor, " + "click, intelhex) so the binary cannot be signed. Please install " + "requirements with:\n" + "\tpython3 -m pip install -r mbed-os/tools/cmake/requirements.txt") + endif() + mbed_post_build_tfm_sign_image( ARM_MUSCA_S1 musca_s1