Have you done a Tools > Burn Bootloader on your Mega 2560 so you're certain the fuses are actually set to the values in boards.txt?
When I run the sketch I get this:
Low: 0xFF
High: 0xD8
Ext: 0xFD
Lock: 0xCF
So you'll note that the lock bits still don't match but if you check what the difference is:
boards.txt:
sketch output:
you can see the only difference is the unused bit 6 and 7.
There is some weirdness in how these unused fuse bits are handled. The AVRDUDE tool used by the Arduino IDE to set the fuses used to handle them one way, then changed in v6.3 to handling them the other way because supposedly that is more correct. This caused a lot of breakage so Arduino modified their version of AVRDUDE to still be compatible with the old fuse values. So I believe this causes AVRDUDE to actually write 0xCF even though the board definition says 0x0F.
from beginning
I want to lock my application section. For this, I change boards.txt (mega main section) lockbits to 0x0C. Then upload a blink sketch using programmer "arduino as isp" upload ends ok.
Disconnent programmer, connect target mega to usb and try to "simple" upload a sketch. The procedure stops with "connection timeout" (from this i "understood" it is not possible to program, so conclude lockbits ok). (after that I found the function that reads lockbits and tried it and see that there is something wrong)
restore value in boards.txt, Reconnect programmer, burn bootloader go back and verify that now target can get sketch through "upload"
Qs:
is 0x0C correct in order to get "further programming and verification disabled"?
Is procedure correct (change boards.txt, upload using pogrammer (arduino as isp))?
demkat1:
Is procedure correct (change boards.txt, upload using pogrammer (arduino as isp))?
No, the procedure is not correct. Only Tools > Burn Bootloader sets the fuses. Upload Using Programmer does not set fuses.
You also need to restart the Arduino IDE after changing boards.txt.
You also need to be sure you are editing the right boards.txt. You may have multiple copies on your computer. Turn on File > Preferences > Show verbose output during: > upload and check the output of the Burn Bootloader command to be sure the correct fuse settings were used.
demkat1:
Then upload a blink sketch using programmer "arduino as isp" upload ends ok.
Disconnent programmer, connect target mega to usb and try to "simple" upload a sketch. The procedure stops with "connection timeout" (from this i "understood" it is not possible to program, so conclude lockbits ok)
The conclusion is not correct. "Upload using programmer" deletes the bootloader. So any subsequent attempt with a USB connection will fail, regardless of the fuse settings
use 1.8.1
Take a mega2560 board. Have an uno "as isp". Burn bootloader. ok, led blinks.
disconnect programmer go to ide,
upload sketch to read fuse and lockbits (see above). ok it works. it gives me E=FD, H=D8, L=FF, lock=CF, as it is on boards.txt (CF=0F unused bits 6,7).
use 1.8.1
Take a mega2560 board. Have an uno "as isp". Burn bootloader. ok, led blinks.
disconnect programmer go to ide,
upload sketch to read fuse and lockbits (see above). ok it works. it gives me E=FD, H=D8, L=FF, lock=CF, as it is on boards.txt (CF=0F unused bits 6,7).
0C should mean serial and parallel programming are disabled (but erase will still work, and erases the lock bits as well.) (0bxxxxxx00) and application section access to the bootloader area is disabled (0bxx00xxxx).
But the bootloader can still access the application section (0bxxxx11xx), which is what you’re seeing, right?
The docs are laid out rather horribly!
(Bootloader programingm isn’t either serial programming or parallel programming as they are using the terms. It’s the bootloader deciding to do self programming. It’s actually a pretty useful state to be in, if you bootloader control secure access to some important stuff...)
westfw:
0C should mean serial and parallel programming are disabled (but erase will still work, and erases the lock bits as well.) (0bxxxxxx00) and application section access to the bootloader area is disabled (0bxx00xxxx).
But the bootloader can still access the application section (0bxxxx11xx), which is what you’re seeing, right?
So, you mean instead of 0C, use 00?
(I can try it on monday, but since it is "scrubing me", pls be so kind and answer with a Y or N
thank you
To "lock" an arduino, I'd leave the bootloader unprogrammed, and set the Lock bits to 0 (the contents of the boot lock bits would be irrelevant at that point.)
The sequence would look like (using a programmer connected to the ISP port):
"Burn Bootloader" - to set fuses appropriately for the "board."
"Upload using programmer" (erases bootloader, uploads sketch, leaves fuses.) (Hmm. There's some chance that newer IDEs will upload the "sketch and the bootloader combined" image. Keep an eye on it...)