Ariadne bootloader burn problem on Mega (Uno used as ISP)

I burned Ariadne bootloader onto my Mega 2560. After that I have some issues, so I wonder if I'm doing it correctly.
(details below, but in a nutshell I have problem loading a sketch via TFTP or via Codebender.cc).

Burner is an Arduino Uno. Using the Arduino IDE (v1.0.5) with the UNOs COM port, UNO board type (i.e. not "Mega" or "Mega with Ariadne" which is the burn target, correct?) and the "Arduino as ISP" setting.

With the following connections:
Arduino Uno Target Mega2560
D10 (SS) Reset
D11 (MOSI) D51
D12 (MISO) D50
D13 (SCK) D52
Gnd Gnd
+5V +5V

as per these instructions (i.e. no capacitor used on Megas reset pin):

I'm creating the hex file with the Lua script from Nick Gammon, from the above site (using MushClient on Vista)

ariadne_atmega2560.hex (size 10 872) from

is used.

The hex output from Lua script ends with a lot of "0XFF" (when the above hex file is used).

Output is pasted in to the "bootloader_atmega2560_v2.h" file, instead of the original hex content (correct? Seemed like the easiest way).

Uploading (of "atmega_board_programmer" sketch, without any shields attached) it to the UNO gives:
avrdude: verification error, first mismatch at byte 0x1380
0xff != 0xe0
but if I remove all the ending "0XFF" then the sketch uploads fine:
Binary sketch size: 16 854 bytes (of a 32 256 byte maximum)

Serial monitor to 115200 looks OK:
Atmega chip programmer.
Written by Nick Gammon.
Version 1.21
Compiled on Jan 6 2014 at 16:51:34
Entered programming mode OK.
Signature = 0x1E 0x98 0x01
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF
HFuse = 0xD8
EFuse = 0xFD
Lock byte = 0xEF
Clock calibration = 0x9A
Bootloader address = 0x3E000
Bootloader length = 3843 bytes.
Type 'V' to verify, or 'G' to program the chip with the bootloader ...

Burn is also OK:
...
No errors found.
...
Done.

Via Linux I can successfully transfer a converted bin file (converted with avr-objcopy -I ihex xxx.cpp.hex -O binary xxx.cpp.bin and uploaded as per GitHub - codebndr/Ariadne-Bootloader: A little less unfinished TFTP bootloader for Arduino Ethernet or Arduino with Ethernet Shield info (e.g. get "received ACK <block=41>"). I do however need to press the Arduino reset button in order to be able to upload the bin file.

But, the sketch does not work if transferred via TFTP.

Codebender can't upload a sketch either (coderbender.cc, I've forwarded port 69 to the default TFTP 192.168.1.128 address). The Codebender transfer never finishes in the GUI.

Serial transfer via the Arduino IDE is still OK, i.e. the sketch works after it's transferred that way.

Is the 'process' I'm using correct?

Thanks in advance!! (sorry for the long post!)

Sounds OK. The trailing 0xFF in the sketch does indeed cause problems uploading the burning sketch, and you can safely delete all trailing 0xFF (stop at the last non 0xFF). This is a problem in the bootloader for the Uno where it assumes that 0xFF is there after a chip erase.

But, the sketch does not work if transferred via TFTP.

Codebender can't upload a sketch either (coderbender.cc, I've forwarded port 69 to the default TFTP 192.168.1.128 address). The Codebender transfer never finishes in the GUI.

I'm not sure what this part refers to. Is this bootloader one that uses TFTP? I haven't used that bootloader. However if it (the bootloader) uploads and verifies OK then you must have other issues, eg. the clock speed of the Mega chip.

OK, thanks!!
Yes exactly, this is the bootloader that enables flashing remotely via TFTP (sorry, should have written that).

Then I'll check for other sources that could be the cause. Will e.g. try with some other boards now when I know how to do.

How do I check that the clock speed is correct?

