Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of RISC-V toolchain #377

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/scripts/gdb_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

SIM_LOG=`realpath sim.log`
OPENOCD_LOG=`realpath openocd.log`
GCC_PREFIX=riscv64-unknown-elf

# Ensure that RISC-V toolchain is installed
if ! which ${GCC_PREFIX}-gcc >/dev/null; then
GCC_PREFIX=riscv32-unknown-elf
fi
if ! which ${GCC_PREFIX}-gcc >/dev/null; then
echo "RISC-V toolchain not found, please refer to https://github.com/chipsalliance/caliptra-rtl?tab=readme-ov-file#riscv-toolchain-installation for more details."
exit 1
fi
export GCC_PREFIX

set +e

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
if: steps.riscv_restore.outputs.cache-hit != 'true'
run: |
# Building from source takes around 6.65 GB of disk and download size
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv64imc-3.0.0/riscv64-unknown-elf.gcc-12.1.0.tar.gz
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv32i-131023/riscv32-unknown-elf.gcc-13.2.0.tar.gz
mkdir /opt/riscv
tar -xzf toolchain.tar.gz -C /opt/riscv/

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/interactive-debugging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
- name: Install Risc V Toolchain
run: |
# Building from source takes around 6.65 GB of disk and download size
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv64imc-3.0.0/riscv64-unknown-elf.gcc-12.1.0.tar.gz
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv32i-131023/riscv32-unknown-elf.gcc-13.2.0.tar.gz
mkdir /opt/riscv
tar -xzf toolchain.tar.gz -C /opt/riscv/

Expand Down Expand Up @@ -268,7 +268,7 @@ jobs:
- name: Install Risc V Toolchain
run: |
# Building from source takes around 6.65 GB of disk and download size
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv64imc-3.0.0/riscv64-unknown-elf.gcc-12.1.0.tar.gz
wget -O toolchain.tar.gz https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv32i-131023/riscv32-unknown-elf.gcc-13.2.0.tar.gz
mkdir /opt/riscv
tar -xzf toolchain.tar.gz -C /opt/riscv/

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ GCC:
- RISCV Toolchain for generating memory initialization files
- `Version 2023.04.29`
- `riscv64-unknown-elf-gcc (g) 12.2.0`
- `riscv32-unknown-elf-gcc (g) 13.2.0`
- G++ Used to compile Verilator objects and test firmware
- `g++ (GCC) 11.2.0`

Expand Down Expand Up @@ -144,12 +145,12 @@ Verilog file lists are generated via VCS and included in the config directory fo
## **Simulation Flow** ##

