diff options
Diffstat (limited to 'bootloader/sansa_as3525.c')
-rw-r--r-- | bootloader/sansa_as3525.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/bootloader/sansa_as3525.c b/bootloader/sansa_as3525.c index 3eb6159800..4219038d9a 100644 --- a/bootloader/sansa_as3525.c +++ b/bootloader/sansa_as3525.c | |||
@@ -27,10 +27,8 @@ | |||
27 | #include <inttypes.h> | 27 | #include <inttypes.h> |
28 | #include "config.h" | 28 | #include "config.h" |
29 | #include "lcd.h" | 29 | #include "lcd.h" |
30 | #ifdef USE_ROCKBOX_USB | ||
31 | #include "usb.h" | 30 | #include "usb.h" |
32 | #include "sysfont.h" | 31 | #include "sysfont.h" |
33 | #endif /* USE_ROCKBOX_USB */ | ||
34 | #include "backlight.h" | 32 | #include "backlight.h" |
35 | #include "button-target.h" | 33 | #include "button-target.h" |
36 | #include "common.h" | 34 | #include "common.h" |
@@ -41,6 +39,33 @@ | |||
41 | 39 | ||
42 | int show_logo(void); | 40 | int show_logo(void); |
43 | 41 | ||
42 | static void usb_mode(void) | ||
43 | { | ||
44 | if(usb_detect() != USB_INSERTED) | ||
45 | { | ||
46 | const char msg[] = "Plug USB cable"; | ||
47 | reset_screen(); | ||
48 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2, | ||
49 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | ||
50 | lcd_update(); | ||
51 | |||
52 | /* wait until USB is plugged */ | ||
53 | while(usb_detect() != USB_INSERTED) ; | ||
54 | } | ||
55 | |||
56 | const char msg[] = "Bootloader USB mode"; | ||
57 | reset_screen(); | ||
58 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2, | ||
59 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | ||
60 | lcd_update(); | ||
61 | |||
62 | while(usb_detect() == USB_INSERTED) | ||
63 | sleep(HZ); | ||
64 | |||
65 | reset_screen(); | ||
66 | lcd_update(); | ||
67 | } | ||
68 | |||
44 | void main(void) __attribute__((noreturn)); | 69 | void main(void) __attribute__((noreturn)); |
45 | void main(void) | 70 | void main(void) |
46 | { | 71 | { |
@@ -84,53 +109,41 @@ void main(void) | |||
84 | 109 | ||
85 | ret = storage_init(); | 110 | ret = storage_init(); |
86 | if(ret < 0) | 111 | if(ret < 0) |
87 | error(EATA,ret); | 112 | error(EATA, ret, true); |
88 | 113 | ||
89 | #ifdef USE_ROCKBOX_USB | ||
90 | usb_init(); | 114 | usb_init(); |
91 | usb_start_monitoring(); | 115 | usb_start_monitoring(); |
92 | if(usb_detect() == USB_INSERTED) | ||
93 | { | ||
94 | const char msg[] = "Bootloader USB mode"; | ||
95 | reset_screen(); | ||
96 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2, | ||
97 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | ||
98 | lcd_update(); | ||
99 | |||
100 | while(usb_detect() == USB_INSERTED) | ||
101 | sleep(HZ); | ||
102 | |||
103 | reset_screen(); | ||
104 | lcd_update(); | ||
105 | } | ||
106 | #endif /* USE_ROCKBOX_USB */ | ||
107 | 116 | ||
108 | if(!disk_init(IF_MV(0))) | 117 | /* Enter USB mode if USB is plugged and SELECT button is pressed */ |
109 | panicf("disk_init failed!"); | 118 | if(btn & BUTTON_SELECT && usb_detect() == USB_INSERTED) |
119 | usb_mode(); | ||
110 | 120 | ||
111 | ret = disk_mount_all(); | 121 | while(!disk_init(IF_MV(0))) |
122 | usb_mode(); | ||
112 | 123 | ||
113 | if(ret <= 0) | 124 | while((ret = disk_mount_all()) <= 0) |
114 | error(EDISK, ret); | 125 | { |
126 | error(EDISK, ret, false); | ||
127 | usb_mode(); | ||
128 | } | ||
115 | 129 | ||
116 | printf("Loading firmware"); | 130 | printf("Loading firmware"); |
117 | 131 | ||
118 | loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */ | 132 | loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */ |
119 | buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE); | 133 | buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE); |
120 | 134 | ||
121 | ret = load_firmware(loadbuffer, BOOTFILE, buffer_size); | 135 | while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0) |
122 | if(ret < 0) | ||
123 | error(EBOOTFILE, ret); | ||
124 | |||
125 | if (ret == EOK) | ||
126 | { | 136 | { |
127 | kernel_entry = (void*) loadbuffer; | 137 | error(EBOOTFILE, ret, false); |
128 | cpucache_invalidate(); | 138 | usb_mode(); |
129 | printf("Executing"); | ||
130 | kernel_entry(); | ||
131 | printf("ERR: Failed to boot"); | ||
132 | } | 139 | } |
133 | 140 | ||
141 | kernel_entry = (void*) loadbuffer; | ||
142 | cpucache_invalidate(); | ||
143 | printf("Executing"); | ||
144 | kernel_entry(); | ||
145 | printf("ERR: Failed to boot"); | ||
146 | |||
134 | /* never returns */ | 147 | /* never returns */ |
135 | while(1) ; | 148 | while(1) ; |
136 | } | 149 | } |