Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6496a6e
Added the register definitions into the includes structure and naivel…
AdamWRichardson Feb 21, 2022
a7e20b9
Added a basic toolchain file for the vex riscv
AdamWRichardson Feb 21, 2022
9c01884
Renamed includes to include and added a new user_project_controls hea…
AdamWRichardson Feb 21, 2022
a9d99d6
Updated the gitignore to ignore build files
AdamWRichardson Feb 21, 2022
a37b6a6
Renamed the toolchain file
AdamWRichardson Feb 21, 2022
05f7a1c
Adding stdint.h into the headerfiles that need them
AdamWRichardson Feb 21, 2022
182d597
Copied the basic io_ports test into the new structure and added the n…
AdamWRichardson Feb 21, 2022
9222f33
Removing standard library when compiling
AdamWRichardson Feb 21, 2022
03eb7b6
Added a readme with documentation on how to build and motivations for…
AdamWRichardson Feb 21, 2022
386ef46
Changed the name of the firmware directory
AdamWRichardson Feb 21, 2022
580cfef
Restructured the io_ports makefile to fit with the new firmware direc…
AdamWRichardson Feb 21, 2022
e84403d
Updated the makefile to include all variables needed to build
AdamWRichardson Feb 21, 2022
3ed00df
Added the linker script and linking to it
AdamWRichardson Feb 22, 2022
835698b
Added all the necessary includes so that they can be cleaned up and p…
AdamWRichardson Feb 22, 2022
c85812f
Added the crt and isr libraries and linked them to the io_ports testcase
AdamWRichardson Feb 22, 2022
1110be0
Restructured the make file to build the firmware from the firmware repo
AdamWRichardson Feb 22, 2022
a9f1d96
Changing the library types for the crt and isr libraries
AdamWRichardson Feb 22, 2022
26c6529
Added the other tests and split out the def.h file even further
AdamWRichardson Feb 22, 2022
54096ec
Changing all the makefiles to build the firmware separately and copy …
AdamWRichardson Feb 22, 2022
203d4a1
Removing the obselete C files
AdamWRichardson Feb 22, 2022
b4bdb8d
Added logs and build outputs to the gitignore
AdamWRichardson Feb 22, 2022
d7b2f5d
Removed duplicated ignore files
AdamWRichardson Feb 22, 2022
61b2d53
Added the dockerfile for building the riscv toolchain needed for the …
AdamWRichardson Feb 22, 2022
631cbd4
Removing the stub and placing it in the uart controls
AdamWRichardson Feb 22, 2022
4bc2fe3
Added the printing to uart to the uart controls library
AdamWRichardson Feb 22, 2022
8edf6a7
Updating the la_test1 to use the printing methods in the uart controls
AdamWRichardson Feb 22, 2022
97aa366
Changing the generator to be make since Ninja is not installed in the…
AdamWRichardson Feb 23, 2022
cb87fa8
Updated the top level makefile to run the tests with the new firmware…
AdamWRichardson Feb 23, 2022
3300111
Adding ninja and removing iverilog from the firmware docker image
AdamWRichardson Feb 23, 2022
458cbd2
Fixing issues with the top level makefile for building the firmware
AdamWRichardson Feb 24, 2022
ecbdc84
Merge branch 'main' into move-firmware-to-common-directory
AdamWRichardson Mar 7, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ precheck_results
*.lst
*.vcd
*.gtkw
*.vvp
*.log
build
39 changes: 29 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# SPDX-License-Identifier: Apache-2.0
MAKEFLAGS+=--warn-undefined-variables

CARAVEL_ROOT?=$(PWD)/caravel
CARAVEL_USER_PROJECT_ROOT:=$(shell readlink -f .)
CARAVEL_ROOT?=${CARAVEL_USER_PROJECT_ROOT}/caravel
PRECHECK_ROOT?=${HOME}/mpw_precheck
MCW_ROOT?=$(PWD)/mgmt_core_wrapper
MCW_ROOT?=${CARAVEL_USER_PROJECT_ROOT}/mgmt_core_wrapper
SIM?=RTL

