Updating user code checksum when debugging

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating user code checksum when debugging

594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by remcopoelstra on Tue Mar 24 08:20:08 MST 2015
Hi,

When debugging an application, the user code checksum (at offset 0x1c) is automatically inserted when flashing the part. Unfortunately it seems this only happens when the data is written starting at address 0x0.
As I'm using a secondary bootloader the final application gets written to address 0x2400. I would like to use the same checksum to validate the user image from the secondary bootloader.
Would it be possible to instruct the debug process to also calculate the checksum when writing at another address in the flash?

Thanks in advance.

Kind regards,

Remco Poelstra
0 Kudos
3 Replies

510 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by remcopoelstra on Wed Mar 25 00:44:40 MST 2015
This works perfect! Many thanks.

Regards,

Remco Poelstra
0 Kudos

510 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Mar 24 10:41:40 MST 2015
There is no way to get the debugger to do this for you.

However, what you could do is embed the checksum creation into your actual build process as follows:

1. Modify the startup code to add a checksum entry as follows:

WEAK void __valid_user_code_checksum(void);

void (* const g_pfnVectors[])(void) =
{
   // Core Level - CM3
   (void *)&_vStackTop, // The initial stack pointer
   ResetISR, // The reset handler
   NMI_Handler, // The NMI handler
   HardFault_Handler, // The hard fault handler
   MemManage_Handler, // The MPU fault handler
   BusFault_Handler, // The bus fault handler
   UsageFault_Handler, // The usage fault handler
   (void *)&__valid_user_code_checksum, // Checksum
... etc
}


2. Create a linker script template in your project (http://www.lpcware.com/content/faq/lpcxpresso/linker-script-templates) and add the following immediately after the existing PROVIDE entries (towards the end of the template), add:

   /* Calculate NXP Cortex-M3 valid user code checksum. This is 0-(sum of first 7 entries in vector table),
    * Note that we must add 1 to each code space vector (LSB = marker for thumb code).
    */
   PROVIDE(__valid_user_code_checksum = 0 - (_vStackTop + (ResetISR + 1) + (NMI_Handler + 1) + (HardFault_Handler + 1) + (MemManage_Handler + 1) + (BusFault_Handler + 1) + (UsageFault_Handler + 1)));


Note that as written above this is suitable for use with CM3/CM4 based parts and would need some modifications for CM0/CM0+ parts (as their vector tables have fewer standard entries defined).

This is actually a mechanism we are considering building into a future LPCXpresso release.

Regards,
LPCXpresso Support

0 Kudos

307 Views
Loïc
Contributor I

Hi,

Sorry to re-open this topic, but i'm working on a LPC804 (Cortex-M0+), and I would like to know if I need to modify the linker script ?

/* ## Create checksum value (used in startup) ## */
PROVIDE(__valid_user_code_checksum = 0 - 
                                     (_vStackTop 
                                      + (ResetISR + 1) 
                                      + (( DEFINED(NMI_Handler) ? NMI_Handler : M0_NMI_Handler ) + 1) 
                                      + (( DEFINED(HardFault_Handler) ? HardFault_Handler : M0_HardFault_Handler ) + 1) 
                                      )
        );

 

Because my vector table looks like this :

void (* const g_pfnVectors[])(void) = {
    // Core Level - CM0P
    &_vStackTop,                       // The initial stack pointer
    ResetISR,                          // The reset handler
    NMI_Handler,                       // The NMI handler
    HardFault_Handler,                 // The hard fault handler
    0,                                 // Reserved
    0,                                 // Reserved
    0,                                 // Reserved
    __valid_user_code_checksum,        // LPC MCU checksum
    0,                                 // ECRP
    0,                                 // Reserved
    0,                                 // Reserved
    SVC_Handler,                       // SVCall handler
    0,                                 // Reserved
    0,                                 // Reserved
    PendSV_Handler,                    // The PendSV handler
    SysTick_Handler,                   // The SysTick handler
... etc
};

 

Do I need to add the SVC_Handler / PendSV_Handler / SysTick_Handler to the checksum operation ?

And do I need to add this to the vector table and checksum operation ?

 MemManage_Handler, // The MPU fault handler
   BusFault_Handler, // The bus fault handler
   UsageFault_Handler, // The usage fault handler

 

Or all of this is okay ?

 

BR,

Loïc

0 Kudos