From: Stephan Baerwolf Date: Mon, 19 Nov 2012 13:33:58 +0000 (+0100) Subject: BUG: fix updater.c to cope with more than 64k flash memory X-Git-Tag: v0.95~4 X-Git-Url: http://git.linex4red.de/pub/USBaspLoader.git/commitdiff_plain/17a4e6e3c2cd19fed08d94f9949140494056484f BUG: fix updater.c to cope with more than 64k flash memory Signed-off-by: Stephan Baerwolf --- diff --git a/updater/updater.c b/updater/updater.c index 0fb4f35..75f0996 100644 --- a/updater/updater.c +++ b/updater/updater.c @@ -129,6 +129,23 @@ void temp_do_spm(const uint32_t flash_byteaddress, const uint8_t spmcrval, const typedef uint32_t mypgm_addr_t; typedef void (*mypgm_spminterface)(const uint32_t flash_byteaddress, const uint8_t spmcrval, const uint16_t dataword); +#if FLASHEND > 65535 +# define mymemcpy_PF mymemcpy_PF_far +void *mymemcpy_PF_far (void *dest, mypgm_addr_t src, size_t n) { + uint8_t *pagedata = (void*)dest; + mypgm_addr_t pageaddr = src; + size_t i; + + for (i=0;i 65535) + deeword=pgm_read_word_far(pageaddr); +#else deeword=pgm_read_word(pageaddr); +#endif if (deeword != pagedata[i]) changed=1; @@ -260,8 +281,13 @@ int main(void) buffer[0]=0; for (i=0;i 65535) + a=pgm_read_word_far((void*)&new_firmware[i]); + b=pgm_read_word_far(NEW_BOOTLOADER_ADDRESS+i); +#else a=pgm_read_word((void*)&new_firmware[i]); b=pgm_read_word(NEW_BOOTLOADER_ADDRESS+i); +#endif if (a!=b) { buffer[0]=1; break; @@ -273,7 +299,6 @@ int main(void) // need to change the firmware... if (buffer[0]) { - // A // copy the current "bootloader__do_spm" to tempoary position via std. "bootloader__do_spm" for (i=0;isizeof(buffer))?sizeof(buffer):(SIZEOF_new_firmware-i)); + mymemcpy_PF((void*)buffer, (uint_farptr_t)((void*)&new_firmware[i]), ((SIZEOF_new_firmware-i)>sizeof(buffer))?sizeof(buffer):(SIZEOF_new_firmware-i)); mypgm_WRITEpage(NEW_BOOTLOADER_ADDRESS+i, buffer, sizeof(buffer), temp_do_spm); @@ -300,7 +325,7 @@ int main(void) #ifdef CONFIG_UPDATER_CLEANMEMCLEAR memset((void*)buffer, 0xff, sizeof(buffer)); #endif - memcpy_PF((void*)buffer, (uint_farptr_t)((void*)&new_firmware[i]), ((SIZEOF_new_firmware-i)>sizeof(buffer))?sizeof(buffer):(SIZEOF_new_firmware-i)); + mymemcpy_PF((void*)buffer, (uint_farptr_t)((void*)&new_firmware[i]), ((SIZEOF_new_firmware-i)>sizeof(buffer))?sizeof(buffer):(SIZEOF_new_firmware-i)); mypgm_WRITEpage(NEW_BOOTLOADER_ADDRESS+i, buffer, sizeof(buffer), new_do_spm);