diff --git a/generators/chipyard/src/main/scala/Subsystem.scala b/generators/chipyard/src/main/scala/Subsystem.scala index 34175d39..3b4d312b 100644 --- a/generators/chipyard/src/main/scala/Subsystem.scala +++ b/generators/chipyard/src/main/scala/Subsystem.scala @@ -12,6 +12,7 @@ import freechips.rocketchip.prci._ import freechips.rocketchip.config.{Field, Parameters} import freechips.rocketchip.devices.tilelink._ import freechips.rocketchip.devices.debug.{HasPeripheryDebug, HasPeripheryDebugModuleImp, ExportDebug, DebugModuleKey} +import sifive.blocks.devices.uart.{HasPeripheryUART, PeripheryUARTKey} import freechips.rocketchip.diplomacy._ import freechips.rocketchip.tile._ import freechips.rocketchip.tilelink._ @@ -45,9 +46,35 @@ trait CanHaveHTIF { this: BaseSubsystem => } } +// This trait adds the "chosen" node to DTS, which +// can be used to pass information to OS about the earlycon +case object ChosenInDTS extends Field[Boolean](true) +trait CanHaveChosenInDTS { this: BaseSubsystem => + if (p(ChosenInDTS)) { + println("got here") + this match { + case t: HasPeripheryUART if (!p(PeripheryUARTKey).isEmpty) => { + println("Add chosen resource") + val chosen = new Device { + def describe(resources: ResourceBindings): Description = { + val stdout = resources("stdout").map(_.value) + Description("chosen", resources("uart").headOption.map { case Binding(_, value) => + "stdout-path" -> Seq(value) + }.toMap) + } + } + ResourceBinding { + t.uarts.foreach(u => Resource(chosen, "uart").bind(ResourceAlias(u.device.label))) + } + } + } + } +} + class ChipyardSubsystem(implicit p: Parameters) extends BaseSubsystem with HasTiles with CanHaveHTIF + with CanHaveChosenInDTS { def coreMonitorBundles = tiles.map { case r: RocketTile => r.module.core.rocketImpl.coreMonitorBundle