From: hackbard Date: Sat, 28 Jul 2007 02:19:33 +0000 (+0200) Subject: added lpcload tool to upload firmware into lpc2220 ram vi uart0 X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f99ed5c4faba98f0afda8d3f90d0481fc70258ee;p=my-code%2Farm.git added lpcload tool to upload firmware into lpc2220 ram vi uart0 --- diff --git a/betty/lpcload.c b/betty/lpcload.c new file mode 100644 index 0000000..e2bef73 --- /dev/null +++ b/betty/lpcload.c @@ -0,0 +1,227 @@ +/* + * lpcload.c - load firmware into ram of lpc2220 via uart0 + * + * author: hackbard@hackdaworld.org + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define VERBOSE (1<<0) +#define FIRMWARE (1<<1) + +#define CRYSTFREQ "10000" + +#define BUFSIZE 64 + +void usage(void) { + + printf("possible argv:\n"); + printf(" -d \n"); + printf(" -f \n"); + printf(" -c \n"); + printf(" -v\n"); + +} + +int txrx(int fd,char *buf,int *len,unsigned char v) { + + int ret,cnt; + int i; + + /* write */ + + if(v&VERBOSE) + printf(" >> "); + cnt=0; + while(*len) { + ret=write(fd,buf+cnt,*len); + if(ret<0) { + perror("txrx write"); + return ret; + } + if(v&VERBOSE) + for(i=0;i0x19)&(buf[cnt+i]<0x7f))? + buf[cnt+i]:'.'); + *len-=ret; + cnt+=ret; + } + if(v&VERBOSE) + printf(" (%d)\n",cnt); + + /* cut the echo */ + // add more checking here! + while(cnt) + cnt-=read(fd,buf,cnt); + + /* read */ + + if(v&VERBOSE) + printf(" << "); + ret=1; + cnt=0; + while(ret>0) { + ret=read(fd,buf+cnt,BUFSIZE-cnt); + if(ret<0) { + perror("txrx read"); + return ret; + } + if(ret+cnt>BUFSIZE) { + printf("txrx read: too small buf size (%d)!\n",BUFSIZE); + return -1; + } + if(v&VERBOSE) + for(i=0;i0x19)&(buf[cnt+i]<0x7f))? + buf[cnt+i]:'.'); + cnt+=ret; + } + if(v&VERBOSE) + printf(" (%d)\n",cnt); + *len=cnt; + + return cnt; +} + +int main(int argc,char **argv) { + + int i; + char tts[128]; + int tts_fd; + char fw[128]; + int fw_fd; + unsigned char info; + struct termios term; + char cfreq[8]; + int len; + char buf[BUFSIZE]; + + /* + * initial ... + */ + + info=0; + memset(&term,0,sizeof(struct termios)); + strncpy(cfreq,CRYSTFREQ,7); + + /* parse argv */ + + for(i=1;i 8n1 + + term.c_cflag&=~PARENB; // no parity + term.c_cflag&=~CSTOPB; // only 1 stop bit + term.c_cflag&=~CSIZE; // no bit mask for data bits + term.c_cflag|=CS8; // 8 data bits + + // line options -> raw input + + term.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG); + + // input options -> disable flow control + + term.c_iflag&=~(IXON|IXOFF|IXANY); + + // more control options -> timeout + + term.c_cc[VMIN]=0; + term.c_cc[VTIME]=10; // 1 second timeout + + tcsetattr(tts_fd,TCSANOW,&term); + + /* auto baud sequence */ + + write(tts_fd,"?",1); + len=0; + txrx(tts_fd,buf,&len,info); + if(strncmp(buf,"Synchronized\r\n",14)) { + printf("auto baud detection failed\n"); + return -1; + } + + /* tell bl that we are synchronized (it's allready in buf) */ + len=14; + txrx(tts_fd,buf,&len,info); + if(strncmp(buf,"OK\r\n",4)) { + printf("sync failed\n"); + return -1; + } + + /* tell bl the crystal frequency */ + len=strlen(cfreq)+2; + strncpy(buf,cfreq,BUFSIZE); + buf[len-2]='\r'; + buf[len-1]='\n'; + txrx(tts_fd,buf,&len,info); + if(strncmp(buf,"OK\r\n",4)) { + printf("freq set failed\n"); + return -1; + } + + + // to be continued ... (parsing fw file and poking it to ram) + +end: + close(tts_fd); + + return 0; +} + diff --git a/betty/readme b/betty/readme index c95b57c..bd8d4a8 100644 --- a/betty/readme +++ b/betty/readme @@ -4,6 +4,8 @@ the betty tv project contents: --------- +* lpcload.c - loads firmware to the lpc2220 via uart0 + * betty.c - replacement firmware for the betty tv remote