Home

Awesome

Ktool

Ktool is the enhanced version of Kendryte kflash.py utility.

It is compatible with kflash.py but introduces many new features and enhancement.

Full sources of the enhanced 2nd stage ISP are available in this repository's src/isp directory.<br> More information about 2nd stage ISP and build instructions are available in the build directory.

<br>

How it works

<br>

Features:

<br>

Standard command line arguments:

Argument                         Description
-h<br>--helpShow help message and exit
-v<br>--versionPrint version and exit
-p PORT<br>--port PORTCommunication port used to connect to the K210 board<br>If not given, automatic port detection is atempted
-b BAUDRATE<br>--baudrate BAUDRATEUART baudrate used for for communication with 2nd stage ISP. Communication with 1st stage ISP is always performed at 115200 Bd.<br>default: 115200
-l ISP_BIN<br>--bootloader ISP_BIN2nd stage ISP binary file name.<br>External ISP binary is usually used only for testing.<br>If not given, internal ISP binary is used (recommended)
-k KEY<br>--key KEYAES key in hex, if you need to encrypt the firmware.<br>There is no documentation about how it works, it probably requires some programming of K210 OTP memory, firmware flashed with this option will not start<br>If not given, no AES encription is used
-t<br>--terminalOpen terminal emulator (default: miniterm) after the operation is finished<br>default: False
-n<br>--noansiDo not use ANSI colors, recommended when ANSI colors are not supported<br>(for example in Windows Command prompt)<br>default: False
-B BOARD<br>--Board BOARDSelect the board to which you are trying to connect<br>Different boards my have different reset to bootloader requirements.<br>If not given automatic board detection is atempted, which usually works good<br>Supported: ḋan, bit, trainer, kd233, goE, goD<br>default: None
--verboseIncrease output verbosity; default: False; not used
-S<br>--SlowSlow download mode; default: False; not used
firmwareThe only positional argument, usually given after all other arguments<br>Name of the file containing firmware or other data to be flashed to K210 SPI Flash<br> Name of the firmware file to be loaded to K210 SRAM and executed<br>Not needed for erase operation, optional for read operation<br>The file may contain binary firmware/data, firmware ELF file or kfpkg package (see below)
<br>

New and changed command line arguments:

Argument                  Description
-a ADDRESS<br>--address ADDRESSFlash address at which the firmware/data will be written for Flash write operations<br>Flash address from which the data will be read for Flash read operations<br>integer, can be given as decimal or hex number<br>default: 0
-E<br>--eraseErase the whole flash chip<br>Be carefull!
-L<br>--rdlenThe length of data to be read from Flash<br>integer, can be given as decimal or hex number<br>default: 0
-R<br>--readRead data from Flash address specified by --address<br>The data will be saved to the firmware name specified in command line<br>default: "flash_dump.bin"
--swapendianSwap endianess when writing the data.<br>It may be necessary when writing some kind of data, for example file system image<br>default: False
-s<br>--sramDownload firmware to K210 SRAM and boot<br>Loading is done by the 2nd stage ISP and can be performed at any baudrate supported by the board<br>default: False<br>kflash.py supports this function, but loading to SRAM is done at 115200 baud, making it impractical for larger firmwares
--termbdr BAUDRATEUART baudrate used for for terminal emulator<br>default: 115200
--noshaFlash without firmware prefix and SHA suffix<br>Used when flashing data which is not executable firmware<br>default: False
-T<br>--onlytermDo not perform any operation, only start the terminal emulator<br>default: False
--resetReset the board before running terminal emulator, used only with --onlyterm option<br>default: False
<br>

kfpkg package

kfpgk package is a ZIP archive containing several firmware or data binary files and a json file describing its content.<br> It is convenient to use it when multiple files must be flashed at different Flash addresses and with different options.

ktool.py can proces this file, unpack the content and perform the necessary operations.

The package must contain the JSON file named flash-list.json which describes which files are to be flashed and how.

The following objects must be present to describe each file under files object:

KeyValue description
addressinteger; Flash address at which the file content will be written
binstring; Name of the file containing firmware/data to be flashed
sha256Prefixboolean<br>if true flash with firmware prefix and SHA suffix (flash the executable firmware)<br>if ḟalse flash without firmware prefix and SHA suffix (data)
swapboolean, may be omitted, if not present defaults to false<br>If true, swap endianess when writing the data.<br>It may be necessary when writing some kind of data, for example file system image
<br>

Examples of flash-list.json

{
    "version": "0.1.0",
    "files": [
        {
            "address": 0,
            "bin": "MicroPython.bin",
            "sha256Prefix": true,
            "swap": false
        },
        {
            "address": 5242880,
            "bin": "MicroPython_lfs.img",
            "sha256Prefix": false,
            "swap": true
        }
    ]
}
{
    "version": "0.1.1",
    "files": [
        {
            "address": 0,
            "bin": "bootloader_lo.bin",
            "sha256Prefix": true
        },
        {
            "address": 4096,
            "bin": "bootloader_hi.bin",
            "sha256Prefix": true
        },
        {
            "address": 16384,
            "bin": "config.bin",
            "sha256Prefix": false
        },
        {
            "address": 20480,
            "bin": "config.bin",
            "sha256Prefix": false
        }
    ]
}