Below is some advice that others may find useful getting a boot loader and non-boot loader version of a PIC18 program to work.
Outline of the task I had.. Adapt an existing (production/field) loader for PIC24/33 FJ&EP to work with a PIC18 project (existing being upgraded).
The PC end program is existing and not being modified.
I found this thread very useful so thanks to the contributors for this..
http://www.microchip.com/forums/m833484-p3.aspx
Using MPLab 8.92, MPLabX V3.26, XC8 V1.37 (free). Win 7 64bit.
Much time was spent trying to get the XC8 compiler to work with MPLab 8.92 to implement the facilities needed for boot loading. Although got it compiling and running. Using the linker script memory region allocations - OK. The compiler would not implement the facilities to intercept the vectors (without resorting to assembly). Not acceptable.
After much time wasted the existing PIC18 project was imported to MPlab X, as if by magic all the promised compiler facilities appeared (MChip PDF document). But there still appears to be some issues. The compiler (free ver) removes unused code/routines but does not appear to have a facility to disable this (would be interested in anybody's success with this).
(as described in thread above) Declare an OFFSET in MPLabX based upon on your designed memory map. Example
0x4000
This does not have to be a command line addition. There is a field in a dialog box that can be adjusted. It is found in the Project Properties, under XC8 Linker, Additional Otions (drop down box) 'Codeoffset'. Now be aware that adding this and compiling, your application is now broken and will not work properly!!!
Nor will the debugger (PICkit 3 in my case) work properly under certain cases.
To permit your application to be developed, with debugger and all, patches need to be added to the original code to 'link' the vectors as the boot loader would.
These are...
void VectorReset() @ 0x0000
{
asm( "GOTO 0x4000");
}
void VectorHigh() @ 0x0008
{
asm( "GOTO 0x4008");
}
void VectorLow() @ 0x0018
{
asm( "GOTO 0x4018");
}
...The compiler will then kill all your good intentions by removing these because they are 'never' used.
They MUST not be declared as interrupts. The only way I found for these to be included is to call all three routines in an 'unreachable' section of code and put up with the compiler warning.
//Need to place 'users' to prevent exclusion by compiler
VectorReset();
VectorLow();
VectorHigh();
I chose the location after the 'forever' while loop in main().
Now when compiled, loaded and debugging, the program operates exactly the same as if the boot loader was used, making it transparent. Simple but essential.
Sorry can not post details of the boot loader as it encrypts and is commercially protected. But if you are familiar with memory maps and such you will be aware of the need to protect certain memory areas, page 0 being one of them.
Hope this assists.
T Yorky.