Skip to content

Commit

Permalink
Add SPI flash configs, IOBinders, and CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwright6323 committed May 7, 2020
1 parent 794509a commit 0e88b64
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ jobs:
steps:
- prepare-rtl:
project-key: "testchipip"
prepare-chipyard-spiflash:
executor: main-env
steps:
- prepare-rtl:
project-key: "chipyard-spiflash"
chipyard-rocket-run-tests:
executor: main-env
steps:
Expand Down Expand Up @@ -300,6 +305,11 @@ jobs:
- run-tests:
tools-version: "esp-tools"
project-key: "chipyard-gemmini"
chipyard-spiflash-run-tests:
executor: main-env
steps:
- run-tests:
project-key: "chipyard-spiflash"
tracegen-run-tests:
executor: main-env
steps:
Expand Down Expand Up @@ -463,6 +473,11 @@ workflows:
- install-riscv-toolchain
- install-verilator

- prepare-chipyard-spiflash:
requires:
- install-riscv-toolchain
- install-verilator

# Run the respective tests

# Run midasexamples test
Expand Down Expand Up @@ -507,6 +522,10 @@ workflows:
requires:
- prepare-tracegen-boom

- chipyard-spiflash-run-tests:
requires:
- prepare-chipyard-spiflash

# Run the firesim tests
- firesim-run-tests:
requires:
Expand Down
1 change: 1 addition & 0 deletions .circleci/defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mapping["chipyard-blkdev"]="SUB_PROJECT=chipyard CONFIG=SimBlockDeviceRocketConf
mapping["chipyard-hwacha"]="SUB_PROJECT=chipyard CONFIG=HwachaRocketConfig"
mapping["chipyard-gemmini"]="SUB_PROJECT=chipyard CONFIG=GemminiRocketConfig"
mapping["chipyard-ariane"]="SUB_PROJECT=chipyard CONFIG=ArianeConfig"
mapping["chipyard-spiflash"]="SUB_PROJECT=chipyard CONFIG=SPIFlashRocketConfig"
mapping["tracegen"]="SUB_PROJECT=chipyard CONFIG=NonBlockingTraceGenL2Config TOP=TraceGenSystem"
mapping["tracegen-boom"]="SUB_PROJECT=chipyard CONFIG=BoomTraceGenConfig TOP=TraceGenSystem"
mapping["firesim"]="SCALA_TEST=firesim.firesim.RocketNICF1Tests"
Expand Down
4 changes: 4 additions & 0 deletions .circleci/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ case $1 in
(cd $LOCAL_CHIPYARD_DIR/generators/sha3/software && ./build.sh)
$LOCAL_SIM_DIR/simulator-chipyard-Sha3RocketConfig $LOCAL_CHIPYARD_DIR/generators/sha3/software/benchmarks/bare/sha3-rocc.riscv
;;
chipyard-spiflash)
make -C $LOCAL_CHIPYARD_DIR/tests
make -C $LOCAL_SIM_DIR ${mapping[$1]} BINARY=$LOCAL_CHIPYARD_DIR/tests/spiflash.riscv SIM_FLAGS="+spiflash0=${LOCAL_CHIPYARD_DIR}/tests/spiflash.img" run-binary
;;
tracegen)
run_tracegen ${mapping[$1]}
;;
Expand Down
10 changes: 10 additions & 0 deletions generators/chipyard/src/main/scala/ConfigFragments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import hwacha.{Hwacha}

import sifive.blocks.devices.gpio._
import sifive.blocks.devices.uart._
import sifive.blocks.devices.spi._

import chipyard.{BuildTop, BuildSystem}

Expand Down Expand Up @@ -52,6 +53,11 @@ class WithUART extends Config((site, here, up) => {
UARTParams(address = 0x54000000L, nTxEntries = 256, nRxEntries = 256))
})

class WithSPIFlash extends Config((site, here, up) => {
case PeripherySPIFlashKey => Seq(
SPIFlashParams(rAddress = 0x10040000, fAddress = 0x20000000, fSize = 0x10000000)) // Note: this matches freedom
})

class WithNoGPIO extends Config((site, here, up) => {
case PeripheryGPIOKey => Nil
})
Expand All @@ -60,6 +66,10 @@ class WithNoUART extends Config((site, here, up) => {
case PeripheryUARTKey => Nil
})

class WithNoSPIFlash extends Config((site, here, up) => {
case PeripherySPIFlashKey => Nil
})

