5 #include "gcc_extensions.h"
10 #include "button-target.h"
19 #include "crc32-rkw.h"
20 #include "rkw-loader.h"
23 /* beginning of DRAM */
24 #define DRAM_ORIG 0x60000000
26 /* bootloader code runs from 0x60700000
27 * so we cannot load more code to not overwrite ourself
29 #define LOAD_SIZE 0x700000
31 extern void show_logo( void );
33 /* This function setup bare minimum
34 * and jumps to rom in order to activate
35 * hardcoded rkusb mode
37 static void enter_rkusb(void)
41 "ldr r0, =0xefff0000 \n"
45 /* Turn off interrupts */
47 "bic r0, r0, #0x1f \n"
48 "orr r0, r0, #0xd3 \n"
51 /* Disable iram remap */
52 "mov r0, #0x18000000 \n"
53 "add r0, r0, #0x1c000 \n"
57 /* Ungate all clocks */
58 "str r1, [r0, #0x18] \n"
60 /* Read SCU_ID to determine
61 * which version of bootrom we have
62 * 2706A has ID 0xa1000604
63 * 2706B and 2705 have ID 0xa10002b7
66 "ldr r2, =0xa1000604 \n"
70 /* Setup stacks in unmapped
71 * iram just as rom will do.
73 * We know about two versions
74 * of bootrom which are very similar
75 * but memory addresses are slightly
79 "ldr r1, =0x18200258 \n"
84 "ldr r1, =0x18200274 \n"
89 "add r1, r1, #0x200 \n"
92 "add r1, r1, #0x400 \n"
95 /* Finaly jump to rkusb handler
103 void main(void) NORETURN_ATTR
;
106 char filename
[MAX_PATH
];
107 unsigned char* loadbuffer
;
108 void(*kernel_entry
)(void);
110 enum {rb
, of
} boot
= rb
;
120 button_init_device();
123 lcd_setfont(FONT_SYSFIXED
);
127 int btn
= button_read_device();
129 /* if there is some other button pressed
130 * besides POWER/PLAY we boot into OF
132 if ((btn
& ~POWEROFF_BUTTON
))
135 /* if we are woken up by USB insert boot into OF */
136 if (DEV_INFO
& (1<<20))
141 ret
= storage_init();
143 error(EATA
, ret
, true);
145 while(!disk_init(IF_MV(0)))
146 panicf("disk_init failed!");
148 while((ret
= disk_mount_all()) <= 0)
149 error(EDISK
, ret
, true);
151 loadbuffer
= (unsigned char*)DRAM_ORIG
; /* DRAM */
154 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s", BOOTFILE
);
156 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s", "BASE.RKW");
158 printf("Bootloader version: %s", RBVERSION
);
159 printf("Loading: %s", filename
);
161 ret
= load_rkw(loadbuffer
, filename
, LOAD_SIZE
);
164 printf(rkw_strerror(ret
));
168 /* if we boot rockbox we shutdown on error
169 * if we boot OF we fall back to rkusb mode on error
177 /* give visual feedback what we are doing */
178 printf("Entering rockchip USB mode...");
186 /* print 'Loading OK' */
187 printf(rkw_strerror(0));
191 /* jump to entrypoint */
192 kernel_entry
= (void*) loadbuffer
;
193 commit_discard_idcache();
198 /* this should never be reached actually */
199 printf("ERR: Failed to boot");
208 /* give visual feedback what we are doing */
209 printf("Entering rockchip USB mode...");