Custom bootloader

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

Custom bootloader

1,528 Views
natjaysurani
Contributor I

Dear NXP support.

I'm using LPC54114 and I'm trying to write an SBL. I looked at AN11610, but I have a different scenario (encryption, external EEPROM, etc.) and i cannot use that SBL, since there are no source files available. Is there any source files available for simple bootloader for MCUxpresso or is IAP example the way to go? I'm mostly interested in memory map and vector table settings that i need to make for my custom bootloader and application.

Best regards,

Labels (3)
0 Kudos
5 Replies

1,116 Views
natjaysurani
Contributor I

Hello Kerry,

just the path i took. I just thought that maybe maybe I'm missing something and there is sometihn more out of box available.

I'll give it a shot, thank you!

Best regards,

Natjay

0 Kudos

1,116 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Natjay Surani,

    1. About the AN11610 SBL source code

     Unfortunately, I also don't have it on my side. So, if you want to modify the function, you need to use the IAP function write the code by yourself.

    We have the LPC54114 mcuxpresso flashiap code for your reference, please refer to the LPC54114 SDK which can be downloaded from this link:

Welcome | MCUXpresso SDK Builder 

2. memory map and vector table.

   You can refer to this post:

Secondary bootloader error 

Floor 3:

Bootloader is located at location 0x0 in memory.
Application is located at location 0x8000 (sector 1)

/*--------------------------------------------------------------------------------*/
/* bootloader config */
typedef void (*USER_ENTRY_PFN)();
#define SBL_SLV_FIRMWARE_START(0x8000)
USER_ENTRY_PFN user_entry;


/* Call bootloader */
__disable_irq();
SCB->VTOR = SBL_SLV_FIRMWARE_START;
__enable_irq();
//__set_MSP(SCB->VTOR);//load stackpointer with initial value
__set_MSP(*(uint32_t *)SBL_SLV_FIRMWARE_START);
(user_entry)();

  

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,116 Views
natjaysurani
Contributor I

Dear Kerry,

I've tried to do the following, but failed to run the program from my 'bootloader' (CPU: LPC54114):

- IAP example will become my bootloader. For now, all I do, is try to execute code at 0x0000 8000

- This is how I tried it:

typedef void (*USER_ENTRY_PFN) ();
#define SBL_SLV_FIRMWARE_START (0x8000)
USER_ENTRY_PFN user_entry;

In main():

__disable_irq();
SCB->VTOR = SBL_SLV_FIRMWARE_START;
__enable_irq();
//__set_MSP(SCB->VTOR);//load stackpointer with initial value
__set_MSP(*(uint32_t *)SBL_SLV_FIRMWARE_START);
(user_entry)();

- for program to run after bootloader, I've took periph_blinky code and set FLASH to start from 0x0000 8000 (as AN suggested)

- If i test periph_blinky with flash start at 0x0000 0000, it works

- I've programmed periph_blinky AXF manually (FALSH start at 0x0000 8000) and it says page 1-1 has been flashed (that should be correct i believe)

- after i flash blinky, i debug IAP example (my 'bootloader'). It only flashes page 0-0 (also OK).

- after i step into line (user_entry)(); , the debugger reports it's at 0x0000 81e8. That corresponds to blinky's  HardFault_Handler, according to map file

Now the questions:

1) any idea why blinky jumps to  HardFault_Handler after i call it from my 'bootloader'?

2) is there any way to load symbol file of blinky? At the moment i'm operating with disassembler only.

I've attached the sample projects for reference. I'm really stuck here :smileysad:

Best regards,

Natjay 

0 Kudos

1,116 Views
natjaysurani
Contributor I

Hello Kerry,

1)

the map file of bootlaoder indicates that the length is 0x4920:

.text 0x00000000 0x4920

2)

As for your second question, I think I've already answered in previous post: I've programmed periph_blinky AXF manually (FLASH start at 0x0000 8000) and it says page 1-1 has been flashed (that should be correct i believe)

This is output from flash tool:


Nt: Loading 'periph_blinky.axf' ELF 0x00008000 len 0x2408
Nc: Opening flash driver E:\nxp\LPCXpresso_8.2.2_650\lpcxpresso\bin\Flash\LPC5411x_256K.cfx
Nt: Writing 9224 bytes to address 0x00008000 in Flash
Pb: 1 of 1 (  0) Writing pages 1-1 at 0x00008000 with 9224 bytes
Ps: (  0) at 00008000: 0 bytes - 0/9224
Ps: (100) at 00008000: 16384 bytes - 16384/9224
Nt: Erased/Wrote page  1-1 with 9224 bytes in 341msec
Pb: (100) Finished writing Flash successfully.
Nt: Flash Write Done
Nt: Loaded 0x2408 bytes in 640ms (about 14kB/s)

If I enter bootloader debug, this is disassembly of location 0x8000:

00008000:   movs    r0, r0
00008002:   movs    r0, #1
00008004:   strh    r1, [r2, #16]
00008006:   movs    r0, r0
00008008:   strh    r1, [r4, #14]
0000800a:   movs    r0, r0
0000800c:   strh    r1, [r5, #14]
0000800e:   movs    r0, r0
00008010:   movs    r0, r0
00008012:   movs    r0, r0
00008014:   movs    r0, r0
00008016:   movs    r0, r0
00008018:   movs    r0, r0

When i step into (user_entry)();

000081e8:   push    {r7}
000081ea:   add     r7, sp, #0
000081ec:   b.n     0x81ec
000081ee:   nop    
000081f0:   push    {r7}
000081f2:   add     r7, sp, #0

and according to blinky map file, this is the function:

0x000081e8 HardFault_Handler

It looks like rom binary perspective, everything is there.

I'm just not sure why HardFault_handler. What causes it?

What resides at 0x8000? First instruction or vector table?

Best regards,

Matej

PS: could it me an error in my calling blinky code?:

typedef void (*USER_ENTRY_PFN) ();

#define SBL_SLV_FIRMWARE_START (0x8000)

USER_ENTRY_PFN user_entry;

.

.

.

.

in main()

__disable_irq();

SCB->VTOR = SBL_SLV_FIRMWARE_START;

__enable_irq();

//__set_MSP(SCB->VTOR);//load stackpointer with initial value

__set_MSP(*(uint32_t *)SBL_SLV_FIRMWARE_START);

(user_entry)();

0 Kudos

1,116 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Natjay,

   Please check your bootloader size, is it smallter than 0x0000 8000? This is very important.

   You also can enter the bootloader debug, check memory 0x0000 8000, and compare it with your application code, is the application code already download to the 0x0000 8000 successfully?


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos