]> hackdaworld.org Git - my-code/arm.git/commitdiff
added fwdump, basic data write implemented
authorhackbard <hackbard@hackdaworld.org>
Sun, 29 Jul 2007 20:03:07 +0000 (22:03 +0200)
committerhackbard <hackbard@hackdaworld.org>
Sun, 29 Jul 2007 20:03:07 +0000 (22:03 +0200)
betty/fwdump.c
betty/lpcload.c

index 6bb250ab4b6b9bd751597f031d555bb557603540..37695088edd431490f1f1defa2906b8e4b2eb79f 100644 (file)
@@ -6,3 +6,10 @@
  *
  */
 
+int main(int argc,char **argv) {
+
+
+
+       return 0;
+}
+
index 8bd853010f225979c073ad24a3d5aaa630b693f6..7c2db70b1546bfa9124dbf44d65c0dc8fd5e8d79 100644 (file)
@@ -19,7 +19,8 @@
 
 #define TXRX_TYPE_BAUD         0x01
 #define TXRX_TYPE_SYNC         0x02
-#define TXRX_TYPE_DATA         0x03
+#define TXRX_TYPE_CMD          0x03
+#define TXRX_TYPE_DATA         0x04
 
 #define CMD_SUCCESS            "0\r\n"
 #define INVALID_COMMAND                "1\r\n"
@@ -125,7 +126,7 @@ int open_firmware(t_lpc *lpc) {
        return lpc->fwfd;
 }
 
-int txrx(t_lpc *lpc,char *buf,int len,u8 type) {
+int txrx(t_lpc *lpc,u8 *buf,int len,u8 type) {
 
        int ret,cnt;
        int i;
@@ -165,6 +166,11 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) {
                }
        }
 
+       /* return here if type is data */
+
+       if(type==TXRX_TYPE_DATA)
+               return cnt;
+
        /* read */
 
        if(lpc->info&VERBOSE)
@@ -190,12 +196,11 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) {
        }
        if(lpc->info&VERBOSE)
                printf(" (%d)\n",cnt);
-       len=cnt;
        buf[cnt]='\0';
 
        /* check/strip return code if type is data */
 
-       if(type==TXRX_TYPE_DATA) {
+       if(type==TXRX_TYPE_CMD) {
                ret=strlen(CMD_SUCCESS);
                if(!strncmp(buf,CMD_SUCCESS,ret)) {
                        for(i=ret;i<cnt;i++)
@@ -213,7 +218,7 @@ int txrx(t_lpc *lpc,char *buf,int len,u8 type) {
 
 int bl_init(t_lpc *lpc) {
 
-       char buf[BUFSIZE];
+       u8 buf[BUFSIZE];
        int len;
 
        /* auto baud sequence */
@@ -247,10 +252,10 @@ int bl_init(t_lpc *lpc) {
 
 int read_part_id(t_lpc *lpc) {
 
-       char buf[BUFSIZE];
+       u8 buf[BUFSIZE];
 
        memcpy(buf,"J\r\n",3);
-       txrx(lpc,buf,3,TXRX_TYPE_DATA);
+       txrx(lpc,buf,3,TXRX_TYPE_CMD);
        lpc->partid=atoi(buf);
 
        return lpc->partid;
@@ -258,11 +263,11 @@ int read_part_id(t_lpc *lpc) {
 
 int read_bcv(t_lpc *lpc) {
 
-       char buf[BUFSIZE];
+       u8 buf[BUFSIZE];
        char *ptr;
 
        memcpy(buf,"K\r\n",3);
-       txrx(lpc,buf,3,TXRX_TYPE_DATA);
+       txrx(lpc,buf,3,TXRX_TYPE_CMD);
        ptr=strtok(buf,"\r\n");
        lpc->bcv[0]=strtol(ptr,NULL,16);
        ptr=strtok(NULL,"\r\n");
@@ -271,7 +276,7 @@ int read_bcv(t_lpc *lpc) {
        return 0;
 }
 
-int uuencode(char *in,char *out) {
+int uuencode(u8 *in,u8 *out) {
 
        out[0]=0x20+((in[0]>>2)&0x3f);
        out[1]=0x20+(((in[0]<<4)|(in[1]>>4))&0x3f);
@@ -281,27 +286,84 @@ int uuencode(char *in,char *out) {
        return 0;
 }
 
-int write_to_ram(t_lpc *lpc,char *buf,int addr,int len) {
+int write_to_ram(t_lpc *lpc,u8 *buf,int addr,int len) {
 
        int lcount;
        u8 checksum;
+       u8 txrxbuf[BUFSIZE];
+       int count,bcnt;
+       int nlen,slen;
+       int i;
 
+       /* check length */
        if(len%4) {
                printf("ram write: not a multiple of 4\n");
                return -1;
        }
 
-       while(1) {
+       /* make it a multiple of 3 (reason: uuencode) */
+       nlen=(len/3+1)*3;
+       if(nlen>BUFSIZE) {
+               printf("ram write: too much data\n");
+               return -1;
+       }
+       for(i=len;i<nlen;i++) buf[i]=0;
+
+       /* prepare write command */
+       snprintf(txrxbuf,BUFSIZE,"W %d %d",addr,len);
+       slen=strlen(txrxbuf);
+       txrxbuf[slen]='\r';
+       txrxbuf[slen+1]='\0';
+       slen+=2;
+
+       /* 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;
+       }
+
+       /* send data */
+       lcount=0;
+       bcnt=0;
+       count=0;
+       checksum=0;
+       while(bcnt<nlen) {
+
+               /* uuencode / prepare data bytes */
+               uuencode(buf+bcnt,txrxbuf);
+               txrxbuf[4]='\0';
+               txrxbuf[5]='\0';
+
+               /* checksum */
+               checksum+=(buf[0]+buf[1]+buf[2]);
+
+               /* send a data line */
+               txrx(lpc,txrxbuf,6,TXRX_TYPE_DATA);
+
+               /* increase counters */
+               lcount+=1;
+               bcnt+=3;
+               count+=3;
+
+               /* checksum */
                if(!(lcount%20)) {
                        /* send checksum */
-                       if(lcount!=0) {
-                               
+                       txrxbuf[0]=checksum;
+                       txrx(lpc,txrxbuf,1,TXRX_TYPE_CMD);
+                       if(!strncmp(txrxbuf,"RESEND\r\n",8)) {
+                               printf("ram write: resending ...\n");
+                               bcnt-=count;
+                       }
+                       if(strncmp(txrxbuf,"OK\r\n",4)) {
+                               printf("ram write: bad response\n");
+                               return -1;
                        }
-                       /* reset checksum */
+                       /* reset checksum & counter */
                        checksum=0;
+                       count=0;
                }
 
-               lcount+=1;
        }
 
        return 0;