Skip to content

Commit c448c20

Browse files
committed
scripts: runners: Add cvi-fiptool
The SOPHGO CVI series SoCs load the RTOS kernel for the 2nd core from a `fip.bin` located in the main storage. This commit introduced a convenient script for updating the `fip.bin` on the external storage mounted to the host, with the newly built `zephyr.bin`. Path to the `fiptool.py` from the official SDK should be provided. Signed-off-by: Chen Xingyu <[email protected]>
1 parent 175cfcc commit c448c20

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

boards/common/cvi-fiptool.board.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
board_set_flasher_ifnset(cvi-fiptool)
4+
board_finalize_runner_args(cvi-fiptool)

scripts/west_commands/runners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def _import_runner_module(runner_name):
3030
'blackmagicprobe',
3131
'bossac',
3232
'canopen_program',
33+
'cvi-fiptool',
3334
'dediprog',
3435
'dfu',
3536
'ecpprog',
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2024 Chen Xingyu <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
'''SOPHGO CVI specific flash only runner.'''
5+
6+
import sys
7+
import time
8+
from os import path
9+
10+
from runners.core import RunnerCaps, ZephyrBinaryRunner
11+
12+
13+
class CviFiptoolBinaryRunner(ZephyrBinaryRunner):
14+
'''Runner front-end for the SOPHGO CVI boards, using fiptool.py from SDK.'''
15+
16+
def __init__(self, cfg, fiptool_py, fip_bin):
17+
super().__init__(cfg)
18+
self.fiptool_py = fiptool_py
19+
self.fip_bin = fip_bin
20+
self.bin_name = cfg.bin_file
21+
22+
@classmethod
23+
def name(cls):
24+
return 'cvi-fiptool'
25+
26+
@classmethod
27+
def capabilities(cls):
28+
return RunnerCaps(commands={'flash'})
29+
30+
@classmethod
31+
def do_add_parser(cls, parser):
32+
parser.add_argument('--fiptool', required=True, help='path to fiptool.py script from SDK')
33+
parser.add_argument('--fip-bin', required=True, help='path to fip.bin file to be updated')
34+
35+
@classmethod
36+
def do_create(cls, cfg, args):
37+
return CviFiptoolBinaryRunner(cfg, args.fiptool, args.fip_bin)
38+
39+
def do_run(self, command, **kwargs):
40+
self.require(self.fiptool_py)
41+
42+
fip_dir = path.dirname(self.fip_bin)
43+
if not path.exists(fip_dir):
44+
print(f'Waiting for {fip_dir} to be present...')
45+
while not path.exists(fip_dir):
46+
time.sleep(1)
47+
48+
if not path.exists(self.fip_bin):
49+
raise RuntimeError(f'File {self.fip_bin} not found')
50+
51+
cmd_flash = [sys.executable, self.fiptool_py]
52+
53+
cmd_flash.extend(['-v', 'genfip', self.fip_bin])
54+
cmd_flash.extend(['--OLD_FIP', self.fip_bin])
55+
cmd_flash.extend(['--BLCP_2ND', self.bin_name])
56+
57+
self.check_call(cmd_flash)
58+
59+
print('')
60+
print('fip.bin updated. Remember to eject the drive before unplugging.')

scripts/west_commands/tests/test_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_runner_imports():
2121
'blackmagicprobe',
2222
'bossac',
2323
'canopen',
24+
'cvi-fiptool',
2425
'dediprog',
2526
'dfu-util',
2627
'ecpprog',

0 commit comments

Comments
 (0)