Skip to content

Commit

Permalink
<Qemu SiFive-E> Add platform support for Qemu SiFive-E
Browse files Browse the repository at this point in the history
- Add qemu sifive_e platform and bootloader support
  Note: Bootloader to be used with following command
  `qemu-system-riscv32 ... -device loader,file=<path to build.elf> ...`
- Updates on platform files to reduce size for bootloader
- Add USE_TIMER to enable/disable from platform config.
- [driver] PLIC will only build if N_PLAT_IRQS are non 0

Issue: #233
  • Loading branch information
akashkollipara committed Feb 19, 2023
1 parent 6df3ffd commit bdc735a
Show file tree
Hide file tree
Showing 21 changed files with 746 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Connect with us over VisorFolks discord server: < [**JOIN**](https://discord.gg/

### Supported Platforms

| Atmel | SiFive | STMicro | TI | Raspberry Pi |
| ---------- | ----------- | ----------- | ----------- | -------------|
| ATMega328P | FE310-G002 | Coming soon | Coming soon | Coming soon |
| ATMega2560 | | | | |
| Atmel | SiFive | STMicro | TI | Raspberry Pi |
| ---------- | ------------- | ----------- | ----------- | -------------|
| ATMega328P | FE310-G002 | Coming soon | Coming soon | Coming soon |
| ATMega2560 | QEMU SiFive-E | | | |

### Programming Languages
* asm/assembly
Expand Down
2 changes: 2 additions & 0 deletions src/driver/interrupt/plic/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
PLIC_PATH := $(GET_PATH)

ifeq ($(ARCH), riscv)
ifneq ($(N_PLAT_IRQS),0)

DIR := $(PLIC_PATH)
include mk/obj.mk

endif
endif
6 changes: 4 additions & 2 deletions src/platform/sifive/common_fe310/platform/plat_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static tvisor_timer_t *plat_timer_port;
* plat_timer_setup - Timer driver setup function
* To be exported to driver table.
*/
static status_t plat_timer_setup(void)
status_t plat_timer_setup(void)
{
status_t ret = success;
const irqs_t *irq;
Expand Down Expand Up @@ -177,7 +177,7 @@ static status_t plat_timer_setup(void)
* plat_timer_exit - Timer driver shutdown function
* To be exported to driver table.
*/
static status_t plat_timer_exit(void)
status_t plat_timer_exit(void)
{
const irqs_t *irq;
arch_di_mtime();
Expand All @@ -189,4 +189,6 @@ static status_t plat_timer_exit(void)
return timer_release_device();
}

#if USE_TIMER
INCLUDE_DRIVER(plat_timer, plat_timer_setup, plat_timer_exit, 0, 1, 1);
#endif
7 changes: 7 additions & 0 deletions src/platform/sifive/common_fe310/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ void platform_setup()
{
status_t ret = success;

#if PRCI_CLK
driver_setup("sysclk_prci");
ret |= sysclk_reset();
#endif

driver_setup("earlycon");
bootmsgs_enable();
#ifdef BOOTLOADER
cyancore_insignia_lite();
#else
cyancore_insignia();
#endif

#if PRINT_MEMORY_LAYOUT
platform_memory_layout();
#endif
Expand Down
10 changes: 10 additions & 0 deletions src/platform/sifive/fe310g002-bl/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ $(eval $(call add_define,ERRATA_CIP578))
#======================================================================
SYSCLK_ENABLE := 1
PRCI_CLK := 1
$(eval $(call add_define,SYSCLK_ENABLE))
$(eval $(call add_define,PRCI_CLK))
#======================================================================

#======================================================================
# Bootload Configuration
#======================================================================
$(eval $(call add_define,BOOTLOADER))

#======================================================================
# Bootloader
# \ Timer: Sched timer/wall clock
#======================================================================
USE_TIMER ?= 0
$(eval $(call add_define,USE_TIMER))
#======================================================================
#======================================================================
9 changes: 9 additions & 0 deletions src/platform/sifive/fe310g002/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ $(eval $(call add_define,ERRATA_CIP578))
#======================================================================
SYSCLK_ENABLE := 1
PRCI_CLK := 1
$(eval $(call add_define,SYSCLK_ENABLE))
$(eval $(call add_define,PRCI_CLK))
#======================================================================

#======================================================================
# Timer: Sched timer/wall clock
#======================================================================
USE_TIMER ?= 1
$(eval $(call add_define,USE_TIMER))
#======================================================================
28 changes: 28 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
#
# File Name : build.mk
# Description : This file accumulates the build scripts from
# all other directories that have HiFive 1 Rev B
# board support sources
# Primary Author : Akash Kollipara [akashkollipara@gmail.com]
# Organisation : Cyancore Core-Team
#

FE310G002_DIR := $(GET_PATH)

ARCH := riscv
BIT := 32
ARCH_VARIANT := imac
ARCH_ABI := ilp32
TARGET_FLAGS += -march=rv32imac -mabi=$(ARCH_ABI)
PLAT_INCLUDE += $(FE310G002_DIR)/include
OUTPUT_FORMAT := elf32-littleriscv

include $(FE310G002_DIR)/config.mk
include $(FE310G002_DIR)/../common_fe310/build.mk
$(eval $(call check_and_include,USE_DEFAULT_RESOURCES,$(FE310G002_DIR)/resources/build.mk))

DIR := $(FE310G002_DIR)
include mk/obj.mk
101 changes: 101 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
#
# File Name : config.mk
# Description : This file defines configuration for HiFive 1B
# Primary Author : Akash Kollipara [akashkollipara@gmail.com]
# Organisation : Cyancore Core-Team
#

#======================================================================
# Configuration file for Platforms
#======================================================================

#======================================================================
# Platform Configuration
# Do not alter below FLAGS unless explicitly mentioned
#======================================================================
N_CORES := 1
$(eval $(call add_define,N_CORES))

CCSMP := 0
$(eval $(call add_define,CCSMP))

$(eval $(call add_define,BIT))

BOOT_CORE_ID:= 0
$(eval $(call add_define,BOOT_CORE_ID))

FLASH_START := 0x000001000
FLASH_SIZE := 0x2000 # 8K
RAM_START := 0x80000000
RAM_SIZE := 0x4000 # 16K
ITIM_START := 0x08000000
ITIM_SIZE := 0x2000 # 8K
HEAP_SIZE ?= 512
STACK_SIZE ?= 0xc00
STACK_SIZE_PCPU ?= 0xc00

$(eval $(call add_define,HEAP_SIZE))
$(eval $(call add_define,STACK_SIZE))
$(eval $(call add_define,STACK_SIZE_PCPU))

# Call this FLAG from Project config file if needed
XCLK ?= 16000000
ICLK ?= 72000000
$(eval $(call add_define,XCLK))
$(eval $(call add_define,ICLK))

N_EXCEP := 12
$(eval $(call add_define,N_EXCEP))

N_IRQ := 12
$(eval $(call add_define,N_IRQ))

N_PLAT_IRQS := 0
$(eval $(call add_define,N_PLAT_IRQS))

MAX_INTERRUPTS_PER_DEVICE := 1
$(eval $(call add_define,MAX_INTERRUPTS_PER_DEVICE))

USE_SPINLOCK ?= 1
$(eval $(call add_define,USE_SPINLOCK))

#======================================================================
# MEMBUF Configuration
#======================================================================
MEMBUF_SIZE ?= 1024
$(eval $(call add_define,MEMBUF_SIZE))
#======================================================================

#======================================================================
# GPIO Configuration
#======================================================================
N_PORT := 1
$(eval $(call add_define,N_PORT))
#======================================================================

#======================================================================
# Errata CIP-578
#======================================================================
ERRATA_CIP578 := 1
$(eval $(call add_define,ERRATA_CIP578))
#======================================================================

#======================================================================
# PRCI Sysclk Configuration
#======================================================================
SYSCLK_ENABLE := 1
PRCI_CLK := 0
$(eval $(call add_define,SYSCLK_ENABLE))
$(eval $(call add_define,PRCI_CLK))
#======================================================================

#======================================================================
# Bootload Configuration
#======================================================================
USE_TIMER ?= 0
$(eval $(call add_define,USE_TIMER))
$(eval $(call add_define,BOOTLOADER))
#======================================================================
20 changes: 20 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/include/plat_defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2022, Cyancore Team
*
* File Name : plat_mem.h
* Description : This file contains defines corresponding to
* fe310-g002 board
* Primary Author : Akash Kollipara [akashkollipara@gmail.com]
* Organisation : Cyancore Core-Team
*/

#pragma once

#define __RISCV_FE310G002__

enum pinmux_functions
{
serial = 0,
pwm = 1
};
28 changes: 28 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/include/plat_mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2022, Cyancore Team
*
* File Name : plat_mem.h
* Description : This file contains memory config of fe310-g002
* Primary Author : Akash Kollipara [akashkollipara@gmail.com]
* Organisation : Cyancore Core-Team
*/

#pragma once

#define FLASH_SIZE 8K
#define RAM_SIZE 16K

#define V_ITMEM_START 0x08000000
#define V_IMEM_START 0x00001000
#define V_DMEM_START 0x80000000

#define L_MEM_START 0x00001000
#define L_MEM_LENGTH 0x00002000

#define ITMEM_LENGTH 0x00002000
#define IMEM_LENGTH 0x00002000
#define DMEM_LENGTH 0x00004000

#define ALIGN_BOUND 4
#define HEAP_ALIGN ALIGN_BOUND
17 changes: 17 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/platform.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2022, Cyancore Team
*
* File Name : platform.c
* Description : This file contains sources for platform apis
* Primary Author : Akash Kollipara [akashkollipara@gmail.com]
* Organisation : Cyancore Core-Team
*/

#include <platform.h>

void platform_jump_to_user_code(void)
{
void (*jmp)(void) = (void *) 0x20000000;
jmp();
}
13 changes: 13 additions & 0 deletions src/platform/sifive/qemu-sifive-e-bl/resources/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
#
# File Name : build.mk
# Description : This file builds resources sources
# Primary Author : Akash Kollipara [akashkollipara@gmail.com]
# Organisation : Cyancore Core-Team
#

DIR := $(GET_PATH)

include mk/obj.mk
Loading

0 comments on commit bdc735a

Please sign in to comment.