Skip to content

Commit

Permalink
Add BootTester
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu1990 committed Nov 27, 2024
1 parent 2584d0e commit 672cf6a
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/test/scala/vexiiriscv/scratchpad/BootTester.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package vexiiriscv.scratchpad

import jssc.{SerialPort, SerialPortException}
import spinal.lib.DoCmd

object BootTester extends App{
var counter = 0
val serialPort = new SerialPort("/dev/ttyUSB2")
var state = "LOGIN"
def tx(that : String): Unit = {
for(c <- that){
serialPort.writeByte(c.toByte)
Thread.sleep(50)
}
}

def reboot(): Unit = {
DoCmd.doCmd("openocd -f ft2232h_breakout.cfg -f vexiiriscv_jtag.tcl -f debug.tcl", "src/main/tcl/openocd")
}

def notify(line : String): Unit = {
state match {
case "LOGIN" => if(line.endsWith("nexys login:")){
println("BOOTED")
Thread.sleep(2000)
tx("root\n")
state = "PASSWORD"
}
case "PASSWORD" => if(line.endsWith("Password:")){
println("BOOTED")
Thread.sleep(2000)
tx("root\n")
state = "LOGGED"
}

case "LOGGED" => if(line.endsWith("root@nexys:")){
println("LOGGED")
Thread.sleep(2000)
tx("poweroff\n")
state = "LITEX"
}
case "LITEX" => if(line.endsWith("reboot: Power down")){
println("LITEX")
Thread.sleep(2000)
reboot()
counter += 1
println("Reboot counter " + counter)
state = "LOGIN"
}
}
// if(line.contains("Debian GNU/Linux trixie/sid nexys ttyLXU0")){
// println("MIAOUUUU")
// tx("root\nroot")
// DoCmd.doCmd("openocd -f ft2232h_breakout.cfg -f vexiiriscv_jtag.tcl -c reset -c exit", "src/main/tcl/openocd")
// }
}

reboot()
try {
var line = new StringBuilder()
serialPort.openPort //Open serial port
serialPort.setParams(115200, 8, 1, 0) //Set params.
while(true){
val buffer = serialPort.readString()
if(buffer!=null){
print(buffer)
buffer.foreach{
case '\n' => line.clear()
case '\r' =>
case c => line += c; notify(line.toString);
}
} else {
Thread.sleep(10)
}
}

serialPort.closePort //Close serial port
} catch {
case ex: SerialPortException =>
System.out.println(ex)
}
}

0 comments on commit 672cf6a

Please sign in to comment.