for d in data:
self.serialport.write(chr(d));
+ #self.serialport.flushOutput();
+ #self.serialport.flushInput();
+
+
if not self.besilent:
- #print "Reading reply to %02x/%02x." % (app,verb);
self.readcmd(blocks);
- #print "Read reply."
-
+
besilent=0;
app=0;
verb=0;
def readcmd(self,blocks=1):
"""Read a reply from the GoodFET."""
while 1:
+ #print "Reading...";
self.app=ord(self.serialport.read(1));
+ #print "APP=%2x" % self.app;
self.verb=ord(self.serialport.read(1));
+ #print "VERB=%02x" % self.verb;
self.count=ord(self.serialport.read(1));
- self.data=self.serialport.read(self.count*blocks);
+ #print "Waiting for %i bytes." % self.count;
+
#print "READ %02x %02x %02x " % (self.app, self.verb, self.count);
#Debugging string; print, but wait.
if self.app==0xFF and self.verb==0xFF:
- print "DEBUG %s" % self.data;
+ print "DEBUG %s" % self.serialport.read(self.count);
else:
+ self.data=self.serialport.read(self.count*blocks);
return self.data;
#Monitor stuff
def MSP430peekblock(self,adr,blocks=1):
"""Grab a few block from an SPI Flash ROM. Block size is unknown"""
data=[adr&0xff, (adr&0xff00)>>8,
- (adr&0xff0000)>>16,(adr&0xff000000)>>24,
- blocks];
+ (adr&0xff0000)>>16,(adr&0xff000000)>>24,
+ blocks];
self.writecmd(self.MSP430APP,0x02,5,data,blocks);
return self.data;
def MSP430masserase(self):
"""Erase MSP430 flash memory."""
self.writecmd(self.MSP430APP,0xE3,0,None);
- def MSP430writeflash(self,adr,val):
- """Write a word of flash memory."""
- if(self.MSP430peek(adr)!=0xFFFF):
- print "FLASH ERROR: %04x not clear." % adr;
- data=[adr&0xFF,(adr&0xFF00)>>8,val&0xFF,(val&0xFF00)>>8];
- self.writecmd(self.MSP430APP,0xE1,4,data);
- rval=ord(self.data[0])+(ord(self.data[1])<<8);
- if(val!=rval):
- print "FLASH WRITE ERROR AT %04x. Found %04x, wrote %04x." % (adr,rval,val);
-
+
def MSP430dumpbsl(self):
self.MSP430dumpmem(0xC00,0xfff);
def MSP430dumpallmem(self):
#Identify model number.
client.MSP430start();
+client.MSP430haltcpu();
#print "started"
if(sys.argv[1]=="info"):
for i in h._buf.keys():
#print "%04x: %04x"%(i,h[i>>1]);
if(i>=start and i<stop and i&1==0):
- client.MSP430writeflash(i,h[i>>1]);
+ client.MSP430pokeflash(i,h[i>>1]);
if(i%0x100==0):
print "%04x" % i;
if(sys.argv[1]=="flashtest"):
//! Read data from address
unsigned int jtag430_readmem(unsigned int adr){
unsigned int toret;
+ jtag430_haltcpu();
+
CLRTCLK;
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
//FCTL1=0xA500, disabling flash write
jtag430_writemem(0x0128, 0xA500);
- jtag430_releasecpu();
+ //jtag430_releasecpu();
}
//FCTL1=0xA500, disabling flash write
jtag430_writemem(0x0128, 0xA500);
- jtag430_releasecpu();
+ //jtag430_releasecpu();
}
//Perform a reset and disable watchdog.
jtag430_por();
+ jtag430_writemem(0x120,0x5a80);//disable watchdog
+
+ jtag430_haltcpu();
}
//! Set CPU to Instruction Fetch
void jtag430_setinstrfetch(){
+
jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
// Wait until instruction fetch state.
unsigned long at;
unsigned int i, val;
+ //debugstr("Classic MSP430 handler.");
+
switch(verb){
case START:
//Enter JTAG mode.
blocks=(len>4?cmddata[4]:1);
at=cmddatalong[0];
- len=0x80;
+ //Fetch large blocks for bulk fetches,
+ //small blocks for individual peeks.
+ if(blocks>1)
+ len=0x80;
+
serial_tx(app);
serial_tx(verb);
serial_tx(len);
while(blocks--){
for(i=0;i<len;i+=2){
jtag430_resettap();
- delay(10);
+ //delay(10);
val=jtag430_readmem(at);
-
+
at+=2;
serial_tx(val&0xFF);
serial_tx((val&0xFF00)>>8);
}
}
-
-
-
break;
case JTAG430_WRITEMEM:
case POKE:
txdata(app,verb,2);
break;
case JTAG430_WRITEFLASH:
- debugstr("Poking flash memory.");
+ //debugstr("Poking flash memory.");
jtag430_writeflash(cmddataword[0],cmddataword[2]);
cmddataword[0]=jtag430_readmem(cmddataword[0]);
txdata(app,verb,2);
void handle(unsigned char app,\r
unsigned char verb,\r
unsigned char len){\r
+ //debugstr("GoodFET");\r
switch(app){\r
case MONITOR:\r
monitorhandle(app,verb,len);\r