Skip to content

Commit 4aec012

Browse files
Appana Durga Kedareswara raomichalsimek
authored andcommitted
zephyr: add support for running lopper commands using west
Update the west to install lopper and use lopper to generate zephyr specific device-trees and config files, not sure whether it's proper way of doing or not please suggest the proper way for plumbing the lopper into west tool. Usage: 1) west update i) clones the lopper repo from github repo. 2) west lopper-install i) installs the lopper binary so that subsequent scripts can import the lopper binary. 3) west lopper-command -p <processor name> -s <system device-tree system-top.dts path> -w <workspace path> i) generates the zephyr specific device-tree's and config files like Kconfig etc, currently script supports only microblaze risc-v. Signed-off-by: Appana Durga Kedareswara rao <[email protected]> Message-ID: <[email protected]> State: pending
1 parent dc242df commit 4aec012

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed

scripts/west-commands.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,13 @@ west-commands:
7676
- name: simulate
7777
class: Simulate
7878
help: simulate board
79+
- file: scripts/west_commands/lopper_install.py
80+
commands:
81+
- name: lopper-install
82+
class: LopperInstall
83+
help: Install lopper as a part of environment
84+
- file: scripts/west_commands/lopper_command.py
85+
commands:
86+
- name: lopper-command
87+
class: LopperCommand
88+
help: work with Lopper Commands
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2024 Advanced Micro Devices, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import subprocess
6+
import sys
7+
import lopper
8+
import os
9+
from west.commands import WestCommand
10+
11+
def get_dir_path(fpath):
12+
"""
13+
This api takes file path and returns it's directory path
14+
15+
Args:
16+
fpath: Path to get the directory path from.
17+
Returns:
18+
string: Full Directory path of the passed path
19+
"""
20+
return os.path.dirname(fpath.rstrip(os.path.sep))
21+
22+
def runcmd(cmd, cwd=None, logfile=None) -> bool:
23+
"""
24+
Run the shell commands.
25+
26+
Args:
27+
| cmd: shell command that needs to be called
28+
| logfile: file to save the command output if required
29+
"""
30+
ret = True
31+
if logfile is None:
32+
try:
33+
subprocess.check_call(cmd, cwd=cwd, shell=True)
34+
except subprocess.CalledProcessError as exc:
35+
ret = False
36+
sys.exit(1)
37+
else:
38+
try:
39+
subprocess.check_call(cmd, cwd=cwd, shell=True, stdout=logfile, stderr=logfile)
40+
except subprocess.CalledProcessError:
41+
ret = False
42+
return ret
43+
44+
class LopperCommand(WestCommand):
45+
def __init__(self):
46+
super().__init__(
47+
'lopper-command', # The name of the command
48+
'Install lopper dependencies and run lopper commands', # Help text for the command
49+
'This command runs lopper commands based on user inputs.'
50+
)
51+
52+
def do_add_parser(self, parser_adder):
53+
parser = parser_adder.add_parser(self.name, help=self.help)
54+
required_argument = parser.add_argument_group("Required arguments")
55+
required_argument.add_argument(
56+
"-p",
57+
"--proc",
58+
action="store",
59+
help="Specify the processor name",
60+
required=True,
61+
)
62+
required_argument.add_argument(
63+
"-s",
64+
"--sdt",
65+
action="store",
66+
help="Specify the System device-tree path (till system-top.dts file)",
67+
required=True,
68+
)
69+
parser.add_argument(
70+
"-w",
71+
"--ws_dir",
72+
action="store",
73+
help="Workspace directory where domain will be created (Default: Current Work Directory)",
74+
default='.',
75+
)
76+
77+
return parser
78+
79+
def do_run(self, args, unknown_args):
80+
sdt = os.path.abspath(args.sdt)
81+
proc = args.proc
82+
workspace = os.path.abspath(args.ws_dir)
83+
lops_dir = os.path.join(get_dir_path(lopper.__file__), "lops")
84+
85+
86+
lops_file = os.path.join(lops_dir, "lop-microblaze-riscv.dts")
87+
runcmd(f"lopper -f --enhanced -O {workspace} -i {lops_file} {sdt} {workspace}/system-domain.dts -- gen_domain_dts microblaze_riscv_0",
88+
cwd = workspace)
89+
runcmd(f"lopper -f --enhanced -O {workspace} -i {lops_file} {workspace}/system-domain.dts {workspace}/system-zephyr.dts -- gen_domain_dts microblaze_riscv_0 zephyr_dt",
90+
cwd = workspace)
91+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2024 Advanced Micro Devices, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import subprocess
6+
import sys
7+
import os
8+
from west.commands import WestCommand
9+
10+
def runcmd(cmd, cwd=None, logfile=None) -> bool:
11+
"""
12+
Run the shell commands.
13+
14+
Args:
15+
| cmd: shell command that needs to be called
16+
| logfile: file to save the command output if required
17+
"""
18+
ret = True
19+
if logfile is None:
20+
try:
21+
subprocess.check_call(cmd, cwd=cwd, shell=True)
22+
except subprocess.CalledProcessError as exc:
23+
ret = False
24+
sys.exit(1)
25+
else:
26+
try:
27+
subprocess.check_call(cmd, cwd=cwd, shell=True, stdout=logfile, stderr=logfile)
28+
except subprocess.CalledProcessError:
29+
ret = False
30+
return ret
31+
32+
class LopperInstall(WestCommand):
33+
def __init__(self):
34+
super().__init__(
35+
'lopper-install', # The name of the command
36+
'Install lopper after west update', # Help text for the command
37+
'This command installs lopper after west update.'
38+
)
39+
40+
def do_add_parser(self, parser_adder):
41+
parser = parser_adder.add_parser(self.name, help=self.help)
42+
return parser
43+
44+
def do_run(self, args, unknown_args):
45+
# Install lopper and its dependencies
46+
self.install_lopper()
47+
48+
def install_lopper(self):
49+
env_path = os.environ.get("VIRTUAL_ENV")
50+
lopper_dir = os.path.join(env_path, "../", "lopper")
51+
runcmd(f"pip install ./[dt,server,yaml,pcpp]",
52+
cwd = lopper_dir)

west.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ manifest:
2323
url-base: https://github.com/zephyrproject-rtos
2424
- name: babblesim
2525
url-base: https://github.com/BabbleSim
26+
- name: devicetree-org
27+
url-base: https://github.com/devicetree-org
2628

2729
group-filter: [-babblesim, -optional]
2830

@@ -342,6 +344,10 @@ manifest:
342344
- name: zcbor
343345
revision: 75d088037eb237b18e7ec1f47c9ce494b9b95aab
344346
path: modules/lib/zcbor
347+
- name: lopper
348+
repo-path: lopper
349+
revision: master
350+
remote: devicetree-org
345351

346352
self:
347353
path: zephyr

0 commit comments

Comments
 (0)