else
status=B2F;
- if(status&0x80)
+ if(status&0x80) {
+ /* send an ack */
+ uart0_send_byte(status);
break;
+ }
}
}
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)
cnt+=ret;
}
+ /* flush */
+ tcflush(sfd,TCIOFLUSH);
+
return 0;
}
int cnt,ret;
u8 cksml,cksmr;
- u8 check;
int i;
/* prepare addr */
/* transfer data */
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) {
len-=ret;
cnt+=ret;
}
- */
+
/* check ack */
while(1) {
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);
}