+ char buf[BUFSIZE];
+ u8 data[BUFSIZE];
+ u32 addr,len,type,val;
+ u8 cksum;
+ int ret,i;
+
+ /* read a line */
+ while(ret) {
+ /* sync line */
+ ret=read(lpc->fwfd,buf,1);
+ switch(buf[0]) {
+ case '\r':
+ continue;
+ case '\n':
+ continue;
+ case ':':
+ /* start code */
+ break;
+ default:
+ printf("fw to ram: no ihex format\n");
+ return -1;
+ }
+ /* read len */
+ ret=read(lpc->fwfd,buf,2);
+ sscanf(buf,"%02x",&len);
+ if(len%4) {
+ printf("fw to ram: len not a multiple of 4\n");
+ return -1;
+ }
+ /* read addr */
+ ret=read(lpc->fwfd,buf,4);
+ sscanf(buf,"%04x",&addr);
+ /* read type */
+ ret=read(lpc->fwfd,buf,2);
+ sscanf(buf,"%02x",&type);
+ /* successfull return if type is end of file */
+ if(type==0x01)
+ return 0;
+ /* read data */
+ ret=read(lpc->fwfd,buf,2*len);
+ if(ret!=(2*len)) {
+ printf("fw to ram: data missing\n");
+ return -1;
+ }
+ /* checksum */
+ cksum=0;
+ for(i=0;i<len;i++) {
+ sscanf(buf+2*i,"%02x",&val);
+ data[i]=val;
+ cksum+=data[i];
+ }
+ ret=read(lpc->fwfd,buf,2);
+ sscanf(buf,"%02x",&val);
+ if(val+cksum!=0x100) {
+ printf("fw to ram: wrong checksum\n");
+ return -1;
+ }
+ /* act according to type */
+ switch(type) {
+ case 0x03:
+ /* get cs and ip */
+ break;
+ case 0x00:
+ write_to_ram(lpc,data,addr,len);
+ break;
+ default:
+ printf("fw to ram: unknown type %02x\n",type);
+ return -1;
+ }
+ }