Arduino Forum

Using Arduino => Avrdude, stk500, Bootloader issues => Topic started by: BoraY on May 21, 2019, 06:25 pm

Title: Does avrdude write the bootloader everytime a sketch is uploaded?
Post by: BoraY on May 21, 2019, 06:25 pm
Hello all,

I am new, and self thought. So, I may use some terminology wrong, please bear with me...

I know that the bootloader starts first with every reset and power on and checks if something is waiting to be uploaded, if not, it exits and whatever code exists in the MCU starts running.

But, what I don't know is, what happens when there is a code waiting to be uploaded. Is avrdude smart enough to start writing the code from the address point right after where the bootloader ends, or every upload just simply starts from address 0 and every time the bootloader is re-written before the actual code? In other words, does the HEX file created by the Arduino IDE also contain the bootloader in the beginning of it, so that writing can start at address 0?

The reason I am asking this is, recently I have "discovered" that avrdude can be used from command line and with a "/parameters" it can be used to upload a HEX code file from an external source, thus eliminating the need for another avr programming software. I have a HEX file which I need to write to an ATmega32U4 (promicro). I want to try this with avrdude, and I am guessing that the HEX I have does not contain the Arduino bootlader since it was not written using Arduino IDE. It is not something pirated I promise. The owner of this code chose not to share his source code and he only distributes it freely as a HEX file. Will avrdude skip the already existing bootloader and start writing after the bootloader or will it just write over the bootloader?   

Thank you!
Title: Re: Does avrdude write the bootloader everytime a sketch is uploaded?
Post by: Juraj on May 21, 2019, 07:00 pm
the bootloader in ATmegas is at the end of the flash memory, not at address 0
Title: Re: Does avrdude write the bootloader everytime a sketch is uploaded?
Post by: sterretje on May 22, 2019, 05:39 am
The IDE generates two hex files, one with the boot loader and one without.

For standard uploads via USB, the IDE tells avrdude to use the latter.
Title: Re: Does avrdude write the bootloader everytime a sketch is uploaded?
Post by: DrAzzy on May 23, 2019, 05:17 pm
Bootloader is only written when you do burn bootloader eith an isp programmer.

Uploading via the bootloader cannot erase the bootloader.

Uploading something via isp will always erase the bootloader (use a board definition without the bootloader if doing this, and do burn bootloader once with that board def selected to set fuses to not use bootloader (fuses are also set only when doing burn bootloader)
Title: Re: Does avrdude write the bootloader everytime a sketch is uploaded?
Post by: Coding Badly on May 24, 2019, 07:43 am
Hello,

Is avrdude smart enough to start writing the code from the address point right after where the bootloader ends, or every upload just simply starts from address 0 and every time the bootloader is re-written before the actual code?
Neither.  The HEX file contains the load addresses.  Normally an application upload starts at address zero (the bootloader is at the other end of Flash).  But nothing prevents an upload into the middle of Flash.  There are fuses that protect the bootloader from being overwritten.

Will avrdude skip the already existing bootloader and start writing after the bootloader or will it just write over the bootloader?   
If you are using ISP (in-system programming; requires a "programmer") then the bootloader will be erased.

If you are using a bootloader (you are) to upload then the bootloader will survive.

Finally, you can determine the load address of the image by inspecting the HEX file with a plain old text editor.