github.com/transparency-dev/armored-witness-os@v0.1.3-0.20240514084412-27eef7325168/trusted_os/console.go (about)

     1  // Copyright 2022 The Armored Witness OS authors. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build !debug
    16  // +build !debug
    17  
    18  package main
    19  
    20  import (
    21  	"io"
    22  	"log"
    23  	_ "unsafe"
    24  
    25  	"github.com/usbarmory/tamago/soc/nxp/imx6ul"
    26  )
    27  
    28  // The Trusted OS does not log any sensitive information to the serial console,
    29  // however it is desirable to silence any potential stack trace or runtime
    30  // errors to avoid unwanted information leaks.
    31  //
    32  // The TamaGo board support for the USB armory Mk II enables the serial console
    33  // (UART2) at runtime initialization, which therefore invokes imx6.UART2.Init()
    34  // before init().
    35  //
    36  // To this end the runtime printk function, responsible for all console logging
    37  // operations (i.e. stdout/stderr), is overridden with a NOP. Secondarily UART2
    38  // is disabled at the first opportunity (init()).
    39  
    40  const debug = false
    41  
    42  func init() {
    43  	// disable console
    44  	imx6ul.UART2.Disable()
    45  	// silence logging
    46  	log.SetOutput(io.Discard)
    47  }
    48  
    49  //go:linkname printk runtime.printk
    50  func printk(c byte) {
    51  	// ensure that any serial output is supressed before UART2 disabling
    52  }
    53  
    54  func getConsoleLogs() []byte {
    55  	return nil
    56  }
    57  
    58  func inspect(buf []byte, _ any) error {
    59  	return nil
    60  }
    61  
    62  func configureUART(_ any) error {
    63  	return nil
    64  }