X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Flpcload.c;h=e1e12b75f1733e66d5bf18260b508671b8328787;hb=a46c0ecf2bd18049cd2fd75d0ab57fe24a62d951;hp=9f60d88c8ab921602c72a0ed6d0d3a606d3f8fc9;hpb=e013de8b92ff7ba9cf70c7c8669c023a315f1348;p=my-code%2Farm.git diff --git a/betty/lpcload.c b/betty/lpcload.c index 9f60d88..e1e12b7 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -22,6 +22,7 @@ #define BANK2 (1<<3) #define BL (1<<4) #define FLASHFW (1<<5) +#define BINARY (1<<6) #define BANK0_ADDR 0x80000000 #define BANK2_ADDR 0x82000000 @@ -97,6 +98,7 @@ void usage(void) { printf(" -Dx \n"); printf(" x=0: bank0, x=2: bank2, x=b: bootloader\n"); printf(" -w \n"); + printf(" -b (if firmware for flash is a binary)\n"); printf(" -v\n"); } @@ -564,8 +566,11 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) { u8 check; int i; + /* prepare addr */ + addr+=lpc->roff; + /* send cmd */ - send_cmd(lpc->sfd,addr+lpc->roff,len,CMD_WRITE); + send_cmd(lpc->sfd,addr,len,CMD_WRITE); /* transfer data */ cnt=0; @@ -591,7 +596,7 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) { break; } if(buf[cnt+i]!=check) - printf("FATAL: write to flash: wrong transfer\n"); + printf("FATAL: write to flash (transfer)\n"); } cksml+=buf[cnt]; cksml+=buf[cnt+1]; @@ -599,6 +604,23 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) { len-=2; } + + /* + cnt=0; + cksml=0; + while(len) { + ret=write(lpc->sfd,buf+cnt,len); + if(ret<0) { + perror("transmit flash content (w)"); + return ret; + } + for(i=cnt;isfd,&cksmr,1); @@ -611,9 +633,10 @@ int write_to_flash(t_lpc *lpc,u8 *buf,u32 addr,int len) { if(cksml!=cksmr) { printf("FATAL: wrong checksum or failure in flash write!\n"); if(cksml+1==cksmr) - printf(" -> most probably due to flash write!"); + printf(" -> most probably due to flash write!\n"); else - printf(" -> most probably due to failure in transfer!"); + printf(" -> most probably failure in transfer!\n"); + printf(" addr:0x%08x l:%02x r:%02x\n",addr,cksml,cksmr); } return 0; @@ -634,6 +657,29 @@ int firmware_to_mem(t_lpc *lpc,u8 memtype) { else return -1; + /* another evil hack to support binary format */ + if((lpc->info&BINARY)&&(memtype==FLASH)) { + addr=0; + ret=1; + while(ret) { + ret=read(fd,buf,16); + if(ret!=16) { + printf("D'OH ...\n"); + return -1; + } + buf[16]='s'; // skip + for(temp=0;temp<16;temp++) + if((u8)buf[temp]!=0xff) + buf[16]='w'; // write + printf("addr:%08x\r",addr+lpc->roff); + fflush(stdout); + if(buf[16]=='w') + write_to_flash(lpc,(u8 *)buf,addr,16); + addr+=16; + } + return 0; + } + /* read a line */ ret=1; while(ret) { @@ -821,6 +867,9 @@ int main(int argc,char **argv) { strncpy(lpc.ffwfile,argv[++i],127); lpc.info|=FLASHFW; break; + case 'b': + lpc.info|=BINARY; + break; default: usage(); return -1;