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 ****************************************************************************/
32 #include "backlight.h"
33 #include "button-target.h"
42 static void usb_mode(void)
44 if(usb_detect() != USB_INSERTED
)
46 const char msg
[] = "Plug USB cable";
48 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
49 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
52 /* wait until USB is plugged */
53 while(usb_detect() != USB_INSERTED
) ;
56 const char msg
[] = "Bootloader USB mode";
58 lcd_putsxy( (LCD_WIDTH
- (SYSFONT_WIDTH
* sizeof(msg
))) / 2,
59 (LCD_HEIGHT
- SYSFONT_HEIGHT
) / 2, msg
);
62 while(usb_detect() == USB_INSERTED
)
69 void main(void) __attribute__((noreturn
));
72 unsigned char* loadbuffer
;
74 void(*kernel_entry
)(void);
88 int btn
= button_read_device();
90 #if !defined(SANSA_FUZE) && !defined(SANSA_CLIP) && !defined(SANSA_CLIPV2) \
91 && !defined(SANSA_CLIPPLUS)
96 printf("Hold switch on");
97 printf("Shutting down...");
103 /* Enable bootloader messages if any button is pressed */
110 ret
= storage_init();
112 error(EATA
, ret
, true);
115 usb_start_monitoring();
117 /* Enter USB mode if USB is plugged and SELECT button is pressed */
118 if(btn
& BUTTON_SELECT
&& usb_detect() == USB_INSERTED
)
121 while(!disk_init(IF_MV(0)))
124 while((ret
= disk_mount_all()) <= 0)
126 error(EDISK
, ret
, false);
130 printf("Loading firmware");
132 loadbuffer
= (unsigned char*)DRAM_ORIG
; /* DRAM */
133 buffer_size
= (int)(loadbuffer
+ (DRAM_SIZE
) - TTB_SIZE
);
135 while((ret
= load_firmware(loadbuffer
, BOOTFILE
, buffer_size
)) < 0)
137 error(EBOOTFILE
, ret
, false);
141 kernel_entry
= (void*) loadbuffer
;
142 cpucache_invalidate();
145 printf("ERR: Failed to boot");