summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-02-08 02:20:05 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-02-08 02:20:05 +0000
commita07c034de77e9159cf5d9501c75ea1f0165b6a13 (patch)
tree4a563faa46f15d67787759e66fa578a6da65273e
parent7667a865ff06565a2a7f91ccde0120cd2e0c977e (diff)
downloadrockbox-a07c034de77e9159cf5d9501c75ea1f0165b6a13.tar.gz
rockbox-a07c034de77e9159cf5d9501c75ea1f0165b6a13.zip
Gigabeat S: Interrupt enabled bootloader. Miscellaneous integration changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16243 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/gigabeat-s.c19
-rw-r--r--firmware/app.lds3
-rw-r--r--firmware/boot.lds104
-rwxr-xr-xfirmware/export/imx31l.h6
-rw-r--r--firmware/export/kernel.h2
-rw-r--r--firmware/kernel.c7
-rw-r--r--firmware/system.c6
-rw-r--r--firmware/target/arm/imx31/crt0.S236
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/avic-imx31.c26
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/avic-imx31.h4
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c32
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-imx31.c14
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-target.h14
-rwxr-xr-xtools/configure2
-rw-r--r--tools/scramble.c2
15 files changed, 283 insertions, 194 deletions
diff --git a/bootloader/gigabeat-s.c b/bootloader/gigabeat-s.c
index a4e6391c7e..f3e2917131 100644
--- a/bootloader/gigabeat-s.c
+++ b/bootloader/gigabeat-s.c
@@ -52,16 +52,27 @@ char buf[MAX_PATH];
52char basedir[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */ 52char basedir[] = "/Content/0b00/00/"; /* Where files sent via MTP are stored */
53char model[5]; 53char model[5];
54int (*kernel_entry)(void); 54int (*kernel_entry)(void);
55extern void reference_system_c(void);
56
57/* Dummy stub that creates C references for C functions only used by
58 assembly - never called */
59void reference_files(void)
60{
61 reference_system_c();
62}
55 63
56void main(void) 64void main(void)
57{ 65{
58 lcd_clear_display(); 66 lcd_clear_display();
59 printf("Hello world!"); 67 printf("Hello world!");
60 printf("Gigabeat S Rockbox Bootloader v.00000002"); 68 printf("Gigabeat S Rockbox Bootloader v.00000003");
69 system_init();
61 kernel_init(); 70 kernel_init();
62 printf("kernel init done"); 71 printf("kernel init done");
63 int rc; 72 int rc;
64 73
74 set_interrupt_status(IRQ_FIQ_ENABLED, IRQ_FIQ_STATUS);
75
65 rc = ata_init(); 76 rc = ata_init();
66 if(rc) 77 if(rc)
67 { 78 {
@@ -109,11 +120,13 @@ void main(void)
109 printf("Loading firmware"); 120 printf("Loading firmware");
110 121
111 unsigned char *loadbuffer = (unsigned char *)0x0; 122 unsigned char *loadbuffer = (unsigned char *)0x0;
112 int buffer_size = 1024*1024; 123 int buffer_size = 31*1024*1024;
113 124
114 rc = load_firmware(loadbuffer, buf, buffer_size); 125 rc = load_firmware(loadbuffer, buf, buffer_size);
115 if(rc < 0) 126 if(rc < 0)
116 error(buf, rc); 127 error((int)buf, rc);
128
129 system_prepare_fw_start();
117 130
118 if (rc == EOK) 131 if (rc == EOK)
119 { 132 {
diff --git a/firmware/app.lds b/firmware/app.lds
index 7fabf3563b..d2a9582a3d 100644
--- a/firmware/app.lds
+++ b/firmware/app.lds
@@ -41,7 +41,8 @@ INPUT(target/sh/crt0.o)
41#define DRAMSIZE (MEMORYSIZE * 0x100000) - 0x100 - PLUGINSIZE - STUBOFFSET - CODECSIZE - LCD_BUFFER_SIZE - TTB_SIZE 41#define DRAMSIZE (MEMORYSIZE * 0x100000) - 0x100 - PLUGINSIZE - STUBOFFSET - CODECSIZE - LCD_BUFFER_SIZE - TTB_SIZE
42#elif CONFIG_CPU==IMX31L 42#elif CONFIG_CPU==IMX31L
43#include "imx31l.h" 43#include "imx31l.h"
44#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE - TTB_SIZE 44/* Subtract 1MB for the FRAME/TTB section */
45#define DRAMSIZE (MEMORYSIZE * 0x100000 - 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE
45#elif CONFIG_CPU==DM320 46#elif CONFIG_CPU==DM320
46#include "dm320.h" 47#include "dm320.h"
47#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE - LCD_BUFFER_SIZE - TTB_SIZE 48#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE - LCD_BUFFER_SIZE - TTB_SIZE
diff --git a/firmware/boot.lds b/firmware/boot.lds
index c0f19bc430..fc876b1d20 100644
--- a/firmware/boot.lds
+++ b/firmware/boot.lds
@@ -80,7 +80,10 @@ INPUT(target/sh/crt0.o)
80#define FLASHORIG 0x001f0000 80#define FLASHORIG 0x001f0000
81#define FLASHSIZE 2M 81#define FLASHSIZE 2M
82#elif CONFIG_CPU == IMX31L 82#elif CONFIG_CPU == IMX31L
83#define DRAMORIG 0x80000000 83#define DRAMORIG (0x02000000-0x00100000)
84#undef DRAMSIZE
85#define DRAMSIZE (1 << 20) /* Limit 1 MB for bootloader */
86#define IRAM DRAM
84#define IRAMORIG 0x1FFFC000 87#define IRAMORIG 0x1FFFC000
85#define IRAMSIZE 16K 88#define IRAMSIZE 16K
86#define FLASHORIG 0x0000000 89#define FLASHORIG 0x0000000
@@ -115,7 +118,12 @@ MEMORY
115#endif 118#endif
116 IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE 119 IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE
117} 120}
118#elif !defined(CPU_PP) && (CONFIG_CPU!=S3C2440) && (CONFIG_CPU!=IMX31L) 121#elif CONFIG_CPU == IMX31L
122MEMORY
123{
124 DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
125}
126#elif !defined(CPU_PP) && (CONFIG_CPU!=S3C2440)
119MEMORY 127MEMORY
120{ 128{
121 DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE 129 DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
@@ -302,48 +310,66 @@ SECTIONS
302} 310}
303#elif (CONFIG_CPU==IMX31L) 311#elif (CONFIG_CPU==IMX31L)
304{ 312{
305#if 0 313 . = DRAMORIG;
314
315 .text :
316 {
317 *(.init.text)
318 *(.text*)
319 *(.icode)
320 *(.glue_7)
321 *(.glue_7t)
322 . = ALIGN(0x4);
323 } > DRAM
324
325 .rodata :
326 {
327 *(.rodata) /* problems without this, dunno why */
328 *(.rodata*)
329 *(.rodata.str1.1)
330 *(.rodata.str1.4)
331 . = ALIGN(0x4);
332
333 /* Pseudo-allocate the copies of the data sections */
334 _datacopy = .;
335 } > DRAM
336
337 .data :
338 {
339 *(.irodata)
340 *(.idata)
341 *(.data*)
342 . = ALIGN(0x4);
343 _dataend = . ;
344 } > DRAM
345
346 .stack :
347 {
348 *(.stack)
349 _stackbegin = .;
350 stackbegin = .;
351 . += 0x2000;
352 _stackend = .;
353 stackend = .;
354 } > IRAM
355
356 .bss :
357 {
358 _edata = .;
359 *(.bss*);
360 *(.ibss);
361 *(COMMON)
362 _end = .;
363 } > DRAM
364
306 .vectors 0x0 : 365 .vectors 0x0 :
307 { 366 {
308 _vectorsstart = .; 367 _vectorsstart = .;
309 *(.vectors); 368 *(.vectors);
369 KEEP(*(.vectors));
310 _vectorsend = .; 370 _vectorsend = .;
311 } AT> DRAM 371 } AT > DRAM
312#endif 372 _vectorscopy = LOADADDR(.vectors);
313 . = 0x82000000;
314
315 .text :
316 {
317 *(.init.text)
318 *(.text*)
319 }
320
321 .data :
322 {
323 *(.icode)
324 *(.irodata)
325 *(.idata)
326 *(.data*)
327 _dataend = . ;
328 }
329
330 .stack :
331 {
332 *(.stack)
333 _stackbegin = .;
334 stackbegin = .;
335 . += 0x2000;
336 _stackend = .;
337 stackend = .;
338 }
339
340 .bss :
341 {
342 _edata = .;
343 *(.bss*);
344 *(.ibss);
345 _end = .;
346 }
347} 373}
348#else 374#else
349{ 375{
diff --git a/firmware/export/imx31l.h b/firmware/export/imx31l.h
index 1712a5b8f2..b1f35e80f2 100755
--- a/firmware/export/imx31l.h
+++ b/firmware/export/imx31l.h
@@ -23,7 +23,8 @@
23#define REG16_PTR_T volatile unsigned short * 23#define REG16_PTR_T volatile unsigned short *
24#define REG32_PTR_T volatile unsigned long * 24#define REG32_PTR_T volatile unsigned long *
25 25
26#define TTB_BASE_ADDR (0x80000000 + (64*1024*1024)-TTB_SIZE) 26/* Place in the section with the framebuffer */
27#define TTB_BASE_ADDR (0x80100000 + 0x00100000 - TTB_SIZE)
27#define IRAM_BASE_ADDR 0x1fffc000 28#define IRAM_BASE_ADDR 0x1fffc000
28#define L2CC_BASE_ADDR 0x30000000 29#define L2CC_BASE_ADDR 0x30000000
29 30
@@ -275,6 +276,7 @@
275#define INTENABLEL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x14)) 276#define INTENABLEL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x14))
276#define INTTYPEH (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x18)) 277#define INTTYPEH (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x18))
277#define INTTYPEL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x1C)) 278#define INTTYPEL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x1C))
279#define NIPRIORITY(n) (((REG32_PTR_T)(AVIC_BASE_ADDR+0x20))[n])
278#define NIPRIORITY7 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x20)) 280#define NIPRIORITY7 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x20))
279#define NIPRIORITY6 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x24)) 281#define NIPRIORITY6 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x24))
280#define NIPRIORITY5 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x28)) 282#define NIPRIORITY5 (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x28))
@@ -294,7 +296,7 @@
294#define FIPNDH (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x60)) 296#define FIPNDH (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x60))
295#define FIPNDL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x64)) 297#define FIPNDL (*(REG32_PTR_T)(AVIC_BASE_ADDR+0x64))
296#define VECTOR_BASE_ADDR (AVIC_BASE_ADDR+0x100) 298#define VECTOR_BASE_ADDR (AVIC_BASE_ADDR+0x100)
297#define VECTOR(n) (*(REG32_PTR_T)(VECTOR_BASE_ADDR+((n)*4))) 299#define VECTOR(n) (((REG32_PTR_T)VECTOR_BASE_ADDR)[n])
298 300
299/* The vectors go all the way up to 63. 4 bytes for each */ 301/* The vectors go all the way up to 63. 4 bytes for each */
300#define INTCNTL_ABFLAG (1 << 25) 302#define INTCNTL_ABFLAG (1 << 25)
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index be5041f6c2..70a2f98d59 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -157,8 +157,6 @@ struct event
157/* We don't enable interrupts in the iPod bootloader, so we need to fake 157/* We don't enable interrupts in the iPod bootloader, so we need to fake
158 the current_tick variable */ 158 the current_tick variable */
159#define current_tick (signed)(USEC_TIMER/10000) 159#define current_tick (signed)(USEC_TIMER/10000)
160#elif (CONFIG_CPU == IMX31L) && defined(BOOTLOADER)
161#define current_tick (signed)((0xFFFFFFFF - EPITCNT1)/10000)
162#else 160#else
163extern volatile long current_tick; 161extern volatile long current_tick;
164#endif 162#endif
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 8eba5651ad..835181f1ae 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -24,9 +24,6 @@
24#include "cpu.h" 24#include "cpu.h"
25#include "system.h" 25#include "system.h"
26#include "panic.h" 26#include "panic.h"
27#if CONFIG_CPU == IMX31L
28#include "avic-imx31.h"
29#endif
30 27
31/* Make this nonzero to enable more elaborate checks on objects */ 28/* Make this nonzero to enable more elaborate checks on objects */
32#ifdef DEBUG 29#ifdef DEBUG
@@ -42,7 +39,7 @@
42#define KERNEL_ASSERT(exp, msg...) ({}) 39#define KERNEL_ASSERT(exp, msg...) ({})
43#endif 40#endif
44 41
45#if (!defined(CPU_PP) && (CONFIG_CPU != IMX31L)) || !defined(BOOTLOADER) 42#if !defined(CPU_PP) || !defined(BOOTLOADER)
46volatile long current_tick NOCACHEDATA_ATTR = 0; 43volatile long current_tick NOCACHEDATA_ATTR = 0;
47#endif 44#endif
48 45
@@ -107,7 +104,7 @@ void sleep(int ticks)
107 104
108void yield(void) 105void yield(void)
109{ 106{
110#if ((CONFIG_CPU == S3C2440 || defined(ELIO_TPJ1022) || CONFIG_CPU == IMX31L) && defined(BOOTLOADER)) 107#if ((CONFIG_CPU == S3C2440 || defined(ELIO_TPJ1022)) && defined(BOOTLOADER))
111 /* Some targets don't like yielding in the bootloader */ 108 /* Some targets don't like yielding in the bootloader */
112#else 109#else
113 switch_thread(NULL); 110 switch_thread(NULL);
diff --git a/firmware/system.c b/firmware/system.c
index 2ba31f254f..65478e724b 100644
--- a/firmware/system.c
+++ b/firmware/system.c
@@ -273,5 +273,11 @@ void __div0(void)
273} 273}
274#endif 274#endif
275 275
276#ifdef BOOTLOADER
277void reference_system_c(void)
278{
279}
280#endif
281
276#endif /* CPU_ARM */ 282#endif /* CPU_ARM */
277 283
diff --git a/firmware/target/arm/imx31/crt0.S b/firmware/target/arm/imx31/crt0.S
index 9d50888536..4e79cd1352 100644
--- a/firmware/target/arm/imx31/crt0.S
+++ b/firmware/target/arm/imx31/crt0.S
@@ -23,9 +23,16 @@
23 23
24 .global start 24 .global start
25start: 25start:
26 b newstart 26 /* Exception vectors */
27 .space 4*12 /* Space for low vectors */ 27 b newstart
28 28 b undef_instr_handler
29 b software_int_handler
30 b prefetch_abort_handler
31 b data_abort_handler
32 b reserved_handler
33 b irq_handler
34 b fiq_handler
35 .balign 0x40, 0x6B
29 36
30/* Arm bootloader and startup code based on startup.s from the iPodLinux loader 37/* Arm bootloader and startup code based on startup.s from the iPodLinux loader
31 * 38 *
@@ -34,28 +41,41 @@ start:
34 * 41 *
35 */ 42 */
36 43
44/* Initially this code is running at VA 0x8a000000 (PA 0x82000000).
45 * The mapping stub is copied to IRAM (0x1fffc000) and jumps to the final
46 * VA remapping starting at 0x01f00000 because the 1MB section containing
47 * the framebuffer at PA 0x81000000 is skipped in the remapping giving 63MB
48 * of contiguous RAM for the firmware. The TTB is placed at the end of said
49 * section.
50 *
51 * For now this will be done in bootloader, especially if usb will be needed
52 * within the bootloader to load the main firmware file. Interrupts will be
53 * needed for this (whether they be swi or irq).
54 */
37newstart: 55newstart:
38 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */ 56 msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
39 57
40#ifdef BOOTLOADER 58#ifdef BOOTLOADER
41 ldr r2, =remap_start 59 adr r2, remap_start /* Load PC-relative labels */
42 ldr r3, =remap_end 60 adr r3, remap_end
43 ldr r5, =TTB_BASE_ADDR /* TTB pointer */ 61 ldr r5, =TTB_BASE_ADDR /* TTB pointer */
44 ldr r6, =IRAM_BASE_ADDR 62 ldr r6, =IRAM_BASE_ADDR
45 mov r1, r6 63 mov r1, r6
46 64
471: 651: /* Copy remapping stub to IRAM */
48 cmp r3, r2 66 cmp r3, r2
49 ldrhi r4, [r2], #4 67 ldrhi r4, [r2], #4
50 strhi r4, [r1], #4 68 strhi r4, [r1], #4
51 bhi 1b 69 bhi 1b
52 70
53 mov pc, r6 71 mov pc, r6
54 72
73 /* Remapping stub. No absolute addresses may be used until after the
74 * remapping is complete. */
55remap_start: 75remap_start:
56 mrc p15, 0, r3, c1, c0, 0 /* perform writeback if D cache is enabled */ 76 mrc p15, 0, r3, c1, c0, 0 /* perform writeback if D cache is enabled */
57 tst r3, #(1 << 2) 77 tst r3, #(1 << 2) /* dcache? */
58 tsteq r3, #(1 << 12) 78 tsteq r3, #(1 << 12) /* or icache? */
59 mcrne p15, 0, r0, c7, c10, 0 /* clean dcache */ 79 mcrne p15, 0, r0, c7, c10, 0 /* clean dcache */
60 mov r0, #0 80 mov r0, #0
61 mcrne p15, 0, r0, c7, c7, 0 /* invalidate I cache and D cache */ 81 mcrne p15, 0, r0, c7, c7, 0 /* invalidate I cache and D cache */
@@ -77,9 +97,9 @@ remap_start:
77 str r1, [r0, #L2_CACHE_CTL_REG] 97 str r1, [r0, #L2_CACHE_CTL_REG]
78 98
79 /* Disble L1 caches and memory manager */ 99 /* Disble L1 caches and memory manager */
80 bic r3, r3, #(1 << 1) 100 bic r3, r3, #(1 << 12) /* L1 I-cache disabled */
81 bic r3, r3, #(1 << 2) 101 bic r3, r3, #((1 << 2) | /* L1 D-cache disabled */ \
82 bic r3, r3, #(1 << 12) 102 (1 << 0)) /* MMU disabled */
83 mcr p15, 0, r3, c1, c0, 0 103 mcr p15, 0, r3, c1, c0, 0
84 104
85 /* 105 /*
@@ -96,92 +116,97 @@ remap_start:
96 /* Invalidate L2 */ 116 /* Invalidate L2 */
97 mov r1, #0x000000FF 117 mov r1, #0x000000FF
98 str r1, [r0, #L2_CACHE_INV_WAY_REG] 118 str r1, [r0, #L2_CACHE_INV_WAY_REG]
99L2_loop: 1191:
100 /* Poll Invalidate By Way register */ 120 /* Poll Invalidate By Way register */
101 ldr r2, [r0, #L2_CACHE_INV_WAY_REG] 121 ldr r1, [r0, #L2_CACHE_INV_WAY_REG]
102 cmp r2, #0 122 cmp r1, #0
103 bne L2_loop 123 bne 1b
104 124
105 /*** End of L2 operations ***/ 125 /*** End of L2 operations ***/
106 126
107 /*remap memory as well as exception vectors*/
108 /*for now this will be done in bootloader, especially
109 if usb will be needed within the bootloader to load the
110 main firmware file. Interrupts will be needed for this
111 (whether they be swi or irq)*/
112
113 /* TTB Initialisation */ 127 /* TTB Initialisation */
114 mov r3, r5 128 mov r2, r5
115 add r2, r3, #TTB_SIZE 129 add r3, r5, #TTB_SIZE
116 mov r1, #0 130 mov r1, #0
117ttbloop: 1311:
118 str r1, [r3], #4 132 str r1, [r2], #4
119 cmp r3, r2 133 cmp r2, r3
120 bne ttbloop 134 blo 1b
121 135
122 /* Set TTB base address */ 136 /* Set TTB base address */
123 mov r3, r5 137 mcr p15, 0, r5, c2, c0, 0
124 mcr p15, 0, r3, c2, c0, 0 138
125 /* Set all domains to manager status */ 139 /* Set all domains to manager status */
126 mvn r3, #0 140 mvn r0, #0
127 mcr p15, 0, r3, c3, c0, 0 141 mcr p15, 0, r0, c3, c0, 0
128 142
129 /* Set page tables */ 143 /* Set page tables */
130 144
131 /* Map each memory loc to itself, no cache */ 145 /* Map each memory loc to itself, no cache */
132 mov r1, #0 /* Physical address */ 146 /* Physical address = 0x0 */
133 mov r3, r5 147 mov r1, #(1 << 10) /* superuser - r/w, user - no access */
134 add r4, r3, #TTB_SIZE /* End position */ 148 orr r1, r1, #((0 << 5) | /* domain 0th */ \
135maploop1: 149 (1 << 4) | /* should be "1" */ \
136 mov r2, r1 150 (1 << 1)) /* Section signature */
137 orr r2, r2, #(1<<10) /* superuser - r/w, user - no access */ 151 mov r2, r5
138 //orr r2, r2, #(0<<5) /* domain 0th */ 152 add r3, r5, #TTB_SIZE /* End position */
139 orr r2, r2, #(1<<4) /* should be "1" */ 1531:
140 orr r2, r2, #(1<<1) /* Section signature */ 154 str r1, [r2], #4
141 str r2, [r3], #4 155 add r1, r1, #(1 << 20) /* Next MB */
142 add r1, r1, #(1<<20) 156 cmp r2, r3
143 cmp r3, r4 157 blo 1b
144 bne maploop1 158 sub r1, r1, #TTB_SIZE/4*(1 << 20) /* Back up */
145 159
146 /* Map 0x80000000 -> 0x0, cached */ 160 /* Map 0x80000000 -> 0x0, cached */
147 mov r1, #0x80000000 /* Physical address */ 161 mov r2, r5 /* TTB pointer */
148 mov r3, r5 /* TTB pointer */ 162 add r3, r5, #63*4 /* End position */
149 add r4, r3, #64*4 /* End position */ 163 orr r1, r1, #0x80000000 /* Physical address */
150maploop2: 164 orr r1, r1, #((1 << 3) | /* cache flag */ \
151 mov r2, r1 165 (1 << 2)) /* buffer flag */
152 orr r2, r2, #(1<<10) /* superuser - r/w, user - no access */ 1661:
153 //orr r2, r2, #(0<<5) /* domain 0th */ 167 str r1, [r2], #4
154 orr r2, r2, #(1<<4) /* should be "1" */ 168 add r1, r1, #(1 << 20)
155 orr r2, r2, #(1<<3) /* cache flags */ 169 and r4, r1, #0x0ff00000
156 orr r2, r2, #(1<<2) /* more cache stuff */ 170 cmp r4, #0x00100000 /* Skip framebuffer */
157 orr r2, r2, #(1<<1) /* Section signature */ 171 addeq r1, r1, #(1 << 20)
158 str r2, [r3], #4 172 cmp r2, r3
159 add r1, r1, #(1<<20) 173 blo 1b
160 bic r6, r1, #0xf0000000
161 cmp r6, #0x00100000 /* Skip framebuffer */
162 addeq r1, r1, #(1<<20)
163 cmp r3, r4
164 bne maploop2
165 174
166 /* Enable MMU */ 175 /* Enable MMU */
167 176
168 mov r0, #0 177 mov r0, #0
169 mcr p15, 0, r0, c8, c7, 0 /* Invalidate TLB */ 178 mcr p15, 0, r0, c8, c7, 0 /* Invalidate TLB */
170 mcr p15, 0, r0, c7, c7, 0 /* Invalidate icache and dcache */ 179 mcr p15, 0, r0, c7, c7, 0 /* Invalidate icache and dcache */
171#if 1 180
181 /* Auxilliary control register */
172 mrc p15, 0, r0, c1, c0, 1 182 mrc p15, 0, r0, c1, c0, 1
173 bic r0, r0, #0x70 183 bic r0, r0, #((1 << 6) | /* Restrict cache size OFF */ \
174 bic r0, r0, #0x07 184 (1 << 5) | /* Enable block tranfer cache operations */ \
185 (1 << 4) | /* Clean+Invalidate cache operation ON */ \
186 (1 << 3)) /* Round-robin micro TLB replacement */
187 orr r0, r0, #((1 << 2) | /* Static branch prediction ON */ \
188 (1 << 1) | /* Dynamic branch prediction ON */ \
189 (1 << 0)) /* Return stack enabled */
175 mcr p15, 0, r0, c1, c0, 1 190 mcr p15, 0, r0, c1, c0, 1
176#endif 191
192 /* Control register */
177 mrc p15, 0, r0, c1, c0, 0 193 mrc p15, 0, r0, c1, c0, 0
178 orr r0, r0, #(1 << 0) /* enable mmu bit */ 194 bic r0, r0, #((1 << 29) | /* AF by AP disabled */ \
179 orr r0, r0, #(1 << 2) /* enable dcache */ 195 (1 << 28) | /* TEX remap disabled */ \
180 bic r0, r0, #(1 << 11) /* no program flow prediction */ 196 (1 << 24) | /* Vectored interrupt OFF */ \
181 orr r0, r0, #(1 << 12) /* enable icache */ 197 (1 << 23) | /* Sub AP bits enabled (compatible) */ \
182 bic r0, r0, #(1 << 13) /* low vectors */ 198 (1 << 22)) /* Unaligned access support disabled */
183 orr r0, r0, #(1 << 14) /* Round-robin */ 199 bic r0, r0, #((1 << 21) | /* All performance features enabled */ \
184 bic r0, r0, #(1 << 21) /* No low latency interrupt */ 200 (1 << 15)) /* Loads to PC set T bit */
201 bic r0, r0, #((1 << 13) | /* Low vectors */ \
202 (1 << 11)) /* Program flow prediction disabled (for now) */
203 orr r0, r0, #((1 << 14) | /* Round-robin replacement for I/D caches */ \
204 (1 << 12) | /* L1 I-cache enabled */ \
205 (1 << 9) | /* ROM protection enabled */ \
206 (1 << 8)) /* MMU protection enabled */
207 orr r0, r0, #((1 << 2) | /* L1 D-cache enabled */ \
208 (1 << 1) | /* Strict alignment enabled */ \
209 (1 << 0)) /* MMU enabled */
185 mcr p15, 0, r0, c1, c0, 0 210 mcr p15, 0, r0, c1, c0, 0
186 nop 211 nop
187 nop 212 nop
@@ -194,8 +219,8 @@ remap_end:
194 219
195#endif /* BOOTLOADER */ 220#endif /* BOOTLOADER */
196 221
197#ifndef BOOTLOADER 222#ifdef BOOTLOADER
198 /* Copy exception handler code to address 0 */ 223 /* Copy bootloader exception handler code to address 0 */
199 ldr r2, =_vectorsstart 224 ldr r2, =_vectorsstart
200 ldr r3, =_vectorsend 225 ldr r3, =_vectorsend
201 ldr r4, =_vectorscopy 226 ldr r4, =_vectorscopy
@@ -204,7 +229,7 @@ remap_end:
204 ldrhi r5, [r4], #4 229 ldrhi r5, [r4], #4
205 strhi r5, [r2], #4 230 strhi r5, [r2], #4
206 bhi 1b 231 bhi 1b
207 232#else
208 /* Zero out IBSS */ 233 /* Zero out IBSS */
209 ldr r2, =_iedata 234 ldr r2, =_iedata
210 ldr r3, =_iend 235 ldr r3, =_iend
@@ -261,47 +286,41 @@ remap_end:
261 msr cpsr_c, #0xd3 286 msr cpsr_c, #0xd3
262 bl main 287 bl main
263 288
264/* Exception handlers. Will be copied to address 0 after memory remapping */ 289#ifdef BOOTLOADER
265_vectorstart: 290 /* Exception vectors with absolute jumps for bootloader */
266 .section .vectors,"aw" 291 .section .vectors,"aw"
267 ldr pc, [pc, #24] 292 ldr pc, [pc, #24]
268 ldr pc, [pc, #24] 293 ldr pc, [pc, #24]
269 ldr pc, [pc, #24] 294 ldr pc, [pc, #24]
270 ldr pc, [pc, #24] 295 ldr pc, [pc, #24]
271 ldr pc, [pc, #24] 296 ldr pc, [pc, #24]
272 ldr pc, [pc, #24] 297 ldr pc, [pc, #24]
273 ldr pc, [pc, #24] 298 ldr pc, [pc, #24]
274 ldr pc, [pc, #24] 299 ldr pc, [pc, #24]
275 300 .word newstart
276 /* Exception vectors */ 301 .word undef_instr_handler
277 .global vectors 302 .word software_int_handler
278vectors: 303 .word prefetch_abort_handler
279 .word start 304 .word data_abort_handler
280 .word undef_instr_handler 305 .word reserved_handler
281 .word software_int_handler 306 .word irq_handler
282 .word prefetch_abort_handler 307 .word fiq_handler
283 .word data_abort_handler 308#endif /* BOOTLOADER */
284 .word reserved_handler
285 .word irq_handler
286 .word fiq_handler
287 309
288 .text 310 .text
289
290 .global UIE 311 .global UIE
291 312
292/* All illegal exceptions call into UIE with exception address as first 313/* All illegal exceptions call into UIE with exception address as first
293 parameter. This is calculated differently depending on which exception 314 * parameter. This is calculated differently depending on which exception
294 we're in. Second parameter is exception number, used for a string lookup 315 * we're in. Second parameter is exception number, used for a string lookup
295 in UIE. 316 * in UIE. */
296 */
297undef_instr_handler: 317undef_instr_handler:
298 mov r0, lr 318 mov r0, lr
299 mov r1, #0 319 mov r1, #0
300 b UIE 320 b UIE
301 321
302/* We run supervisor mode most of the time, and should never see a software 322/* We run supervisor mode most of the time, and should never see a software
303 exception being thrown. Perhaps make it illegal and call UIE? 323 * exception being thrown. Perhaps make it illegal and call UIE? */
304 */
305software_int_handler: 324software_int_handler:
306reserved_handler: 325reserved_handler:
307 movs pc, lr 326 movs pc, lr
@@ -316,11 +335,6 @@ data_abort_handler:
316 mov r1, #2 335 mov r1, #2
317 b UIE 336 b UIE
318 337
319#ifdef BOOTLOADER
320UIE:
321 b UIE
322#endif
323
324/* 256 words of IRQ stack */ 338/* 256 words of IRQ stack */
325 .space 256*4 339 .space 256*4
326irq_stack: 340irq_stack:
diff --git a/firmware/target/arm/imx31/gigabeat-s/avic-imx31.c b/firmware/target/arm/imx31/gigabeat-s/avic-imx31.c
index fa74d3bb9f..b04b22911a 100644
--- a/firmware/target/arm/imx31/gigabeat-s/avic-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/avic-imx31.c
@@ -84,18 +84,24 @@ void __attribute__((naked)) fiq_handler(void)
84 84
85void avic_init(void) 85void avic_init(void)
86{ 86{
87 int i;
88
87 /* Disable all interrupts and set to unhandled */ 89 /* Disable all interrupts and set to unhandled */
88 avic_disable_int(ALL); 90 avic_disable_int(ALL);
89 91
92 /* Reset AVIC control */
93 INTCNTL = 0;
94
90 /* Init all interrupts to type IRQ */ 95 /* Init all interrupts to type IRQ */
91 avic_set_int_type(ALL, IRQ); 96 avic_set_int_type(ALL, IRQ);
92 97
98 /* Set all normal to lowest priority */
99 for (i = 0; i < 8; i++)
100 NIPRIORITY(i) = 0;
101
93 /* Set NM bit to enable VIC */ 102 /* Set NM bit to enable VIC */
94 INTCNTL |= INTCNTL_NM; 103 INTCNTL |= INTCNTL_NM;
95 104
96 /* Enable IRQ/FIQ in imx31 INTCNTL reg */
97 INTCNTL &= ~(INTCNTL_ABFEN | INTCNTL_NIDIS | INTCNTL_FIDIS);
98
99 /* Enable VE bit in CP15 Control reg to enable VIC */ 105 /* Enable VE bit in CP15 Control reg to enable VIC */
100 asm volatile ( 106 asm volatile (
101 "mrc p15, 0, r0, c1, c0, 0 \n" 107 "mrc p15, 0, r0, c1, c0, 0 \n"
@@ -104,11 +110,20 @@ void avic_init(void)
104 : : : "r0"); 110 : : : "r0");
105 111
106 /* Enable normal interrupts at all priorities */ 112 /* Enable normal interrupts at all priorities */
107 NIMASK = 16; 113 NIMASK = 0x1f;
114}
115
116void avic_set_int_priority(enum IMX31_INT_LIST ints,
117 unsigned long ni_priority)
118{
119 volatile unsigned long *reg = &NIPRIORITY((63 - ints) / 8);
120 unsigned int shift = 4*(ints % 8);
121 unsigned long mask = 0xful << shift;
122 *reg = (*reg & ~mask) | ((ni_priority << shift) & mask);
108} 123}
109 124
110void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype, 125void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype,
111 void (*handler)(void)) 126 unsigned long ni_priority, void (*handler)(void))
112{ 127{
113 int oldstatus = set_interrupt_status(IRQ_FIQ_DISABLED, 128 int oldstatus = set_interrupt_status(IRQ_FIQ_DISABLED,
114 IRQ_FIQ_STATUS); 129 IRQ_FIQ_STATUS);
@@ -118,6 +133,7 @@ void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype,
118 avic_set_int_type(ints, intstype); 133 avic_set_int_type(ints, intstype);
119 VECTOR(ints) = (long)handler; 134 VECTOR(ints) = (long)handler;
120 INTENNUM = ints; 135 INTENNUM = ints;
136 avic_set_int_priority(ints, ni_priority);
121 } 137 }
122 138
123 set_interrupt_status(oldstatus, IRQ_FIQ_STATUS); 139 set_interrupt_status(oldstatus, IRQ_FIQ_STATUS);
diff --git a/firmware/target/arm/imx31/gigabeat-s/avic-imx31.h b/firmware/target/arm/imx31/gigabeat-s/avic-imx31.h
index 29a3ec8dd0..7bb7c09da7 100644
--- a/firmware/target/arm/imx31/gigabeat-s/avic-imx31.h
+++ b/firmware/target/arm/imx31/gigabeat-s/avic-imx31.h
@@ -49,7 +49,9 @@ enum IMX31_INT_LIST
49 49
50void avic_init(void); 50void avic_init(void);
51void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype, 51void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype,
52 void (*handler)(void)); 52 unsigned long ni_priority, void (*handler)(void));
53void avic_set_int_priority(enum IMX31_INT_LIST ints,
54 unsigned long ni_priority);
53void avic_disable_int(enum IMX31_INT_LIST ints); 55void avic_disable_int(enum IMX31_INT_LIST ints);
54void avic_set_int_type(enum IMX31_INT_LIST ints, enum INT_TYPE intstype); 56void avic_set_int_type(enum IMX31_INT_LIST ints, enum INT_TYPE intstype);
55#endif 57#endif
diff --git a/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c b/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
index 3c44a156b0..c2fddc40a7 100644
--- a/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/kernel-imx31.c
@@ -7,7 +7,6 @@
7 7
8extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); 8extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
9 9
10#ifndef BOOTLOADER
11static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void) 10static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
12{ 11{
13 int i; 12 int i;
@@ -23,14 +22,11 @@ static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
23 22
24 current_tick++; 23 current_tick++;
25} 24}
26#endif
27 25
28void tick_start(unsigned int interval_in_ms) 26void tick_start(unsigned int interval_in_ms)
29{ 27{
30 EPITCR1 &= ~(1 << 0); /* Disable the counter */ 28 CLKCTL_CGR0 |= (3 << 6); /* EPIT1 module clock ON - before writing regs! */
31 EPITCR1 |= (1 << 16); /* Reset */ 29 EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable the counter */
32
33 CLKCTL_CGR0 |= (0x3 << 6); /* Clock ON */
34 CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */ 30 CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */
35 31
36 /* NOTE: This isn't really accurate yet but it's close enough to work 32 /* NOTE: This isn't really accurate yet but it's close enough to work
@@ -39,17 +35,21 @@ void tick_start(unsigned int interval_in_ms)
39 /* CLKSRC=32KHz, EPIT Output Disconnected, Enabled 35 /* CLKSRC=32KHz, EPIT Output Disconnected, Enabled
40 * prescale 1/32, Reload from modulus register, Compare interrupt enabled, 36 * prescale 1/32, Reload from modulus register, Compare interrupt enabled,
41 * Count from load value */ 37 * Count from load value */
42 EPITCR1 = (0x3 << 24) | (1 << 19) | (32 << 4) | 38 EPITCR1 = (3 << 24) | (1 << 19) | (32 << 4) |
43 (1 << 3) | (1 << 2) | (1 << 1); 39 (1 << 3) | (1 << 2) | (1 << 1);
44#ifndef BOOTLOADER
45 EPITLR1 = interval_in_ms;
46 EPITCMPR1 = 0; /* Event when counter reaches 0 */
47 avic_enable_int(EPIT1, IRQ, EPIT1_HANDLER);
48#else
49 (void)interval_in_ms;
50#endif
51 EPITSR1 = 1; /* Clear any pending interrupt after
52 enabling the vector */
53 40
41 EPITLR1 = interval_in_ms; /* Count down from interval */
42 EPITCMPR1 = 0; /* Event when counter reaches 0 */
43 EPITSR1 = 1; /* Clear any pending interrupt */
44 avic_enable_int(EPIT1, IRQ, 7, EPIT1_HANDLER);
54 EPITCR1 |= (1 << 0); /* Enable the counter */ 45 EPITCR1 |= (1 << 0); /* Enable the counter */
55} 46}
47
48#ifdef BOOTLOADER
49void tick_stop(void)
50{
51 avic_disable_int(EPIT1); /* Disable insterrupt */
52 EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable counter */
53 CLKCTL_CGR0 &= ~(3 << 6); /* EPIT1 module clock OFF */
54}
55#endif
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
index ed5a26cd6e..c77c923d60 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
@@ -1,6 +1,7 @@
1#include "kernel.h" 1#include "kernel.h"
2#include "system.h" 2#include "system.h"
3#include "panic.h" 3#include "panic.h"
4#include "avic-imx31.h"
4#include "mmu-imx31.h" 5#include "mmu-imx31.h"
5#include "system-target.h" 6#include "system-target.h"
6#include "lcd.h" 7#include "lcd.h"
@@ -19,11 +20,20 @@ void system_reboot(void)
19 20
20void system_init(void) 21void system_init(void)
21{ 22{
22#ifndef BOOTLOADER 23 /* MCR WFI enables wait mode */
24 CLKCTL_CCMR &= ~(3 << 14);
23 avic_init(); 25 avic_init();
24#endif
25} 26}
26 27
28#ifdef BOOTLOADER
29void system_prepare_fw_start(void)
30{
31 set_interrupt_status(IRQ_FIQ_DISABLED, IRQ_FIQ_STATUS);
32 avic_disable_int(ALL);
33 tick_stop();
34}
35#endif
36
27inline void dumpregs(void) 37inline void dumpregs(void)
28{ 38{
29 asm volatile ("mov %0,r0\n\t" 39 asm volatile ("mov %0,r0\n\t"
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-target.h b/firmware/target/arm/imx31/gigabeat-s/system-target.h
index 1f7a2475af..327d72b7bc 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/system-target.h
@@ -33,24 +33,28 @@ static inline void udelay(unsigned int usecs)
33#define __dbg_hw_info(...) 0 33#define __dbg_hw_info(...) 0
34#define __dbg_ports(...) 0 34#define __dbg_ports(...) 0
35 35
36void system_prepare_fw_start(void);
37void tick_stop(void);
38
36#define HAVE_INVALIDATE_ICACHE 39#define HAVE_INVALIDATE_ICACHE
37static inline void invalidate_icache(void) 40static inline void invalidate_icache(void)
38{ 41{
39 long rd = 0;
40 asm volatile( 42 asm volatile(
41 "mcr p15, 0, %0, c7, c10, 0 \n" 43 /* Clean and invalidate entire data cache */
44 "mcr p15, 0, %0, c7, c14, 0 \n"
45 /* Invalidate entire instruction cache */
42 "mcr p15, 0, %0, c7, c5, 0 \n" 46 "mcr p15, 0, %0, c7, c5, 0 \n"
43 : : "r"(rd) 47 : : "r"(0)
44 ); 48 );
45} 49}
46 50
47#define HAVE_FLUSH_ICACHE 51#define HAVE_FLUSH_ICACHE
48static inline void flush_icache(void) 52static inline void flush_icache(void)
49{ 53{
50 long rd = 0;
51 asm volatile ( 54 asm volatile (
55 /* Clean entire data cache */
52 "mcr p15, 0, %0, c7, c10, 0 \n" 56 "mcr p15, 0, %0, c7, c10, 0 \n"
53 : : "r"(rd) 57 : : "r"(0)
54 ); 58 );
55} 59}
56 60
diff --git a/tools/configure b/tools/configure
index f0004fd2ba..52d48e2c79 100755
--- a/tools/configure
+++ b/tools/configure
@@ -1213,7 +1213,7 @@ EOF
1213 target_id=26 1213 target_id=26
1214 modelname="gigabeats" 1214 modelname="gigabeats"
1215 target="-DGIGABEAT_S" 1215 target="-DGIGABEAT_S"
1216 memory=32 # always 1216 memory=64
1217 arm9tdmicc 1217 arm9tdmicc
1218 tool="$rootdir/tools/scramble -add=gigs" 1218 tool="$rootdir/tools/scramble -add=gigs"
1219 bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" 1219 bmp2rb_mono="$rootdir/tools/bmp2rb -f 0"
diff --git a/tools/scramble.c b/tools/scramble.c
index b5aba3fbaa..3e5a0771bc 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -107,7 +107,7 @@ void usage(void)
107 "\t-add=X Rockbox generic \"add-up\" checksum format\n" 107 "\t-add=X Rockbox generic \"add-up\" checksum format\n"
108 "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n" 108 "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd, mn2g\n"
109 "\t ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2,\n" 109 "\t ip3g, ip4g, mini, iax5, h10, h10_5gb, tpj2,\n"
110 "\t c200, e200, giga, m100, m500)\n" 110 "\t c200, e200, giga, gigs, m100, m500)\n"
111 "\nNo option results in Archos standard player/recorder format.\n"); 111 "\nNo option results in Archos standard player/recorder format.\n");
112 112
113 exit(1); 113 exit(1);