How to change the LPC 1765 bootloader content through user application(IAP)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to change the LPC 1765 bootloader content through user application(IAP)

3,011 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Mon Mar 23 23:14:44 MST 2015
I have a UART bootloader for LPC1765, through this boot loader user application can be updated. I want to change the bootloader content through the user application. Is it possible to change the boot loader content through the user (IAP) application programming?
标签 (1)
0 项奖励
回复
12 回复数

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal on Fri Mar 27 08:38:11 MST 2015
Dear Bavarian,

1. I am copying the 3rd sector flash data to RAM.
2. Erasing 3rd sector
3. Changing one byte in the RAM data - That is the change i want to do in SBL(change is a data, not instruction).
4. Writing the data in 3rd sector - write success
5. Jumping SBL is doing by invoking feed seq to WDT. If sequence is not feeded then WDT reset the MCU.
6. I have one flag in flash i will set that flag, if the flag is set then My SBL wait for user code chunk(). If the flag is 0 then My SBL jumps to User application.
7. Sometimes copy RAM to flash fail then it is okay for me. All the time it will not fail right?

Regards
R.Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bavarian on Fri Mar 27 07:43:17 MST 2015
Ok, a few more hints/notes/questions:

[list]
  [*]  It's pretty OK to use this version 4 from RedSuite, as long as it creates valid code and the device you are using is supported. There is no urgent reason to upgrade to a new GUI or even a new compiler, you would just get into new problems which you wouldn't have without the upgrade.
  [*]  If you don't change the content of the first 7 words (= 32 bits), then the content of the 8th word stays also the same (as initially generated by FlashMagic)
  [*]  I assume you do an IAP call to erase the first flash sector and afterwards an IAP call to program the updated SBL into the empty sector.
  [*]  Is it an instruction which is changed in the SBL or a parameter? What do you do if during the update process the device looses power or for whatever reasons crashes? Then you have erased the SBL but didn't program a new one --> chip will not longer start correctly.
  [*]  How do you "jump" to the new secondary bootloader? Do you jump to the address of the ResetHandler or simply to 0? The address where the ResetHandler is contains executable code, address 0 just contains the ResetHandler address. The ARM can't do anything with it, it needs executable code. When you do a reset then the flow is differently. Then the ARM fetches in a hardwired function the ResetHandler address from location 0 and a StackPointer address from location 4, then branches to the ResetHandler address and executes from there.
[/list]

Hope this helps,
NXP Support Team
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Thu Mar 26 03:32:19 MST 2015
Hi,

1.Read from where?
Reading 16k (sector 0 t0 3) from flash starting address is 0x00.

2.how was that image created?
SBL is updated using flash magic or debugger. - I hope that would have created.

3. When i am changing the secondary bootloader code then my boot checksum is not changing so i am changing binary data(change what i need)writing the same boot checksum in location 8 and writing data to flash.

4. Still bootloader is not starting.

-Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Mar 25 09:07:54 MST 2015

Quote:
1. My IDE is redsuit NXP 4,Controller is LPC 1765.


This is very old -- download the latest 7.6.2 [BTW, a new update is expected very soon]


Quote:
i. Read the first 16k data to RAM, starting address 0x00. (I am not seeing boot checksum at 8th location, i have 0x00)



Read from where; how was that image created?


Quote:
iii.Calculate the checksum of 7 byte and storing at 8th location.



If you cannot read correctly, then of course you will fail! My pseodo code read writes words (i.e. longs aka as 32-bit)

You have been given all the information that you need or been pointed to official sources.
What more do you want?

Mike
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Wed Mar 25 08:01:16 MST 2015
Hi,

I am doing the following things

1. My IDE is redsuit NXP 4,Controller is LPC 1765.
2. Created a secondary bootloader (UART) hex file (starting address 0x00 - sector - 0)and it is updated using flash magic. This will occupy the 14k flash from address 0x00.
3. User application starting address is 0x00010000 - Sector 16(0x10).
4. User application code has the function ModifySBLData() and if it is called then it will do the following operation - It has many other functions like LED ON, LED OFF.

                ModifySBLData()
