Flash Write protection to prevent access to firmware
In devices such as the ARV family from Microchip (formerly Atmel) there are Lock Bits that determine how much access to the boot area is available to users.  To change the Lock Bits, a chip erase command must be issued first. If one has the chip and a Programmer, one can erase/flash the region - but any code that was on the chip will be lost.  

Malicious user code can not rewrite the flash if the lock bits are programmed to not allow that.  In the Atmega328P for example, there are 3 pairs of lock bits that protect:  

programming of the Flash and EEPROM, 

Store Program Memory (SPM) or Load Program Memory (LPM) instruction accessing the application section, 

and SPM or LPM accessing the boot loader section.