From: hackbard Date: Wed, 1 Aug 2007 13:20:04 +0000 (+0200) Subject: addr modifications (+ ram offset - hex file offset) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=4474a24ed63502f06e217a30350155b7b8ae6a80;p=my-code%2Farm.git addr modifications (+ ram offset - hex file offset) --- diff --git a/betty/lpcload.c b/betty/lpcload.c index c2b1114..a1dd97f 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -40,6 +40,7 @@ #define INVALID_STOP_BIT "18\r\n" #define CRYSTFREQ "10000" +#define RAMOFFSET 0x40000200 #define BUFSIZE 128 @@ -56,6 +57,8 @@ typedef struct s_lpc { char freq[8]; /* frequency */ int partid; /* part id */ u8 bcv[2]; /* boot code version */ + u32 hoff; /* start addr of ihex file */ + u32 roff; /* ram offset of uc */ } t_lpc; void usage(void) { @@ -64,6 +67,7 @@ void usage(void) { printf(" -d \n"); printf(" -f \n"); printf(" -c \n"); + printf(" -r \n"); printf(" -v\n"); } @@ -118,6 +122,9 @@ int open_serial_device(t_lpc *lpc) { int open_firmware(t_lpc *lpc) { + int ret; + char buf[BUFSIZE]; + /* open firmware file */ lpc->fwfd=open(lpc->fwfile,O_RDONLY); @@ -125,6 +132,16 @@ int open_firmware(t_lpc *lpc) { if(lpc->fwfd<0) perror("fw open"); + /* read hex file offset */ + + ret=read(lpc->fwfd,buf,7); + if(buf[0]!=':') { + printf("fw open: not an intel hex file?\n"); + return -1; + } + sscanf(buf+3,"%04x",&(lpc->hoff)); + lseek(lpc->fwfd,0,SEEK_SET); + return lpc->fwfd; } @@ -311,7 +328,12 @@ int write_to_ram(t_lpc *lpc,u8 *buf,u32 addr,int len) { } for(i=len;iroff-lpc->hoff); + /* prepare write command */ + if(lpc->info&VERBOSE) + printf("writing %02x bytes to %08x\n",len,addr); snprintf(txrxbuf,BUFSIZE,"W %d %d\r\n",addr,len); slen=strlen(txrxbuf); @@ -456,6 +478,7 @@ int main(int argc,char **argv) { memset(&lpc,0,sizeof(t_lpc)); strncpy(lpc.freq,CRYSTFREQ,7); + lpc.roff=RAMOFFSET; /* parse argv */ @@ -491,9 +514,14 @@ int main(int argc,char **argv) { if(open_serial_device(&lpc)<0) goto end; + /* open firmware file */ + if(open_firmware(&lpc)<0) + goto end; + /* boot loader init */ printf("boot loader init ...\n"); - bl_init(&lpc); + if(bl_init(&lpc)<0) + return -1; /* read part id */ read_part_id(&lpc); @@ -504,8 +532,6 @@ int main(int argc,char **argv) { printf("boot code version: %02x %02x\n",lpc.bcv[0],lpc.bcv[1]); // to be continued ... (parsing fw file and poking it to ram) - if(open_firmware(&lpc)<0) - goto end; firmware_to_ram(&lpc); end: