
Tool for programming Tock onto hardware boards.
Install
pip3 install pipx
pipx install tockloader
If you want tab completions:
register-python-argcomplete tockloader >> ~/.bashrc
Usage
This tool installs a binary called tockloader, which supports several commands.
Primary Commands
These are the main commands for managing apps on a board.
tockloader install
Load Tock applications on to the board. Use --no-replace to install
multiple copies of the same app.
tockloader update
Update an application that is already flashed to the board with a new
binary.
tockloader uninstall [application name(s)]
Remove an application from flash by its name.
Board Inspection Commands
These query the board for its current state.
tockloader list
Print information about the apps currently loaded onto the board.
tockloader info
Show all properties of the board.
Utility Commands
These provide other helpful features.
tockloader listen
Listen to UART printf() data from a board. Use the option --rtt to use
Segger's RTT listener instead of using a serial port.
Other Commands
These provide more internal functionality.
tockloader flash
Load binaries onto hardware platforms that are running a compatible bootloader.
This is used by the TockOS Make system
when kernel binaries are programmed to the board with make program.
tockloader inspect-tab
Show details about a compiled TAB file.
tockloader enable-app [application name(s)]
Enable an app so that the kernel will run it at boot.
tockloader disable-app [application name(s)]
Disable an app so that the kernel will not start it at boot.
tockloader sticky-app [application name(s)]
Mark an app as sticky so that the --force flag is required to uninstall it.
tockloader unsticky-app [application name(s)]
Remove the sticky flag from an app.
tockloader list-attributes
Show all of the attributes that are stored on the board.
tockloader set-attribute [attribute key] [attribute value]
Set a particular attribute key to the specified value. This will overwrite
an existing attribute if the key matches.
tockloader remove-attribute [attribute key]
Remove a particular attribute from the board.
tockloader dump-flash-page [page number]
Show the contents of a page of flash.
tockloader read [address] [# bytes]
Read arbitrary flash memory from the board.
tockloader write [address] [# bytes] [value]
Write arbitrary flash memory on the board with a specific value.
tockloader list-known-boards
Print which boards tockloader has default settings for built-in.
tockloader set-start-address [address]
Set the jump address the bootloader uses for the location of the kernel.
tockloader local-board set [board]
Set the name of the board to use with a local binary file instead of hardware.
tockloader local-board unset
Remove the board to use with a local binary file instead of hardware.
tockloader local-board flush
Write the local binary file to the hardware board.
tockloader tbf tlv add|modify|delete [TLVNAME]
Interact with TLV structures within a TBF.
tockloader tbf credential add|delete [credential type]
Add and remove credentials in the TBF footer.
tockloader tbf convert [output format]
Convert a TBF to a different format.
tockloader kernel attrs add [attr_type] [attr_args] [kernel binary]
Interact with kernel attributes.
tockloader tickv get|append|invalidate|dump|cleanup|reset [key] [value]
Interact with a TicKV key-value database.
Specifying the Board
For tockloader to know how to interface with a particular hardware board,
it tries several options:
Read the parameters from the bootloader. Tockloader assumes it can open a
serial connection to a
tock-bootloader on the board.
Use JLinkExe, OpenOCD, STLink, or the default virtual board to discover
known boards.
Use the --board command line flag and a list of known boards.
Use individual command line flags that specify how to interact with the
board.
If command line flags are passed they take priority over any automatically
discovered options.
Tockloader has hardcoded parameters for a variety of boards. You can list these
with:
tockloader list-known-boards
To use a known board, if it is not automatically discovered, you can:
tockloader [command] --board [board]
If your board is not a known board, you can specify the required parameters
via command line options. Note, you also need to provide a name for the board.
tockloader [command] --board [board] --arch [arch] --page-size [page_size]
board: The name of the board. This helps prevent incompatible applications
from being flashed on the wrong board.
arch: The architecture of the board. Likely cortex-m0 or cortex-m4.
page_size: The size in bytes of the smallest erasable unit in flash.
Specifying the Communication Channel
Tockloader defaults to using a serial connection to an on-chip bootloader to
program and interact with a board. If you need to use a different communication
mechanism, you can specify what Tockloader should use with command line
arguments. Note, Tockloader's board autodiscovery process also selects different
communication channels based on which board it finds.
To use a JTAG interface using JLinkExe, specify --jlink. JLinkExe requires
knowing the device type of the MCU on the board.
tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--jlink --jlink-cmd [jlink_cmd] --jlink-device [device] \
--jlink-speed [speed] --jlink-if [if] \
--jlink-serial-number [serial_number]
jlink_cmd: The JLink executable to invoke. Defaults to JLinkExe on
Mac/Linux, and JLink on Windows.
device: The JLinkExe device identifier.
speed: The speed value to pass to JLink. Defaults to 1200.
if: The interface to pass to JLink.
serial-number: The serial number of the target board to use with JLink.
Tockloader can also do JTAG using OpenOCD. OpenOCD needs to know which config
file to use.
tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--openocd --openocd-board [openocd_board] \
--openocd-cmd [openocd_cmd] \
--openocd-options [openocd_options] \
--openocd-commands [openocd_commands]
openocd_board: The .cfg file in the board folder in OpenOCD to use.
openocd_cmd: The OpenOCD executable to invoke. Defaults to openocd.
openocd_options: A list of Tock-specific flags used to customize how
Tockloader calls OpenOCD based on experience with various boards and their
quirks. Options include:
noreset: Removes the command reset init; from OpenOCD commands.
nocmdprefix: Removes the commands init; reset init; halt; from OpenOCD
commands.
workareazero: Adds the command set WORKAREASIZE 0; to OpenOCD commands.
resume: Adds the commands soft_reset_halt; resume; to OpenOCD commands.
openocd_commands: This sets a custom OpenOCD command string to allow
Tockloader to program arbitrary chips with OpenOCD before support for the
board is officially include in Tockloader. The following main operations can
be customized:
program: Operation used to write a binary to the chip.
read: Operation used to read arbitrary flash memory on the chip.
erase: Operation that erases arbitrary ranges of flash memory on the chip.
The custom values are specified as key=value pairs, for example,
--openocd_commands 'program=write_image; halt;' 'erase=flash fillb {address:#x} 0xff 512;'. Operation strings can include wildcards which will
get set with the correct value by Tockloader:
{{binary}}: The binary file path.
{address:#x}: The specified address for the binary to be programmed at.
{length}: The number of bytes. Only valid for the read operation.
For STM32 boards, Tockloader supports
STLINK. The stlink tool knows how to
interface with the boards, so there are not many flags.
tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--stlink \
--stinfo-cmd [stinfo_cmd] --stflash-cmd [stflash_cmd]
stinfo_cmd: The st-info executable to invoke. Defaults to st-info.
stflash_cmd: The st-flash executable to invoke. Defaults to st-flash.
For nRF5x boards, Tockloader supports
nrfutil. This
tool uses JLink to program Nordic's nRF5x development boards. After installing
nrfutil, be sure to run nrfutil install device to be able to flash
hardware.
tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--nrfutil \
--nrfutil-cmd [nrfutil_cmd]
--nrfutil-serial-number [serial_number]
nrfutil_cmd: The nrfutil executable to invoke. Defaults to nrfutil.
serial_number: The serial number of a particular board to flash. Defaults to
the first board discovered.
For NXP boards, Tockloader supports
LinkServer.
This tool uses LinkServer to program NXP boards.
tockloader [command] --board [board] --arch [arch] --page-size [page_size] \
--linkserver \
--linkserver-cmd [linkserver_cmd]
--linkserver-device [linkserver_device]
--linkserver-probe [linkserver_probe]
linkserver_cmd: The LinkServer executable to invoke. Defaults to
LinkServer.
linkserver_device: The LinkServer device name to use with the flash
command.
linkserver_probe: The probe index or serial number to use.
For Espressif boards, Tockloader supports using
esptool. This tool can communicate with
the serial-based bootloader in Espressif chips to program their external SPI
flash.
tockloader [command] --esptool [--port [port]] [--board [board]]
port: The serial port that the ESP chip is attached to. Required if more
than one candidate port is found.
board: Defaults to esp32-c3-devkitm-1 for chips attached to a USB-UART
bridge, and esp32-c3-devkit-rust-2 for chips attached through their
integrated USB Serial/JTAG controller.
esptool (>= 5.0) is an optional dependency, as it is GPL-licensed. Install it
with pip install esptool or pipx inject tockloader esptool, depending on how
you installed Tockloader.
Finally, Tockloader can treat a local file as though it were the flash contents
of a board. The file can then be loaded separately onto a board.
tockloader [command] --flash-file [filepath]
filepath: The file to use as the flash contents. Will be created if it
doesn't exist.
Tockloader can use a flash file by default. This is particularly helpful for
virtual, QEMU-based boards, or other boards that do not support fine-grained
reading and writing. You can set the default local board to use:
tockloader local-board set [board]
If the board you are using is new or not a known board in tockloader, you can
manually specifying the necessary parameters:
tockloader local-board set [board] --arch [arch] --app-address [address] --flash-address [address] --flush-command [command] --binary-path [path]
board: Name of the board you want to use.
arch: Name of the architecture the board uses.
app-address: The flash address where apps start.
flash-address: The address where flash starts.
flush-command: The command to write the file to the board. Use {binary} to
specify where the file path should go in the command.
binary-path: Where the actual flash-file binary should be located. Optional.
If not provided defaults to a suitable tockloader application data
directory.
Then, tockloader commands will use a virtual image file for all operations that
interact with a board.
You can reverse this with:
tockloader local-board unset
Example Usage
Install an app, make sure it's up to date, and make sure it's the only app on
the board:
tockloader install --make --erase
Get all info from the board that can be used to help debugging:
tockloader info
Print additionally debugging information. This can be helpful when using JTAG.
tockloader install --debug
Get printf() data from a board:
tockloader listen
Additional Flags