-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-vyond
executable file
·166 lines (140 loc) · 7.42 KB
/
run-vyond
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
# See LICENSE for license details.
# Vyond Commandline Interface
# With this python program, you can build and run every combination of Rocket-Aware HW (e.g., Rocket SoC or QEMU)
# and SW (e.g., Bare-metal or Security Monitor).
# Although each component has its own small script to build and run, this CLI will show you every commands in one place.
# Author: Sungkeun Kim ([email protected])
import sys
import os
import os.path
import argparse
from typing import List
progName = 'vyond'
#####################################
# Directory info
#####################################
root = f'{os.getcwd()}'
chipyard_root = f'{root}/chipyard-1.11.0'
tee_root = f'{root}/tee'
sm_root = f'{tee_root}/monitor'
fw_root = f'{tee_root}/sbi'
def validate_absolute_path(path):
if not os.path.isabs(path):
raise argparse.ArgumentTypeError(f"'{path}' is not an absolute path.")
if not os.path.exists(path):
raise argparse.ArgumentTypeError(f"'{path}' does not exist.")
return path
def buildWGRocketSim(args):
cmd = f'cd {chipyard_root}/sims/verilator; make CONFIG=WGRocketConfig'
if args.debug:
cmd = cmd + ' debug'
os.system(cmd)
def runWGRocketSim(args):
runcmd = 'run-binary'
if args.debug:
runcmd = runcmd + '-debug'
cmd = f'cd {chipyard_root}/sims/verilator; make CONFIG=WGRocketConfig {runcmd} BINARY={args.program_path}'
os.system(cmd)
def buildWGRocketFPGA(args):
cmd = f'cd {chipyard_root}/fpga; make SUB_PROJECT=wgvcu118 bitstream'
os.system(cmd)
def buildSM(args):
if args.clean_build:
os.system(f'cd {sm_root}; cargo clean')
cmd = f'cd {sm_root}; cargo build'
if args.semihosting:
cmd = cmd + ' --features semihosting'
os.system(cmd)
def buildFW(args):
libvyond = f'{sm_root}/target/riscv64gc-unknown-linux-gnu/debug/libvyond.a'
if not os.path.exists(libvyond):
print("sm does not exist. Build sm first.")
exit(1)
if args.clean_build:
cmd = f'cd {fw_root}; rm -rf opensbi/build; ./build.sh {args.payload_path}'
else:
cmd = f'cd {fw_root}; ./build.sh {args.payload_path}'
print(f'Running cmd: {cmd}')
os.system(cmd)
def flashFWToSD(args):
cmd = f'sudo sgdisk --clear -g --set-alignment=34 --new=1:34:1048576 --new=2:1048594:0 --typecode=1:af0a --typecode=2:af00 {args.blk_dev_file} '
cmd = cmd + f' sudo dd if={args.fw_path} of=/dev/sdh1 status=progress oflag=sync bs=1M'
os.system(cmd)
def runFWOnWGQemu(args):
cmd = f'cd {tee_root}; ./run.sh'
if args.debug:
cmd = cmd + ' -debug'
cmd = cmd + f' -fw {args.fw_path} -qemu {args.qemu}'
print(cmd)
os.system(cmd)
def main(argv: List[str] = None):
if os.getenv('VYOND_ENV_SETUP') != 'YES':
print("Environment Variabls are not set. run 'source %s' first." % 'env.sh')
exit(1)
parser = argparse.ArgumentParser(
prog=progName,
description="Vyond Commandline Interface",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.set_defaults(func=lambda x: parser.print_help())
subparsers = parser.add_subparsers(title='commands')
#################################################################
# Sub command - Build WG-Aware Rocket RTL Simulation
#################################################################
parser_buildWGRocketSim = subparsers.add_parser('build-wgrocket-sim', help='Build WG-Aware Rocket RTL Simulation')
parser_buildWGRocketSim.add_argument('--debug', action='store_true', default=False, help="build with debugging symbol")
parser_buildWGRocketSim.set_defaults(func=buildWGRocketSim)
#################################################################
# Sub command - Run WG-Aware Rocket RTL Simulation
#################################################################
parser_runWGRocketSim = subparsers.add_parser('run-wgrocket-sim', help='Run WG-Aware Rocket RTL Simulation')
parser_runWGRocketSim.add_argument('--debug', action='store_true', default=False, help="run with debugging symbol")
parser_runWGRocketSim.add_argument("program_path", type=validate_absolute_path, help="Absolute Program path to run")
parser_runWGRocketSim.set_defaults(func=runWGRocketSim)
#################################################################
# Sub command - Build FPGA bitstream for WG-Aware Rocket
#################################################################
parser_buildWGRocketFPGA = subparsers.add_parser('build-wgrocket-fpga', help='Build a VCU118 FPGA bitstream for WG-Aware Rocket SoC.')
parser_buildWGRocketFPGA.set_defaults(func=buildWGRocketFPGA)
#################################################################
# build sm
#################################################################
parser_buildSM = subparsers.add_parser('build-sm', help='Build Security Monitor')
parser_buildSM.add_argument("--semihosting", action='store_true', default=False, help="Enable semihosting. It doesn't work with Rocket SoC")
parser_buildSM.add_argument("--clean-build", action='store_true', default=False, help="Clean build")
parser_buildSM.set_defaults(func=buildSM)
#################################################################
# build fw
#################################################################
parser_buildFW = subparsers.add_parser('build-fw', help='Build firmware payload')
parser_buildFW.add_argument("--clean-build", action='store_true', default=False, help="Clean build")
parser_buildFW.add_argument("payload_path", type=validate_absolute_path, help="firmware path")
parser_buildFW.set_defaults(func=buildFW)
#################################################################
# Sub command - Write a firmware to SDCard
#################################################################
parser_flashFWToSD = subparsers.add_parser('flash-fw', help='Write the firmware to sdcard')
parser_flashFWToSD.add_argument("blk_dev_file", type=validate_absolute_path, help="Block Device File for the SDCard")
parser_flashFWToSD.add_argument("--fw_path", type=str, default='./tee/sbi/opensbi/build/platform/generic/firmware/fw_payload.bin', help="Absolute Firmware path")
parser_flashFWToSD.set_defaults(func=flashFWToSD)
#################################################################
# Sub command - Run FW on WG-Aware Qemu
#################################################################
parser_runFWOnWGQemu = subparsers.add_parser('run-fw-on-qemu', help='Run FW on WG-Aware qemu')
parser_runFWOnWGQemu.add_argument('--debug', action='store_true', default=False, help="run with gdb")
parser_runFWOnWGQemu.add_argument("--qemu", type=str, default='../prebuilt/qemu-system-riscv64', help="Absolute path to wg-aware qemu")
parser_runFWOnWGQemu.add_argument("--fw_path", type=str, default='./sbi/opensbi/build/platform/generic/firmware/fw_payload.bin', help="Absolute Firmware path")
parser_runFWOnWGQemu.set_defaults(func=runFWOnWGQemu)
args = parser.parse_args()
#################################################################
# Create CLI class and call selected sub command.
#################################################################
try:
args = parser.parse_args(sys.argv[1:])
args.func(args)
except KeyboardInterrupt:
print(f"{argv}{os.linesep}")
sys.exit(0)
if __name__ == "__main__":
sys.exit(main())