From: hackbard Date: Sat, 1 Sep 2007 22:22:45 +0000 (+0200) Subject: cksm implemented (still basic flash access not working!) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=eca427bb7d2ac0dbd337a3797fcea63991c51b38;p=my-code%2Farm.git cksm implemented (still basic flash access not working!) --- diff --git a/betty/fwflash.c b/betty/fwflash.c index c4a2155..2704fd5 100644 --- a/betty/fwflash.c +++ b/betty/fwflash.c @@ -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>((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;isfd,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); }