-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fpga/src/main/resources/zcu102/sdboot (Folder): Add bootrom code whic…
…h supports pmod sd boot.
- Loading branch information
Showing
19 changed files
with
1,118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 sdboot.elf.lds | ||
|
||
PBUS_CLK ?= 1000000 # default to 1MHz but really should be overridden | ||
|
||
default: elf bin dump | ||
|
||
elf := $(BUILD_DIR)/sdboot.elf | ||
$(elf): head.S kprintf.c sd.c | ||
mkdir -p $(BUILD_DIR) | ||
$(CC) $(CFLAGS) -DTL_CLK="$(PBUS_CLK)UL" $(LFLAGS) -o $@ head.S sd.c kprintf.c | ||
|
||
.PHONY: elf | ||
elf: $(elf) | ||
|
||
bin := $(BUILD_DIR)/sdboot.bin | ||
$(bin): $(elf) | ||
mkdir -p $(BUILD_DIR) | ||
$(OBJCOPY) -O binary --change-addresses=-0x10000 $< $@ | ||
|
||
.PHONY: bin | ||
bin: $(bin) | ||
|
||
dump := $(BUILD_DIR)/sdboot.dump | ||
$(dump): $(elf) | ||
$(OBJDUMP) -D -S $< > $@ | ||
|
||
.PHONY: dump | ||
dump: $(dump) | ||
|
||
.PHONY: clean | ||
clean:: | ||
rm -rf $(BUILD_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// See LICENSE.Sifive for license details. | ||
#ifndef _SDBOOT_COMMON_H | ||
#define _SDBOOT_COMMON_H | ||
|
||
#ifndef PAYLOAD_DEST | ||
#define PAYLOAD_DEST MEMORY_MEM_ADDR | ||
#endif | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 // 0x80000000 内存起始地址 | ||
jr s1 | ||
|
||
.section .dtb | ||
.align 3 | ||
dtb: |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// See LICENSE.Sifive 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// See LICENSE.Sifive 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 */ |
14 changes: 14 additions & 0 deletions
14
fpga/src/main/resources/zcu102/sdboot/include/devices/clint.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// See LICENSE.Sifive 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 */ |
24 changes: 24 additions & 0 deletions
24
fpga/src/main/resources/zcu102/sdboot/include/devices/gpio.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// See LICENSE.Sifive for license details. | ||
|
||
#ifndef _SIFIVE_GPIO_H | ||
#define _SIFIVE_GPIO_H | ||
|
||
#define GPIO_INPUT_VAL (0x00) | ||
#define GPIO_INPUT_EN (0x04) | ||
#define GPIO_OUTPUT_EN (0x08) | ||
#define GPIO_OUTPUT_VAL (0x0C) | ||
#define GPIO_PULLUP_EN (0x10) | ||
#define GPIO_DRIVE (0x14) | ||
#define GPIO_RISE_IE (0x18) | ||
#define GPIO_RISE_IP (0x1C) | ||
#define GPIO_FALL_IE (0x20) | ||
#define GPIO_FALL_IP (0x24) | ||
#define GPIO_HIGH_IE (0x28) | ||
#define GPIO_HIGH_IP (0x2C) | ||
#define GPIO_LOW_IE (0x30) | ||
#define GPIO_LOW_IP (0x34) | ||
#define GPIO_IOF_EN (0x38) | ||
#define GPIO_IOF_SEL (0x3C) | ||
#define GPIO_OUTPUT_XOR (0x40) | ||
|
||
#endif /* _SIFIVE_GPIO_H */ |
31 changes: 31 additions & 0 deletions
31
fpga/src/main/resources/zcu102/sdboot/include/devices/plic.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// See LICENSE.Sifive for license details. | ||
|
||
#ifndef PLIC_H | ||
#define PLIC_H | ||
|
||
#include <const.h> | ||
|
||
// 32 bits per source | ||
#define PLIC_PRIORITY_OFFSET _AC(0x0000,UL) | ||
#define PLIC_PRIORITY_SHIFT_PER_SOURCE 2 | ||
// 1 bit per source (1 address) | ||
#define PLIC_PENDING_OFFSET _AC(0x1000,UL) | ||
#define PLIC_PENDING_SHIFT_PER_SOURCE 0 | ||
|
||
//0x80 per target | ||
#define PLIC_ENABLE_OFFSET _AC(0x2000,UL) | ||
#define PLIC_ENABLE_SHIFT_PER_TARGET 7 | ||
|
||
|
||
#define PLIC_THRESHOLD_OFFSET _AC(0x200000,UL) | ||
#define PLIC_CLAIM_OFFSET _AC(0x200004,UL) | ||
#define PLIC_THRESHOLD_SHIFT_PER_TARGET 12 | ||
#define PLIC_CLAIM_SHIFT_PER_TARGET 12 | ||
|
||
#define PLIC_MAX_SOURCE 1023 | ||
#define PLIC_SOURCE_MASK 0x3FF | ||
|
||
#define PLIC_MAX_TARGET 15871 | ||
#define PLIC_TARGET_MASK 0x3FFF | ||
|
||
#endif /* PLIC_H */ |
79 changes: 79 additions & 0 deletions
79
fpga/src/main/resources/zcu102/sdboot/include/devices/spi.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// See LICENSE.Sifive for license details. | ||
|
||
#ifndef _SIFIVE_SPI_H | ||
#define _SIFIVE_SPI_H | ||
|
||
/* Register offsets */ | ||
|
||
#define SPI_REG_SCKDIV 0x00 | ||
#define SPI_REG_SCKMODE 0x04 | ||
#define SPI_REG_CSID 0x10 | ||
#define SPI_REG_CSDEF 0x14 | ||
#define SPI_REG_CSMODE 0x18 | ||
|
||
#define SPI_REG_DCSSCK 0x28 | ||
#define SPI_REG_DSCKCS 0x2a | ||
#define SPI_REG_DINTERCS 0x2c | ||
#define SPI_REG_DINTERXFR 0x2e | ||
|
||
#define SPI_REG_FMT 0x40 | ||
#define SPI_REG_TXFIFO 0x48 | ||
#define SPI_REG_RXFIFO 0x4c | ||
#define SPI_REG_TXCTRL 0x50 | ||
#define SPI_REG_RXCTRL 0x54 | ||
|
||
#define SPI_REG_FCTRL 0x60 | ||
#define SPI_REG_FFMT 0x64 | ||
|
||
#define SPI_REG_IE 0x70 | ||
#define SPI_REG_IP 0x74 | ||
|
||
/* Fields */ | ||
|
||
#define SPI_SCK_POL 0x1 | ||
#define SPI_SCK_PHA 0x2 | ||
|
||
#define SPI_FMT_PROTO(x) ((x) & 0x3) | ||
#define SPI_FMT_ENDIAN(x) (((x) & 0x1) << 2) | ||
#define SPI_FMT_DIR(x) (((x) & 0x1) << 3) | ||
#define SPI_FMT_LEN(x) (((x) & 0xf) << 16) | ||
|
||
/* TXCTRL register */ | ||
#define SPI_TXWM(x) ((x) & 0xffff) | ||
/* RXCTRL register */ | ||
#define SPI_RXWM(x) ((x) & 0xffff) | ||
|
||
#define SPI_IP_TXWM 0x1 | ||
#define SPI_IP_RXWM 0x2 | ||
|
||
#define SPI_FCTRL_EN 0x1 | ||
|
||
#define SPI_INSN_CMD_EN 0x1 | ||
#define SPI_INSN_ADDR_LEN(x) (((x) & 0x7) << 1) | ||
#define SPI_INSN_PAD_CNT(x) (((x) & 0xf) << 4) | ||
#define SPI_INSN_CMD_PROTO(x) (((x) & 0x3) << 8) | ||
#define SPI_INSN_ADDR_PROTO(x) (((x) & 0x3) << 10) | ||
#define SPI_INSN_DATA_PROTO(x) (((x) & 0x3) << 12) | ||
#define SPI_INSN_CMD_CODE(x) (((x) & 0xff) << 16) | ||
#define SPI_INSN_PAD_CODE(x) (((x) & 0xff) << 24) | ||
|
||
#define SPI_TXFIFO_FULL (1 << 31) | ||
#define SPI_RXFIFO_EMPTY (1 << 31) | ||
|
||
/* Values */ | ||
|
||
#define SPI_CSMODE_AUTO 0 | ||
#define SPI_CSMODE_HOLD 2 | ||
#define SPI_CSMODE_OFF 3 | ||
|
||
#define SPI_DIR_RX 0 | ||
#define SPI_DIR_TX 1 | ||
|
||
#define SPI_PROTO_S 0 | ||
#define SPI_PROTO_D 1 | ||
#define SPI_PROTO_Q 2 | ||
|
||
#define SPI_ENDIAN_MSB 0 | ||
#define SPI_ENDIAN_LSB 1 | ||
|
||
#endif /* _SIFIVE_SPI_H */ |
28 changes: 28 additions & 0 deletions
28
fpga/src/main/resources/zcu102/sdboot/include/devices/uart.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// See LICENSE.Sifive for license details. | ||
|
||
#ifndef _SIFIVE_UART_H | ||
#define _SIFIVE_UART_H | ||
|
||
/* Register offsets */ | ||
#define UART_REG_TXFIFO 0x00 | ||
#define UART_REG_RXFIFO 0x04 | ||
#define UART_REG_TXCTRL 0x08 | ||
#define UART_REG_RXCTRL 0x0c | ||
#define UART_REG_IE 0x10 | ||
#define UART_REG_IP 0x14 | ||
#define UART_REG_DIV 0x18 | ||
|
||
/* TXCTRL register */ | ||
#define UART_TXEN 0x1 | ||
#define UART_TXNSTOP 0x2 | ||
#define UART_TXWM(x) (((x) & 0xffff) << 16) | ||
|
||
/* RXCTRL register */ | ||
#define UART_RXEN 0x1 | ||
#define UART_RXWM(x) (((x) & 0xffff) << 16) | ||
|
||
/* IP register */ | ||
#define UART_IP_TXWM 0x1 | ||
#define UART_IP_RXWM 0x2 | ||
|
||
#endif /* _SIFIVE_UART_H */ |
Oops, something went wrong.