github.com/usbarmory/armory-boot@v0.0.0-20240307133412-208c66a380b9/main.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 main 10 11 import ( 12 "fmt" 13 "log" 14 15 "github.com/usbarmory/armory-boot/config" 16 "github.com/usbarmory/armory-boot/disk" 17 "github.com/usbarmory/armory-boot/exec" 18 19 usbarmory "github.com/usbarmory/tamago/board/usbarmory/mk2" 20 "github.com/usbarmory/tamago/soc/nxp/imx6ul" 21 "github.com/usbarmory/tamago/soc/nxp/usdhc" 22 ) 23 24 var Build string 25 var Revision string 26 27 var Boot string 28 var Start string 29 30 // signify/minisign authentication when defined 31 var PublicKeyStr string 32 33 func init() { 34 log.SetFlags(0) 35 36 if err := imx6ul.SetARMFreq(900); err != nil { 37 panic(fmt.Sprintf("cannot change ARM frequency, %v\n", err)) 38 } 39 } 40 41 func preLaunch() { 42 usbarmory.LED("blue", false) 43 usbarmory.LED("white", false) 44 } 45 46 func main() { 47 var card *usdhc.USDHC 48 49 usbarmory.LED("blue", false) 50 usbarmory.LED("white", false) 51 52 switch Boot { 53 case "eMMC": 54 card = usbarmory.MMC 55 case "uSD": 56 card = usbarmory.SD 57 default: 58 panic("invalid boot parameter") 59 } 60 61 part, err := disk.Detect(card, Start) 62 63 if err != nil { 64 panic(fmt.Sprintf("boot media error, %v\n", err)) 65 } 66 67 usbarmory.LED("blue", true) 68 69 if len(PublicKeyStr) == 0 { 70 log.Printf("armory-boot: no public key, skipping signature verification") 71 } 72 73 conf, err := config.Load(part, config.DefaultConfigPath, config.DefaultSignaturePath, PublicKeyStr) 74 75 if err != nil { 76 panic(fmt.Sprintf("configuration error, %v\n", err)) 77 } 78 79 log.Printf("\n%s", conf.JSON) 80 81 usbarmory.LED("white", true) 82 83 var image exec.BootImage 84 85 if conf.ELF { 86 image = &exec.ELFImage{ 87 Region: mem, 88 ELF: conf.Kernel(), 89 } 90 } else { 91 image = &exec.LinuxImage{ 92 Region: mem, 93 Kernel: conf.Kernel(), 94 DeviceTreeBlob: conf.DeviceTreeBlob(), 95 InitialRamDisk: conf.InitialRamDisk(), 96 KernelOffset: kernelOffset, 97 DeviceTreeBlobOffset: paramsOffset, 98 InitialRamDiskOffset: initrdOffset, 99 CmdLine: conf.CmdLine, 100 } 101 } 102 103 if err = image.Load(); err != nil { 104 panic(fmt.Sprintf("load error, %v\n", err)) 105 } 106 107 log.Printf("armory-boot: starting kernel@%.8x\n", image.Entry()) 108 109 if err = image.Boot(preLaunch); err != nil { 110 panic(fmt.Sprintf("load error, %v\n", err)) 111 } 112 }