Skip to content

Commit

Permalink
scripts: runners: Add west flash command for B91 platform
Browse files Browse the repository at this point in the history
This commit implements west flash command for Telink B91 platform.
west flash command uses ICEman and SPI burn from AndeSight for flashing.

Signed-off-by: Alex Kolosov <[email protected]>
  • Loading branch information
rikorsev authored and cfriedt committed Dec 6, 2021
1 parent 3293217 commit f374d6b
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
4 changes: 4 additions & 0 deletions boards/common/spi_burn.board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

board_set_flasher_ifnset(spi_burn)
board_finalize_runner_args(spi_burn)
4 changes: 4 additions & 0 deletions boards/riscv/tlsr9518adk80d/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

board_runner_args(spi_burn --addr 0x0)
include(${ZEPHYR_BASE}/boards/common/spi_burn.board.cmake)
11 changes: 10 additions & 1 deletion boards/riscv/tlsr9518adk80d/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,16 @@ serial port:
Flashing
========

In order to flash the TLSR9518ADK80D board check the following resources:
Use west flash command in order to flash the TLSR9518ADK80D board:

.. code-block:: console
west flash --telink-tools-path=$TELINK_TOOLCHAIN_PATH
Here, TELINK_TOOLCHAIN_PATH is a path to `Telink RISC-V Linux Toolchain`_.
The toolchain contains tools for the board flashing as well.

Refer for the following resources for more information about the board flashing:

- `Burning and Debugging Tools for all Series`_
- `Burning and Debugging Tools for TLSR9 Series`_
Expand Down
1 change: 1 addition & 0 deletions scripts/west_commands/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _import_runner_module(runner_name):
'openocd',
'pyocd',
'qemu',
'spi_burn',
'stm32cubeprogrammer',
'stm32flash',
'xtensa',
Expand Down
100 changes: 100 additions & 0 deletions scripts/west_commands/runners/spi_burn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) 2021, Telink Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

import os
import time
import subprocess

from runners.core import ZephyrBinaryRunner, RunnerCaps

class SpiBurnBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for SPI_burn.'''

def __init__(self, cfg, addr, spiburn, iceman, erase=False):
super().__init__(cfg)

self.bin = cfg.bin_file
self.spiburn = spiburn
self.iceman = iceman
self.addr = addr
self.erase = bool(erase)

@classmethod
def name(cls):
return 'spi_burn'

@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'}, erase=True)

@classmethod
def do_add_parser(cls, parser):
parser.add_argument('--addr', default='0x0',
help='start flash address to write')
parser.add_argument('--telink-tools-path', help='path to Telink flash tools')

@classmethod
def do_create(cls, cfg, args):

if args.telink_tools_path:
spiburn = f'{args.telink_tools_path}/flash/bin/SPI_burn'
iceman = f'{args.telink_tools_path}/ice/ICEman'
else:
# If telink_tools_path arg is not specified then pass to tools shall be specified in PATH
spiburn = 'SPI_burn'
iceman = 'ICEman'

return SpiBurnBinaryRunner(cfg, args.addr, spiburn, iceman, args.erase)

def do_run(self, command, **kwargs):

self.require(self.spiburn)

# Find path to ICEman with require call
self.iceman_path = self.require(self.iceman)

if command == "flash":
self._flash()
else:
self.logger.error(f'{command} not supported!')

def _flash(self):

origin_dir = os.getcwd()
iceman_dir = os.path.dirname(self.iceman_path)

try:

# ICEman tool from Andestech is required to be run from its root dir,
# due to the tool looking for its config files in currently active dir.
# In attempt to run it from other dirs it returns with an error that
# required config file is missing

# Go into ICEman dir
os.chdir(iceman_dir)

# RUN ice in a background
cmd_ice_run = ["./ICEman", '-Z', 'v5', '-l', 'aice_sdp.cfg']

ice_process = subprocess.Popen(cmd_ice_run)

# Wait for initialization
time.sleep(1)

# Compose flash command
cmd_flash = [self.spiburn, '--addr', str(self.addr), '--image', self.bin]

if self.erase:
cmd_flash += ["--erase-all"]

# Run SPI burn flash tool
self.check_call(cmd_flash)

finally:

# Kill ICEman
ice_process.terminate()

# Restore origin dir
os.chdir(origin_dir)
1 change: 1 addition & 0 deletions scripts/west_commands/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_runner_imports():
'openocd',
'pyocd',
'qemu',
'spi_burn',
'stm32cubeprogrammer',
'stm32flash',
'xtensa'))
Expand Down

0 comments on commit f374d6b

Please sign in to comment.