github.com/transparency-dev/armored-witness-boot@v0.1.0/console.go (about) 1 // Copyright 2022 The Armored Witness Boot 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 !console 16 // +build !console 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 // This bootloader does not log any sensitive information to the serial 29 // console, however it is desirable to silence any potential stack trace or 30 // runtime 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 func init() { 41 // disable console 42 imx6ul.UART2.Disable() 43 // silence logging 44 log.SetOutput(io.Discard) 45 } 46 47 //go:linkname printk runtime.printk 48 func printk(c byte) { 49 // ensure that any serial output is supressed before UART2 disabling 50 }