export SKYWATER_COMMIT=c094b6e83a4f9298e47f696ec5a7fd53535ec5eb
Expand Down Expand Up @@ -59,6 +60,27 @@ install:
simenv:
docker pull efabless/dv_setup:latest

PATTERNS=$(shell cd verilog/dv && find * -maxdepth 0 -type d)
DV_PATTERNS = $(foreach dv, $(PATTERNS), verify-$(dv))
TARGET_PATH=$(shell pwd)
VERIFY_COMMAND="cd ${TARGET_PATH}/verilog/dv/$* && \
export SIM=${SIM} && ${MAKE} sim"

FIRMWARE_SOURCE_DIR := ${CARAVEL_USER_PROJECT_ROOT}/caravel_firmware
FIRMWARE_BUILD_DIR := ${CARAVEL_USER_PROJECT_ROOT}/build
FIRMWARE_GENERATOR ?= 'Unix Makefiles'

.PHONY: configure-firmware
configure_firmware:
cmake -DCMAKE_TOOLCHAIN_FILE=${FIRMWARE_SOURCE_DIR}/cmake/vexriscv_toolchain.cmake \
-B${FIRMWARE_BUILD_DIR} \
-G${FIRMWARE_GENERATOR} \
${FIRMWARE_SOURCE_DIR}

.PHONY: firmware
firmware: configure_firmware
cmake --build ${FIRMWARE_BUILD_DIR}

.PHONY: setup
setup: install check-env install_mcw pdk openlane

Expand All @@ -82,12 +104,12 @@ docker_run_verify=\
-e TARGET_PATH=${TARGET_PATH} -e PDK_ROOT=${PDK_ROOT} \
-e CARAVEL_ROOT=${CARAVEL_ROOT} \
-e TOOLS=/opt/riscv32i \
-e DESIGNS=$(TARGET_PATH) \
-e CORE_VERILOG_PATH=$(TARGET_PATH)/mgmt_core_wrapper/verilog \
-e DESIGNS=${TARGET_PATH} \
-e CORE_VERILOG_PATH=${TARGET_PATH}/mgmt_core_wrapper/verilog \
-e GCC_PREFIX=riscv32-unknown-elf \
-e MCW_ROOT=$(MCW_ROOT) \
-u $$(id -u $$USER):$$(id -g $$USER) efabless/dv_setup:latest \
sh -c $(verify_command)
-e MCW_ROOT=${MCW_ROOT} \
efabless/dv_setup:latest \
sh -c ${VERIFY_COMMAND}

.PHONY: harden
harden: $(blocks)
Expand Down Expand Up @@ -204,6 +226,3 @@ check-pdk:
help:
cd $(CARAVEL_ROOT) && $(MAKE) help
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'



7 changes: 7 additions & 0 deletions caravel_firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(CaravelFirmware VERSION 0.1.0 LANGUAGES C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)

add_subdirectory(src)
27 changes: 27 additions & 0 deletions caravel_firmware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Caravel firmware
The files in this directory are a common place for firmware code to be written. Whilst a subdirectory now this directory should be made a separate repo and then "submoduled" in any caravel repo that requires it. This allows common aspects of the firmware to be developed independently of the design, but the design specifies exactly which version of firmware is relevant to the current state of the design.

## Motivation
The reason to move firmware builds into a single place is twofold:
* All configuration necessary to compile the firmware is in one place. For users developing firmware it then becomes transparent what compiler flags, linker scripts etc... are required to compile their own firmware.
* Firmware development continues independently of the design. Abstract classes and structs that are independent of the design can be developed separately to the design and the design specifies when it's ready to take those updates.

