u8 bank;
u32 i;
u16 data;
+ u8 byte;
+ u8 cksm;
/* which bank to program */
if(addr<0x82000000)
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;
/* relock bypass */
unlock_bypass_reset(bank);
+
+ /* send an ack */
+ uart0_send_byte(cksm);
}
/*
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) {
}
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;
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));
/* 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);
}