You appear to be using an external crystal, is that correct? What frequency is it? (Or perhaps from your post it is in fact a Arduino Mega board, so it should be running at 16 MHz).

But, the sketch does not work if transferred via TFTP.

Can you elaborate a bit more? From the page you linked you should be able to connect via tftp. If you attempt to do so, what happens? Can you post output?

And to clarify a bit, you have the Mega2560 board with the Ethernet shield? Which shield exactly? This shield works when used for other purposes, is that right?

Are you using the default IP address of 192.168.1.250?

I re-did everything again and now I got it working when flashing via Linux (RPi in this case)!
I.e. I can flash a sketch via Ethernet using TFTP and the sketch is working fine.

I do however still have to reset the board manually to be able to upload a sketch, which some sources say that you don't need to do any longer (which then removes some of the advantages with this bootloader. I will see if I can get some clarification on how it should work).

More testing to be done soon to get more info (like why it's OK now), but to answer your questions:

  • Yes,it's an Arduino Mega which is being programmed
  • The Ethernet shield is an Wiznet W5100 and it has been OK previously
  • The printout while uploading a sketch is as above, i.e. e.g. "received ACK <block=41>", longer example below
  • The IP address used with TFTP is the default one for Ariadne, 192.168.1.128/24. For the Ethernet shield any address (same subnet) works fine, e.g. 192.168.1.145/24
  • The problem earlier was that I could flash via TFTP, but then the sketch was not working. E.g. if I now load a sketch with a web server measuring the temperature via 1-wire it works fine to read out the value. Earlier it was NOK (after flashing via TFTP) to even reach the web server, unless I flashed it again via serial connection instead

Flashing from Windows is still NOK, but that must be something with the client since it's OK from Linux/Raspberry Pi (using same nw, no fw in between).

(I still don't get flashing from codebender.cc working, even with port forwarding setup, but I'll take that with them. Codebender is an open source online Arduino editor and compiler supporting flashing via TFTP. The codebender people have done some of the Ariadne bootloader coding).

Thanks again for your help!

Example printout when flashing via TFTP (reset button pressed and then the first ACK is received):
tftp> put xx10.bin
sent WRQ <file=xx10.bin, mode=octet>
sent WRQ <file=xx10.bin, mode=octet>
sent WRQ <file=xx10.bin, mode=octet>
received ACK <block=0>
sent DATA <block=1, 512 bytes>
received ACK <block=1>
sent DATA <block=2, 512 bytes>
received ACK <block=2>
...
sent DATA <block=43, 512 bytes>
received ACK <block=43>
sent DATA <block=44, 32 bytes>
received ACK <block=44>
Sent 22048 bytes in 46.2 seconds
tftp>

I do however still have to reset the board manually to be able to upload a sketch, which some sources say that you don't need to do any longer ...

I don't totally see how you can run the bootloader without resetting, although you could play with the fuses. Some fuse settings (lock bits really) don't allow you to execute bootloader code from within the non-bootloader section.

OK, it's solved now. I had to include the reset lib so I don't need to reset manually, but can do it from remote.

The trailing 0xFF in the sketch does indeed cause problems uploading the burning sketch, and you can safely delete all trailing 0xFF (stop at the last non 0xFF). This is a problem in the bootloader for the Uno where it assumes that 0xFF is there after a chip erase.

What does this refer to? Do you need to do something special for burning an Uno, with regards to the trailing 0xFF?

If I burn Ariadne bootloader on an Uno, either removing all the trailing 0xFF or leaving ~120 of them in, the burn is successful (if I leave all 0xFF in then I can't upload the sketch).

However, after the succesful bootloader burning I cannot upload a sketch, like blink, to the programmed Uno without getting:
Binary sketch size: 1 084 bytes (of a 28 672 byte maximum)
avrdude: verification error, first mismatch at byte 0x0000
0x0c != 0x1c
avrdude: verification error; content mismatch

I have only updated the hex in the bootloader_atmega328.h file. Tried burning from both a Mega and from another Uno (using the cabling described on your site), but with the same NOK result.

You have two issues here. Uploading any sketch with a lot of trailing 0xFF (using the bootloader) may fail, but you have worked around that. Thus we presume that the bootloader is now on the target chip.

If you are having trouble using this bootloader then there is an issue with that. Is this still the TFTP thing? Failing at byte 0x0000 is hardly the trailing 0xFF problem.

Can you describe the process a bit more? Are you uploading, via avrdude (through the IDE?) a sketch via TFTP? How does this work exactly?

Thanks for the prompt reply!

The Ariadne bootloader runs fine on a Mega, now I try to get it working on an Uno, hence I wondered about your comment regarding that the Uno assumes that 0xFF is present after a chip erase.

I would say it's not a TFTP issue, since it fails prior to that.

Process:
I'm using the Lua script on your page to convert the bootloader hex file. Pasting the result in to the bootloader_atmega328.h file, of the Atmega_Board_Programmer sketch.

Transfering the Atmega_Board_Programmer sketch to the Arduino used to burn the Uno (I've tried using both a Mega with Ariadne bootloader and another Uno with standard bootloader as the programmer).
Note that my Uno's are R2, not R3.

Connecting (different depending if Mega or Uno is used as programmer) as per your page.
Burn, which is reported as sucessful.

But, if I then disconnect the programmer Arduino from the target Uno and try to upload e.g. a blink sketch (via the normal IDE, using serial conn.) I get the "mismatch at byte..." result.

If it had worked, I would have changed the TFTP EEPROM address from it's default value of 192.168.1.128/24 to whatever I wanted to use for my Ethernet shield, i.e. so the two are the same (a sketch exits to read the EEPROM values (btw, also gives the above fault code when I try to upload it) and another to set it. These sketches are the ones I can successfully use with the Mega which successfully runs the Ariadne bootloader now).

If I would have gotten this far, I would have transfered a sketch (which would use the reset server lib to be able to reset from remote etc) via TFTP.

I.e. after burning the bootloader I can't succesfully transfer any sketch using the IDE and a serial conn (like the Blink sketch or the AnalogReadSerial sketch). For the Mega that succesfully run Ariadne now, it works fine to transfer via serial as well.

This makes me believe there is either:

  • Something wrong with the ariadne_atmega328.hex bootloader file (same result with the ariadne_atmega328_ethernet.hex file btw) or
  • I need to change something more than just the hex in the Atmega_Board_Programmer sketch or
  • I need an "external" programmer instead of using an Arduino ISP to get ariadne_atmega328.hex sucessfully on the Uno R2

What do you think?

I noted that the size between Ariadne and Optiboot are: ariadne_atmega328.hex: 7664 vs optiboot_atmega328.hex: 1467, but I don't know if that affects anything in the Atmega_Board_Programmer sketch.

Thanks for your help!

But, if I then disconnect the programmer Arduino from the target Uno and try to upload e.g. a blink sketch (via the normal IDE, using serial conn.) I get the "mismatch at byte..." result.

I'm not understanding this part. The TFTP bootloader won't work with serial comms, will it? Or does it? I don't know enough about that bootloader to say.

I've never seen the Ariadne bootloader, but I do know that if you change to a larger bootloader (e.g. optiboot to ariadne), you must first set the fuses so that you reserve enough upper flash memory for the new (and larger) bootloader, and then recompile the bootloader so that it loads at whatever the new starting address is for the reserved space. Otherwise the chip will not know what address to "jump to" after it comes off of reset and wants to execute the bootloader. I'm not sure how to do that with the Arduino IDE (I use Code::Blocks) but I am sure Nick can coach you through the process.

Well that's true, and my bootloader-uploader has that coded into it, eg.

// see Atmega328 datasheet page 298
signatureType signatures [] = 
  {
//     signature          description   flash size  bootloader size
...
  
  { { 0x1E, 0x95, 0x0F }, "ATmega328P",  32 * kb,       512, 
        atmega328_optiboot,   // loader image
        0x7E00,               // start address
        sizeof atmega328_optiboot, 
        128,          // page size (for committing)
        0xFF,         // fuse low byte: external clock, max start-up time
        0xDE,         // fuse high byte: SPI enable, boot into bootloader, 512 byte bootloader
        0x05,         // fuse extended byte: brown-out detection at 2.7V
        0x2F },       // lock bits: SPM is not allowed to write to the Boot Loader section.

You would need to get the the bootloader size right (in this case it is 512), the start address, and the fuses. See this for calculating fuses:

http://www.engbedded.com/fusecalc

Hmmm... I looked at the Ariadne hex file for the '328p on the Github site posted above, and it starts at address 0x7000 and ends at 0x7a70, giving 0xa70 or 2672 bytes in size. By comparison, optiboot for the '328p starts at 0x7e00 and ends right at 0x7fff, yielding 0x1ff or 511 bytes. So it looks like the ariadne bootloader is larger, and by necessity starts at a lower address. Since 2672 > 2048, he would probably have to allocate 4K for the bootloader, which would set the starting point to 0x7000 (an aside, the data sheet I have for the '328p seems to have incorrect addresses). Or am I missing something here? BTW, I did not realize that Github provided precompiled binaries, and I thought he was trying to stuff the '2560 loader into the '328p. My bad =(.

Thanks microcat and Nick!

Unfortunately I don't know enough about this to be sure I understand everything I need to change.

But, in the boards.txt for the Ariadne bootloader there is all this info (the Uno part of this file), with e.g. high fuses and lock bits info:
ariadne328U.upload.protocol=arduino
ariadne328U.upload.maximum_size=28672
ariadne328U.upload.speed=115200

ariadne328U.bootloader.low_fuses=0xFF
ariadne328U.bootloader.high_fuses=0xD8
ariadne328U.bootloader.extended_fuses=0x05
ariadne328U.bootloader.path=ariadne
ariadne328U.bootloader.file=ariadne_atmega328.hex
ariadne328U.bootloader.unlock_bits=0x3F
ariadne328U.bootloader.lock_bits=0x0F

Also, in the ariadne_atmega328.lst file (in the git Master branch), there is e.g. this size info:
Idx Name Size VMA LMA File off Algn
0 .note.gnu.build-id 00000024 00000000 00000000 000000d4 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .data 0000001c 00800100 00007a7a 00000b72 2
0
CONTENTS, ALLOC, LOAD, DATA
2 .text 00000a7a 00007000 00007000 000000f8 21
CONTENTS, ALLOC, LOAD, READONLY, CODE
3 .bss 00000011 0080011c 0080011c 00000b8e 2
0
ALLOC
4 .stab 00003edc 00000000 00000000 00000b90 22
CONTENTS, READONLY, DEBUGGING
5 .stabstr 00001476 00000000 00000000 00004a6c 2
0
CONTENTS, READONLY, DEBUGGING
6 .comment 00000011 00000000 00000000 00005ee2 2**0
CONTENTS, READONLY

In the Mega master branch it's however (still for the ariadne_atmega328.lst file):
Idx Name Size VMA LMA File off Algn
0 .data 0000001c 00800100 00007a54 00000ae8 20
CONTENTS, ALLOC, LOAD, DATA
1 .text 00000a54 00007000 00007000 00000094 2
1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .bss 0000000f 0080011c 0080011c 00000b04 20
ALLOC
3 .stab 000043c8 00000000 00000000 00000b04 2
2
CONTENTS, READONLY, DEBUGGING
4 .stabstr 000015c2 00000000 00000000 00004ecc 20
CONTENTS, READONLY, DEBUGGING
5 .comment 00000011 00000000 00000000 0000648e 2
0
CONTENTS, READONLY

ariadne_atmega328.hex file exists in both branches.

https://github.com/codebendercc/Ariadne-Bootloader/tree/mega

Hi gandalf50!

I'm trying to burn the Ariadne bootloader into the mega 2560 with your method but I'm stuck at the part when you convert ariadne_atmega2560.hex into bootloader_atmega2560_v2.h format to be compatible with Gammon's sketch.

Also, I'm on Linux and have no access to a Windows machine to use the "Lua script" you are saying.
Do you have to change some other parameters like fuses?

Can you please send to me the complete modified sketch? It would be greatly appreciated.

Thanks in advance,

Ignacio

Hi Ignacio,

I've mailed you the converted hex I used. I didn't do any changes in the sketch, but I should probably have changed at least the lock bits to 0x0F (for the Mega2560). Unfortunately I don't know enough about this, so no guaranties that it's correct and doesn't brick your Arduino.

Hi,

I tried to burn 2560 bootloader from 2560 like Nick Gammon explained her http://www.gammon.com.au/forum/?id=11635,

I get this

Atmega chip programmer.
Written by Nick Gammon.
Version 1.21
Compiled on Jun  2 2014 at 12:04:44
Entered programming mode OK.
Signature = 0x1E 0x98 0x01 
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF 
HFuse = 0xD8 
EFuse = 0xFD 
Lock byte = 0xFF 
Clock calibration = 0x95 
Bootloader address = 0x3E000
Bootloader length = 7474 bytes.
Type 'V' to verify, or 'G' to program the chip with the bootloader ...

And if i press 'G'

Erasing chip ...
Writing bootloader ...
Committing page starting at 0x3E000
Committing page starting at 0x3E100
Committing page starting at 0x3E200
Committing page starting at 0x3E300
Committing page starting at 0x3E400
Committing page starting at 0x3E500
Committing page starting at 0x3E600
Committing page starting at 0x3E700
Committing page starting at 0x3E800
Committing page starting at 0x3E900
Committing page starting at 0x3EA00
Committing page starting at 0x3EB00
Committing page starting at 0x3EC00
Committing page starting at 0x3ED00
Committing page starting at 0x3EE00
Committing page starting at 0x3EF00
Committing page starting at 0x3F000
Committing page starting at 0x3F100
Committing page starting at 0x3F200
Committing page starting at 0x3F300
Committing page starting at 0x3F400
Committing page starting at 0x3F500
Committing page starting at 0x3F600
Committing page starting at 0x3F700
Committing page starting at 0x3F800
Committing page starting at 0x3F900
Committing page starting at 0x3FA00
Committing page starting at 0x3FB00
Committing page starting at 0x3FC00
Committing page starting at 0x3FD00
Written.
Verifying ...
Verification error at address 3E000. Got: 0x00  Expected: 0x0D 
Verification error at address 3E001. Got: 0x00  Expected: 0x94 
Verification error at address 3E002. Got: 0x00  Expected: 0x89 
.
.
Verification error at address 3E063. Got: 0x00  Expected: 0xF1 
Verification error at address 3E064. Got: 0x00  Expected: 0x0D 
7197 verification error(s).
First 100 shown.
Type 'C' when ready to continue with another chip ...

Why is it failed?

Tried from 2560 to duemilanove 328p-pu

Atmega chip programmer.
Written by Nick Gammon.
Version 1.21
Compiled on Jun  2 2014 at 13:20:04
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F 
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xFF 
HFuse = 0xDA 
EFuse = 0xFD 
Lock byte = 0xCF 
Clock calibration = 0xAD 
Bootloader address = 0x7E00
Bootloader length = 512 bytes.
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
Using Uno Optiboot 16 MHz loader.
Type 'V' to verify, or 'G' to program the chip with the bootloader ...
Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
Verification error at address 7E00. Got: 0x00  Expected: 0x11 
Verification error at address 7E01. Got: 0x00  Expected: 0x24 
.
.
Verification error at address 7E6A. Got: 0x00  Expected: 0xAF 
Verification error at address 7E6B. Got: 0x00  Expected: 0xD0 
496 verification error(s).
First 100 shown.
Type 'C' when ready to continue with another chip ...