From b0a0fc8d41d02ed1992f5fe13e94ac51e4b032c4 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Thu, 17 Oct 2024 12:47:01 +0100 Subject: [PATCH 1/2] OS uses appropriate wakeHandler for applet runtime --- trusted_os/handler.go | 20 ++++++++++++++++++-- trusted_os/main.go | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/trusted_os/handler.go b/trusted_os/handler.go index 5ec2669..c30e5ac 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,21 @@ var irqHandler = make(map[int]func()) func wakeHandler(g uint32, p uint32) func wakeHandlerPreGo123(g uint32, p uint32) +var ( + // wHandler is the wakeHandler implementation to be used, 1.23+ by default. + wHandler = wakeHandler + wHandlerCutover = *semver.New("1.23.0") +) + +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 +61,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 +83,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) From 59c8303ead35f31b22ca8ef796ca8c6eaf31d381 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Thu, 17 Oct 2024 14:17:35 +0100 Subject: [PATCH 2/2] Fix comments --- trusted_os/handler.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trusted_os/handler.go b/trusted_os/handler.go index c30e5ac..871fbb2 100644 --- a/trusted_os/handler.go +++ b/trusted_os/handler.go @@ -39,10 +39,14 @@ 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("1.23.0") + wHandlerCutover = *semver.New(handlerCutover) ) func configureWakeHandler(rtVersion semver.Version) {