no byte reply anymore (due to ack and tcflush) -> incredible speedup!
authorhackbard <hackbard@staubsauger.localdomain>
Tue, 4 Sep 2007 00:06:05 +0000 (02:06 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Tue, 4 Sep 2007 00:06:05 +0000 (02:06 +0200)
betty/fwflash.c
betty/lpcload.c

index fd8d31b..85a64fa 100644 (file)
@@ -272,8 +272,11 @@ void flash_chip_erase(u8 bank) {
                else
                        status=B2F;
 
-               if(status&0x80)
+               if(status&0x80) {
+                       /* send an ack */
+                       uart0_send_byte(status);
                        break;
+               }
        }
 }
 
@@ -351,11 +354,9 @@ int receive_data_and_write_to_flash(u32 addr,u32 datalen) {
        ret=0;
        for(i=0;i<datalen/2;i++) {
                byte=uart0_get_byte();
-               uart0_send_byte(byte);
                data=byte;
                cksm+=byte;
                byte=uart0_get_byte();
-               uart0_send_byte(byte);
                cksm+=byte;
                data|=byte<<8;
                if(flash_write(addr,data)<0)
index e1e12b7..38d5386 100644 (file)
@@ -556,6 +556,9 @@ int send_cmd(int sfd,u32 addr,u32 len,u8 cmd) {
                cnt+=ret;
        }
 
+       /* flush  */
+       tcflush(sfd,TCIOFLUSH);
+
        return 0;
 }
 
@@ -563,7 +566,6 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) {
 
        int cnt,ret;
        u8 cksml,cksmr;
-       u8 check;
        int i;
 
        /* prepare addr */
@@ -576,39 +578,6 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) {
        cnt=0;
        cksml=0;
        while(len) {
-               for(i=0;i<2;i++) {
-                       while(1) {
-                               ret=write(lpc->sfd,buf+cnt+i,1);
-                               if(ret<0) {
-                                       perror("transmit flash content (w)");
-                                       return ret;
-                               }
-                               if(ret==1)
-                                       break;
-                       }
-                       while(1) {
-                               ret=read(lpc->sfd,&check,1);
-                               if(ret<0) {
-                                       perror("transmit flash content (r)");
-                                       return ret;
-                               }
-                               if(ret==1)
-                                       break;
-                       }
-                       if(buf[cnt+i]!=check)
-                               printf("FATAL: write to flash (transfer)\n");
-               }
-               cksml+=buf[cnt];
-               cksml+=buf[cnt+1];
-               cnt+=2;
-               len-=2;
-       }
-
-
-       /*
-       cnt=0;
-       cksml=0;
-       while(len) {
                ret=write(lpc->sfd,buf+cnt,len);
                if(ret<0) {
                        perror("transmit flash content (w)");
@@ -619,7 +588,7 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) {
                len-=ret;
                cnt+=ret;
        }
-       */
+
 
        /* check ack */
        while(1) {
@@ -931,6 +900,10 @@ int main(int argc,char **argv) {
        if(lpc.info&FLASHFW) {
                printf("writing firmware to flash ...\n");
                send_cmd(lpc.sfd,0,'0',CMD_CHIP_ERASE);
+               /* ack */
+               ret=0;
+               while(!ret)
+                       read(lpc.sfd,&ret,1);
                lpc.roff=BANK0_ADDR;
                firmware_to_mem(&lpc,FLASH);
        }