diff options
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/h10.c | 252 |
1 files changed, 127 insertions, 125 deletions
diff --git a/bootloader/h10.c b/bootloader/h10.c index e80e28fe5b..d7942c9583 100644 --- a/bootloader/h10.c +++ b/bootloader/h10.c | |||
@@ -66,10 +66,10 @@ static void memmove16(void *dest, const void *src, unsigned count) | |||
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | /* Load original iriver firmware. This function expects a file called "H10_20GC.mi4" in | 69 | /* Load original iriver firmware. This function expects a file called |
70 | the root directory of the player. It should be decrypted and have the header stripped | 70 | "H10_20GC.mi4" in the root directory of the player. It should be decrypted |
71 | using mi4code. It reads the file in to a memory buffer called buf. The rest of the | 71 | and have the header stripped using mi4code. It reads the file in to a memory |
72 | loading is done in main() | 72 | buffer called buf. The rest of the loading is done in main() |
73 | */ | 73 | */ |
74 | int load_iriver(unsigned char* buf) | 74 | int load_iriver(unsigned char* buf) |
75 | { | 75 | { |
@@ -93,144 +93,146 @@ unsigned char loadbuffer[MAX_LOADSIZE]; | |||
93 | 93 | ||
94 | void main(void) | 94 | void main(void) |
95 | { | 95 | { |
96 | /* Attempt to load original iriver firmware. Successfully starts loading the iriver | 96 | /* Attempt to load original iriver firmware. Successfully starts loading the |
97 | firmware but then locks up once the "System Initialising" screen is displayed. | 97 | iriver firmware but then locks up once the "System Initialising" screen |
98 | 98 | is displayed. | |
99 | The iriver firmware was decrypted and the header removed. It was then appended to | 99 | |
100 | the end of bootloader.bin and an mi4 file was created from the resulting file. | 100 | The iriver firmware was decrypted and the header removed. It was then |
101 | 101 | appended to the end of bootloader.bin and an mi4 file was created from | |
102 | The original firmware starts at 0xd800 in the file and is of length 0x47da00. | 102 | the resulting file. |
103 | 103 | ||
104 | The whole file (bootloader.bin + decrypted mi4) are loaded to memory by the | 104 | The original firmware starts at 0xd800 in the file and is of length |
105 | original iriver bootloader on startup. This copies the mi4 part to the start | 105 | 0x47da00. |
106 | of DRAM and passes execution to there. | 106 | |
107 | 107 | The whole file (bootloader.bin + decrypted mi4) are loaded to memory by | |
108 | memmove16((void*)DRAMORIG, (void*)(DRAMORIG + 0xd800), 0x47da00); | 108 | the original iriver bootloader on startup. This copies the mi4 part to |
109 | asm volatile( | 109 | the start of DRAM and passes execution to there. |
110 | "mov r0, #" SC(DRAMORIG) "\n" | 110 | |
111 | "mov pc, r0 \n" | 111 | memmove16((void*)DRAMORIG, (void*)(DRAMORIG + 0xd800), 0x47da00); |
112 | ); | 112 | asm volatile( |
113 | */ | 113 | "mov r0, #" SC(DRAMORIG) "\n" |
114 | "mov pc, r0 \n" | ||
115 | ); | ||
116 | */ | ||
114 | 117 | ||
115 | int i; | 118 | int i; |
116 | int rc; | 119 | int rc; |
117 | int btn; | 120 | int btn; |
121 | int fd; | ||
122 | char buffer[24]; | ||
118 | 123 | ||
119 | i=ata_init(); | 124 | i=ata_init(); |
120 | disk_init(); | 125 | disk_init(); |
121 | rc = disk_mount_all(); | 126 | rc = disk_mount_all(); |
122 | 127 | ||
123 | /* Load original iriver firmware. Uses load_iriver(buf) to load the decrypted mi4 file from | 128 | /* Load original iriver firmware. Uses load_iriver(buf) to load the |
124 | disk to DRAM. This then copies that part of DRAM to the start of DRAM and passes | 129 | decrypted mi4 file from disk to DRAM. This then copies that part of DRAM |
125 | execution to there. | 130 | to the start of DRAM and passes |
126 | 131 | execution to there. | |
127 | rc=load_iriver(loadbuffer); | 132 | |
128 | memcpy((void*)DRAMORIG,loadbuffer,rc); | 133 | rc=load_iriver(loadbuffer); |
129 | asm volatile( | 134 | memcpy((void*)DRAMORIG,loadbuffer,rc); |
130 | "mov r0, #" SC(DRAMORIG) "\n" | 135 | asm volatile( |
131 | "mov pc, r0 \n" | 136 | "mov r0, #" SC(DRAMORIG) "\n" |
132 | );*/ | 137 | "mov pc, r0 \n" |
133 | 138 | );*/ | |
134 | 139 | ||
135 | /* This assumes that /test.txt exists */ | 140 | |
136 | int fd; | 141 | /* This assumes that /test.txt exists */ |
137 | char buffer[24]; | 142 | fd=open("/test.txt",O_RDWR); |
138 | fd=open("/test.txt",O_RDWR); | 143 | |
139 | 144 | ||
140 | 145 | /* | |
141 | /* WARNING: Running this code on the H10 caused permanent damage to my H10's hdd | 146 | for(i=0;i<100;i++){ |
142 | I strongly recommend against trying it. | 147 | btn = button_read_device(); |
143 | 148 | switch(btn){ | |
144 | for(i=0;i<100;i++){ | 149 | case BUTTON_LEFT: |
145 | btn = button_read_device(); | 150 | snprintf(buffer, sizeof(buffer), "Left"); |
146 | switch(btn){ | 151 | write(fd,buffer,sizeof(buffer)); |
147 | case BUTTON_LEFT: | 152 | break; |
148 | snprintf(buffer, sizeof(buffer), "Left"); | 153 | case BUTTON_RIGHT: |
149 | write(fd,buffer,sizeof(buffer)); | 154 | break; |
150 | break; | 155 | case BUTTON_REW: |
151 | case BUTTON_RIGHT: | 156 | break; |
152 | break; | 157 | case BUTTON_FF: |
153 | case BUTTON_REW: | 158 | break; |
154 | break; | 159 | case BUTTON_PLAY: |
155 | case BUTTON_FF: | 160 | break; |
156 | break; | 161 | default: |
157 | case BUTTON_PLAY: | 162 | break; |
158 | break; | 163 | } |
159 | default: | 164 | |
160 | break; | ||
161 | } | ||
162 | |||
163 | 165 | ||
164 | } | 166 | } |
165 | */ | 167 | */ |
166 | 168 | ||
167 | 169 | ||
168 | 170 | ||
169 | /* Investigate gpio | 171 | /* Investigate gpio |
170 | 172 | ||
171 | unsigned int gpio_a, gpio_b, gpio_c, gpio_d; | 173 | unsigned int gpio_a, gpio_b, gpio_c, gpio_d; |
172 | unsigned int gpio_e, gpio_f, gpio_g, gpio_h; | 174 | unsigned int gpio_e, gpio_f, gpio_g, gpio_h; |
173 | unsigned int gpio_i, gpio_j, gpio_k, gpio_l; | 175 | unsigned int gpio_i, gpio_j, gpio_k, gpio_l; |
174 | 176 | ||
175 | gpio_a = GPIOA_INPUT_VAL; | 177 | gpio_a = GPIOA_INPUT_VAL; |
176 | gpio_b = GPIOB_INPUT_VAL; | 178 | gpio_b = GPIOB_INPUT_VAL; |
177 | gpio_c = GPIOC_INPUT_VAL; | 179 | gpio_c = GPIOC_INPUT_VAL; |
178 | 180 | ||
179 | gpio_g = GPIOG_INPUT_VAL; | 181 | gpio_g = GPIOG_INPUT_VAL; |
180 | gpio_h = GPIOH_INPUT_VAL; | 182 | gpio_h = GPIOH_INPUT_VAL; |
181 | gpio_i = GPIOI_INPUT_VAL; | 183 | gpio_i = GPIOI_INPUT_VAL; |
182 | 184 | ||
183 | snprintf(buffer, sizeof(buffer), "GPIO_A: %02x GPIO_G: %02x\n", gpio_a, gpio_g); | 185 | snprintf(buffer,sizeof(buffer),"GPIO_A: %02x GPIO_G: %02x\n",gpio_a,gpio_g); |
184 | write(fd,buffer,sizeof(buffer)); | 186 | write(fd,buffer,sizeof(buffer)); |
185 | snprintf(buffer, sizeof(buffer), "GPIO_B: %02x GPIO_H: %02x\n", gpio_b, gpio_h); | 187 | snprintf(buffer,sizeof(buffer),"GPIO_B: %02x GPIO_H: %02x\n",gpio_b,gpio_h); |
186 | write(fd,buffer,sizeof(buffer)); | 188 | write(fd,buffer,sizeof(buffer)); |
187 | snprintf(buffer, sizeof(buffer), "GPIO_C: %02x GPIO_I: %02x\n", gpio_c, gpio_i); | 189 | snprintf(buffer,sizeof(buffer),"GPIO_C: %02x GPIO_I: %02x\n",gpio_c,gpio_i); |
188 | write(fd,buffer,sizeof(buffer)); | 190 | write(fd,buffer,sizeof(buffer)); |
189 | 191 | ||
190 | gpio_d = GPIOD_INPUT_VAL; | 192 | gpio_d = GPIOD_INPUT_VAL; |
191 | gpio_e = GPIOE_INPUT_VAL; | 193 | gpio_e = GPIOE_INPUT_VAL; |
192 | gpio_f = GPIOF_INPUT_VAL; | 194 | gpio_f = GPIOF_INPUT_VAL; |
193 | 195 | ||
194 | gpio_j = GPIOJ_INPUT_VAL; | 196 | gpio_j = GPIOJ_INPUT_VAL; |
195 | gpio_k = GPIOK_INPUT_VAL; | 197 | gpio_k = GPIOK_INPUT_VAL; |
196 | gpio_l = GPIOL_INPUT_VAL; | 198 | gpio_l = GPIOL_INPUT_VAL; |
197 | 199 | ||
198 | snprintf(buffer, sizeof(buffer), "GPIO_D: %02x GPIO_J: %02x\n", gpio_d, gpio_j); | 200 | snprintf(buffer,sizeof(buffer),"GPIO_D: %02x GPIO_J: %02x\n",gpio_d,gpio_j); |
199 | write(fd,buffer,sizeof(buffer)); | 201 | write(fd,buffer,sizeof(buffer)); |
200 | snprintf(buffer, sizeof(buffer), "GPIO_E: %02x GPIO_K: %02x\n", gpio_e, gpio_k); | 202 | snprintf(buffer,sizeof(buffer),"GPIO_E: %02x GPIO_K: %02x\n",gpio_e,gpio_k); |
201 | write(fd,buffer,sizeof(buffer)); | 203 | write(fd,buffer,sizeof(buffer)); |
202 | snprintf(buffer, sizeof(buffer), "GPIO_F: %02x GPIO_L: %02x\n", gpio_f, gpio_l); | 204 | snprintf(buffer,sizeof(buffer),"GPIO_F: %02x GPIO_L: %02x\n",gpio_f,gpio_l); |
203 | write(fd,buffer,sizeof(buffer)); | 205 | write(fd,buffer,sizeof(buffer)); |
204 | */ | 206 | */ |
205 | 207 | ||
206 | 208 | ||
207 | 209 | ||
208 | /* Detect the scroller being touched | 210 | /* Detect the scroller being touched |
209 | 211 | ||
210 | int j = 0; | 212 | int j = 0; |
211 | for(j=0;j<1000;j++){ | 213 | for(j=0;j<1000;j++){ |
212 | if(gpio_c!=0xF7){ | 214 | if(gpio_c!=0xF7){ |
213 | snprintf(buffer, sizeof(buffer), "GPIO_C: %02x\n", gpio_c); | 215 | snprintf(buffer, sizeof(buffer), "GPIO_C: %02x\n", gpio_c); |
214 | write(fd,buffer,sizeof(buffer)); | 216 | write(fd,buffer,sizeof(buffer)); |
215 | } | 217 | } |
216 | if(gpio_d!=0xDD){ | 218 | if(gpio_d!=0xDD){ |
217 | snprintf(buffer, sizeof(buffer), "GPIO_D: %02x\n", gpio_d); | 219 | snprintf(buffer, sizeof(buffer), "GPIO_D: %02x\n", gpio_d); |
218 | write(fd,buffer,sizeof(buffer)); | 220 | write(fd,buffer,sizeof(buffer)); |
219 | } | 221 | } |
220 | }*/ | 222 | }*/ |
221 | 223 | ||
222 | 224 | ||
223 | /* Apparently necessary for the data to be actually written to file */ | 225 | /* Apparently necessary for the data to be actually written to file */ |
224 | fsync(fd); | 226 | fsync(fd); |
225 | udelay(1000000); | 227 | udelay(1000000); |
226 | 228 | ||
227 | /* This causes the device to shut off instantly | 229 | /* This causes the device to shut off instantly |
228 | 230 | ||
229 | GPIOF_OUTPUT_VAL = 0; | 231 | GPIOF_OUTPUT_VAL = 0; |
230 | */ | 232 | */ |
231 | 233 | ||
232 | close(fd); | 234 | close(fd); |
233 | udelay(1000000); | 235 | udelay(1000000); |
234 | } | 236 | } |
235 | 237 | ||
236 | /* These functions are present in the firmware library, but we reimplement | 238 | /* These functions are present in the firmware library, but we reimplement |