### Caliptra Top VCS Steps: ###
1. Setup tools, add to PATH (ensure riscv64-unknown-elf-gcc is also available)
1. Setup tools, add to PATH (ensure RISC-V toolchain is also available)
2. Define all environment variables above
- For the initial test run after downloading repository, `iccm_lock` is recommended for TESTNAME
- See [Regression Tests](#Regression-Tests) for information about available tests.
3. Create a run folder for build outputs (and cd to it)
4. [OPTIONAL] By default, this run flow will use the riscv64 toolchain to compile test firmware (according to TESTNAME) into program.hex, iccm.hex, dccm.hex, and mailbox.hex. As a first pass, integrators may alternatively use the pre-built hexfiles for convenience (available for [iccm_lock](src/integration/test_suites/iccm_lock) test). To do this, copy [iccm_lock.hex](src/integration/test_suites/iccm_lock/iccm_lock.hex) to the run directory and rename to `program.hex`. [dccm.hex](src/integration/test_suites/iccm_lock/iccm_lock.hex) should also be copied to the run directory, as-is. Use `touch iccm.hex mailbox.hex` to create empty hex files, as these are unnecessary for `iccm_lock` test.
4. [OPTIONAL] By default, this run flow will use the RISC-V toolchain to compile test firmware (according to TESTNAME) into program.hex, iccm.hex, dccm.hex, and mailbox.hex. As a first pass, integrators may alternatively use the pre-built hexfiles for convenience (available for [iccm_lock](src/integration/test_suites/iccm_lock) test). To do this, copy [iccm_lock.hex](src/integration/test_suites/iccm_lock/iccm_lock.hex) to the run directory and rename to `program.hex`. [dccm.hex](src/integration/test_suites/iccm_lock/iccm_lock.hex) should also be copied to the run directory, as-is. Use `touch iccm.hex mailbox.hex` to create empty hex files, as these are unnecessary for `iccm_lock` test.
5. Invoke `${CALIPTRA_ROOT}/tools/scripts/Makefile` with target 'program.hex' to produce SRAM initialization files from the firmware found in `src/integration/test_suites/${TESTNAME}`
- E.g.: `make -f ${CALIPTRA_ROOT}/tools/scripts/Makefile program.hex`
- NOTE: TESTNAME may also be overridden in the makefile command line invocation, e.g. `make -f ${CALIPTRA_ROOT}/tools/scripts/Makefile TESTNAME=iccm_lock program.hex`
Expand All @@ -165,13 +166,13 @@ Verilog file lists are generated via VCS and included in the config directory fo
8. Simulate project with `caliptra_top_tb` as the top target

### Caliptra Top Verilator Steps: ###
1. Setup tools, add to PATH (ensure Verilator, GCC, and riscv64-unknown-elf-gcc are available)
1. Setup tools, add to PATH (ensure Verilator, GCC, and RISC-V toolchain are available)
2. Define all environment variables above
- For the initial test run after downloading repository, `iccm_lock` is recommended for TESTNAME
- See [Regression Tests](#Regression-Tests) for information about available tests.
3. Create a run folder for build outputs
- Recommended to place run folder under `${CALIPTRA_WORKSPACE}/scratch/$USER/verilator/<date>`
4. [OPTIONAL] By default, this run flow will use the riscv64 toolchain to compile test firmware (according to TESTNAME) into program.hex, iccm.hex, dccm.hex, and mailbox.hex. As a first pass, integrators may alternatively use the pre-built hexfiles for convenience (available for `iccm_lock` test). To do this, copy `iccm_lock.hex` to the run directory and rename to `program.hex`. `dccm.hex` should also be copied to the run directory, as-is. Use `touch iccm.hex mailbox.hex` to create empty hex files, as these are unnecessary for `iccm_lock` test.
4. [OPTIONAL] By default, this run flow will use the RISC-V toolchain to compile test firmware (according to TESTNAME) into program.hex, iccm.hex, dccm.hex, and mailbox.hex. As a first pass, integrators may alternatively use the pre-built hexfiles for convenience (available for `iccm_lock` test). To do this, copy `iccm_lock.hex` to the run directory and rename to `program.hex`. `dccm.hex` should also be copied to the run directory, as-is. Use `touch iccm.hex mailbox.hex` to create empty hex files, as these are unnecessary for `iccm_lock` test.
5. Run Caliptra/tools/scripts/Makefile, which provides steps to run a top-level simulation in Verilator
- Example command:
`make -C <path/to/run/folder> -f ${CALIPTRA_ROOT}/tools/scripts/Makefile TESTNAME=${TESTNAME} debug=1 verilator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
GCC_PREFIX = riscv64-unknown-elf
BUILD_DIR = $(CURDIR)

# Define test name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -ex

# Invoke GDB and dump core registers
riscv64-unknown-elf-gdb -n --batch -x dump_registers.gdb >gdb.log
${GCC_PREFIX}-gdb -n --batch -x dump_registers.gdb >gdb.log
# Parse the log, extract register values. Skip those which change as the
# program executes since we don't know at which point we tap in.
cat gdb.log | grep -E '^ra |^sp |^gp |^tp |^t[01256] |^s[0-9]+ |^a[0-9]+ |^\$[0-9]+' >regdump.txt
Expand Down
2 changes: 1 addition & 1 deletion src/integration/test_suites/infinite_loop/mem_access.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -ex

# Invoke GDB
riscv64-unknown-elf-gdb -n --batch -x mem_access.gdb >gdb.log
${GCC_PREFIX}-gdb -n --batch -x mem_access.gdb >gdb.log
# Parse the log
cat gdb.log | grep -E '^\$[0-9]+' >out.txt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -ex

# Invoke GDB
riscv64-unknown-elf-gdb -n --batch -x peripheral_access.gdb >gdb.log
${GCC_PREFIX}-gdb -n --batch -x peripheral_access.gdb >gdb.log
# Parse the log
cat gdb.log | grep -E '^\$[0-9]+' >out.txt

Expand Down
12 changes: 10 additions & 2 deletions tools/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ VERILATOR = verilator
GCC_PREFIX = riscv64-unknown-elf
BUILD_DIR = $(CURDIR)

rv_gcc_version = $(strip $(shell $(GCC_PREFIX)-gcc --version | head -1 | sed "s/$(GCC_PREFIX)-gcc (\w\+) //"))
# Ensure that RISC-V toolchain is installed
ifeq ($(shell which $(GCC_PREFIX)-gcc 2> /dev/null),)
GCC_PREFIX = riscv32-unknown-elf
endif
ifeq ($(shell which $(GCC_PREFIX)-gcc 2> /dev/null),)
$(error RISC-V toolchain not found, please refer to https://github.com/chipsalliance/caliptra-rtl?tab=readme-ov-file#riscv-toolchain-installation for more details)
endif

rv_gcc_version = $(strip $(shell $(GCC_PREFIX)-gcc --version | head -1 | sed "s/$(GCC_PREFIX)-gcc (.*) //"))
$(info rv_gcc_version is $(rv_gcc_version))
ifeq (12.2.0, $(rv_gcc_version))
ifeq "12.2.0" "$(word 1, $(sort 12.2.0 $(rv_gcc_version)))"
ABI = -mabi=ilp32 -march=rv32imc_zicsr_zifencei
else
ABI = -mabi=ilp32 -march=rv32imc
Expand Down
Loading