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 ****************************************************************************/
30 #ifdef USE_ROCKBOX_USB
33 #endif /* USE_ROCKBOX_USB */
34 #include "backlight.h"
35 #include "button-target.h"
44 #ifdef USE_ROCKBOX_USB
45 static void usb_mode(void)
47 if(usb_detect() != USB_INSERTED
)
49 const char msg
[] = "Plug USB cable";
51 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
52 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
55 /* wait until USB is plugged */
56 while(usb_detect() != USB_INSERTED
) ;
59 const char msg
[] = "Bootloader USB mode";
61 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
62 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
65 while(usb_detect() == USB_INSERTED
)
71 #endif /* USE_ROCKBOX_USB */
73 void main(void) __attribute__((noreturn
));
76 unsigned char* loadbuffer
;
78 void(*kernel_entry
)(void);
92 int btn
= button_read_device();
94 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP) && !defined(SANSA_CLIPV2) \
95 && !defined(SANSA_CLIPPLUS)
100 printf("Hold switch on");
101 printf("Shutting down...");
107 /* Enable bootloader messages if any button is pressed */
114 ret
= storage_init();
116 error(EATA
, ret
, true);
118 #ifdef USE_ROCKBOX_USB
120 usb_start_monitoring();
122 /* Enter USB mode if USB is plugged and SELECT button is pressed */
123 if(btn
& BUTTON_SELECT
&& usb_detect() == USB_INSERTED
)
125 #endif /* USE_ROCKBOX_USB */
127 while(!disk_init(IF_MV(0)))
128 #ifdef USE_ROCKBOX_USB
131 panicf("disk_init failed!");
134 while((ret
= disk_mount_all()) <= 0)
136 #ifdef USE_ROCKBOX_USB
137 error(EDISK
, ret
, false);
140 error(EDISK
, ret
, true);
144 printf("Loading firmware");
146 loadbuffer
= (unsigned char*)DRAM_ORIG
; /* DRAM */
147 buffer_size
= (int)(loadbuffer
+ (DRAM_SIZE
) - TTB_SIZE
);
149 while((ret
= load_firmware(loadbuffer
, BOOTFILE
, buffer_size
)) < 0)
151 #ifdef USE_ROCKBOX_USB
152 error(EBOOTFILE
, ret
, false);
155 error(EBOOTFILE
, ret
, true);
159 kernel_entry
= (void*) loadbuffer
;
160 cpucache_invalidate();
163 printf("ERR: Failed to boot");