Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(version): inject git commit SHA to hardware CommitIDModule #3818

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import $file.openLLC.common
/* for publishVersion */
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import java.io.{BufferedReader, InputStreamReader}
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
Expand Down Expand Up @@ -277,8 +278,28 @@ object xiangshan extends XiangShanModule with HasChisel with ScalafmtModule {
LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMM dd hh:mm:ss yyyy").withLocale(new Locale("en")))),
)

def gitStatus: T[String] = {
val gitRevParseBuilder = new ProcessBuilder("git", "rev-parse", "HEAD")
val gitRevParseProcess = gitRevParseBuilder.start()
val shaReader = new BufferedReader(new InputStreamReader(gitRevParseProcess.getInputStream))
val sha = shaReader.readLine()

val gitStatusBuilder = new ProcessBuilder("git", "status", "-uno", "--porcelain")
val gitStatusProcess = gitStatusBuilder.start()
val gitStatusReader = new BufferedReader(new InputStreamReader(gitStatusProcess.getInputStream))
val status = gitStatusReader.readLine()
val gitDirty = if (status == null) 0 else 1

val str =
s"""|SHA=$sha
|dirty=$gitDirty
|""".stripMargin
str
}

override def resources = T.sources {
os.write(T.dest / "publishVersion", publishVersion())
os.write(T.dest / "gitStatus", gitStatus())
super.resources() ++ Seq(PathRef(T.dest))
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/scala/xiangshan/backend/fu/NewCSR/CommitIDModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xiangshan.backend.fu.NewCSR

import chisel3._

import java.util.Properties

class CommitIDModule(shaWidth: Int) extends Module {
val io = IO(new Bundle {
val commitID = Output(UInt(shaWidth.W))
val dirty = Output(Bool())
})

val props = new Properties()
props.load((os.resource / "gitStatus").getInputStream)

val sha = props.get("SHA").asInstanceOf[String].take(shaWidth / 4)
val dirty = props.get("dirty").asInstanceOf[String].toInt

println(s"[CommitIDModule] SHA=$sha")
println(s"[CommitIDModule] dirty=$dirty")

io.commitID := BigInt(sha, 16).U(shaWidth.W)
io.dirty := dirty.U
}
6 changes: 6 additions & 0 deletions src/main/scala/xiangshan/backend/fu/NewCSR/NewCSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ class NewCSR(implicit val p: Parameters) extends Module

val permitMod = Module(new CSRPermitModule)
val sstcIRGen = Module(new SstcInterruptGen)
val commidIdMod = Module(new CommitIDModule(40))

val gitCommitSHA = WireInit(commidIdMod.io.commitID)
val gitDirty = WireInit(commidIdMod.io.dirty)
dontTouch(gitCommitSHA)
dontTouch(gitDirty)

private val wenLegal = permitMod.io.out.hasLegalWen

Expand Down
Loading