X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Flpcload.c;h=80af804153dc5697da32ba6ae3f30a598cfcd45d;hb=9fe785e6bc1cf36626f4a3db7877b5f7df76ed61;hp=0d2f9c85ddd9bfd9f5394c556a38ee666d707aa8;hpb=feece393fb07514608a7ad21eaa376ea3375e945;p=my-code%2Farm.git diff --git a/betty/lpcload.c b/betty/lpcload.c index 0d2f9c8..80af804 100644 --- a/betty/lpcload.c +++ b/betty/lpcload.c @@ -112,11 +112,15 @@ int open_serial_device(t_lpc *lpc) { //term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL); term.c_iflag&=~(INLCR|ICRNL|IXANY); term.c_iflag|=(IXON|IXOFF); + + // output options + + term.c_oflag=0; // more control options -> timeout / flow control term.c_cc[VMIN]=0; - term.c_cc[VTIME]=10; // 1 second timeout + term.c_cc[VTIME]=40; // 4 second timeout term.c_cc[VSTART]=0x11; term.c_cc[VSTOP]=0x13; @@ -471,12 +475,15 @@ int firmware_to_ram(t_lpc *lpc) { } /* act according to type */ switch(type) { - case 0x03: - /* get cs and ip */ - break; + //case 0x03: + // /* get cs and ip */ + // break; case 0x00: write_to_ram(lpc,buf,addr,len); break; + case 0x01: + write_to_ram(lpc,buf,addr,len); + break; default: printf("fw to ram: unknown type %02x\n",type); return -1; @@ -490,6 +497,8 @@ int main(int argc,char **argv) { t_lpc lpc; int i; + u8 buf[BUFSIZE]; + int ret; /* * initial ... @@ -533,15 +542,21 @@ 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"); if(bl_init(&lpc)<0) return -1; + /* quit if there is no hex file to process */ + if(!(lpc.info&FIRMWARE)) { + printf("no firmware -> aborting\n"); + goto end; + } + + /* open firmware file */ + if(open_firmware(&lpc)<0) + goto end; + /* parse intel hex file and write to ram */ printf("write firmware to ram ...\n"); firmware_to_ram(&lpc); @@ -552,9 +567,31 @@ int main(int argc,char **argv) { /* go! */ printf("go ...\n"); - go(&lpc); + ret=go(&lpc); + + /* tell the user that the error might be due to the jump */ + printf("\n\n"); + if(ret<0) + printf("the above error might be due to the jump!\n\n"); + + /* query user for serial port listening */ + printf("continue listening on serial port? (ctrl+c to quit) [y|n]: "); + buf[0]=getchar(); printf("\n"); + if(buf[0]!='y') + goto end; + + /* continue lsitening on serial port */ + ret=1; + while(ret) { + ret=read(lpc.sfd,buf,BUFSIZE); + printf("\rread %d bytes: ",ret); + for(i=0;i