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

     1  // Copyright (c) WithSecure Corporation
     2  // https://foundry.withsecure.com
     3  //
     4  // Use of this source code is governed by the license
     5  // that can be found in the LICENSE file.
     6  
     7  //go:build !console
     8  // +build !console
     9  
    10  package main
    11  
    12  import (
    13  	"io"
    14  	"log"
    15  	_ "unsafe"
    16  
    17  	"github.com/usbarmory/tamago/soc/nxp/imx6ul"
    18  )
    19  
    20  // This bootloader does not log any sensitive information to the serial
    21  // console, however it is desirable to silence any potential stack trace or
    22  // runtime errors to avoid unwanted information leaks.
    23  //
    24  // The TamaGo board support for the USB armory Mk II enables the serial console
    25  // (UART2) at runtime initialization, which therefore invokes imx6.UART2.Init()
    26  // before init().
    27  //
    28  // To this end the runtime printk function, responsible for all console logging
    29  // operations (i.e. stdout/stderr), is overridden with a NOP. Secondarily UART2
    30  // is disabled at the first opportunity (init()).
    31  
    32  func init() {
    33  	// disable console
    34  	imx6ul.UART2.Disable()
    35  	// silence logging
    36  	log.SetOutput(io.Discard)
    37  }
    38  
    39  //go:linkname printk runtime.printk
    40  func printk(c byte) {
    41  	// ensure that any serial output is supressed before UART2 disabling
    42  }