3.4.5 How Can I Prevent Misuse of My Code?
First, many devices with flash program memory allow all or part of this memory to be write protected. The device configuration bits need to be set correctly for this to take place, so see 7.3 Configuration Bit Access, 25.4.14 Specifying Configuration Bits for CCI, and your device data sheet.
Second, you can prevent third-party code being programmed at unused locations in the program memory by filling these locations with a value rather than leaving them in their default unprogrammed state. You can chose a fill value that corresponds to an instruction or set all the bits so as the values cannot be further modified. (Consider what will happen if your program somehow reaches and starts executing from these filled values. What instruction will be executed?)
Use the --fill
command to fill unused memory. Find usage
information for this command in 5.7.10 Options for Linking.