-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
87 lines (66 loc) · 1.6 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
// https://github.com/usbarmory/armory-ums
//
// 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 main
import (
"errors"
"log"
"github.com/usbarmory/tamago/soc/nxp/imx6ul"
"github.com/usbarmory/tamago/soc/nxp/usb"
"github.com/usbarmory/tamago/soc/nxp/usdhc"
usbarmory "github.com/usbarmory/tamago/board/usbarmory/mk2"
)
var cards []*usdhc.USDHC
func init() {
log.SetFlags(0)
switch imx6ul.Model() {
case "i.MX6ULL", "i.MX6ULZ":
imx6ul.SetARMFreq(imx6ul.FreqMax)
case "i.MX6UL":
imx6ul.SetARMFreq(imx6ul.Freq528)
}
}
func detect(card *usdhc.USDHC) (err error) {
if card == nil {
return errors.New("no such device")
}
if err = card.Detect(); err != nil {
return
}
info := card.Info()
capacity := int64(info.BlockSize) * int64(info.Blocks)
giga := capacity / (1000 * 1000 * 1000)
gibi := capacity / (1024 * 1024 * 1024)
log.Printf("imx6_usdhc: %d GB/%d GiB card detected %+v", giga, gibi, info)
cards = append(cards, card)
return
}
func main() {
err := detect(usbarmory.SD)
if err != nil {
usbarmory.LED("white", false)
} else {
usbarmory.LED("white", true)
}
err = detect(usbarmory.MMC)
if err != nil {
usbarmory.LED("blue", false)
} else {
usbarmory.LED("blue", true)
}
device := &usb.Device{
Setup: setup,
}
configureDevice(device)
iface := buildMassStorageInterface()
device.Configurations[0].AddInterface(iface)
usbarmory.USB1.Init()
usbarmory.USB1.DeviceMode()
usbarmory.USB1.Reset()
// never returns
usbarmory.USB1.Start(device)
}