Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Bender.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ packages:
- common_cells
- register_interface
clint:
revision: d5390a805c20f9226758a152ba1645f61da73349
version: 0.2.0
revision: 2318184fc191e94b7069436ba28bfe0f485b8a67
version: null
source:
Git: https://github.com/pulp-platform/clint.git
dependencies:
- apb
- common_cells
- register_interface
common_cells:
revision: 9afda9abb565971649c2aa0985639c096f351171
version: 1.38.0
Expand Down
8 changes: 5 additions & 3 deletions Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ package:
- "Thomas Benz <tbenz@iis.ee.ethz.ch>"

dependencies:
apb: { git: "https://github.com/pulp-platform/apb.git", version: 0.2.4 }
apb_uart: { git: "https://github.com/pulp-platform/apb_uart.git", version: 0.2.3 }
axi: { git: "https://github.com/pulp-platform/axi.git", version: 0.39.8 }
axi_llc: { git: "https://github.com/pulp-platform/axi_llc.git", version: 0.2.1 }
axi_riscv_atomics: { git: "https://github.com/pulp-platform/axi_riscv_atomics.git", version: 0.8.2 }
axi_rt: { git: "https://github.com/pulp-platform/axi_rt.git", version: 0.0.0-alpha.10 }
axi_vga: { git: "https://github.com/pulp-platform/axi_vga.git", version: 0.1.3 }
clic: { git: "https://github.com/pulp-platform/clic.git", version: 3.0.0 }
clint: { git: "https://github.com/pulp-platform/clint.git", version: 0.2.0 }
clint: { git: "https://github.com/pulp-platform/clint.git", rev: rdl }
common_cells: { git: "https://github.com/pulp-platform/common_cells.git", version: 1.38.0 }
common_verification: { git: "https://github.com/pulp-platform/common_verification.git", version: 0.2.3 }
cva6: { git: "https://github.com/pulp-platform/cva6.git", rev: pulp-v2.0.0 }
Expand All @@ -39,8 +40,9 @@ sources:
- hw/future/UsbOhciAxi4.v
- hw/future/spinal_usb_ohci.sv
- hw/bootrom/cheshire_bootrom.sv
- hw/regs/cheshire_reg_pkg.sv
- hw/regs/cheshire_reg_top.sv
- hw/regs/cheshire_regs_addrmap_pkg.sv
- hw/regs/cheshire_regs_pkg.sv
- hw/regs/cheshire_regs.sv
- hw/cheshire_idma_wrap.sv
- hw/cheshire_pkg.sv
- hw/cheshire_soc.sv
Expand Down
25 changes: 17 additions & 8 deletions cheshire.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ IDMA_ROOT := $(shell $(BENDER) path idma)
DRAM_RTL_SIM_ROOT := $(shell $(BENDER) path dram_rtl_sim)

REGTOOL ?= $(CHS_REG_DIR)/vendor/lowrisc_opentitan/util/regtool.py
PEAKRDL ?= peakrdl

PEAKRDL_INCLUDES := -I $(CHS_ROOT)/hw/regs

################
# Dependencies #
Expand Down Expand Up @@ -83,14 +86,19 @@ include $(CHS_ROOT)/sw/sw.mk
###############

# SoC registers
$(CHS_ROOT)/hw/regs/cheshire_reg_pkg.sv $(CHS_ROOT)/hw/regs/cheshire_reg_top.sv: $(CHS_ROOT)/hw/regs/cheshire_regs.hjson
$(REGTOOL) -r $< --outdir $(dir $@)
$(CHS_ROOT)/hw/regs/cheshire_regs_pkg.sv $(CHS_ROOT)/hw/regs/cheshire_regs.sv: \
$(CHS_ROOT)/hw/regs/cheshire_regs.rdl
$(PEAKRDL) regblock $< -o $(CHS_ROOT)/hw/regs/ --cpuif apb4-flat --default-reset arst_n
@sed -i '1i// Copyright 2025 ETH Zurich and University of Bologna.\n// Solderpad Hardware License, Version 0.51, see LICENSE for details.\n// SPDX-License-Identifier: SHL-0.51\n' \
$(CHS_ROOT)/hw/regs/cheshire_regs.sv $(CHS_ROOT)/hw/regs/cheshire_regs_pkg.sv

$(CHS_ROOT)/hw/regs/cheshire_regs_addrmap_pkg.sv: $(CHS_ROOT)/hw/regs/cheshire_regs.rdl
$(PEAKRDL) raw-header $< --format svpkg -o $@
@sed -i '1i// Copyright 2025 ETH Zurich and University of Bologna.\n// Solderpad Hardware License, Version 0.51, see LICENSE for details.\n// SPDX-License-Identifier: SHL-0.51\n' $@

