From: hackbard Date: Fri, 3 Aug 2007 00:52:40 +0000 (+0200) Subject: troubles concerning data + cksum-response :/ X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=c085074294f2852dbe03000d077c9a44b0d7d888;p=my-code%2Farm.git troubles concerning data + cksum-response :/ --- diff --git a/betty/lpcload.c b/betty/lpcload.c index a1dd97f..905ebbd 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -21,6 +21,7 @@ #define TXRX_TYPE_SYNC 0x02 #define TXRX_TYPE_CMD 0x03 #define TXRX_TYPE_DATA 0x04 +#define TXRX_TYPE_CKSM 0x05 #define CMD_SUCCESS "0\r\n" #define INVALID_COMMAND "1\r\n" @@ -106,14 +107,18 @@ int open_serial_device(t_lpc *lpc) { term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG); - // input options -> disable flow control + // input options -> enable flow control - term.c_iflag&=~(IXON|IXOFF|IXANY); + //term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL); + term.c_iflag&=~(INLCR|ICRNL); + term.c_iflag|=(IXON|IXOFF|IXANY); - // more control options -> timeout + // more control options -> timeout / flow control term.c_cc[VMIN]=0; term.c_cc[VTIME]=10; // 1 second timeout + term.c_cc[VSTART]=0x11; + term.c_cc[VSTOP]=0x13; tcsetattr(lpc->sfd,TCSANOW,&term); @@ -169,26 +174,58 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) { len-=ret; cnt+=ret; } - if(lpc->info&VERBOSE) - printf(" (%d)\n",cnt); + if(lpc->info&VERBOSE) { + printf(" | "); + for(i=0;i0) { ret=read(lpc->sfd,buf,cnt); if(ret<0) { perror("txrx echo cut"); return ret; } + if(type==TXRX_TYPE_CKSM) { + printf(" cksm resp: "); + for(i=0;isfd,buf,BUFSIZE); + for(i=0;i0) { + while(ret) { ret=read(lpc->sfd,buf+cnt,BUFSIZE-cnt); if(ret<0) { perror("txrx read"); @@ -213,11 +250,15 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) { buf[cnt+i]:'.'); cnt+=ret; } - if(lpc->info&VERBOSE) - printf(" (%d)\n",cnt); + if(lpc->info&VERBOSE) { + printf(" | "); + for(i=0;iroff); + len=strlen(buf); + ret=txrx(lpc,buf,ret,TXRX_TYPE_CMD); + + return ret; +} + +int uuencode(char *in,char *out) { + + int i; out[0]=0x20+((in[0]>>2)&0x3f); out[1]=0x20+(((in[0]<<4)|(in[1]>>4))&0x3f); out[2]=0x20+(((in[1]<<2)|(in[2]>>6))&0x3f); out[3]=0x20+(in[2]&0x3f); + printf(" enc: "); + for(i=0;i<3;i++) + printf("%02x ",in[i]); + printf("-> "); + for(i=0;i<4;i++) + printf("%02x ",out[i]); + printf("\n"); + return 0; } -int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { +int write_to_ram(t_lpc *lpc,char *buf,u32 addr,int len) { int lcount; u32 checksum; @@ -333,16 +407,16 @@ int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { /* prepare write command */ if(lpc->info&VERBOSE) - printf("writing %02x bytes to %08x\n",len,addr); + printf("writing 0x%02x bytes to 0x%08x\n",len,addr); snprintf(txrxbuf,BUFSIZE,"W %d %d\r\n",addr,len); slen=strlen(txrxbuf); /* send command and check return code */ txrx(lpc,txrxbuf,slen,TXRX_TYPE_CMD); - if(strncmp(txrxbuf,"OK\r\n",4)) { - printf("ram write: write command failed\n"); - return -1; - } + //if(strncmp(txrxbuf,"OK\r\n",4)) { + // printf("ram write: write command failed\n"); + // return -1; + //} /* send data */ lcount=0; @@ -353,11 +427,12 @@ int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { /* uuencode / prepare data bytes */ uuencode(buf+bcnt,txrxbuf); - txrxbuf[4]='\0'; - txrxbuf[5]='\0'; + txrxbuf[4]='\r'; + txrxbuf[5]='\n'; /* checksum */ - checksum+=(buf[0]+buf[1]+buf[2]); + checksum+=(buf[bcnt]+buf[bcnt+1]+buf[bcnt+2]); + printf("----> %d %d\n",checksum,bcnt); /* send a data line */ txrx(lpc,txrxbuf,6,TXRX_TYPE_DATA); @@ -370,9 +445,9 @@ int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { /* checksum */ if((!(lcount%20))|(bcnt==nlen)) { /* send checksum */ - snprintf(txrxbuf,BUFSIZE,"%d\r\n",checksum); + snprintf(txrxbuf,BUFSIZE,"%d\r\n",checksum%0x100); slen=strlen(txrxbuf); - txrx(lpc,txrxbuf,slen,TXRX_TYPE_CMD); + txrx(lpc,txrxbuf,slen,TXRX_TYPE_CKSM); if(!strncmp(txrxbuf,"RESEND\r\n",8)) { printf("ram write: resending ...\n"); bcnt-=count; @@ -394,10 +469,8 @@ int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { int firmware_to_ram(t_lpc *lpc) { char buf[BUFSIZE]; - u8 data[BUFSIZE]; - u32 addr,len,type,val; - u8 cksum; - int ret,i; + u32 addr,len,type; + int ret; /* read a line */ while(ret) { @@ -438,25 +511,14 @@ int firmware_to_ram(t_lpc *lpc) { return -1; } /* checksum */ - cksum=0; - for(i=0;ifwfd,buf,2); - sscanf(buf,"%02x",&val); - if(val+cksum!=0x100) { - printf("fw to ram: wrong checksum\n"); - return -1; - } /* act according to type */ switch(type) { case 0x03: /* get cs and ip */ break; case 0x00: - write_to_ram(lpc,data,addr,len); + write_to_ram(lpc,buf,addr,len); break; default: printf("fw to ram: unknown type %02x\n",type); @@ -531,9 +593,15 @@ int main(int argc,char **argv) { read_bcv(&lpc); printf("boot code version: %02x %02x\n",lpc.bcv[0],lpc.bcv[1]); - // to be continued ... (parsing fw file and poking it to ram) + /* parse intel hex file and write to ram */ firmware_to_ram(&lpc); + /* unlock go cmd */ + unlock_go(&lpc); + + /* go! */ + go(&lpc); + end: close(lpc.sfd); close(lpc.fwfd);