blob: 11888ef27239528cadf67e943ba730b559755fd3 [file] [log] [blame]
Jens Arnolddbff1f22005-11-27 23:55:13 +00001/***************************************************************************
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 Stenberg2acc0ac2008-06-28 18:10:04 +000016 * 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 Arnolddbff1f22005-11-27 23:55:13 +000020 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25
Jens Arnold4c385142005-11-30 00:05:40 +000026#include "uclimage.h"
27
Jens Arnolddbff1f22005-11-27 23:55:13 +000028#define ICODE_ATTR __attribute__ ((section (".icode")))
Jens Arnolddbff1f22005-11-27 23:55:13 +000029
30/* Symbols defined in the linker script */
31extern char iramcopy[], iramstart[], iramend[];
32extern char stackend[];
Jens Arnolddbff1f22005-11-27 23:55:13 +000033extern char loadaddress[], dramend[];
34
35/* Prototypes */
Jens Arnold104b81e2005-11-28 23:40:57 +000036extern void start(void);
37
Jens Arnolddbff1f22005-11-27 23:55:13 +000038void main(void) ICODE_ATTR;
Jens Arnold2c52dee2008-10-28 21:07:53 +000039int ucl_nrv2e_decompress_8(const unsigned char *src, unsigned char *dst,
40 unsigned long *dst_len) ICODE_ATTR;
Jens Arnolddbff1f22005-11-27 23:55:13 +000041
42/* Vector table */
43void (*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 Arnolddbff1f22005-11-27 23:55:13 +000051/** All subsequent functions are executed from IRAM **/
52
Jens Arnold4c385142005-11-30 00:05:40 +000053#define ALIGNED_IMG_SIZE ((sizeof(image) + 3) & ~3)
Jens Arnolddbff1f22005-11-27 23:55:13 +000054/* This will never return */
55void main(void)
56{
57 unsigned long dst_len; /* dummy */
Jens Arnold4c385142005-11-30 00:05:40 +000058 unsigned long *src = (unsigned long *)image;
59 unsigned long *dst = (unsigned long *)(dramend - ALIGNED_IMG_SIZE);
Jens Arnold104b81e2005-11-28 23:40:57 +000060
61 do
62 *dst++ = *src++;
63 while (dst < (unsigned long *)dramend);
64
Jens Arnold4c385142005-11-30 00:05:40 +000065 ucl_nrv2e_decompress_8(dramend - ALIGNED_IMG_SIZE, loadaddress, &dst_len);
Jens Arnolddbff1f22005-11-27 23:55:13 +000066
67 asm(
68 "mov.l @%0+,r0 \n"
Jens Arnolddbff1f22005-11-27 23:55:13 +000069 "jmp @r0 \n"
Jens Arnold104b81e2005-11-28 23:40:57 +000070 "mov.l @%0+,r15 \n"
Jens Arnolddbff1f22005-11-27 23:55:13 +000071 : : "r"(loadaddress) : "r0"
72 );
73}