-
Notifications
You must be signed in to change notification settings - Fork 784
Add support for Xilinx Virtex-7 FPGA VC709 board #835
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
Changes from all commits
908acb3
7888b11
98bb00f
e6f4528
aed1f14
9ea9c18
a09bb6f
18c2da2
83e6b65
82b20a8
44e91e5
550628a
498b978
5134387
33e001a
4554b85
c6a02ef
de74a18
36c7d1e
26fce71
8ea6d38
0959757
52f5f3d
d97e5d7
49db3be
a5e2c13
310e81b
d26e1c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,20 @@ ifeq ($(SUB_PROJECT),arty) | |
| FPGA_BRAND ?= xilinx | ||
| endif | ||
|
|
||
| ifeq ($(SUB_PROJECT),vc709) | ||
| SBT_PROJECT ?= fpga_platforms | ||
| MODEL ?= VC709FPGATestHarness | ||
| VLOG_MODEL ?= VC709FPGATestHarness | ||
| MODEL_PACKAGE ?= chipyard.fpga.vc709 | ||
| CONFIG ?= RocketVC709Config | ||
| CONFIG_PACKAGE ?= chipyard.fpga.vc709 | ||
| GENERATOR_PACKAGE ?= chipyard | ||
| TB ?= none # unused | ||
| TOP ?= ChipTop | ||
| BOARD ?= vc709 | ||
| FPGA_BRAND ?= xilinx | ||
| endif | ||
|
|
||
| include $(base_dir)/variables.mk | ||
|
|
||
| # default variables to build the arty example | ||
|
|
@@ -71,6 +85,7 @@ default: $(mcs) | |
| # misc. directories | ||
| ######################################################################################### | ||
| fpga_dir := $(base_dir)/fpga/fpga-shells/$(FPGA_BRAND) | ||
| fpga_board_script_dir := $(fpga_dir)/$(BOARD)/tcl | ||
| fpga_common_script_dir := $(fpga_dir)/common/tcl | ||
|
|
||
| ######################################################################################### | ||
|
|
@@ -120,9 +135,19 @@ debug-bitstream: $(build_dir)/obj/post_synth.dcp | |
| $(build_dir)/debug_obj \ | ||
| $(fpga_common_script_dir) | ||
|
|
||
| MCS_FILE := $(build_dir)/obj/$(MODEL).mcs | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the MCS file used for? I removed this when originally setting up this work to keep things clean.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since every time we power off the board, the uploaded bit-stream will be lost. When working around the kernel after building up the prototype, we would not want to upload the bit-stream too often. Having a mcs file is better choice. It will save our time in the post stage of testing the prototype! |
||
| $(MCS_FILE): $(BIT_FILE) | ||
| cd $(build_dir); vivado \ | ||
| -nojournal -mode batch \ | ||
| -source $(fpga_common_script_dir)/write_cfgmem.tcl \ | ||
| -tclargs $(BOARD) $@ $^ \ | ||
|
|
||
| .PHONY: mcs | ||
| mcs: $(MCS_FILE) | ||
|
|
||
| ######################################################################################### | ||
| # general cleanup rules | ||
| ######################################################################################### | ||
| .PHONY: clean | ||
| clean: | ||
| rm -rf $(gen_dir) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Chipyard we have this So I would revert this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your suggestion that It would be better to have a new target like |
||
| rm -rf $(build_dir) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Guide | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 points here. 1st. We are currently trying to get FireMarshal to target the prototype platforms so a lot involving building Linux won't be necessary (stay tuned for that). 2nd. At a minimum, this should be put in markdown and put in the Chipyard docs in the prototyping section. Once that is done we can talk more about how to make this a bit more understandable for folks. |
||
|
|
||
|
|
||
| ``` | ||
| $ export RISCV_LINUX=~/riscv-linux | ||
| $ export BUILDS=$(RISCV_LINUX)/builds | ||
| $ export OPENSBI=$(RISCV_LINUX)/opensbi | ||
| $ export LINUX=$(RISCV_LINUX)/linux | ||
| $ export CHIPYARD=~/chipyard | ||
| $ export gen_src=$(CHIPYARD)/fpga/generated-src | ||
| $ export RocketVC709Config=chipyard.fpga.vc709.VC709FPGATestHarness.RocketVC709Config | ||
| $ export BoomVC709Config=chipyard.fpga.vc709.VC709FPGATestHarness.BoomVC709Config | ||
| ``` | ||
| Build Linux kernel | ||
| ``` | ||
| $ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- menuconfig | ||
| $ make -j8 ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- | ||
| ``` | ||
| Convert *.dts files into *.dtb format. | ||
| ``` | ||
| $ cd $RISCV_LINUX/$BUILDS | ||
| $ cp -p $gen_src/$RocketVC709Config/$(RocketVC709Config).dts $BUILDS | ||
| $ dtc -I dts -O dtb -o $(RocketVC709Config).dtb $(RocketVC709Config).dts | ||
| $ cp -p $gen_src/$BoomVC709Config/$(BoomVC709Config).dts $BUILDS | ||
| $ dtc -I dts -O dtb -o $(BoomVC709Config).dtb $(BoomVC709Config).dts | ||
| ``` | ||
| Build Open SBI for RocketVC709Config. | ||
| ``` | ||
| make PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM_RISCV_XLEN=64 FW_PAYLOAD=y FW_PAYLOAD_PATH=~/riscv-linux/linux/arch/riscv/boot/Image FW_FDT_PATH=$BUILDS/$(RocketVC709Config).dtb clean | ||
| make PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM_RISCV_XLEN=64 FW_PAYLOAD=y FW_PAYLOAD_PATH=~/riscv-linux/linux/arch/riscv/boot/Image FW_FDT_PATH=$BUILDS/$(RocketVC709Config).dtb install | ||
| ``` | ||
| Build Open SBI for BoomVC709Config. | ||
| ``` | ||
| make PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM_RISCV_XLEN=64 FW_PAYLOAD=y FW_PAYLOAD_PATH=~/riscv-linux/linux/arch/riscv/boot/Image FW_FDT_PATH=$BUILDS/$(BoomVC709Config).dtb clean | ||
| make PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- PLATFORM_RISCV_XLEN=64 FW_PAYLOAD=y FW_PAYLOAD_PATH=~/riscv-linux/linux/arch/riscv/boot/Image FW_FDT_PATH=$BUILDS/$(BoomVC709Config).dtb install | ||
| ``` | ||
| Find the `ttyUSB*` device. The outputs looks like this: `[79643.136986] usb 1-9: cp210x converter now attached to ttyUSB2`. | ||
| ``` | ||
| $ sudo dmesg | grep tty | ||
| ``` | ||
| Download `fw_payload.bin` to the board, then start up the kernel. | ||
| ``` | ||
| $ sudo ./serial /dev/ttyUSB2 0x80000000 ../opensbi/build/platform/generic/firmware/fw_payload.bin | ||
| $ sudo ./serial /dev/ttyUSB2 | ||
| ``` | ||
|
|
||
| ``` | ||
| $ make PLATFORM=generic CROSS_COMPILE=riscv64-unknown-linux-gnu- FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image install | ||
| $ qemu-system-riscv64 -M virt -m 256M -nographic -bios opensbi/build/platform/generic/firmware/fw_jump.bin -kernel ./linux/arch/riscv/boot/Image -drive file=./rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0" | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # RISCV environment variable must be set | ||
| ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
| BUILD_DIR := $(ROOT_DIR)/build | ||
|
|
||
| CC=$(RISCV)/bin/riscv64-unknown-elf-gcc | ||
| OBJCOPY=$(RISCV)/bin/riscv64-unknown-elf-objcopy | ||
| OBJDUMP=$(RISCV)/bin/riscv64-unknown-elf-objdump | ||
| CFLAGS=-march=rv64ima -mcmodel=medany -O2 -std=gnu11 -Wall -nostartfiles | ||
| CFLAGS+= -fno-common -g -DENTROPY=0 -mabi=lp64 -DNONSMP_HART=0 | ||
| CFLAGS+= -I $(ROOT_DIR)/include -I. | ||
| LFLAGS=-static -nostdlib -L $(ROOT_DIR)/linker -T bootrom.elf.lds | ||
|
|
||
| PBUS_CLK ?= 1000000 # default to 1MHz but really should be overridden | ||
|
|
||
| default: elf bin dump | ||
|
|
||
| elf := $(BUILD_DIR)/bootrom.elf | ||
| $(elf): head.S crc16.c kprintf.c serial.c | ||
| mkdir -p $(BUILD_DIR) | ||
| $(CC) $(CFLAGS) -DTL_CLK="$(PBUS_CLK)UL" $(LFLAGS) -o $@ head.S crc16.c kprintf.c serial.c | ||
|
|
||
| .PHONY: elf | ||
| elf: $(elf) | ||
|
|
||
| bin := $(BUILD_DIR)/bootrom.bin | ||
| $(bin): $(elf) | ||
| mkdir -p $(BUILD_DIR) | ||
| $(OBJCOPY) -O binary --change-addresses=-0x10000 $< $@ | ||
|
|
||
| .PHONY: bin | ||
| bin: $(bin) | ||
|
|
||
| dump := $(BUILD_DIR)/bootrom.dump | ||
| $(dump): $(elf) | ||
| $(OBJDUMP) -D -S $< > $@ | ||
|
|
||
| .PHONY: dump | ||
| dump: $(dump) | ||
|
|
||
| .PHONY: clean | ||
| clean:: | ||
| rm -rf $(BUILD_DIR) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # RISCV environment variable must be set | ||
|
|
||
| CC=$(RISCV)/bin/riscv64-unknown-elf-gcc | ||
| OBJCOPY=$(RISCV)/bin/riscv64-unknown-elf-objcopy | ||
| CFLAGS=-march=rv64imac -mcmodel=medany -O2 -std=gnu11 -Wall -nostartfiles | ||
| CFLAGS+= -fno-common -g -DENTROPY=0 -mabi=lp64 -DNONSMP_HART=0 | ||
| CFLAGS+= -I $(BOOTROM_DIR)/include -I. | ||
| LFLAGS=-static -nostdlib -L $(BOOTROM_DIR)/linker -T bootrom.elf.lds | ||
|
|
||
| dts := $(BUILD_DIR)/$(CONFIG_PROJECT).$(CONFIG).dts | ||
| dtb := $(BUILD_DIR)/$(CONFIG_PROJECT).$(CONFIG).dtb | ||
| clk := $(BUILD_DIR)/$(CONFIG_PROJECT).$(CONFIG).tl_clock.h | ||
|
|
||
| ## device tree | ||
| $(clk): $(dts) | ||
| awk '/tlclk {/ && !f{f=1; next}; f && match($$0, /^.*clock-frequency.*<(.*)>.*/, arr) { print "#define TL_CLK " arr[1] "UL"}' $< > [email protected] | ||
| mv [email protected] $@ | ||
|
|
||
| $(dtb): $(dts) | ||
| dtc -I dts -O dtb -o $@ $< | ||
|
|
||
| .PHONY: dtb | ||
| dtb: $(dtb) | ||
|
|
||
| ## uart_boot | ||
| elf := $(BUILD_DIR)/bootrom.elf | ||
| $(elf): $(dtb) head.S crc16.c kprintf.c serial.c $(clk) | ||
| $(CC) $(CFLAGS) -include $(clk) -DDEVICE_TREE='"$(dtb)"' $(LFLAGS) -o $@ head.S crc16.c kprintf.c serial.c | ||
|
|
||
| ## sd_boot | ||
| # elf := $(BUILD_DIR)/bootrom.elf | ||
| # $(elf): $(dtb) head.S kprintf.c sd.c $(clk) | ||
| # $(CC) $(CFLAGS) -include $(clk) -DDEVICE_TREE='"$(dtb)"' $(LFLAGS) -o $@ head.S sd.c kprintf.c | ||
|
|
||
| .PHONY: elf | ||
| elf: $(elf) | ||
|
|
||
| bin := $(BUILD_DIR)/bootrom.bin | ||
| $(bin): $(elf) | ||
| $(OBJCOPY) -O binary $< $@ | ||
|
|
||
| .PHONY: bin | ||
| bin: $(bin) | ||
|
|
||
| hex := $(BUILD_DIR)/bootrom.hex | ||
| $(hex): $(bin) | ||
| od -t x4 -An -w4 -v $< > $@ | ||
|
|
||
| .PHONY: hex | ||
| hex: $(hex) | ||
|
|
||
| # # Berkeley Boot Loader (BBL) | ||
| # elf := $(RISCV)/riscv64-unknown-elf/bin/bbl | ||
| # bin := $(BUILD_DIR)/bootrom.bin | ||
| # $(bin): $(elf) | ||
| # $(OBJCOPY) -O binary $< $@ | ||
|
|
||
| # hex := $(BUILD_DIR)/bootrom.hex | ||
| # $(hex): $(bin) | ||
| # od -t x4 -An -w4 -v $< > $@ | ||
|
|
||
| # Finally | ||
| romgen := $(BUILD_DIR)/rom.v | ||
| $(romgen): $(hex) | ||
| $(rocketchip_dir)/scripts/vlsi_rom_gen $(ROMCONF) $< > $@ | ||
|
|
||
| .PHONY: romgen | ||
| romgen: $(romgen) | ||
|
|
||
| .PHONY: clean | ||
| clean:: | ||
| rm -rf $(hex) $(elf) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #ifndef _SDBOOT_COMMON_H | ||
| #define _SDBOOT_COMMON_H | ||
|
|
||
| #ifndef PAYLOAD_DEST | ||
| #define PAYLOAD_DEST MEMORY_MEM_ADDR | ||
| #endif | ||
|
|
||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * @,@Author: ,: your name | ||
| * @,@Date: ,: 1970-01-01 08:00:00 | ||
| * @,@LastEditTime: ,: 2021-01-30 11:48:26 | ||
| * @,@LastEditors: ,: Please set LastEditors | ||
| * @,@Description: ,: In User Settings Edit | ||
| * @,@FilePath: ,: /freedom/bootrom/sdboot/crc16.h | ||
| */ | ||
| #include "include/crc16.h" | ||
|
|
||
| inline uint16_t crc16_round(uint16_t crc, uint8_t data) { | ||
| crc = (uint8_t)(crc >> 8) | (crc << 8); | ||
| crc ^= data; | ||
| crc ^= (uint8_t)(crc >> 4) & 0xf; | ||
| crc ^= crc << 12; | ||
| crc ^= (crc & 0xff) << 5; | ||
| return crc; | ||
| } | ||
|
|
||
| uint16_t crc16(uint8_t *q) { | ||
| uint16_t crc = 0; | ||
| for (int i = 0; i < CRC16_LEN; i++) { | ||
| crc = crc16_round(crc, *q++); | ||
| } | ||
| return crc; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #include "gpio.h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // See LICENSE.Sifive for license details. | ||
| #include <platform.h> | ||
| #include <smp.h> | ||
| #include "common.h" | ||
|
|
||
| .section .text.init | ||
| .option norvc | ||
| .globl _prog_start | ||
| _prog_start: | ||
| smp_pause(s1, s2) | ||
| li sp, (PAYLOAD_DEST + 0xffff000) | ||
| call main | ||
| smp_resume(s1, s2) | ||
| csrr a0, mhartid // hartid for next level bootloader | ||
| la a1, dtb // dtb address for next level bootloader | ||
| li s1, PAYLOAD_DEST | ||
| jr s1 | ||
|
|
||
| .section .dtb | ||
| .align 3 | ||
| dtb: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include <stdint.h> | ||
| #include "./include/platform.h" | ||
| #include "./include/common.h" | ||
|
|
||
| #define DEBUG | ||
| #include "kprintf.h" | ||
|
|
||
| #define MAX_CORES 8 | ||
|
|
||
| int main(void) | ||
| { | ||
| kputs("this is hello\n"); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // See LICENSE for license details. | ||
| #ifndef _RISCV_BITS_H | ||
| #define _RISCV_BITS_H | ||
|
|
||
| #define likely(x) __builtin_expect((x), 1) | ||
| #define unlikely(x) __builtin_expect((x), 0) | ||
|
|
||
| #define ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b)) | ||
| #define ROUNDDOWN(a, b) ((a)/(b)*(b)) | ||
|
|
||
| #define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
| #define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
| #define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi) | ||
|
|
||
| #define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1))) | ||
| #define INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1)))) | ||
|
|
||
| #define STR(x) XSTR(x) | ||
| #define XSTR(x) #x | ||
|
|
||
| #if __riscv_xlen == 64 | ||
| # define SLL32 sllw | ||
| # define STORE sd | ||
| # define LOAD ld | ||
| # define LWU lwu | ||
| # define LOG_REGBYTES 3 | ||
| #else | ||
| # define SLL32 sll | ||
| # define STORE sw | ||
| # define LOAD lw | ||
| # define LWU lw | ||
| # define LOG_REGBYTES 2 | ||
| #endif | ||
| #define REGBYTES (1 << LOG_REGBYTES) | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // See LICENSE for license details. | ||
| /* Derived from <linux/const.h> */ | ||
|
|
||
| #ifndef _SIFIVE_CONST_H | ||
| #define _SIFIVE_CONST_H | ||
|
|
||
| #ifdef __ASSEMBLER__ | ||
| #define _AC(X,Y) X | ||
| #define _AT(T,X) X | ||
| #else | ||
| #define _AC(X,Y) (X##Y) | ||
| #define _AT(T,X) ((T)(X)) | ||
| #endif /* !__ASSEMBLER__*/ | ||
|
|
||
| #define _BITUL(x) (_AC(1,UL) << (x)) | ||
| #define _BITULL(x) (_AC(1,ULL) << (x)) | ||
|
|
||
| #endif /* _SIFIVE_CONST_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include <stdint.h> | ||
|
|
||
| #define CRC16_BITS 12 | ||
| #define CRC16_LEN 4096 | ||
| #define NUM_BLOCKS 1024 | ||
| #define NAK 0x15 | ||
| #define ACK 0x06 | ||
|
|
||
| uint16_t crc16_round(uint16_t crc, uint8_t data); | ||
| uint16_t crc16(uint8_t *q); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // See LICENSE for license details. | ||
|
|
||
| #ifndef _SIFIVE_CLINT_H | ||
| #define _SIFIVE_CLINT_H | ||
|
|
||
|
|
||
| #define CLINT_MSIP 0x0000 | ||
| #define CLINT_MSIP_size 0x4 | ||
| #define CLINT_MTIMECMP 0x4000 | ||
| #define CLINT_MTIMECMP_size 0x8 | ||
| #define CLINT_MTIME 0xBFF8 | ||
| #define CLINT_MTIME_size 0x8 | ||
|
|
||
| #endif /* _SIFIVE_CLINT_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is originally used in sifive/freedom. I do not remember the original intention. It can be removed since we no longer need it currently.