-
Notifications
You must be signed in to change notification settings - Fork 0
Target Class
Target is a high-level interface for the target device — the Silicon Labs MCU/SoC behind the adapter. It works with any supported debug adapter (Silicon Labs or generic J-Link). It covers flashing, erasing, CTUNE, flash protection, security/Secure Engine, key provisioning, and Series 3 code-region configuration.
from pathlib import Path
from pycommander import Commander, Target
commander = Commander(serial_number="440055955")
target = Target(part_number="EFR32MG24", commander=commander)
print(target.info())
target.flashApplication(filenames=[Path("firmware.hex")], masserase=True, verify=True)Target(part_number: str, commander: CommanderBase)-
part_number— the device part number (e.g."EFR32MG24"); applied as--deviceto the underlying commands. -
commander— aCommander/CommanderBaseproviding the connection.
When you build an Adapter with a target_device, a Target is created automatically and attached as adapter.target.
Return conventions. Look-ups return a typed dataclass (see Data-Types) or
Noneon failure. Actions returnbool. Methods that take file paths raiseFileNotFoundErrorif a file is missing, and some raiseValueErrorfor invalid arguments — all before Commander is invoked.
⚠️ Several security operations write to OTP memory or permanently change device lifecycle state. These are flagged below and typically gated behind aconfirmargument. They cannot be undone.
Return a TargetInfo (part number, die revision, production version, flash/SRAM size, unique ID), or None.
Reset the target device.
Mass-erase the device, clearing the main flash.
Erase selected flash pages.
-
ranges: list[tuple[int|str, int|str]]—(start, end)ranges; extended to page boundaries. -
regions: list[str]— named memory regions (@region).
flashApplication(filenames, address=None, include_sections=[], exclude_sections=[], treat_as_binary=False, masserase=False, force=False, reset=True, halt=False, close=True, verify=True) -> bool
Flash one or more images (.bin, .s37, .hex, .gbl, .rps) and handle the flash/verify/reset steps.
-
filenames: list[Path]— files to flash (must exist). -
address: int— flash address; ignored for.hex/.s37. -
include_sections/exclude_sections— ELF sections to include/exclude. -
treat_as_binary— treat files as flat binaries regardless of extension. -
masserase— mass-erase before flashing. -
force— force the flash. -
reset— reset after flashing (defaultTrue). -
halt— halt the device after flashing. -
close— close code regions after flashing (Series 3 only). -
verify— verify flash contents afterward (defaultTrue).
target.flashApplication(filenames=[Path("firmware.hex")], masserase=True, verify=True)flashRamCode(filenames, address=None, include_sections=[], exclude_sections=[], vtor=None, force=False, halt=False) -> bool
Flash code into RAM (no reset). vtor sets the vector table address (ignored for .hex/.s37).
Apply memory patches.
-
patches: list[tuple[int|str, int|str, int|str|None]]—(address, data[, length])entries.
Read the CTUNE values present on the device as a CtuneValue — from the Device Info page (di), the board EEPROM (board), and the MFG token (token).
Write the CTUNE token.
- If
valueisNone, the value is taken from the board EEPROM (auto-set). - If
valueis anint, that value is written. -
forcewrites even when the desired value is already configured. Withoutforce, the method short-circuits toTrueif the token already matches.
ctune = target.getCTUNE()
target.setCTUNE(ctune.board) # copy board value into the token
target.setCTUNE(0xA8) # set an explicit valueWrite-protect the given ranges and/or regions. At least one must be specified (otherwise ValueError).
Read-protect the given ranges and/or regions. At least one must be specified.
Disable write protection across the entire flash.
Disable read protection across the entire flash.
target.enableWriteProtection(ranges=[(0x00000000, 0x00008000)])
target.disableWriteProtection()Return a SecurityStatus describing boot status, installed keys, debug-lock / device-erase / secure-boot / secure-debug-unlock state, SE firmware version, tamper state, and (optionally) TrustZone config/state. Returns None on failure.
Enable secure debug unlock.
Disable secure debug unlock.
⚠️ If device erase is disabled and the device is locked, debug access becomes permanently disabled. Passconfirm=Trueto proceed without the prompt.
lockDebugAccess(trustzone=None, allow_reset=True, disable_device_erase=False, confirm=False) -> bool
Lock the debug interface via the Secure Engine.
-
trustzone— a 4-bit string (each char"0"/"1"); invalid values raiseValueError. -
disable_device_erase— also disable device erase (requiresconfirm=True).
⚠️ Disabling device erase is permanent and irreversible.
unlockDebugAccess(allow_reset=True, certificate_file=None, certificate_private_key=None, certificate_public_key=None, certificate_signature=None, command_key=None, command_signature=None, authorization=None, unlock_param=None) -> bool
Unlock the debug interface via the Secure Engine, supplying the relevant certificate/signature/authorization material.
Generate an AES-CCM GBL decryption key and write it to outfile.
Write a GBL decryption key to OTP memory.
⚠️ Permanent. Passconfirm=Trueto proceed without the prompt.
Generate an ECC-P256 signing key pair; optionally also write the public key to a token file.
Read the public signing key from the device (or None).
Write a public signing key to OTP memory. Raises RuntimeError if one already exists.
⚠️ Permanent.
Generate an ECC-P256 command key pair; optionally write the public key to a token file.
Read the public command key from the device (or None).
Write a public command key to OTP memory. Raises RuntimeError if one already exists.
⚠️ Permanent.
writeManufacturingTokens(tokenfiles=[], tokens=[], tokengroup=None, tokendefs=None, securerange=None) -> bool
Write manufacturing tokens. Series 1 and 2 only. Token files must exist.
-
tokens: list[tuple[str, str]]—(TOKEN_NAME, value)entries.
writeStaticTokens(tokenfiles=[], tokens=[], tokengroup=None, tokendefs=None, securerange=None) -> bool
Write static tokens. Series 3 only. (Same parameters; delegates to the same Commander operation.)
For lower-level token read/erase/header operations, see the tokens command reference.
Read the device's region configuration as a RegionConfig (code_regions + data_region), or None.
Read the region configuration and write it to a file.
Write a region configuration. Without force, the method first reads the existing config and skips the write (returning True) if it already matches. Invalid protection modes raise ValueError.
Write a region configuration from a YAML file. The file must exist and contain a regions list, each with size_kb and a valid protection_mode; otherwise ValueError / FileNotFoundError.
Close a code region by index. code_version (if given) must be a 32-bit unsigned integer. An out-of-range index raises ValueError. Without force, an already-closed region returns True.
Region CodeRegionConfig entries carry a CodeRegionProtectionMode (ENCRYPTED_AND_AUTHENTICATED, ENCRYPTED, NONE).
Generate a security configuration. If outfile is None, the config is written to this computer's security store; otherwise to the file.
Read the security configuration from the device as a dict, or None.
Write a security configuration. If config_file is None, it is taken from this computer's security store for the device.
⚠️ Permanent. Passconfirm=Trueto proceed without the prompt.
Provision the Secure Engine firmware from a file (must exist).
Upgrade the Secure Engine firmware. If sefw_file is None, the bundled SE firmware is used. confirm=True is only required when the supplied address is in RAM.
Check whether a newer SE firmware is available; returns a SeFirmwareInfo (current_version, latest_version, upgrade_available), or None.
- Data-Types — every dataclass and enum returned above.
-
Reference-Security — the lower-level
securitycommand suite these helpers build on. -
Reference-Device-Flash-Memory — the
device,flashandverifysuites.
PyCommander · GitHub · Simplicity Commander docs · Licensed under the Silicon Labs MSLA
Getting started
Using PyCommander
Topics
Command reference
- Overview
- adapter · aem · vcom · ctune
- device · flash · verify · readmem · extflash
- security
- tokens · nvm3 · littlefs
- convert · ebl · gbl3 · gbl4 · ota · rps · postbuild
- util · serial · mfg917
Contributing