Fix FS#12606 - next track can cause the screen to be cleared
[maemo-rb.git] / bootloader / rk27xx.c
blobdfba9704c22d39c741bc8674ab5284ad2643c534
1 #include <stdio.h>
2 #include <system.h>
3 #include <inttypes.h>
4 #include "config.h"
5 #include "gcc_extensions.h"
6 #include "lcd.h"
7 #include "font.h"
8 #include "backlight.h"
9 #include "adc.h"
10 #include "button-target.h"
11 #include "button.h"
12 #include "common.h"
13 #include "storage.h"
14 #include "disk.h"
15 #include "panic.h"
16 #include "power.h"
17 #include "string.h"
18 #include "file.h"
19 #include "crc32-rkw.h"
20 #include "rkw-loader.h"
22 #define DRAM_ORIG 0x60000000
23 #define LOAD_SIZE 0x700000
25 extern void show_logo( void );
27 void main(void) NORETURN_ATTR;
28 void main(void)
30 char filename[MAX_PATH];
31 unsigned char* loadbuffer;
32 void(*kernel_entry)(void);
33 int ret;
34 enum {rb, of} boot = rb;
36 power_init();
37 system_init();
38 kernel_init();
39 enable_irq();
41 adc_init();
42 lcd_init();
43 backlight_init();
44 button_init_device();
46 font_init();
47 lcd_setfont(FONT_SYSFIXED);
49 show_logo();
51 int btn = button_read_device();
53 /* if there is some other button pressed
54 * besides POWER/PLAY we boot into OF
56 if ((btn & ~POWEROFF_BUTTON))
57 boot = of;
59 /* if we are woken up by USB insert boot into OF */
60 if (DEV_INFO & (1<<20))
61 boot = of;
63 lcd_clear_display();
65 ret = storage_init();
66 if(ret < 0)
67 error(EATA, ret, true);
69 while(!disk_init(IF_MV(0)))
70 panicf("disk_init failed!");
72 while((ret = disk_mount_all()) <= 0)
73 error(EDISK, ret, true);
75 loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
77 if (boot == rb)
78 snprintf(filename,sizeof(filename), BOOTDIR "/%s", BOOTFILE);
79 else if (boot == of)
80 snprintf(filename,sizeof(filename), BOOTDIR "/%s", "BASE.RKW");
82 printf("Loading: %s", filename);
84 ret = load_rkw(loadbuffer, filename, LOAD_SIZE);
85 if (ret < 0)
87 printf(rkw_strerror(ret));
88 lcd_update();
89 sleep(5*HZ);
90 power_off();
92 else
94 printf(rkw_strerror(0));
95 sleep(HZ);
98 kernel_entry = (void*) loadbuffer;
99 commit_discard_idcache();
101 printf("Executing");
102 kernel_entry();
104 printf("ERR: Failed to boot");
105 sleep(5*HZ);
106 power_off();
108 /* hang */
109 while(1);