add new feature: "BOOTUP_CLEARRAM"
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Sun, 31 Mar 2013 14:11:35 +0000 (16:11 +0200)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Sun, 31 Mar 2013 23:04:37 +0000 (23:04 +0000)
Under normal circumstances, RESET will not clear contents of RAM.
As always, if you want it done - do it yourself...

Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
firmware/bootloaderconfig.h
firmware/main.c

index af67d6e..65b9cdb 100644 (file)
@@ -288,6 +288,16 @@ these macros are defined, the boot loader usees them.
  * Nevertheless this feature saves lots of memory.
  */
 
+#ifdef CONFIG_USE__BOOTUP_CLEARRAM
+#      define USE_BOOTUP_CLEARRAM              1
+#else
+#      define USE_BOOTUP_CLEARRAM              0
+#endif
+/* This macro enables some (init3) code, executed at bootup.
+ * This codefragment will safely overwrite the whole SRAM with "0"
+ * (except registers and IO), since RESET will NOT clear old RAM content.
+ */
+
 //#define SIGNATURE_BYTES             0x1e, 0x93, 0x07, 0     /* ATMega8 */
 /* This macro defines the signature bytes returned by the emulated USBasp to
  * the programmer software. They should match the actual device at least in
index 7ce88db..91127ef 100644 (file)
@@ -178,6 +178,32 @@ static const uchar  signatureBytes[4] = {
 
 /* ------------------------------------------------------------------------ */
 
+#if (USE_BOOTUP_CLEARRAM)
+/*
+* Under normal circumstances, RESET will not clear contents of RAM.
+* As always, if you want it done - do it yourself...
+*/
+void __attribute__ ((naked)) __attribute__ ((section (".init3"))) __clearram(void);
+void __clearram(void) {
+  extern size_t __bss_end;
+  asm volatile (
+    "__clearram:\n\t"
+    "ldi r29, %[ramendhi]\n\t"
+    "ldi r28, %[ramendlo]\n\t"
+    "__clearramloop%=:\n\t"
+    "st -Y , __zero_reg__\n\t"
+    "cp r28, %A[bssend]\n\t"
+    "cpc r29, %B[bssend]\n\t"
+    "brne __clearramloop%=\n\t"
+    :
+    : [ramendhi] "M" (((RAMEND+1)>>8) & 0xff),
+      [ramendlo] "M" (((RAMEND+1)>>0) & 0xff),
+      [bssend] "r" (&__bss_end)
+    : "memory"
+      );
+}
+#endif
+
 #if (!USE_EXCESSIVE_ASSEMBLER) || (!(defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) || defined (__AVR_ATmega8HVA__)))
 static void (*nullVector)(void) __attribute__((__noreturn__));
 #endif