From: hackbard Date: Mon, 3 Sep 2007 05:37:20 +0000 (+0200) Subject: support for binaries usinf -b, BUT: dirty dirty slow slow fucked up code! i mean it! X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a46c0ecf2bd18049cd2fd75d0ab57fe24a62d951;p=my-code%2Farm.git support for binaries usinf -b, BUT: dirty dirty slow slow fucked up code! i mean it! --- diff --git a/betty/fwflash.c b/betty/fwflash.c index 7c9551f..fd8d31b 100644 --- a/betty/fwflash.c +++ b/betty/fwflash.c @@ -313,6 +313,9 @@ int flash_write(u32 addr,u16 data) { u16 check; + if(data==0xffff) + return 0; + *((unsigned volatile short *)addr)=0xa0; *((unsigned volatile short *)addr)=data; while(1) { diff --git a/betty/lpcload.c b/betty/lpcload.c index d1bfd54..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"); } @@ -602,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); @@ -638,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) { @@ -825,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;