summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-11-30 00:05:40 +0000
committerJens Arnold <amiconn@rockbox.org>2005-11-30 00:05:40 +0000
commit4c385148ac4a2f4959ec39841c20eaeb42ace668 (patch)
tree09f7e37c89a0a187fc1573efbfa9f2bd8cd60ec2
parent8b022749a7c29ce5f7254fc153ca78b087e53e04 (diff)
downloadrockbox-4c385148ac4a2f4959ec39841c20eaeb42ace668.tar.gz
rockbox-4c385148ac4a2f4959ec39841c20eaeb42ace668.zip
Self-extracting loader: Cleaner method for inclusion of the UCL-compressed image. The input image is now checked for correctness and converted to C source. The Makefile still needs fixing...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8109 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/decompressor/Makefile17
-rw-r--r--firmware/decompressor/decompressor.c13
-rwxr-xr-xfirmware/decompressor/link.lds6
-rwxr-xr-xtools/ucl2src.pl110
4 files changed, 129 insertions, 17 deletions
diff --git a/firmware/decompressor/Makefile b/firmware/decompressor/Makefile
index 29a78523ea..4136eafdb7 100644
--- a/firmware/decompressor/Makefile
+++ b/firmware/decompressor/Makefile
@@ -18,13 +18,14 @@ OBJDIR := .
18# FIXME: get proper value from build system 18# FIXME: get proper value from build system
19MEMORYSIZE = 2 19MEMORYSIZE = 2
20 20
21
22LDS := link.lds 21LDS := link.lds
23LINKFILE = $(OBJDIR)/linkage.lds 22LINKFILE = $(OBJDIR)/linkage.lds
24OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/rockboxucl.o $(OBJDIR)/startup.o 23OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/uclimage.o $(OBJDIR)/startup.o
25 24
26CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns 25CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns
27 26
27all: $(OBJDIR)/compressed.bin
28
28$(OBJDIR)/compressed.bin : $(OBJDIR)/compressed.elf 29$(OBJDIR)/compressed.bin : $(OBJDIR)/compressed.elf
29 @echo "OBJCOPY "`basename $@` 30 @echo "OBJCOPY "`basename $@`
30 @$(OC) -O binary $< $@ 31 @$(OC) -O binary $< $@
@@ -37,6 +38,12 @@ $(LINKFILE): $(LDS)
37 @echo "Build LDS file" 38 @echo "Build LDS file"
38 @cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@ 39 @cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@
39 40
40$(OBJDIR)/rockboxucl.o: $(OBJDIR)/rockbox.ucl 41$(OBJDIR)/decompressor.o : $(OBJDIR)/uclimage.h
41 @echo "OBJCOPY rockbox.ucl" 42
42 @$(OC) -I binary -O elf32-sh -B sh --rename-section .data=.image,alloc,load,data,contents $< $@ 43$(OBJDIR)/uclimage.c : $(OBJDIR)/rockbox.ucl $(TOOLSDIR)/ucl2src.pl
44 @echo "UCL2SRC"
45 @perl -s $(TOOLSDIR)/ucl2src.pl -p=uclimage $< $@
46
47$(OBJDIR)/uclimage.h : $(OBJDIR)/rockbox.ucl $(TOOLSDIR)/ucl2src.pl
48 @echo "UCL2SRC"
49 @perl -s $(TOOLSDIR)/ucl2src.pl -p=uclimage $< $@
diff --git a/firmware/decompressor/decompressor.c b/firmware/decompressor/decompressor.c
index 9cd7d5998e..d368c79538 100644
--- a/firmware/decompressor/decompressor.c
+++ b/firmware/decompressor/decompressor.c
@@ -21,13 +21,13 @@
21 * 21 *
22 ****************************************************************************/ 22 ****************************************************************************/
23 23
24#include "uclimage.h"
25
24#define ICODE_ATTR __attribute__ ((section (".icode"))) 26#define ICODE_ATTR __attribute__ ((section (".icode")))
25#define UCL_HEADER 26 /* size of the header generated by uclpack */
26 27
27/* Symbols defined in the linker script */ 28/* Symbols defined in the linker script */
28extern char iramcopy[], iramstart[], iramend[]; 29extern char iramcopy[], iramstart[], iramend[];
29extern char stackend[]; 30extern char stackend[];
30extern char imgstart[], imgend[];
31extern char loadaddress[], dramend[]; 31extern char loadaddress[], dramend[];
32 32
33/* Prototypes */ 33/* Prototypes */
@@ -113,20 +113,19 @@ int ucl_nrv2e_decompress_8(const unsigned char *src, unsigned char *dst,
113 return ilen; 113 return ilen;
114} 114}
115 115
116#define ALIGNED_IMG_SIZE ((sizeof(image) + 3) & ~3)
116/* This will never return */ 117/* This will never return */
117void main(void) 118void main(void)
118{ 119{
119 unsigned long dst_len; /* dummy */ 120 unsigned long dst_len; /* dummy */
120 unsigned long img_len = (unsigned long)(imgend - imgstart); 121 unsigned long *src = (unsigned long *)image;
121 unsigned long *src = (unsigned long *)imgstart; 122 unsigned long *dst = (unsigned long *)(dramend - ALIGNED_IMG_SIZE);
122 unsigned long *dst = (unsigned long *)(dramend - img_len);
123 123
124 do 124 do
125 *dst++ = *src++; 125 *dst++ = *src++;
126 while (dst < (unsigned long *)dramend); 126 while (dst < (unsigned long *)dramend);
127 127
128 ucl_nrv2e_decompress_8(dramend - img_len + UCL_HEADER, 128 ucl_nrv2e_decompress_8(dramend - ALIGNED_IMG_SIZE, loadaddress, &dst_len);
129 loadaddress, &dst_len);
130 129
131 asm( 130 asm(
132 "mov.l @%0+,r0 \n" 131 "mov.l @%0+,r0 \n"
diff --git a/firmware/decompressor/link.lds b/firmware/decompressor/link.lds
index 9cb4be8830..d0e11c1094 100755
--- a/firmware/decompressor/link.lds
+++ b/firmware/decompressor/link.lds
@@ -40,15 +40,11 @@ SECTIONS
40 { 40 {
41 *(.data) 41 *(.data)
42 . = ALIGN(0x4); 42 . = ALIGN(0x4);
43 _imgstart = .;
44 *(.image)
45 . = ALIGN(0x4);
46 _imgend = .;
47 _iramcopy = .; 43 _iramcopy = .;
48 } > DRAM 44 } > DRAM
49 45
50 .iram IRAMORIG : AT ( _iramcopy ) 46 .iram IRAMORIG : AT ( _iramcopy )
51 { 47 {
52 _iramstart = .; 48 _iramstart = .;
53 *(.icode) 49 *(.icode)
54 *(.idata) 50 *(.idata)
diff --git a/tools/ucl2src.pl b/tools/ucl2src.pl
new file mode 100755
index 0000000000..54cda5b3c0
--- /dev/null
+++ b/tools/ucl2src.pl
@@ -0,0 +1,110 @@
1#!/usr/bin/env perl
2############################################################################
3# __________ __ ___.
4# Open \______ \ ____ ____ | | _\_ |__ _______ ___
5# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# \/ \/ \/ \/ \/
9# $Id$
10#
11# Copyright (C) 2005 by Jens Arnold
12#
13# All files in this archive are subject to the GNU General Public License.
14# See the file COPYING in the source tree root for full license agreement.
15#
16# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17# KIND, either express or implied.
18#
19############################################################################
20
21if (!$ARGV[0])
22{
23 print <<HERE
24Usage: ucl2src [-p=<prefix>] <ucl file>
25
26Check & strip header from an .ucl file and generate <prefix>.c and
27<prefix>.h from it.
28HERE
29;
30 exit;
31}
32
33my $prefix = $p;
34if(!$prefix) {
35 $prefix="uclimage";
36}
37
38my $input = $ARGV[0];
39my $buffer;
40my $insize;
41my $readsize = 0;
42
43open(INF, "<$input") or die "Can't open $input";
44binmode INF;
45
46# check UCL header
47
48# magic header
49read(INF, $buffer, 8);
50if ($buffer ne pack("C8", 0x00, 0xe9, 0x55, 0x43, 0x4c, 0xff, 0x01, 0x1a))
51{
52 die "Not an UCL file.";
53}
54read(INF, $buffer, 4);
55
56# method
57read(INF, $buffer, 1);
58if (ord($buffer) != 0x2E)
59{
60 die sprintf("Wrong compression method (expected 0x2E, found 0x%02X)",
61 ord($buffer));
62}
63
64read(INF, $buffer, 9);
65
66# file size
67read(INF, $buffer, 4);
68$insize = unpack("N", $buffer) + 8;
69
70open(OUTF, ">$prefix.c") or die "Can't open $prefix.c";
71
72print OUTF <<HERE
73/* This file was automatically generated using ucl2src.pl */
74
75/* Data compressed with UCL method 0x2e follows */
76const unsigned char image[] = {
77HERE
78 ;
79
80while (read(INF, $buffer, 1))
81{
82 $readsize++;
83 printf OUTF ("0x%02x,", ord($buffer));
84 if (!($readsize % 16))
85 {
86 print OUTF "\n";
87 }
88}
89
90close(INF);
91
92if ($readsize != $insize)
93{
94 die "Input file truncated, got $readsize of $insize bytes."
95}
96
97print OUTF <<HERE
98};
99/* end of compressed image */
100HERE
101 ;
102close(OUTF);
103
104open(OUTF, ">$prefix.h") or die "Can't open $prefix.h";
105
106print OUTF "/* This file was automatically generated using ucl2src.pl */\n";
107print OUTF "extern const unsigned char image[".$insize."];\n";
108
109close(OUTF);
110