i.  Read the first 16k data to RAM, starting address 0x00. (I am not seeing boot checksum at 8th location, i have 0x00)
ii. Modify the binary data.
iii.Calculate the checksum of 7 byte and storing at 8th location.
iv. Copy the modified data to flash.

5. Above user application is builded as like earlier. - Output file is bin file
6. Updating the above user application bin file via secondary bootloader.
7. User application works normally.
8. At some point user application calls the ModifySBLData() function - all the above said process executed and verified that updated data is in flash
9. LED ON/OFF function called - working fine
10. Jumping to Secondary bootloader but Secondary bootloader is not starting.

What mistake i am doing.

Regards
R.Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Mar 25 03:58:37 MST 2015
YOU have to create the checksum in your image before downloading/burning to flash.

It is is the two's complement of the sum of the first 7 vector entries and is stored in the 8th entry (normally reserved/not used).

This only applies to the boot block as is stated in the UM (I already gave the reference).
E.g.
    unsigned long *ptr;     // the base of your (binaray) image
    unsigned long cks = 0;

    for (i = 0, i < 7; i++)
        cks += *ptr++;
    cks = (~cks)+1;
    *ptr = cks;               // ptr left pointing to eigth entry at end of loop


You can add this to your build process by using the supplied checksum tool as a post build step
Normally this is present, but commented out (with the '#'). Read your LPCXPresso help.
Or search forum for boot checksum or similar.

Alternatively, see (and adapt) this thread.

Cheers, Mike





0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Wed Mar 25 00:09:33 MST 2015
Dear MikeSimmonds,

I have checked the first 8 locations in sector 0 of the flash also checked in flash address 0x1C. But i couldn't find the boot checksum in my image, Can you please help me to identify the boot checksum.

My boot loader start address is 0x00000000 - Sector 0.
User Application  start address is 0x00010000- Sector 16(0x10).

Regards
R.Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Wed Mar 25 00:07:32 MST 2015
Dear MikeSimmonds,

I have checked the first 8 locations in sector 0 of the flash also checked in flash address 0x1C. But i couldn't find the boot checksum in my image, Can you please help me to identify the boot checksum.

Regards
R.Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Tue Mar 24 05:52:27 MST 2015
Thanks MIke,

You are right, I have not done the boot checksum. I will try that and get back.

Thanks
R.Dhanapal
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Tue Mar 24 05:24:41 MST 2015
I am sorry, but I cannot advise about the correctness of your replacement bootloader code.

Well, one hint maybe.

I am guessing that you 'installed' the original boot loader via either the debugger or FlashMagic.

Both these paths will set the correct 'boot checksum'. [Look this up in your UM "Criterion for Valid User Code"]
I am further guessing that in your new image, you have not done this.

If this is not the case, you will have to seek assistance elsewhere.

Mike.
0 项奖励
回复

2,610 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dhanapal_2005 on Tue Mar 24 03:03:52 MST 2015
Thanks MIke,

Bootloader size is 14k. Loaded the bootloader in mc board. I made changes in the bootloader and recompiled it. The only difference is one byte.

In the user application i read the 14k bootloader content in the RAM and changed only one byte in RAM data and updated the data in the flash.
If i read the flash content then my changes are updated, but my bootloader is not working even if mc is rebooted.

Thanks
R.Dhanapal
0 项奖励
回复

2,611 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Tue Mar 24 00:16:36 MST 2015
Yes, but with reservations.

You would probably have to copy the boot loader update code in to internal SRAM and execute from there.
[Because you cannot read (i.e prefetch code) from the flash while it is being erased or programmed.]

Also, (simplistically) ALL interrupts must be disabled. [Because an interrupt will read the vector table in flash.]

Ideally, the replacement image should also be completely saved (also in RAM) to make things easier.

THE BIG ISSUE IS that if the update fails, you then have an un-bootable device, and to recover from
that situation, you will need ISP mode and e.g. FlashMagic with a known good boot loader.

If you do go for this scenario, I would suggest adding the 'boot update' code say at the end of the actual
boot loader. The application (in your scenario) would copy that to RAM and execute as outlined above.

This way, you don't have update code added to every application, but just once in the boot loader.

Cheers, MIke



0 项奖励
回复