I'm not sure what part you are talking about, but S12, S08 and MCF51 operate almost identically.
- I want to protect the flash from reading and I still need to use the backdoor key to
- verify the part was correctly programmed at the factory.
Backdoor access is not required to verify flash programming at factory. MCU becomes secured and not readable over BDM only after reset. So you flash your code and verify it as many times as you wish without any problems. Just don't reset or cycle power between flashing and verify.
To enable backdoor access, you need to program KEYEN bits to 10 in NVOPT and fill NVBACKKEY bytes with your key.
To backdoor unsecure you need to execute routine in RAM, which would set KEYACC bit, write key to compare to NVBACKKEY locations, and clear KEYACC bit. This should be done from function in RAM, since flash is not readable while KEYACC is set. (NVBACKEY is also not readable while KEYACC is set.)
- When the bootloader runs does it need to enter the key to be able load the application.
No. Flash erase and write are allowed while MCU is secured. So bootloader should have no problems operating in secured MCU. Security only disables reading flash, RAM and EEPROM via BDM pin.
Backdoor unsecure is required in case you want to debug secured MCU without erasing it, or read some parameters or error logs stored in secured MCU.
- Can I include the key the application? Is this the correct approach?
This is possible. But you need some secure way to tell application it is time to unsecure. Sending unknown backdoor key over SCI may be quite secure. Applying some secred waveform to some test pin may be also quite secure.