I used the ArduinoISP sketch and uploaded into an Uno and ICSP-connected a Diecimila with ATMega168 and burnt the bootloader it thru the ArduinoIDE v1.8.5. Verifying using the ATMega_Board_Detector sketch tells me the 168 now contains the ATMegaboot_168_diecimila bootloader, which is 2048 bytes in size and starts at 0x3800, with a signature of 1E 94 06 (which matches the Atmel official documentation). After removing the Uno and connecting the Diecimila directly to the computer, setting Board and Processor in the IDE, I can now upload a sketch to the Diecimila. No problem.
However, I want to load the smaller Optiboot into the Diecimila. After uploading the ATMega_Board_Programmer sketch (v1.38) into the Uno, the signature of the Diecimila chip is listed as 1E 94 0B (mismatch with Atmel docu) and bootloading fails. I changed the Board_Programmer sketch and changed 0B to 06. This time, the Optiboot loader is loaded successfully: 512 bytes in size and starting at address 0x3E00. This is verified and confirmed using the Board_Detector sketch. However, I now can no longer upload sketches into the Diecimila/168/Optiboot. Error is "stk500() programmer not responding". Because the starting address 0x3E00 doesn't match, I also changed the Board_Programmer sketch and changed start address from 0x3E00 to 0x3800 and try again. Still no luck. Same error message.
I am very sure the selections in the Arduino IDE for board / processor / port are correct.
As a test, I put an ATMega328 on the Diecimila board, and programmed it with both methods. The signature now is the same (1E 95 0F) but the starting address and size for ATMegaboot_168_ATMega328 are 0x7800 and 2048 bytes versus 0x7E00 for the 512 bytes of Optiboot_ATMega328. When trying to load a sketch, only the ArduinoISP -loaded bootloaders allow loading of sketches.
Is it not possible to replace the bootloader? Is there something else I need to change in the Arduino IDE config?
If you changed the bootloader then you have to change the boot vector with extended fuse according the datasheet.
It is BOOTSZ1:0 and should be 1,0 for 168P for 512B (256 words) boot region. Did you change it?
I am very sure the selections in the Arduino IDE for board / processor / port are correct.
What board have you selected for "ATmega168P running optiboot"? Which "Board Package"?
signature of 1E 94 06 (which matches the Atmel official documentation)
the signature of the Diecimila chip is listed as 1E 94 0B (mismatch with Atmel docu)
"... 06" is an ATmega168 or ATmega168A
"... 0B" is an ATmega168P or ATmega168PA
(There are generally two possible solutions for the P vs not-P problem. Either you use a bootloader that lies about the chip type, and compile using the normal IDE settings (328P, 168 non-P) (I believe that this is what the "board programmer" does), or you get a core that actually supports both chips (ie "MiniCore".) But you can't mix them - if you load the non-P bootloader, you have to go with a non-P core, even if it's a -P chip.)
What I was actually doing wrong is ... after successfully uploading the bootloader into the 168 (as evidenced by the familiar 2 blips per second) ... I tried to load the next sketch by setting the board back to "Arduino Diecimila" and "Processor" to 168 using the original menu options from before installing the miniCore ... ... I guess that is what happens when you don't really understand the magic that is happening underneath it all.
After changing back to the miniCore selections used for programming, I can now upload whichever sketch I have.
Thank you both for your help.
PS: I'm trying to fully grasp the consequences of using the miniCore (apart from the smaller bootloader size obviously) ... reading through MCUdude's github ... does that mean that certain functions in the "standard" Arduino libraries are replaced with different/improved versions? ... and that some of the Arduino Reference material regarding their functions/arguments/execution time/etc is not accurate and their behavior might be different? ... or are the changes limited to the additional functions as described in the github? ... any website or link or reference material you can recommend for me to delve into this a little deeper?