From 4f38ab4538cab071f87b615d95736ebc5fe93b61 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:02:59 -0500 Subject: [PATCH] [Silabs] Add .rps support in the build step and flasher script (#30444) --- build/toolchain/flashable_executable.gni | 6 ++ scripts/examples/gn_silabs_example.sh | 2 +- ...ware_utils.py => silabs_firmware_utils.py} | 16 +++--- third_party/silabs/silabs_board.gni | 7 +++ third_party/silabs/silabs_executable.gni | 55 +++++++++++++++++-- 5 files changed, 73 insertions(+), 13 deletions(-) rename scripts/flashing/{efr32_firmware_utils.py => silabs_firmware_utils.py} (93%) diff --git a/build/toolchain/flashable_executable.gni b/build/toolchain/flashable_executable.gni index 97b2b44f1ac51c..6233d58382b43d 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 the 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 0ebcc463ff7454..ae1d60e4eb69d7 100755 --- a/scripts/examples/gn_silabs_example.sh +++ b/scripts/examples/gn_silabs_example.sh @@ -285,7 +285,7 @@ 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 optArgs+="chip_device_platform =\"SiWx917\" " 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..5e0a689f5a62f4 100755 --- a/scripts/flashing/efr32_firmware_utils.py +++ b/scripts/flashing/silabs_firmware_utils.py @@ -12,19 +12,19 @@ # 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. 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] -Flash EFR32 device +Flash SILABS device optional arguments: -h, --help show this help message and exit @@ -55,7 +55,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. @@ -71,7 +71,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. """, @@ -105,11 +105,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'}, { 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..a639a4d19ae62d 100644 --- a/third_party/silabs/silabs_executable.gni +++ b/third_party/silabs/silabs_executable.gni @@ -14,12 +14,40 @@ import("//build_overrides/build.gni") 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" objcopy_image_format = "srec" objcopy = "arm-none-eabi-objcopy" @@ -29,9 +57,13 @@ 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/efr32_firmware_utils.py", + "${chip_root}/scripts/flashing/silabs_firmware_utils.py", "${chip_root}/scripts/flashing/firmware_utils.py", ] copy(flashing_runtime_target) { @@ -42,7 +74,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" @@ -62,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" ] + } } }