]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/mx50_arm2/flash_header.S
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / board / freescale / mx50_arm2 / flash_header.S
1 /*
2  * Copyright (C) 2010 Freescale Semiconductor, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17  * MA 02111-1307 USA
18  */
19
20 #include <config.h>
21 #include <asm/arch/mx50.h>
22
23 #ifdef  CONFIG_FLASH_HEADER
24 #ifndef CONFIG_FLASH_HEADER_OFFSET
25 # error "Must define the offset of flash header"
26 #endif
27
28 .section ".text.flasheader", "x"
29         b       _start
30         .org    CONFIG_FLASH_HEADER_OFFSET
31
32 /* First IVT to copy the plugin that initializes the system into OCRAM */
33 ivt_header:        .long 0x402000D1    /* Tag=0xD1, Len=0x0020, Ver=0x40 */
34 app_code_jump_v:   .long 0xF8006458    /* Plugin entry point */
35 reserv1:           .long 0x0
36 dcd_ptr:           .long 0x0
37 boot_data_ptr:     .long 0xF8006420
38 self_ptr:          .long 0xF8006400
39 app_code_csf:      .long 0x0           /* reserve 4K for csf */
40 reserv2:           .long 0x0
41 boot_data:         .long 0xF8006000
42 image_len:         .long 8*1024        /* Can copy upto 72K, OCRAM free space */
43 plugin:            .long 0x1           /* Enable plugin flag */
44
45 /* Second IVT to give entry point into the bootloader copied to DDR */
46 ivt2_header:       .long 0x402000D1    //Tag=0xD1, Len=0x0020, Ver=0x40
47 app2_code_jump_v:  .long _start   // Entry point for the bootloader
48 reserv3:           .long 0x0
49 dcd2_ptr:          .long 0x0
50 boot_data2_ptr:    .long boot_data2
51 self_ptr2:         .long ivt2_header
52 app_code_csf2:     .long 0x0 // reserve 4K for csf
53 reserv4:           .long 0x0
54 boot_data2:        .long TEXT_BASE
55 image_len2:        .long _end - TEXT_BASE
56 plugin2:           .long 0x0
57
58 /*=============================================================================
59  * Here starts the plugin code
60  *===========================================================================*/
61
62 plugin_start:
63 /* Save the return address and the function arguments */
64         push    {r0-r2, lr}
65
66 /*=============================================================================
67  *init script for codex LPDDR1-200MHz CPU board
68  *===========================================================================*/
69
70 /* Setup PLL1 to be 800 MHz */
71         ldr r0, =CCM_BASE_ADDR
72
73 /* Switch ARM domain to be clocked from LP-APM */
74         mov r1, #0x4
75         str r1, [r0, #CLKCTL_CCSR]
76
77         ldr r0, =PLL1_BASE_ADDR
78         ldr r1, =0x1232
79         str r1, [r0, #PLL_DP_CTL]     /* Set DPLL ON (set UPEN bit); BRMO=1 */
80         ldr r1, =0x2
81         str r1, [r0, #PLL_DP_CONFIG]  /* Enable auto-restart AREN bit */
82
83         ldr r1, =DP_OP_800
84         str r1, [r0, #PLL_DP_OP]
85         str r1, [r0, #PLL_DP_HFS_OP]
86
87         ldr r1, =DP_MFD_800
88         str r1, [r0, #PLL_DP_MFD]
89         str r1, [r0, #PLL_DP_HFS_MFD]
90
91         ldr r1, =DP_MFN_800
92         str r1, [r0, #PLL_DP_MFN]
93         str r1, [r0, #PLL_DP_HFS_MFN]
94
95         /* Now restart PLL */
96         ldr r1, =0x1232
97         str r1, [r0, #PLL_DP_CTL]
98 wait_pll1_lock:
99         ldr r1, [r0, #PLL_DP_CTL]
100         ands r1, r1, #0x1
101         beq wait_pll1_lock
102
103 /* Switch ARM back to PLL1 */
104         ldr r0, =CCM_BASE_ADDR
105         ldr r1, =0x0
106         str r1, [r0,#CLKCTL_CCSR]
107
108 /*=============================================================================
109  * Enable all clocks (they are disabled by ROM code)
110  *===========================================================================*/
111
112         mov r1, #0xffffffff
113         str r1, [r0, #0x68]
114         str r1, [r0, #0x6c]
115         str r1, [r0, #0x70]
116         str r1, [r0, #0x74]
117         str r1, [r0, #0x78]
118         str r1, [r0, #0x7c]
119         str r1, [r0, #0x80]
120         str r1, [r0, #0x84]
121
122 #if defined(CONFIG_LPDDR2)
123
124 /* DDR clock setting -- Set DDR to be div 3 to get 266MHz */
125 /* setmem /32 0x53FD4098 = 0x80000003 */
126         ldr r1, =0x80000003
127         str r1, [r0, #0x98]
128
129 /* poll to make sure DDR dividers take effect */
130 1:
131         ldr r1, [r0, #0x8c]
132         ands r1, r1, #0x4
133         bne 1b
134
135 /*=============================================================================
136  * IOMUX
137  *===========================================================================*/
138         ldr r0, =0x53fa8000
139         mov r1, #0x04000000
140         str r1, [r0, #0x6ac]
141         mov r2, #0x00380000
142         str r2, [r0, #0x6a4]
143         str r2, [r0, #0x668]
144         str r2, [r0, #0x698]
145         str r2, [r0, #0x6a0]
146         str r2, [r0, #0x6a8]
147         str r2, [r0, #0x6b4]
148         str r2, [r0, #0x498]
149         str r2, [r0, #0x49c]
150         str r2, [r0, #0x4f0]
151         str r2, [r0, #0x500]
152         str r2, [r0, #0x4c8]
153         str r2, [r0, #0x528]
154         str r2, [r0, #0x4f4]
155         str r2, [r0, #0x4fc]
156         str r2, [r0, #0x4cc]
157         str r2, [r0, #0x524]
158
159 /*=============================================================================
160  * DDR setting
161  *===========================================================================*/
162
163         ldr r0, =DATABAHN_BASE_ADDR
164 /* setmem /32 0x14000000        = 0x00000500 */
165         ldr r1, =0x00000500
166         str r1, [r0, #0x0]
167 /* setmem /32 0x14000004        = 0x00000000 */
168         ldr r1, =0x00000000
169         str r1, [r0, #0x4]
170 /* setmem /32 0x14000008        = 0x0000001b */
171         ldr r1, =0x0000001b
172         str r1, [r0, #0x8]
173 /* setmem /32 0x1400000c        = 0x0000d056 */
174         ldr r1, =0x0000d056
175         str r1, [r0, #0xc]
176 /* setmem /32 0x14000010        = 0x0000010b */
177         ldr r1, =0x0000010b
178         str r1, [r0, #0xc]
179 /* setmem /32 0x14000014        = 0x00000a6b */
180         ldr r1, =0x00000a6b
181         str r1, [r0, #0x14]
182 /* setmem /32 0x14000018        = 0x02020d0c */
183         ldr r1, =0x02020d0c
184         str r1, [r0, #0x18]
185 /* setmem /32 0x1400001c        = 0x0c110302 */
186         ldr r1, =0x0c110302
187         str r1, [r0, #0x1c]
188 /* setmem /32 0x14000020        = 0x05020503 */
189         ldr r1, =0x05020503
190         str r1, [r0, #0x20]
191 /* setmem /32 0x14000024        = 0x00000105 */
192         ldr r1, =0x00000105
193         str r1, [r0, #0x24]
194 /* setmem /32 0x14000028        = 0x01000403 */
195         ldr r1, =0x01000403
196         str r1, [r0, #0x28]
197 /* setmem /32 0x1400002c        = 0x09040501 */
198         ldr r1, =0x09040501
199         str r1, [r0, #0x2c]
200 /* setmem /32 0x14000030        = 0x02000000 */
201         ldr r1, =0x02000000
202         str r1, [r0, #0x30]
203 /* setmem /32 0x14000034        = 0x00000e02 */
204         ldr r1, =0x00000e02
205         str r1, [r0, #0x34]
206 /* setmem /32 0x14000038        = 0x00000006 */
207         ldr r1, =0x00000006
208         str r1, [r0, #0x38]
209 /* setmem /32 0x1400003c        = 0x00002301 */
210         ldr r1, =0x00002301
211         str r1, [r0, #0x3c]
212 /* setmem /32 0x14000040        = 0x00050408 */
213         ldr r1, =0x00050408
214         str r1, [r0, #0x40]
215 /* setmem /32 0x14000044        = 0x00000300 */
216         ldr r1, =0x00000300
217         str r1, [r0, #0x44]
218 /* setmem /32 0x14000048        = 0x00260026 */
219         ldr r1, =0x00260026
220         str r1, [r0, #0x48]
221 /* setmem /32 0x1400004c        = 0x00010000 */
222         ldr r1, =0x00010000
223         str r1, [r0, #0x4c]
224 /* setmem /32 0x1400005c        = 0x02000000 */
225         ldr r1, =0x02000000
226         str r1, [r0, #0x5c]
227 /* setmem /32 0x14000060        = 0x00000002 */
228         ldr r1, =0x00000002
229         str r1, [r0, #0x60]
230 /* setmem /32 0x14000064        = 0x00000000 */
231         ldr r1, =0x00000000
232         str r1, [r0, #0x64]
233 /* setmem /32 0x14000068        = 0x00000000 */
234         ldr r1, =0x00000000
235         str r1, [r0, #0x68]
236 /* setmem /32 0x1400006c        = 0x00040042 */
237         ldr r1, =0x00040042
238         str r1, [r0, #0x6c]
239 /* setmem /32 0x14000070        = 0x00000001 */
240         ldr r1, =0x00000001
241         str r1, [r0, #0x70]
242 /* setmem /32 0x14000074        = 0x00000000 */
243         ldr r1, =0x00000001
244         str r1, [r0, #0x74]
245 /* setmem /32 0x14000078        = 0x00040042 */
246         ldr r1, =0x00040042
247         str r1, [r0, #0x78]
248 /* setmem /32 0x1400007c        = 0x00000001 */
249         ldr r1, =0x00000001
250         str r1, [r0, #0x7c]
251 /* setmem /32 0x14000080        = 0x010b0000 */
252         ldr r1, =0x010b0000
253         str r1, [r0, #0x80]
254 /* setmem /32 0x14000084        = 0x00000060 */
255         ldr r1, =0x00000060
256         str r1, [r0, #0x84]
257 /* setmem /32 0x14000088        = 0x02400018 */
258         ldr r1, =0x02400018
259         str r1, [r0, #0x88]
260 /* setmem /32 0x1400008c        = 0x01000e00 */
261         ldr r1, =0x01000e00
262         str r1, [r0, #0x8c]
263 /* setmem /32 0x14000090        = 0x0a010101 */
264         ldr r1, =0x0a010101
265         str r1, [r0, #0x90]
266 /* setmem /32 0x14000094        = 0x01011f1f */
267         ldr r1, =0x01011f1f
268         str r1, [r0, #0x94]
269 /* setmem /32 0x14000098        = 0x01010101 */
270         ldr r1, =0x01010101
271         str r1, [r0, #0x98]
272 /* setmem /32 0x1400009c        = 0x00030101 */
273         ldr r1, =0x00030101
274         str r1, [r0, #0x9c]
275 /* setmem /32 0x140000a0        = 0x00010000 */
276         ldr r1, =0x00010000
277         str r1, [r0, #0xa0]
278 /* setmem /32 0x140000a4        = 0x00010000 */
279         ldr r1, =0x00010000
280         str r1, [r0, #0xa4]
281 /* setmem /32 0x140000a8        = 0x00000000 */
282         ldr r1, =0x00000000
283         str r1, [r0, #0xa8]
284 /* setmem /32 0x140000ac        = 0x0000ffff */
285         ldr r1, =0x0000ffff
286         str r1, [r0, #0xac]
287 /* setmem /32 0x140000c8        = 0x02020101 */
288         ldr r1, =0x02020101
289         str r1, [r0, #0xc8]
290 /* setmem /32 0x140000cc        = 0x01000000 */
291         ldr r1, =0x01000000
292         str r1, [r0, #0xcc]
293 /* setmem /32 0x140000d0        = 0x01000201 */
294         ldr r1, =0x01000201
295         str r1, [r0, #0xd0]
296 /* setmem /32 0x140000d4        = 0x00000200 */
297         ldr r1, =0x00000200
298         str r1, [r0, #0xd4]
299 /* setmem /32 0x140000d8        = 0x00000102 */
300         ldr r1, =0x00000102
301         str r1, [r0, #0xd8]
302 /* setmem /32 0x140000dc        = 0x0000ffff */
303         ldr r1, =0x0000ffff
304         str r1, [r0, #0xdc]
305 /* setmem /32 0x140000e0        = 0x0000ffff */
306         ldr r1, =0x0000ffff
307         str r1, [r0, #0xdc]
308 /* setmem /32 0x140000e4        = 0x02020000 */
309         ldr r1, =0x02020000
310         str r1, [r0, #0xe4]
311 /* setmem /32 0x140000e8        = 0x02020202 */
312         ldr r1, =0x02020202
313         str r1, [r0, #0xe8]
314 /* setmem /32 0x140000ec        = 0x00000202 */
315         ldr r1, =0x00000202
316         str r1, [r0, #0xec]
317 /* setmem /32 0x140000f0        = 0x01010064 */
318         ldr r1, =0x01010064
319         str r1, [r0, #0xf0]
320 /* setmem /32 0x140000f4        = 0x01010101 */
321         ldr r1, =0x01010101
322         str r1, [r0, #0xf4]
323 /* setmem /32 0x140000f8        = 0x00010101 */
324         ldr r1, =0x00010101
325         str r1, [r0, #0xf8]
326 /* setmem /32 0x140000fc        = 0x00000064 */
327         ldr r1, =0x00000064
328         str r1, [r0, #0xfc]
329 /* setmem /32 0x14000100        = 0x00000000 */
330         ldr r1, =0x00000000
331         str r1, [r0, #0x100]
332 /* setmem /32 0x14000104        = 0x02000802 */
333         ldr r1, =0x02000802
334         str r1, [r0, #0x104]
335 /* setmem /32 0x14000108        = 0x04080000 */
336         ldr r1, =0x04080000
337         str r1, [r0, #0x108]
338 /* setmem /32 0x1400010c        = 0x04080408 */
339         ldr r1, =0x04080408
340         str r1, [r0, #0x10c]
341 /* setmem /32 0x14000110        = 0x04080408 */
342         ldr r1, =0x04080408
343         str r1, [r0, #0x110]
344 /* setmem /32 0x14000114        = 0x03060408 */
345         ldr r1, =0x03060408
346         str r1, [r0, #0x114]
347 /* setmem /32 0x14000118        = 0x01010002 */
348         ldr r1, =0x01010002
349         str r1, [r0, #0x118]
350 /* setmem /32 0x1400011c        = 0x00000000 */
351         ldr r1, =0x00000000
352         str r1, [r0, #0x11c]
353 /* setmem /32 0x14000200        = 0x00000000 */
354         ldr r1, =0x00000000
355         str r1, [r0, #0x200]
356 /* setmem /32 0x14000204        = 0x00000000 */
357         ldr r1, =0x00000000
358         str r1, [r0, #0x204]
359 /* setmem /32 0x14000208        = 0xf5003a27 */
360         ldr r1, =0xf5003a27
361         str r1, [r0, #0x208]
362 /* setmem /32 0x1400020c        = 0x074002e1 */
363         ldr r1, =0x074002e1
364         str r1, [r0, #0x20c]
365 /* setmem /32 0x14000210        = 0xf5003a27 */
366         ldr r1, =0xf5003a27
367         str r1, [r0, #0x210]
368 /* setmem /32 0x14000214        = 0x074002e1 */
369         ldr r1, =0x074002e1
370         str r1, [r0, #0x214]
371 /* setmem /32 0x14000218        = 0xf5003a27 */
372         ldr r1, =0xf5003a27
373         str r1, [r0, #0x218]
374 /* setmem /32 0x1400021c        = 0x074002e1 */
375         ldr r1, =0x074002e1
376         str r1, [r0, #0x21c]
377 /* setmem /32 0x14000220        = 0xf5003a27 */
378         ldr r1, =0xf5003a27
379         str r1, [r0, #0x220]
380 /* setmem /32 0x14000224        = 0x074002e1 */
381         ldr r1, =0x074002e1
382         str r1, [r0, #0x224]
383 /* setmem /32 0x14000228        = 0xf5003a27 */
384         ldr r1, =0xf5003a27
385         str r1, [r0, #0x228]
386 /* setmem /32 0x1400022c        = 0x074002e1 */
387         ldr r1, =0x074002e1
388         str r1, [r0, #0x22c]
389 /* setmem /32 0x14000230        = 0x00000000 */
390         ldr r1, =0x00000000
391         str r1, [r0, #0x230]
392 /* setmem /32 0x14000234        = 0x00810006 */
393         ldr r1, =0x00810006
394         str r1, [r0, #0x234]
395 /* setmem /32 0x14000238        = 0x20099414 */
396         ldr r1, =0x20099414
397         str r1, [r0, #0x238]
398 /* setmem /32 0x1400023c        = 0x000a1401 */
399         ldr r1, =0x000a1401
400         str r1, [r0, #0x23c]
401 /* setmem /32 0x14000240        = 0x20099414 */
402         ldr r1, =0x20099414
403         str r1, [r0, #0x240]
404 /* setmem /32 0x14000244        = 0x000a1401 */
405         ldr r1, =0x000a1401
406         str r1, [r0, #0x244]
407 /* setmem /32 0x14000248        = 0x20099414 */
408         ldr r1, =0x20099414
409         str r1, [r0, #0x248]
410 /* setmem /32 0x1400024c        = 0x000a1401 */
411         ldr r1, =0x000a1401
412         str r1, [r0, #0x24c]
413 /* setmem /32 0x14000250        = 0x20099414 */
414         ldr r1, =0x20099414
415         str r1, [r0, #0x250]
416 /* setmem /32 0x14000254        = 0x000a1401 */
417         ldr r1, =0x000a1401
418         str r1, [r0, #0x254]
419 /* setmem /32 0x14000258        = 0x20099414 */
420         ldr r1, =0x000a1401
421         str r1, [r0, #0x258]
422 /* setmem /32 0x1400025c        = 0x000a1401 */
423         ldr r1, =0x000a1401
424         str r1, [r0, #0x25c]
425
426 /* Start ddr */
427 /* setmem /32 0x14000000 = 0x00000501  // bit[0]: start */
428         ldr r1, =0x00000501
429         str r1, [r0, #0x0]
430 /* poll to make sure it is done */
431 1:
432         ldr r1, [r0, #0xa8]
433         ands r1, r1, #0x10
434         beq 1b
435 #else
436
437 /*==================================================================
438  * lpddr1-mddr
439  *=================================================================*/
440
441 /* DDR clock setting -- Set DDR to be div 4 to get 200MHz */
442 /* setmem /32 0x53FD4098 = 0x80000004 */
443         ldr r1, =0x80000004
444         str r1, [r0, #0x98]
445
446 /* poll to make sure DDR dividers take effect */
447 1:
448     ldr r1, [r0, #0x8c]
449     ands r1, r1, #0x4
450     bne 1b
451
452 /*==================================================================
453  * IOMUX
454  *=================================================================*/
455         ldr r0, =0x53fa8600
456         mov r1, #0x02000000
457         mov r3, #0x00200000
458         mov r2, #0x0
459         str r1, [r0, #0xac]
460         str r2, [r0, #0x6c]
461         str r2, [r0, #0x8c]
462         str r3, [r0, #0xa4]
463         str r3, [r0, #0x68]
464         str r3, [r0, #0x98]
465         str r3, [r0, #0xa0]
466         str r3, [r0, #0xa8]
467         str r3, [r0, #0xb4]
468
469         ldr r0, =0x53fa8400
470         str r3, [r0, #0x98]
471         str r3, [r0, #0x9c]
472         str r3, [r0, #0xf0]
473         str r3, [r0, #0x100]
474         str r3, [r0, #0xc8]
475         str r3, [r0, #0x128]
476         str r3, [r0, #0xf4]
477         str r3, [r0, #0xfc]
478         str r3, [r0, #0xcc]
479         str r3, [r0, #0x124]
480         str r2, [r0, #0x270]
481
482 /*==============================================================
483  *  DDR setting
484  *=============================================================*/
485         ldr r0, =DATABAHN_BASE_ADDR
486 /* setmem /32 0x14000000 = 0x00000100 */
487         ldr r1, =0x00000100
488         str r1, [r0, #0x0]
489 /* setmem /32 0x14000008 = 0x00009c40 */
490         ldr r1, =0x00009c40
491         str r1, [r0, #0x8]
492 /* setmem /32 0x14000014 = 0x02000000 */
493         ldr r1, =0x02000000
494         str r1, [r0, #0x14]
495 /* setmem /32 0x14000018 = 0x01010706 */
496         ldr r1, =0x01010706
497         str r1, [r0, #0x018]
498 /* setmem /32 0x1400001c = 0x080b0201 */
499         ldr r1, =0x080b0201
500         str r1, [r0, #0x01c]
501 /* setmem /32 0x14000020 = 0x02000303 */
502         ldr r1, =0x02000303
503         str r1, [r0, #0x020]
504 /* setmem /32 0x14000024 = 0x0136b002 */
505         ldr r1, =0x0136b002
506         str r1, [r0, #0x024]
507 /* setmem /32 0x14000028 = 0x01000101 */
508         ldr r1, =0x01000101
509         str r1, [r0, #0x028]
510 /* setmem /32 0x1400002c = 0x06030301 */
511         ldr r1, =0x06030301
512         str r1, [r0, #0x02c]
513 /* setmem /32 0x14000030 = 0x00000000 */
514         ldr r1, =0x00000000
515         str r1, [r0, #0x030]
516 /* setmem /32 0x14000034 = 0x00000a02 */
517         ldr r1, =0x00000a02
518         str r1, [r0, #0x034]
519 /* setmem /32 0x14000038 = 0x00000003 */
520         ldr r1, =0x00000003
521         str r1, [r0, #0x038]
522 /* setmem /32 0x1400003c = 0x00001401 */
523         ldr r1, =0x00001401
524         str r1, [r0, #0x03c]
525 /* setmem /32 0x14000040 = 0x0005030f */
526         ldr r1, =0x0005030f
527         str r1, [r0, #0x040]
528 /* setmem /32 0x14000044 = 0x00000200 */
529         ldr r1, =0x00000200
530         str r1, [r0, #0x044]
531 /* setmem /32 0x14000048 = 0x00180018 */
532         ldr r1, =0x00180018
533         str r1, [r0, #0x048]
534 /* setmem /32 0x1400004c = 0x00010000 */
535         ldr r1, =0x00010000
536         str r1, [r0, #0x04c]
537 /* setmem /32 0x1400005c = 0x01000000 */
538         ldr r1, =0x01000000
539         str r1, [r0, #0x05c]
540 /* setmem /32 0x14000060 = 0x00000001 */
541         ldr r1, =0x00000001
542         str r1, [r0, #0x060]
543 /* setmem /32 0x14000064 = 0x00000000 */
544         ldr r1, =0x00000000
545         str r1, [r0, #0x064]
546 /* setmem /32 0x14000068 = 0x00320000 */
547         ldr r1, =0x00320000
548         str r1, [r0, #0x068]
549 /* setmem /32 0x1400006c = 0x00000000 */
550         ldr r1, =0x00000000
551         str r1, [r0, #0x06c]
552 /* setmem /32 0x14000070 = 0x00000000 */
553         ldr r1, =0x00000000
554         str r1, [r0, #0x070]
555 /* setmem /32 0x14000074 = 0x00320000 */
556         ldr r1, =0x00320000
557         str r1, [r0, #0x074]
558 /* setmem /32 0x14000080 = 0x02000000 */
559         ldr r1, =0x02000000
560         str r1, [r0, #0x080]
561 /* setmem /32 0x14000084 = 0x00000100 */
562         ldr r1, =0x00000100
563         str r1, [r0, #0x084]
564 /* setmem /32 0x14000088 = 0x02400040 */
565         ldr r1, =0x02400040
566         str r1, [r0, #0x088]
567 /* setmem /32 0x1400008c = 0x01000000 */
568         ldr r1, =0x01000000
569         str r1, [r0, #0x08c]
570 /* setmem /32 0x14000090 = 0x0a000100 */
571         ldr r1, =0x0a000100
572         str r1, [r0, #0x090]
573 /* setmem /32 0x14000094 = 0x01011f1f */
574         ldr r1, =0x01011f1f
575         str r1, [r0, #0x094]
576 /* setmem /32 0x14000098 = 0x01010101 */
577         ldr r1, =0x01010101
578         str r1, [r0, #0x098]
579 /* setmem /32 0x1400009c = 0x00030101 */
580         ldr r1, =0x00030101
581         str r1, [r0, #0x09c]
582 /* setmem /32 0x140000a4 = 0x00010000 */
583         ldr r1, =0x00010000
584         str r1, [r0, #0x0a4]
585 /* setmem /32 0x140000ac = 0x0000ffff */
586         ldr r1, =0x0000ffff
587         str r1, [r0, #0x0ac]
588 /* setmem /32 0x140000c8 = 0x02020101 */
589         ldr r1, =0x02020101
590         str r1, [r0, #0x0c8]
591 /* setmem /32 0x140000cc = 0x00000000 */
592         ldr r1, =0x00000000
593         str r1, [r0, #0x0cc]
594 /* setmem /32 0x140000d0 = 0x01000202 */
595         ldr r1, =0x01000202
596         str r1, [r0, #0x0d0]
597 /* setmem /32 0x140000d4 = 0x02030302 */
598         ldr r1, =0x02030302
599         str r1, [r0, #0x0d4]
600 /*  setmem /32 0x140000d8 = 0x00000001 */
601         ldr r1, =0x00000001
602         str r1, [r0, #0x0d8]
603 /* setmem /32 0x140000dc = 0x0000ffff */
604         ldr r1, =0x0000ffff
605         str r1, [r0, #0x0dc]
606 /* setmem /32 0x140000e0 = 0x0000ffff */
607         ldr r1, =0x0000ffff
608         str r1, [r0, #0x0e0]
609 /* setmem /32 0x140000e4 = 0x02020000 */
610         ldr r1, =0x02020000
611         str r1, [r0, #0x0e4]
612 /* setmem /32 0x140000e8 = 0x02020202 */
613         ldr r1, =0x02020202
614         str r1, [r0, #0x0e8]
615 /* setmem /32 0x140000ec = 0x00000202 */
616         ldr r1, =0x00000202
617         str r1, [r0, #0x0ec]
618 /* setmem /32 0x140000f0 = 0x01010064 */
619         ldr r1, =0x01010064
620         str r1, [r0, #0x0f0]
621 /* setmem /32 0x140000f4 = 0x01010101 */
622         ldr r1, =0x01010101
623         str r1, [r0, #0x0f4]
624 /* setmem /32 0x140000f8 = 0x00010101 */
625         ldr r1, =0x00010101
626         str r1, [r0, #0x0f8]
627 /* setmem /32 0x140000fc = 0x00000064 */
628         ldr r1, =0x00000064
629         str r1, [r0, #0x0fc]
630 /* setmem /32 0x14000104 = 0x02000602 */
631         ldr r1, =0x02000602
632         str r1, [r0, #0x0104]
633 /* setmem /32 0x14000108 = 0x06120000 */
634         ldr r1, =0x06120000
635         str r1, [r0, #0x0108]
636 /* setmem /32 0x1400010c = 0x06120612 */
637         ldr r1, =0x06120612
638         str r1, [r0, #0x010c]
639 /* setmem /32 0x14000110 = 0x06120612 */
640         ldr r1, =0x06120612
641         str r1, [r0, #0x0110]
642 /* setmem /32 0x14000114 = 0x01030612 */
643         ldr r1, =0x01030612
644         str r1, [r0, #0x0114]
645 /* setmem /32 0x14000118 = 0x01010002 */
646         ldr r1, =0x01010002
647         str r1, [r0, #0x0118]
648
649 /*=============================================================
650  *  DDR PHY setting
651  *===========================================================*/
652
653 /* setmem /32 0x14000200 = 0x00000000 */
654         ldr r1, =0x00000000
655         str r1, [r0, #0x200]
656 /* setmem /32 0x14000204 = 0x00000000 */
657         ldr r1, =0x00000000
658         str r1, [r0, #0x0204]
659
660 /* setmem /32 0x14000208 = 0xf5002725 */
661         ldr r1, =0xf5002725
662         str r1, [r0, #0x0208]
663 /* setmem /32 0x14000210 = 0xf5002725 */
664         ldr r1, =0xf5002725
665         str r1, [r0, #0x210]
666 /* setmem /32 0x14000218 = 0xf5002725 */
667         ldr r1, =0xf5002725
668         str r1, [r0, #0x218]
669 /* setmem /32 0x14000220 = 0xf5002725 */
670         ldr r1, =0xf5002725
671         str r1, [r0, #0x0220]
672 /* setmem /32 0x14000228 = 0xf5002725 */
673         ldr r1, =0xf5002725
674         str r1, [r0, #0x0228]
675
676 /* setmem /32 0x1400020c = 0x070002d0 */
677         ldr r1, =0x070002d0
678         str r1, [r0, #0x020c]
679
680 /* setmem /32 0x14000214 = 0x074002d0 */
681         ldr r1, =0x074002d0
682         str r1, [r0, #0x0214]
683
684 /* setmem /32 0x1400021c = 0x074002d0 */
685         ldr r1, =0x074002d0
686         str r1, [r0, #0x021c]
687
688 /* setmem /32 0x14000224 = 0x074002d0 */
689         ldr r1, =0x074002d0
690         str r1, [r0, #0x0224]
691
692 /* setmem /32 0x1400022c = 0x074002d0 */
693         ldr r1, =0x074002d0
694         str r1, [r0, #0x022c]
695 /* setmem /32 0x14000230 = 0x00000000 */
696         ldr r1, =0x00000000
697         str r1, [r0, #0x0230]
698 /* setmem /32 0x14000234 = 0x00800006 */
699         ldr r1, =0x00800006
700         str r1, [r0, #0x0234]
701
702 /* setmem /32 0x14000238 = 0x200e1014 */
703         ldr r1, =0x200e1014
704         str r1, [r0, #0x0238]
705 /* setmem /32 0x14000240 = 0x200e1014 */
706         ldr r1, =0x200e1014
707         str r1, [r0, #0x0240]
708 /* setmem /32 0x14000248 = 0x200e1014 */
709         ldr r1, =0x200e1014
710         str r1, [r0, #0x0248]
711 /* setmem /32 0x14000250 = 0x200e1014 */
712         ldr r1, =0x200e1014
713         str r1, [r0, #0x0250]
714 /* setmem /32 0x14000258 = 0x200e1014 */
715         ldr r1, =0x200e1014
716         str r1, [r0, #0x0258]
717
718 /* setmem /32 0x1400023c = 0x000d9f01 */
719         ldr r1, =0x000d9f01
720         str r1, [r0, #0x023c]
721 /* setmem /32 0x14000244 = 0x000d9f01 */
722         ldr r1, =0x000d9f01
723         str r1, [r0, #0x0244]
724 /* setmem /32 0x1400024c = 0x000d9f01 */
725         ldr r1, =0x000d9f01
726         str r1, [r0, #0x024c]
727 /* setmem /32 0x14000254 = 0x000d9f01 */
728         ldr r1, =0x000d9f01
729         str r1, [r0, #0x0254]
730 /* setmem /32 0x1400025c = 0x000d9f01 */
731         ldr r1, =0x000d9f01
732         str r1, [r0, #0x025c]
733
734 /* Start ddr */
735 /* setmem /32 0x14000000 = 0x00000101  // bit[0]: start */
736         ldr r1, =0x00000101
737         str r1, [r0, #0x0]
738 /* poll to make sure it is done */
739 1:
740         ldr r1, [r0, #0xa8]
741         ands r1, r1, #0x10
742         beq 1b
743
744 #endif
745
746 /*
747  * The following is to fill in those arguments for this ROM function
748  * pu_irom_hwcnfg_setup(void **start, size_t *bytes, const void *boot_data)
749  *
750  * This function is used to copy data from the storage media into DDR.
751
752  * start - Initial (possibly partial) image load address on entry.
753  * Final image load address on exit.
754  * bytes - Initial (possibly partial) image size on entry.
755  * Final image size on exit.
756  * boot_data - Initial @ref ivt Boot Data load address.
757  */
758         adr r0, DDR_DEST_ADDR
759         adr r1, COPY_SIZE
760         adr r2, BOOT_DATA
761
762 before_calling_rom___pu_irom_hwcnfg_setup:
763         mov r4, #0x2a00
764         add r4, r4, #0x19
765         blx r4 // This address might change in future ROM versions
766 after_calling_rom___pu_irom_hwcnfg_setup:
767
768
769 /* To return to ROM from plugin, we need to fill in these argument.
770  * Here is what need to do:
771  * Need to construct the paramters for this function before return to ROM:
772  * plugin_download(void **start, size_t *bytes, UINT32 *ivt_offset)
773  */
774         pop {r0-r2, lr}
775         ldr r3, DDR_DEST_ADDR
776         str r3, [r0]
777         ldr r3, COPY_SIZE
778         str r3, [r1]
779         mov r3, #0x400  /* Point to the second IVT table at offset 0x42C */
780         add r3, r3, #0x2C
781         str r3, [r2]
782         mov r0, #1
783         bx lr          /* return back to ROM code */
784
785 DDR_DEST_ADDR:    .word   0x77800000
786 COPY_SIZE:        .word   0x40000
787 BOOT_DATA:        .word   0x77800000
788                   .word   0x40000 /*data be copied by pu_irom_hwcnfg_setup()*/
789                   .word   0
790
791 #endif