A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

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

+129 -17
+12 -5
firmware/decompressor/Makefile
··· 18 18 # FIXME: get proper value from build system 19 19 MEMORYSIZE = 2 20 20 21 - 22 21 LDS := link.lds 23 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 25 CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns 26 + 27 + all: $(OBJDIR)/compressed.bin 27 28 28 29 $(OBJDIR)/compressed.bin : $(OBJDIR)/compressed.elf 29 30 @echo "OBJCOPY "`basename $@` ··· 37 38 @echo "Build LDS file" 38 39 @cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@ 39 40 40 - $(OBJDIR)/rockboxucl.o: $(OBJDIR)/rockbox.ucl 41 - @echo "OBJCOPY rockbox.ucl" 42 - @$(OC) -I binary -O elf32-sh -B sh --rename-section .data=.image,alloc,load,data,contents $< $@ 41 + $(OBJDIR)/decompressor.o : $(OBJDIR)/uclimage.h 42 + 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 $< $@
+6 -7
firmware/decompressor/decompressor.c
··· 21 21 * 22 22 ****************************************************************************/ 23 23 24 + #include "uclimage.h" 25 + 24 26 #define ICODE_ATTR __attribute__ ((section (".icode"))) 25 - #define UCL_HEADER 26 /* size of the header generated by uclpack */ 26 27 27 28 /* Symbols defined in the linker script */ 28 29 extern char iramcopy[], iramstart[], iramend[]; 29 30 extern char stackend[]; 30 - extern char imgstart[], imgend[]; 31 31 extern char loadaddress[], dramend[]; 32 32 33 33 /* Prototypes */ ··· 113 113 return ilen; 114 114 } 115 115 116 + #define ALIGNED_IMG_SIZE ((sizeof(image) + 3) & ~3) 116 117 /* This will never return */ 117 118 void main(void) 118 119 { 119 120 unsigned long dst_len; /* dummy */ 120 - unsigned long img_len = (unsigned long)(imgend - imgstart); 121 - unsigned long *src = (unsigned long *)imgstart; 122 - unsigned long *dst = (unsigned long *)(dramend - img_len); 121 + unsigned long *src = (unsigned long *)image; 122 + unsigned long *dst = (unsigned long *)(dramend - ALIGNED_IMG_SIZE); 123 123 124 124 do 125 125 *dst++ = *src++; 126 126 while (dst < (unsigned long *)dramend); 127 127 128 - ucl_nrv2e_decompress_8(dramend - img_len + UCL_HEADER, 129 - loadaddress, &dst_len); 128 + ucl_nrv2e_decompress_8(dramend - ALIGNED_IMG_SIZE, loadaddress, &dst_len); 130 129 131 130 asm( 132 131 "mov.l @%0+,r0 \n"
+1 -5
firmware/decompressor/link.lds
··· 40 40 { 41 41 *(.data) 42 42 . = ALIGN(0x4); 43 - _imgstart = .; 44 - *(.image) 45 - . = ALIGN(0x4); 46 - _imgend = .; 47 43 _iramcopy = .; 48 44 } > DRAM 49 45 50 46 .iram IRAMORIG : AT ( _iramcopy ) 51 - { 47 + { 52 48 _iramstart = .; 53 49 *(.icode) 54 50 *(.idata)
+110
tools/ucl2src.pl
··· 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 +