Hi Vidar,

(btw., better subscribe to the list to see all replies, in case
someone replies to the list only)

> 1) I am not able to make avr-gdb load programfile correctly, I only get 
> packet erros, but those are ignoerd and

Ah, yes, I know...

> 2) It takes an enormous time to load, 15 minutes, and it fails in the end

That's because eventually all the programming attempts ended in timeouts.

> Am I doing something wrong?

Nope, that's always been the case.  When I started with the JTAG ICE
mkII porting work, I simply had bigger fish to fry first, as AVRDUDE
has already been there to program the flash, so I could concentrate in
AVaRICE onto the actual debugging work.

Later on, I got used to memory uploads not working, and never really
investigated.

Now, I dug up the code again a bit.

The basic issue, it seems is, that the JTAG ICE mkII behaves quite a
bit differently than the mkI version did (which much of this code has
been inherited from).  Unfortunately, GDB has no idea about our memory
being organized in terms of pages, so it sends us small chunks of
flash ROM bytes to program.  Apparently, the mkI could handle that,
so updating the flash ROM "chunkwise" did work there.

For the mkII, this never really worked.  I tried to resort to the
memory type called "MTYPE_SPM", in the hope it would do the trick, but
it didn't, so I eventually gave up on it.

I tried some quick hacks now, in an attempt to emulate the "chunkwise"
update through sending full pages where only the relevant part of
that page has been filled in (leaving the remainder at 0xFF, i.e. at
"no change"), yet it still writes garbage to some locations.  I'm
appending you that diff, in case you want to play around with it.
Perhaps you can see my mistake?

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)
Index: src/jtag2rw.cc
===================================================================
RCS file: /home/cvs/avarice/avarice/src/jtag2rw.cc,v
retrieving revision 1.5
diff -u -u -r1.5 jtag2rw.cc
--- src/jtag2rw.cc      8 Aug 2006 21:27:34 -0000       1.5
+++ src/jtag2rw.cc      9 Dec 2010 16:30:00 -0000
@@ -217,13 +217,18 @@
        numBytes > 4)
     {
        debugOut("Detected GDB \"load\" command, erasing flash.\n");
-       //whichSpace = MTYPE_FLASH_PAGE; // this will turn on progmode
        eraseProgramMemory();
     }
+    if (whichSpace == MTYPE_SPM)
+    {
+       whichSpace = MTYPE_FLASH_PAGE; // this will turn on progmode
+    }
 
     bool needProgmode = whichSpace >= MTYPE_FLASH_PAGE;
     unsigned int pageSize = 0;
     bool wasProgmode = programmingEnabled;
+    unsigned long baseAddr = addr;
+    unsigned long offset = 0;
     if (needProgmode && !programmingEnabled)
        enableProgramming();
 
@@ -239,26 +244,27 @@
     }
     if (pageSize > 0) {
        unsigned int mask = pageSize - 1;
-       addr &= ~mask;
-       check(numBytes == pageSize,
-             "jtagWrite(): numByte does not match page size");
+       baseAddr &= ~mask;
+        offset = addr & mask;
     }
-    uchar *command = new uchar [10 + numBytes];
+    size_t bufSize = 10 + (pageSize > 0? pageSize: numBytes);
+    uchar *command = new uchar [bufSize];
+    memset(command, 0xff, bufSize);
     command[0] = CMND_WRITE_MEMORY;
     command[1] = whichSpace;
     if (pageSize) {
        u32_to_b4(command + 2, pageSize);
-       u32_to_b4(command + 6, addr);
+       u32_to_b4(command + 6, baseAddr);
     } else {
        u32_to_b4(command + 2, numBytes);
-       u32_to_b4(command + 6, addr);
+       u32_to_b4(command + 6, baseAddr);
     }
-    memcpy(command + 10, buffer, numBytes);
+    memcpy(command + 10 + offset, buffer, numBytes);
 
     uchar *response;
     int responseSize;
 
-    check(doJtagCommand(command, 10 + numBytes, response, responseSize),
+    check(doJtagCommand(command, bufSize, response, responseSize),
          "Failed to write target memory space");
     delete [] command;
     delete [] response;
------------------------------------------------------------------------------
_______________________________________________
avarice-user mailing list
avarice-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avarice-user

Reply via email to