From 38553db74fa6fa474384b28853940bd4decc21b2 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 16 Jun 2021 14:04:29 +0100 Subject: [PATCH] tfm-post-build: Don't capture subprocess stdout subprocess.PIPE is used to enable the parent process to communicate with the subprocess via pipes, which mean all stdout and stderr messages are captured and returned as part of Popen.communicate's result tuple. In our case, we want to display the error messages on the console, so we don't need to capture the output from stdout. Example of a typical error message before this change: ``` Traceback (most recent call last): File "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 "platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py", line 81, in sign_and_merge_tfm_bin " secure binary, Error code: " + str(retcode)) Exception: Unable to sign musca_b1 secure binary, Error code: 1 ``` Example of the error message after this change: ``` Traceback (most recent call last): File "/mbed-os/tools/psa/tfm/bin_utils/wrapper.py", line 13, in import click ModuleNotFoundError: No module named 'click' Traceback (most recent call last): File "platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py", line 194, in sign_and_merge_tfm_bin(args.tfm_target, args.target_path, args.non_secure_bin, args.secure_bin) File "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 ``` This is a significant improvement as now you can see what the reason for the failure was. --- .../TARGET_TFM_LATEST/scripts/generate_mbed_image.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py index fb7000386ba3..840aee13b1d9 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py @@ -152,14 +152,11 @@ def find_bl2_size(configFile): return bl2_size def run_cmd(cmd, directory): - popen_instance = subprocess.Popen( cmd, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=directory, ) - popen_instance.communicate() return popen_instance.returncode