> 1. If my bootloader is not using interrupts, do I need to redirect the vector table?
Since a bootloader is (normally) write-protected, the default vector area located in the same protected sectors will not be changeable. This means you need to redirect the vectors your app uses. This can be done in three main ways (with several variations):
a. Use hardware vector redirection, when available.
b. Use software vector redirection. Each vector in the bootloader points to code in the bootloader that loads the address from the corresponding redirected vector and jumps to it.
c. Each vector in the bootloader points to code in the bootloader that jumps to the corresponding entry of a JMP table in the app. (The difference with [b] is that each app vector now needs 3 bytes, instead of 2, but on the plus side, the interrupt latency is somewhat smaller.)
>2. What is the reason of redirecting the vector table? I understand that vector table redirection reason is in
> case a user app (not bootloader) wishes to modify interrupt vector information without unprotecting bootloader
> and reset vector space. How does user app can modify it? What does it mean?
> The only way I can think of modifying this is by flashing new firmware which is done by the bootloader.
The app vectors are modified each time you load a new app (via the bootloader). Since your app interrupt handlers normally change location from version to version, the corresponding vectors must also be updated to point to the correct entry locations for each ISR.
>3. If my bootloader size is 512 bytes, do I need to protect flash address 0xFDFF through 0xFFFF?
You need to protect the minimum for your MCU variant. For some MCUs, this is a multiple of 512 (like QE's 1024), for others, like the DZ it's multiples of 768, etc.
>4. If redirection of vector table is needed, is it enough to modify the registers NVOPT.FNORED? Will this
> automatically redirect the vector table to 0xFDFF?
For hardware redirection, yes. (I assume you have some Flash protected, though, or redirection won't happen.) The actual address of the vector table depends on how much Flash is protected.
>5. Do I need to modify NVOPT.FNORED in the common area so it takes effect on bootloader and user app?
I'm not sure what you mean by this. FNORED is fixed during installation of the bootloader. It cannot be changed later by your app.
>6. In the .PRM file do I need to define new ROM segment for my user app which starts from 0xFDFF and use >#pragma 0xFDFF in all .c files of the application?
C users will help you with that...
>7. When the mcu reset, it will invoke _EntryPoint which will init clock and other common stuff and it will then read the
> flash (in a known location) to see if to run user app or go to bootloader. Do I need two main() one for bootloader and
> one for user app which will be in 0xFDFF segment?
Unless you're dealing with specific hardware requirements, I would avoid doing any irreversible setup from within the bootloader. Some registers are write-once. For me, the best approach is to defer all such setup to the actual app. That way, if a different requirement is needed after initial deployment, it can be handled in the updated app.
So, I would prefer to use the default startup settings, which among other things it means the bootloader always uses the internal oscillator. Run a check for a valid app being present (by CRC calculation, or other method). My own bootloader even sets all affected registers (like those used by the SCI for the firmware update) back to the default settings before executing the app. That way, my app will start running as if straight out of reset.
In some cases, however, (for example, when you need to keep certain pins in a specific default state,) the bootloader should do this setup upon startup, even if an app is not available. For example, a door security system should keep the doors locked (or unlocked, for fail-safe systems) during the firmware update, especially if such update can be performed from a remote location, and not on-site.