added massive comment in memory.h about how memory is laid out to work with the bootloader. more code cleanup
This commit is contained in:
@@ -28,21 +28,94 @@
|
||||
#define MEMORY_
|
||||
|
||||
/**
|
||||
* When changing the location of the application in flash memory these files and settings
|
||||
* must be updated.
|
||||
* In bootloader project:
|
||||
* VectorRemap.asm HiVector goto -> APP_FW_MEMORY_OFFSET + 0x08
|
||||
* LoVector goto -> APP_FW_MEMORY_OFFSET + 0x18
|
||||
* Configuration > Linker > Memory Model > ROM space -> default,-APP_FW_MEMORY_OFFSET-7FFF
|
||||
* In application project:
|
||||
* Configuration > Linker > Memory Model > ROM space -> default,-0-[[APP_FW_MEMORY_OFFSET-1]],-[[APP_FW_MEMORY_OFFSET+6]]-[[APP_FW_MEMORY_OFFSET+7]],-[[APP_FW_MEMORY_OFFSET+0x16]]-[[APP_FW_MEMORY_OFFSET+0x17]]
|
||||
* ##########################################################################################
|
||||
* ### Regarding the modified memory layout of program flash to accomodate the bootloader ###
|
||||
* ##########################################################################################
|
||||
*
|
||||
* This firmware implements a bootloader to allow the user to flash firmware over USB without requiring an external
|
||||
* programmer/debugger such as the ICD or Pickit 3. The bootloader and the application are separate binaries that
|
||||
* are compiled and linked independently of each other.
|
||||
*
|
||||
* The bootloader occupies memory in program flash starting at address 0x0000. The MCU will always start program
|
||||
* execution at this address. The application occupies program flash memory starting from a predetermined address after
|
||||
* the end of the memory space occupied by the bootloader through the remainder of the program flash memory. As an
|
||||
* example let's assume the application starts at address 0x1400. The memory map of the corresponding program flash is
|
||||
* shown below.
|
||||
*
|
||||
* ###############################
|
||||
* # Memory Map of Program Flash #
|
||||
* ###############################
|
||||
*
|
||||
* Address Description
|
||||
* ------------------------
|
||||
* 0x0000 Bootloader reset vector
|
||||
* 0x0008 Bootloader interrupt vector (high)
|
||||
* 0x0018 Bootloader interrupt vector (low)
|
||||
* ...
|
||||
* 0x0030 Bootloader absolute entrypoint (application can enter bootloader by jumping to this address)
|
||||
* ==[Remainder of bootloader code]==
|
||||
* 0x1400 Application reset vector
|
||||
* 0x1406 Application signature word**
|
||||
* 0x1408 Application interrupt vector (high)****
|
||||
* 0x1416 Application version word***
|
||||
* 0x1418 Application interrupt vector (low)****
|
||||
* ==[Remainder of application code]==
|
||||
* 0x7FFF (Last byte of program flash)
|
||||
*
|
||||
* Notes: ** The signature word is written with a known value by the bootloader after it writes the application
|
||||
* code to flash memory and verifies the data written. If the bootloader does not read this exact value
|
||||
* at this address at startup it will assume the application code is corrupted and immediately enter
|
||||
* firmware update mode so valid application code can be flashed.
|
||||
* *** The version word is stored at this address by the application code at link time. Currently unused
|
||||
* but I'm leaving the functionality in so the bootloader can report the version of the current
|
||||
* application.
|
||||
* **** The bootloader's interrupt vectors will forward interrupts to the application's interrupt vectors
|
||||
* because they were moved when we offset the application code to 0x1400.
|
||||
*
|
||||
* ##############################################
|
||||
* # Changing the application's memory location #
|
||||
* ##############################################
|
||||
*
|
||||
* 2 source files must be modified, as well as the project configurations for both the bootloader and application
|
||||
* projects.
|
||||
*
|
||||
* #
|
||||
* # File changes
|
||||
* #
|
||||
* File Location Changes
|
||||
* ------------------------------------------------
|
||||
* VectorRemap.asm bootloader * Change address in HiVector goto instruction to address of application
|
||||
* high priority interrupt vector (ex. 0x1408).
|
||||
* * Change address in LoVector goto instruction (NOT the goto 0x30) to address
|
||||
* of application low priority interrupt vector (ex. 0x1418).
|
||||
* THIS FILE shared * Change APP_FW_MEMORY_OFFSET to the starting address of the application
|
||||
* (ex. 0x1400)
|
||||
*
|
||||
* #
|
||||
* # BOOTLOADER project configuration changes
|
||||
* #
|
||||
* Configuration > Linker > Memory Model > ROM space
|
||||
* * Add memory range of application as a protected region. Ranges are separated by a single comma. Ranges that
|
||||
* start with a '-' will be considered protected. Memory addresses specified in hexadecimal. No spaces allowed.
|
||||
* (ex. 'default,-1400-7FFF')
|
||||
*
|
||||
* #
|
||||
* # APPLICATION project configuration changes
|
||||
* #
|
||||
* Configuration > Linker > Memory Model > Additional Options > Code offset
|
||||
* * Set to APP_FW_MEMORY_OFFSET
|
||||
* Configuration > Linker > Memory Model > ROM space
|
||||
* * Add memory ranges for bootloader, application signature word, and application version word as protected
|
||||
* regions. Ranges are separated by a single comma. Ranges that start with a '-' will be considered protected.
|
||||
* Memory addresses specified in hexadecimal. No spaces allowed.
|
||||
* (ex. 'default,-0-13FF,-1406-1407,-1416-1417')
|
||||
*/
|
||||
|
||||
/**
|
||||
* The base address of the application memory space. The application's reset vector will be
|
||||
* at this address.
|
||||
*/
|
||||
#define APP_FW_MEMORY_OFFSET 0x2000
|
||||
#define APP_FW_MEMORY_OFFSET 0x1400
|
||||
|
||||
/**
|
||||
* The address in application memory space that stores the application's version number.
|
||||
@@ -59,7 +132,7 @@
|
||||
* The absolute address of the bootloader entrypoint. The application can jump to the
|
||||
* bootloader by executing a "goto" instruction with this address.
|
||||
*/
|
||||
#define BOOTLOADER_ENTRYPOINT 0x001C
|
||||
#define BOOTLOADER_ENTRYPOINT 0x0030
|
||||
|
||||
#endif /* MEMORY_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user