Flash Sections

Flash of the Relevant Devices can be split into three separate sections: BOOT, application code (APPCODE) and application data (APPDATA). This scheme allows for the protection and safe storage of several individual segments of code or data. The granularity of the division is 256 bytes.

The size of the three sections is set using the fuses Boot Section End (BOOTEND) and Application Code Section End (APPEND). BOOTEND determines the size of the BOOT. APPEND determines the size of the APPCODE. APPCODE will be placed immediately after the BOOT. The remaining pages will be part of APPDATA, placed immediately after APPCODE. If both fuses are set to zero, all pages are allocated to the BOOT. This is the normal procedure if only an application is written to Flash, with no bootloader.
Figure 1. Flash Sections

If FUSE.BOOTEND is written to 0x04 and FUSE.APPEND is written to 0x08, the first 4*256 bytes will be BOOT, the next 4*256 bytes will be APPCODE, and the remaining Flash will be APPDATA.

To protect the data in the three sections, directional write protection is implemented:

In addition to the directional write protection, two register bits can be used to increase restrictions.

By writing a 1 to the Application Code Section Write Protection (APCWP) bit, the application code section is protected from further writes. The bit can be found in the Control B (CTRLB) register of the Nonvolatile Memory Controller (NVMCTRL) peripheral. This bit is cleared on Reset.

As the BOOT section can never be written by the CPU, there is no need to protect BOOT from writes in the same manner. But by writing a 1 to the Boot Section Lock (BOOTLOCK) bit in CTRLB register of the NVMCTRL peripheral, reading and executing code from BOOT can be prevented. This bit is cleared on Reset.

Refer to the Nonvolatile Memory Controller (NVMCTRL) chapter in the Relevant Devices data sheet for more details.