diff options
-rw-r--r-- | firmware/decompressor/Makefile | 17 | ||||
-rw-r--r-- | firmware/decompressor/decompressor.c | 13 | ||||
-rwxr-xr-x | firmware/decompressor/link.lds | 6 | ||||
-rwxr-xr-x | tools/ucl2src.pl | 110 |
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 |
19 | MEMORYSIZE = 2 | 19 | MEMORYSIZE = 2 |
20 | 20 | ||
21 | |||
22 | LDS := link.lds | 21 | LDS := link.lds |
23 | LINKFILE = $(OBJDIR)/linkage.lds | 22 | LINKFILE = $(OBJDIR)/linkage.lds |
24 | OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/rockboxucl.o $(OBJDIR)/startup.o | 23 | OBJS := $(OBJDIR)/decompressor.o $(OBJDIR)/uclimage.o $(OBJDIR)/startup.o |
25 | 24 | ||
26 | CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns | 25 | CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns |
27 | 26 | ||
27 | all: $(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 */ |
28 | extern char iramcopy[], iramstart[], iramend[]; | 29 | extern char iramcopy[], iramstart[], iramend[]; |
29 | extern char stackend[]; | 30 | extern char stackend[]; |
30 | extern char imgstart[], imgend[]; | ||
31 | extern char loadaddress[], dramend[]; | 31 | extern 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 */ |
117 | void main(void) | 118 | void 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 | |||
21 | if (!$ARGV[0]) | ||
22 | { | ||
23 | print <<HERE | ||
24 | Usage: ucl2src [-p=<prefix>] <ucl file> | ||
25 | |||
26 | Check & strip header from an .ucl file and generate <prefix>.c and | ||
27 | <prefix>.h from it. | ||
28 | HERE | ||
29 | ; | ||
30 | exit; | ||
31 | } | ||
32 | |||
33 | my $prefix = $p; | ||
34 | if(!$prefix) { | ||
35 | $prefix="uclimage"; | ||
36 | } | ||
37 | |||
38 | my $input = $ARGV[0]; | ||
39 | my $buffer; | ||
40 | my $insize; | ||
41 | my $readsize = 0; | ||
42 | |||
43 | open(INF, "<$input") or die "Can't open $input"; | ||
44 | binmode INF; | ||
45 | |||
46 | # check UCL header | ||
47 | |||
48 | # magic header | ||
49 | read(INF, $buffer, 8); | ||
50 | if ($buffer ne pack("C8", 0x00, 0xe9, 0x55, 0x43, 0x4c, 0xff, 0x01, 0x1a)) | ||
51 | { | ||
52 | die "Not an UCL file."; | ||
53 | } | ||
54 | read(INF, $buffer, 4); | ||
55 | |||
56 | # method | ||
57 | read(INF, $buffer, 1); | ||
58 | if (ord($buffer) != 0x2E) | ||
59 | { | ||
60 | die sprintf("Wrong compression method (expected 0x2E, found 0x%02X)", | ||
61 | ord($buffer)); | ||
62 | } | ||
63 | |||
64 | read(INF, $buffer, 9); | ||
65 | |||
66 | # file size | ||
67 | read(INF, $buffer, 4); | ||
68 | $insize = unpack("N", $buffer) + 8; | ||
69 | |||
70 | open(OUTF, ">$prefix.c") or die "Can't open $prefix.c"; | ||
71 | |||
72 | print OUTF <<HERE | ||
73 | /* This file was automatically generated using ucl2src.pl */ | ||
74 | |||
75 | /* Data compressed with UCL method 0x2e follows */ | ||
76 | const unsigned char image[] = { | ||
77 | HERE | ||
78 | ; | ||
79 | |||
80 | while (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 | |||
90 | close(INF); | ||
91 | |||
92 | if ($readsize != $insize) | ||
93 | { | ||
94 | die "Input file truncated, got $readsize of $insize bytes." | ||
95 | } | ||
96 | |||
97 | print OUTF <<HERE | ||
98 | }; | ||
99 | /* end of compressed image */ | ||
100 | HERE | ||
101 | ; | ||
102 | close(OUTF); | ||
103 | |||
104 | open(OUTF, ">$prefix.h") or die "Can't open $prefix.h"; | ||
105 | |||
106 | print OUTF "/* This file was automatically generated using ucl2src.pl */\n"; | ||
107 | print OUTF "extern const unsigned char image[".$insize."];\n"; | ||
108 | |||
109 | close(OUTF); | ||
110 | |||