Hardware flash write protection
The hardware flash write protection driver (fprotect
) can be used to protect flash areas from writing.
The driver uses a hardware peripheral (BPROT, ACL, or SPU, depending on the chip model) to protect the area.
The protection is irreversible until a reset occurs.
The following example shows how to protect PM_B0_SIZE
bytes of the flash area starting from PM_B0_ADDRESS
:
int err = fprotect_area(PM_B0_ADDRESS, PM_B0_SIZE);
API documentation
include/fprotect.h
lib/fprotect/
- group fprotect
API for write protection of flash areas using Hardware peripheral.
Functions
-
int fprotect_area(uint32_t start, size_t length)
Protect flash area against writes.
- Parameters:
start – [in] Start of range to protect.
length – [in] Length in bytes of range to protect.
- Return values:
0 – On success.
-EINVAL – If any of the argument are incorrect.
-EFAULT – If the protection was not applied properly.
-ENOSPC – If function is called too many times. Applies to devices where there is a limited number of configuration registers which are used for all address ranges.
-
int fprotect_area_no_access(uint32_t start, size_t length)
Protect flash area against reads/writes.
- Parameters:
start – [in] Start of range to protect.
length – [in] Length in bytes of range to protect.
- Return values:
0 – On success.
-EINVAL – If any of the argument are incorrect.
-EFAULT – If the protection was not applied properly.
-ENOSPC – If function is called too many times. Applies to devices where there is a limited number of configuration registers which are used for all address ranges.
-
uint32_t fprotect_is_protected(uint32_t addr)
Check whether a block has already been protected.
NB: Only supported on HW platforms with ACL (CONFIG_HAS_HW_NRF_ACL).
- Parameters:
addr – [in] The address to check. The block containing this address will be checked.
- Return values:
0 – If not protected
1 – If only write protected
2 – If only read protected
3 – If write and read protected
-
int fprotect_area(uint32_t start, size_t length)