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.
This commit is contained in:
maralvira 2010-11-07 14:11:50 +00:00
parent 9f7d860e9c
commit f913cf728b
2 changed files with 33 additions and 15 deletions

View file

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: flasher.c,v 1.2 2010/07/28 18:43:04 maralvira Exp $
* $Id: flasher.c,v 1.3 2010/11/07 14:11:50 maralvira Exp $
*/
#include <mc1322x.h>
@ -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<len; i++) {
c = getc();
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&c, 8+i, 1);

View file

@ -15,9 +15,11 @@ my $verbose;
my $rts = 'rts';
my $command = '';
my $do_exit;
my $zerolen;
GetOptions ('file=s' => \$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,13 +102,19 @@ 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));
if(($s == 0) ||
((!defined($zerolen)) && ($s == 1))) {
open(FILE, $filename) or die($!);
print "Sending $filename\n";
@ -115,9 +126,10 @@ while(1) {
$ob->write($c);
}
}
}
last if ($s==1);
if((-e $second)) {
if((-e $second) || defined($zerolen)) {
$s=1; $filename = $second;
} else {
last;