diff --git a/bootloader/src/bootloader.c b/bootloader/src/bootloader.c index fa4fce4..6fb28fc 100644 --- a/bootloader/src/bootloader.c +++ b/bootloader/src/bootloader.c @@ -10,7 +10,7 @@ #define BOOTLOADER_VERSION_MINOR 2 //Legal value 0-99. (1 = X.01) //Section defining the address range to erase for the erase device command, along with the valid programming range to be reported by the QUERY_DEVICE command. -#define PROGRAM_MEM_START_ADDRESS REMAPPED_APPLICATION_RESET_VECTOR //Beginning of application program memory (not occupied by bootloader). **THIS VALUE MUST BE ALIGNED WITH 64 BYTE BLOCK BOUNDRY** Also, in order to work correctly, make sure the StartPageToErase is set to erase this section. +#define PROGRAM_MEM_START_ADDRESS APP_FW_MEMORY_OFFSET //Beginning of application program memory (not occupied by bootloader). **THIS VALUE MUST BE ALIGNED WITH 64 BYTE BLOCK BOUNDRY** Also, in order to work correctly, make sure the StartPageToErase is set to erase this section. #define MAX_PAGE_TO_ERASE 511 //Last 64 byte page of flash on the PIC18F4550 #define PROGRAM_MEM_STOP_ADDRESS 0x008000 //**MUST BE WORD ALIGNED (EVEN) ADDRESS. This address does not get updated, but the one just below it does: IE: If PROGRAM_MEM_STOP_ADDRESS = 0x200, 0x1FF is the last programmed address (0x200 not programmed)** @@ -397,7 +397,7 @@ void ProcessIO(void) //in this firmware and is available for requesting by the host software. PacketToPC.Command = QUERY_EXTENDED_INFO; //Echo the command byte PacketToPC.BootloaderVersion = ((unsigned int)BOOTLOADER_VERSION_MAJOR << 8)| BOOTLOADER_VERSION_MINOR; - PacketToPC.ApplicationVersion = *(const unsigned int*)APP_VERSION_ADDRESS; + PacketToPC.ApplicationVersion = *(const unsigned int*)APP_FW_VERSION_ADDRESS; PacketToPC.SignatureAddress = APP_SIGNATURE_ADDRESS; PacketToPC.SignatureValue = APP_SIGNATURE_VALUE; PacketToPC.ErasePageSize = ERASE_PAGE_SIZE; diff --git a/bootloader/src/bootloader.h b/bootloader/src/bootloader.h index 00a58e2..a4a9107 100644 --- a/bootloader/src/bootloader.h +++ b/bootloader/src/bootloader.h @@ -29,18 +29,10 @@ #include "memory.h" +#define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value + void UserInit(void); void ProcessIO(void); -//Vector remapping/absolute address constants -#define REMAPPED_APPLICATION_RESET_VECTOR APP_FW_MEMORY_OFFSET -//#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR APP_FW_MEMORY_OFFSET + 0x08 //See VectorRemap.asm -//#define REMAPPED_APPLICATION_LOW_ISR_VECTOR APP_FW_MEMORY_OFFSET + 0x18 //See VectorRemap.asm -#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS BOOTLOADER_ENTRYPOINT //Execute a "goto 0x001C" inline assembly instruction, if you want to enter the bootloader mode from the application via software - -//#define APP_SIGNATURE_ADDRESS APP_FW_MEMORY_OFFSET + 0x06 //0x1C06 and 0x1C07 contains the "signature" WORD, indicating successful erase/program/verify operation -//#define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value -//#define APP_VERSION_ADDRESS APP_FW_MEMORY_OFFSET + 0x16 //0x1C16 and 0x1C17 should contain the application image firmware version number - #endif /* BOOTLOADER_ */ diff --git a/bootloader/src/main.c b/bootloader/src/main.c index 89280c0..ca4f5a7 100644 --- a/bootloader/src/main.c +++ b/bootloader/src/main.c @@ -36,11 +36,11 @@ DoFlashSignatureCheck: //Also make sure the first WORD of program memory in the app space //is not blank, meaning there is an application image programmed into the device. - if(*(const unsigned int*)REMAPPED_APPLICATION_RESET_VECTOR != 0xFFFF) + if(*(const unsigned int*)APP_FW_MEMORY_OFFSET != 0xFFFF) { //Go ahead and jump out of bootloader mode into the application run mode #asm - goto REMAPPED_APPLICATION_RESET_VECTOR + goto APP_FW_MEMORY_OFFSET #endasm } } diff --git a/common_src/memory.h b/common_src/memory.h index fc1f5c1..6bdd7a9 100644 --- a/common_src/memory.h +++ b/common_src/memory.h @@ -18,24 +18,48 @@ *************************************************************************/ /** - * @file memory. + * @file memory.h * @author Justin Byers * @date August 11, 2019 - * @brief + * @brief Program flash memory addresses of data relocated to work with the bootloader. * */ #ifndef MEMORY_ #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: + * + */ + +/** + * 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 BOOTLOADER_ENTRYPOINT 0x001C - +/** + * The address in application memory space that stores the application's version number. + */ #define APP_FW_VERSION_ADDRESS (APP_FW_MEMORY_OFFSET + 0x16) -#define APP_SIGNATURE_ADDRESS (APP_FW_MEMORY_OFFSET + 0x06) //0x1C06 and 0x1C07 contains the "signature" WORD, indicating successful erase/program/verify operation -#define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value -#define APP_VERSION_ADDRESS APP_FW_VERSION_ADDRESS //0x1C16 and 0x1C17 should contain the application image firmware version number +/** + * The address in application memory space that stores the signature word written by + * the bootloader after a sucessful flash of application firmware. + */ +#define APP_SIGNATURE_ADDRESS (APP_FW_MEMORY_OFFSET + 0x06) + +/** + * 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 #endif /* MEMORY_ */