@@ -13,6 +13,7 @@ import freechips.rocketchip.diplomacy.{AddressSet, RegionType, TransferSizes}
13
13
import freechips .rocketchip .resources .{Resource , SimpleDevice }
14
14
import freechips .rocketchip .subsystem ._
15
15
import freechips .rocketchip .tilelink .{TLFragmenter , TLManagerNode , TLSlaveParameters , TLSlavePortParameters }
16
+ import freechips .rocketchip .util .{FileName , SystemFileName , ResourceFileName }
16
17
17
18
import java .nio .ByteBuffer
18
19
import java .nio .file .{Files , Paths }
@@ -22,7 +23,11 @@ case class BootROMParams(
22
23
address : BigInt = 0x10000 ,
23
24
size : Int = 0x10000 ,
24
25
hang : BigInt = 0x10040 , // The hang parameter is used as the power-on reset vector
25
- contentFileName : String )
26
+ driveResetVector : Boolean = true ,
27
+ appendDTB : Boolean = true ,
28
+ name : String = " bootrom" ,
29
+ contentFileName : FileName = SystemFileName (" ./bootrom/bootrom.img" )
30
+ )
26
31
27
32
class TLROM (val base : BigInt , val size : Int , contentsDelayed : => Seq [Byte ], executable : Boolean = true , beatBytes : Int = 4 ,
28
33
resources : Seq [Resource ] = new SimpleDevice (" rom" , Seq (" sifive,rom0" )).reg(" mem" ))(implicit p : Parameters ) extends LazyModule
@@ -63,7 +68,7 @@ class TLROM(val base: BigInt, val size: Int, contentsDelayed: => Seq[Byte], exec
63
68
}
64
69
}
65
70
66
- case class BootROMLocated (loc : HierarchicalLocation ) extends Field [Option [BootROMParams ]](None )
71
+ case class BootROMLocated (loc : HierarchicalLocation ) extends Field [Seq [BootROMParams ]](Nil )
67
72
68
73
object BootROM {
69
74
/** BootROM.attach not only instantiates a TLROM and attaches it to the tilelink interconnect
@@ -73,27 +78,40 @@ object BootROM {
73
78
def attach (params : BootROMParams , subsystem : BaseSubsystem with HasHierarchicalElements with HasTileInputConstants , where : TLBusWrapperLocation )
74
79
(implicit p : Parameters ): TLROM = {
75
80
val tlbus = subsystem.locateTLBusWrapper(where)
76
- val bootROMDomainWrapper = tlbus.generateSynchronousDomain(" BootROM " ).suggestName(" bootrom_domain " )
81
+ val bootROMDomainWrapper = tlbus.generateSynchronousDomain(params.name ).suggestName(s " ${params.name} _domain " )
77
82
78
83
val bootROMResetVectorSourceNode = BundleBridgeSource [UInt ]()
79
- lazy val contents = {
80
- val romdata = Files .readAllBytes(Paths .get(params.contentFileName))
81
- val rom = ByteBuffer .wrap(romdata)
82
- rom.array() ++ subsystem.dtb.contents
84
+ val rom = params.contentFileName match {
85
+ case SystemFileName (fileName) => {
86
+ val romdata = Files .readAllBytes(Paths .get(fileName))
87
+ ByteBuffer .wrap(romdata).array()
88
+ }
89
+ case ResourceFileName (fileName) => {
90
+ val file = os.resource / os.RelPath (fileName.dropWhile(_ == '/' ))
91
+ os.read.bytes(file)
92
+ }
93
+ }
94
+
95
+ lazy val contents = if (params.appendDTB) {
96
+ rom ++ subsystem.dtb.contents
97
+ } else {
98
+ rom
83
99
}
84
100
85
101
val bootrom = bootROMDomainWrapper {
86
102
LazyModule (new TLROM (params.address, params.size, contents, true , tlbus.beatBytes))
87
103
}
88
104
89
- bootrom.node := tlbus.coupleTo(" bootrom " ){ TLFragmenter (tlbus, Some (" BootROM " )) := _ }
105
+ bootrom.node := tlbus.coupleTo(params.name ){ TLFragmenter (tlbus, Some (params.name )) := _ }
90
106
// Drive the `subsystem` reset vector to the `hang` address of this Boot ROM.
91
- subsystem.tileResetVectorNexusNode := bootROMResetVectorSourceNode
92
- InModuleBody {
93
- val reset_vector_source = bootROMResetVectorSourceNode.bundle
94
- require(reset_vector_source.getWidth >= params.hang.bitLength,
95
- s " BootROM defined with a reset vector ( ${params.hang})too large for physical address space ( ${reset_vector_source.getWidth}) " )
96
- bootROMResetVectorSourceNode.bundle := params.hang.U
107
+ if (params.driveResetVector) {
108
+ subsystem.tileResetVectorNexusNode := bootROMResetVectorSourceNode
109
+ InModuleBody {
110
+ val reset_vector_source = bootROMResetVectorSourceNode.bundle
111
+ require(reset_vector_source.getWidth >= params.hang.bitLength,
112
+ s " BootROM defined with a reset vector ( ${params.hang})too large for physical address space ( ${reset_vector_source.getWidth}) " )
113
+ bootROMResetVectorSourceNode.bundle := params.hang.U
114
+ }
97
115
}
98
116
bootrom
99
117
}
0 commit comments