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
This commit is contained in:
Rafaël Carré 2010-06-23 05:08:36 +00:00
parent 28bcc17dde
commit 1ec821244a
12 changed files with 77 additions and 63 deletions

View File

@ -118,7 +118,7 @@ char *strerror(int error)
}
}
void error(int errortype, int error)
void error(int errortype, int error, bool shutdown)
{
switch(errortype)
{
@ -137,7 +137,8 @@ void error(int errortype, int error)
lcd_update();
sleep(5*HZ);
power_off();
if(shutdown)
power_off();
}
/* Load firmware image in a format created by tools/scramble */

View File

@ -43,7 +43,7 @@ extern bool verbose;
void reset_screen(void);
void printf(const char *format, ...);
char *strerror(int error);
void error(int errortype, int error);
void error(int errortype, int error, bool shutdown);
int load_firmware(unsigned char* buf, char* firmware, int buffer_size);
int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size);
#ifdef ROCKBOX_HAS_LOGF

View File

@ -96,7 +96,7 @@ void main(void)
ret = disk_mount_all();
if (ret <= 0)
error(EDISK, ret);
error(EDISK, ret, true);
printf("Loading Rockbox firmware...");
@ -105,7 +105,7 @@ void main(void)
ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
if(ret < 0)
error(EBOOTFILE, ret);
error(EBOOTFILE, ret, true);
else if(ret == EOK)
{

View File

@ -302,7 +302,7 @@ static void __attribute__((noreturn)) handle_firmware_load(void)
load_buf_size);
if(rc < 0)
error(EBOOTFILE, rc);
error(EBOOTFILE, rc, true);
/* Pause to look at messages */
pause_if_button_pressed(false);
@ -359,7 +359,7 @@ void main(void)
if(rc)
{
reset_screen();
error(EATA, rc);
error(EATA, rc, true);
}
disk_init();
@ -367,7 +367,7 @@ void main(void)
rc = disk_mount_all();
if (rc<=0)
{
error(EDISK,rc);
error(EDISK, rc, true);
}
printf("Init complete");

View File

@ -181,7 +181,7 @@ void main(void)
if(rc)
{
reset_screen();
error(EATA, rc);
error(EATA, rc, true);
}
disk_init();
@ -189,7 +189,7 @@ void main(void)
rc = disk_mount_all();
if (rc<=0)
{
error(EDISK,rc);
error(EDISK, rc, true);
}
printf("Loading firmware");
@ -202,7 +202,7 @@ void main(void)
rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
if(rc < 0)
error(EBOOTFILE, rc);
error(EBOOTFILE, rc, true);
storage_close();
system_prepare_fw_start();

View File

@ -124,7 +124,7 @@ void* main(void)
if (num_partitions<=0)
{
error(EDISK,num_partitions);
error(EDISK, num_partitions, true);
}
pinfo = disk_partinfo(1);

View File

@ -540,7 +540,7 @@ void* main(void)
}
printf(buf);
} else {
error(EATA, i);
error(EATA, i, true);
}
#endif
@ -548,7 +548,7 @@ void* main(void)
num_partitions = disk_mount_all();
if (num_partitions<=0)
{
error(EDISK,num_partitions);
error(EDISK,num_partitions, true);
}
/* Just list the first 2 partitions since we don't have any devices yet
@ -643,7 +643,7 @@ void* main(void)
return (void*)loadbuffer;
}
error(0, 0);
error(0, 0, true);
}
return (void*)loadbuffer;
}

View File

@ -85,14 +85,14 @@ int main(void)
if(rc)
{
reset_screen();
error(EATA, rc);
error(EATA, rc, true);
}
disk_init(IF_MD(0));
rc = disk_mount_all();
if (rc<=0)
{
error(EDISK,rc);
error(EDISK,rc, true);
}
printf("Loading firmware");
@ -105,7 +105,7 @@ int main(void)
rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
if(rc < 0)
error(EBOOTFILE, rc);
error(EBOOTFILE, rc, true);
printf("Loaded firmware %d\n", rc);

View File

@ -119,7 +119,7 @@ void main(void)
if(rc)
{
reset_screen();
error(EATA, rc);
error(EATA, rc, true);
}
printf("disk");
@ -129,7 +129,7 @@ void main(void)
rc = disk_mount_all();
if (rc<=0)
{
error(EDISK,rc);
error(EDISK,rc, true);
}
printf("Loading firmware");
@ -139,7 +139,7 @@ void main(void)
rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
if(rc < 0)
error(EBOOTFILE, rc);
error(EBOOTFILE, rc, true);
if (rc == EOK)
{

View File

@ -94,7 +94,7 @@ static int boot_of(void)
printf("Mounting disk...");
rc = disk_mount_all();
if (rc <= 0)
error(EDISK,rc);
error(EDISK, rc, true);
/* TODO: get this from the NAND flash instead of SD */
fd = open("/ccpmp.bin", O_RDONLY);
@ -147,7 +147,7 @@ static int boot_rockbox(void)
printf("Mounting disk...");
rc = disk_mount_all();
if (rc <= 0)
error(EDISK,rc);
error(EDISK,rc, true);
printf("Loading firmware...");
rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
@ -172,7 +172,7 @@ static void reset_configuration(void)
rc = disk_mount_all();
if (rc <= 0)
error(EDISK,rc);
error(EDISK,rc, true);
if(rename(ROCKBOX_DIR "/config.cfg", ROCKBOX_DIR "/config.old") == 0)
show_splash(HZ/2, "Configuration reset successfully!");
@ -271,7 +271,7 @@ int main(void)
rc = storage_init();
if(rc)
error(EATA, rc);
error(EATA, rc, true);
/* Don't mount the disks yet, there could be file system/partition errors
which are fixable in USB mode */

