github.com/usbarmory/armory-boot@v0.0.0-20240307133412-208c66a380b9/exec/boot_arm.go (about)

     1  // https://github.com/usbarmory/armory-boot
     2  //
     3  // Copyright (c) WithSecure Corporation
     4  // https://foundry.withsecure.com
     5  //
     6  // Use of this source code is governed by the license
     7  // that can be found in the LICENSE file.
     8  
     9  // Package exec provides support for kernel image loading and booting on the
    10  // USB armory Mk II platform.
    11  //
    12  // This package is only meant to be used with `GOOS=tamago GOARCH=arm` as
    13  // supported by the TamaGo framework for bare metal Go on ARM SoCs, see
    14  // https://github.com/usbarmory/tamago.
    15  package exec
    16  
    17  import (
    18  	"errors"
    19  
    20  	"github.com/usbarmory/tamago/arm"
    21  	"github.com/usbarmory/tamago/soc/nxp/imx6ul"
    22  )
    23  
    24  // defined in boot.s
    25  func exec(kernel uint32, params uint32, mmu bool)
    26  func svc()
    27  
    28  func boot(kernel uint, params uint, cleanup func(), mmu bool) (err error) {
    29  	arm.SystemExceptionHandler = func(n int) {
    30  		if n != arm.SUPERVISOR {
    31  			panic("unhandled exception")
    32  		}
    33  
    34  		cleanup()
    35  
    36  		if !mmu {
    37  			imx6ul.ARM.FlushDataCache()
    38  			imx6ul.ARM.DisableCache()
    39  		}
    40  
    41  		exec(uint32(kernel), uint32(params), mmu)
    42  	}
    43  
    44  	svc()
    45  
    46  	return errors.New("supervisor failure")
    47  }