Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Created January 9, 2020 08:26
Show Gist options
  • Save lupyuen/3ee440542853e1e637582c4efa1b240a to your computer and use it in GitHub Desktop.
Save lupyuen/3ee440542853e1e637582c4efa1b240a to your computer and use it in GitHub Desktop.

What is "flash protection"?

PineTime’s flash memory is protected by the Access Port Protection feature of the Nordic nRF52 Microcontroller

The Access Port Protection feature locks the nRF52 flash ROM from any dumping, modification and prevents debugging. Access Port Protection is enabled in production devices, so that people can’t snoop into an nRF52 gadget and tamper with the ROM.

Access Port Protection prevents us from flashing and debugging PineTime in its shipped form, so we need to remove the protection.

To remove Access Port Protection, we need to set the ERASEALL register to 1. Upon restart, the nRF52 Microcontroller will erase all contents of the flash ROM and allow flashing / debugging.

Check out the scripts for removing flash protection: flash-unprotect.sh, flash-unprotect.ocd

Turning on flash protection is more tricky... We need to load nRF52's UICR flash region from a file to set APPROTECT register to 0.

Check out the scripts for enabling flash protection: flash-protect.sh, flash-protect.ocd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment