Hi,
I'm trying to implement the internal flash dual image boot on LPC5536 using IAR.
First of all let me know if i understand well how it works: Let's consider figure 86, chapter 26.3.1.1.1.1 of of LPC553x Reference Manual, and let's assume that header of image0 contains an image version 0, and header of image1 contains an image version 1. At startup ROM checks both headers and since image1 has an higher image version, image1 is run. Correct?
In LPC5536 the total size of the flash is 0x3DC00, so dividing it by 2, each block will have size 0x1EE00
First thing to do is to change the CMPA fields FLASH_REMAP_SIZE and FLASH_REMAP_OFFSET to match the 0x1EE00 block size.
To access CMPA, i used functions from fsl_flash_ffr.h, named FFR_GetCustomerData and FFR_CustFactoryPageWrite. In particular, after calling FLASH_Init and FFR_Init, I use these functions as follows:
static cmpa_cfg_info_t cmpa;
status = FFR_GetCustomerData(&s_flashDriver,(uint8_t *)&cmpa,0,512);
if (status != kStatus_Success)
{
error_trap();
}
cmpa.flashRemapSize = 0x1EDFF;
cmpa.flashRemapOffset = 0x1EE00;
status = FFR_CustFactoryPageWrite(&s_flashDriver,(uint8_t *)&cmpa,false);
if (status != kStatus_Success)
{
error_trap();
}
This part of code seems to work without particular problems.
Second thing to do is to produce image with version number in the header; to achive this, i change the "startup_LPC55S36.s" file as follows:
__vector_table
DCD sfe(CSTACK)
DCD Reset_Handler
DCD NMI_Handler
DCD HardFault_Handler
DCD MemManage_Handler
DCD BusFault_Handler
DCD UsageFault_Handler
__vector_table_0x1c
DCD SecureFault_Handler
DCD 0x1EDFF
DCD 0x10400
DCD 0
DCD SVC_Handler
DCD DebugMon_Handler
DCD 0
DCD PendSV_Handler
DCD SysTick_Handler
...
In this way, using 0x10400 i produce an image with version number 1, using 0x20400 i produce an image with version number 2 and so on.
I completed the example application turning on a blue LED in image0 and a red LED in image1.
From IAR options i created a srec file filling unused memory with 0xFF until address 0x1EDFF, and i used ISP functions to write the images into flash.
The problem is that regardless of the image version, the only image loaded at startup is image0.
So the question is can you help me to spot the mistake in this code and to implement the dual image boot correctly?
Thanks
Enrico
已解决! 转到解答。
Hello @EnBono
I made a dual image test on my side, it can works well. I used led_blinky demo under SDK, default led is RED, use this as image0, version is "1",start from 0x00, then change RED LED to BLUE LED, start from 0x20000, as image 1, version is "2".
Use blhost program CMPA.
About projects, .bin files and cmpa.bin, please see attachment.
BR
Alice
Hello @EnBono
1)
First of all let me know if i understand well how it works: Let's consider figure 86, chapter 26.3.1.1.1.1 of of LPC553x Reference Manual, and let's assume that header of image0 contains an image version 0, and header of image1 contains an image version 1. At startup ROM checks both headers and since image1 has an higher image version, image1 is run. Correct?
->> Yes.
2) How about refer to Fig86 to remap?
3) Please read out memory after program, check whether program the two images correct.
BR
Alice
Hello @Alice_Yang,
2)
How about refer to Fig86 to remap?
->> I produced something similar. Reading out the memory after programming, it can be seen that there is a first image from 0x0 to 0x1EDFF (the real image is from 0x0 to 0x2EE1, the rest of the image is filled with 0xFF), and there is a second image from 0x1EE00 to 0x3DBFF (the real image is from 0x1EE00 to 0x21CE1, the rest of the image is filled with 0xFF)
3)
Please read out memory after program, check whether program the two images correct.
->> I read out the memory and the images are exactly the same contained in srecord files.
Using bootloader, i tried to read the property "Check Status", and i got 10403 code (0x28A3) which should mean "Application CRC check is invalid". However i'm trying to use a plain image without CRC.
Moreover, when building the image1 in IAR, i keep "transparent" that this will be placed in memory with an offset. This means that the image is build exatcly as image 0, and when i write it into flash, i add an offset to the addresses (for example srecord address 0 will be placed in 0x1EE00, srecord address 0x10 wil be placed in 0x1EE10 and so on). Is it correct?
Thanks
Enrico
Hello @EnBono
I made a dual image test on my side, it can works well. I used led_blinky demo under SDK, default led is RED, use this as image0, version is "1",start from 0x00, then change RED LED to BLUE LED, start from 0x20000, as image 1, version is "2".
Use blhost program CMPA.
About projects, .bin files and cmpa.bin, please see attachment.
BR
Alice