Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script to prepare bcm43438 ucode for disassembling #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions debug/ucode_write_byte.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env perl

use strict;
use warnings;

=pod
This script can be used to rearrange the ucode found in the bcm43438 to enable disassembling
The '-r' parameter can be used to reverse this process
=cut

my $buffer;
my @bytes = ();
my $cnt = 0;
my $reverse = 0;
my $infile;
my $outfile;

my $num_args = $#ARGV + 1;
if ($num_args < 2) {
print "Usage: [-r] in_file out_file\n";
exit;
}

if($ARGV[0] =~ '-r') {
$reverse = 1;
$infile = $ARGV[1];
$outfile = $ARGV[2];
} else {
$infile = $ARGV[0];
$outfile = $ARGV[1];
}

print("Using infile: '$infile', outfile: '$outfile'\n");
# File size of $infile
my $ucode_len = -s $infile;

open(FH, '<:raw', $infile);
read(FH, $buffer, $ucode_len);
@bytes = unpack('C*',$buffer); # 'C*' multiple unsigned character
close(FH);

open(FHW, '>:raw', $outfile);
if(not $reverse) {
while($cnt < $ucode_len) {
$cnt += 7;
my $byte1 = ($bytes[$cnt-3] << 16) | ($bytes[$cnt-4] << 24) | ($bytes[$cnt-1]) | ($bytes[$cnt-2] << 8);
print FHW pack('I', $byte1); # 'I' 32 bit unsigned int
my $byte2 = ($bytes[$cnt-6] << 8) | ($bytes[$cnt-7] << 16) | ($bytes[$cnt-5]);
print FHW pack('I', $byte2);
}
} else {
while($cnt < $ucode_len) {
$cnt += 8;
my $byte1 = sprintf("%014x", ($bytes[$cnt-2] << 48) | ($bytes[$cnt-3] << 40) | ($bytes[$cnt-4] << 32) | ($bytes[$cnt-5] << 24) | ($bytes[$cnt-6] << 16) | ($bytes[$cnt-7] << 8) | ($bytes[$cnt-8]));
print FHW pack('H*', $byte1); # 'H*' hex string (high nybble first)
}
}
close(FHW);