Skip to content

Commit c64a28e

Browse files
committed
zephyr: west: add gigadevice west extension commands
1 parent ac01cb9 commit c64a28e

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

zephyr/west/gigadevice.py

100644100755
Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,52 @@
1111
from west.commands import WestCommand # your extension must subclass this
1212
from west import log # use this for user output
1313

14+
from pathlib import Path
15+
import yaml
16+
import os
1417

15-
class Gigadevice(WestCommand):
18+
REPO_ROOT = Path(__file__).absolute().parents[2]
19+
"""Repository root (used for input/output default folders)."""
20+
21+
22+
class Install:
23+
def __init__(self, config=REPO_ROOT / 'zephyr' / 'west' / 'gigadevice.yml'):
24+
self.config = self.parse_config(config)
25+
self.pyocd_install()
26+
27+
def parse_config(self, config):
28+
with open(config, 'r') as f:
29+
return yaml.safe_load(f)
30+
31+
def pyocd_install(self):
32+
for pyocd_packages in self.config['pyocd-packages']:
33+
self.pyocd_install_one(pyocd_packages)
1634

35+
def pyocd_install_one(self, package):
36+
print(package)
37+
if 'url' in package:
38+
self.pyocd_install_one_from_url(package)
39+
else:
40+
self.pyocd_install_one_from_mdk(package)
41+
42+
def pyocd_install_one_from_mdk(self, package):
43+
# run shell command: pyocd pack install package['pack']
44+
os.system('echo pyocd pack install ' + package['pack'])
45+
pass
46+
47+
def pyocd_install_one_from_url(self, package):
48+
file_name = '%s.rar' % package['pack']
49+
# Download from url to tmp folder
50+
log.inf('download', package['url'], 'to', file_name)
51+
# unrar file to tmp folder
52+
os.system(f'echo unrar x ${file_name}')
53+
# find pack file in tmp folder
54+
# check pack file hash value
55+
# storage pack file to support folder
56+
pass
57+
58+
59+
class Gigadevice(WestCommand):
1760
def __init__(self):
1861
super().__init__(
1962
'gigadevice', # gets stored as self.name
@@ -45,8 +88,6 @@ def do_run(self, args, unknown_args):
4588
# required is BAR
4689
match args.command:
4790
case 'install':
48-
log.inf('command is', args.command)
49-
log.inf('we can install some pack for pyocd')
50-
log.inf('TODO: RUN: pyocd pack install gd32e103')
91+
Install()
5192
case _:
52-
log.inf('command is', args.command)
93+
log.inf('command is', args.command, REPO_ROOT)

zephyr/west/gigadevice.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2023 YuLong Yao <[email protected]>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
pyocd-packages:
6+
- pack: gd32e103
7+
- pack: gd32a503
8+
url: https://www.gd32mcu.com/download/down/document_id/405/path_type/1
9+
hash: xxxxx

0 commit comments

Comments
 (0)