Replace application at runtime with IAP and boot switch

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

Replace application at runtime with IAP and boot switch

1,256 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ahp on Mon Jul 02 01:11:45 MST 2012
I am developing a GSM based application using LPC1768 on an LPCXpresso board and Red Suite 3. I use FlashMagic for deployment (not debugging and test, I use a debugging link directly from Red Suite 3).

The LPC1768 has got 512kbyte Flash. The main application uses about 150kbyte, so I am able to have two complete applications in Flash at the same time. Initially only one application exist, but the application is able to load another from GSM into unused Flash using IAP.

I expect to place the boot application in the first 4k sector. The configurations in the next two 4k sectors and the applications from 0X0000 3000 - 0x0003 FFFF (application 1) and 0x0004 0000 - 0x0007 FFFF (application 2).

I then want to have the boot application (boot switch) determine which is the newest application based on the configurations in sector 2 and 3 and jump to the newest application.

I have the following questions:

1. How do we write an application that can move the instruction pointer to the correct start address and at the same time make sure the active interrupt vectors in the first 256 bytes work correctly. Where to move the instruction pointer should be read from the configurations in sector 2 and 3.

2. How to deploy an application to an address other than 0x0000 0000. When building the .axf and .hex file it is always deployed to address 0 in the Flash, regardless of whether I deploy with FlashMagic or Red Suite. How do I change this starting address?

With respect to loading to another start address I have found a section in the .ld file used by Red Suite which allows to move the start address, but the .hex file (generated with arm-none-eabi-objcopy) still indicate an address starting form 0. Also when I attempt to download using Red Suite with another start address it fails with a message about not being able to download to another start address for ELF files.

I have found several references in boot loaders where it simply says: "Load the application to address xxx", and in IAP I know how to do that, but not from FlashMagic/Red Suite.

If you are not able to help me directly maybe you know of a company which would be able to take on the assignment. I have not been able to find any consulting companies with this level of NXP knowledge. I asked embedded artists, and they suggested this group. Alternatively if there is some literature or code examples which might help I would be very great-full.

Thank you in advance
0 Kudos
Reply
4 Replies

1,205 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ahp on Wed Jul 04 06:00:31 MST 2012
I would just like to add that I have found the solution for the .hex file and why the offset was not correct.

It turns out that changing the .axf file (which apparently is a variation of an .elf file) into a .bin file using objcopy looses the offset. If instead I generate the .hex file directly from the .axf file it includes the correct offset.

Using

arm-none-eabi-objcopy -O ihex ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.hex;

I get the following hex file:

:1030000000800010013100006931000071310000C2
:10301000793100008131000089310000000000009A
:1030200000000000000000000000000091310000DE

and that is much better. ${BuildArtifactFileName} is the .axf file. Before the line wrote

arm-none-eabi-objcopy -I binary -O ihex ${BuildArtifactFileBaseName}.bin ${BuildArtifactFileBaseName}.hex

where first teh ..bin file was generated from the .axf file.

Based on this I now have a functioning prototype, so I will close this thread. Thank you very much for all your help.
0 Kudos
Reply

1,205 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ahp on Tue Jul 03 03:09:17 MST 2012
Thank you very much for your very helpful replies.

I found the part in usb-boot-loader example about starting the user application and updating the interrupt vector, and after remembering to only call SystemInit(); from CMSIS once (I left it in the user application and removed it from the boot switch), then it worked like a charm.

Updating the link script also worked perfectly, thank you. I updated the line:

  MFlash512 (rx) : ORIGIN = 0x3000, LENGTH = 0x3D000 /* 256k */

and it works when I download from Red Suite (via Program Flash). The only problem is that my hex file is still not generated correctly. The first three lines of the generated hex file is:

:1000000000800010453100001D310000213100004A
:1000100025310000293100002D3100000259FEEF8A
:10002000000000000000000000000000313100006E

The build command to generate the hex file is:

arm-none-eabi-size ${BuildArtifactFileName}; arm-none-eabi-objcopy -O binary ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.bin ; checksum -p ${TargetChip} -d ${BuildArtifactFileBaseName}.bin;  arm-none-eabi-objcopy -I binary -O ihex ${BuildArtifactFileBaseName}.bin ${BuildArtifactFileBaseName}.hex

The .axf file has the correct address, as it works when I download it from Red Suite. The .bin file do not work correctly when I download it from Red Suite, so it must be

arm-none-eabi-objcopy -O binary ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.bin

that does not generate the correct offset (or if the .bin per definition do not include to-data, then it is arm-none-eabi-objcopy -I binary -O ihex ${BuildArtifactFileBaseName}.bin ${BuildArtifactFileBaseName}.hex).

Do you know if I need to update my Post build command for generating the .hex file? I know there are some start address parameters for arm-none-eabi-objcopy, but I have not been able to get them to work. Does anyone know what I am doing wrong, and perhaps have an example of how to use the arm-none-eabi-objcopy to get an offset in the origin / start address?

Thank you again for all the valuable help.
0 Kudos
Reply

1,205 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Mon Jul 02 13:22:02 MST 2012
ahp,

You should indeed have a look at the bootloader as whitecoe suggest. That bootloader is part of the examples that are installed as part of the LPCXpresso tools (it is the RDB1768cmsis2_usb_bootloader that is part of the RDB1768cmsis2.zip examples). There is some information in that example on how to setup LPCXpresso (or RedSuite) to create an application that is located at a different address than default 0.

1) see the readme that is part of the example. Per default LPCXpresso tools (and RedSuite) use something called "managed linker script" this will let the tools create the linker scripts for your setup and your selected LPC1xxx memory range. When you unset this option you can create your own linker scripts that let your program start at a different address.
If you do this correctly then the hex file will also show a different address than 0 but you have to unset the managed linker script setting otherwise the tools will keep overwriting your version of the linker script.

Please note that when you want an image in two different places then you will need two different images since there are absolute addresses in these images.

2) see the bootloader example. There is a register somewhere that tells you where the interrupt table is placed. By writing a value into that register you can relocate the interrupt table to a different address.
This is also done by the bootloader.

Regarding to debugging: the debugger assumes a default situation with the image starting at address 0. What I do is to use two different linker scripts: one during development and debugging that allows me to use normal debugging tools and techniques and one that is purely used for a distribution image.

Rob
0 Kudos
Reply

1,205 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Mon Jul 02 03:49:38 MST 2012

Quote: ahp

1. How do we write an application that can move the instruction pointer to the correct start address and at the same time make sure the active interrupt vectors in the first 256 bytes work correctly. Where to move the instruction pointer should be read from the configurations in sector 2 and 3.

2. How to deploy an application to an address other than 0x0000 0000. When building the .axf and .hex file it is always deployed to address 0 in the Flash, regardless of whether I deploy with FlashMagic or Red Suite. How do I change this starting address?



Have you actually looked at the bootloader example for the RDB1768 which ships with Red Suite / LPCXpresso? You might also want to look at the Code Red FAQ on Debugging through a bootloader.

Anyway, there has been a fair amount of discussion on bootloaders previously in the forum if you use the sticky post "*** Searching the LPCXpresso Forum and Code Red's FAQ site ***" to do a search.

And if you are using Red Suite, if you are having tool issues - you could always try pinging Code Red directly...

http://www.code-red-tech.com/support.php

HTH!
0 Kudos
Reply