Skip to content

Commit

Permalink
[Silabs] Add .rps support in the build step and flasher script (#30444)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs authored and pull[bot] committed Nov 27, 2023
1 parent 406dd4d commit 4f38ab4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 13 deletions.
6 changes: 6 additions & 0 deletions build/toolchain/flashable_executable.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/gn_silabs_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\" "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
""",
Expand Down Expand Up @@ -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'}, {
Expand Down
7 changes: 7 additions & 0 deletions third_party/silabs/silabs_board.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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,
Expand Down
55 changes: 51 additions & 4 deletions third_party/silabs/silabs_executable.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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"
Expand All @@ -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" ]
}
}
}

0 comments on commit 4f38ab4

Please sign in to comment.