1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Rafaël Carré
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
29 #include "gcc_extensions.h"
31 #ifdef USE_ROCKBOX_USB
34 #endif /* USE_ROCKBOX_USB */
35 #include "backlight.h"
36 #include "button-target.h"
45 #ifdef USE_ROCKBOX_USB
46 static void usb_mode(void)
48 if(usb_detect() != USB_INSERTED
)
50 static const char msg
[] = "Plug USB cable";
52 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
53 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
56 /* wait until USB is plugged */
57 while(usb_detect() != USB_INSERTED
) ;
60 static const char msg
[] = "Bootloader USB mode";
62 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
63 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
66 while(usb_detect() == USB_INSERTED
)
72 #endif /* USE_ROCKBOX_USB */
74 void main(void) NORETURN_ATTR
;
77 unsigned char* loadbuffer
;
79 void(*kernel_entry
)(void);
93 int btn
= button_read_device();
95 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP) && !defined(SANSA_CLIPV2) \
96 && !defined(SANSA_CLIPPLUS)
101 printf("Hold switch on");
102 printf("Shutting down...");
108 /* Enable bootloader messages if any button is pressed */
115 ret
= storage_init();
117 error(EATA
, ret
, true);
119 #ifdef USE_ROCKBOX_USB
121 usb_start_monitoring();
123 /* Enter USB mode if USB is plugged and SELECT button is pressed */
124 if(btn
& BUTTON_SELECT
&& usb_detect() == USB_INSERTED
)
126 #endif /* USE_ROCKBOX_USB */
128 while(!disk_init(IF_MV(0)))
129 #ifdef USE_ROCKBOX_USB
132 panicf("disk_init failed!");
135 while((ret
= disk_mount_all()) <= 0)
137 #ifdef USE_ROCKBOX_USB
138 error(EDISK
, ret
, false);
141 error(EDISK
, ret
, true);
145 printf("Loading firmware");
147 loadbuffer
= (unsigned char*)DRAM_ORIG
; /* DRAM */
148 buffer_size
= (int)(loadbuffer
+ (DRAM_SIZE
) - TTB_SIZE
);
150 while((ret
= load_firmware(loadbuffer
, BOOTFILE
, buffer_size
)) < 0)
152 #ifdef USE_ROCKBOX_USB
153 error(EBOOTFILE
, ret
, false);
156 error(EBOOTFILE
, ret
, true);
160 kernel_entry
= (void*) loadbuffer
;
161 cpucache_invalidate();
164 printf("ERR: Failed to boot");