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 /* setup stacks in unmapped
58 * iram just as rom will do
61 "ldr r1, =0x18200274 \n"
62 "add r1, r1, #0x200 \n"
65 "add r1, r1, #0x400 \n"
68 /* jump to main() in rom
69 * just before dfu handler
76 void main(void) NORETURN_ATTR
;
79 char filename
[MAX_PATH
];
80 unsigned char* loadbuffer
;
81 void(*kernel_entry
)(void);
83 enum {rb
, of
} boot
= rb
;
96 lcd_setfont(FONT_SYSFIXED
);
100 int btn
= button_read_device();
102 /* if there is some other button pressed
103 * besides POWER/PLAY we boot into OF
105 if ((btn
& ~POWEROFF_BUTTON
))
108 /* if we are woken up by USB insert boot into OF */
109 if (DEV_INFO
& (1<<20))
114 ret
= storage_init();
116 error(EATA
, ret
, true);
118 while(!disk_init(IF_MV(0)))
119 panicf("disk_init failed!");
121 while((ret
= disk_mount_all()) <= 0)
122 error(EDISK
, ret
, true);
124 loadbuffer
= (unsigned char*)DRAM_ORIG
; /* DRAM */
127 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s", BOOTFILE
);
129 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s", "BASE.RKW");
131 printf("Bootloader version: %s", RBVERSION
);
132 printf("Loading: %s", filename
);
134 ret
= load_rkw(loadbuffer
, filename
, LOAD_SIZE
);
137 printf(rkw_strerror(ret
));
141 /* if we boot rockbox we shutdown on error
142 * if we boot OF we fall back to rkusb mode on error
150 /* give visual feedback what we are doing */
151 printf("Entering rockchip USB mode...");
159 /* print 'Loading OK' */
160 printf(rkw_strerror(0));
164 /* jump to entrypoint */
165 kernel_entry
= (void*) loadbuffer
;
166 commit_discard_idcache();
171 /* this should never be reached actually */
172 printf("ERR: Failed to boot");
181 /* give visual feedback what we are doing */
182 printf("Entering rockchip USB mode...");