blob: 98cbe9ed0f00f45f481727a407b50d0db8667989 [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001#!/bin/bash
2
3# Copyright lowRISC contributors.
4# Licensed under the Apache License, Version 2.0, see LICENSE for details.
5# SPDX-License-Identifier: Apache-2.0
6
7# This script converts all SystemVerilog RTL files to Verilog and then
8# runs Yosys.
9#
10# The following tools are required:
11# - sv2v: SystemVerilog-to-Verilog converter from github.com/zachjs/sv2v
12# - yosys: synthesis tool from github.com/YosysHQ/yosys
Nils Graf03a87c02020-06-26 18:01:17 -070013# - Cadence Conformal
lowRISC Contributors802543a2019-08-31 12:12:56 +010014#
15# Usage:
Nils Graf03a87c02020-06-26 18:01:17 -070016# ./syn_yosys.sh 2>&1 | tee syn.std
lowRISC Contributors802543a2019-08-31 12:12:56 +010017
18#-------------------------------------------------------------------------
Nils Graf03cf29f2019-09-18 16:06:17 -070019# use fusesoc to generate files and file list
lowRISC Contributors802543a2019-08-31 12:12:56 +010020#-------------------------------------------------------------------------
Nils Graf03a87c02020-06-26 18:01:17 -070021\rm -Rf build syn_out
22fusesoc --cores-root .. run --target=syn \
23 --setup lowrisc:systems:top_earlgrey > /dev/null 2>&1
lowRISC Contributors802543a2019-08-31 12:12:56 +010024
25# copy all files into directory "syn_out"
lowRISC Contributors802543a2019-08-31 12:12:56 +010026mkdir syn_out
Zachary Snow42ae6fc2020-06-10 21:15:29 -040027cp \
Nils Graf03a87c02020-06-26 18:01:17 -070028 build/*/src/*/*.sv* \
29 build/*/src/*/*/*.sv* \
30 build/*/src/*/*/*/*.sv* \
Zachary Snow42ae6fc2020-06-10 21:15:29 -040031 syn_out
32cd syn_out
33
Nils Graf03a87c02020-06-26 18:01:17 -070034# copy file list, remove incdir and pins_if, and flatten pathnames
35grep -Ev 'incdir|pins_if' ../build/*/*/*.scr | sed 's!.*/!!' > flist_gold
Zachary Snow42ae6fc2020-06-10 21:15:29 -040036
Nils Graf03a87c02020-06-26 18:01:17 -070037# generate revised flist by replacing '.sv' by '.v' and removing packages
38sed 's/.sv/.v/g' flist_gold | grep -v "_pkg.v" > flist_rev
lowRISC Contributors802543a2019-08-31 12:12:56 +010039
40#-------------------------------------------------------------------------
41# convert all RTL files to Verilog
42#-------------------------------------------------------------------------
Nils Graf03a87c02020-06-26 18:01:17 -070043
44# hack SystemVerilog files to avoid SV2V and/or LEC issues
45# TODO: eventually remove these hacks
46
47# 1) Setting ByteAccess = 0 for tlul_adapter_sram.sv doesn't work. This
48# hack changes the functionality so needs fixing
49sed -i 's/ByteAccess *(0)/ByteAccess(1)/g' *.sv
50
51# 2) Replace "inside" for dm_csrs.sv and dm_mem.sv. This hack changes
52# the functionality so needs fixing
53sed -i 's/) inside/)/g' dm_csrs.sv
54sed -i 's/\[(dm::Data0):DataEnd\]:/dm::Data0:/g' dm_csrs.sv
55sed -i 's/\[(dm::ProgBuf0):ProgBufEnd\]:/dm::ProgBuf0:/g' dm_csrs.sv
56sed -i 's/inside//g' dm_mem.sv
57sed -i 's/\[(dm::DataAddr):DataEndAddr\]:/dm::DataAddr:/' dm_mem.sv
58sed -i 's/\[DataBaseAddr:DataEndAddr\]:/DataBaseAddr:/' dm_mem.sv
59sed -i 's/\[ProgBufBaseAddr:ProgBufEndAddr\]:/ProgBufBaseAddr:/' dm_mem.sv
60sed -i 's/\[AbstractCmdBaseAddr:AbstractCmdEndAddr\]:/AbstractCmdBaseAddr:/' dm_mem.sv
61sed -i 's/\[FlagsBaseAddr:FlagsEndAddr\]:/FlagsBaseAddr:/' dm_mem.sv
62
63printf "\nSV2V VERSION:\n"
64sv2v --version
65
66printf "\nSV2V ERRORS:\n"
67
68# prim_util_memload.sv is only meant to be included within a module
69mv prim_util_memload.sv{,h}
70sed -i "s/prim_util_memload\.sv/prim_util_memload.svh/" *.sv
71
Zachary Snow42ae6fc2020-06-10 21:15:29 -040072sv2v -DSYNTHESIS *.sv > combined.v
73# split files up
74modules=`cat combined.v | grep "^module" | sed -e "s/^module //" | sed -e "s/ (//"`
75echo "$modules" > modules.txt # for debugging
76for module in $modules; do
77 sed -n "/^module $module /,/^endmodule/p" < combined.v > $module.v
lowRISC Contributors802543a2019-08-31 12:12:56 +010078done
Zachary Snow42ae6fc2020-06-10 21:15:29 -040079rm combined.v
lowRISC Contributors802543a2019-08-31 12:12:56 +010080
Nils Graf03a87c02020-06-26 18:01:17 -070081# rename ibex_register_file_ff, match filename to module name
82mv ibex_register_file{,_ff}.v
83
84# remove *pkg.v files (they are empty files and not needed for Verilog)
85rm -Rf *_pkg.v
86
lowRISC Contributors802543a2019-08-31 12:12:56 +010087#-------------------------------------------------------------------------
Philipp Wagner14a3fee2019-11-21 10:07:02 +000088# run LEC (generarted Verilog vs. original SystemVerilog)
Nils Graf03cf29f2019-09-18 16:06:17 -070089#-------------------------------------------------------------------------
90printf "\n\nLEC RESULTS:\n"
Nils Graf03a87c02020-06-26 18:01:17 -070091
92# top_earlgrey and all its submodules
93declare -a modules=(
94 "rv_dm"
95 "spi_device"
96 "usbdev"
97 "flash_ctrl"
98 "tlul_adapter_sram"
99 "prim_rom_adv"
100 "prim_ram_1p_adv"
101 "uart"
102 "gpio"
103 "aes"
104 "hmac"
105 "pinmux"
106 "padctrl"
107 "alert_handler"
108 "pwrmgr"
109 "rstmgr"
110 "clkmgr"
111 "nmi_gen"
112 "rv_timer"
113 "rv_plic"
114 "rv_core_ibex"
115 "xbar_main"
116 "xbar_peri"
117 "flash_phy"
118 "top_earlgrey"
119)
120
121for module in "${modules[@]}"; do
122 export LEC_TOP="$module"
123
124 # run Conformal LEC
125 lec -xl -nogui -nobanner \
126 -dofile ../../hw/formal/lec_sv2v.do \
127 -logfile lec_${module}.log \
128 <<< "exit -force" > /dev/null 2>&1
Nils Graf03cf29f2019-09-18 16:06:17 -0700129
130 # summarize results
Zachary Snow42ae6fc2020-06-10 21:15:29 -0400131 result=`grep "Compare Results" lec_${module}.log 2>&1`
Nils Graf03cf29f2019-09-18 16:06:17 -0700132 if [ $? -ne 0 ]; then
133 result="CRASH"
134 else
135 result=`echo $result | awk '{ print $4 }'`
136 fi
Nils Graf03a87c02020-06-26 18:01:17 -0700137 printf "%-25s %s\n" $module $result
Nils Graf03cf29f2019-09-18 16:06:17 -0700138done
Nils Graf03cf29f2019-09-18 16:06:17 -0700139
140#-------------------------------------------------------------------------
lowRISC Contributors802543a2019-08-31 12:12:56 +0100141# run yosys
142#-------------------------------------------------------------------------
Nils Graf03cf29f2019-09-18 16:06:17 -0700143printf "\n\nYosys:\n"
Zachary Snow42ae6fc2020-06-10 21:15:29 -0400144yosys -QTqp "
Nils Graf03a87c02020-06-26 18:01:17 -0700145 read_verilog *.v;
146 hierarchy -check -top top_earlgrey;
147 synth_xilinx;
148 write_blif out.blif;
149 write_edif out.edif;
150 write_json out.json;
Zachary Snow42ae6fc2020-06-10 21:15:29 -0400151"
lowRISC Contributors802543a2019-08-31 12:12:56 +0100152
lowRISC Contributors802543a2019-08-31 12:12:56 +0100153# TODOs:
lowRISC Contributors802543a2019-08-31 12:12:56 +0100154# - add full yosys synthesis for all modules
155# - add final LEC check (RTL-versus-netlist)