From 4d47f83d8faac6e9d26a386338bc2289592b862d Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Mon, 6 Sep 2010 12:05:34 -0400 Subject: [PATCH] modify flasher.c to not create a vaild boot magic number if the length of the file is zero modify mc1322x-load.pl to optionally send a zero length file with -z; extra data on the command line is still written. This allows you to burn the mac adress without flashing a vaild image. --- tests/flasher.c | 10 ++++++++-- tools/mc1322x-load.pl | 36 ++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/tests/flasher.c b/tests/flasher.c index 694e9aa14..f2cb29a76 100644 --- a/tests/flasher.c +++ b/tests/flasher.c @@ -141,6 +141,14 @@ void main(void) { dbg_put_hex32(type); dbg_putstr("\n\r"); + /* don't make a valid boot image if the received length is zero */ + if(len == 0) { + ((uint8_t *)buf)[0] = 'N'; + ((uint8_t *)buf)[1] = 'O'; + ((uint8_t *)buf)[2] = 'N'; + ((uint8_t *)buf)[3] = 'O'; + } + err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, 0, 4); dbg_putstr("nvm_write returned: 0x"); @@ -151,8 +159,6 @@ void main(void) { err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&len, 4, 4); /* read a byte, write a byte */ - /* byte at a time will make this work as a contiki process better */ - /* for OTAP */ for(i=0; i \$filename, 'secondfile=s' => \$second, + 'zerolen' => \$zerolen, 'terminal=s' => \$term, 'verbose' => \$verbose, 'baud=s' => \$baud, @@ -31,8 +33,10 @@ $| = 1; if($filename eq '') { print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n"; print " or : mc1322x-load.pl -f flasher.bin -s flashme.bin 0x1e000,0x11223344,0x55667788\n"; + print " or : mc1322x-load.pl -f flasher.bin -z 0x1e000,0x11223344,0x55667788\n"; print " -f required: binary file to load\n"; print " -s optional: secondary binary file to send\n"; + print " -z optional: send a zero length file as secondary\n"; print " -t terminal default: /dev/ttyUSB0\n"; print " -b baud rate default: 115200\n"; print " -r [none|rts] flow control default: rts\n"; @@ -65,6 +69,7 @@ $ob->rts_active(1); my $s = 0; my $reset = 0; +my $size = 0; while(1) { @@ -97,27 +102,34 @@ while(1) { } print $ret . "\n"; - if (-e $filename) { + if (-e $filename || (defined($zerolen) && ($s == 1))) { - my $size = -s $filename; + if(defined($zerolen) && ($s == 1)) { + $size = 0; + } else { + $size = -s $filename; + } print ("Size: $size bytes\n"); $ob->write(pack('V',$size)); - open(FILE, $filename) or die($!); - print "Sending $filename\n"; - - my $i = 1; - while(read(FILE, $c, 1)) { - $i++; - usleep(50); # this is as fast is it can go... - usleep(50) if ($s==1); - $ob->write($c); + if(($s == 0) || + ((!defined($zerolen)) && ($s == 1))) { + open(FILE, $filename) or die($!); + print "Sending $filename\n"; + + my $i = 1; + while(read(FILE, $c, 1)) { + $i++; + usleep(50); # this is as fast is it can go... + usleep(50) if ($s==1); + $ob->write($c); + } } } last if ($s==1); - if((-e $second)) { + if((-e $second) || defined($zerolen)) { $s=1; $filename = $second; } else { last;