summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-06-23 05:08:36 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-06-23 05:08:36 +0000
commit1ec821244afc4f671c0c94519cd3a70b2777bf74 (patch)
tree748eead72f705c1e3a91120dc890be49617239c9
parent28bcc17ddef4cfad2d1a669869f2f81f0724acb9 (diff)
downloadrockbox-1ec821244afc4f671c0c94519cd3a70b2777bf74.tar.gz
rockbox-1ec821244afc4f671c0c94519cd3a70b2777bf74.zip
Sansa AMS bootloader: enter USB mode only when needed
- If an error happens when reading partitions / rockbox.sansa - If the select button was pressed add an argument to error() to not power off, when we're going to enter USB mode to try to fix the problem, but display the error message anyway for debugging purpose git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27075 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--bootloader/common.c5
-rw-r--r--bootloader/common.h2
-rw-r--r--bootloader/creativezvm.c4
-rw-r--r--bootloader/gigabeat-s.c6
-rw-r--r--bootloader/gigabeat.c6
-rw-r--r--bootloader/main-e200r-installer.c2
-rw-r--r--bootloader/main-pp.c6
-rw-r--r--bootloader/mini2440.c6
-rw-r--r--bootloader/mrobe500.c6
-rw-r--r--bootloader/ondavx747.c8
-rw-r--r--bootloader/sansa_as3525.c81
-rw-r--r--bootloader/telechips.c6
12 files changed, 76 insertions, 62 deletions
diff --git a/bootloader/common.c b/bootloader/common.c
index 67b5816694..362c3b4d11 100644
--- a/bootloader/common.c
+++ b/bootloader/common.c
@@ -118,7 +118,7 @@ char *strerror(int error)
118 } 118 }
119} 119}
120 120
121void error(int errortype, int error) 121void error(int errortype, int error, bool shutdown)
122{ 122{
123 switch(errortype) 123 switch(errortype)
124 { 124 {
@@ -137,7 +137,8 @@ void error(int errortype, int error)
137 137
138 lcd_update(); 138 lcd_update();
139 sleep(5*HZ); 139 sleep(5*HZ);
140 power_off(); 140 if(shutdown)
141 power_off();
141} 142}
142 143
143/* Load firmware image in a format created by tools/scramble */ 144/* Load firmware image in a format created by tools/scramble */
diff --git a/bootloader/common.h b/bootloader/common.h
index 2cdf5865b2..6713585ad8 100644
--- a/bootloader/common.h
+++ b/bootloader/common.h
@@ -43,7 +43,7 @@ extern bool verbose;
43void reset_screen(void); 43void reset_screen(void);
44void printf(const char *format, ...); 44void printf(const char *format, ...);
45char *strerror(int error); 45char *strerror(int error);
46void error(int errortype, int error); 46void error(int errortype, int error, bool shutdown);
47int load_firmware(unsigned char* buf, char* firmware, int buffer_size); 47int load_firmware(unsigned char* buf, char* firmware, int buffer_size);
48int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size); 48int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size);
49#ifdef ROCKBOX_HAS_LOGF 49#ifdef ROCKBOX_HAS_LOGF
diff --git a/bootloader/creativezvm.c b/bootloader/creativezvm.c
index 73968c3b3f..7dcbac7dcc 100644
--- a/bootloader/creativezvm.c
+++ b/bootloader/creativezvm.c
@@ -96,7 +96,7 @@ void main(void)
96 96
97 ret = disk_mount_all(); 97 ret = disk_mount_all();
98 if (ret <= 0) 98 if (ret <= 0)
99 error(EDISK, ret); 99 error(EDISK, ret, true);
100 100
101 printf("Loading Rockbox firmware..."); 101 printf("Loading Rockbox firmware...");
102 102
@@ -105,7 +105,7 @@ void main(void)
105 105
106 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size); 106 ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
107 if(ret < 0) 107 if(ret < 0)
108 error(EBOOTFILE, ret); 108 error(EBOOTFILE, ret, true);
109 109
110 else if(ret == EOK) 110 else if(ret == EOK)
111 { 111 {
diff --git a/bootloader/gigabeat-s.c b/bootloader/gigabeat-s.c
index dcff26c4de..b6db9e633f 100644
--- a/bootloader/gigabeat-s.c
+++ b/bootloader/gigabeat-s.c
@@ -302,7 +302,7 @@ static void __attribute__((noreturn)) handle_firmware_load(void)
302 load_buf_size); 302 load_buf_size);
303 303
304 if(rc < 0) 304 if(rc < 0)
305 error(EBOOTFILE, rc); 305 error(EBOOTFILE, rc, true);
306 306
307 /* Pause to look at messages */ 307 /* Pause to look at messages */
308 pause_if_button_pressed(false); 308 pause_if_button_pressed(false);
@@ -359,7 +359,7 @@ void main(void)
359 if(rc) 359 if(rc)
360 { 360 {
361 reset_screen(); 361 reset_screen();
362 error(EATA, rc); 362 error(EATA, rc, true);
363 } 363 }
364 364
365 disk_init(); 365 disk_init();
@@ -367,7 +367,7 @@ void main(void)
367 rc = disk_mount_all(); 367 rc = disk_mount_all();
368 if (rc<=0) 368 if (rc<=0)
369 { 369 {
370 error(EDISK,rc); 370 error(EDISK, rc, true);
371 } 371 }
372 372
373 printf("Init complete"); 373 printf("Init complete");
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index 7a634b329c..cfba4bb38d 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -181,7 +181,7 @@ void main(void)
181 if(rc) 181 if(rc)
182 { 182 {
183 reset_screen(); 183 reset_screen();
184 error(EATA, rc); 184 error(EATA, rc, true);
185 } 185 }
186 186
187 disk_init(); 187 disk_init();
@@ -189,7 +189,7 @@ void main(void)
189 rc = disk_mount_all(); 189 rc = disk_mount_all();
190 if (rc<=0) 190 if (rc<=0)
191 { 191 {
192 error(EDISK,rc); 192 error(EDISK, rc, true);
193 } 193 }
194 194
195 printf("Loading firmware"); 195 printf("Loading firmware");
@@ -202,7 +202,7 @@ void main(void)
202 202
203 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); 203 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
204 if(rc < 0) 204 if(rc < 0)
205 error(EBOOTFILE, rc); 205 error(EBOOTFILE, rc, true);
206 206
207 storage_close(); 207 storage_close();
208 system_prepare_fw_start(); 208 system_prepare_fw_start();
diff --git a/bootloader/main-e200r-installer.c b/bootloader/main-e200r-installer.c
index defdea4574..178a03b42e 100644
--- a/bootloader/main-e200r-installer.c
+++ b/bootloader/main-e200r-installer.c
@@ -124,7 +124,7 @@ void* main(void)
124 124
125 if (num_partitions<=0) 125 if (num_partitions<=0)
126 { 126 {
127 error(EDISK,num_partitions); 127 error(EDISK, num_partitions, true);
128 } 128 }
129 129
130 pinfo = disk_partinfo(1); 130 pinfo = disk_partinfo(1);
diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c
index 37f42eda43..f0e9e7cdf3 100644
--- a/bootloader/main-pp.c
+++ b/bootloader/main-pp.c
@@ -540,7 +540,7 @@ void* main(void)
540 } 540 }
541 printf(buf); 541 printf(buf);
542 } else { 542 } else {
543 error(EATA, i); 543 error(EATA, i, true);
544 } 544 }
545#endif 545#endif
546 546
@@ -548,7 +548,7 @@ void* main(void)
548 num_partitions = disk_mount_all(); 548 num_partitions = disk_mount_all();
549 if (num_partitions<=0) 549 if (num_partitions<=0)
550 { 550 {
551 error(EDISK,num_partitions); 551 error(EDISK,num_partitions, true);
552 } 552 }
553 553
554 /* Just list the first 2 partitions since we don't have any devices yet 554 /* Just list the first 2 partitions since we don't have any devices yet
@@ -643,7 +643,7 @@ void* main(void)
643 return (void*)loadbuffer; 643 return (void*)loadbuffer;
644 } 644 }
645 645
646 error(0, 0); 646 error(0, 0, true);
647 } 647 }
648 return (void*)loadbuffer; 648 return (void*)loadbuffer;
649} 649}
diff --git a/bootloader/mini2440.c b/bootloader/mini2440.c
index f4441c3730..23f135cb1a 100644
--- a/bootloader/mini2440.c
+++ b/bootloader/mini2440.c
@@ -85,14 +85,14 @@ int main(void)
85 if(rc) 85 if(rc)
86 { 86 {
87 reset_screen(); 87 reset_screen();
88 error(EATA, rc); 88 error(EATA, rc, true);
89 } 89 }
90 90
91 disk_init(IF_MD(0)); 91 disk_init(IF_MD(0));
92 rc = disk_mount_all(); 92 rc = disk_mount_all();
93 if (rc<=0) 93 if (rc<=0)
94 { 94 {
95 error(EDISK,rc); 95 error(EDISK,rc, true);
96 } 96 }
97 97
98 printf("Loading firmware"); 98 printf("Loading firmware");
@@ -105,7 +105,7 @@ int main(void)
105 105
106 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); 106 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
107 if(rc < 0) 107 if(rc < 0)
108 error(EBOOTFILE, rc); 108 error(EBOOTFILE, rc, true);
109 109
110 printf("Loaded firmware %d\n", rc); 110 printf("Loaded firmware %d\n", rc);
111 111
diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c
index d6ca58e009..39e898b4c0 100644
--- a/bootloader/mrobe500.c
+++ b/bootloader/mrobe500.c
@@ -119,7 +119,7 @@ void main(void)
119 if(rc) 119 if(rc)
120 { 120 {
121 reset_screen(); 121 reset_screen();
122 error(EATA, rc); 122 error(EATA, rc, true);
123 } 123 }
124 124
125 printf("disk"); 125 printf("disk");
@@ -129,7 +129,7 @@ void main(void)
129 rc = disk_mount_all(); 129 rc = disk_mount_all();
130 if (rc<=0) 130 if (rc<=0)
131 { 131 {
132 error(EDISK,rc); 132 error(EDISK,rc, true);
133 } 133 }
134 134
135 printf("Loading firmware"); 135 printf("Loading firmware");
@@ -139,7 +139,7 @@ void main(void)
139 139
140 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); 140 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
141 if(rc < 0) 141 if(rc < 0)
142 error(EBOOTFILE, rc); 142 error(EBOOTFILE, rc, true);
143 143
144 if (rc == EOK) 144 if (rc == EOK)
145 { 145 {
diff --git a/bootloader/ondavx747.c b/bootloader/ondavx747.c
index 4dfc78d58c..2903b04252 100644
--- a/bootloader/ondavx747.c
+++ b/bootloader/ondavx747.c
@@ -94,7 +94,7 @@ static int boot_of(void)
94 printf("Mounting disk..."); 94 printf("Mounting disk...");
95 rc = disk_mount_all(); 95 rc = disk_mount_all();
96 if (rc <= 0) 96 if (rc <= 0)
97 error(EDISK,rc); 97 error(EDISK, rc, true);
98 98
99 /* TODO: get this from the NAND flash instead of SD */ 99 /* TODO: get this from the NAND flash instead of SD */
100 fd = open("/ccpmp.bin", O_RDONLY); 100 fd = open("/ccpmp.bin", O_RDONLY);
@@ -147,7 +147,7 @@ static int boot_rockbox(void)
147 printf("Mounting disk..."); 147 printf("Mounting disk...");
148 rc = disk_mount_all(); 148 rc = disk_mount_all();
149 if (rc <= 0) 149 if (rc <= 0)
150 error(EDISK,rc); 150 error(EDISK,rc, true);
151 151
152 printf("Loading firmware..."); 152 printf("Loading firmware...");
153 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000); 153 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
@@ -172,7 +172,7 @@ static void reset_configuration(void)
172 172
173 rc = disk_mount_all(); 173 rc = disk_mount_all();
174 if (rc <= 0) 174 if (rc <= 0)
175 error(EDISK,rc); 175 error(EDISK,rc, true);
176 176
177 if(rename(ROCKBOX_DIR "/config.cfg", ROCKBOX_DIR "/config.old") == 0) 177 if(rename(ROCKBOX_DIR "/config.cfg", ROCKBOX_DIR "/config.old") == 0)
178 show_splash(HZ/2, "Configuration reset successfully!"); 178 show_splash(HZ/2, "Configuration reset successfully!");
@@ -271,7 +271,7 @@ int main(void)
271 271
272 rc = storage_init(); 272 rc = storage_init();
273 if(rc) 273 if(rc)
274 error(EATA, rc); 274 error(EATA, rc, true);
275 275
276 /* Don't mount the disks yet, there could be file system/partition errors 276 /* Don't mount the disks yet, there could be file system/partition errors
277 which are fixable in USB mode */ 277 which are fixable in USB mode */
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
42int show_logo(void); 40int show_logo(void);
43 41
42static 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
44void main(void) __attribute__((noreturn)); 69void main(void) __attribute__((noreturn));
45void main(void) 70void 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}
diff --git a/bootloader/telechips.c b/bootloader/telechips.c
index 9e9e75c183..adf3e63483 100644
--- a/bootloader/telechips.c
+++ b/bootloader/telechips.c
@@ -158,21 +158,21 @@ void* main(void)
158 if(rc) 158 if(rc)
159 { 159 {
160 reset_screen(); 160 reset_screen();
161 error(EATA, rc); 161 error(EATA, rc, true);
162 } 162 }
163 163
164 printf("mount"); 164 printf("mount");
165 rc = disk_mount_all(); 165 rc = disk_mount_all();
166 if (rc<=0) 166 if (rc<=0)
167 { 167 {
168 error(EDISK,rc); 168 error(EDISK,rc, true);
169 } 169 }
170 170
171 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); 171 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
172 172
173 if (rc < 0) 173 if (rc < 0)
174 { 174 {
175 error(EBOOTFILE,rc); 175 error(EBOOTFILE,rc, true);
176 } 176 }
177 else if (rc == EOK) 177 else if (rc == EOK)
178 { 178 {