avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avrdude-dev] [RFC] stk500: skip empty pages


From: E. Weddington
Subject: [avrdude-dev] [RFC] stk500: skip empty pages
Date: Tue, 16 Sep 2003 10:39:32 -0600

Hello all,

Attached is a patch for the stk500, which skips empty pages on a paged 
write. This is useful in a project I have, where there is an application 
and a bootloader in a mega128. So there is a chunk of code at the 
begginning addresses and small chunck of code at a very high address and a 
whole lotta nothing in between. This will significantly speed up 
programming time.

Now, this code assumes nothing about whether the chip was previously 
erased. If the chip was erased, the code behaves as expected. If the chip 
was not erased, then skipping over a page of 0xFFs does nothing more than 
trying to write 0xFFs (erased state) to an already programmed page, i.e. 
they both do nothing.

Comments?

Eric

Index: stk500.c
===================================================================
RCS file: /cvsroot/avrdude/avrdude/stk500.c,v
retrieving revision 1.37
diff -u -r1.37 stk500.c
--- stk500.c    31 Aug 2003 15:40:59 -0000      1.37
+++ stk500.c    16 Sep 2003 16:27:55 -0000
@@ -50,6 +50,9 @@
 static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value);
 static int stk500_setparm(PROGRAMMER * pgm, unsigned parm, unsigned value);
 static void stk500_print_parms1(PROGRAMMER * pgm, char * p);
+static int stk500_is_page_empty(unsigned int address, int page_size, 
+    const unsigned char *buf);
+
 
 static int stk500_send(PROGRAMMER * pgm, char * buf, size_t len)
 {
@@ -731,6 +734,10 @@
 
   for (addr = 0; addr < n; addr += page_size) {
     report_progress (addr, n_bytes, NULL);
+    if(stk500_is_page_empty(addr, page_size, m->buf))
+    {
+        continue;
+    }
     tries = 0;
   retry:
     tries++;
@@ -778,6 +785,21 @@
   return n;
 }
 
+static int stk500_is_page_empty(unsigned int address, int page_size, const 
unsigned char *buf)
+{
+    int i;
+    for(i = 0; i < page_size; i++)
+    {
+        if(buf[address + i] != 0xFF)
+        {
+            /* Page is not empty. */
+            return(0);
+        }
+    }
+    
+    /* Page is empty. */
+    return(1);
+}
 
 static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, 
                              int page_size, int n_bytes)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]