diff options
Diffstat (limited to 'bootloader/main-pp.c')
-rw-r--r-- | bootloader/main-pp.c | 225 |
1 files changed, 46 insertions, 179 deletions
diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c index 1da24b7d9b..a02510e31c 100644 --- a/bootloader/main-pp.c +++ b/bootloader/main-pp.c @@ -19,156 +19,27 @@ * KIND, either express or implied. * ****************************************************************************/ -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdarg.h> +#include "common.h" #include "cpu.h" +#include "file.h" #include "system.h" -#include "lcd.h" #include "kernel.h" -#include "thread.h" -#include "ata.h" -#include "fat.h" -#include "disk.h" +#include "lcd.h" #include "font.h" -#include "adc.h" -#include "backlight.h" +#include "ata.h" #include "button.h" -#include "panic.h" +#include "disk.h" #include "power.h" -#include "file.h" -/* Size of the buffer to store the loaded firmware image */ +/* Maximum allowed firmware image size. 10MB is more than enough */ #define MAX_LOADSIZE (10*1024*1024) -/* A buffer to load the iriver firmware or Rockbox into */ -unsigned char loadbuffer[MAX_LOADSIZE]; +/* A buffer to load the original firmware or Rockbox into */ +unsigned char *loadbuffer = (unsigned char *)DRAM_START; +/* Bootloader version */ char version[] = APPSVERSION; -#define DRAM_START 0x10000000 - -int line=0; -char printfbuf[256]; - -void reset_screen(void) -{ - lcd_clear_display(); - line = 0; -} - -void printf(const char *format, ...) -{ - int len; - unsigned char *ptr; - va_list ap; - va_start(ap, format); - - - ptr = printfbuf; - len = vsnprintf(ptr, sizeof(printfbuf), format, ap); - va_end(ap); - - lcd_puts(0, line++, ptr); - lcd_update(); - if(line >= (LCD_HEIGHT/SYSFONT_HEIGHT)) - line = 0; -} - -/* Load original mi4 firmware. This function expects a file called - "/System/OF.bin" on the player. It should be a mi4 firmware decrypted - and header stripped using mi4code. It reads the file in to a memory - buffer called buf. The rest of the loading is done in main() and crt0.S -*/ -int load_original_firmware(unsigned char* buf) -{ - int fd; - int rc; - int len; - - fd = open("/System/OF.bin", O_RDONLY); - - len = filesize(fd); - - if (len > MAX_LOADSIZE) - return -6; - - rc = read(fd, buf, len); - if(rc < len) - return -4; - - close(fd); - return len; -} - -/* Load Rockbox firmware (rockbox.*) */ -int load_rockbox(unsigned char* buf) -{ - int fd; - int rc; - int len; - unsigned long chksum; - char model[5]; - unsigned long sum; - int i; - - fd = open("/.rockbox/" BOOTFILE, O_RDONLY); - if(fd < 0) - { - fd = open("/" BOOTFILE, O_RDONLY); - if(fd < 0) - return -1; - } - - len = filesize(fd) - 8; - - printf("Length: %x", len); - - if (len > MAX_LOADSIZE) - return -6; - - lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); - - rc = read(fd, &chksum, 4); - chksum=betoh32(chksum); /* Rockbox checksums are big-endian */ - if(rc < 4) - return -2; - - printf("Checksum: %x", chksum); - - rc = read(fd, model, 4); - if(rc < 4) - return -3; - - model[4] = 0; - - printf("Model name: %s", model); - - lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); - - rc = read(fd, buf, len); - if(rc < len) - return -4; - - close(fd); - - sum = MODEL_NUMBER; - - for(i = 0;i < len;i++) { - sum += buf[i]; - } - - printf("Sum: %x", sum); - - if(sum != chksum) - return -5; - - return len; -} - void* main(void) { char buf[256]; @@ -183,8 +54,6 @@ void* main(void) font_init(); button_init(); - line=0; - lcd_setfont(FONT_SYSFIXED); printf("Rockbox boot loader"); @@ -193,18 +62,20 @@ void* main(void) i=ata_init(); if (i==0) { - identify_info=ata_get_identify(); - /* Show model */ - for (i=0; i < 20; i++) { - ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); - } - buf[40]=0; - for (i=39; i && buf[i]==' '; i--) { - buf[i]=0; - } - printf(buf); + identify_info=ata_get_identify(); + /* Show model */ + for (i=0; i < 20; i++) { + ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); + } + buf[40]=0; + for (i=39; i && buf[i]==' '; i--) { + buf[i]=0; + } + printf(buf); } else { - printf("ATA: %d", i); + printf("ATA error: %d", i); + sleep(HZ*5); + power_off(); } disk_init(); @@ -212,6 +83,8 @@ void* main(void) if (rc<=0) { printf("No partition found"); + sleep(HZ*5); + power_off(); } pinfo = disk_partinfo(0); @@ -220,39 +93,37 @@ void* main(void) i=button_read_device(); if(i==BUTTON_LEFT) { + /* Load original mi4 firmware. This expects a file called + "/System/OF.bin" on the player. It should be a mi4 firmware decrypted + and header stripped using mi4code. It reads the file in to a memory + buffer called loadbuffer. The rest of the loading is done in crt0.S + */ printf("Loading original firmware..."); - rc=load_original_firmware(loadbuffer); + rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE); + if (rc < EOK) { + printf("Error!"); + printf("Can't load /System/OF.bin:"); + printf(strerror(rc)); + sleep(HZ*5); + power_off(); + } } else { printf("Loading Rockbox..."); - rc=load_rockbox(loadbuffer); + rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE); + if (rc < EOK) { + printf("Error!"); + printf("Can't load %s:", BOOTFILE); + printf(strerror(rc)); + sleep(HZ*5); + power_off(); + } } - - if (rc < 0) { - printf("Rockbox error: %d",rc); - while(1) {} - } - - memcpy((void*)DRAM_START,loadbuffer,rc); - return (void*)DRAM_START; + return (void*)loadbuffer; } /* These functions are present in the firmware library, but we reimplement them here because the originals do a lot more than we want */ - -void reset_poweroff_timer(void) -{ -} - -int dbg_ports(void) -{ - return 0; -} - -void mpeg_stop(void) -{ -} - void usb_acknowledge(void) { } @@ -260,7 +131,3 @@ void usb_acknowledge(void) void usb_wait_for_disconnect(void) { } - -void sys_poweroff(void) -{ -} |