From 2f16d4f1b3e52f0a268fa9679a72694f5a89dedf Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Tue, 19 Dec 2006 11:33:53 +0000 Subject: Add working dual-boot bootloaders for H10 and Sansa, which allow booting the OF and Rockbox. Rolo also works. Changes made: Combine bootloader/h10.c and bootloader/e200.c into a common bootloader file (bootloader/main-pp.c) to be used by all mi4 based PortalPlayer targets. The file bootloader/main-pp.c is based off the old bootloader/h10.c with some minor changes to allow it to work on the Sansa too. This effectively adds a Sansa bootloader. Define MODEL_NAME string in config-*.h for use in bootloader. Split crt0-pp.S into separate files for bootloader and normal builds. Bootloader code is now in crt0-pp-bl.S while normal build code stays in crt0-pp.S. Improvements to crt0-pp.S and crt0-pp-bl.S (mostly to make it more multiprocessor safe): * Leave space in bootloader at 0xe0-0xeb since scramble writes over there when it creates the mi4 file (don't leave space for iPods since it's not needed and all code in crt0-pp-bl.S needs to fit before the boot_table at 0x100). * Remove unused DEBUG and STUB code from crt0-pp.S. * Make CPU wait for COP to be sleeping when we put the COP to sleep. * Invalidate COP cache when COP wakes * Flush CPU cache before waking COP * Make sure only the CPU clears the BSS (not the COP) * Make sure only the CPU sets up its own stack (not the COP) Rolo works on H10, so enable it. Make Sansa e200 use rockbox.e200 rather than PP5022.mi4 for 'Normal' builds. This makes updating rockbox simpler as we don't need to go through the firmware update procedure, but rather just put a new rockbox.e200 on the device. rockbox.e200 uses a simple 'add' checksum. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11815 a1c6a512-1295-4272-9138-f99709370657 --- bootloader/SOURCES | 6 +- bootloader/e200.c | 190 ------------------------------------- bootloader/h10.c | 261 -------------------------------------------------- bootloader/main-pp.c | 263 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 265 insertions(+), 455 deletions(-) delete mode 100644 bootloader/e200.c delete mode 100644 bootloader/h10.c create mode 100644 bootloader/main-pp.c (limited to 'bootloader') diff --git a/bootloader/SOURCES b/bootloader/SOURCES index 94f5a60e6b..b86365b429 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES @@ -2,10 +2,8 @@ ipod.c #elif defined(GIGABEAT_F) gigabeat.c -#elif defined(SANSA_E200) -e200.c -#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) -h10.c +#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(SANSA_E200) +main-pp.c #elif defined(ELIO_TPJ1022) tpj1022.c #else diff --git a/bootloader/e200.c b/bootloader/e200.c deleted file mode 100644 index 27b1118a1c..0000000000 --- a/bootloader/e200.c +++ /dev/null @@ -1,190 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 Daniel Stenberg - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include "cpu.h" -#include "system.h" -#include "lcd.h" -#include "kernel.h" -#include "thread.h" -#include "ata.h" -#include "fat.h" -#include "disk.h" -#include "font.h" -#include "adc.h" -#include "backlight.h" -#include "panic.h" -#include "power.h" -#include "file.h" - -static inline void blink(void) -{ - volatile unsigned int* ptr; - int i; - ptr = (volatile unsigned int*)0x70000020; - - *ptr &= ~(1 << 13); - for(i = 0; i < 0xfffff; i++) - { - } - *ptr |= (1 << 13); - for(i = 0; i < 0xfffff; i++) - { - } -} - -static inline void slow_blink(void) -{ - volatile unsigned int* ptr; - int i; - ptr = (volatile unsigned int*)0x70000020; - - *ptr &= ~(1 << 13); - for(i = 0; i < (0xfffff); i++) - { - } - for(i = 0; i < (0xfffff); i++) - { - } - for(i = 0; i < (0xfffff); i++) - { - } - - *ptr |= (1 << 13); - for(i = 0; i < (0xfffff); i++) - { - } - for(i = 0; i < (0xfffff); i++) - { - } - for(i = 0; i < (0xfffff); i++) - { - } -} - -static inline unsigned long get_pc(void) -{ - unsigned long pc; - asm volatile ( - "mov %0, pc\n" - : "=r"(pc) - ); - return pc; -} - -/* 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) -{ - unsigned int gpio_a, gpio_b, gpio_c, gpio_d; - unsigned int gpio_e, gpio_f, gpio_g, gpio_h; - unsigned int gpio_i, gpio_j, gpio_k, gpio_l; - - char buf[128]; - int line; - - lcd_setmargins(0, 0); - lcd_clear_display(); - lcd_setfont(FONT_SYSFIXED); - - while(1) - { - gpio_a = GPIOA_INPUT_VAL; - gpio_b = GPIOB_INPUT_VAL; - gpio_c = GPIOC_INPUT_VAL; - - gpio_g = GPIOG_INPUT_VAL; - gpio_h = GPIOH_INPUT_VAL; - gpio_i = GPIOI_INPUT_VAL; - - line = 0; - snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i); - lcd_puts(0, line++, buf); - line++; - - gpio_d = GPIOD_INPUT_VAL; - gpio_e = GPIOE_INPUT_VAL; - gpio_f = GPIOF_INPUT_VAL; - - gpio_j = GPIOJ_INPUT_VAL; - gpio_k = GPIOK_INPUT_VAL; - gpio_l = GPIOL_INPUT_VAL; - - snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l); - lcd_puts(0, line++, buf); - line++; - snprintf(buf, sizeof(buf), "ADC_1: %02x", adc_read(ADC_0)); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "ADC_2: %02x", adc_read(ADC_1)); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "ADC_3: %02x", adc_read(ADC_2)); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "ADC_4: %02x", adc_read(ADC_3)); - lcd_puts(0, line++, buf); - lcd_update(); - } - return 0; -} - -void mpeg_stop(void) -{ -} - -void usb_acknowledge(void) -{ -} - -void usb_wait_for_disconnect(void) -{ -} - -void sys_poweroff(void) -{ -} - -void system_reboot(void) -{ - -} - -void main(void) -{ - kernel_init(); - adc_init(); - lcd_init_device(); - - dbg_ports(); -} - diff --git a/bootloader/h10.c b/bootloader/h10.c deleted file mode 100644 index 0cfd64a96e..0000000000 --- a/bootloader/h10.c +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2006 by Barry Wardell - * - * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing - * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include "cpu.h" -#include "system.h" -#include "lcd.h" -#include "kernel.h" -#include "thread.h" -#include "ata.h" -#include "fat.h" -#include "disk.h" -#include "font.h" -#include "adc.h" -#include "backlight.h" -#include "button.h" -#include "panic.h" -#include "power.h" -#include "file.h" - -/* Size of the buffer to store the loaded Rockbox/iriver image */ -#define MAX_LOADSIZE (5*1024*1024) - -/* A buffer to load the iriver firmware or Rockbox into */ -unsigned char loadbuffer[MAX_LOADSIZE]; - -char version[] = APPSVERSION; - -#define DRAM_START 0x10000000 - -int line=0; - -/* Load original iriver firmware. This function expects a file called - "/System/Original.mi4" on the player. It should be decrypted - and have the 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_iriver(unsigned char* buf) -{ - int fd; - int rc; - int len; - - fd = open("/System/Original.mi4", 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.h10) */ -int load_rockbox(unsigned char* buf) -{ - int fd; - int rc; - int len; - unsigned long chksum; - char model[5]; - unsigned long sum; - int i; - char str[80]; - - fd = open("/.rockbox/" BOOTFILE, O_RDONLY); - if(fd < 0) - { - fd = open("/" BOOTFILE, O_RDONLY); - if(fd < 0) - return -1; - } - - len = filesize(fd) - 8; - - snprintf(str, sizeof(str), "Length: %x", len); - lcd_puts(0, line++ ,str); - lcd_update(); - - 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; - - snprintf(str, sizeof(str), "Checksum: %x", chksum); - lcd_puts(0, line++ ,str); - lcd_update(); - - rc = read(fd, model, 4); - if(rc < 4) - return -3; - - model[4] = 0; - - snprintf(str, sizeof(str), "Model name: %s", model); - lcd_puts(0, line++ ,str); - lcd_update(); - - 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]; - } - - snprintf(str, sizeof(str), "Sum: %x", sum); - lcd_puts(0, line++ ,str); - lcd_update(); - - if(sum != chksum) - return -5; - - return len; -} - -void* main(void) -{ - char buf[256]; - int i; - int rc; - unsigned short* identify_info; - struct partinfo* pinfo; - - system_init(); - kernel_init(); - lcd_init(); - font_init(); - - line=0; - - lcd_setfont(FONT_SYSFIXED); - - lcd_puts(0, line++, "Rockbox boot loader"); - snprintf(buf, sizeof(buf), "Version: 20%s", version); - lcd_puts(0, line++, buf); - snprintf(buf, sizeof(buf), "iriver H10"); - lcd_puts(0, line++, buf); - lcd_update(); - - 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; - } - lcd_puts(0, line++, buf); - lcd_update(); - } else { - snprintf(buf, sizeof(buf), "ATA: %d", i); - lcd_puts(0, line++, buf); - lcd_update(); - } - - disk_init(); - rc = disk_mount_all(); - if (rc<=0) - { - lcd_puts(0, line++, "No partition found"); - lcd_update(); - } - - 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(); - - i=button_read_device(); - if(i==BUTTON_LEFT) - { - lcd_puts(0, line, "Loading iriver firmware..."); - lcd_update(); - rc=load_iriver(loadbuffer); - } else { - lcd_puts(0, line, "Loading Rockbox..."); - lcd_update(); - rc=load_rockbox(loadbuffer); - } - - if (rc < 0) { - snprintf(buf, sizeof(buf), "Rockbox error: %d",rc); - lcd_puts(0, line++, buf); - lcd_update(); - } - - memcpy((void*)DRAM_START,loadbuffer,rc); - - return (void*)DRAM_START; -} - -/* 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) -{ -} - -void usb_wait_for_disconnect(void) -{ -} - -void sys_poweroff(void) -{ -} diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c new file mode 100644 index 0000000000..a533cc7044 --- /dev/null +++ b/bootloader/main-pp.c @@ -0,0 +1,263 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Barry Wardell + * + * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing + * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" + +#include +#include +#include +#include "cpu.h" +#include "system.h" +#include "lcd.h" +#include "kernel.h" +#include "thread.h" +#include "ata.h" +#include "fat.h" +#include "disk.h" +#include "font.h" +#include "adc.h" +#include "backlight.h" +#include "button.h" +#include "panic.h" +#include "power.h" +#include "file.h" + +/* Size of the buffer to store the loaded firmware image */ +#define MAX_LOADSIZE (10*1024*1024) + +/* A buffer to load the iriver firmware or Rockbox into */ +unsigned char loadbuffer[MAX_LOADSIZE]; + +char version[] = APPSVERSION; + +#define DRAM_START 0x10000000 + +int 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; + char str[80]; + + fd = open("/.rockbox/" BOOTFILE, O_RDONLY); + if(fd < 0) + { + fd = open("/" BOOTFILE, O_RDONLY); + if(fd < 0) + return -1; + } + + len = filesize(fd) - 8; + + snprintf(str, sizeof(str), "Length: %x", len); + lcd_puts(0, line++ ,str); + lcd_update(); + + 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; + + snprintf(str, sizeof(str), "Checksum: %x", chksum); + lcd_puts(0, line++ ,str); + lcd_update(); + + rc = read(fd, model, 4); + if(rc < 4) + return -3; + + model[4] = 0; + + snprintf(str, sizeof(str), "Model name: %s", model); + lcd_puts(0, line++ ,str); + lcd_update(); + + 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]; + } + + snprintf(str, sizeof(str), "Sum: %x", sum); + lcd_puts(0, line++ ,str); + lcd_update(); + + if(sum != chksum) + return -5; + + return len; +} + +void* main(void) +{ + char buf[256]; + int i; + int rc; + unsigned short* identify_info; + struct partinfo* pinfo; + + system_init(); + kernel_init(); + lcd_init(); + font_init(); + button_init(); + + line=0; + + lcd_setfont(FONT_SYSFIXED); + + lcd_puts(0, line++, "Rockbox boot loader"); + snprintf(buf, sizeof(buf), "Version: 20%s", version); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), MODEL_NAME); + lcd_puts(0, line++, buf); + lcd_update(); + + 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; + } + lcd_puts(0, line++, buf); + lcd_update(); + } else { + snprintf(buf, sizeof(buf), "ATA: %d", i); + lcd_puts(0, line++, buf); + lcd_update(); + } + + disk_init(); + rc = disk_mount_all(); + if (rc<=0) + { + lcd_puts(0, line++, "No partition found"); + lcd_update(); + } + + 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(); + + i=button_read_device(); + if(i==BUTTON_LEFT) + { + lcd_puts(0, line++, "Loading original firmware..."); + lcd_update(); + rc=load_original_firmware(loadbuffer); + } else { + lcd_puts(0, line++, "Loading Rockbox..."); + lcd_update(); + rc=load_rockbox(loadbuffer); + } + + if (rc < 0) { + snprintf(buf, sizeof(buf), "Rockbox error: %d",rc); + lcd_puts(0, line++, buf); + lcd_update(); + while(1) {} + } + + memcpy((void*)DRAM_START,loadbuffer,rc); + + return (void*)DRAM_START; +} + +/* 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) +{ +} + +void usb_wait_for_disconnect(void) +{ +} + +void sys_poweroff(void) +{ +} -- cgit v1.2.3