# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MLA -- USB Library

20 December, 2013

- 1
- 2
…
- 264
- 265
- 266
- 267
- 268
…
- 311
- 312

In the following examples we will be increasing the size of the boot loader from 0x1400 to 0x2400 in length.
First start by determining the size that you want the boot loader to be. This must be a multiple of an erase page. On many
PIC24F devices there is a 512 instruction word erase page (1024 addresses per page). Please insure that the address you
select for the end of the boot loader corresponds to a page boundary. There are several ways to determine the size of the
boot loader application. Below is an example of one method.
1) Remove the boot loader linker script provided if it is causing link errors due either to optimization settings or added code.
2) Build the project
3) Open the memory window and find the last non-blank address in the program memory space.
4) Find the next flash erase page address after this address. Add any additional buffer room that you might want for future
boot loader development, growth, or changes. Use this address as your new boot loader end address.
Once the end address of the boot loader is known, start by modifying the boot loader linker script program memory region to
match that change. The boot loader linker script can either be found in the folder containing the boot loader project file or in a
folder that is specified for boot loader linker scripts. In the linker script find the memory regions.
MEMORY
{
data (a!xr) : ORIGIN = 0x800, LENGTH = 0x4000
reset : ORIGIN = 0x0, LENGTH = 0x4
ivt : ORIGIN = 0x4, LENGTH = 0xFC
aivt : ORIGIN = 0x104, LENGTH = 0xFC
program (xr) : ORIGIN = 0x400, LENGTH = 0x2000
config4 : ORIGIN = 0x2ABF8, LENGTH = 0x2
config3 : ORIGIN = 0x2ABFA, LENGTH = 0x2
config2 : ORIGIN = 0x2ABFC, LENGTH = 0x2
config1 : ORIGIN = 0x2ABFE, LENGTH = 0x2
}
Change the LENGTH field of the program memory section to match the new length. Note that this is length and not the end
address. To get the end address, please add LENGTH + ORIGIN.
Next, locate the __APP_IVT_BASE definition in the linker file. Change this to equal the end address of your boot loader.
__APP_IVT_BASE = 0x2400;
Once the length of the boot loader is changed, you will need to make similar changes in the application boot loader linker
script. The application boot loader linker scripts are typically found in a folder with the boot loader project. In the application
linker file, locate the memory regions section. In this section there are three items that need to change.
1. The first is the ORIGIN of the app_ivt section. This needs to be modified to match the new end address of the boot loader.
2. Second, move the ORIGIN of the program memory section to the ORIGIN of app_ivt + the LENGTH of the app_ivt section
so that the program memory starts immediately after the app_ivt section.
3. Last, change the LENGTH field of the program section so that it goes to the end of the program memory of the device.
Remember that the LENGTH field is the length starting from the origin and not the end address. An easy way to make
sure that this address is correct is by just subtracting off from the LENGTH the same amount that was added to the
ORIGIN.
MEMORY
{
data (a!xr) : ORIGIN = 0x800, LENGTH = 0x4000
reset : ORIGIN = 0x0, LENGTH = 0x4
ivt : ORIGIN = 0x4, LENGTH = 0xFC
aivt : ORIGIN = 0x104, LENGTH = 0xFC
app_ivt : ORIGIN = 0x2400, LENGTH = 0x110
program (xr) : ORIGIN = 0x2510, LENGTH = 0x286E8
config4 : ORIGIN = 0x2ABF8, LENGTH = 0x2
config3 : ORIGIN = 0x2ABFA, LENGTH = 0x2
config2 : ORIGIN = 0x2ABFC, LENGTH = 0x2
config1 : ORIGIN = 0x2ABFE, LENGTH = 0x2
}
The final changes that needs to be made are in the boot loader code itself. Open up the boot loader project.
1. Find the ProgramMemStart definition in the main.c file. Change the start address to match the new address.
1.6 Demos MLA - USB Library Help Device - Boot Loader - HID
266

- 1
- 2
…
- 264
- 265
- 266
- 267
- 268
…
- 311
- 312