]> hackdaworld.org Git - my-code/arm.git/commitdiff
cksm implemented (still basic flash access not working!)
authorhackbard <hackbard@staubsauger.localdomain>
Sat, 1 Sep 2007 22:22:45 +0000 (00:22 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Sat, 1 Sep 2007 22:22:45 +0000 (00:22 +0200)
betty/fwflash.c
betty/lpcload.c

index c4a2155a6089a71ce083c36b7bf6fb466bc2187a..2704fd5a41d96c484e26dc020be8b8e174fe2105 100644 (file)
@@ -295,6 +295,8 @@ void receive_data_and_write_to_flash(u32 addr,u32 datalen) {
        u8 bank;
        u32 i;
        u16 data;
+       u8 byte;
+       u8 cksm;
 
        /* which bank to program */
        if(addr<0x82000000)
@@ -306,9 +308,14 @@ void receive_data_and_write_to_flash(u32 addr,u32 datalen) {
        unlock_bypass(bank);
 
        /* receive and write data */
+       cksm=0;
        for(i=0;i<datalen/2;i++) {
-               data=uart0_get_byte();
-               data=uart0_get_byte()<<8;
+               byte=uart0_get_byte();
+               data=byte;
+               cksm+=byte;
+               byte=uart0_get_byte();
+               cksm+=byte;
+               data|=byte<<8;
                *((unsigned volatile short *)addr)=0xa0;
                *((unsigned volatile short *)addr)=data;
                addr+=2;
@@ -316,6 +323,9 @@ void receive_data_and_write_to_flash(u32 addr,u32 datalen) {
 
        /* relock bypass */
        unlock_bypass_reset(bank);
+
+       /* send an ack */
+       uart0_send_byte(cksm);
 }
 
 /*
index 4f62a59253febac2fd3f716dce996f3b69eb2f16..748a0963c06a1a2781412822b4dbc5e7ec14fab4 100644 (file)
@@ -539,31 +539,30 @@ int send_cmd(int sfd,u32 addr,u32 len,u8 cmd) {
                send[1+i+as]=(len>>((ls-1-i)*8))&0xff;
 
        cnt=0;
-       printf("  sending cmd: ");
        while(size) {
                ret=write(sfd,send+cnt,size);
                if(ret<0) {
                        perror("dump file: send cmd ");
                        return ret;
                }
-               for(i=cnt;i<cnt+ret;i++)
-                       printf("%02x ",send[i]);
                size-=ret;
                cnt+=ret;
        }
-       printf("\n");
 
        return 0;
 }
 
-int write_to_flash(t_lpc *lpc,char *buf,u32 addr,int len) {
+int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) {
 
        int cnt,size,ret;
+       u8 cksm;
 
        /* send cmd */
-       send_cmd(lpc->sfd,addr,len,CMD_WRITE);
+       send_cmd(lpc->sfd,addr+lpc->roff,len,CMD_WRITE);
 
        /* transfer data */
+       cnt=0;
+       cksm=0;
        while(len) {
                size=2;
                while(size) {
@@ -574,7 +573,21 @@ int write_to_flash(t_lpc *lpc,char *buf,u32 addr,int len) {
                        }
                        size-=ret;
                }
+               cksm+=buf[cnt];
+               cksm+=buf[cnt+1];
                cnt+=2;
+               len-=2;
+       }
+
+       /* check ack */
+       ret=read(lpc->sfd,buf,1);
+       if(ret<0) {
+               perror("write to flash: ack rx");
+               return ret;
+       }
+       if(buf[0]!=cksm) {
+               printf("FATAL: write to ram: wrong checksum!\n");
+               return -1;
        }
 
        return 0;
@@ -647,7 +660,7 @@ int firmware_to_mem(t_lpc *lpc,u8 memtype) {
                                if(memtype==RAM)
                                        write_to_ram(lpc,buf,addr,len);
                                else
-                                       write_to_flash(lpc,buf,addr,len);
+                                       write_to_flash(lpc,(u8 *)buf,addr,len);
                                break;
                        case 0x04:
                                lpc->roff=((buf[0]<<24)|(buf[1]<<16));
@@ -841,7 +854,8 @@ int main(int argc,char **argv) {
 
        /* write a firmware to the lpc flash */
        if(lpc.info&FLASHFW) {
-               send_cmd(lpc.sfd,0,0,CMD_CHIP_ERASE);
+               printf("writing firmware to flash ...\n");
+               send_cmd(lpc.sfd,0,'0',CMD_CHIP_ERASE);
                lpc.roff=BANK0_ADDR;
                firmware_to_mem(&lpc,FLASH);
        }