Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Jens Arnold |
| 11 | * |
| 12 | * Self-extracting firmware loader to work around the 200KB size limit |
| 13 | * for archos player and recorder v1 |
| 14 | * Decompresses a built-in UCL-compressed image (method 2e) and executes it. |
| 15 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License |
| 18 | * as published by the Free Software Foundation; either version 2 |
| 19 | * of the License, or (at your option) any later version. |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 20 | * |
| 21 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 22 | * KIND, either express or implied. |
| 23 | * |
| 24 | ****************************************************************************/ |
| 25 | |
Jens Arnold | 4c38514 | 2005-11-30 00:05:40 +0000 | [diff] [blame] | 26 | #include "uclimage.h" |
| 27 | |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 28 | #define ICODE_ATTR __attribute__ ((section (".icode"))) |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 29 | |
| 30 | /* Symbols defined in the linker script */ |
| 31 | extern char iramcopy[], iramstart[], iramend[]; |
| 32 | extern char stackend[]; |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 33 | extern char loadaddress[], dramend[]; |
| 34 | |
| 35 | /* Prototypes */ |
Jens Arnold | 104b81e | 2005-11-28 23:40:57 +0000 | [diff] [blame] | 36 | extern void start(void); |
| 37 | |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 38 | void main(void) ICODE_ATTR; |
Jens Arnold | 2c52dee | 2008-10-28 21:07:53 +0000 | [diff] [blame] | 39 | int ucl_nrv2e_decompress_8(const unsigned char *src, unsigned char *dst, |
| 40 | unsigned long *dst_len) ICODE_ATTR; |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 41 | |
| 42 | /* Vector table */ |
| 43 | void (*vbr[]) (void) __attribute__ ((section (".vectors"))) = |
| 44 | { |
| 45 | start, (void *)stackend, |
| 46 | start, (void *)stackend, |
| 47 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 49 | }; |
| 50 | |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 51 | /** All subsequent functions are executed from IRAM **/ |
| 52 | |
Jens Arnold | 4c38514 | 2005-11-30 00:05:40 +0000 | [diff] [blame] | 53 | #define ALIGNED_IMG_SIZE ((sizeof(image) + 3) & ~3) |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 54 | /* This will never return */ |
| 55 | void main(void) |
| 56 | { |
| 57 | unsigned long dst_len; /* dummy */ |
Jens Arnold | 4c38514 | 2005-11-30 00:05:40 +0000 | [diff] [blame] | 58 | unsigned long *src = (unsigned long *)image; |
| 59 | unsigned long *dst = (unsigned long *)(dramend - ALIGNED_IMG_SIZE); |
Jens Arnold | 104b81e | 2005-11-28 23:40:57 +0000 | [diff] [blame] | 60 | |
| 61 | do |
| 62 | *dst++ = *src++; |
| 63 | while (dst < (unsigned long *)dramend); |
| 64 | |
Jens Arnold | 4c38514 | 2005-11-30 00:05:40 +0000 | [diff] [blame] | 65 | ucl_nrv2e_decompress_8(dramend - ALIGNED_IMG_SIZE, loadaddress, &dst_len); |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 66 | |
| 67 | asm( |
| 68 | "mov.l @%0+,r0 \n" |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 69 | "jmp @r0 \n" |
Jens Arnold | 104b81e | 2005-11-28 23:40:57 +0000 | [diff] [blame] | 70 | "mov.l @%0+,r15 \n" |
Jens Arnold | dbff1f2 | 2005-11-27 23:55:13 +0000 | [diff] [blame] | 71 | : : "r"(loadaddress) : "r0" |
| 72 | ); |
| 73 | } |