ezusb_convert is a script used to convert an Intel HEX firmware file into a set of C arrays for use in header files. Increase the portability of this script by translating it from Perl to a POSIX shell script. Perl is not was widely installed on UNIX machines as is a POSIX-conforming shell, therefore portability of this script, and therefore a small part of the build, should be increased. Signed-off-by: Jorge Natz <jorgenatzdev@xxxxxxxxx> --- diff -uprN a/drivers/usb/serial/ezusb_convert.pl b/drivers/usb/serial/ezusb_convert.pl --- a/drivers/usb/serial/ezusb_convert.pl 2016-05-15 16:43:13.000000000 -0600 +++ b/drivers/usb/serial/ezusb_convert.pl 1969-12-31 17:00:00.000000000 -0700 @@ -1,50 +0,0 @@ -#! /usr/bin/perl -w - - -# convert an Intel HEX file into a set of C records usable by the firmware -# loading code in usb-serial.c (or others) - -# accepts the .hex file(s) on stdin, a basename (to name the initialized -# array) as an argument, and prints the .h file to stdout. Typical usage: -# perl ezusb_convert.pl foo <foo.hex >fw_foo.h - - -my $basename = $ARGV[0]; -die "no base name specified" unless $basename; - -while (<STDIN>) { - # ':' <len> <addr> <type> <len-data> <crc> '\r' - # len, type, crc are 2-char hex, addr is 4-char hex. type is 00 for - # normal records, 01 for EOF - my($lenstring, $addrstring, $typestring, $reststring, $doscrap) = - /^:(\w\w)(\w\w\w\w)(\w\w)(\w+)(\r?)$/; - die "malformed line: $_" unless $reststring; - last if $typestring eq '01'; - my($len) = hex($lenstring); - my($addr) = hex($addrstring); - my(@bytes) = unpack("C*", pack("H".(2*$len), $reststring)); - #pop(@bytes); # last byte is a CRC - push(@records, [$addr, \@bytes]); -} - -@sorted_records = sort { $a->[0] <=> $b->[0] } @records; - -print <<"EOF"; -/* - * ${basename}_fw.h - * - * Generated from ${basename}.s by ezusb_convert.pl - * This file is presumed to be under the same copyright as the source file - * from which it was derived. - */ - -EOF - -print "static const struct ezusb_hex_record ${basename}_firmware[] = {\n"; -foreach $r (@sorted_records) { - printf("{ 0x%04x,\t%d,\t{", $r->[0], scalar(@{$r->[1]})); - print join(", ", map {sprintf('0x%02x', $_);} @{$r->[1]}); - print "} },\n"; -} -print "{ 0xffff,\t0,\t{0x00} }\n"; -print "};\n"; diff -uprN a/drivers/usb/serial/ezusb_convert.sh b/drivers/usb/serial/ezusb_convert.sh --- a/drivers/usb/serial/ezusb_convert.sh 1969-12-31 17:00:00.000000000 -0700 +++ b/drivers/usb/serial/ezusb_convert.sh 2016-08-30 08:01:07.493087802 -0600 @@ -0,0 +1,44 @@ +#!/bin/sh + +# convert an Intel HEX file to a two-dimensional C record set + +# takes HEX file on stdin, and prints header file on stdout +# example: ./ezusb_convert.sh foo < foo.hex > foo_fw.h + +# Exit on error +set -e + +basename=$1 +if ! [ $basename ]; then + echo “no base name specified” + exit +fi + +echo '/*\n * '$basename'_fw.h' +echo ' *' +echo ' * Generated from '$basename'.s by ezusb_convert.sh' +cat << "EOF" + * This file is presumed to be under the same copyright as the source file + * from which it was derived. + */ + +EOF +echo 'static const struct ezusb_hex_record '$basename'_firmware[] = {' + +for LINE in $(sed -e s'/^[^:].*//' -e s'/^........[^0].*//' | sort -k 1.4); do + if ! [ $(echo $LINE | grep '^:') ]; then + continue + fi + reststring=$(echo ${LINE%??} | cut -c 10- | tr '[:upper:]' '[:lower:]') + if ! [ $reststring ]; then + printf "malformed line:%" $reststring + exit 1 + fi + charcount=0 + echo -n '{ 0x'$(echo $LINE | head -c 7 | tail -c 4 | tr '[:upper:]' '[:lower:]') + echo -n ', '$(printf "%d" 0x$(echo $LINE | head -c 3 | tail -c 2))', {' + echo -n $(echo $reststring | sed -e s'/../0x&, /g' -e s'/, $//') + echo '} },' +done + +echo '{ 0xffff,\t0,\t{0x00} }\n};' diff -uprN a/drivers/usb/serial/Makefile-keyspan_pda_fw b/drivers/usb/serial/Makefile-keyspan_pda_fw --- a/drivers/usb/serial/Makefile-keyspan_pda_fw 2016-05-15 16:43:13.000000000 -0600 +++ b/drivers/usb/serial/Makefile-keyspan_pda_fw 2016-08-29 20:09:39.653038229 -0600 @@ -12,5 +12,5 @@ all: keyspan_pda_fw.h as31 -l $< mv $*.obj $@ -%_fw.h: %.hex ezusb_convert.pl - perl ezusb_convert.pl $* < $< > $@ +%_fw.h: %.hex ezusb_convert.sh + ./ezusb_convert.sh $* < $< > $@ diff -uprN a/firmware/keyspan_pda/keyspan_pda.S b/firmware/keyspan_pda/keyspan_pda.S --- a/firmware/keyspan_pda/keyspan_pda.S 2016-05-15 16:43:13.000000000 -0600 +++ b/firmware/keyspan_pda/keyspan_pda.S 2016-08-29 20:29:35.380974152 -0600 @@ -84,7 +84,7 @@ * gcc -x assembler-with-cpp -P -E -o keyspan_pda.asm keyspan_pda.s * as31 -l keyspan_pda.asm * mv keyspan_pda.obj keyspan_pda.hex - * perl ezusb_convert.pl keyspan_pda < keyspan_pda.hex > keyspan_pda_fw.h + * ./ezusb_convert.sh keyspan_pda < keyspan_pda.hex > keyspan_pda_fw.h * Get as31 from <http://www.pjrc.com/tech/8051/index.html>, and hack on it * a bit to make it build. * diff -uprN a/firmware/keyspan_pda/xircom_pgs.S b/firmware/keyspan_pda/xircom_pgs.S --- a/firmware/keyspan_pda/xircom_pgs.S 2016-05-15 16:43:13.000000000 -0600 +++ b/firmware/keyspan_pda/xircom_pgs.S 2016-08-29 20:30:12.196972179 -0600 @@ -84,7 +84,7 @@ * gcc -x assembler-with-cpp -P -E -o keyspan_pda.asm keyspan_pda.s * as31 -l keyspan_pda.asm * mv keyspan_pda.obj keyspan_pda.hex - * perl ezusb_convert.pl keyspan_pda < keyspan_pda.hex > keyspan_pda_fw.h + * ./ezusb_convert.sh keyspan_pda < keyspan_pda.hex > keyspan_pda_fw.h * Get as31 from <http://www.pjrc.com/tech/8051/index.html>, and hack on it * a bit to make it build. * -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html