-
Notifications
You must be signed in to change notification settings - Fork 53
/
init.go
174 lines (144 loc) · 3.85 KB
/
init.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// NXP i.MX6UL initialization
// https://github.com/usbarmory/tamago
//
// Copyright (c) WithSecure Corporation
// https://foundry.withsecure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
package imx6ul
import (
"runtime"
_ "unsafe"
"github.com/usbarmory/tamago/arm"
"github.com/usbarmory/tamago/bits"
"github.com/usbarmory/tamago/dma"
"github.com/usbarmory/tamago/internal/reg"
"github.com/usbarmory/tamago/soc/nxp/bee"
"github.com/usbarmory/tamago/soc/nxp/dcp"
"github.com/usbarmory/tamago/soc/nxp/enet"
"github.com/usbarmory/tamago/soc/nxp/usb"
)
// i.MX processor families
const (
IMX6UL = 0x64
IMX6ULL = 0x65
)
//go:linkname ramStackOffset runtime.ramStackOffset
var ramStackOffset uint32 = 0x100
var (
// Processor family
Family uint32
// Flag native or emulated processor
Native bool
// SDP flags whether Serial Download Protocol over USB has been used to
// boot this runtime. The value is always false on non-secure (e.g.
// TrustZone Normal World) processor modes.
SDP bool
)
// Init takes care of the lower level SoC initialization triggered early in
// runtime setup (e.g. runtime.hwinit).
func Init() {
if ARM.Mode() != arm.SYS_MODE {
// initialization required only when in PL1
return
}
ramStart, _ := runtime.MemRegion()
ARM.Init(ramStart)
ARM.EnableVFP()
// required when booting in SDP mode
ARM.EnableSMP()
// MMU initialization is required to take advantage of data cache
ARM.InitMMU()
ARM.EnableCache()
_, fam, revMajor, revMinor := SiliconVersion()
Family = fam
if revMajor != 0 || revMinor != 0 {
Native = true
}
initTimers()
}
func init() {
// Initialize watchdogs, this must be done within 16 seconds to clear
// their power-down counter event
// (p4085, 59.5.3 Power-down counter event, IMX6ULLRM).
WDOG1.Init()
WDOG2.Init()
WDOG3.Init()
// use internal OCRAM (iRAM) as default DMA region
dma.Init(OCRAM_START, OCRAM_SIZE)
OCOTP.Init()
model := Model()
switch model {
case "i.MX6UL":
if Native {
// Configuration and Manufacturing Info
// p2203, 35.5.15 OCOTP_CFG3, IMX6ULRM
cfg3, _ := OCOTP.Read(0, 4)
// BEE_UNAVAILABLE
if bits.Get(&cfg3, 25, 1) == 0 {
// Bus Encryption Engine
BEE = &bee.BEE{
Base: BEE_BASE,
SNVS: SNVS,
}
SNVS.DryIce = SNVS_LP_BASE
}
}
OCOTP.Banks = 16
case "i.MX6ULL", "i.MX6ULZ":
// Data Co-Processor
DCP = &dcp.DCP{
Base: DCP_BASE,
CCGR: CCM_CCGR0,
CG: CCGRx_CG5,
IRQ: DCP_IRQ,
DeriveKeyMemory: dma.Default(),
}
OCOTP.Banks = 8
}
switch model {
case "i.MX6UL", "i.MX6ULL":
// Ethernet MAC 1
ENET1 = &enet.ENET{
Index: 1,
Base: ENET1_BASE,
CCGR: CCM_CCGR0,
CG: CCGRx_CG6,
Clock: GetPeripheralClock,
IRQ: ENET1_IRQ,
EnablePLL: EnableENETPLL,
}
// Ethernet MAC 2
ENET2 = &enet.ENET{
Index: 2,
Base: ENET2_BASE,
CCGR: CCM_CCGR0,
CG: CCGRx_CG6,
Clock: GetPeripheralClock,
IRQ: ENET2_IRQ,
EnablePLL: EnableENETPLL,
}
}
if !Native || ARM.NonSecure() {
return
}
// OCOTP_ANA1 Temperature Sensor Calibration Data
// p3531, 52.2 Software Usage Guidelines, IMX6ULLRM
ana1, _ := OCOTP.Read(1, 6)
// initialize temperature monitor
TEMPMON.Init(ana1)
// DryIce Trim Values
// p1060, 8.5.2 DryIce Trim Value Register, IMX6ULSRM
mem1, _ := OCOTP.Read(1, 1)
// initialize security state machine (SSM)
SNVS.Init(mem1)
// On the i.MX6UL family the only way to detect if we are booting
// through Serial Download Mode over USB is to check whether the USB
// OTG1 controller was running in device mode prior to our own
// initialization.
if reg.Get(USB1_BASE+usb.USB_UOGx_USBMODE, usb.USBMODE_CM, 0b11) == usb.USBMODE_CM_DEVICE &&
reg.Get(USB1_BASE+usb.USB_UOGx_USBCMD, usb.USBCMD_RS, 1) != 0 {
SDP = true
}
}