## Building
To build the firmware you need to install cmake (and optionally Ninja) and ensure that the GCC toolchain executables are added to the PATH. Cmake is a fantastic tool which is able to generate build scripts for multiple toolchains (GNU Make, Ninja, MSVC, Xcode) so that firmware can be built on any platform. For more information please consult [the cmake documentation](https://cmake.org/).

### Configuration
The build with cmake takes place in two parts; configuration, which generates the build files and building which does the compilation. To configure the cmake build run
```bash
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/vexriscv_toolchain.cmake -Bbuild -GNinja
```
from this directory. This can be explained as:
* `-DCMAKE_TOOLCHAIN_FILE=cmake/vexriscv_toolchain.cmake` tells cmake to load the toochain as specified by `vexriscv_toolchain.cmake`. This file just tells cmake where to find the compiler and some global additional compiler flags.
* `-Bbuild` tells cmake to put the build files in a directory called `build`
* `-GNinja` tells cmake which generator to use. This is optional and defaults to whatever host you are building on, for Linux systems this is GNU Make. Ninja is a fast and efficient alternative and I suggest using it.

### Building
Now that cmake has configured the build, the source code can be compiled. To do this simply run
```bash
cmake --build build/
```
which tells cmake to build all things in the `build/` directory. All the build artifacts are placed in the `build/` directory with the same layout as this directory.
18 changes: 18 additions & 0 deletions caravel_firmware/cmake/vexriscv_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# To use this file you must invoke cmake with -DCMAKE_TOOLCHAIN_FILE like so:
# (From build directory)
# `cmake -DCMAKE_TOOLCHAIN_FILE=cmake/riscv_toolchain.cmake .`

find_path(RISCV_TOOLCHAIN_PATH "riscv32-unknown-elf-gcc" ENV PATH)
message("RISC-V compiler found in: ${RISCV_TOOLCHAIN_PATH}")

set(CMAKE_SYSTEM_NAME Generic)

set(CMAKE_C_COMPILER ${RISCV_TOOLCHAIN_PATH}/riscv32-unknown-elf-gcc)
set(CMAKE_CXX_COMPILER ${RISCV_TOOLCHAIN_PATH}/riscv32-unknown-elf-g++)

set(RISCV_GENERAL_COMPILER_FLAGS "-g -nostdlib")
set(RISCV_C_FLAGS ${RISCV_GENERAL_COMPILER_FLAGS})
set(RISCV_CXX_FLAGS ${RISCV_GENERAL_COMPILER_FLAGS})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${RISCV_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RISCV_CXX_FLAGS}")
30 changes: 30 additions & 0 deletions caravel_firmware/environment/apt_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Requirements to install with apt

# Shell tools
bash-completion
git
vim

# Firmware build dependencies
ninja-build

# RISC-V toolchain dependencies
autoconf
automake
autotools-dev
bc
bison
build-essential
curl
flex
gawk
gperf
libexpat-dev
libgmp-dev
libmpc-dev
libmpfr-dev
libtool
patchutils
python3
texinfo
zlib1g-dev
38 changes: 38 additions & 0 deletions caravel_firmware/environment/riscv_toolchain.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2020 Efabless Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier: Apache-2.0

ARG BASE_IMAGE=ubuntu:20.04
FROM ${BASE_IMAGE}

ENV TOOLCHAIN_DOWNLOAD_DIR=/tmp/riscv-gnu-toolchain
ENV TOOLCHAIN_INSTALL_DIR=/opt/riscv32i

ARG DEBIAN_FRONTEND=noninteractive

COPY ./environment/apt_requirements.txt /tmp

RUN apt-get update && \
apt-get install -y $(grep -v "^#" /tmp/apt_requirements.txt | tr "\n" " ")

RUN git clone https://github.com/riscv/riscv-gnu-toolchain ${TOOLCHAIN_DOWNLOAD_DIR} && \
cd ${TOOLCHAIN_DOWNLOAD_DIR} && \
./configure --prefix=${TOOLCHAIN_INSTALL_DIR} --with-arch=rv32i && \
make -j $(nproc) && \
cd / && \
rm -rf ${TOOLCHAIN_DOWNLOAD_DIR}

ENV PATH=${TOOLCHAIN_INSTALL_DIR}/bin:${PATH}

CMD /bin/bash
Loading