| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# This script converts the output from SnoopyPro's log window into a M920x driver compatible binary form. |
| 4 |
# Taken from http://www.linuxtv.org/wiki/index.php/ULi_M920x_sp_firmware |
| 5 |
|
| 6 |
sub get_line { |
| 7 |
|
| 8 |
|
| 9 |
while($line = <STDIN>) { |
| 10 |
if($line =~ m/\S+ \S+ \S+ \S+ \S+ \S+ \S+ \S+ \S+ \S+ \S+/) { |
| 11 |
#print "returning line $line"; |
| 12 |
return $line; |
| 13 |
}else{ |
| 14 |
#print "not matched $line\n"; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
#exit; |
| 19 |
} |
| 20 |
|
| 21 |
sub get_line_read { |
| 22 |
|
| 23 |
while($line = <STDIN>) { |
| 24 |
|
| 25 |
#d5748560 78669980 C Ci:004:00 0 1 = 50 |
| 26 |
#d3ea8260 44357030 C Ci:004:00 0 1 = bc |
| 27 |
if($line =~ m/\S+ \S+ C \S+ \S+ (\S+) = (\S+)/) { |
| 28 |
return $2; |
| 29 |
}else{ |
| 30 |
#print "not matched $line\n"; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
$linenum = 0; |
| 37 |
sub get_tf_data { |
| 38 |
$full = ""; |
| 39 |
|
| 40 |
$line = <STDIN>; $linenum++; |
| 41 |
while($line =~ m/^\S\S\S\S: (.+)/) { |
| 42 |
$full .= $1; |
| 43 |
#print "$1"; |
| 44 |
$line = <STDIN>; $linenum++; |
| 45 |
} |
| 46 |
return $full; |
| 47 |
} |
| 48 |
|
| 49 |
open(out,">fw") || die "Can't open fw"; |
| 50 |
|
| 51 |
sub write_bytes { |
| 52 |
my($str) = @_; |
| 53 |
|
| 54 |
#print "ds $str sd\n"; |
| 55 |
|
| 56 |
@bytes = split(/ /, $str); |
| 57 |
foreach(@bytes){ |
| 58 |
#print "$_\n"; |
| 59 |
print out pack("C", hex($_)); |
| 60 |
} |
| 61 |
|
| 62 |
#exit(1); |
| 63 |
} |
| 64 |
|
| 65 |
sub to_words { |
| 66 |
my($str) = @_; |
| 67 |
|
| 68 |
print "ds $str sd\n"; |
| 69 |
|
| 70 |
@bytes = split(/\S+ \S+/, $str); |
| 71 |
foreach(@bytes){ |
| 72 |
print "$_\n"; |
| 73 |
print out pack("v", hex($_)); |
| 74 |
} |
| 75 |
|
| 76 |
exit(1); |
| 77 |
} |
| 78 |
|
| 79 |
while($line = <STDIN>) { $linenum++; |
| 80 |
|
| 81 |
if($line =~ m/SetupPacket:/) { |
| 82 |
$setup_linenum = $linenum; |
| 83 |
$setup = get_tf_data(); |
| 84 |
|
| 85 |
#to_words($setup); |
| 86 |
|
| 87 |
#write_bytes($setup); |
| 88 |
|
| 89 |
#print "$line\n"; |
| 90 |
|
| 91 |
while($line = <STDIN>) { $linenum++; |
| 92 |
if($line =~ m/TransferBuffer: 0x00000040/) { |
| 93 |
#print "$setup, $setup_linenum\n"; |
| 94 |
|
| 95 |
@bytes = split(/ /, $setup); |
| 96 |
print out pack("v", hex($bytes[3] . $bytes[2])); |
| 97 |
print out pack("v", hex($bytes[5] . $bytes[4])); |
| 98 |
print out pack("v", hex("0x40")); |
| 99 |
|
| 100 |
$lid = get_tf_data(); |
| 101 |
write_bytes($lid); |
| 102 |
#print $lid; |
| 103 |
#print "\n"; |
| 104 |
|
| 105 |
last; |
| 106 |
}elsif($line =~ m/No TransferBuffer/) { |
| 107 |
last; |
| 108 |
}elsif($line =~ m/TransferBuffer:/) { |
| 109 |
last; |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
} |