From 19c61dc5b284648a7a2584624edbdcb6708e0eb5 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 13 Mar 2011 14:22:00 -0400 Subject: [PATCH] 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); +