2011-05-30 21:10:37 +00:00
|
|
|
#include <stdio.h>
|
2012-02-28 14:51:36 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include "config.h"
|
2014-01-05 19:32:09 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
2012-02-28 14:51:36 +00:00
|
|
|
#include "gcc_extensions.h"
|
2011-05-30 21:10:37 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "font.h"
|
2012-02-28 14:51:36 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "button-target.h"
|
|
|
|
#include "button.h"
|
2011-05-30 21:10:37 +00:00
|
|
|
#include "common.h"
|
2012-02-28 14:51:36 +00:00
|
|
|
#include "storage.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "crc32-rkw.h"
|
2012-03-03 23:06:20 +00:00
|
|
|
#include "rkw-loader.h"
|
2012-04-30 13:54:06 +00:00
|
|
|
#include "version.h"
|
2013-04-30 11:18:27 +00:00
|
|
|
#include "i2c-rk27xx.h"
|
2012-03-04 14:34:29 +00:00
|
|
|
#include "loader_strerror.h"
|
2011-06-05 10:26:06 +00:00
|
|
|
|
2012-04-27 14:19:31 +00:00
|
|
|
/* beginning of DRAM */
|
2012-02-28 14:51:36 +00:00
|
|
|
#define DRAM_ORIG 0x60000000
|
2012-04-27 14:19:31 +00:00
|
|
|
|
|
|
|
/* bootloader code runs from 0x60700000
|
|
|
|
* so we cannot load more code to not overwrite ourself
|
|
|
|
*/
|
2012-02-28 14:51:36 +00:00
|
|
|
#define LOAD_SIZE 0x700000
|
2011-06-05 10:26:06 +00:00
|
|
|
|
2012-02-28 14:51:36 +00:00
|
|
|
extern void show_logo( void );
|
2011-06-05 10:26:06 +00:00
|
|
|
|
2012-04-27 14:19:31 +00:00
|
|
|
/* This function setup bare minimum
|
|
|
|
* and jumps to rom in order to activate
|
|
|
|
* hardcoded rkusb mode
|
|
|
|
*/
|
|
|
|
static void enter_rkusb(void)
|
|
|
|
{
|
|
|
|
asm volatile (
|
2012-07-10 07:10:30 +00:00
|
|
|
/* Turn off cache */
|
2012-04-27 14:19:31 +00:00
|
|
|
"ldr r0, =0xefff0000 \n"
|
|
|
|
"ldrh r1, [r0] \n"
|
|
|
|
"strh r1, [r0] \n"
|
|
|
|
|
2012-07-10 07:10:30 +00:00
|
|
|
/* Turn off interrupts */
|
2012-04-27 14:19:31 +00:00
|
|
|
"mrs r0, cpsr \n"
|
|
|
|
"bic r0, r0, #0x1f \n"
|
|
|
|
"orr r0, r0, #0xd3 \n"
|
|
|
|
"msr cpsr, r0 \n"
|
|
|
|
|
2012-07-10 07:10:30 +00:00
|
|
|
/* Disable iram remap */
|
2012-04-27 14:19:31 +00:00
|
|
|
"mov r0, #0x18000000 \n"
|
|
|
|
"add r0, r0, #0x1c000 \n"
|
|
|
|
"mov r1, #0 \n"
|
|
|
|
"str r1, [r0, #4] \n"
|
|
|
|
|
2012-07-10 07:10:30 +00:00
|
|
|
/* Ungate all clocks */
|
|
|
|
"str r1, [r0, #0x18] \n"
|
|
|
|
|
|
|
|
/* Read SCU_ID to determine
|
|
|
|
* which version of bootrom we have
|
|
|
|
* 2706A has ID 0xa1000604
|
2013-11-23 21:43:19 +00:00
|
|
|
* 2706B and 2705 have ID 0xa100027b
|
2012-04-27 14:19:31 +00:00
|
|
|
*/
|
2012-07-10 07:10:30 +00:00
|
|
|
"ldr r1, [r0] \n"
|
|
|
|
"ldr r2, =0xa1000604 \n"
|
|
|
|
"cmp r1, r2 \n"
|
|
|
|
"bne rk27xx_new \n"
|
|
|
|
|
|
|
|
/* Setup stacks in unmapped
|
|
|
|
* iram just as rom will do.
|
|
|
|
*
|
|
|
|
* We know about two versions
|
|
|
|
* of bootrom which are very similar
|
|
|
|
* but memory addresses are slightly
|
|
|
|
* different.
|
|
|
|
*/
|
|
|
|
"rk27xx_old: \n"
|
|
|
|
"ldr r1, =0x18200258 \n"
|
|
|
|
"ldr r0, =0xaf0 \n"
|
|
|
|
"b jump_to_rom \n"
|
|
|
|
|
|
|
|
"rk27xx_new: \n"
|
2012-04-27 14:19:31 +00:00
|
|
|
"ldr r1, =0x18200274 \n"
|
2012-07-10 07:10:30 +00:00
|
|
|
"ldr r0, =0xec0 \n"
|
|
|
|
|
|
|
|
"jump_to_rom: \n"
|
|
|
|
"msr cpsr, #0xd2 \n"
|
2012-04-27 14:19:31 +00:00
|
|
|
"add r1, r1, #0x200 \n"
|
|
|
|
"mov sp, r1 \n"
|
|
|
|
"msr cpsr, #0xd3 \n"
|
|
|
|
"add r1, r1, #0x400 \n"
|
|
|
|
"mov sp, r1 \n"
|
|
|
|
|
2012-07-10 07:10:30 +00:00
|
|
|
/* Finaly jump to rkusb handler
|
|
|
|
* in bootrom.
|
2012-04-27 14:19:31 +00:00
|
|
|
*/
|
|
|
|
"bx r0 \n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-07-10 07:10:30 +00:00
|
|
|
|
2012-02-28 14:51:36 +00:00
|
|
|
void main(void) NORETURN_ATTR;
|
2011-05-30 21:10:37 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2012-02-28 14:51:36 +00:00
|
|
|
char filename[MAX_PATH];
|
|
|
|
unsigned char* loadbuffer;
|
|
|
|
void(*kernel_entry)(void);
|
|
|
|
int ret;
|
|
|
|
enum {rb, of} boot = rb;
|
2011-05-30 21:10:37 +00:00
|
|
|
|
2012-02-28 14:51:36 +00:00
|
|
|
power_init();
|
2011-05-30 21:10:37 +00:00
|
|
|
system_init();
|
|
|
|
kernel_init();
|
2013-04-29 07:04:20 +00:00
|
|
|
i2c_init();
|
2011-05-30 21:10:37 +00:00
|
|
|
enable_irq();
|
|
|
|
|
2012-02-28 14:51:36 +00:00
|
|
|
adc_init();
|
|
|
|
lcd_init();
|
|
|
|
backlight_init();
|
|
|
|
button_init_device();
|
|
|
|
|
2011-05-30 21:10:37 +00:00
|
|
|
font_init();
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
show_logo();
|
2012-02-28 14:51:36 +00:00
|
|
|
|
|
|
|
int btn = button_read_device();
|
|
|
|
|
|
|
|
/* if there is some other button pressed
|
|
|
|
* besides POWER/PLAY we boot into OF
|
|
|
|
*/
|
|
|
|
if ((btn & ~POWEROFF_BUTTON))
|
|
|
|
boot = of;
|
|
|
|
|
|
|
|
/* if we are woken up by USB insert boot into OF */
|
|
|
|
if (DEV_INFO & (1<<20))
|
|
|
|
boot = of;
|
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
|
|
|
ret = storage_init();
|
|
|
|
if(ret < 0)
|
|
|
|
error(EATA, ret, true);
|
|
|
|
|
|
|
|
while(!disk_init(IF_MV(0)))
|
|
|
|
panicf("disk_init failed!");
|
|
|
|
|
|
|
|
while((ret = disk_mount_all()) <= 0)
|
|
|
|
error(EDISK, ret, true);
|
|
|
|
|
|
|
|
loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
|
|
|
|
|
|
|
|
if (boot == rb)
|
|
|
|
snprintf(filename,sizeof(filename), BOOTDIR "/%s", BOOTFILE);
|
|
|
|
else if (boot == of)
|
|
|
|
snprintf(filename,sizeof(filename), BOOTDIR "/%s", "BASE.RKW");
|
|
|
|
|
2012-04-30 13:54:06 +00:00
|
|
|
printf("Bootloader version: %s", RBVERSION);
|
2012-02-28 14:51:36 +00:00
|
|
|
printf("Loading: %s", filename);
|
|
|
|
|
|
|
|
ret = load_rkw(loadbuffer, filename, LOAD_SIZE);
|
2012-03-04 14:34:29 +00:00
|
|
|
|
|
|
|
if (ret <= EFILE_EMPTY)
|
2012-02-28 14:51:36 +00:00
|
|
|
{
|
2012-03-04 14:34:29 +00:00
|
|
|
error(EBOOTFILE, ret, false);
|
2012-04-27 14:19:31 +00:00
|
|
|
|
|
|
|
/* if we boot rockbox we shutdown on error
|
|
|
|
* if we boot OF we fall back to rkusb mode on error
|
|
|
|
*/
|
|
|
|
if (boot == rb)
|
|
|
|
{
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* give visual feedback what we are doing */
|
|
|
|
printf("Entering rockchip USB mode...");
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
enter_rkusb();
|
|
|
|
}
|
2012-02-28 14:51:36 +00:00
|
|
|
}
|
|
|
|
else
|
2011-05-30 21:10:37 +00:00
|
|
|
{
|
2012-04-27 14:19:31 +00:00
|
|
|
/* print 'Loading OK' */
|
2012-03-04 14:34:29 +00:00
|
|
|
printf("Loading OK");
|
2012-02-28 14:51:36 +00:00
|
|
|
sleep(HZ);
|
2011-05-30 21:10:37 +00:00
|
|
|
}
|
2012-02-28 14:51:36 +00:00
|
|
|
|
2012-04-27 14:19:31 +00:00
|
|
|
/* jump to entrypoint */
|
2012-02-28 14:51:36 +00:00
|
|
|
kernel_entry = (void*) loadbuffer;
|
|
|
|
commit_discard_idcache();
|
|
|
|
|
|
|
|
printf("Executing");
|
|
|
|
kernel_entry();
|
|
|
|
|
2012-04-27 14:19:31 +00:00
|
|
|
/* this should never be reached actually */
|
2012-02-28 14:51:36 +00:00
|
|
|
printf("ERR: Failed to boot");
|
|
|
|
sleep(5*HZ);
|
2012-04-27 14:19:31 +00:00
|
|
|
|
|
|
|
if (boot == rb)
|
|
|
|
{
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* give visual feedback what we are doing */
|
|
|
|
printf("Entering rockchip USB mode...");
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
enter_rkusb();
|
|
|
|
}
|
2012-02-28 14:51:36 +00:00
|
|
|
|
|
|
|
/* hang */
|
|
|
|
while(1);
|
2011-05-30 21:10:37 +00:00
|
|
|
}
|