Bootloader Generator User's Guide: 2015-2016 Microchip Technology Inc. DS40001779B
Bootloader Generator User's Guide: 2015-2016 Microchip Technology Inc. DS40001779B
User’s Guide
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our website
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE online help.
Select the Help menu, and then Topics to open a list of available online help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
Bootloader Generator. Items discussed in this chapter include:
• Document Layout
• Conventions Used in this Guide
• Warranty Registration
• Recommended Reading
• The Microchip Website
• Development Systems Customer Change Notification Service
• Customer Support
• Revision History
DOCUMENT LAYOUT
This document describes how to use the Bootloader Generator software library through
MCC to produce code for application integration, along with use of MPLAB® X and the
Unified Bootloader Application. The document is organized as follows:
• Chapter 1. “Overview”
• Chapter 2. “Options, Parts and Pieces”
• Chapter 3. “Hex File”
• Chapter 4. “MCC Bootloader Generator”
• Chapter 5. “Merge Bootloader with the Application”
• Chapter 6. “Bootloader Host Application”
• Chapter 7. “Bootloader Protocol”
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB® IDE User’s Guide
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog
A menu selection select Enable Programmer
Quotes A field name in a window or “Save project before build”
dialog
Underlined, italic text with A menu path File>Save
right angle bracket
Bold characters A dialog button Click OK
A tab Click the Power tab
N‘Rnnnn A number in verilog format, 4‘b0010, 2‘hF1
where N is the total number of
digits, R is the radix and n is a
digit.
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Filenames autoexec.bat
File paths c:\mcc18\h
Keywords _asm, _endasm, static
Command-line options -Opa+, -Opa-
Bit values 0, 1
Constants 0xFF, ‘A’
Italic Courier New A variable argument file.o, where file can be
any valid filename
Square brackets [ ] Optional arguments mcc18 [options] file
[options]
Curly brackets and pipe Choice of mutually exclusive errorlevel {0|1}
character: { | } arguments; an OR selection
Ellipses... Replaces repeated text var_name [,
var_name...]
Represents code supplied by void main (void)
user { ...
}
WARRANTY REGISTRATION
Please complete the enclosed Warranty Registration Card and mail it promptly.
Sending in the Warranty Registration Card entitles users to receive new product
updates. Interim software releases are available at the Microchip website.
RECOMMENDED READING
This user’s guide describes how to use Bootloader Generator MCC software library,
and Unified Bootloader host application. Other useful documents are listed below. The
following Microchip documents are available and recommended as supplemental ref-
erence resources.
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the website at:
http://www.microchip.com/support.
REVISION HISTORY
Revision A (October, 2016)
This is the initial release of this document.
Bootloader
Host
End
Application
The host application is responsible for loading the new hex file, and send it to the
bootloader through supported command syntax. The end application is required to be
aware of the bootloader, and must understand how to return control to the bootloader
upon request, or configured events. The bootloader by default is generated to run upon
start-up, and confirms if a valid application is loaded. If a valid application is present,
control is relinquished, otherwise operation will remain within the bootloader. This is
further explained in Chapter 5. “Bootloader Host Application”.
The host application used to manage the bootload process can be Microchip’s Unified
Bootloader Application, a custom made stand-alone application, or a separate external
Microcontroller device. Either way, the end purpose remains the same; updating the
end application firmware version through use of the Bootloader and supported
commands. This user’s guide describes one form of implementation, using the
Bootloader Generator MCC software library to produce code which supports proper
command syntax for interaction with Unified Bootloader host Application.
It will describe how to configure an end-application to be aware of boot-loading
possibility which transfers control back to the Bootloader under a trigging condition.
Note: Some developers see the Read Program command as a possible security
hole and typically wish to omit functionality.
Switch to bootloader
End application clears
the new Reset vector
and resets device.
On Reset, the bootloader
checks the new Reset vector
Host sends commands to and interprets the 0x00
erase application area instruction as
and write new application. bootload requested.
Another method involves use of a state variable stored in nonvolatile memory; this
location is known by both bootloader and end-application. The bootloader on start-up
will inspect the value for a specific value representing a “valid application” code. Values
used do not matter, but should be consistent and known by both bootloader and
end-application firmware.
The state variable at a minimal must support three states:
• Erased/Blank
• End-Application Valid
• Bootload requested
Example steps for this process are as follows (see Figure 2-2):
1. Host communicates to end-application a “Bootloader Request”.
2. End-application sets the nonvolatile memory variable to indicate a requested
bootload operation, and resets the device.
3. On start-up the bootloader inspect the value and finding a “Bootloader
Requested” state or erased value, stays within bootloader operation.
4. The host application issues Erase command request over the end-application
code range.
5. The host application loads the new firmware hex file, and issues Write command
request in sections until the full end-application is updated.
6. Host calculates a checksum value of the hex file, then issues a Calculate
Checksum command request to the bootloader for comparison.
Switch to bootloader
End application sets
state variable to “bootload
requested”
and resets device.
On Reset, the bootloader
checks the state variable;
Host sends commands to indicates bootload requested.
erase application area
and write new application.
Switch to bootloader
End application clears
the pre-calculated value
and resets the device.
On Reset, the bootloader
calculates the checksum of
Host sends commands to the application area which fails
erase application area the now cleared pre-calculated
and write new application. value and runs the bootloader.
If the end-device does not normally connect to the host device, it is possible to modify
the bootloader so that upon power-on the communication bus is monitored. On
start-up, the bootloader would listen for any activity, if detected, the bootloader will
remain in control instead of relinquishing to the end-application. However, if after a
configured length of time no activity is observed, the end application is granted control
by the bootloader (see Figure 2-4).
In addition to one of the above bootload entry methods, it may be beneficial to have a
means to force the bootloader to run notwithstanding the state of the primary entry
method. The bootloader supports checking the state of an IO line for this purpose.
2.7 ENCRYPTION
It is possible to encrypt the data which is sent to the device. In order for this encryption
to be effective, a robust key management system is required to be in place.
No encryption methods are supported at this time. Customers who wish to implement
an encryption scheme in their bootloader should contact Microchip for support in this
regard.
6. Select the Memory Peripheral. Nothing further needs to be configured. This will
include a memory.h file which has #defines that specify how big the Flash
memory is, write latches and erase row size.
Note: The Reset vector must be aligned to the beginning of an erase row. The
Erase command erases the entire row. The bootloader needs to make sure
it does not erase any part of the bootloader, so any Erase command not
starting on a row boundary will be disallowed.
8. Open the Pin Manager Grid View. Configure pin selections for the bootloader
operation behavior. As shown below, the lab RA0 is used for the Bootloader
Indication pin (output), RA5 is the Bootloader entry pin (input), Tx and Rx are on
RC0 and RC1.
9. Select Pin Module from the Project Resources, “System” option. Configure
applicable pins to be digital by deselecting the analog check box option on all
pins used.
11. For the final step, configure to only build within a specified memory space. Open
the Project Properties window; this can be done by right clicking on a project and
selecting properties. Select XC8 Linker, under the XC8 global options. Select
“Memory Model” under the Option Categories combo box. For example, entering
the value of 0-2FF would restrict the generated code to the first 0x300 words of
ROM when compiling project code. Refer to code size for appropriate ROM
reservation size. To best understand the required ROM range, after a successful
build of the Bootloader project, refer to the “PIC Memory Views” --> “Program
Memory”; or at the Window --> “Dashboard”, Memory Section.
4. From the Conf: [No Configurations] select the “XC8 Compiler” under “XC8 global
options”. The first field is labeled as “Define a macros”, double click inside the
blank field or press on the icon. Add the Text, “OMIT_CONFIGURATIONS” to the
field.
#endif
Using OMIT instead of INCLUDE means the Configuration bits will be generated by
default. This is to great advantage when merging the bootloader with the application.
From Conf: [Offset] select “XC8 Linker” under “XC8 global options”. Select the
“Additional Options” from the “Option categories” combo box. Enter into the
”Codeoffset” field the program memory Flash value where the application will start
while leaving room to not occupy the bootloader code space. This will automatically
remap the Reset, and interrupt vectors to appropriate locations, respectively. For
example, a value of 0x300 on a PIC16 will offset the Reset Vector to 0x300 and
Interrupt Service Routine to 0x304; on a PIC18 Interrupt Service Routines would be
located at 0x308 and 0x318. Apply the same offset to the “Combined” configuration.
6.2 PREREQUISITES
Make sure that the MPLAB X IDE or MPLAB communication libraries are installed on
the machine. If any problems arise while starting the application, try re-installing
MPLAB X.
The values to be entered in the text fields for the “Program Memory size” and
“Bootloader offset” must be in hex format. By default, the application is set to have an
offset of 300 (hex) with program memory size as 4000 (hex).
Version 1.0 of the application performs “Program Memory and EEPROM” writes only
with UART interface.
2. Pick the device family (PIC16 or PIC18) from the other drop-down menu (see
Figure 6-3).
4. Set the program memory size depending on the target device (see Figure 6-5).
Be aware that the program memory size is the number of locations. For example,
if the target device has program memory starting from 0-3FFF, then 4000 should
be entered in the text field. The size of every location depends on the target
device. Some devices have word-addressable Flash and others have it
byte-addressable.
5. Click the Program Device button (see Figure 6-6 through Figure 6-8).
6. Select the File then Open/Load file to select the hex file to load.
7. Once the device is programmed, the bootloader will disconnect from the COM
port.
6.5 TROUBLESHOOTING
If the application fails to connect, close the application, unplug the target device, plug
it back in and start the application again. If the device is connected while the application
is running, click the Refresh option under the menu to pull up the COM port. Pull up
the Console window to check the nature of the error. There is a status label above the
progress bar which displays messages appropriately.
Send GetVersion
Command
Success No
?
Yes
Erase Application
Area
Write a line to
memory
Last Line No
Sent?SE
Yes
Request Checksum
of App Area
No
Checksums Abort
Match?SEN Bootload
Yes
Reset Device
Note: Most PIC16F1 devices can only change Configuration Words via an
external programmer, not via a bootloader.
Tx to device: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Description: Request bootloader version information.
Rx from device:
Command string: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Bootloader Version: 0x06 0x00
Max Packet size:0x00 0x01 (0x100)
Not Used: 0x00 0x00
Device ID:0xA1 0x5C
Not Used:0x00 0x00
Erase Row Size:0x40
Write Latches:0x40
Config Words:0x00 0x28 0x5F 0x3C
Note: The erase address must be aligned to the first address of an erase row. Any
attempt to erase with an address not at the beginning of a row will be
rejected with an address error code.
Rx from Device:
Command String:0x08 0x00 0x3B 0x00 0x00 0x00 0x05 0x00 0x00
Checksum:0x15 0x4D