OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / tools / misc / ipd.gdb
1 #
2 #       GDB init script to support the Cirrus Logic EP9312 ARM
3 #       based CPU.
4 #
5 #       (C) Copyright 2003-2004, Greg Ungerer <gerg@snapgear.com>
6 #
7 #       Designed to be used with the Macraigor RAVEN wiggler for
8 #       ARM based 20ping JTAG setups. I use their OCdemon Linux
9 #       driver and arm-elf-gdb with it.
10 #
11
12 define uart-count
13 printf "%d\n", $r4
14 end
15
16 #
17 #       UART functions
18 #
19 define uart1-init
20 # This is set to 115200,8,n,1
21 set *((unsigned long *) 0x808c0010) = 0x07000000
22 set *((unsigned long *) 0x808c000c) = 0x00000000
23 set *((unsigned long *) 0x808c0008) = 0x60000000
24 set *((unsigned long *) 0x808c0014) = 0x01000000
25 end
26
27 define uart1-print
28 set *((unsigned long *) 0x808c0000) = $arg0
29 end
30
31 define uart1-loopback
32 set *((unsigned long *) 0x808c0014) = 0x81000000
33 end
34
35 define uart2-init
36 echo  uart2-init\n
37 # 8 fifo-enable 1 none
38 # fifo set *((unsigned char *) 0x808d0008) = 0x70
39 # BR = 0007 = 14.7456MHz / (16 * 115200) - 1
40 set *((unsigned char *) 0x808d0010) = 0x00
41 set *((unsigned char *) 0x808d000c) = 0x00
42 set *((unsigned char *) 0x808d0008) = 0x00
43 set *((unsigned char *) 0x808d0010) = 0x07
44 set *((unsigned char *) 0x808d000c) = 0x00
45 set *((unsigned char *) 0x808d0008) = 0x60
46 set *((unsigned char *) 0x808d0014) = 0x01
47 end
48
49 define uart2-print
50 set *((unsigned char *) 0x808d0000) = $arg0
51 end
52
53 define uart2-loopback
54 set *((unsigned char *) 0x808d0014) = 0x81
55 end
56
57 define uart3-init
58 # set UARTBAUD
59 set $tmp = * (unsigned long *) 0x80930004
60 set * (unsigned long *) 0x80930004 = ($tmp | 0x20000000)
61 # This is set to 115200,8,n,1
62 set *((unsigned long *) 0x808e0010) = 0x07000000
63 set *((unsigned long *) 0x808e000c) = 0x00000000
64 set *((unsigned long *) 0x808e0008) = 0x60000000
65 set *((unsigned long *) 0x808e0014) = 0x01000000
66 end
67
68 define uart3-print
69 set *((unsigned long *) 0x808e0000) = $arg0
70 end
71
72 define uart3-loopback
73 set *((unsigned long *) 0x808e0014) = 0x81000000
74 end
75
76
77 define uart-fetchcode
78 set *((unsigned long *) 0xc0000000) = 0xe3a01102 
79 set *((unsigned long *) 0xc0000004) = 0xe381188d 
80 set *((unsigned long *) 0xc0000008) = 0xe3a02007 
81 set *((unsigned long *) 0xc000000c) = 0xe5812010
82 set *((unsigned long *) 0xc0000010) = 0xe3a02000
83 set *((unsigned long *) 0xc0000014) = 0xe581200c
84 set *((unsigned long *) 0xc0000018) = 0xe3a02060
85 set *((unsigned long *) 0xc000001c) = 0xe5812008
86 set *((unsigned long *) 0xc0000020) = 0xe3a02001
87 set *((unsigned long *) 0xc0000024) = 0xe581200c
88 set *((unsigned long *) 0xc0000028) = 0xe3a04000 
89 set *((unsigned long *) 0xc000002c) = 0xe3a05103 
90 set *((unsigned long *) 0xc0000030) = 0xe3855a01 
91 # set *((unsigned long *) 0xc0000030) = 0xe38558ff 
92 set *((unsigned long *) 0xc0000034) = 0xe3a03010 
93 set *((unsigned long *) 0xc0000038) = 0xe5912018 
94 set *((unsigned long *) 0xc000003c) = 0xe1120003
95 set *((unsigned long *) 0xc0000040) = 0x1afffffc
96 set *((unsigned long *) 0xc0000044) = 0xe5912000
97 set *((unsigned long *) 0xc0000048) = 0xe5c52000
98 set *((unsigned long *) 0xc000004c) = 0xe2855001
99 set *((unsigned long *) 0xc0000050) = 0xe2844001
100 set *((unsigned long *) 0xc0000054) = 0xeafffff7
101 end
102
103 define uart-load
104 uart-fetchcode
105 set $pc = 0xc0000000
106 printf "Ready to download over serial line...\n"
107 c
108 end
109
110
111 define led-on
112 set *((unsigned long *) 0x03ffe600) = 0x00000006
113 set *((unsigned long *) 0x03ffe604) = 0x00000000
114 set *((unsigned long *) 0x03ffe608) = 0x00000006
115
116 end
117
118
119 define mem-init
120 echo  mem-init\n
121 # Set SDCS0 to be 16MB (2*64Mbit devices parallel on 32bit data bus)
122 # This sets it for RAS=2, CAS=3, 4 banks
123 set *((unsigned long *) 0x80060010) = 0x00210028
124 shell sleep 1
125
126 # Set global config to initiate NOPs
127 set *((unsigned long *) 0x80060004) = 0x80000003
128 shell sleep 1
129
130 # Send PRECHARGE-ALL command
131 set *((unsigned long *) 0x80060004) = 0x80000001
132
133 # Enable refresh engine to generate some fast refreshes
134 set *((unsigned long *) 0x80060008) = 0x00000010
135 shell sleep 1
136
137 # Switch refresh engine back to normal
138 set *((unsigned long *) 0x80060008) = 0x00000023
139
140 # Send MODE command
141 set *((unsigned long *) 0x80060004) = 0x80000002
142 set $junk = *((unsigned long *) 0xc0008800)
143 set $junk = *((unsigned long *) 0xc0408800)
144 set $junk = *((unsigned long *) 0xc0808800)
145 set $junk = *((unsigned long *) 0xc0c08800)
146
147 # Set the real value into the global configuration register
148 set *((unsigned long *) 0x80060004) = 0x80000000
149
150 shell sleep 1
151
152 end
153
154 define unlock
155 set *((unsigned char *) 0x809300C0 ) = 0xaa
156 end
157
158 #
159 #       Set the internal PLL clocks
160 #
161 define clk1-init
162 echo  clk1-init\n
163 # load tools/bin/clk
164 # set $pc = 0xc0000000
165 # stepi 9
166 # set * (unsigned long *) 0x80930020 = 0
167 #
168 # Fout = 14.7456MHz
169 # safe settings
170 #
171 set * (unsigned long *) 0x80930020 = 0
172 shell sleep 1
173 end
174
175 define clk2-init
176 echo  clk2-init\n
177 # load tools/bin/clk2
178 # set $pc = 0xc0000000
179 # stepi 9
180 # set * (unsigned long *) 0x80930024 = 0x300dc317
181 #
182 # Fout = 192000000.00
183 # USB  =  48000000.00
184 #
185 set * (unsigned long *) 0x80930024 = 0x300dc317
186 shell sleep 1
187 end
188
189 define dev-init
190 echo  dev-init\n
191 load tools/bin/devcfg
192 set $pc = 0xc0000000
193 stepi 8
194 #
195 # unlock the Syscon lock
196 #
197 # set * (unsigned long *) 0x809300c0 = 0x000000aa
198 #
199 # Uart1En, Uart2En
200
201 # unlock
202 # set * (unsigned long *) 0x80930080 = 0x00140000
203 # shell sleep 1
204 end
205
206 #
207 #       Some simple memory tests.
208 #
209 define mem-fill
210 set $num = 0
211 set $addr = $arg0
212 set $val = $arg1
213 while ($num < 0x1000)
214         set *((unsigned long *) $addr) = $val
215         set $addr = $addr + 4
216         set $num = $num + 1
217 end
218 end
219
220
221 define mem-check
222 set $num = 0
223 set $addr = $arg0
224 set $val = $arg1
225 while ($num < 0x1000)
226         set $rd = *((unsigned long *) $addr)
227         if ($rd != $val)
228                 print $addr
229         end
230         set $addr = $addr + 4
231         set $num = $num + 1
232 end
233 end
234
235 define mem-test
236 set $num = 0
237 #set $total = 0x100000
238 set $total = 0x100
239 set $addr = $arg0
240 set $val = $arg1
241 while ($num < $total)
242         set *((unsigned long *) $addr) = $val
243         set $addr = $addr + 4
244         set $num = $num + 1
245         set $val = $val + 1
246 end
247 set $num = 0
248 set $addr = $arg0
249 set $val = $arg1
250 while ($num < $total)
251         set $rd = *((unsigned long *) $addr)
252         if ($rd != $val)
253                 print $addr
254         end
255         set $addr = $addr + 4
256         set $num = $num + 1
257         set $val = $val + 1
258 end
259 end
260
261
262 define mem-compare
263 set $src1 = $arg0
264 set $src2 = $arg1
265 set $num = 0
266 while ($num < $arg2)
267         set $val1 = *((unsigned long *) $src1)
268         set $val2 = *((unsigned long *) $src2)
269         if ($val1 != $val2)
270                 printf "ERROR: [%x]=%x [%x]=%x\n", $src1, $val1, $src2, $val2
271         end
272         set $src1 = $src1 + 4
273         set $src2 = $src2 + 4
274         set $num = $num + 4
275 end
276 end
277
278
279 #
280 #       FLASH handling code.
281 #
282 define flash-id-8
283 set  * (((unsigned short *) $arg0) + 0x00) = 0xf0
284 set  * (((unsigned short *) $arg0) + 0x55) = 0x98
285 p /x * (((unsigned short *) $arg0) + 0x10)
286 p /x * (((unsigned short *) $arg0) + 0x11)
287 p /x * (((unsigned short *) $arg0) + 0x12)
288 end
289
290 define flash-id-16
291 set  * ((unsigned short *) $arg0 + 0x00) = 0x00f0
292 set  * ((unsigned short *) $arg0 + 0xaa) = 0x0098
293 p /x * ((unsigned short *) $arg0 + 0x20)
294 end
295
296 define flash-erase
297 printf "ERASE: addr=%x", $arg0
298 set *((unsigned char *) $arg0) = 0x20
299 set *((unsigned char *) $arg0) = 0xd0
300 shell sleep 2
301 set *((unsigned char *) $arg0) = 0xff
302 printf "\n"
303 end
304
305
306 define flash-eraseall
307 set $addr = 0
308 while ($addr < 0x400000)
309         flash-erase 0x00000000+$addr
310         set $addr = $addr + 0x20000
311 end
312 end
313
314
315 define flash-eraseimage
316 set $addr = 0x40000
317 while ($addr < 0x400000)
318         flash-erase 0x00000000+$addr
319         set $addr = $addr + 0x20000
320 end
321 end
322
323
324 define flash-eraseboot
325 flash-erase 0x00000000
326 end
327
328
329 define flash-program-byte
330 set *((unsigned char *) $arg0) = 0x40
331 set *((unsigned char *) $arg0) = $arg1
332 set $delay = 0
333 while ($delay < 5)
334         set $val = *((unsigned char *) $arg0)
335         set $delay = $delay + 1
336 end
337 set *((unsigned char *) $arg0) = 0xff
338 end
339
340
341 define flash-program
342 set $num = $arg0
343 set $count = 0
344 set $src = 0xc0000000
345 set $dst = 0x00000000
346 while ($count < $num)
347         set $byte = *((unsigned char *) $src)
348         flash-program-byte $dst $byte
349         set $src = $src + 1
350         set $dst = $dst + 1
351         if (($count & 0x3ff) == 0)
352                 printf "PROGRAMING FLASH: 0x%08x-0x%08x\n", $count, ($count+0x400)
353         end
354         set $count = $count + 1
355 end
356 end
357
358
359 define flash-burncode
360 set *((unsigned long *) 0xc0000000) = 0xe3a01000
361 set *((unsigned long *) 0xc0000004) = 0xe3a05103
362 set *((unsigned long *) 0xc0000008) = 0xe3855a01
363 set *((unsigned long *) 0xc000000c) = 0xe3856902
364 set *((unsigned long *) 0xc0000010) = 0xe3a02040
365 set *((unsigned long *) 0xc0000014) = 0xe3822901
366 set *((unsigned long *) 0xc0000018) = 0xe3a03080
367 set *((unsigned long *) 0xc000001c) = 0xe3a040ff
368 set *((unsigned long *) 0xc0000020) = 0xe3844cff
369 set *((unsigned long *) 0xc0000024) = 0xe1c120b0
370 set *((unsigned long *) 0xc0000028) = 0xe1d570b0
371 set *((unsigned long *) 0xc000002c) = 0xe1c170b0
372 set *((unsigned long *) 0xc0000030) = 0xe1d170b0
373 set *((unsigned long *) 0xc0000034) = 0xe1170003
374 set *((unsigned long *) 0xc0000038) = 0x0afffffc
375 set *((unsigned long *) 0xc000003c) = 0xe1c140b0
376 set *((unsigned long *) 0xc0000040) = 0xe2811002
377 set *((unsigned long *) 0xc0000044) = 0xe2855002
378 set *((unsigned long *) 0xc0000048) = 0xe1550006
379 set *((unsigned long *) 0xc000004c) = 0x1afffff4
380 set *((unsigned long *) 0xc0000050) = 0xe1a00000
381 set *((unsigned long *) 0xc0000054) = 0xe1a00000
382 set *((unsigned long *) 0xc0000058) = 0xeafffffe
383 end
384
385 define swreset
386 set * ((unsigned long *) 0x80940000) = 0x0000aaaa
387 shell sleep 1
388 # set * ((unsigned long *) 0x80930080) = 0x80000000
389 # set * ((unsigned long *) 0x80930080) = 0x00000000
390 end
391
392 #
393 #       Load and program the boot code into flash.
394 #
395 define init
396 # swreset
397 mem-init
398 clk1-init
399 clk2-init
400 # mem-init
401 shell sleep 1
402 dev-init
403 shell sleep 1
404
405 uart2-init
406 uart2-print 0x0a
407 uart2-print 0x0d
408 uart2-print 0x52
409 uart2-print 0x65
410 uart2-print 0x61
411 uart2-print 0x64
412 uart2-print 0x79
413 uart2-print 0x0a
414 uart2-print 0x0d
415 end
416
417 define flash-boot
418 flash-erase 0x00000000
419 shell sleep 1
420 flash-burncode
421 set $pc = 0xc0000000
422 c
423 end
424
425 define flash-memboot
426 # FIXME: this just does not seem to work right...
427 init
428 load boot/boot-ram.elf
429 flash-erase 0x00000000
430 flash-burncode
431 set $pc = 0xc0000000
432 c
433 end
434
435
436 #
437 #       Startup commands...
438 #
439 set output-radix 16
440 set input-radix 16
441
442 target remote localhost:8888
443
444 #set print pretty
445 #set print asm-demangle
446 display/i $pc
447