2011-05-30 21:10:37 +00:00
|
|
|
#include <stdio.h>
|
2012-02-28 14:51:36 +00:00
|
|
|
#include <system.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "config.h"
|
|
|
|
#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"
|
2011-06-05 10:26:06 +00:00
|
|
|
|
2012-02-28 14:51:36 +00:00
|
|
|
#define DRAM_ORIG 0x60000000
|
|
|
|
#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-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();
|
|
|
|
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");
|
|
|
|
|
|
|
|
printf("Loading: %s", filename);
|
|
|
|
|
|
|
|
ret = load_rkw(loadbuffer, filename, LOAD_SIZE);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf(rkw_strerror(ret));
|
|
|
|
lcd_update();
|
|
|
|
sleep(5*HZ);
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
else
|
2011-05-30 21:10:37 +00:00
|
|
|
{
|
2012-02-28 14:51:36 +00:00
|
|
|
printf(rkw_strerror(0));
|
|
|
|
sleep(HZ);
|
2011-05-30 21:10:37 +00:00
|
|
|
}
|
2012-02-28 14:51:36 +00:00
|
|
|
|
|
|
|
kernel_entry = (void*) loadbuffer;
|
|
|
|
commit_discard_idcache();
|
|
|
|
|
|
|
|
printf("Executing");
|
|
|
|
kernel_entry();
|
|
|
|
|
|
|
|
printf("ERR: Failed to boot");
|
|
|
|
sleep(5*HZ);
|
|
|
|
power_off();
|
|
|
|
|
|
|
|
/* hang */
|
|
|
|
while(1);
|
2011-05-30 21:10:37 +00:00
|
|
|
}
|