# where the updating firmware should be located (starting address)
FLASHADDRESS = 0x0000
+# use any fix (ATxmega compatible) crc32, uncomment to disable feature or set automatically with value "0"
+;UPDATECRC32 = 0
+
# some MCU independent defines...
#...will be extended within MCU dependend configuration below...
DEFINES += -DCONFIG_NO__CHIP_ERASE -DCONFIG_NO__ONDEMAND_PAGEERASE
updater.o: updater.c usbasploader.h usbasploader.raw usbasploader.o $(DEPENDS)
+ifndef UPDATECRC32
$(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) $(CFLAGS)
+else
+ifeq ($(UPDATECRC32), 0)
+ $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) -DUPDATECRC32=0x$(shell crc32 usbasploader.raw) $(CFLAGS)
+else
+ $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) -DUPDATECRC32=$(UPDATECRC32) $(CFLAGS)
+endif
+endif
# $(CC) updater.c -c -o updater.o $(CFLAGS)
updater.elf: updater.o usbasploader.o $(DEPENDS)
--- /dev/null
+/****************************************************************************/
+/* CRC32 stuff taken and adapted from lib_crc version 1.16 : */
+/* Library : lib_crc */
+/* File : lib_crc.c */
+/* Author : Lammert Bies 1999-2008 */
+/* E-mail : info@lammertbies.nl */
+/****************************************************************************/
+
+/* the ATxmega series NVM CRC compatible polynom */
+/* on ATxmega you can do this much faster in hardware */
+#define P_32 0xEDB88320L
+#define D_32 0xFFFFFFFFL
+
+uint32_t crc_tab32_value(uint8_t address) {
+ uint32_t result;
+ uint8_t j;
+
+ result = (uint32_t)address & 0xffL;
+ for (j=0; j<8; j++) {
+ if (result & 0x00000001L) result = (result >> 1) ^ P_32;
+ else result = result >> 1;
+ }
+
+ return result;
+}
+
+uint32_t update_crc_32(uint32_t crc, uint8_t c) {
+ uint32_t tmp, long_c;
+
+ long_c = (uint32_t)c & 0xffL;
+
+ tmp = crc ^ long_c;
+ crc = (crc >> 8) ^ crc_tab32_value(tmp & 0xffL);
+
+ return crc;
+}
}
#endif
+#if defined(UPDATECRC32)
+#include "crccheck.c"
+#endif
+
// #pragma GCC diagnostic ignored "-Wno-pointer-to-int-cast"
int main(void)
{
+#if defined(UPDATECRC32)
+ uint32_t crcval;
+#endif
size_t i;
uint8_t buffer[SPM_PAGESIZE];
wdt_disable();
cli();
+#if defined(UPDATECRC32)
+ // check if new firmware-image is corrupted
+ crcval = D_32;
+ for (i=0;i<SIZEOF_new_firmware;i+=1) {
+#if (FLASHEND > 65535)
+ crcval = update_crc_32(crcval, pgm_read_byte_far(FULLCORRECTFLASHADDRESS(&new_firmware[i])));
+#else
+ crcval = update_crc_32(crcval, pgm_read_byte(FULLCORRECTFLASHADDRESS(&new_firmware[i])));
+#endif
+ }
+ crcval ^= D_32;
+
+ // allow to change the firmware
+ if (crcval == ((uint32_t)UPDATECRC32)) {
+#endif
+
// check if firmware would change...
buffer[0]=0;
for (i=0;i<SIZEOF_new_firmware;i+=2) {
}
+#if defined(UPDATECRC32)
+ }
+#endif
+
return 0;
}