From 0fc424031bf4abacf6453411be806f7a0b7106d8 Mon Sep 17 00:00:00 2001 From: claudiol Date: Wed, 22 May 2019 12:53:43 -0400 Subject: [PATCH] Fixed jump table relocation problem. Firmware update works. --- firmware/sys/target_50g/usbdriver.c | 2 +- firmware/sys/usbcommon.c | 41 +++++++++++++++-------------- newrpl-fw.pro | 4 +-- usbselector.cpp | 7 +++++ 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/firmware/sys/target_50g/usbdriver.c b/firmware/sys/target_50g/usbdriver.c index 3b3e2e2..c56c83c 100644 --- a/firmware/sys/target_50g/usbdriver.c +++ b/firmware/sys/target_50g/usbdriver.c @@ -339,7 +339,7 @@ BYTE __usb_rxtxbuffer[LONG_BUFFER_SIZE] __SCRATCH_MEMORY__; // LARG BINT __usb_rxoffset __SYSTEM_GLOBAL__; // STARTING OFFSET OF THE DATA IN THE RX BUFFER volatile BINT __usb_rxtxtop __SYSTEM_GLOBAL__; // NUMBER OF BYTES USED IN THE RX BUFFER volatile BINT __usb_rxtxbottom __SYSTEM_GLOBAL__; // NUMBER OF BYTES IN THE RX BUFFER ALREADY READ BY THE USER -BINT __usb_rxtotalbytes __SYSTEM_GLOBAL__; // TOTAL BYTES ON THE FILE, 0 MEANS DON'T KNOW YET +volatile BINT __usb_rxtotalbytes __SYSTEM_GLOBAL__; // TOTAL BYTES ON THE FILE, 0 MEANS DON'T KNOW YET BINT __usb_txtotalbytes __SYSTEM_GLOBAL__; // TOTAL BYTES ON THE FILE, 0 MEANS DON'T KNOW YET BINT __usb_txseq __SYSTEM_GLOBAL__; // SEQUENTIAL NUMBER WITHIN A FRAGMENT OF DATA diff --git a/firmware/sys/usbcommon.c b/firmware/sys/usbcommon.c index efb3575..e159a6c 100644 --- a/firmware/sys/usbcommon.c +++ b/firmware/sys/usbcommon.c @@ -308,7 +308,9 @@ void usb_receivecontrolpacket() // SIGNAL THE ERROR AND LEAVE THE REQUESTED OFFSET AT rxoffset __usb_drvstatus|=USB_STATUS_ERROR; __usb_rxoffset=ctl->p_offset; - } + } else { + __usb_drvstatus&=~USB_STATUS_ERROR; + } if(ctl->p_data[2]) { // SIGNAL THAT THE REMOTE ACKNOWLEDGED THE END OF FILE MARK __usb_drvstatus|=USB_STATUS_EOF; @@ -477,8 +479,8 @@ int usb_txfileopen(int file_type) end=tmr_ticks(); if(tmr_ticks2ms(start,end)>USB_TIMEOUT_MS) { //************************************ - fprintf(stderr,"fileopen previous data timeout\n"); - fflush(stderr); + //fprintf(stderr,"fileopen previous data timeout\n"); + ////fflush(stderr); //************************************ return 0; } @@ -503,8 +505,8 @@ int usb_txfileopen(int file_type) if(tmr_ticks2ms(start,end)>USB_TIMEOUT_MS) { //************************************ - fprintf(stderr,"fileopen general timeout\n"); - fflush(stderr); + //fprintf(stderr,"fileopen general timeout\n"); + //fflush(stderr); //************************************ __usb_fileid=0; return 0; // FAIL IF TIMEOUT @@ -513,8 +515,8 @@ int usb_txfileopen(int file_type) usb_sendcontrolpacket(P_TYPE_GETSTATUS); if(!usb_waitforreport()) { //************************************ - fprintf(stderr,"fileopen NO REPORT timeout\n"); - fflush(stderr); + //fprintf(stderr,"fileopen NO REPORT timeout\n"); + //fflush(stderr); //************************************ __usb_fileid=0; return 0; // FAIL IF TIMEOUT @@ -533,8 +535,8 @@ int usb_txfileopen(int file_type) // REPLYING WITH A DIFFERENT FILEID, PERHAPS IT'S STILL CLOSING THE PREVIOUS FILE // KEEP WAITING //************************************ - fprintf(stderr,"fileopen bad fileid\n"); - fflush(stderr); + //fprintf(stderr,"fileopen bad fileid\n"); + //fflush(stderr); //************************************ } @@ -600,8 +602,8 @@ int usb_filewrite(int fileid,BYTEPTR data,int nbytes) __usb_rxtxtop=new__usb_rxtxtop; __usb_drvstatus|=USB_STATUS_TXDATA; //************************************ - fprintf(stderr,"Write %d bytes, offset=%d\n",available,__usb_offset); - fflush(stderr); + //fprintf(stderr,"Write %d bytes, offset=%d\n",available,__usb_offset); + //fflush(stderr); //************************************ nbytes-=available; sent+=available; @@ -620,11 +622,6 @@ int usb_txfileclose(int fileid) // SET THE TOTAL SIZE OF THE FILE BASED ON THE LAST BUFFER SENT int total=__usb_rxtxtop-__usb_rxtxbottom; if(total<0) total+=RING_BUFFER_SIZE; - //************************************ - fprintf(stderr,"fileclose totalbytes=%d, top=%d,bottom=%d,offset=%d\n",__usb_offset+total,__usb_rxtxtop,__usb_rxtxbottom,__usb_offset); - fprintf(stderr,"fileclose __usb_txtotalbytes=%d\n",__usb_txtotalbytes); - fflush(stderr); - //************************************ __usb_txtotalbytes=__usb_offset+total; // SIGNAL THAT WE HAVE A NEW BUFFER READY @@ -645,8 +642,8 @@ int usb_txfileclose(int fileid) if(!__usb_fileid) { result=0; //************************************ - fprintf(stderr,"fileclose ABORTED file\n"); - fflush(stderr); + //fprintf(stderr,"fileclose ABORTED file\n"); + //fflush(stderr); //************************************ break; } // COMMUNICATION WAS ABORTED @@ -656,8 +653,8 @@ int usb_txfileclose(int fileid) end=tmr_ticks(); if(tmr_ticks2ms(start,end)>USB_TIMEOUT_MS) { //************************************ - fprintf(stderr,"filclose timeout\n"); - fflush(stderr); + //fprintf(stderr,"filclose timeout\n"); + //fflush(stderr); //************************************ result=0; break; } // FAIL IF TIMEOUT @@ -666,6 +663,10 @@ int usb_txfileclose(int fileid) } while(1); + //************************************ + //fprintf(stderr,"fileclose totalbytes=%d\n",__usb_txtotalbytes); + //fflush(stderr); + //************************************ __usb_fileid=0; // CLOSE THE FILE diff --git a/newrpl-fw.pro b/newrpl-fw.pro index 9d7d118..fe16e88 100644 --- a/newrpl-fw.pro +++ b/newrpl-fw.pro @@ -323,8 +323,8 @@ QMAKE_CXX = arm-none-eabi-g++ QMAKE_LINK = arm-none-eabi-gcc #QMAKE_AR_CMD = arm-none-eabi-ar -cqs $(TARGET) $(OBJECTS) #QMAKE_AR_CMD = arm-none-eabi-ld --verbose -T$$PWD/firmware/ld.script -nodefaultlibs -nostdlib -L$$GCC_LIBDIR $(OBJECTS) -lgcc -o $(TARGET).elf -QMAKE_CFLAGS_DEBUG = -g -mtune=arm920t -mcpu=arm920t -mlittle-endian -fomit-frame-pointer -fno-toplevel-reorder -msoft-float -Og -pipe -mthumb-interwork -nostdinc -QMAKE_CFLAGS_RELEASE = -g -mtune=arm920t -mcpu=arm920t -mlittle-endian -fomit-frame-pointer -fno-toplevel-reorder -msoft-float -O2 -fno-partial-inlining -pipe -mthumb-interwork -nostdinc +QMAKE_CFLAGS_DEBUG = -g -mtune=arm920t -mcpu=arm920t -mlittle-endian -fno-jump-tables -fomit-frame-pointer -fno-toplevel-reorder -msoft-float -Og -pipe -mthumb-interwork -nostdinc +QMAKE_CFLAGS_RELEASE = -g -mtune=arm920t -mcpu=arm920t -mlittle-endian -fno-jump-tables -fomit-frame-pointer -fno-toplevel-reorder -msoft-float -O2 -fno-partial-inlining -pipe -mthumb-interwork -nostdinc QMAKE_CFLAGS_SHLIB = QMAKE_CFLAGS_MT = QMAKE_CFLAGS_MT_DBG = diff --git a/usbselector.cpp b/usbselector.cpp index 777c276..a0b265b 100644 --- a/usbselector.cpp +++ b/usbselector.cpp @@ -761,6 +761,13 @@ void FWThread::run() header[1]=__fwupdate_address+(offset<<2); header[2]=1024; + //************************************ + fprintf(stderr,"Starting flash block=%08X\n",header[1]); + fflush(stderr); + //************************************ + + + if(result && (!usb_filewrite(fileid,(BYTEPTR)header,3*sizeof(WORD)))) { // TODO: SOME KIND OF ERROR result=0;