Add chosen node to DTS to enable dynamic earlycon select

This commit is contained in:
Jerry Zhao
2023-03-25 21:34:32 -07:00
parent 93f1c5cf33
commit f474646c17

View File

@@ -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