From 4c385148ac4a2f4959ec39841c20eaeb42ace668 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 30 Nov 2005 00:05:40 +0000 Subject: 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 --- tools/ucl2src.pl | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 tools/ucl2src.pl (limited to 'tools/ucl2src.pl') 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 @@ +#!/usr/bin/env perl +############################################################################ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id$ +# +# Copyright (C) 2005 by Jens Arnold +# +# All files in this archive are subject to the GNU General Public License. +# See the file COPYING in the source tree root for full license agreement. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +############################################################################ + +if (!$ARGV[0]) +{ + print <] + +Check & strip header from an .ucl file and generate .c and +.h from it. +HERE +; + exit; +} + +my $prefix = $p; +if(!$prefix) { + $prefix="uclimage"; +} + +my $input = $ARGV[0]; +my $buffer; +my $insize; +my $readsize = 0; + +open(INF, "<$input") or die "Can't open $input"; +binmode INF; + +# check UCL header + +# magic header +read(INF, $buffer, 8); +if ($buffer ne pack("C8", 0x00, 0xe9, 0x55, 0x43, 0x4c, 0xff, 0x01, 0x1a)) +{ + die "Not an UCL file."; +} +read(INF, $buffer, 4); + +# method +read(INF, $buffer, 1); +if (ord($buffer) != 0x2E) +{ + die sprintf("Wrong compression method (expected 0x2E, found 0x%02X)", + ord($buffer)); +} + +read(INF, $buffer, 9); + +# file size +read(INF, $buffer, 4); +$insize = unpack("N", $buffer) + 8; + +open(OUTF, ">$prefix.c") or die "Can't open $prefix.c"; + +print OUTF <$prefix.h") or die "Can't open $prefix.h"; + +print OUTF "/* This file was automatically generated using ucl2src.pl */\n"; +print OUTF "extern const unsigned char image[".$insize."];\n"; + +close(OUTF); + -- cgit v1.2.3