|
@@ -1,15 +1,15 @@
|
1
|
1
|
package main
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
|
- "bufio"
|
5
|
4
|
"code.beefchicken.com/trimtools/dotx"
|
6
|
5
|
"code.beefchicken.com/trimtools/monitor"
|
|
6
|
+ "github.com/chzyer/readline"
|
|
7
|
+
|
7
|
8
|
"encoding/binary"
|
8
|
9
|
"flag"
|
9
|
10
|
"fmt"
|
10
|
|
- "io"
|
11
|
|
- "io/ioutil"
|
12
|
11
|
"log"
|
|
12
|
+ "math"
|
13
|
13
|
"os"
|
14
|
14
|
"strconv"
|
15
|
15
|
"strings"
|
|
@@ -17,42 +17,30 @@ import (
|
17
|
17
|
|
18
|
18
|
func main() {
|
19
|
19
|
|
20
|
|
- var baud, dataBits, stopBits int
|
21
|
|
- var debug, startMonitor, dummy bool
|
|
20
|
+ var baud int
|
|
21
|
+ var debug, interactiveMonitor, showVersion, dummy bool
|
22
|
22
|
var device, parity string
|
|
23
|
+ var inFile, outFile string
|
23
|
24
|
|
24
|
|
- flag.IntVar(&baud, "baud", 38400, "baud rate")
|
25
|
|
- flag.IntVar(&dataBits, "databits", 8, "data bits")
|
26
|
|
- flag.IntVar(&stopBits, "stopbits", 1, "stop bits")
|
27
|
|
- flag.BoolVar(&debug, "debug", false, "enable debug messages")
|
28
|
|
- flag.BoolVar(&startMonitor, "M", false, "start monitor")
|
29
|
|
- flag.BoolVar(&dummy, "dummy", false, "dummy mode")
|
30
|
|
- flag.StringVar(&device, "device", "/dev/tty.usbserial-AB0JS0VU", "serial port device")
|
31
|
|
- flag.StringVar(&parity, "parity", "n", "parity (n,e,o)")
|
|
25
|
+ flag.IntVar(&baud, "b", 38400, "baud rate")
|
|
26
|
+ flag.StringVar(&parity, "p", "none", "parity (none, even, lsodd)")
|
32
|
27
|
|
|
28
|
+ flag.BoolVar(&debug, "x", false, "enable debug messages")
|
|
29
|
+ flag.BoolVar(&interactiveMonitor, "m", false, "start interactive monitor")
|
|
30
|
+ flag.BoolVar(&showVersion, "v", false, "show version and exit")
|
|
31
|
+ flag.BoolVar(&dummy, "dummy", false, "dummy mode")
|
|
32
|
+ flag.StringVar(&device, "d", "/dev/tty.usbserial-AB0JS0VU", "serial port device")
|
|
33
|
+ flag.StringVar(&outFile, "s", "", "save firmware from receiver to file")
|
|
34
|
+ flag.StringVar(&inFile, "f", "", "write firmware from file to receiver")
|
33
|
35
|
flag.Parse()
|
34
|
36
|
|
35
|
|
- inFile := flag.Arg(0)
|
36
|
|
- // if inFile == "" {
|
37
|
|
- // fmt.Printf("Usage:\n%s [flags] <.X file>\n", os.Args[0])
|
38
|
|
- // os.Exit(1)
|
39
|
|
- // }
|
|
37
|
+ if showVersion {
|
|
38
|
+ fmt.Println("loader(.exe) Trimble 4000 Firmware Loader")
|
|
39
|
+ fmt.Println("Written by Keelan Lightfoot - http://beefchicken.com")
|
|
40
|
+ return
|
|
41
|
+ }
|
40
|
42
|
|
41
|
43
|
var fw *dotx.DotXFile
|
42
|
|
- if inFile != "" {
|
43
|
|
- // load file
|
44
|
|
- f, err := os.Open(inFile)
|
45
|
|
- if err != nil {
|
46
|
|
- log.Fatal(err)
|
47
|
|
- }
|
48
|
|
- defer f.Close()
|
49
|
|
- fw, err = dotx.ReadDotX(f)
|
50
|
|
- if err != nil {
|
51
|
|
- log.Fatal(err)
|
52
|
|
- }
|
53
|
|
- fmt.Println(fw.FirmwareDate())
|
54
|
|
-
|
55
|
|
- }
|
56
|
44
|
|
57
|
45
|
var mon *monitor.Monitor
|
58
|
46
|
var err error
|
|
@@ -60,9 +48,12 @@ func main() {
|
60
|
48
|
if dummy {
|
61
|
49
|
mon = &monitor.Monitor{
|
62
|
50
|
Debug: debug,
|
|
51
|
+ Dummy: dummy,
|
63
|
52
|
}
|
|
53
|
+ fmt.Println("Monitor dummy mode active.")
|
|
54
|
+
|
64
|
55
|
} else {
|
65
|
|
- mon, err = monitor.Connect(device, baud, dataBits, stopBits, parity, debug)
|
|
56
|
+ mon, err = monitor.Connect(device, baud, 8, 1, parity, debug)
|
66
|
57
|
if err != nil {
|
67
|
58
|
log.Fatal(err)
|
68
|
59
|
}
|
|
@@ -74,147 +65,194 @@ func main() {
|
74
|
65
|
log.Fatal(err)
|
75
|
66
|
}
|
76
|
67
|
|
77
|
|
- if fw != nil {
|
78
|
|
- mon.WriteFirmware(fw)
|
|
68
|
+ if interactiveMonitor {
|
|
69
|
+ runMonitor(mon)
|
|
70
|
+ return
|
79
|
71
|
}
|
80
|
72
|
|
81
|
|
- if startMonitor {
|
82
|
|
- reader := bufio.NewReader(os.Stdin)
|
83
|
|
- running := true
|
84
|
|
- for running {
|
85
|
|
- fmt.Print("\nenter command: ")
|
86
|
|
- b, err := reader.ReadBytes('\n')
|
87
|
|
- if err == io.EOF {
|
88
|
|
- fmt.Println("bye")
|
89
|
|
- break
|
90
|
|
- }
|
91
|
|
- cmd := strings.Fields(string(b))
|
92
|
|
- if len(cmd) == 0 {
|
93
|
|
- continue
|
94
|
|
- }
|
95
|
|
- switch strings.ToLower(cmd[0]) {
|
96
|
|
- case "?":
|
97
|
|
- fmt.Println("Manual help mode:")
|
98
|
|
- fmt.Println(" Q or X : Exit program.")
|
99
|
|
- fmt.Println(" R : Reset target and exit program.")
|
100
|
|
- fmt.Println(" U addr count : hex/ascii dump of count bytes starting at addr")
|
101
|
|
- fmt.Println(" (UD command works with doubles)")
|
102
|
|
- fmt.Println(" D addr count data... : download data bytes to target address")
|
103
|
|
- fmt.Println(" (DD command works with doubles)")
|
104
|
|
- fmt.Println(" F addr count char : fill target memory block")
|
105
|
|
- fmt.Println(" V : Display firmware versions and code segment ranges.")
|
106
|
|
- fmt.Println(" O : Display options data.")
|
107
|
|
- fmt.Println(" ")
|
108
|
|
- fmt.Println(" Addresses and data default to hex. Counts default to decimal.")
|
109
|
|
- fmt.Println(" $xxxx or !dddd force hex or decimal.")
|
110
|
|
- fmt.Println(" CoMmAnDs ArE CaSe InSeNsITiVe.")
|
111
|
|
- case "q":
|
112
|
|
- fallthrough
|
113
|
|
- case "x":
|
114
|
|
- running = false
|
115
|
|
- case "r":
|
116
|
|
- mon.Stop()
|
117
|
|
- running = false
|
118
|
|
- case "u":
|
119
|
|
- handleUCommand(mon, cmd)
|
120
|
|
- case "ul":
|
121
|
|
- handleULCommand(mon, cmd)
|
122
|
|
- case "uf": // dump to file
|
123
|
|
- handleUFCommand(mon, cmd)
|
124
|
|
- case "ud":
|
125
|
|
- fmt.Println("unimplemented")
|
126
|
|
- case "d":
|
127
|
|
- handleDCommand(mon, cmd)
|
128
|
|
- case "dd":
|
129
|
|
- fmt.Println("unimplemented")
|
130
|
|
- case "f":
|
131
|
|
-
|
132
|
|
- b2, _ := mon.ReadMemory(0x80600+62, 10)
|
133
|
|
- fmt.Printf("% 02x\n", b2)
|
134
|
|
- fmt.Printf("%s\n", string(b2))
|
135
|
|
-
|
136
|
|
- b3, _ := mon.ReadMemory(0x80600+72, 10)
|
137
|
|
- fmt.Printf("% 02x\n", b3)
|
138
|
|
- fmt.Printf("%s\n", string(b3))
|
139
|
|
-
|
140
|
|
- fmt.Println("unimplemented")
|
141
|
|
- case "v":
|
142
|
|
- info, err := mon.GetReceiverInfo()
|
143
|
|
- if err != nil {
|
144
|
|
- log.Fatal(err)
|
145
|
|
- }
|
146
|
|
- info.PrintVersions()
|
147
|
|
- case "o":
|
148
|
|
- info, err := mon.GetReceiverInfo()
|
149
|
|
- if err != nil {
|
150
|
|
- log.Fatal(err)
|
151
|
|
- }
|
152
|
|
- info.PrintOptions()
|
153
|
|
- }
|
|
73
|
+ if outFile != "" {
|
|
74
|
+ fmt.Printf("Saving .X format firmware to '%s'...\n", outFile)
|
|
75
|
+ fw, err = mon.CaptureReceiverFirmware()
|
|
76
|
+ if err != nil {
|
|
77
|
+ log.Fatal(err)
|
|
78
|
+ }
|
|
79
|
+ f, err := os.Create(outFile)
|
|
80
|
+ if err != nil {
|
|
81
|
+ log.Fatal(err)
|
|
82
|
+ }
|
|
83
|
+ err = fw.WriteDotX(f)
|
|
84
|
+ if err != nil {
|
|
85
|
+ log.Fatal(err)
|
|
86
|
+ }
|
|
87
|
+ f.Close()
|
|
88
|
+ }
|
154
|
89
|
|
|
90
|
+ if inFile != "" {
|
|
91
|
+ fmt.Printf("Loading .X format firmware from '%s'...\n", inFile)
|
|
92
|
+ f, err := os.Open(inFile)
|
|
93
|
+ if err != nil {
|
|
94
|
+ log.Fatal(err)
|
|
95
|
+ }
|
|
96
|
+ fw, err = dotx.ReadDotX(f)
|
|
97
|
+ if err != nil {
|
|
98
|
+ log.Fatal(err)
|
|
99
|
+ }
|
|
100
|
+ f.Close()
|
|
101
|
+ err = mon.ProgramReceiver(fw)
|
|
102
|
+ if err != nil {
|
|
103
|
+ log.Fatal(err)
|
155
|
104
|
}
|
156
|
105
|
}
|
157
|
|
- //
|
158
|
|
- // b, err := mon.ReadMemory(0x712804, 4)
|
159
|
|
- // if err != nil {
|
160
|
|
- // log.Fatal(err)
|
161
|
|
- // }
|
162
|
|
- // fmt.Printf("% 02x\n", b)
|
163
|
106
|
|
164
|
107
|
}
|
165
|
108
|
|
166
|
|
-func handleDCommand(mon *monitor.Monitor, cmd []string) {
|
167
|
|
- if len(cmd) < 3 {
|
168
|
|
- fmt.Println("d address d1 d2 d3 dn...")
|
169
|
|
- return
|
|
109
|
+func runMonitor(mon *monitor.Monitor) {
|
|
110
|
+ commands := map[string]func(*monitor.Monitor, []string) bool{
|
|
111
|
+ "?": handleHelpCommand,
|
|
112
|
+ "q": handleQuitCommand,
|
|
113
|
+ "x": handleQuitCommand,
|
|
114
|
+ "r": handleResetCommand,
|
|
115
|
+ "u": handleUCommand,
|
|
116
|
+ "uw": handleUWCommand,
|
|
117
|
+ "ul": handleULCommand,
|
|
118
|
+ "ud": handleUDCommand,
|
|
119
|
+ "d": handleDCommand,
|
|
120
|
+ "dw": handleDWCommand,
|
|
121
|
+ "dl": handleDLCommand,
|
|
122
|
+ "dd": handleDDCommand,
|
|
123
|
+ "f": handleFCommand,
|
|
124
|
+ "v": handleVersionCommand,
|
|
125
|
+ "o": handleOptionsCommand,
|
|
126
|
+ "j": handleJCommand,
|
170
|
127
|
}
|
171
|
|
- addr, ok := parseNum(cmd[1], 16)
|
172
|
|
- if !ok {
|
173
|
|
- fmt.Println("invalid address")
|
174
|
|
- return
|
|
128
|
+
|
|
129
|
+ rl, err := readline.New("enter command: ")
|
|
130
|
+ if err != nil {
|
|
131
|
+ panic(err)
|
175
|
132
|
}
|
176
|
|
- v := make([]byte, 0)
|
177
|
|
- for _, s := range cmd[2:] {
|
178
|
|
- b, ok := parseNum(s, 16)
|
179
|
|
- if !ok {
|
180
|
|
- fmt.Printf("invalid byte: %s\n", s)
|
181
|
|
- return
|
|
133
|
+ defer rl.Close()
|
|
134
|
+
|
|
135
|
+ for {
|
|
136
|
+ fmt.Println("")
|
|
137
|
+ s, err := rl.Readline()
|
|
138
|
+ fmt.Println("")
|
|
139
|
+
|
|
140
|
+ if err != nil {
|
|
141
|
+ fmt.Println("bye")
|
|
142
|
+ break
|
|
143
|
+ }
|
|
144
|
+ cmd := strings.Fields(s)
|
|
145
|
+ if len(cmd) == 0 {
|
|
146
|
+ continue
|
|
147
|
+ }
|
|
148
|
+ verb := strings.ToLower(cmd[0])
|
|
149
|
+
|
|
150
|
+ if f := commands[verb]; f != nil {
|
|
151
|
+ if f(mon, cmd) {
|
|
152
|
+ break
|
|
153
|
+ }
|
|
154
|
+ } else {
|
|
155
|
+ fmt.Printf("unrecognized command: %s\n", verb)
|
182
|
156
|
}
|
183
|
|
- v = append(v, byte(b))
|
184
|
|
- }
|
185
|
|
- err := mon.WriteMemory(addr, v)
|
186
|
|
- if err != nil {
|
187
|
|
- fmt.Println("failed: %v\n", err)
|
188
|
157
|
}
|
|
158
|
+
|
|
159
|
+}
|
|
160
|
+
|
|
161
|
+func handleQuitCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
162
|
+ return true
|
|
163
|
+}
|
|
164
|
+
|
|
165
|
+func handleHelpCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
166
|
+ fmt.Print(
|
|
167
|
+ "Manual help mode:\n",
|
|
168
|
+ " Q or X : Exit program.\n",
|
|
169
|
+ " R : Reset target and exit program.\n",
|
|
170
|
+ " U addr count : hex/ascii dump of count bytes starting at addr\n",
|
|
171
|
+ " (UD command works with doubles)\n",
|
|
172
|
+ " (UW command works with words)\n",
|
|
173
|
+ " (UL command works with longs)\n",
|
|
174
|
+ " D addr count data... : download data bytes to target address\n",
|
|
175
|
+ " (DD command works with doubles)\n",
|
|
176
|
+ " (DW command works with words)\n",
|
|
177
|
+ " (DL command works with longs)\n",
|
|
178
|
+ " F addr count byte : fill target memory block\n",
|
|
179
|
+ " V : Display firmware versions and code segment ranges.\n",
|
|
180
|
+ " O : Display options data.\n",
|
|
181
|
+ " J addr : Jump to address.\n",
|
|
182
|
+ " \n",
|
|
183
|
+ " Addresses and data default to hex. Counts default to decimal.\n",
|
|
184
|
+ " $xxxx or !dddd force hex or decimal.\n",
|
|
185
|
+ " CoMmAnDs ArE CaSe InSeNsITiVe.\n",
|
|
186
|
+ )
|
|
187
|
+
|
|
188
|
+ return false
|
189
|
189
|
}
|
190
|
190
|
|
191
|
|
-func handleUCommand(mon *monitor.Monitor, cmd []string) {
|
|
191
|
+func handleResetCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
192
|
+ mon.Stop()
|
|
193
|
+ return false
|
|
194
|
+}
|
|
195
|
+
|
|
196
|
+func handleUCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
197
|
+ return ulCmd(mon, cmd, 1)
|
|
198
|
+}
|
|
199
|
+
|
|
200
|
+func handleUWCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
201
|
+ return ulCmd(mon, cmd, 2)
|
|
202
|
+}
|
|
203
|
+
|
|
204
|
+func handleULCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
205
|
+ return ulCmd(mon, cmd, 4)
|
|
206
|
+}
|
|
207
|
+
|
|
208
|
+func ulCmd(mon *monitor.Monitor, cmd []string, chunk int) bool {
|
192
|
209
|
if len(cmd) < 3 {
|
193
|
|
- fmt.Println("u address count")
|
194
|
|
- return
|
|
210
|
+ fmt.Printf("%s address count\n", cmd[0])
|
|
211
|
+ return false
|
195
|
212
|
}
|
196
|
213
|
addr, ok := parseNum(cmd[1], 16)
|
197
|
214
|
if !ok {
|
198
|
|
- fmt.Println("invalid address")
|
199
|
|
- return
|
|
215
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
216
|
+ return false
|
200
|
217
|
}
|
201
|
218
|
count, ok := parseNum(cmd[2], 10)
|
202
|
219
|
if !ok {
|
203
|
|
- fmt.Println("invalid count")
|
204
|
|
- return
|
|
220
|
+ fmt.Printf("invalid count: '%s'\n", cmd[2])
|
|
221
|
+ return false
|
205
|
222
|
}
|
206
|
|
- b, err := mon.ReadMemory(addr, int(count))
|
|
223
|
+
|
|
224
|
+ b, err := mon.ReadMemory(addr, int(count)*chunk)
|
207
|
225
|
if err != nil {
|
208
|
226
|
log.Fatal(err)
|
209
|
227
|
}
|
210
|
|
- fmt.Printf("upload data from target memory\n")
|
211
|
|
- fmt.Printf("start address: %08x number of bytes: %d\n", addr, count)
|
212
|
|
- for i := 0; i < int(count); i += 16 {
|
|
228
|
+
|
|
229
|
+ var dataType string
|
|
230
|
+
|
|
231
|
+ if chunk == 1 {
|
|
232
|
+ dataType = "byte"
|
|
233
|
+ } else if chunk == 2 {
|
|
234
|
+ dataType = "word"
|
|
235
|
+ } else if chunk == 4 {
|
|
236
|
+ dataType = "long"
|
|
237
|
+ }
|
|
238
|
+ fmt.Printf("upload %s data from target memory\n", dataType)
|
|
239
|
+ fmt.Printf("start address: %08x number of %ss: %d\n", addr, dataType, count)
|
|
240
|
+ for i := 0; i < int(count)*chunk; i += 16 {
|
213
|
241
|
e := i + 16
|
214
|
242
|
if e > len(b) {
|
215
|
243
|
e = len(b)
|
216
|
244
|
}
|
217
|
|
- line := fmt.Sprintf("%08x % 02x", addr+uint32(i), b[i:e])
|
|
245
|
+ line := fmt.Sprintf("%08x ", addr+uint32(i))
|
|
246
|
+ for q := 0; q < (e - i); q += chunk {
|
|
247
|
+ if chunk == 1 {
|
|
248
|
+ line = fmt.Sprintf("%s %02x", line, b[i+q])
|
|
249
|
+ } else if chunk == 2 {
|
|
250
|
+ line = fmt.Sprintf("%s %04x", line, binary.BigEndian.Uint16(b[i+q:]))
|
|
251
|
+ } else if chunk == 4 {
|
|
252
|
+ line = fmt.Sprintf("%s %08x", line, binary.BigEndian.Uint32(b[i+q:]))
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+
|
218
|
256
|
fmt.Printf("% -60s", line)
|
219
|
257
|
for j := i; j < e; j++ {
|
220
|
258
|
if b[j] >= 32 && b[j] <= 126 {
|
|
@@ -225,79 +263,190 @@ func handleUCommand(mon *monitor.Monitor, cmd []string) {
|
225
|
263
|
}
|
226
|
264
|
fmt.Printf("\n")
|
227
|
265
|
}
|
|
266
|
+ return false
|
228
|
267
|
}
|
229
|
268
|
|
230
|
|
-func handleULCommand(mon *monitor.Monitor, cmd []string) {
|
|
269
|
+func handleUDCommand(mon *monitor.Monitor, cmd []string) bool {
|
231
|
270
|
if len(cmd) < 3 {
|
232
|
271
|
fmt.Println("u address count")
|
233
|
|
- return
|
|
272
|
+ return false
|
234
|
273
|
}
|
235
|
274
|
addr, ok := parseNum(cmd[1], 16)
|
236
|
275
|
if !ok {
|
237
|
|
- fmt.Println("invalid address")
|
238
|
|
- return
|
|
276
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
277
|
+ return false
|
239
|
278
|
}
|
240
|
279
|
count, ok := parseNum(cmd[2], 10)
|
241
|
280
|
if !ok {
|
242
|
|
- fmt.Println("invalid count")
|
243
|
|
- return
|
|
281
|
+ fmt.Printf("invalid count: '%s'\n", cmd[2])
|
|
282
|
+ return false
|
244
|
283
|
}
|
245
|
|
- count *= 4
|
246
|
|
- b, err := mon.ReadMemory(addr, int(count))
|
|
284
|
+ b, err := mon.ReadMemory(addr, int(count)*8)
|
247
|
285
|
if err != nil {
|
248
|
|
- log.Fatal(err)
|
|
286
|
+ fmt.Printf("read failed: %v\n", err)
|
249
|
287
|
}
|
250
|
|
- fmt.Printf("upload long data from target memory\n")
|
251
|
|
- fmt.Printf("start address: %08x number of bytes: %d\n", addr, count)
|
252
|
|
- for i := 0; i < int(count); i += 16 {
|
253
|
|
- e := i + 16
|
254
|
|
- if e > len(b) {
|
255
|
|
- e = len(b)
|
|
288
|
+ fmt.Printf("upload doubles from target memory\n")
|
|
289
|
+ fmt.Printf("start address: %08x number of doubles: %d\n", addr, count)
|
|
290
|
+
|
|
291
|
+ for i := 0; i < int(count); i++ {
|
|
292
|
+ fmt.Printf("%08x %23.13e\n", int(addr)+i*8, math.Float64frombits(binary.BigEndian.Uint64(b[i*8:])))
|
|
293
|
+ }
|
|
294
|
+ return false
|
|
295
|
+}
|
|
296
|
+
|
|
297
|
+func handleDCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
298
|
+ return dlCmd(mon, cmd, 1)
|
|
299
|
+}
|
|
300
|
+
|
|
301
|
+func handleDWCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
302
|
+ return dlCmd(mon, cmd, 2)
|
|
303
|
+}
|
|
304
|
+
|
|
305
|
+func handleDLCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
306
|
+ return dlCmd(mon, cmd, 4)
|
|
307
|
+}
|
|
308
|
+
|
|
309
|
+func dlCmd(mon *monitor.Monitor, cmd []string, chunk int) bool {
|
|
310
|
+ if len(cmd) < 3 {
|
|
311
|
+ fmt.Printf("%s address v1 v2 v3 vn...\n", cmd[0])
|
|
312
|
+ return false
|
|
313
|
+ }
|
|
314
|
+ addr, ok := parseNum(cmd[1], 16)
|
|
315
|
+ if !ok {
|
|
316
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
317
|
+ return false
|
|
318
|
+ }
|
|
319
|
+
|
|
320
|
+ var dataType string
|
|
321
|
+
|
|
322
|
+ if chunk == 1 {
|
|
323
|
+ dataType = "byte"
|
|
324
|
+ } else if chunk == 2 {
|
|
325
|
+ dataType = "word"
|
|
326
|
+ } else if chunk == 4 {
|
|
327
|
+ dataType = "long"
|
|
328
|
+ }
|
|
329
|
+ fmt.Printf("download %s data to target memory\n", dataType)
|
|
330
|
+ fmt.Printf("start address: %08x number of %ss: %d\n", addr, dataType, len(cmd[2:]))
|
|
331
|
+
|
|
332
|
+ v := make([]byte, len(cmd[2:])*chunk)
|
|
333
|
+ i := 0
|
|
334
|
+ for _, s := range cmd[2:] {
|
|
335
|
+ l, ok := parseNum(s, 16)
|
|
336
|
+ if !ok {
|
|
337
|
+ fmt.Printf("invalid value: %s\n", s)
|
|
338
|
+ return false
|
256
|
339
|
}
|
257
|
|
- line := fmt.Sprintf("%08x ", addr+uint32(i))
|
258
|
|
- for q := 0; q < (e - i); q += 4 {
|
259
|
|
- line = fmt.Sprintf("%s %08x", line, binary.BigEndian.Uint32(b[i+q:]))
|
|
340
|
+
|
|
341
|
+ if chunk == 1 {
|
|
342
|
+ v[i] = byte(l)
|
|
343
|
+ } else if chunk == 2 {
|
|
344
|
+ binary.BigEndian.PutUint16(v[i:], uint16(l))
|
|
345
|
+ } else if chunk == 4 {
|
|
346
|
+ binary.BigEndian.PutUint32(v[i:], l)
|
260
|
347
|
}
|
261
|
348
|
|
262
|
|
- fmt.Printf("% -60s", line)
|
263
|
|
- for j := i; j < e; j++ {
|
264
|
|
- if b[j] >= 32 && b[j] <= 126 {
|
265
|
|
- fmt.Print(string(b[j]))
|
266
|
|
- } else {
|
267
|
|
- fmt.Print(".")
|
268
|
|
- }
|
|
349
|
+ i += chunk
|
|
350
|
+ }
|
|
351
|
+ err := mon.WriteMemory(addr, v)
|
|
352
|
+ if err != nil {
|
|
353
|
+ fmt.Println("failed: %v\n", err)
|
|
354
|
+ }
|
|
355
|
+ return false
|
|
356
|
+}
|
|
357
|
+
|
|
358
|
+func handleDDCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
359
|
+ if len(cmd) < 3 {
|
|
360
|
+ fmt.Println("dd address d1 d2 d3 dn...")
|
|
361
|
+ return false
|
|
362
|
+ }
|
|
363
|
+ addr, ok := parseNum(cmd[1], 16)
|
|
364
|
+ if !ok {
|
|
365
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
366
|
+ return false
|
|
367
|
+ }
|
|
368
|
+ v := make([]byte, len(cmd[2:])*8)
|
|
369
|
+ i := 0
|
|
370
|
+ for _, s := range cmd[2:] {
|
|
371
|
+ f, err := strconv.ParseFloat(s, 64)
|
|
372
|
+ if err != nil {
|
|
373
|
+ fmt.Printf("invalid float: %s\n", s)
|
|
374
|
+ return false
|
269
|
375
|
}
|
270
|
|
- fmt.Printf("\n")
|
|
376
|
+
|
|
377
|
+ binary.BigEndian.PutUint64(v[i:], math.Float64bits(f))
|
|
378
|
+ i += 8
|
|
379
|
+ }
|
|
380
|
+ err := mon.WriteMemory(addr, v)
|
|
381
|
+ if err != nil {
|
|
382
|
+ fmt.Println("failed: %v\n", err)
|
271
|
383
|
}
|
|
384
|
+ return false
|
272
|
385
|
}
|
273
|
386
|
|
274
|
|
-func handleUFCommand(mon *monitor.Monitor, cmd []string) {
|
|
387
|
+func handleFCommand(mon *monitor.Monitor, cmd []string) bool {
|
275
|
388
|
if len(cmd) < 4 {
|
276
|
|
- fmt.Println("u file address count")
|
277
|
|
- return
|
|
389
|
+ fmt.Println("f address count byte")
|
|
390
|
+ return false
|
278
|
391
|
}
|
279
|
|
- fileName := cmd[1]
|
280
|
|
-
|
281
|
|
- addr, ok := parseNum(cmd[2], 16)
|
|
392
|
+ addr, ok := parseNum(cmd[1], 16)
|
282
|
393
|
if !ok {
|
283
|
|
- fmt.Println("invalid address")
|
284
|
|
- return
|
|
394
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
395
|
+ return false
|
285
|
396
|
}
|
286
|
|
- count, ok := parseNum(cmd[3], 10)
|
|
397
|
+ count, ok := parseNum(cmd[2], 10)
|
287
|
398
|
if !ok {
|
288
|
|
- fmt.Println("invalid count")
|
289
|
|
- return
|
|
399
|
+ fmt.Printf("invalid count: '%s'\n", cmd[2])
|
|
400
|
+ return false
|
|
401
|
+ }
|
|
402
|
+ b, ok := parseNum(cmd[3], 16)
|
|
403
|
+ if !ok {
|
|
404
|
+ fmt.Printf("invalid byte: '%s'\n", cmd[3])
|
|
405
|
+ return false
|
|
406
|
+ }
|
|
407
|
+ v := make([]byte, count)
|
|
408
|
+ for i := 0; i < len(v); i++ {
|
|
409
|
+ v[i] = byte(b)
|
290
|
410
|
}
|
291
|
|
- b, err := mon.ReadMemory(addr, int(count))
|
|
411
|
+ err := mon.WriteMemory(addr, v)
|
292
|
412
|
if err != nil {
|
293
|
|
- fmt.Printf("read failed: %v\n", err)
|
|
413
|
+ fmt.Println("failed: %v\n", err)
|
294
|
414
|
}
|
295
|
|
- err = ioutil.WriteFile(fileName, b, 0644)
|
|
415
|
+ return false
|
|
416
|
+}
|
|
417
|
+
|
|
418
|
+func handleVersionCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
419
|
+ info, err := mon.GetReceiverInfo()
|
296
|
420
|
if err != nil {
|
297
|
|
- fmt.Printf("write to file failed: %v\n", err)
|
|
421
|
+ fmt.Printf("GetReceiverInfo failed: %v\n", err)
|
|
422
|
+ return false
|
298
|
423
|
}
|
299
|
|
- fmt.Printf("wrote %d bytes to %s\n", len(b), fileName)
|
|
424
|
+ info.PrintVersions()
|
|
425
|
+ return false
|
|
426
|
+}
|
|
427
|
+
|
|
428
|
+func handleOptionsCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
429
|
+ info, err := mon.GetReceiverInfo()
|
|
430
|
+ if err != nil {
|
|
431
|
+ fmt.Printf("GetReceiverInfo failed: %v\n", err)
|
|
432
|
+ return false
|
|
433
|
+ }
|
|
434
|
+ info.PrintOptions()
|
|
435
|
+ return false
|
|
436
|
+}
|
300
|
437
|
|
|
438
|
+func handleJCommand(mon *monitor.Monitor, cmd []string) bool {
|
|
439
|
+ if len(cmd) < 2 {
|
|
440
|
+ fmt.Println("j address")
|
|
441
|
+ return false
|
|
442
|
+ }
|
|
443
|
+ addr, ok := parseNum(cmd[1], 16)
|
|
444
|
+ if !ok {
|
|
445
|
+ fmt.Printf("invalid address: '%s'\n", cmd[1])
|
|
446
|
+ return false
|
|
447
|
+ }
|
|
448
|
+ mon.Jump(addr)
|
|
449
|
+ return false
|
301
|
450
|
}
|
302
|
451
|
|
303
|
452
|
func parseNum(s string, base int) (uint32, bool) {
|
|
@@ -315,25 +464,3 @@ func parseNum(s string, base int) (uint32, bool) {
|
315
|
464
|
}
|
316
|
465
|
return uint32(v), true
|
317
|
466
|
}
|
318
|
|
-
|
319
|
|
-// enter command: ud 0 100
|
320
|
|
-// upload doubles from target memory
|
321
|
|
-// start address: number of doubles: 00000000 1.1125369292673e-308
|
322
|
|
-// 00000008 6.8043917048940e-310
|
323
|
|
-// 00000010 6.8086356964769e-310
|
324
|
|
-// 00000018 6.8128796880598e-310
|
325
|
|
-// 00000020 6.8171236796428e-310
|
326
|
|
-// 00000028 6.8213676712257e-310
|
327
|
|
-// 00000030 0.0000000000000e+000
|
328
|
|
-// 00000038 0.0000000000000e+000
|
329
|
|
-// 00000040 0.0000000000000e+000
|
330
|
|
-// 00000048 0.0000000000000e+000
|
331
|
|
-// 00000050 0.0000000000000e+000
|
332
|
|
-// 00000058 0.0000000000000e+000
|
333
|
|
-// 00000060 6.8298556544112e-310
|
334
|
|
-// 00000068 7.5076211100665e-310
|
335
|
|
-// 00000070 8.9157775173783e-310
|
336
|
|
-// 00000078 6.8298556544421e-310
|
337
|
|
-// 00000080 6.8302800535493e-310
|
338
|
|
-// 00000088 7.0492700191769e-310
|
339
|
|
-// 00000090 6.8302800537515e-310
|