From ae5f878d6acadabaa671a7a30b87e16eb1d718a7 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Wed, 30 Nov 2016 10:55:18 -0800 Subject: Bump Everything to Match new Freedom Repo (#8) * Bump tool versions * Use version of OpenOCD which can load programs into flash * Bump OpenOCD to Handle ISSI Flash Programming * Update Header files * add initial support for hifive1 * add dhrystone * add clock helper functions * add openocd cfg file * Demo_GPIO checkpoint -- compiles and runs but no blinky LEDs * Remove riscv-tests submodule * Remove FPGA files, as they are no longer relevant to this Repository * Add openocd_upload script * Add Pinmux Mappings Adding the pinmux mappings to the Platform Header * Add IOF Mappings to platform header * Re-order the IOF Mapping declarations * Add more useful things to platform headers * Get GPIO Demo working again (except interrupts aren't working) * Update README with more OS packages needed A bare ubuntu-16.04.1-server installation could not run `make tools` without these packages. * bump openocd to get SCKDIV fix * Remove duplicated help text for run_debug target * Add package to README that is needed for openocd build Without this package I was seeing two different failures like below when running `make tools`. /home/scottj/freedom-e-sdk/openocd/configure: line 4533: syntax error near unexpected token `0.23' /home/scottj/freedom-e-sdk/openocd/configure: line 4533: `PKG_PROG_PKG_CONFIG(0.23)' Makefile:70: recipe for target '/home/scottj/freedom-e-sdk/toolchain/bin/openocd' failed make: *** [/home/scottj/freedom-e-sdk/toolchain/bin/openocd] Error 2 ... or ... + autoconf configure.ac:12: error: possibly undefined macro: AC_MSG_WARN If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. configure.ac:240: error: possibly undefined macro: AC_MSG_NOTICE configure.ac:342: error: possibly undefined macro: AC_DEFINE Makefile:70: recipe for target '/home/scottj/freedom-e-sdk/toolchain/bin/openocd' failed make: *** [/home/scottj/freedom-e-sdk/toolchain/bin/openocd] Error 1 * Bump OpenOCD to not overwrite SCKDIV when flashing * Roll back CoreMark --- software/shared/Makefile.shared | 48 -------- software/shared/drivers_sifive/plic.c | 123 -------------------- software/shared/drivers_sifive/plic.h | 70 ------------ software/shared/entry.S | 1 - software/shared/gpio.h | 10 -- software/shared/init.c | 48 -------- software/shared/shared.h | 73 ------------ software/shared/spi.h | 8 -- software/shared/syscall.c | 206 ---------------------------------- software/shared/uart.h | 12 -- 10 files changed, 599 deletions(-) delete mode 100644 software/shared/Makefile.shared delete mode 100644 software/shared/drivers_sifive/plic.c delete mode 100644 software/shared/drivers_sifive/plic.h delete mode 120000 software/shared/entry.S delete mode 100644 software/shared/gpio.h delete mode 100644 software/shared/init.c delete mode 100644 software/shared/shared.h delete mode 100644 software/shared/spi.h delete mode 100644 software/shared/syscall.c delete mode 100644 software/shared/uart.h (limited to 'software/shared') diff --git a/software/shared/Makefile.shared b/software/shared/Makefile.shared deleted file mode 100644 index 70550a0..0000000 --- a/software/shared/Makefile.shared +++ /dev/null @@ -1,48 +0,0 @@ -# See LICENSE for license details. - -SHARED_DIR = $(SWDIR)/shared - -ASM_SRCS += $(SHARED_DIR)/entry.S - -C_SRCS += $(SHARED_DIR)/init.c -C_SRCS += $(SHARED_DIR)/syscall.c -C_SRCS += $(SHARED_DIR)/drivers_sifive/plic.c - -PLATFORM ?= freedom-e300 -LINKER_SCRIPT := $(SWDIR)/../riscv-tests/debug/targets/$(PLATFORM)/link.lds -HEADERS += $(SHARED_DIR)/*.h - -C_SRCS += $(TARGET).c - -INCLUDES += -I . -INCLUDES += -I $(SHARED_DIR) -INCLUDES += -I $(SWDIR)/../riscv-tests/env -INCLUDES += -I$(SHARED_DIR)/drivers_sifive/ - -CC = $(SWDIR)/../toolchain/bin/riscv32-unknown-elf-gcc - -CFLAGS += $(CDEFINES) - -LDFLAGS := -T $(LINKER_SCRIPT) -nostdlib -nostartfiles -lc -lgcc -LDFLAGS += -L$(SHARED_DIR) -LDFLAGS += -L$(SHARED_DIR)/drivers -LDFLAGS += -L$(SHARED_DIR)/hal - -ASM_OBJS := $(patsubst %.S,%.o,$(ASM_SRCS)) -C_OBJS := $(patsubst %.c,%.o,$(C_SRCS)) - -$(TARGET): $(ASM_OBJS) $(C_OBJS) $(LINKER_SCRIPT) - $(CC) $(CFLAGS) $(INCLUDES) $(C_OBJS) $(ASM_OBJS) -o $@ $(LDFLAGS) - -$(ASM_OBJS): %.o: %.S $(HEADERS) - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< - -$(C_OBJS): %.o: %.c $(HEADERS) - $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< - -all: default - -clean: - rm -f $(TARGET) *.o $(SHARED_DIR)/*.o $(SHARED_DIR)/drivers/*/*.o $(SHARED_DIR)/drivers_sifive/*.o - -.PHONY: clean all default diff --git a/software/shared/drivers_sifive/plic.c b/software/shared/drivers_sifive/plic.c deleted file mode 100644 index ec0c178..0000000 --- a/software/shared/drivers_sifive/plic.c +++ /dev/null @@ -1,123 +0,0 @@ -// See LICENSE for license details. - -#include "plic.h" -#include "encoding.h" -#include - - -// Note that there are no assertions or bounds checking on these -// parameter values. - -void volatile_memzero(uint8_t * base, unsigned int size){ - - volatile uint8_t * ptr; - for (ptr = base; ptr < (base + size); ptr++){ - *ptr = 0; - } -} - -void PLIC_init ( - plic_instance_t * this_plic, - uintptr_t base_addr, - uint32_t num_sources, - uint32_t num_priorities - ){ - - this_plic->base_addr = base_addr; - this_plic->num_sources = num_sources; - this_plic->num_priorities = num_priorities; - - // Disable all interrupts (don't assume that these registers are reset). - unsigned long hart_id = read_csr(mhartid); - volatile_memzero((uint8_t*) (this_plic->base_addr + - PLIC_ENABLE_OFFSET + - (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET)), - (num_sources + 8) / 8); - - // Set all priorities to 0 (equal priority -- don't assume that these are reset). - volatile_memzero ((uint8_t *)(this_plic->base_addr + - PLIC_PRIORITY_OFFSET), - (num_sources + 1) << PLIC_PRIORITY_SHIFT_PER_SOURCE); - - // Set the threshold to 0. - volatile plic_threshold* threshold = (plic_threshold*) - (this_plic->base_addr + - PLIC_THRESHOLD_OFFSET + - (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET)); - - *threshold = 0; - -} - -void PLIC_set_threshold (plic_instance_t * this_plic, plic_threshold threshold){ - - unsigned long hart_id = read_csr(mhartid); - volatile plic_threshold* threshold_ptr = (plic_threshold*) (this_plic->base_addr + - PLIC_THRESHOLD_OFFSET + - (hart_id << PLIC_THRESHOLD_SHIFT_PER_TARGET)); - - *threshold_ptr = threshold; - -} - - -void PLIC_enable_interrupt (plic_instance_t * this_plic, plic_source source){ - - unsigned long hart_id = read_csr(mhartid); - volatile uint8_t * current_ptr = (volatile uint8_t *)(this_plic->base_addr + - PLIC_ENABLE_OFFSET + - (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) + - (source >> 3)); - uint8_t current = *current_ptr; - current = current | ( 1 << (source & 0x7)); - *current_ptr = current; - -} - -void PLIC_disable_interrupt (plic_instance_t * this_plic, plic_source source){ - - unsigned long hart_id = read_csr(mhartid); - volatile uint8_t * current_ptr = (volatile uint8_t *) (this_plic->base_addr + - PLIC_ENABLE_OFFSET + - (hart_id << PLIC_ENABLE_SHIFT_PER_TARGET) + - (source >> 3)); - uint8_t current = *current_ptr; - current = current & ~(( 1 << (source & 0x7))); - *current_ptr = current; - -} - -void PLIC_set_priority (plic_instance_t * this_plic, plic_source source, plic_priority priority){ - - if (this_plic->num_priorities > 0) { - volatile plic_priority * priority_ptr = (volatile plic_priority *) - (this_plic->base_addr + - PLIC_PRIORITY_OFFSET + - (source << PLIC_PRIORITY_SHIFT_PER_SOURCE)); - *priority_ptr = priority; - } -} - -plic_source PLIC_claim_interrupt(plic_instance_t * this_plic){ - - unsigned long hart_id = read_csr(mhartid); - - volatile plic_source * claim_addr = (volatile plic_source * ) - (this_plic->base_addr + - PLIC_CLAIM_OFFSET + - (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET)); - - return *claim_addr; - -} - -void PLIC_complete_interrupt(plic_instance_t * this_plic, plic_source source){ - - unsigned long hart_id = read_csr(mhartid); - volatile plic_source * claim_addr = (volatile plic_source *) (this_plic->base_addr + - PLIC_CLAIM_OFFSET + - (hart_id << PLIC_CLAIM_SHIFT_PER_TARGET)); - *claim_addr = source; - -} - diff --git a/software/shared/drivers_sifive/plic.h b/software/shared/drivers_sifive/plic.h deleted file mode 100644 index 14118a5..0000000 --- a/software/shared/drivers_sifive/plic.h +++ /dev/null @@ -1,70 +0,0 @@ -// See LICENSE for license details. - -#ifndef PLIC_H -#define PLIC_H - -#include -#include -#include -#include - - -#include "encoding.h" - -// 32 bits per source -#define PLIC_PRIORITY_OFFSET 0x0000UL -#define PLIC_PRIORITY_SHIFT_PER_SOURCE 2 -// 1 bit per source (1 address) -#define PLIC_PENDING_OFFSET 0x1000UL -#define PLIC_PENDING_SHIFT_PER_SOURCE 0 - -//0x80 per target -#define PLIC_ENABLE_OFFSET 0x2000UL -#define PLIC_ENABLE_SHIFT_PER_TARGET 7 - - -#define PLIC_THRESHOLD_OFFSET 0x200000UL -#define PLIC_CLAIM_OFFSET 0x200004UL -#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 - - -typedef struct __plic_instance_t -{ - uintptr_t base_addr; - - uint32_t num_sources; - uint32_t num_priorities; - -} plic_instance_t; - -typedef uint32_t plic_source; -typedef uint32_t plic_priority; -typedef uint32_t plic_threshold; - -void PLIC_init ( - plic_instance_t * this_plic, - uintptr_t base_addr, - uint32_t num_sources, - uint32_t num_priorities - ); - -void PLIC_enable_interrupt (plic_instance_t * this_plic, plic_source source); - -void PLIC_disable_interrupt (plic_instance_t * this_plic, plic_source source); - -void PLIC_set_priority (plic_instance_t * this_plic, plic_source source, plic_priority priority); - -plic_source PLIC_claim_interrupt(plic_instance_t * this_plic); - -void PLIC_complete_interrupt(plic_instance_t * this_plic, plic_source source); - -void PLIC_set_threshold(plic_instance_t * this_plic, plic_threshold threshold); - -#endif diff --git a/software/shared/entry.S b/software/shared/entry.S deleted file mode 120000 index 11f412b..0000000 --- a/software/shared/entry.S +++ /dev/null @@ -1 +0,0 @@ -../../riscv-tests/debug/programs/entry.S \ No newline at end of file diff --git a/software/shared/gpio.h b/software/shared/gpio.h deleted file mode 100644 index ed48255..0000000 --- a/software/shared/gpio.h +++ /dev/null @@ -1,10 +0,0 @@ -// See LICENSE for license details. - -#ifndef SIFIVE_GPIO_H -#define SIFIVE_GPIO_H - -#define GPIO_IN_OFFSET 0 -#define GPIO_OUT_OFFSET 0 -#define GPIO_TRI_OFFSET 4 - -#endif diff --git a/software/shared/init.c b/software/shared/init.c deleted file mode 100644 index ab790b2..0000000 --- a/software/shared/init.c +++ /dev/null @@ -1,48 +0,0 @@ -// See LICENSE for license details. - -#include -#include -#include -#include - -#include "encoding.h" -#include "shared.h" - -int main(void); - -#ifdef USE_PLIC -extern void handle_m_ext_interrupt(); -#endif - - -#ifdef USE_M_TIME -extern void handle_m_time_interrupt(); -#endif - - -void _init(void) -{ - - exit(main()); -} - -uintptr_t handle_trap(uintptr_t mcause, uintptr_t epc) -{ - if (0){ -#ifdef USE_PLIC - // External Machine-Level Interrupt from PLIC - }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT)) { - handle_m_ext_interrupt(); -#endif -#ifdef USE_M_TIME - // External Machine-Level Interrupt from PLIC - }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER)) { - handle_m_time_interrupt(); -#endif - } - else{ - write(1, "trap\n", 5); - _exit(1 + mcause); - } - return epc; -} diff --git a/software/shared/shared.h b/software/shared/shared.h deleted file mode 100644 index e8f3bf4..0000000 --- a/software/shared/shared.h +++ /dev/null @@ -1,73 +0,0 @@ -// See LICENSE for license details. - -#ifndef SIFIVE_SHARED_H -#define SIFIVE_SHARED_H - -#include "uart.h" -#include "gpio.h" -#include "plic.h" - -// Some things missing from the official encoding.h -#define MCAUSE_INT 0x80000000 -#define MCAUSE_CAUSE 0x7FFFFFFF - -/**************************************************************************** - * Platform definitions - *****************************************************************************/ - -#define MTIMECMP_BASE_ADDR 0x44004000UL -#define MTIME_ADDR 0x4400BFF8UL -#define PLIC_BASE_ADDR 0x40000000UL -#define UART_BASE_ADDR 0x48000000UL -#define GPIO_BASE_ADDR 0x48002000UL -#define SPI_BASE_ADDR 0x48001000UL - - -/**************************************************************************** - * Clock Parameters - *****************************************************************************/ - -#define RTC_PRESCALER 100 -#define CLOCK_FREQUENCY 62500000 - -/**************************************************************************** - * GPIO Connections - *****************************************************************************/ - - -// Each of these OFFSETS holds 4 bits. - -#define RED_LEDS_OFFSET 0 -#define GREEN_LEDS_OFFSET 4 -#define BLUE_LEDS_OFFSET 8 -#define JA_OUT_OFFSET 12 // JA Pins 1-4 are outputs. - -#define BUTTONS_OFFSET 16 -#define SWITCHES_OFFSET 20 -#define JA_IN_OFFSET 24 // JA Pins 7-10 are inputs. -// reserved input offset 38 // Tied to zero. - -/**************************************************************************** - * External Interrupts handled by PLIC. - *****************************************************************************/ - -// Interrupt devices -#define INT_DEVICE_BUTTON_0 1 -#define INT_DEVICE_BUTTON_1 2 -#define INT_DEVICE_BUTTON_2 3 -#define INT_DEVICE_BUTTON_3 4 - -#define INT_DEVICE_JA_7 5 -#define INT_DEVICE_JA_8 6 -#define INT_DEVICE_JA_9 7 -#define INT_DEVICE_JA_10 8 - - -// Setting these correctly makes the initialization scripts -// run faster. -#define PLIC_NUM_SOURCES 31 -#define PLIC_NUM_PRIORITIES 0 - -void write_hex(int fd, uint32_t hex); - -#endif diff --git a/software/shared/spi.h b/software/shared/spi.h deleted file mode 100644 index 9c974c1..0000000 --- a/software/shared/spi.h +++ /dev/null @@ -1,8 +0,0 @@ -// See LICENSE for license details. - -#ifndef SIFIVE_SPI_H -#define SIFIVE_SPI_H - -//TODO - -#endif diff --git a/software/shared/syscall.c b/software/shared/syscall.c deleted file mode 100644 index 1acb88f..0000000 --- a/software/shared/syscall.c +++ /dev/null @@ -1,206 +0,0 @@ -// See LICENSE for license details. - -/* This is an incomplete version of a syscall library, - * which really only supports simple reads and writes over UART. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "encoding.h" - -#include "shared.h" - -volatile uint64_t tohost __attribute__((aligned(64))); -volatile uint64_t fromhost __attribute__((aligned(64))); - -void write_hex(int fd, uint32_t hex){ - uint8_t ii; - uint8_t jj; - char towrite; - write( fd , "0x", 2 ); - for (ii = 8 ; ii > 0; ii--){ - jj = ii-1; - uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4)); - towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA)); - write( fd, &towrite, 1); - } - -} - - -void _exit(int code) -{ - volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET); - const char * message = "\nProgam has exited with code:"; - - *leds = (~(code)); - - write(STDERR_FILENO, message, strlen(message)); - write_hex(STDERR_FILENO, code); - - while (1){}; - -} - -void *sbrk(ptrdiff_t incr) -{ - // extern char _end[]; - // extern char _heap_end[]; - // static char *curbrk = _end; - - // if ((curbrk + incr < _end) || (curbrk + incr > _heap_end)) - return NULL - 1; - - // curbrk += incr; - //return curbrk - incr; -} - -static int stub(int err) -{ - errno = err; - return -1; -} - -int open(const char* name, int flags, int mode) -{ - return stub(ENOENT); -} - -int openat(int dirfd, const char* name, int flags, int mode) -{ - return stub(ENOENT); -} - -int close(int fd) -{ - return stub(EBADF); -} - -int execve(const char* name, char* const argv[], char* const env[]) -{ - return stub(ENOMEM); -} - -int fork() -{ - return stub(EAGAIN); -} - -int fstat(int fd, struct stat *st) -{ - if (isatty(fd)) { - st->st_mode = S_IFCHR; - return 0; - } - - return stub(EBADF); -} - -int getpid() -{ - return 1; -} - -int isatty(int fd) -{ - if (fd == STDOUT_FILENO || fd == STDERR_FILENO) - return 1; - - errno = EBADF; - return 0; -} - -int kill(int pid, int sig) -{ - return stub(EINVAL); -} - -int link(const char *old_name, const char *new_name) -{ - return stub(EMLINK); -} - -off_t lseek(int fd, off_t ptr, int dir) -{ - if (isatty(fd)) - return 0; - - return stub(EBADF); -} - -ssize_t read(int fd, void* ptr, size_t len) -{ - int i; - uint8_t * current = (uint8_t*) ptr; - volatile uint8_t * uart_rx = (uint8_t*) (UART_BASE_ADDR + UART_RX_OFFSET); - volatile uint32_t * uart_rx_cnt = (uint32_t*) (UART_BASE_ADDR + UART_RX_COUNT_OFFSET); - - ssize_t result = 0; - - if (isatty(fd)) { - - for (current = (uint8_t*) ptr; - (current < ((uint8_t*) ptr) + len) && (*uart_rx_cnt > 0); - current ++){ - *current = *uart_rx; - result ++; - } - return result; - - } - - return stub(EBADF); -} - -int stat(const char* file, struct stat* st) -{ - return stub(EACCES); -} - -clock_t times(struct tms* buf) -{ - return stub(EACCES); -} - -int unlink(const char* name) -{ - return stub(ENOENT); -} - -int wait(int* status) -{ - return stub(ECHILD); -} - -ssize_t write(int fd, const void* ptr, size_t len) -{ - - const uint8_t * current = (const char*) ptr; - volatile uint32_t * uart_tx_count = (uint32_t*) (UART_BASE_ADDR + UART_TX_COUNT_OFFSET); - volatile uint8_t * uart_tx = (uint8_t*) (UART_BASE_ADDR + UART_TX_OFFSET); - - size_t jj; - if (isatty(fd)) { - - for (jj = 0; jj < len; jj++){ - - while ((*uart_tx_count) < 1){}; - *uart_tx = current[jj]; - - if (current[jj] == '\n'){ - while ((*uart_tx_count) < 1){}; - *uart_tx = '\r'; - } - } - return len; - } - return stub(EBADF); -} diff --git a/software/shared/uart.h b/software/shared/uart.h deleted file mode 100644 index e97ef8b..0000000 --- a/software/shared/uart.h +++ /dev/null @@ -1,12 +0,0 @@ -// See LICENSE for license details. - -#ifndef SIFIVE_UART_H -#define SIFIVE_UART_H - -#define UART_RX_OFFSET 0 -#define UART_TX_OFFSET 0 -#define UART_TX_COUNT_OFFSET 0x4 -#define UART_RX_COUNT_OFFSET 0x8 -#define UART_DIVIDER_OFFSET 0xC - -#endif -- cgit v1.2.3