flash_tools
Gadgets for hacking on monome firmware images.
Setup
Needs Python 3.5-ish.
python -m virtualenv .
source Scripts/activate
pip install -r requirements.pipTools
repl - firmware file inspection
python main.py teletype repl --version 3.0.0 teletype-backup.hexwill drop you to a Python shell. Variables in scope are:
-
ffi- A CFFI instance for working with C data structures, with the definitions in scope for the flash data structure of firmware/version you specify. -
ih- An IntelHex instance with the specified hex file loaded. -
flash- Abyteswith the whole contents of flash. -
nvram_data- The C structure from flash represented as a python object (built by CFFI). -
hexdump- A function for formatting bytestrings as more readable hex dumps.
extract - convert presets from a hexdump to a JSON file
Get into bootloader mode:
- turn off ansible
- unplug the USB A-A cable from ansible
- hold down the preset/mode button while powering on ansible
- plug in the USB A-A cable
Dump the hex file:
dfu-programmer at32uc3b0512 read > ansible-backup.hexRun the script:
python main.py ansible extract --version 1.6.1 ansible-backup.hex --out ansible-presets.jsonThe preset format from the module's flash is different depending on
your firmware version, so you need to specify the firmware version the
hexdump came from with the --version switch if different from the
default (1.6.1). Support for a different firmware version is
straightforward to add, see e.g. schemata/v161.py.
docdef - generate data structures describing C structs as JSON
This is the flakiest one and will require some manual editing of the result, docs and cleanup forthcoming.