|
@@ -389,9 +389,28 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
|
|
|
|
|
|
#define buff ((uint8_t*)(RAMSTART))
|
|
|
#ifdef VIRTUAL_BOOT_PARTITION
|
|
|
-#define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
|
|
|
-#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
|
+#define rstVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+4))
|
|
|
+#define rstVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+5))
|
|
|
+#define wdtVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
|
+#define wdtVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+7))
|
|
|
+#if FLASHEND > 8192
|
|
|
+
|
|
|
+#define rstVect0 2
|
|
|
+#define rstVect1 3
|
|
|
+#define wdtVect0 (WDT_vect_num*4+2)
|
|
|
+#define wdtVect1 (WDT_vect_num*4+3)
|
|
|
+#define appstart_vec (WDT_vect_num*2)
|
|
|
+#else
|
|
|
+
|
|
|
+#define rstVect0 0
|
|
|
+#define rstVect1 1
|
|
|
+#define wdtVect0 (WDT_vect_num*2)
|
|
|
+#define wdtVect1 (WDT_vect_num*2+1)
|
|
|
+#define appstart_vec (WDT_vect_num)
|
|
|
#endif
|
|
|
+#else
|
|
|
+#define appstart_vec (0)
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -451,7 +470,7 @@ int main(void) {
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
+
|
|
|
watchdogConfig(WATCHDOG_1S);
|
|
|
|
|
|
#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH)
|
|
@@ -539,23 +558,56 @@ int main(void) {
|
|
|
verifySpace();
|
|
|
|
|
|
#ifdef VIRTUAL_BOOT_PARTITION
|
|
|
- if ((uint16_t)(void*)address == 0) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- uint16_t vect = buff[0] | (buff[1]<<8);
|
|
|
- rstVect = vect;
|
|
|
- wdtVect = buff[8] | (buff[9]<<8);
|
|
|
- vect -= 4;
|
|
|
- buff[8] = vect & 0xff;
|
|
|
- buff[9] = vect >> 8;
|
|
|
+#if FLASHEND > 8192
|
|
|
+
|
|
|
+ * AVR with 4-byte ISR Vectors and "jmp"
|
|
|
+ */
|
|
|
+ if (address == 0) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ rstVect0_sav = buff[rstVect0];
|
|
|
+ rstVect1_sav = buff[rstVect1];
|
|
|
+ wdtVect0_sav = buff[wdtVect0];
|
|
|
+ wdtVect1_sav = buff[wdtVect1];
|
|
|
+
|
|
|
+
|
|
|
+ buff[wdtVect0] = rstVect0_sav;
|
|
|
+ buff[wdtVect1] = rstVect1_sav;
|
|
|
|
|
|
|
|
|
- buff[0] = 0x7f;
|
|
|
- buff[1] = 0xce;
|
|
|
+ buff[rstVect0] = ((uint16_t)main) & 0xFF;
|
|
|
+ buff[rstVect1] = ((uint16_t)main) >> 8;
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+#else
|
|
|
+
|
|
|
+ * AVR with 2-byte ISR Vectors and rjmp
|
|
|
+ */
|
|
|
+ if ((uint16_t)(void*)address == rstVect0) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ rstVect0_sav = buff[rstVect0];
|
|
|
+ rstVect1_sav = buff[rstVect1];
|
|
|
+ wdtVect0_sav = buff[wdtVect0];
|
|
|
+ wdtVect1_sav = buff[wdtVect1];
|
|
|
+
|
|
|
+
|
|
|
+ uint16_t vect=rstVect0_sav+(rstVect1_sav<<8);
|
|
|
+ vect -= WDT_vect_num;
|
|
|
+
|
|
|
+ buff[wdtVect0] = vect & 0xff;
|
|
|
+ buff[wdtVect1] = vect >> 8;
|
|
|
+
|
|
|
+ buff[0] = (((uint16_t)main) & 0xFFF) & 0xFF;
|
|
|
+ buff[1] = ((((uint16_t)main) & 0xFFF) >> 8) | 0xC0;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+#endif
|
|
|
|
|
|
writebuffer(desttype, buff, address, savelength);
|
|
|
|
|
@@ -569,7 +621,7 @@ int main(void) {
|
|
|
desttype = getch();
|
|
|
|
|
|
verifySpace();
|
|
|
-
|
|
|
+
|
|
|
read_mem(desttype, address, length);
|
|
|
}
|
|
|
|
|
@@ -673,7 +725,7 @@ uint8_t getch(void) {
|
|
|
*/
|
|
|
watchdogReset();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
ch = UART_UDR;
|
|
|
#endif
|
|
|
|
|
@@ -756,17 +808,13 @@ void appStart(uint8_t rstFlags) {
|
|
|
__asm__ __volatile__ ("mov r2, %0\n" :: "r" (rstFlags));
|
|
|
|
|
|
watchdogConfig(WATCHDOG_OFF);
|
|
|
+
|
|
|
+
|
|
|
__asm__ __volatile__ (
|
|
|
-#ifdef VIRTUAL_BOOT_PARTITION
|
|
|
-
|
|
|
- "ldi r30,4\n"
|
|
|
+
|
|
|
+ "ldi r30,%[rstvec]\n"
|
|
|
"clr r31\n"
|
|
|
-#else
|
|
|
-
|
|
|
- "clr r30\n"
|
|
|
- "clr r31\n"
|
|
|
-#endif
|
|
|
- "ijmp\n"
|
|
|
+ "ijmp\n"::[rstvec] "M"(appstart_vec)
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -854,10 +902,10 @@ static inline void read_mem(uint8_t memtype, uint16_t address, pagelen_t length)
|
|
|
do {
|
|
|
#ifdef VIRTUAL_BOOT_PARTITION
|
|
|
|
|
|
- if (address == 0) ch=rstVect & 0xff;
|
|
|
- else if (address == 1) ch=rstVect >> 8;
|
|
|
- else if (address == 8) ch=wdtVect & 0xff;
|
|
|
- else if (address == 9) ch=wdtVect >> 8;
|
|
|
+ if (address == rstVect0) ch = rstVect0_sav;
|
|
|
+ else if (address == rstVect1) ch = rstVect1_sav;
|
|
|
+ else if (address == wdtVect0) ch = wdtVect0_sav;
|
|
|
+ else if (address == wdtVect1) ch = wdtVect1_sav;
|
|
|
else ch = pgm_read_byte_near(address);
|
|
|
address++;
|
|
|
#elif defined(RAMPZ)
|