diff --git a/trusted_os/handler.go b/trusted_os/handler.go index 5ec2669..871fbb2 100644 --- a/trusted_os/handler.go +++ b/trusted_os/handler.go @@ -17,6 +17,7 @@ package main import ( "log" + "github.com/coreos/go-semver/semver" "github.com/usbarmory/tamago/arm" "github.com/usbarmory/tamago/bits" "github.com/usbarmory/tamago/soc/nxp/imx6ul" @@ -38,6 +39,25 @@ var irqHandler = make(map[int]func()) func wakeHandler(g uint32, p uint32) func wakeHandlerPreGo123(g uint32, p uint32) +// handlerCutover is the semver representation of the cut over between wakeHandler implementations above. +// Anything less that this should use the legacy PreGo123 version. +const handlerCutover = "1.23.0" + +var ( + // wHandler is the wakeHandler implementation to be used, 1.23+ by default. + wHandler = wakeHandler + wHandlerCutover = *semver.New(handlerCutover) +) + +func configureWakeHandler(rtVersion semver.Version) { + if rtVersion.LessThan(wHandlerCutover) { + wHandler = wakeHandlerPreGo123 + log.Printf("SM Using legacy pre-%s wakeHandler", wHandlerCutover.String()) + } else { + wHandler = wakeHandler + } +} + func isr() { irq := imx6ul.GIC.GetInterrupt(true) @@ -45,7 +65,7 @@ func isr() { handle() return } - log.Printf("unexpected IRQ %d", irq) + log.Printf("SM unexpected IRQ %d", irq) } func fiqHandler(ctx *monitor.ExecCtx) (_ error) { @@ -67,7 +87,7 @@ func fiqHandler(ctx *monitor.ExecCtx) (_ error) { // mask FIQs, applet handler will request unmasking when done bits.Set(&ctx.SPSR, CPSR_FIQ) - wakeHandler(appletHandlerG, appletHandlerP) + wHandler(appletHandlerG, appletHandlerP) return } diff --git a/trusted_os/main.go b/trusted_os/main.go index ec59d4e..29f60b1 100644 --- a/trusted_os/main.go +++ b/trusted_os/main.go @@ -228,7 +228,10 @@ func main() { log.Printf("SM applet verification error, %v", err) } loadedAppletVersion = manifest.Git.TagName - log.Printf("SM Loaded applet version %s", loadedAppletVersion.String()) + loadedAppletRuntime := manifest.Build.TamagoVersion + log.Printf("SM Loaded applet version %s (with TamaGo runtime %s)", loadedAppletVersion.String(), loadedAppletRuntime.String()) + + configureWakeHandler(loadedAppletRuntime) usbarmory.LED("white", true)