summaryrefslogtreecommitdiffstats
path: root/fpga/hp_lcd_driver/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'fpga/hp_lcd_driver/scripts')
-rwxr-xr-xfpga/hp_lcd_driver/scripts/xilinx_bit_to_bin.pl80
1 files changed, 80 insertions, 0 deletions
diff --git a/fpga/hp_lcd_driver/scripts/xilinx_bit_to_bin.pl b/fpga/hp_lcd_driver/scripts/xilinx_bit_to_bin.pl
new file mode 100755
index 0000000..317a09e
--- /dev/null
+++ b/fpga/hp_lcd_driver/scripts/xilinx_bit_to_bin.pl
@@ -0,0 +1,80 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+
+sub read_file($) {
+ my ($name) = @_;
+
+ my $fh = new IO::File "<" . $name;
+ binmode $fh;
+ local $/;
+ my $guts = $fh->getline;
+ $fh->close;
+ undef $fh;
+
+ return $guts;
+}
+
+sub dump_file($$) {
+ my ( $name, $guts ) = @_;
+
+ my $fh = new IO::File ">" . $name;
+ binmode $fh;
+ $fh->print($guts);
+ $fh->close;
+ undef $fh;
+}
+
+sub read_section($$$){
+ my ($in,$ll,$t)=@_;
+
+ die "file ends too soon" if length($$in)<($ll+1);
+ die "section type mismatch" if substr($$in,0,1) ne $t;
+
+ my $ls= substr($$in,1,$ll);
+ $$in=substr($$in,1+$ll);
+
+ my $l=0;
+ for ( my $i = 0; $i < length($ls); $i++ ) {
+ $l<<=8;
+ $l=$l+ord( substr( $ls, $i, 1));
+ }
+
+
+
+ die "file ends too soon" if length($$in)<$l;
+
+ my $v=substr($$in,0,$l);
+ $$in=substr($$in,$l);
+
+ return $v;
+}
+
+
+
+
+my $in=read_file($ARGV[0]);
+
+die "file ends too soon" if length($in)<13;
+
+$in=substr($in,13);
+
+
+my $file_name=read_section(\$in,2,'a');
+my $part_name=read_section(\$in,2,'b');
+my $date=read_section(\$in,2,'c');
+my $time=read_section(\$in,2,'d');
+my $data=read_section(\$in,4,'e');
+
+print "partname=$part_name\n";
+
+my $b=unpack('b*',$data);
+$data=pack('B*',$b);
+
+
+dump_file($ARGV[1],$data);
+
+