From a30a07a931083b56ad4201d36bc4b8591a693510 Mon Sep 17 00:00:00 2001 From: Florian Brabetz Date: Thu, 24 Oct 2013 15:45:01 +0200 Subject: [PATCH] Initial commit of jed_to_dump.pl converter script --- tools/jed_to_dump.pl | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 tools/jed_to_dump.pl diff --git a/tools/jed_to_dump.pl b/tools/jed_to_dump.pl new file mode 100755 index 0000000..7049ad5 --- /dev/null +++ b/tools/jed_to_dump.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +use Modern::Perl; +use FileHandle; + +my $inputFilename; +my $outputFilename; + +if( not defined $ARGV[0] ) { + say "Argument missing. Please pass the JEDEC (*.jed) file as first argument."; + say "Usage: ./jed_to_dump.pl inputfile [outputfile]"; + exit; +} + +if( @ARGV > 2 ) { + say "To much arguments"; + exit; +} + +if ( $ARGV[0] =~ /\.jed$/ ) { + $inputFilename = $ARGV[0]; +} else { + say "Please pass the JEDEC (*.jed) file as first argument."; + exit; +} + +if( defined $ARGV[1] ) { + $outputFilename = $ARGV[1]; + if( ! ( $outputFilename =~ /.dump/ ) ) { + $outputFilename .= ".dump"; + } +} else { + $outputFilename = $inputFilename; + $outputFilename =~ s/\.jed/\.dump/; +} + +open my $fh, ">", $outputFilename or die "Output $outputFilename file can't be created: $!"; + +while (<>) { + state $lineNumber = 0; + if ( /^[01]/ ) { + my $completeHexString = unpack( "H32", pack( "B*", $_ ) ); + my @hexArray; + @hexArray = unpack( "A2" x (length($completeHexString)/2), $completeHexString); + printf $fh "0x" . "%04x" . ":\t ", $lineNumber; + $lineNumber++; + local $" = " "; + printf $fh "@hexArray \n"; + } else { + if ( /NOTE TAG DATA\*/ ) { + say "$inputFilename successfuly converted to $outputFilename."; + last; # last interation in while loop; + } + } +} + +close $fh; + +exit; -- 2.43.0