2 ############################################################################
4 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
11 # Copyright (C) 2005 by Jens Arnold
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.
16 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 # KIND, either express or implied.
19 ############################################################################
24 Usage: ucl2src [-p=<prefix>] <ucl file>
26 Check & strip header from an .ucl file and generate <prefix>.c and
43 open(INF
, "<$input") or die "Can't open $input";
49 read(INF
, $buffer, 8);
50 if ($buffer ne pack("C8", 0x00, 0xe9, 0x55, 0x43, 0x4c, 0xff, 0x01, 0x1a))
52 die "Not an UCL file.";
54 read(INF
, $buffer, 4);
57 read(INF
, $buffer, 1);
58 if (ord($buffer) != 0x2E)
60 die sprintf("Wrong compression method (expected 0x2E, found 0x%02X)",
64 read(INF
, $buffer, 9);
67 read(INF
, $buffer, 4);
68 $insize = unpack("N", $buffer) + 8;
70 open(OUTF
, ">$prefix.c") or die "Can't open $prefix.c";
73 /* This file was automatically generated using ucl2src.pl */
75 /* Data compressed with UCL method 0x2e follows */
76 const unsigned char image[] = {
80 while (read(INF
, $buffer, 1))
83 printf OUTF
("0x%02x,", ord($buffer));
84 if (!($readsize % 16))
92 if ($readsize != $insize)
94 die "Input file truncated, got $readsize of $insize bytes."
99 /* end of compressed image */
104 open(OUTF
, ">$prefix.h") or die "Can't open $prefix.h";
106 print OUTF
"/* This file was automatically generated using ucl2src.pl */\n";
107 print OUTF
"extern const unsigned char image[".$insize."];\n";