From a54a5e04d93820cef896b3372dbfe345ff1ccc6d Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Mon, 13 Nov 2023 08:51:09 -0500 Subject: [PATCH 1/8] add rps ext to flasher tools --- scripts/examples/gn_silabs_example.sh | 8 +++++++- ..._firmware_utils.py => silabs_firmware_utils.py} | 14 ++++++++++++-- third_party/silabs/silabs_board.gni | 7 +++++++ third_party/silabs/silabs_executable.gni | 12 +++++++++--- 4 files changed, 35 insertions(+), 6 deletions(-) rename scripts/flashing/{efr32_firmware_utils.py => silabs_firmware_utils.py} (93%) diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 717783cff2925f..0ed6f1815dc984 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -31,6 +31,7 @@ fi set -x env USE_WIFI=false +USE_RPS_EXTENSION=false USE_DOCKER=false USE_GIT_SHA_FOR_VERSION=true USE_SLC=false @@ -281,9 +282,10 @@ else fi # 917 exception. TODO find a more generic way - if [ "$SILABS_BOARD" == "BRD4325B" ] || [ "$SILABS_BOARD" == "BRD4325C" ] || [ "$SILABS_BOARD" == "BRD4338A" ]; then + if [ "$SILABS_BOARD" == "BRD4325B" ] || [ "$SILABS_BOARD" == "BRD4325C" ] || [ "$SILABS_BOARD" == "BRD4338A" ] || [ "$SILABS_BOARD" == "BRD4325G" ]; then echo "Compiling for 917 WiFi SOC" USE_WIFI=true + USE_RPS_EXTENSION=true optArgs+="chip_device_platform =\"SiWx917\" " fi @@ -336,6 +338,10 @@ else #print stats arm-none-eabi-size -A "$BUILD_DIR"/*.out + # Generate RPS file from .s37 for 917 SoC builds + # if ["USE_RPS_EXTENSION" == true]; then + # fi + # add bootloader to generated image if [ "$USE_BOOTLOADER" == true ]; then diff --git a/scripts/flashing/efr32_firmware_utils.py b/scripts/flashing/silabs_firmware_utils.py similarity index 93% rename from scripts/flashing/efr32_firmware_utils.py rename to scripts/flashing/silabs_firmware_utils.py index 989cc97f19ca32..969864e138ada8 100755 --- a/scripts/flashing/efr32_firmware_utils.py +++ b/scripts/flashing/silabs_firmware_utils.py @@ -19,7 +19,7 @@ For `Flasher`, see the class documentation. For the parse_command() interface or standalone execution: -usage: efr32_firmware_utils.py [-h] [--verbose] [--erase] [--application FILE] +usage: silabs_firmware_utils.py [-h] [--verbose] [--erase] [--application FILE] [--verify_application] [--reset] [--skip_reset] [--commander FILE] [--device DEVICE] [--serialno SERIAL] [--ip ADDRESS] @@ -49,6 +49,7 @@ Do not reset device after flashing """ +import os import sys import firmware_utils @@ -133,9 +134,18 @@ def verify(self, image): def flash(self, image): """Flash image.""" + ext = os.path.splitext(image)[-1].lower() + + if ext == ".rps": + # rps load command for .rps files + arguments = ['rps', 'load'] + else: + # flash command for .s37 files + arguments = ['flash'] + return self.run_tool( 'commander', - ['flash', self.DEVICE_ARGUMENTS, image], + [arguments, self.DEVICE_ARGUMENTS, image], name='Flash') def reset(self): diff --git a/third_party/silabs/silabs_board.gni b/third_party/silabs/silabs_board.gni index cd433ed61da49c..dd34fc6e04ef9a 100644 --- a/third_party/silabs/silabs_board.gni +++ b/third_party/silabs/silabs_board.gni @@ -51,6 +51,9 @@ declare_args() { # Self-provision enabled use_provision_channel = false + + # Board required .rps file to flash instead of .s37 + use_rps_extension = false } declare_args() { @@ -111,6 +114,7 @@ if (silabs_board == "BRD4304A") { show_qr_code = false wifi_soc = true silabs_board_lower = "brd4325b" + use_rps_extension = true } else if (silabs_board == "BRD4325C") { silabs_family = "SiWx917-common" silabs_mcu = "SiWG917M111MGTBA" @@ -119,6 +123,7 @@ if (silabs_board == "BRD4304A") { wifi_soc = true wifi_soc_common_flash = true silabs_board_lower = "brd4325c" + use_rps_extension = true } else if (silabs_board == "BRD4325G") { silabs_family = "SiWx917-common" silabs_mcu = "SiWG917M111MGTBA" @@ -127,6 +132,7 @@ if (silabs_board == "BRD4304A") { wifi_soc = true wifi_soc_common_flash = true silabs_board_lower = "brd4325g" + use_rps_extension = true } else if (silabs_board == "BRD4338A") { silabs_family = "SiWx917-common" silabs_mcu = "SiWG917M111MGTBA" @@ -135,6 +141,7 @@ if (silabs_board == "BRD4304A") { wifi_soc = true wifi_soc_common_flash = true silabs_board_lower = "brd4338a" + use_rps_extension = true } else if (silabs_board == "BRD4180A") { assert( false, diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index 5d3c73c0998906..600088d265eadd 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -14,13 +14,19 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") - import("${build_root}/toolchain/flashable_executable.gni") +import("silabs_board.gni") template("silabs_executable") { output_base_name = get_path_info(invoker.output_name, "name") - objcopy_image_name = output_base_name + ".s37" + if (use_rps_extension) { + extension = ".rps" + } else { + extension = ".s37" + } + + objcopy_image_name = output_base_name + extension objcopy_image_format = "srec" objcopy = "arm-none-eabi-objcopy" @@ -31,7 +37,7 @@ template("silabs_executable") { flashing_runtime_target = target_name + ".flashing_runtime" flashing_script_inputs = [ - "${chip_root}/scripts/flashing/efr32_firmware_utils.py", + "${chip_root}/scripts/flashing/silabs_firmware_utils.py", "${chip_root}/scripts/flashing/firmware_utils.py", ] copy(flashing_runtime_target) { From 5b1c84fb08ab31ce309638725f30efe0545aed2f Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 09:50:31 -0500 Subject: [PATCH 2/8] Add rps generation from s37 --- build/toolchain/flashable_executable.gni | 6 +++++ scripts/examples/gn_silabs_example.sh | 31 ++++++++++++++---------- third_party/silabs/silabs_executable.gni | 14 +++++------ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/build/toolchain/flashable_executable.gni b/build/toolchain/flashable_executable.gni index 97b2b44f1ac51c..7394c8644b14d2 100644 --- a/build/toolchain/flashable_executable.gni +++ b/build/toolchain/flashable_executable.gni @@ -147,6 +147,12 @@ template("flashable_executable") { } else { flashing_options = [] } + + # Allows to set a different image name in flasher script + if (defined(invoker.flashing_image_name)) { + image_name = invoker.flashing_image_name + } + flashing_options += [ "--application", rebase_path(image_name, root_out_dir, root_out_dir), diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 0ed6f1815dc984..090aacbcc31dfa 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -338,29 +338,35 @@ else #print stats arm-none-eabi-size -A "$BUILD_DIR"/*.out - # Generate RPS file from .s37 for 917 SoC builds - # if ["USE_RPS_EXTENSION" == true]; then - # fi + # Get .s37 path and name + binName="$(find "$BUILD_DIR" -type f -name "*.s37")" + + # set commander path + if [ -z "$COMMANDER_PATH" ]; then + commanderPath="commander" + else + commanderPath="$COMMANDER_PATH" + fi + + # # Generate RPS file from .s37 for 917 SoC builds + if [ "$USE_RPS_EXTENSION" == true ]; then + + # Create .rps + rpsName=$(sed 's/[^\.]*$/rps/' <<< "$binName") + "$commanderPath" rps create "$rpsName" --app "$binName" + fi # add bootloader to generated image if [ "$USE_BOOTLOADER" == true ]; then - binName="" InternalBootloaderBoards=("BRD4337A" "BRD2704A" "BRD2703A" "BRD4319A") bootloaderPath="" - commanderPath="" + # find the matter root folder if [ -z "$MATTER_ROOT" ]; then MATTER_ROOT="$CHIP_ROOT" fi - # set commander path - if [ -z "$COMMANDER_PATH" ]; then - commanderPath="commander" - else - commanderPath="$COMMANDER_PATH" - fi - # search bootloader directory for the respective bootloaders for the input board bootloaderFiles=("$(find "$MATTER_ROOT/third_party/silabs/matter_support/matter/efr32/bootloader_binaries/" -maxdepth 1 -name "*$SILABS_BOARD*" | tr '\n' ' ')") @@ -378,7 +384,6 @@ else bootloaderPath="${bootloaderFiles[0]}" fi echo "$bootloaderPath" - binName="$(find "$BUILD_DIR" -type f -name "*.s37")" echo "$binName" "$commanderPath" convert "$binName" "$bootloaderPath" -o "$binName" fi diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index 600088d265eadd..05ee67cb8ddf2a 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -19,13 +19,7 @@ import("silabs_board.gni") template("silabs_executable") { output_base_name = get_path_info(invoker.output_name, "name") - - if (use_rps_extension) { - extension = ".rps" - } else { - extension = ".s37" - } - + extension = ".s37" objcopy_image_name = output_base_name + extension objcopy_image_format = "srec" objcopy = "arm-none-eabi-objcopy" @@ -35,6 +29,10 @@ template("silabs_executable") { # even if the build and flashing steps take place on different machines # or in different containers. + if (use_rps_extension) { + flashing_image_name = output_base_name + ".rps" + } + flashing_runtime_target = target_name + ".flashing_runtime" flashing_script_inputs = [ "${chip_root}/scripts/flashing/silabs_firmware_utils.py", @@ -48,7 +46,7 @@ template("silabs_executable") { flashing_script_generator = "${chip_root}/scripts/flashing/gen_flashing_script.py" flashing_script_name = output_base_name + ".flash.py" - flashing_options = [ "efr32" ] + flashing_options = [ "silabs" ] flash_target_name = target_name + ".flash_executable" flashbundle_name = "${target_name}.flashbundle.txt" From 1657b139a945c8f04702fd8af013290648769e96 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 09:52:30 -0500 Subject: [PATCH 3/8] removed unused var --- third_party/silabs/silabs_executable.gni | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index 05ee67cb8ddf2a..177c339e90c806 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -19,8 +19,7 @@ import("silabs_board.gni") template("silabs_executable") { output_base_name = get_path_info(invoker.output_name, "name") - extension = ".s37" - objcopy_image_name = output_base_name + extension + objcopy_image_name = output_base_name + ".s37" objcopy_image_format = "srec" objcopy = "arm-none-eabi-objcopy" From a085ee4f4b81c2fc07ee4268ec35b82aa2b9326b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 14 Nov 2023 14:53:28 +0000 Subject: [PATCH 4/8] Restyled by shfmt --- scripts/examples/gn_silabs_example.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 090aacbcc31dfa..8080a122798a7c 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -352,7 +352,7 @@ else if [ "$USE_RPS_EXTENSION" == true ]; then # Create .rps - rpsName=$(sed 's/[^\.]*$/rps/' <<< "$binName") + rpsName=$(sed 's/[^\.]*$/rps/' <<<"$binName") "$commanderPath" rps create "$rpsName" --app "$binName" fi From 85ffa2dd9c5c5c7615d6aa5f1a6c71fe5580a7cd Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 15:39:00 -0500 Subject: [PATCH 5/8] add build step for rps generation --- build/toolchain/flashable_executable.gni | 2 +- scripts/examples/gn_silabs_example.sh | 26 +++++--------- third_party/silabs/silabs_executable.gni | 44 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/build/toolchain/flashable_executable.gni b/build/toolchain/flashable_executable.gni index 7394c8644b14d2..6233d58382b43d 100644 --- a/build/toolchain/flashable_executable.gni +++ b/build/toolchain/flashable_executable.gni @@ -148,7 +148,7 @@ template("flashable_executable") { flashing_options = [] } - # Allows to set a different image name in flasher script + # Allows to set a different image name in the flasher script if (defined(invoker.flashing_image_name)) { image_name = invoker.flashing_image_name } diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 8080a122798a7c..46977348a742a3 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -338,27 +338,17 @@ else #print stats arm-none-eabi-size -A "$BUILD_DIR"/*.out - # Get .s37 path and name - binName="$(find "$BUILD_DIR" -type f -name "*.s37")" - - # set commander path - if [ -z "$COMMANDER_PATH" ]; then - commanderPath="commander" - else - commanderPath="$COMMANDER_PATH" - fi - - # # Generate RPS file from .s37 for 917 SoC builds - if [ "$USE_RPS_EXTENSION" == true ]; then - - # Create .rps - rpsName=$(sed 's/[^\.]*$/rps/' <<<"$binName") - "$commanderPath" rps create "$rpsName" --app "$binName" - fi - # add bootloader to generated image if [ "$USE_BOOTLOADER" == true ]; then + # Get .s37 path and name + binName="$(find "$BUILD_DIR" -type f -name "*.s37")" + # set commander path + if [ -z "$COMMANDER_PATH" ]; then + commanderPath="commander" + else + commanderPath="$COMMANDER_PATH" + fi InternalBootloaderBoards=("BRD4337A" "BRD2704A" "BRD2703A" "BRD4319A") bootloaderPath="" diff --git a/third_party/silabs/silabs_executable.gni b/third_party/silabs/silabs_executable.gni index 177c339e90c806..a639a4d19ae62d 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -17,6 +17,35 @@ import("//build_overrides/chip.gni") import("${build_root}/toolchain/flashable_executable.gni") import("silabs_board.gni") +template("generate_rps_file") { + forward_variables_from(invoker, + [ + "conversion_input", + "conversion_output", + "deps", + ]) + action(target_name) { + # Check if variables exist + commander_path = getenv("COMMANDER_PATH") + if (commander_path == "") { + commander_path = "commander" + } + + inputs = [ conversion_input ] + outputs = [ conversion_output ] + + args = [ + commander_path, + "rps", + "create", + rebase_path(conversion_output, root_build_dir), + "--app", + rebase_path(conversion_input, root_build_dir), + ] + script = "${build_root}/gn_run_binary.py" + } +} + template("silabs_executable") { output_base_name = get_path_info(invoker.output_name, "name") objcopy_image_name = output_base_name + ".s37" @@ -65,10 +94,25 @@ template("silabs_executable") { deps = [ ":$executable_target" ] } + if (use_rps_extension) { + rps_target_name = target_name + ".rps" + generate_rps_file(rps_target_name) { + conversion_input = "${root_out_dir}/${objcopy_image_name}" + conversion_output = "${root_out_dir}/${flashing_image_name}" + deps = [ + ":$executable_target", + ":$flash_target_name.image", + ] + } + } group(target_name) { deps = [ ":$flash_target_name", ":$hex_target_name", ] + + if (use_rps_extension) { + deps += [ ":$rps_target_name" ] + } } } From df659f08d382665703b72061a5239ce799db2962 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 15:49:37 -0500 Subject: [PATCH 6/8] revert changes on build script --- scripts/examples/gn_silabs_example.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/examples/gn_silabs_example.sh b/scripts/examples/gn_silabs_example.sh index 46977348a742a3..033477b67b886a 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -31,7 +31,6 @@ fi set -x env USE_WIFI=false -USE_RPS_EXTENSION=false USE_DOCKER=false USE_GIT_SHA_FOR_VERSION=true USE_SLC=false @@ -285,7 +284,6 @@ else if [ "$SILABS_BOARD" == "BRD4325B" ] || [ "$SILABS_BOARD" == "BRD4325C" ] || [ "$SILABS_BOARD" == "BRD4338A" ] || [ "$SILABS_BOARD" == "BRD4325G" ]; then echo "Compiling for 917 WiFi SOC" USE_WIFI=true - USE_RPS_EXTENSION=true optArgs+="chip_device_platform =\"SiWx917\" " fi @@ -340,23 +338,23 @@ else # add bootloader to generated image if [ "$USE_BOOTLOADER" == true ]; then - # Get .s37 path and name - binName="$(find "$BUILD_DIR" -type f -name "*.s37")" - # set commander path - if [ -z "$COMMANDER_PATH" ]; then - commanderPath="commander" - else - commanderPath="$COMMANDER_PATH" - fi + binName="" InternalBootloaderBoards=("BRD4337A" "BRD2704A" "BRD2703A" "BRD4319A") bootloaderPath="" - + commanderPath="" # find the matter root folder if [ -z "$MATTER_ROOT" ]; then MATTER_ROOT="$CHIP_ROOT" fi + # set commander path + if [ -z "$COMMANDER_PATH" ]; then + commanderPath="commander" + else + commanderPath="$COMMANDER_PATH" + fi + # search bootloader directory for the respective bootloaders for the input board bootloaderFiles=("$(find "$MATTER_ROOT/third_party/silabs/matter_support/matter/efr32/bootloader_binaries/" -maxdepth 1 -name "*$SILABS_BOARD*" | tr '\n' ' ')") @@ -374,6 +372,7 @@ else bootloaderPath="${bootloaderFiles[0]}" fi echo "$bootloaderPath" + binName="$(find "$BUILD_DIR" -type f -name "*.s37")" echo "$binName" "$commanderPath" convert "$binName" "$bootloaderPath" -o "$binName" fi From d4a2eea048721de923276ab3835219776769272d Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 15:54:16 -0500 Subject: [PATCH 7/8] rename efr32 to silabs --- scripts/flashing/silabs_firmware_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/flashing/silabs_firmware_utils.py b/scripts/flashing/silabs_firmware_utils.py index 969864e138ada8..01353ecd677abc 100755 --- a/scripts/flashing/silabs_firmware_utils.py +++ b/scripts/flashing/silabs_firmware_utils.py @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Flash an EFR32 device. +"""Flash an SILABS device. This is layered so that a caller can perform individual operations through an `Flasher` instance, or operations according to a command line. @@ -24,7 +24,7 @@ [--commander FILE] [--device DEVICE] [--serialno SERIAL] [--ip ADDRESS] -Flash EFR32 device +Flash SILABS device optional arguments: -h, --help show this help message and exit @@ -56,7 +56,7 @@ # Additional options that can be use to configure an `Flasher` # object (as dictionary keys) and/or passed as command line options. -EFR32_OPTIONS = { +SILABS_OPTIONS = { # Configuration options define properties used in flashing operations. 'configuration': { # Tool configuration options. @@ -72,7 +72,7 @@ Unable to execute {commander}. Please ensure that this tool is installed and - available. See the EFR32 example README for + available. See the SILABS example README for installation instructions. """, @@ -106,11 +106,11 @@ class Flasher(firmware_utils.Flasher): - """Manage efr32 flashing.""" + """Manage silabs flashing.""" def __init__(self, **options): - super().__init__(platform='EFR32', module=__name__, **options) - self.define_options(EFR32_OPTIONS) + super().__init__(platform='SILABS', module=__name__, **options) + self.define_options(SILABS_OPTIONS) # Common command line arguments for commander device subcommands. DEVICE_ARGUMENTS = [{'optional': 'serialno'}, { From 890ea43477245028d777fb384560b08e38332912 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Tue, 14 Nov 2023 17:08:52 -0500 Subject: [PATCH 8/8] use flash command for all extensions --- scripts/flashing/silabs_firmware_utils.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/scripts/flashing/silabs_firmware_utils.py b/scripts/flashing/silabs_firmware_utils.py index 01353ecd677abc..5e0a689f5a62f4 100755 --- a/scripts/flashing/silabs_firmware_utils.py +++ b/scripts/flashing/silabs_firmware_utils.py @@ -49,7 +49,6 @@ Do not reset device after flashing """ -import os import sys import firmware_utils @@ -134,18 +133,9 @@ def verify(self, image): def flash(self, image): """Flash image.""" - ext = os.path.splitext(image)[-1].lower() - - if ext == ".rps": - # rps load command for .rps files - arguments = ['rps', 'load'] - else: - # flash command for .s37 files - arguments = ['flash'] - return self.run_tool( 'commander', - [arguments, self.DEVICE_ARGUMENTS, image], + ['flash', self.DEVICE_ARGUMENTS, image], name='Flash') def reset(self):