Optiloader writes fuse bytes to be zero, that doesn't look right?

I've been browsing Westfw's optiloader file WestfW-OptiLoader-f41e3fd.zip

The part that puzzles me is the treatment of the fuse bytes.

According to the source:

image_t PROGMEM image_328p = {
  {
    "optiboot_atmega328.hex"    }
  ,
  {
    "atmega328P"    }
  ,
  0x950F,				/* Signature bytes for 328P */
  {
    0x3F,0xFF,0xDE,0x05,0    }  /* fuses to set during programming */
  ,
  {
    0x2F,0,0,0,0    }  /* fuses to set after programming */

I added a couple of comments.

Now as I read that:

#define FUSE_PROT 0			/* memory protection */
#define FUSE_LOW 1			/* Low fuse */
#define FUSE_HIGH 2			/* High fuse */
#define FUSE_EXT 3			/* Extended fuse */

After programming (and this code appears to be executed) it sets the low, high, and extended fuses to be 0. But that just doesn't look right, looking at the fuse meanings. For example that turns on "reset disable" and "debug wire". It also sets the bootloader size to 2048 words.

So I'm clearly missing something here, but what?

The code fetches the value to be programmed and only programs it if the value is non-zero.

See target_progfuses() and target_normfuses().

johnwasser:
The code fetches the value to be programmed and only programs it if the value is non-zero.

See target_progfuses() and target_normfuses().

Ach! I missed this:

if (f) {
...

Thanks!

To tell the truth, I missed it too when I read target_progfuses() and the first time through target_normfuses(). Then I noticed it on second reading and went back to target_progfuses() and found the same thing there! I hate when the code changes between readings. :frowning:

It's so nice to have other people explain my questionable code :slight_smile: