After upload with a programmer fuses are not changed ... pb ?

Hi

After flashing a bootloader the fuses are programmed so the board starts at the bootloader address.
i.e. in case of the 328p the high fuse is 0xDA meaning the boot address is 0x3C00 (where the bootloard sits) as the
reset vector is not set.
If instead of flashing a sketch via the bootloader we flash using the "upload with a programmer" (with arduino as ISP) the sketch
is programmed but the bootloader is erased !! (that is what I can notice on my avr). However the fuses are not reprogrammed
therefore the reset will be done at the same address but as the bootloader has been erased ... oops !
Have anyone ever encountered a pb ?

Any clue ?

Yes, File:Upload Using Programmer wipes out the bootloader and the sketch starts nearly immediately after a reset.
I have not seen an issue with a sketch starting incorrectly.

well well that means the sketch is not big enough to be implemented in the boot section.

If your sketch is big enough (that could be the purpose of using the boot section space) then
you will start having problems from what I understand.

Let me explain :

if the boot reset fuse is still programmed (as the upload does not change it but erases the boot section)
then the reset vector still points to the boot loader reset (i.e 0x3C00).
Unfornutanely there is no JMP instruction at this location as it has been erased. Instead there is
0xFFFF this opcode does not correcpond to any valid opcode as per the ATMEL doc.
I dont know how the cpu behaves in that case. I suspect the cpu ignores this instruction and increments the Program Counter. Then as the memory has been wiped the cpu finds only 0xFFFF
until the PC rolls to 0x0000. At last there is a proper JMP opcode and the sketch starts !!!!!

Fine! we are lucky we dont see the problem. But now let's suppose our sketch is big enough so there
is some code at the 0x3C00 address then the cpu will execute it and the result is unexpected !!

Don't you agree ?

So when we upload a sketch erasing the boot loader it seems to me important to change
the bootreset fuse so the reset vector can point to the application reset that is to say 0x0000
avoiding futur problems.

This comes from my reading of the ATMEL doc. Please let me know if I misunderstood something.

Shasha

I don't know, I've never really looked into the specifics of it.
My biggest program to date, and it did a lot, was only 13K when compiled.
Could be that Upload Using Programmer alters the fuses as needed, and when you put the bootloader back in they are changed again.

Try Nick Gammon's fuse reader and see what you get after both methods

I did check after downloading the sketch. Fuses are not changed.
I also looked at the command issued by the IDE, this is just the download nothing regarding fuses.
On the contrary in the command issued for the bootloader I can see the fuses being programmed.

With 13Kb you are far away from the critical area. It is around 30Kb.

Well there is a work around that is to use avrdude directly and add the fuse in the command line.

thank you anyway
shasha