1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
diff --git a/firmware/target/arm/as3525/app.lds b/firmware/target/arm/as3525/app.lds
index c2fce0d..d6ea4c7 100644
--- a/firmware/target/arm/as3525/app.lds
+++ b/firmware/target/arm/as3525/app.lds
@@ -26,6 +26,7 @@ STARTUP(target/arm/crt0.o)
 #define IRAMSIZE (0x20000)
 #endif
 
+#define DRAM_RO_OFFSET (DRAM_SIZE + 0x100000)
 
 /* Where the codec buffer ends, and the plugin buffer starts */
 #if CODEC_BUFFER_FILLS_IRAM
@@ -46,14 +47,15 @@ MEMORY
 SECTIONS
 {
     loadaddress = DRAM_ORIG;
+    . = DRAM_ORIG;
 
-    .vectors :
+    .vectors . + DRAM_RO_OFFSET:
     {
         _vectors_start = .;
         *(.init.text)
-    } > DRAM
+    } AT> DRAM
 
-    .text :
+    .text . :
     {
         _loadaddress = .;
         _textstart = .;
@@ -61,13 +63,13 @@ SECTIONS
         *(.glue_7)
         *(.glue_7t)
         . = ALIGN(0x4);
-    } > DRAM
+    } AT> DRAM
 
-    .rodata :
+    .rodata . :
     {
         *(.rodata*)
         . = ALIGN(0x4);
-    } > DRAM
+    } AT> DRAM
 
     .data :
     {
diff --git a/firmware/target/arm/as3525/memory-init.S b/firmware/target/arm/as3525/memory-init.S
index 49b0546..b96a219 100644
--- a/firmware/target/arm/as3525/memory-init.S
+++ b/firmware/target/arm/as3525/memory-init.S
@@ -126,30 +126,44 @@ memory_init:
     mov     r1, #0                          @ virtual address
     mov     r2, #0x1000                     @ size (all memory)
     mov     r3, #CACHE_NONE
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     mov     r0, #0                          @ physical address
     ldr     r1, =IRAM_ORIG                  @ virtual address
     mov     r2, #1                          @ size : 1MB
     mov     r3, #CACHE_ALL
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     mov     r0, #0                          @ physical address
     ldr     r1, =UNCACHED_ADDR(IRAM_ORIG)   @ virtual address
     mov     r2, #1                          @ size : 1MB
     mov     r3, #CACHE_NONE
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     mov     r0, #0x30000000                 @ physical address
     mov     r1, #DRAM_ORIG                  @ virtual address
     mov     r2, #MEMORYSIZE                 @ size
     mov     r3, #CACHE_ALL
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
+    bl      map_section
+
+    mov     r0, #0x30000000                 @ physical address
+    mov     r1, #DRAM_ORIG                  @ virtual address
+    add     r1, r1, #((MEMORYSIZE+1) * 0x100000)
+    mov     r2, #MEMORYSIZE                 @ size
+    mov     r3, #(1 << 3)           @ cacheable
+    add     r3, #(1 << 5)           @ domain 1 (Client)
+@    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     mov     r0, #0x30000000                 @ physical address
     mov     r1, #UNCACHED_ADDR(DRAM_ORIG)   @ virtual address
     mov     r2, #MEMORYSIZE                 @ size
     mov     r3, #CACHE_NONE
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     /* map 1st mbyte of RAM at 0x0 to have exception vectors available */
@@ -161,6 +175,7 @@ memory_init:
     mov     r1, #0                          @ virtual address
     mov     r2, #1                          @ size
     mov     r3, #CACHE_ALL
+    orr     r3, r3, #(1<<10)                @ AP = 01 = RW
     bl      map_section
 
     bl      enable_mmu
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index 9edc598..b8b1763 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -712,6 +712,8 @@ static void init_controller(void)
 
 int sd_init(void)
 {
+    //char *b = sd_thread_name;
+    //*b = 'l';
     int ret;
 
     bitset32(&CGU_PERI, CGU_MCI_CLOCK_ENABLE);
diff --git a/firmware/target/arm/mmu-arm.S b/firmware/target/arm/mmu-arm.S
index 522aa9f..66713bb 100644
--- a/firmware/target/arm/mmu-arm.S
+++ b/firmware/target/arm/mmu-arm.S
@@ -93,6 +93,7 @@ ttb_init:
     ldr     r0, =TTB_BASE_ADDR      @
     mvn     r1, #0                  @
     mcr     p15, 0, r0, c2, c0, 0   @ Set the TTB base address
+    bic     r1, r1, #(1 << 3)       @ D1 = Client (access are checked)
     mcr     p15, 0, r1, c3, c0, 0   @ Set all domains to manager status
     bx      lr                      @
     .size   ttb_init, .-ttb_init
@@ -117,8 +118,9 @@ map_section:
     @  3,2: Cache flags (flags (r3))
     @  1:   Section signature
     orr     r0, r0, r3
-    orr     r0, r0, #0x410
-    orr     r0, r0, #0x2
+@    orr     r0, r0, #(1<<10) @ AP bit = 01 = RW
+    orr     r0, r0, #0x10 @ always 1
+    orr     r0, r0, #0x2  @ section sig
 
     @ unsigned int* ttbPtr = TTB_BASE + (va >> 20);
     @ sections are 1MB size
@@ -160,6 +162,7 @@ enable_mmu:
     orr     r0, r0, #1              @ enable mmu bit, i and dcache
     orr     r0, r0, #1<<2           @ enable dcache
     orr     r0, r0, #1<<12          @ enable icache
+    orr     r0, r0, #1<<9           @ ROM protection (read-only)
     mcr     p15, 0, r0, c1, c0, 0   @
     nop                             @
     nop                             @