class WithL2TLBs(entries: Int) extends Config((site, here, up) => {
case RocketTilesKey => up(RocketTilesKey) map (tile => tile.copy(
core = tile.core.copy(nL2TLBEntries = entries)
Expand Down
2 changes: 2 additions & 0 deletions generators/chipyard/src/main/scala/DigitalTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DigitalTop(implicit p: Parameters) extends System
with testchipip.CanHavePeripherySerial // Enables optionally adding the TSI serial-adapter and port
with sifive.blocks.devices.uart.HasPeripheryUART // Enables optionally adding the sifive UART
with sifive.blocks.devices.gpio.HasPeripheryGPIO // Enables optionally adding the sifive GPIOs
with sifive.blocks.devices.spi.HasPeripherySPIFlash // Enables optionally adding the sifive SPI flash controller
with icenet.CanHavePeripheryIceNIC // Enables optionally adding the IceNIC for FireSim
with chipyard.example.CanHavePeripheryInitZero // Enables optionally adding the initzero example widget
with chipyard.example.CanHavePeripheryGCD // Enables optionally adding the GCD example widget
Expand All @@ -32,6 +33,7 @@ class DigitalTopModule[+L <: DigitalTop](l: L) extends SystemModule(l)
with testchipip.CanHavePeripherySerialModuleImp
with sifive.blocks.devices.uart.HasPeripheryUARTModuleImp
with sifive.blocks.devices.gpio.HasPeripheryGPIOModuleImp
with sifive.blocks.devices.spi.HasPeripherySPIFlashModuleImp
with icenet.CanHavePeripheryIceNICModuleImp
with chipyard.example.CanHavePeripheryGCDModuleImp
with freechips.rocketchip.util.DontTouch
Expand Down
46 changes: 42 additions & 4 deletions generators/chipyard/src/main/scala/IOBinders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import freechips.rocketchip.util._

import sifive.blocks.devices.gpio._
import sifive.blocks.devices.uart._
import sifive.blocks.devices.spi._

import barstools.iocell.chisel._

Expand Down Expand Up @@ -88,10 +89,8 @@ object AddIOCells {
def gpio(gpios: Seq[GPIOPortIO], genFn: () => DigitalGPIOCell = IOCell.genericGPIO): (Seq[Seq[Analog]], Seq[Seq[IOCell]]) = {
gpios.zipWithIndex.map({ case (gpio, i) =>
gpio.pins.zipWithIndex.map({ case (pin, j) =>
val g = IO(Analog(1.W))
g.suggestName("gpio_${i}_${j}")
val iocell = genFn()
iocell.suggestName(s"iocell_gpio_${i}_${j}")
val g = IO(Analog(1.W)).suggestName("gpio_${i}_${j}")
val iocell = genFn().suggestName(s"iocell_gpio_${i}_${j}")
iocell.io.o := pin.o.oval
iocell.io.oe := pin.o.oe
iocell.io.ie := pin.o.ie
Expand All @@ -115,6 +114,37 @@ object AddIOCells {
}).unzip
}

/**
* Add IO cells to a SiFive SPI devices and name the IO ports.
* @param spiPins A Seq of SPI port bundles
* @param basename The base name for this port (defaults to "spi")
* @param genFn A callable function to generate a DigitalGPIOCell module to use
* @return Returns a tuple of (A Seq of top-level SPIChipIO IOs; a 2D Seq of IOCell module references)
*/
def spi(spiPins: Seq[SPIPortIO], basename: String = "spi", genFn: () => DigitalGPIOCell = IOCell.genericGPIO): (Seq[SPIChipIO], Seq[Seq[IOCell]]) = {
spiPins.zipWithIndex.map({ case (s, i) =>
val port = IO(new SPIChipIO(s.c.csWidth)).suggestName(s"${basename}_${i}")
val iocellBase = s"iocell_${basename}_${i}"

// SCK and CS are unidirectional outputs
val sckIOs = IOCell.generateFromSignal(s.sck, port.sck, Some(s"${iocellBase}_sck"))
val csIOs = IOCell.generateFromSignal(s.cs, port.cs, Some(s"${iocellBase}_cs"))

// DQ are bidirectional, so then need special treatment
val dqIOs = s.dq.zip(port.dq).zipWithIndex.map { case ((pin, ana), j) =>
val iocell = genFn().suggestName(s"${iocellBase}_dq_${j}")
iocell.io.o := pin.o
iocell.io.oe := pin.oe
iocell.io.ie := true.B
pin.i := iocell.io.i
iocell.io.pad <> ana
iocell
}

(port, dqIOs ++ csIOs ++ sckIOs)
}).unzip
}

/**
* Add IO cells to a debug module and name the IO ports.
* @param psd A PSDIO bundle
Expand Down Expand Up @@ -172,6 +202,14 @@ class WithUARTAdapter extends OverrideIOBinder({
}
})

class WithSimSPIFlashModel extends OverrideIOBinder({
(system: HasPeripherySPIFlashModuleImp) => {
val (ports, ioCells2d) = AddIOCells.spi(system.qspi, "qspi")
val harnessFn = (th: chipyard.TestHarness) => { SimSPIFlashModel.connect(ports, th.reset)(system.p); Nil }
Seq((ports, ioCells2d.flatten, Some(harnessFn)))
}
})

class WithSimBlockDevice extends OverrideIOBinder({
(system: CanHavePeripheryBlockDeviceModuleImp) => system.connectSimBlockDevice(system.clock, system.reset.asBool); Nil
})
Expand Down
2 changes: 2 additions & 0 deletions generators/chipyard/src/main/scala/config/ArianeConfigs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArianeConfig extends Config(
new chipyard.config.WithNoGPIO ++ // no top-level GPIO pins (overrides default set in sifive-blocks)
new chipyard.config.WithBootROM ++ // use default bootrom
new chipyard.config.WithUART ++ // add a UART
new chipyard.config.WithNoSPIFlash ++ // no SPI flash controller
new freechips.rocketchip.subsystem.WithNoMMIOPort ++ // no top-level MMIO master port (overrides default set in rocketchip)
new freechips.rocketchip.subsystem.WithNoSlavePort ++ // no top-level MMIO slave port (overrides default set in rocketchip)
new freechips.rocketchip.subsystem.WithInclusiveCache ++ // use Sifive L2 cache
Expand All @@ -34,6 +35,7 @@ class dmiArianeConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
new freechips.rocketchip.subsystem.WithInclusiveCache ++
Expand Down
8 changes: 8 additions & 0 deletions generators/chipyard/src/main/scala/config/BoomConfigs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SmallBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++ // no top-level GPIO pins (overrides default set in sifive-blocks)
new chipyard.config.WithBootROM ++ // use default bootrom
new chipyard.config.WithUART ++ // add a UART
new chipyard.config.WithNoSPIFlash ++ // no SPI flash controller
new chipyard.config.WithL2TLBs(1024) ++ // use L2 TLBs
new freechips.rocketchip.subsystem.WithNoMMIOPort ++ // no top-level MMIO master port (overrides default set in rocketchip)
new freechips.rocketchip.subsystem.WithNoSlavePort ++ // no top-level MMIO slave port (overrides default set in rocketchip)
Expand All @@ -35,6 +36,7 @@ class MediumBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand All @@ -54,6 +56,7 @@ class LargeBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand All @@ -73,6 +76,7 @@ class MegaBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand All @@ -92,6 +96,7 @@ class DualSmallBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand All @@ -111,6 +116,7 @@ class SmallRV32BoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand All @@ -132,6 +138,7 @@ class HwachaLargeBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new hwacha.DefaultHwachaConfig ++ // use Hwacha vector accelerator
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
Expand All @@ -154,6 +161,7 @@ class LoopbackNICLargeBoomConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new freechips.rocketchip.subsystem.WithNoMMIOPort ++
new freechips.rocketchip.subsystem.WithNoSlavePort ++
Expand Down
7 changes: 7 additions & 0 deletions generators/chipyard/src/main/scala/config/HeteroConfigs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LargeBoomAndRocketConfig extends Config(
new chipyard.config.WithNoGPIO ++ // no top-level GPIO pins (overrides default set in sifive-blocks)
new chipyard.config.WithBootROM ++ // use default bootrom
new chipyard.config.WithUART ++ // add a UART
new chipyard.config.WithNoSPIFlash ++ // no SPI flash controller
new chipyard.config.WithL2TLBs(1024) ++ // use L2 TLBs
new chipyard.config.WithRenumberHarts ++ // avoid hartid overlap
new boom.common.WithLargeBooms ++ // 3-wide boom
Expand All @@ -38,6 +39,7 @@ class HwachaLargeBoomAndHwachaRocketConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new hwacha.DefaultHwachaConfig ++ // add hwacha to all harts
new chipyard.config.WithRenumberHarts ++
Expand All @@ -61,6 +63,7 @@ class DualLargeBoomAndRocketConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new chipyard.config.WithRenumberHarts ++
new boom.common.WithLargeBooms ++
Expand All @@ -84,6 +87,7 @@ class LargeBoomAndHwachaRocketConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithMultiRoCC ++ // support heterogeneous rocc
new chipyard.config.WithMultiRoCCHwacha(1) ++ // put hwacha on hart-2 (rocket)
new chipyard.config.WithL2TLBs(1024) ++
Expand All @@ -110,6 +114,7 @@ class LargeBoomAndRV32RocketConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new chipyard.config.WithRenumberHarts ++
new boom.common.WithLargeBooms ++
Expand All @@ -134,6 +139,7 @@ class DualLargeBoomAndDualRocketConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithL2TLBs(1024) ++
new chipyard.config.WithRenumberHarts ++
new boom.common.WithLargeBooms ++
Expand All @@ -156,6 +162,7 @@ class LargeBoomAndRocketWithControlCoreConfig extends Config(
new chipyard.config.WithNoGPIO ++
new chipyard.config.WithBootROM ++
new chipyard.config.WithUART ++
new chipyard.config.WithNoSPIFlash ++
new chipyard.config.WithControlCore ++ // add small control core to last hartid
new chipyard.config.WithL2TLBs(1024) ++
new chipyard.config.WithRenumberHarts ++
Expand Down
Loading

0 comments on commit 0e88b64

Please sign in to comment.