lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | #!/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 Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 13 | # - Cadence Conformal |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 14 | # |
| 15 | # Usage: |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 16 | # ./syn_yosys.sh 2>&1 | tee syn.std |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 17 | |
| 18 | #------------------------------------------------------------------------- |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 19 | # use fusesoc to generate files and file list |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 20 | #------------------------------------------------------------------------- |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 21 | \rm -Rf build syn_out |
| 22 | fusesoc --cores-root .. run --target=syn \ |
| 23 | --setup lowrisc:systems:top_earlgrey > /dev/null 2>&1 |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 24 | |
| 25 | # copy all files into directory "syn_out" |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 26 | mkdir syn_out |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 27 | cp \ |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 28 | build/*/src/*/*.sv* \ |
| 29 | build/*/src/*/*/*.sv* \ |
| 30 | build/*/src/*/*/*/*.sv* \ |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 31 | syn_out |
| 32 | cd syn_out |
| 33 | |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 34 | # copy file list, remove incdir and pins_if, and flatten pathnames |
| 35 | grep -Ev 'incdir|pins_if' ../build/*/*/*.scr | sed 's!.*/!!' > flist_gold |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 36 | |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 37 | # generate revised flist by replacing '.sv' by '.v' and removing packages |
| 38 | sed 's/.sv/.v/g' flist_gold | grep -v "_pkg.v" > flist_rev |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 39 | |
| 40 | #------------------------------------------------------------------------- |
| 41 | # convert all RTL files to Verilog |
| 42 | #------------------------------------------------------------------------- |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 43 | |
| 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 |
| 49 | sed -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 |
| 53 | sed -i 's/) inside/)/g' dm_csrs.sv |
| 54 | sed -i 's/\[(dm::Data0):DataEnd\]:/dm::Data0:/g' dm_csrs.sv |
| 55 | sed -i 's/\[(dm::ProgBuf0):ProgBufEnd\]:/dm::ProgBuf0:/g' dm_csrs.sv |
| 56 | sed -i 's/inside//g' dm_mem.sv |
| 57 | sed -i 's/\[(dm::DataAddr):DataEndAddr\]:/dm::DataAddr:/' dm_mem.sv |
| 58 | sed -i 's/\[DataBaseAddr:DataEndAddr\]:/DataBaseAddr:/' dm_mem.sv |
| 59 | sed -i 's/\[ProgBufBaseAddr:ProgBufEndAddr\]:/ProgBufBaseAddr:/' dm_mem.sv |
| 60 | sed -i 's/\[AbstractCmdBaseAddr:AbstractCmdEndAddr\]:/AbstractCmdBaseAddr:/' dm_mem.sv |
| 61 | sed -i 's/\[FlagsBaseAddr:FlagsEndAddr\]:/FlagsBaseAddr:/' dm_mem.sv |
| 62 | |
| 63 | printf "\nSV2V VERSION:\n" |
| 64 | sv2v --version |
| 65 | |
| 66 | printf "\nSV2V ERRORS:\n" |
| 67 | |
| 68 | # prim_util_memload.sv is only meant to be included within a module |
| 69 | mv prim_util_memload.sv{,h} |
| 70 | sed -i "s/prim_util_memload\.sv/prim_util_memload.svh/" *.sv |
| 71 | |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 72 | sv2v -DSYNTHESIS *.sv > combined.v |
| 73 | # split files up |
| 74 | modules=`cat combined.v | grep "^module" | sed -e "s/^module //" | sed -e "s/ (//"` |
| 75 | echo "$modules" > modules.txt # for debugging |
| 76 | for module in $modules; do |
| 77 | sed -n "/^module $module /,/^endmodule/p" < combined.v > $module.v |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 78 | done |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 79 | rm combined.v |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 80 | |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 81 | # rename ibex_register_file_ff, match filename to module name |
| 82 | mv ibex_register_file{,_ff}.v |
| 83 | |
| 84 | # remove *pkg.v files (they are empty files and not needed for Verilog) |
| 85 | rm -Rf *_pkg.v |
| 86 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 87 | #------------------------------------------------------------------------- |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 88 | # run LEC (generarted Verilog vs. original SystemVerilog) |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 89 | #------------------------------------------------------------------------- |
| 90 | printf "\n\nLEC RESULTS:\n" |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 91 | |
| 92 | # top_earlgrey and all its submodules |
| 93 | declare -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 | |
| 121 | for 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 Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 129 | |
| 130 | # summarize results |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 131 | result=`grep "Compare Results" lec_${module}.log 2>&1` |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 132 | if [ $? -ne 0 ]; then |
| 133 | result="CRASH" |
| 134 | else |
| 135 | result=`echo $result | awk '{ print $4 }'` |
| 136 | fi |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 137 | printf "%-25s %s\n" $module $result |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 138 | done |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 139 | |
| 140 | #------------------------------------------------------------------------- |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 141 | # run yosys |
| 142 | #------------------------------------------------------------------------- |
Nils Graf | 03cf29f | 2019-09-18 16:06:17 -0700 | [diff] [blame] | 143 | printf "\n\nYosys:\n" |
Zachary Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 144 | yosys -QTqp " |
Nils Graf | 03a87c0 | 2020-06-26 18:01:17 -0700 | [diff] [blame] | 145 | 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 Snow | 42ae6fc | 2020-06-10 21:15:29 -0400 | [diff] [blame] | 151 | " |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 152 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 153 | # TODOs: |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 154 | # - add full yosys synthesis for all modules |
| 155 | # - add final LEC check (RTL-versus-netlist) |