From cb7e695ef9d0166b77f14d6d260733f0ff888f13 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Thu, 5 Jan 2006 17:02:48 +0000 Subject: iPod: Fix the bootloader so it can load and run the original Apple firmware again. The Rockbox firmware was doing too much to the hardware so we remove most of the initialisation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8301 a1c6a512-1295-4272-9138-f99709370657 --- bootloader/ipod.c | 11 ++++++++++- firmware/crt0.S | 8 ++++---- firmware/drivers/power.c | 2 ++ firmware/export/config-ipodcolor.h | 2 ++ firmware/export/config-ipodnano.h | 2 ++ firmware/export/config-ipodvideo.h | 2 ++ firmware/export/kernel.h | 6 ++++++ firmware/kernel.c | 11 ++++++++++- firmware/system.c | 11 +++++++---- 9 files changed, 45 insertions(+), 10 deletions(-) diff --git a/bootloader/ipod.c b/bootloader/ipod.c index 5b8c0ee217..b1722086e1 100644 --- a/bootloader/ipod.c +++ b/bootloader/ipod.c @@ -415,7 +415,16 @@ void* main(void) lcd_puts(0, line++, "Rockbox loaded."); lcd_update(); memcpy((void*)DRAM_START,loadbuffer,rc); - return (void*)DRAM_START; + + /* Transfer execution directly to Rockbox - we don't want + to run the rest of the bootloader startup code. */ + asm volatile( + "mov r0, #0x10000000 \n" + "mov pc, r0 \n" + ); + + /* We don't get here, but keep the compiler happy. */ + return (void*)0; } } diff --git a/firmware/crt0.S b/firmware/crt0.S index df2ff5884d..9dad41944a 100644 --- a/firmware/crt0.S +++ b/firmware/crt0.S @@ -197,12 +197,13 @@ start_loc: /* execute the loader - this will load an image to 0x10000000 */ bl main + /* The loader only returns if it is loading the Apple firmware or Linux - + the following code isn't executed when starting Rockbox */ + /* save the startup address for the COP */ ldr r1, =startup_loc str r0, [r1] -#if 0 -/* TODO: fix something for the COP to wake up to, until then let it sleep. */ #if CONFIG_CPU==PP5002 /* make sure COP is sleeping */ ldr r4, =0xcf004050 @@ -227,8 +228,7 @@ start_loc: @ldr r4, =PP5020_COP_CTRL mov r3, #0x0 str r3, [r4] -#endif -#endif +#endif /* jump to start location */ mov pc, r0 diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index 04168f9895..141d985ee6 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c @@ -262,8 +262,10 @@ void power_off(void) #if CONFIG_CPU == MCF5249 and_l(~0x00080000, &GPIO1_OUT); #elif CONFIG_CPU == PP5020 +#ifndef BOOTLOADER /* We don't turn off the ipod, we put it in a deep sleep */ pcf50605_standby_mode(); +#endif #elif defined(GMINI_ARCH) P1 &= ~1; P1CON &= ~1; diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h index 6de461f952..778055f3d7 100644 --- a/firmware/export/config-ipodcolor.h +++ b/firmware/export/config-ipodcolor.h @@ -27,7 +27,9 @@ #define CONFIG_CODEC SWCODEC /* define this if you have a real-time clock */ +#ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#endif /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h index bf7362a168..86cc279bb8 100644 --- a/firmware/export/config-ipodnano.h +++ b/firmware/export/config-ipodnano.h @@ -27,7 +27,9 @@ #define CONFIG_CODEC SWCODEC /* define this if you have a real-time clock */ +#ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#endif /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h index 3c3f403983..e06e999e1c 100644 --- a/firmware/export/config-ipodvideo.h +++ b/firmware/export/config-ipodvideo.h @@ -27,7 +27,9 @@ #define CONFIG_CODEC SWCODEC /* define this if you have a real-time clock */ +#ifndef BOOTLOADER #define CONFIG_RTC RTC_PCF50605 +#endif /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 23c7bc7cb1..42d160bcea 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h @@ -66,7 +66,13 @@ struct mutex }; /* global tick variable */ +#if (CONFIG_CPU == PP5020) && defined(BOOTLOADER) +/* We don't enable interrupts in the iPod bootloader, so we need to fake + the current_tick variable */ +#define current_tick ((*((volatile long*)0x60005010))/10000) +#else extern long current_tick; +#endif #ifdef SIMULATOR #define sleep(x) sim_sleep(x) diff --git a/firmware/kernel.c b/firmware/kernel.c index 6166437282..a353c4bdc9 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c @@ -25,7 +25,9 @@ #include "system.h" #include "panic.h" +#if (CONFIG_CPU != PP5020) || !defined(BOOTLOADER) long current_tick = 0; +#endif static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); @@ -48,7 +50,7 @@ void kernel_init(void) num_queues = 0; memset(all_queues, 0, sizeof(all_queues)); - + tick_start(1000/HZ); } @@ -319,6 +321,7 @@ void tick_start(unsigned int interval_in_ms) #define USECS_PER_INT 0x2710 +#ifndef BOOTLOADER void TIMER1(void) { int i; @@ -336,9 +339,11 @@ void TIMER1(void) current_tick++; wake_up_thread(); } +#endif void tick_start(unsigned int interval_in_ms) { +#ifndef BOOTLOADER /* TODO: use interval_in_ms to set timer periode */ (void)interval_in_ms; PP5020_TIMER1 = 0x0; @@ -347,6 +352,10 @@ void tick_start(unsigned int interval_in_ms) PP5020_TIMER1 = 0xc0000000 | USECS_PER_INT; /* unmask interrupt source */ PP5020_CPU_INT_EN = PP5020_TIMER1_MASK; +#else + /* We don't enable interrupts in the bootloader */ + (void)interval_in_ms; +#endif } #endif diff --git a/firmware/system.c b/firmware/system.c index 0015b3a55d..7afa3f720e 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -1106,6 +1106,7 @@ int system_memory_guard(int newmode) } #elif CONFIG_CPU==PP5020 +#ifndef BOOTLOADER extern void TIMER1(void); extern void ipod_4g_button_int(void); @@ -1116,6 +1117,7 @@ void irq(void) else if (PP5020_CPU_HI_INT_STAT & PP5020_I2C_MASK) ipod_4g_button_int(); } +#endif /* TODO: The following two function have been lifted straight from IPL, and hence have a lot of numeric addresses used straight. I'd like to use @@ -1124,11 +1126,10 @@ void irq(void) to extend the funtions to do alternate cache configurations and/or some other CPU frequency scaling. */ +#ifndef BOOTLOADER static void ipod_init_cache(void) { -/* Initialising the cache in the iPod Video bootloader prevents - Rockbox from starting */ -#if !defined(BOOTLOADER) || !defined(APPLE_IPODVIDEO) +/* Initialising the cache in the iPod bootloader prevents Rockbox from starting */ unsigned i; /* cache init mode? */ @@ -1147,7 +1148,6 @@ static void ipod_init_cache(void) for (i = 0x10000000; i < 0x10002000; i += 16) inb(i); -#endif } static void ipod_set_cpu_speed(void) @@ -1163,9 +1163,11 @@ static void ipod_set_cpu_speed(void) outl((inl(0x60006020) & 0x0fffff0f) | 0x20000070, 0x60006020); } +#endif void system_init(void) { +#ifndef BOOTLOADER /* disable all irqs */ outl(-1, 0x60001138); outl(-1, 0x60001128); @@ -1176,6 +1178,7 @@ void system_init(void) outl(-1, 0x6000101c); ipod_set_cpu_speed(); ipod_init_cache(); +#endif } void system_reboot(void) -- cgit v1.2.3