forked from google/trillian-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
137 lines (106 loc) · 2.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// https://github.com/usbarmory/armory-boot
//
// Copyright (c) F-Secure Corporation
// https://foundry.f-secure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
//go:build armory
// +build armory
package main
import (
"fmt"
"log"
"strconv"
usbarmory "github.com/usbarmory/tamago/board/f-secure/usbarmory/mark-two"
"github.com/usbarmory/tamago/dma"
"github.com/usbarmory/tamago/soc/imx6"
)
var Build string
var Revision string
var Boot string
var StartKernel string
var StartProof string
var PublicKeyStr string
var (
partition *Partition
proofPartition *Partition
)
func init() {
usbarmory.LED("blue", false)
usbarmory.LED("white", false)
log.SetFlags(0)
if err := imx6.SetARMFreq(900); err != nil {
panic(fmt.Sprintf("cannot change ARM frequency, %v\n", err))
}
kernOffset, err := strconv.ParseInt(StartKernel, 10, 64)
if err != nil {
panic(fmt.Sprintf("invalid start kernel offset, %v\n", err))
}
partition = &Partition{
Offset: kernOffset,
}
proofOffset, err := strconv.ParseInt(StartProof, 10, 64)
if err != nil {
panic(fmt.Sprintf("invalid proof partition start offset: %v\n", err))
}
proofPartition = &Partition{
Offset: proofOffset,
}
switch Boot {
case "eMMC":
partition.Card = usbarmory.MMC
proofPartition.Card = usbarmory.MMC
case "uSD":
partition.Card = usbarmory.SD
proofPartition.Card = usbarmory.SD
default:
panic("invalid boot parameter")
}
}
func main() {
dma.Init(dmaStart, dmaSize)
if err := partition.Card.Detect(); err != nil {
panic(fmt.Sprintf("boot media error, %v\n", err))
}
usbarmory.LED("blue", true)
if err := conf.Init(partition, defaultConfigPath); err != nil {
panic(fmt.Sprintf("configuration error, %v\n", err))
}
if err := verifyIntegrity(proofPartition, partition); err != nil {
panic(fmt.Sprintf("invalid proof bundle: %v\n", err))
}
if len(PublicKeyStr) > 0 {
err := conf.Verify(defaultConfigPath+signatureSuffix, PublicKeyStr)
if err != nil {
panic(fmt.Sprintf("configuration error, %v\n", err))
}
} else {
log.Printf("armory-boot: no public key, skipping signature verification")
}
err := conf.Load()
if err != nil {
panic(fmt.Sprintf("configuration error, %v\n", err))
}
if !verifyHash(conf.kernel, conf.kernelHash) {
panic("invaid kernel hash")
}
if len(conf.params) > 0 {
if !verifyHash(conf.params, conf.paramsHash) {
panic("invalid dtb hash")
}
conf.params, err = fixupDeviceTree(conf.params, conf.CmdLine)
if err != nil {
panic(fmt.Sprintf("dtb fixup error, %v\n", err))
}
}
usbarmory.LED("white", true)
mem, _ := dma.Reserve(dmaSize, 0)
if conf.elf {
boot(loadELF(mem, conf.kernel), 0)
} else {
dma.Write(mem, kernelOffset, conf.kernel)
dma.Write(mem, paramsOffset, conf.params)
boot(mem+kernelOffset, mem+paramsOffset)
}
}