Skip to content
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

boards/opentitan: Build OpenTitan with target device specific parameters #1741

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions boards/opentitan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
earlgrey = { path = "../../chips/earlgrey" }
lowrisc = { path = "../../chips/lowrisc" }

[features]
# OpenTitan SoC design can be synthesized or compiled for different targets. A
# target can be a specific FPGA board, an ASIC technology, or a simulation tool.
# Please see: https://docs.opentitan.org/doc/ug/getting_started/ for further
# information.
#
# OpenTitan CPU and possibly other components must be configured appropriately
# for a specific target:
# - fpga_nexysvideo:
# OpenTitan SoC design running on Nexys Video Artix-7 FPGA.
#
# - sim_verilator:
# OpenTitan SoC design simulated in Verilator.
fpga_nexysvideo = ["earlgrey/config_fpga_nexysvideo"]
sim_verilator = ["earlgrey/config_sim_verilator"]
9 changes: 9 additions & 0 deletions boards/opentitan/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Makefile for building the tock kernel for the OpenTitan platform

DEFAULT_BOARD_CONFIGURATION=fpga_nexysvideo
TARGET=riscv32imc-unknown-none-elf
PLATFORM=opentitan

include ../Makefile.common

# Pass OpenTitan board configuration option in `BOARD_CONFIGURATION` through
# Cargo `--features`. Please see `Cargo.toml` for available options.
ifneq ($(BOARD_CONFIGURATION),)
CARGO_FLAGS += --features=$(BOARD_CONFIGURATION)
else
CARGO_FLAGS += --features=$(DEFAULT_BOARD_CONFIGURATION)
endif

qemu: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
$(call check_defined, OPENTITAN_BOOT_ROM)
qemu-system-riscv32 -M opentitan -kernel $^ -bios $(OPENTITAN_BOOT_ROM) -nographic -serial mon:stdio
Expand Down
2 changes: 1 addition & 1 deletion boards/opentitan/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub unsafe fn reset_handler() {
// Create a shared UART channel for the console and for kernel debug.
let uart_mux = components::console::UartMuxComponent::new(
&earlgrey::uart::UART0,
230400,
earlgrey::uart::UART0_BAUDRATE,
dynamic_deferred_caller,
)
.finalize(());
Expand Down
5 changes: 5 additions & 0 deletions chips/earlgrey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
edition = "2018"

[features]
config_fpga_nexysvideo = ["config_disable_default"]
config_sim_verilator = ["config_disable_default"]
config_disable_default = []

[dependencies]
lowrisc = { path = "../lowrisc" }
rv32i = { path = "../../arch/rv32i" }
Expand Down
3 changes: 2 additions & 1 deletion chips/earlgrey/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use kernel::Chip;
use rv32i::csr::{mcause, mie::mie, mip::mip, mtvec::mtvec, CSR};
use rv32i::syscall::SysCall;

use crate::chip_config::CONFIG;
use crate::gpio;
use crate::hmac;
use crate::interrupts;
Expand All @@ -20,7 +21,7 @@ use crate::timer;
use crate::uart;
use crate::usbdev;

pub const CHIP_FREQ: u32 = 50_000_000;
pub const CHIP_FREQ: u32 = CONFIG.chip_freq;

pub struct EarlGrey<A: 'static + Alarm<'static>> {
userspace_kernel_boundary: SysCall,
Expand Down
29 changes: 29 additions & 0 deletions chips/earlgrey/src/chip_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Chip specific configuration.

// Chip configuration based on the target device.
pub struct Config<'a> {
pub name: &'a str,
pub chip_freq: u32,
pub uart_baudrate: u32,
}

#[cfg(not(feature = "config_disable_default"))]
pub const CONFIG: Config = Config {
name: &"default",
chip_freq: 50_000_000,
uart_baudrate: 230400,
};

#[cfg(feature = "config_fpga_nexysvideo")]
pub const CONFIG: Config = Config {
name: &"fpga_nexysvideo",
chip_freq: 50_000_000,
uart_baudrate: 230400,
};

#[cfg(feature = "config_sim_verilator")]
pub const CONFIG: Config = Config {
name: &"sim_verilator",
chip_freq: 500_000,
uart_baudrate: 9600,
};
1 change: 1 addition & 0 deletions chips/earlgrey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![crate_name = "earlgrey"]
#![crate_type = "rlib"]

mod chip_config;
mod interrupts;

pub mod aes;
Expand Down
3 changes: 3 additions & 0 deletions chips/earlgrey/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use kernel::common::StaticRef;
use lowrisc::uart::{Uart, UartRegisters};

use crate::chip;
use crate::chip_config::CONFIG;

pub const UART0_BAUDRATE: u32 = CONFIG.uart_baudrate;

pub static mut UART0: Uart = Uart::new(UART0_BASE, chip::CHIP_FREQ);

Expand Down