# CLINT
CLINTCORES ?= 1
include $(CLINTROOT)/clint.mk
$(CLINTROOT)/.generated:
flock -x $@ $(MAKE) clint && touch $@

# OpenTitan peripherals
include $(OTPROOT)/otp.mk
Expand Down Expand Up @@ -118,8 +126,9 @@ $(CHS_SLINK_DIR)/.generated: $(CHS_ROOT)/hw/serial_link.hjson
include $(IDMA_ROOT)/idma.mk

CHS_HW_ALL += $(IDMA_FULL_RTL)
CHS_HW_ALL += $(CHS_ROOT)/hw/regs/cheshire_reg_pkg.sv $(CHS_ROOT)/hw/regs/cheshire_reg_top.sv
CHS_HW_ALL += $(CLINTROOT)/.generated
CHS_HW_ALL += $(CHS_ROOT)/hw/regs/cheshire_regs_addrmap_pkg.sv
CHS_HW_ALL += $(CHS_ROOT)/hw/regs/cheshire_regs_pkg.sv $(CHS_ROOT)/hw/regs/cheshire_regs.sv
CHS_HW_ALL += $(CLINTROOT)/src/clint_reg.sv
CHS_HW_ALL += $(OTPROOT)/.generated
CHS_HW_ALL += $(AXIRTROOT)/.generated
CHS_HW_ALL += $(AXI_VGA_ROOT)/.generated
Expand Down Expand Up @@ -147,11 +156,11 @@ CHS_BOOTROM_ALL += $(CHS_ROOT)/hw/bootrom/cheshire_bootrom.sv $(CHS_ROOT)/hw/boo
# Simulation #
##############

$(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl: $(CHS_ROOT)/Bender.yml
$(CHS_ROOT)/target/sim/vsim/compile.cheshire_soc.tcl: $(CHS_ROOT)/Bender.yml $(CHS_ROOT)/Bender.lock
$(BENDER) script vsim -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOG_ARGS)" > $@
echo 'vlog "$(realpath $(CHS_ROOT))/target/sim/src/elfloader.cpp" -ccflags "-std=c++11" -cpppath "$(CXX_PATH)"' >> $@

$(CHS_ROOT)/target/sim/vcs/compile.cheshire_soc.sh: $(CHS_ROOT)/Bender.yml
$(CHS_ROOT)/target/sim/vcs/compile.cheshire_soc.sh: $(CHS_ROOT)/Bender.yml $(CHS_ROOT)/Bender.lock
$(BENDER) script vcs -t sim -t test $(CHS_BENDER_RTL_FLAGS) --vlog-arg="$(VLOGAN_ARGS)" --vlogan-bin="$(VLOGAN)" > $@
chmod +x $@

Expand Down
13 changes: 7 additions & 6 deletions hw/bootrom/cheshire_bootrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ int boot_passive(uint64_t core_freq) {
// Initialize UART with debug settings
uart_debug_init(&__base_uart, core_freq);
// scratch[0] provides an entry point, scratch[1] a start signal
volatile uint32_t *scratch = reg32(&__base_regs, CHESHIRE_SCRATCH_0_REG_OFFSET);
volatile cheshire_regs_t *regs = CHS_REGS;
// While we poll bit 2 of scratch[2], check for incoming UART debug requests
while (!(scratch[2] & 2))
while (!(regs->scratch[2].w & 2))
if (uart_debug_check(&__base_uart)) return uart_debug_serve(&__base_uart);
// No UART (or JTAG) requests came in, but scratch[2][2] was set --> run code at scratch[1:0]
scratch[2] = 0;
return boot_next_stage((void *)(uintptr_t)(((uint64_t)scratch[1] << 32) | scratch[0]));
regs->scratch[2].w = 0;
return boot_next_stage(
(void *)(uintptr_t)(((uint64_t)regs->scratch[1].w << 32) | regs->scratch[0].w));
}

int boot_spi_sdcard(uint64_t core_freq, uint64_t rtc_freq) {
Expand Down Expand Up @@ -69,8 +70,8 @@ int boot_i2c_24fc1025(uint64_t core_freq) {

int main() {
// Read boot mode and reference frequency
uint32_t bootmode = *reg32(&__base_regs, CHESHIRE_BOOT_MODE_REG_OFFSET);
uint32_t rtc_freq = *reg32(&__base_regs, CHESHIRE_RTC_FREQ_REG_OFFSET);
uint32_t bootmode = CHS_REGS->boot_mode.f.boot_mode;
uint32_t rtc_freq = CHS_REGS->rtc_freq.f.ref_freq;
// Compute the boot core frequency using the reference clock
uint64_t core_freq = clint_get_core_freq(rtc_freq, 2500);
// In case of reentry, store return in scratch0 as is convention
Expand Down
Loading
Loading