Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
908acb3
add serial-boot for vc709 board, add configs for vc709 prototyping.
mbs0221 Feb 1, 2021
7888b11
update support for vc709
mbs0221 Feb 1, 2021
98bb00f
add support for vc709
mbs0221 Feb 1, 2021
e6f4528
update support for vc709
mbs0221 Feb 2, 2021
aed1f14
add support for vc709 board
mbs0221 Feb 3, 2021
9ea9c18
add support for dual memory channels
mbs0221 Feb 5, 2021
a09bb6f
support DDR3 dual memory channels for vc709
mbs0221 Mar 4, 2021
18c2da2
update support for dual memory channels
mbs0221 Mar 5, 2021
83e6b65
support PCIeX8 for vc709
mbs0221 Mar 8, 2021
82b20a8
update PCIeX8 support for vc709
mbs0221 Mar 9, 2021
44e91e5
update support for dual memory channels and PCIe X8
mbs0221 Mar 10, 2021
550628a
update Makefile
mbs0221 Mar 11, 2021
498b978
update Makefile of uartsend
mbs0221 Mar 11, 2021
5134387
update support for vc709 board
mbs0221 Mar 13, 2021
33e001a
update support for vc709
mbs0221 Mar 13, 2021
4554b85
add README.md
mbs0221 Mar 13, 2021
c6a02ef
update Configs.scala
mbs0221 Mar 16, 2021
de74a18
update I2C and PCIe support for vc709 board.
mbs0221 Mar 17, 2021
36c7d1e
remove unnecessary files
mbs0221 Mar 17, 2021
26fce71
update support for I2C, UART and PCIe.
mbs0221 Mar 17, 2021
8ea6d38
update support for one DDR3 controller
mbs0221 Mar 17, 2021
0959757
updata support for GPIO in vc709
mbs0221 Mar 20, 2021
52f5f3d
update support for vc709 board
mbs0221 Mar 25, 2021
d97e5d7
Update and rename gpoi.c to gpio.c
mbs0221 Mar 29, 2021
49db3be
Update Configs.scala
mbs0221 Mar 29, 2021
a5e2c13
update UART support for vc709
mbs0221 Mar 31, 2021
310e81b
Merge branch 'vc709-dev' of https://github.com/mbs0221/chipyard into …
mbs0221 Mar 31, 2021
d26e1c3
Update platform.h
mbs0221 Mar 31, 2021
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
27 changes: 26 additions & 1 deletion fpga/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Author

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.

fpga_common_script_dir := $(fpga_dir)/common/tcl

#########################################################################################
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

@abejgonzalez abejgonzalez Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Chipyard we have this clean target "clean" everything (hence the gen_dir being deleted). I wouldn't be opposed to adding a new target like clean-specific (or a better name) that just deletes the sources related to this config.

So I would revert this.

Copy link
Author

Choose a reason for hiding this comment

The 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 clean-specific for a certain config!

rm -rf $(build_dir)
50 changes: 50 additions & 0 deletions fpga/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Guide
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
```
42 changes: 42 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/Makefile
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)
72 changes: 72 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/Makefile.mk
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)
9 changes: 9 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/common.h
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
26 changes: 26 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/crc16.c
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;
}
1 change: 1 addition & 0 deletions fpga/src/main/resources/vc709/uartboot/gpio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "gpio.h"
21 changes: 21 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/head.S
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:
14 changes: 14 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/hello.c
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;
}
36 changes: 36 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/include/bits.h
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
18 changes: 18 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/include/const.h
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 */
10 changes: 10 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/include/crc16.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);
14 changes: 14 additions & 0 deletions fpga/src/main/resources/vc709/uartboot/include/devices/clint.h
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 */
Loading