View File

@ -27,10 +27,8 @@
#include <inttypes.h>
#include "config.h"
#include "lcd.h"
#ifdef USE_ROCKBOX_USB
#include "usb.h"
#include "sysfont.h"
#endif /* USE_ROCKBOX_USB */
#include "backlight.h"
#include "button-target.h"
#include "common.h"
@ -41,6 +39,33 @@
int show_logo(void);
static void usb_mode(void)
{
if(usb_detect() != USB_INSERTED)
{
const char msg[] = "Plug USB cable";
reset_screen();
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2,
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
lcd_update();
/* wait until USB is plugged */
while(usb_detect() != USB_INSERTED) ;
}
const char msg[] = "Bootloader USB mode";
reset_screen();
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2,
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
lcd_update();
while(usb_detect() == USB_INSERTED)
sleep(HZ);
reset_screen();
lcd_update();
}
void main(void) __attribute__((noreturn));
void main(void)
{
@ -84,53 +109,41 @@ void main(void)
ret = storage_init();
if(ret < 0)
error(EATA,ret);
error(EATA, ret, true);
#ifdef USE_ROCKBOX_USB
usb_init();
usb_start_monitoring();
if(usb_detect() == USB_INSERTED)
/* Enter USB mode if USB is plugged and SELECT button is pressed */
if(btn & BUTTON_SELECT && usb_detect() == USB_INSERTED)
usb_mode();
while(!disk_init(IF_MV(0)))
usb_mode();
while((ret = disk_mount_all()) <= 0)
{
const char msg[] = "Bootloader USB mode";
reset_screen();
lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * sizeof(msg))) / 2,
(LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
lcd_update();
while(usb_detect() == USB_INSERTED)
sleep(HZ);
reset_screen();
lcd_update();
error(EDISK, ret, false);
usb_mode();
}
#endif /* USE_ROCKBOX_USB */
if(!disk_init(IF_MV(0)))
panicf("disk_init failed!");
ret = disk_mount_all();
if(ret <= 0)
error(EDISK, ret);
printf("Loading firmware");
loadbuffer = (unsigned char*)DRAM_ORIG; /* DRAM */
buffer_size = (int)(loadbuffer + (DRAM_SIZE) - TTB_SIZE);
ret = load_firmware(loadbuffer, BOOTFILE, buffer_size);
if(ret < 0)
error(EBOOTFILE, ret);
if (ret == EOK)
while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0)
{
kernel_entry = (void*) loadbuffer;
cpucache_invalidate();
printf("Executing");
kernel_entry();
printf("ERR: Failed to boot");
error(EBOOTFILE, ret, false);
usb_mode();
}
kernel_entry = (void*) loadbuffer;
cpucache_invalidate();
printf("Executing");
kernel_entry();
printf("ERR: Failed to boot");
/* never returns */
while(1) ;
}

View File

@ -158,21 +158,21 @@ void* main(void)
if(rc)
{
reset_screen();
error(EATA, rc);
error(EATA, rc, true);
}
printf("mount");
rc = disk_mount_all();
if (rc<=0)
{
error(EDISK,rc);
error(EDISK,rc, true);
}
rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
if (rc < 0)
{
error(EBOOTFILE,rc);
error(EBOOTFILE,rc, true);
}
else if (rc == EOK)
{