A hex file can be created that contains both the application and the bootloader. Merging the bootloader and application hex files can be done as follows:
First, make a hex file for the bootloader and then load it into your application project. A unified hex file will be made by the compiler. Please read section 5.4 of the MPLAB® X IDE User's Guide which can be downloaded from the 'Documentation' tab of the product landing page.
Steps to be followed (from Section 5.4 of the User's Guide):
- In the project tree, there is a branch called loadables in MPLAB X IDE.
- Open the first project
- Right-click on loadables in the project tree and add the second project.
- Perform a build or debug. That will merge both project hex files or elf files for debugging.
Check to make sure that the two projects do not overlap in memory. If they do, you will get an error. When combining the Bootloader and Application projects in MPLAB X IDE, make sure that both the bootloader's configuration and the application's configuration bits are the same. Otherwise, this will generate a data conflict error with a given address. To resolve this, match the bootloader's configuration bits with the application's configuration bits.
Please note that his method doesn't work for all PIC® MCUs. We do not have a document listing which ones work. The only way to verify for now is by testing it. For an XC16 application, if there is a data conflict at the IVT, in the XC16 linker options uncheck the box for creating the default ISR.
Here's a forum post that has some good discussion on "Merging Bootloader and Application Hex files": http://www.microchip.com/forums/m441306.aspx.