I am using "Arduino as ISP" to program my project and figured out that program/verify is OK only for blank devices. That is, if I attempt to program an non-blank device it will program but then fail on verify.
I figured this out as I was constantly failing to verify a chip that was fine a minute ago and the device was never powered, other than through the "Arduino as ISP" programmer.
I went through with AVR910 app note and programmed routines used to read/set fuses and erase the chip into the same HW used for "Arduino as ISP" . I was able to read fuses, ID and erase the chip.
After I erased chip I was able to program it again no problem. I then changed one constant in the sketch and recompiled and reupload through "Arduino as ISP" and failed the verify. I went in with my "eraser sw" and after erasing the chip I programmed with "Arduino as ISP" and then the verify was OK again.
I also quickly went through the code and could not find the routine to erase the chip.
But consider that Arduino as ICSP is a work-around that generally gives proper results but may fail in some circumstances. Buy a REAL ICSP if perfection is a requirement.
So question is why is erase part being omitted, that is the topic. Or maybe it is not omitted, just I can't seem to find it?
I can read ID with both SW, this is also off the table.
As far as perfection goes buying a REAL ICSP would be the option if demanding an erase from an "Arduino as ISP" is considered too much. But then I would also be tempted to replace Arduino too.
The toolchain was chosen because of price, but if "Arduino as ISP" really can not be used as an programmer for already programmed chips, than it is time to find something else.
Try unsetting BOOTRST. I'm guessing that the bootloader area is maybe excluded from part of the check/erase somehow and your sketch is breaking into it. The bootloader area is 2k for that chip.
Oops. I've just seen that the fuse structure for an ATmega168 is completely different to ATMega328P which I initially assumed you were using. That picture I sent was not relevant.
The BOOTRST setting is in the EXT fuse on the 168. Is that where you changed it ?
AFAIK, this works fine on all common chips. I suppose that if you have some less common chip that somehow needs the 'R' chip-erase command instead, it might fail.
Please tell us exactly what avrdude command you are using, and include the output when you invoke it with "-vvvv" for verbose debugging.