I tried self programming on the AVR128DA48. I have set BOOTSIZE=4, my program fits into the BOOT section (<2KB). The following code works:
while(NVMCTRL.STATUS & (NVMCTRL_FBUSY_bm|NVMCTRL_EEBUSY_bm)); NVMCTRL.CTRLB=NVMCTRL_FLMAP_SECTION3_gc; _PROTECTED_WRITE_SPM(NVMCTRL.CTRLA,NVMCTRL_CMD_FLWR_gc); p=(unsigned char *) 0x8400; *p=0xab; NVMCTRL.CTRLA=NVMCTRL_CMD_NOOP_gc;
The page from section 3 is programmed as expected (Address 0x18400 in code space).
When I set p to some value below 0x8400 (0x8000 or 0x8200), programming fails and NVMCTRL.STATUS returns a WRITEPROTECT error.
I have no idea why this happens because the address that should be programmed is outside the boot section.