summaryrefslogtreecommitdiffstats
path: root/bootloader/gigabeat.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2007-02-22 15:09:49 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2007-02-22 15:09:49 +0000
commit46597c953963eb8333e5122896fdcb4d0ec9f93f (patch)
tree434605a340de75938beb7cb996f57c333649f88e /bootloader/gigabeat.c
parent9744433752b59a5da45c8076c4be6d2980d8cbbb (diff)
downloadrockbox-46597c953963eb8333e5122896fdcb4d0ec9f93f.tar.gz
rockbox-46597c953963eb8333e5122896fdcb4d0ec9f93f.tar.bz2
rockbox-46597c953963eb8333e5122896fdcb4d0ec9f93f.zip
FS#6554 - Move bootloader code into a common file
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12453 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r--bootloader/gigabeat.c148
1 files changed, 42 insertions, 106 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index a466f9498f..f9073028fb 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -18,11 +18,10 @@
#include "power.h"
#include "file.h"
#include "button-target.h"
+#include "common.h"
extern void map_memory(void);
-int line = 0;
-
char version[] = APPSVERSION;
static void go_usb_mode(void)
@@ -55,30 +54,25 @@ int restore_fwimg01dat(void)
int orig_file = 0, dest_file = 0;
int size = 0, size_read;
static char buf[4096];
- char lcd_buf[64];
-
+
orig_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT.ORIG", O_RDONLY);
if(orig_file < 0) {
/* Couldn't open source file */
- lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for reading");
- lcd_update();
+ printf("Couldn't open FWIMG01.DAT.ORIG for reading");
return(1);
}
- lcd_puts(0, line++, "FWIMG01.DAT.ORIG opened for reading");
- lcd_update();
+ printf("FWIMG01.DAT.ORIG opened for reading");
dest_file = open("/GBSYSTEM/FWIMG/FWIMG01.DAT", O_RDWR);
if(dest_file < 0) {
/* Couldn't open destination file */
- lcd_puts(0, line++, "Couldn't open FWIMG01.DAT.ORIG for writing");
- lcd_update();
+ printf("Couldn't open FWIMG01.DAT.ORIG for writing");
close(orig_file);
return(2);
}
- lcd_puts(0, line++, "FWIMG01.DAT opened for writing");
- lcd_update();
+ printf("FWIMG01.DAT opened for writing");
do {
/* Copy in chunks */
@@ -95,65 +89,22 @@ int restore_fwimg01dat(void)
close(orig_file);
close(dest_file);
- snprintf(lcd_buf, sizeof(lcd_buf), "Finished copying %ld bytes from", size);
- lcd_puts(0, line++, lcd_buf);
- lcd_puts(0, line++, "FWIMG01.DAT.ORIG to FWIMG01.DAT");
+ printf("Finished copying %ld bytes from", size);
+ printf("FWIMG01.DAT.ORIG to FWIMG01.DAT");
return(0);
}
-
-int load_rockbox(const char* file_name, unsigned char* buf, int buffer_size)
-{
- int fd;
- int rc;
- int len;
- char str[256];
-
- fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
- if(fd < 0) {
- fd = open("/" BOOTFILE, O_RDONLY);
- if(fd < 0)
- return -1;
- }
- fd = open(file_name, O_RDONLY);
- if(fd < 0)
- return -2;
-
- len = filesize(fd);
-
- if(len > buffer_size) {
- snprintf(str, sizeof(str), "len: %d buf: %d", len, buffer_size);
- lcd_puts(0, line++, str);
- lcd_update();
- return -6;
- }
-
- rc = read(fd, buf, len);
- if(rc < len) {
- snprintf(str, sizeof(str), "len: %d rc: %d", len, rc);
- lcd_puts(0, line++, str);
- lcd_update();
- return -4;
- }
-
- close(fd);
-
- return len;
-}
-
char buf[256];
void display_instructions(void)
{
lcd_setfont(FONT_SYSFIXED);
- lcd_puts(0, line++, "Hold MENU when booting for rescue mode.");
- lcd_puts(0, line++, " \"VOL+\" button to restore original kernel");
- lcd_puts(0, line++, " \"A\" button to load original firmware");
- line++;
- snprintf(buf, sizeof(buf), "FRAME %x TTB %x", FRAME, TTB_BASE);
- lcd_puts(0, line++, buf);
- lcd_update();
+ printf("Hold MENU when booting for rescue mode.");
+ printf(" \"VOL+\" button to restore original kernel");
+ printf(" \"A\" button to load original firmware");
+ printf("");
+ printf("FRAME %x TTB %x", FRAME, TTB_BASE);
}
void * main(void)
@@ -179,23 +130,20 @@ void * main(void)
}
if(GPGDAT & 2) {
lcd_init();
- lcd_puts(0, line++, "Entering rescue mode..");
- lcd_update();
+ printf("Entering rescue mode..");
go_usb_mode();
while(1);
}
if(GPGDAT & 0x10) {
lcd_init();
load_original = true;
- lcd_puts(0, line++, "Loading original firmware...");
- lcd_update();
+ printf("Loading original firmware...");
}
i = ata_init();
i = disk_mount_all();
if(!show_bootsplash) {
- snprintf(buf, sizeof(buf), "disk_mount_all: %d", i);
- lcd_puts(0, line++, buf);
+ printf("disk_mount_all: %d", i);
}
if(show_bootsplash) {
int fd = open("/bootsplash.raw", O_RDONLY);
@@ -216,17 +164,15 @@ void * main(void)
if(GPGDAT & 4) {
/* Try to restore the original kernel/bootloader if a copy is found */
- lcd_puts(0, line++, "Restoring FWIMG01.DAT...");
- lcd_update();
+ printf("Restoring FWIMG01.DAT...");
if(!restore_fwimg01dat()) {
- lcd_puts(0, line++, "Restoring FWIMG01.DAT successful.");
+ printf("Restoring FWIMG01.DAT successful.");
} else {
- lcd_puts(0, line++, "Restoring FWIMG01.DAT failed.");
+ printf("Restoring FWIMG01.DAT failed.");
}
- lcd_puts(0, line++, "Now power cycle to boot original");
- lcd_update();
+ printf("Now power cycle to boot original");
while(1);
}
@@ -242,76 +188,66 @@ void * main(void)
for(i=39; i && buf[i]==' '; i--)
buf[i] = 0;
- lcd_puts(0, line++, "Model");
- lcd_puts(0, line++, buf);
+ printf("Model");
+ printf(buf);
for(i=0; i < 4; i++)
((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
buf[8]=0;
- lcd_puts(0, line++, "Firmware");
- lcd_puts(0, line++, buf);
+ printf("Firmware");
+ printf(buf);
pinfo = disk_partinfo(0);
- snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB",
- pinfo->type, pinfo->size / 2048);
- lcd_puts(0, line++, buf);
- lcd_update();
+ printf("Partition 0: 0x%02x %ld MB", pinfo->type, pinfo->size / 2048);
}
/* Load original firmware */
if(load_original) {
loadbuffer = (unsigned char*)0x30008000;
buffer_size =(unsigned char*)0x31000000 - loadbuffer;
- rc = load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size);
- if(rc < 0) {
- lcd_puts(0, line++, "failed to load original firmware. Loading rockbox");
- lcd_update();
+ rc = load_firmware("rockbox.gigabeat", loadbuffer, buffer_size);
+ if(rc < EOK) {
+ printf("Error!");
+ printf("Failed to load original firmware:");
+ printf(strerror(rc));
+ printf("Loading rockbox");
sleep(2*HZ);
goto load_rockbox;
}
- snprintf(buf, sizeof(buf), "Loaded: %d", rc);
- lcd_puts(0, line++, buf);
- lcd_update();
+ printf("Loaded: %d", rc);
sleep(2*HZ);
(*((int*)0x7000000)) = 333;
rc = *((int*)0x7000000+0x8000000);
- snprintf(buf, sizeof(buf), "Bank0 mem test: %d", rc);
- lcd_puts(0, line++, buf);
- lcd_update();
+ printf("Bank0 mem test: %d", rc);
sleep(3*HZ);
- lcd_puts(0, line++, "Woops, should not return from firmware!");
- lcd_update();
+ printf("Woops, should not return from firmware!");
goto usb;
}
load_rockbox:
map_memory();
if(!show_bootsplash) {
- lcd_puts(0, line, "Loading Rockbox...");
- lcd_update();
+ printf("Loading Rockbox...");
}
loadbuffer = (unsigned char*) 0x100;
buffer_size = (unsigned char*)0x400000 - loadbuffer;
- rc=load_rockbox("/rockbox.gigabeat", loadbuffer, buffer_size);
- if(rc < 0) {
- snprintf(buf, sizeof(buf), "Rockbox error: %d",rc);
- lcd_puts(0, line++, buf);
- lcd_update();
+ rc=load_firmware("rockbox.gigabeat", loadbuffer, buffer_size);
+ if(rc < EOK) {
+ printf("Error!");
+ printf("Can't load rockbox.gigabeat:");
+ printf(strerror(rc));
} else {
if(!show_bootsplash) {
- lcd_puts(0, line++, "Rockbox loaded.");
- lcd_update();
+ printf("Rockbox loaded.");
}
kernel_entry = (void*) loadbuffer;
rc = kernel_entry();
- snprintf(buf, sizeof(buf), "Woops, should not return from firmware: %d", rc);
- lcd_puts(0, line++, buf);
- lcd_update();
+ printf("Woops, should not return from firmware: %d", rc);
goto usb;
}
usb: