From 72cb4157d965fd54425c697285b9a78ea333167e Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sat, 12 Mar 2011 22:36:39 -0500 Subject: [PATCH 1/3] fix burn-macs to work on 32-bit machines too --- tools/test-grid/burn-macs.pl | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/test-grid/burn-macs.pl b/tools/test-grid/burn-macs.pl index 8434f2fb4..311bac768 100755 --- a/tools/test-grid/burn-macs.pl +++ b/tools/test-grid/burn-macs.pl @@ -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) { From 19c61dc5b284648a7a2584624edbdcb6708e0eb5 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 13 Mar 2011 14:22:00 -0400 Subject: [PATCH 2/3] add tool to burn the mac of a single econotag --- tools/burn-mac.pl | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 tools/burn-mac.pl diff --git a/tools/burn-mac.pl b/tools/burn-mac.pl new file mode 100755 index 000000000..867d411bf --- /dev/null +++ b/tools/burn-mac.pl @@ -0,0 +1,63 @@ +#!/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=012345678 | --term device] flasher.bin address\n"; + die; +} + +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); + From 51ca60b35f79e8c2d36796c4fba02d67737f219f Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 13 Mar 2011 16:39:32 -0400 Subject: [PATCH 3/3] add bin2macbin.pl to create bins that will also set the mac address add usage to burn-mac.pl --- tools/bin2macbin.pl | 82 +++++++++++++++++++++++++++++++++++++++++++++ tools/burn-mac.pl | 6 ++-- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100755 tools/bin2macbin.pl diff --git a/tools/bin2macbin.pl b/tools/bin2macbin.pl new file mode 100755 index 000000000..1c97b3243 --- /dev/null +++ b/tools/bin2macbin.pl @@ -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\""); + + diff --git a/tools/burn-mac.pl b/tools/burn-mac.pl index 867d411bf..6ea201309 100755 --- a/tools/burn-mac.pl +++ b/tools/burn-mac.pl @@ -16,8 +16,10 @@ my $bin = shift; my $address = shift; if (!defined($address) || !defined($bin)) { - print "Usage: $0 [--iab=a8c | --oui=012345678 | --term device] flasher.bin address\n"; - die; + 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;