Merge remote branch 'libmc1322x/master'

This commit is contained in:
Mariano Alvira 2011-03-13 17:14:32 -04:00
commit 74517b9df4
3 changed files with 162 additions and 10 deletions

82
cpu/mc1322x/tools/bin2macbin.pl Executable file
View File

@ -0,0 +1,82 @@
#!/usr/bin/perl
use strict;
use File::Copy;
use Getopt::Long;
use File::Basename;
my $cmd;
my $oui;
my $iab;
GetOptions ('iab=s' => \$iab,
'oui=s' => \$oui,
) or die 'bad options';
my $address = shift;
my $infile = shift;
my $outfile = shift;
if (!defined($address) || !defined($infile)) {
print "Usage: $0 [--iab=a8c | --oui=abcdef ] address infile [outfile]\n";
print " iab is 12-bit and address is 28-bit e.g. --iab=a8c 1234567\n";
print " oui is 24-bit and address is 40-bit e.g. --oui=abcdef 123456789a\n";
print "\n";
print " if outfile is not specified, for infile foo.bin outfile will be\n";
print " foo-[macaddress].bin e.g:\n";
print " for --iab=a8c 1234567 foo.bin -> foo-0050c2a8c1234567.bin\n";
print " for --oui=abcdef 123456789a foo.bin -> foo-abcdef123456789a.bin\n";
exit;
}
my $mac_h;
my $mac_l;
if(defined($iab)) {
$iab = hex($iab);
$address = hex($address);
$mac_h = 0x0050C200 | ($iab >> 4);
$mac_l = (($iab & 0xf) << 28) | $address;
} else {
$address =~ /(.*?)(.{0,8})$/;
my ($addr_h, $addr_l) = ($1, $2);
if(!$addr_h) { $addr_h = 0 };
$oui = hex($oui);
$addr_l = hex($addr_l);
$addr_h = hex($addr_h);
$mac_h = ($oui << 8) | $addr_h;
$mac_l = $addr_l;
}
printf("mach %x macl %x\n", $mac_h, $mac_l);
my @words;
for(my $i=0; $i<4; $i++) {
push @words, ($mac_l >> ($i * 8)) & 0xff;
}
for(my $i=0; $i<4; $i++) {
push @words, ($mac_h >> ($i * 8)) & 0xff;
}
reverse @words;
#foreach my $byte (@words) {
# printf("%02X",$byte);
#}
#print "\n";
if(!defined($outfile))
{
my $basename = basename($infile,(".bin"));
$outfile = sprintf("-%08x%08x.bin",$mac_h, $mac_l);
$outfile = $basename . $outfile;
print "outfile $outfile\n";
}
copy($infile, $outfile) or die("Couldn't copy $infile to $outfile");
$cmd = sprintf("echo -n -e '\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X\\x%02X' | dd of=$outfile bs=1 seek=122872 conv=notrunc",
$words[7],$words[6],$words[5],$words[4],
$words[3],$words[2],$words[1],$words[0]);
print "$cmd\n";
system("bash -c \"$cmd\"");

65
cpu/mc1322x/tools/burn-mac.pl Executable file
View File

@ -0,0 +1,65 @@
#!/usr/bin/perl
use strict;
use Getopt::Long;
my $oui;
my $addr = "0x1e000";
my $iab;
my $term = "/dev/ttyUSB1";
GetOptions ('iab=s' => \$iab,
'oui=s' => \$oui,
'term=s' => \$term,
) or die 'bad options';
my $bin = shift;
my $address = shift;
if (!defined($address) || !defined($bin)) {
print "Usage: $0 [--iab=a8c | --oui=abcdef | --term device] flasher.bin address\n";
print " iab is 12-bit and address is 28-bit e.g. --iab=a8c 1234567\n";
print " oui is 24-bit and address is 40-bit e.g. --oui=abcdef 123456789a\n";
exit;
}
my $mac_h;
my $mac_l;
if(defined($iab)) {
$iab = hex($iab);
$address = hex($address);
$mac_h = 0x0050C200 | ($iab >> 4);
$mac_l = (($iab & 0xf) << 28) | $address;
} else {
$address =~ /(.*?)(.{0,8})$/;
my ($addr_h, $addr_l) = ($1, $2);
if(!$addr_h) { $addr_h = 0 };
$oui = hex($oui);
$addr_l = hex($addr_l);
$addr_h = hex($addr_h);
$mac_h = ($oui << 8) | $addr_h;
$mac_l = $addr_l;
}
printf("mach %x macl %x\n", $mac_h, $mac_l);
my @words;
for(my $i=0; $i<4; $i++) {
push @words, ($mac_l >> ($i * 8)) & 0xff;
}
for(my $i=0; $i<4; $i++) {
push @words, ($mac_h >> ($i * 8)) & 0xff;
}
reverse @words;
#foreach my $byte (@words) {
# printf("%02X",$byte);
#}
#print "\n";
my $word1 = sprintf("%02X%02X%02X%02X",$words[4],$words[5],$words[6],$words[7]);
my $word2 = sprintf("%02X%02X%02X%02X",$words[0],$words[1],$words[2],$words[3]);
my $cmd = "mc1322x-load.pl -e -f $bin -z -t $term -c 'bbmc -l redbee-econotag reset' $addr,0x$word1,0x$word2 &";
print "$cmd\n";
system($cmd);

View File

@ -5,11 +5,14 @@ my $bin = shift;
my $terms = shift;
my $addr = "0x1e000";
my $company_id;
my $iab = 0xabc; # Redwire, LLC's IAB
my $iab = 0xa8c; # Redwire, LLC's IAB
my $mac_h;
my $mac_l;
if(defined($iab)) {
$company_id = (0x0050C2 << 12) | $iab;
$mac_h = 0x0050C200 | ($iab >> 4);
$mac_l = ($iab & 0xf) << 28;
}
if (! $terms) {
@ -19,15 +22,17 @@ if (! $terms) {
for (my $t=0; $t<$terms; $t++) {
my $dev_num = 2 * $t + 1;
$mac_l |= $dev_num;
#stupid 32-bit thing...
my $mac;
if(defined($iab)) {
$mac = ($company_id << 28) | $dev_num;
} else {
$mac = ($company_id << 40) | $dev_num;
}
printf("mac_h %x\n", $mac_h);
printf("mac_l %x\n", $mac_l);
my @words;
for(my $i=0; $i<8; $i++) {
push @words, ($mac >> ($i * 8)) & 0xff;
for(my $i=0; $i<4; $i++) {
push @words, ($mac_h >> ($i * 8)) & 0xff;
}
for(my $i=0; $i<4; $i++) {
push @words, ($mac_l >> ($i * 8)) & 0xff;
}
reverse @words;
foreach my $byte (@words) {