Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello,

I got a question about the configurations for HWCON and SWCON. SWCON resets after a PORST as menitoned in the manual 11-69 and copies the content from HWCON.
But when a system reset is made the SWCON is read. instead of HWCON.

I want to use the ABM mode after a system reset. I am setting the abm mode with the function from the xmc4_scu.c

/* API to program a new device bootmode */
void XMC_SCU_SetBootMode(const XMC_SCU_BOOTMODE_t bootmode)
{
SCU_GENERAL->STCON = (uint32_t)bootmode;
}


when i read the SWCON it is set to ABM0 mode.

I need to define the ABM Header now. ( I took part of user OMR example)

abm0[0] = 0xA5C3E10F; // abm magic key
abm0[1] = 0x0C004000; // BOOT_START_ADDRESS start address of Usercode
abm0[2] = 0xFC000; // Application length ( 0x0C100000 - 0x0C004000)
abm0[3] = crc32Gen((unsigned int *)0x0C004000, 0xFC000); // CRC32 for application length
abm0[4] = crc32Gen(abm0, ABM_HEAD_SIZE-4); // CRC32 for above 4


abm0[4] is the crc32 of abm0[0], abm0[1], abm0[2] and abm0[3] right?

now I need to write the header to the address 0x0c00ffe0, right?

Flash002_WritePage (0x0c00ffe0, abm0);


is there an internal crc calculation for the application?
0 Likes
1 Solution
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
shenj wrote:
Hello Travis,
Great job, could you please write an application note about this? Could you please create some figures for this application note. Many thanks. Thanks also to OMR.

Questions:
(1) Reference Manual Page 2608 XMC4500 : VMA = LMA & 0x04000000
Is this not the VMA = LMA | 0x04000000 ? I mean VMA and LMA has an address offset of 0x04000000.
(2) Where are the link symbols saved in Flash? For example, __initial_sp. I know that &__initial_sp gives the correct address in PSRAM (specified by linker script). But where is __initial_sp in flash saved ( i mean in the .hex file or the .bin file)?



Hi,

Yes, I will do that. And thanks for your feedback.

BR
Travis

View solution in original post

0 Likes
16 Replies
User6793
Level 4
Level 4

unsigned int Booter::crc32Gen(unsigned int *memPtr, unsigned int size)
{
unsigned int result = 0;
#if (!IS_BOOTER)
crc32Init();
crc32Chunk(memPtr, size);
result = crc32Res();
#endif
return result;
}

void Booter::crc32Init(void) // HW CRC generator, init for chunk
{
#if (!IS_BOOTER)
SCU_RESET->PRCLR2 = SCU_RESET_PRCLR2_FCERS_Msk;
while((SCU_RESET->PRSTAT2 & SCU_RESET_PRSTAT2_FCERS_Msk))
;

FCE->CLC = 0;
while((FCE->CLC & FCE_CLC_DISS_Msk))
;

FCE_KE0->CFG = 0;
FCE_KE0->CRC = 0;
#endif
}

void Booter::crc32Chunk(unsigned int *memPtr, unsigned int size) // HW CRC generator, chunk data
{
#if (!IS_BOOTER)
size >>=2; // /4 since memPtr is a word pointer

for (uint32_t i=0; i FCE_KE0->IR = *memPtr++;
}
#endif
}

unsigned int Booter::crc32Res(void) // HW CRC generator, final chunk result
{
unsigned int result = 0;
#if (!IS_BOOTER)
result = FCE_KE0->RES;
result = FCE_KE0->RES; // must be read twice, or else the result is wrong!
#endif
return result;
}


🙂
0 Likes
User6793
Level 4
Level 4
0 Likes
Not applicable
Thanks OMR. Sorry for the late reply, I was on vacation 🙂

Before I proceed I want to explain my reason. I want to use the ABM Header because I'm still working on my bootloader. I'm using a XMC4500 (with Dave4) but I cant use the ASC Bootloader because the pins
which are needed are used for something else. Therefore I have to find another solution. The only solution is now to have a Bootloader starting at 0x0C000000 which jumps to the application
after receiving and saving the data of the application. The receiving and writing of the data works. I've check the memory with the J-Mem tool. The bootloader is communicating with my selfwritten
windows application.

My only problem is I cant jump to the application. I've tried it with your code and couldnt get it to work.

PPB->VTOR = APP_START_ADDRESS;
asm(
"ldr sp, [%0]\n\t"
"ldr r0, [%0, #4]\n\t"
"bx r0"
:
: "r" (APP_START_ADDRESS)
:);


I guess I need the ABM and set the SWCON to ABM and then do a system reset.
I'm calculating and writing the CRC checksums only once (after a flag has been set) AND before I write anything in the desired Code range or into the last 32 Byte of the first 64KB sector.
Is that right?

I can calculate the CRC Checksums. But I'm not sure if the results are valid. I get the Checksum 0 for both the abm0[3] CRC32 for application length and abm0[4] CRC32 for above 4.

I used the start address for calculating the CRC-32 for the application. The application should start at 0x0C080000 and is defined as APP_START_ADDRESS.
The size therefore 0x0C100000 - 0x0C080000 = 0x80000

with crc32Gen(APP_START_ADDRESS, 0x80000) I get the crc of 0

ABM Header with the define ABM_ADDRESS 0x0C00FFE0
For the Header the size is 0x0C010000 - 0x0C00FFE0 = 0x20

with crc32Gen(ABM_ADDRESS, 0x20) I get the crc of 0.

Why ist that?

I've also tried it with Travis is suggestion

/***********************************************************
* Coding supply by verification team
*
***********************************************************/
uword crc_gen (uword *data, uword size)
{
uword crc = 0xFFFFFFFF;
for(uword i=0; i uword word = *(data+i);
uword feedback =
((crc & (1 << 31)) ? 1 : 0) ^
((crc & (1 << 30)) ? 1 : 0) ^
((crc & (1 << 29)) ? 1 : 0) ^
((crc & (1 << 27)) ? 1 : 0) ^
((crc & (1 << 26)) ? 1 : 0) ^
((crc & (1 << 24)) ? 1 : 0) ^
((crc & (1 << 23)) ? 1 : 0) ^
((crc & (1 << 21)) ? 1 : 0) ^
((crc & (1 << 20)) ? 1 : 0) ^
((crc & (1 << 19)) ? 1 : 0) ^
((crc & (1 << 15)) ? 1 : 0) ^
((crc & (1 << 9)) ? 1 : 0) ^
((crc & (1 << 8)) ? 1 : 0) ^
((crc & (1 << 5)) ? 1 : 0);

crc = ((word ^ ((crc & 0x7fffffff) << 1)) & 0xfffffffe) | (feedback ^ ((word & 1) ? 1 : 0));
}

return crc;

}


uword Calculate_WordSize (uword start, uword end)
{
uword size;

size = (end-start);
size = size >> 2;

return size;
}

With that I dont get zeros as a result. But its not working either 😞
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

I am making an example on this and will let you know soon.
0 Likes
Not applicable
I am looking forward to this example. I am also interested in how to set up the linker script for two co-existing firmwares? And if one failts, the second will be used for boot?
0 Likes
User6793
Level 4
Level 4
You might find something useful in this thread: https://www.infineonforums.com/threads/1854-Bootloader-running-from-Flash
Pay especially attention to post #20 and #42-#45
And this thread: https://www.infineonforums.com/threads/3276-Enable-fallback-Alternate-Boot-Mode-%28ABM%29

I'm under the impression that you are using ABM for a booter and an APP?
I don't think that is what is was intended for. It was ment for a fallback copy of the booter itself. The APP can reside at any address.
The ABM system only works on the first 2 64Kbyte chunks of the FLASH.

Before you start using ABM, you must have the booter->APP jump mechanism working.
The APP must contain its own 'load image' starting with a complete vector table and CPU set-up.
If it still fails, it could be because of interrupts used by the booter is not disabled before the jump. If not, the IRQ service routine is not found after the VTOR register is reloaded.
0 Likes
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi Guys,

This Alternate Boot Mode (ABM) with XMC4500 relaxkit consist of 2 parts the Application software and the Loader software. Please import these 2 project into your DAVE4.
Overview of these project are mentioned in this thread and they can also be found in the readme file of each individual project.

To test this ABM example, please program your XMC4500 with the Application software. Then exit the debugger and reset the XMC4500. You should see the LED1 and LED2 turn ON.
Pressing the button 1 will cause it to go into ABM which you will see the LED1 and LED2 flashing.


Overview of the Loader Software

The whole intention of the loader software is to be located in memory location 0x080C0000 (can be decided by user) and to perform a firmware update when it is necessary during the
run time of the application software.

In order to have the CPU jump to the allocated memory location for firmware update, the application software has to create a correct Alternate Boot Mode (ABM) Header with the start
address of the loader software (see XMC4000 user manual) and eventually perform a reset to ABM boot mode.

There are 2 Alternate Boot Mode Header and they are reserved in the below fixed address.
ABM0 address (0x0800FFE0)
ABM1 address (0x0801FFE0)

For this example, successful entry into the Loader software will be represented by flashing of LED1 and LED2 instead of a firmware update. To EXIT this Loader software to
Application software press BUTTON1.

The loader software also include a calculation or preview of the ABM header. After you are very sure that the Loader software is 100% stable you can merge this Loader
software with the Application software to form a single project.


Questions and Answer

1. How to map this Loader Software to memory location 0x080C0000?


Edit the "linker_script.id" file as shown below ..........

FLASH_1_cached(RX) : ORIGIN = 0x080C0000, LENGTH = 0x100000 /*Update_ABM: This code is located in 0x080C0000*/
FLASH_1_uncached(RX) : ORIGIN = 0x0C0C0000, LENGTH = 0x100000 /*Update_ABM: This code is located in 0x080C0000*/



2. How to configure the ABM header?

This function create a preview of the ABM header. Please take a screen shot of the "PSRAM_Header", which is needed to be
hard coded into the application software.

void BL_Checksum_PSRAM_calc(void)
{
PSRAM_Header->MagicKey = MAGIC_KEY;
PSRAM_Header->StartAddress = 0x080C0000; // Update_ABM: Ensure that this loader start address is correct
PSRAM_Header->Length = 0xFFFFFFFF;
PSRAM_Header->ApplicationCRC32 = 0xFFFFFFFF;
PSRAM_Header->HeaderCRC32 = BL_CalculateHeaderCRC32(PSRAM_Header);
}


3. How to EXIT from Alternate Boot Mode to Normal mode (Application Software)?

You can make use of this function with SW_CONFIG_Normal ................

void Reset_to_NormalMode(void)
{
/* Clear the reset cause field for proper reset detection of the ssw */
SCU_RESET->RSTCLR = 1< /* Set ABM0 as boot mode in SWCON field of STCON register */
WR_REG(SCU_GENERAL->STCON,
SCU_GENERAL_STCON_SWCON_Msk,
SCU_GENERAL_STCON_SWCON_Pos,
SW_CONFIG_Normal);
/* request system reset */
PPB->AIRCR = 1 << PPB_AIRCR_SYSRESETREQ_Pos |
0x5FA<}

4. How can I combined this loader software with my application software to form a single project?

As we know that the Application software begins execution in location 0x08000000 and the loader software is located in 0x080C0000, hence we can create a single project which
consist of both softwares. This can be done with the follow steps.

Step 1: Request the compilier to generate a BIN file.

Step 2: Convert the BIN file to a C source code. You can use this tool to export BIN file to a C file
http://www.hexworkshop.com/

Step 3: Place this C source code into the Application project


Overview of the Application Software

The Application software is located in address 0x0800 0000. Within this software it contains the Alternate Boot Mode Header and also the application software which basically
turn ON LED1 and LED2 indicating that this is in the normal boot mode. To get into Alternate Boot Mode, press BUTTON1 which will do a reset to ABM and you can see both the LED1
and LED2 are blinking which indicate successful entry into Alternate Boot Mode.

Do note that the loader software (loader_0x80C0000.c) is also integrated with the Application software to form a single project.

Questions and Answers

1. How to get into Alternate Boot Mode?

Step 1:
Create an ABM header with the required Start Address and also a valid CRC value of the ABM header.

Step 2:
Map this ABM header to ABM0 address (0x0800FFE0) or ABM1 address (0x0801FFE0)

Step 3:
Perform a reset with "SW_CONFIG_ABM1"

void Reset_to_ABM1(void)
{
/* Clear the reset cause field for proper reset detection of the ssw */
SCU_RESET->RSTCLR = 1< /* Set ABM0 as boot mode in SWCON field of STCON register */
WR_REG(SCU_GENERAL->STCON,
SCU_GENERAL_STCON_SWCON_Msk,
SCU_GENERAL_STCON_SWCON_Pos,
SW_CONFIG_ABM1);
/* request system reset */
PPB->AIRCR = 1 << PPB_AIRCR_SYSRESETREQ_Pos |
0x5FA<}



2. How to map the ABM header to the memory address?

Step 1:
Section needs to be created as shown below ..........

static const ABM_Header_t __attribute__((section(".flash_abm"))) // Update_ABM: Check the script file
ABM1_Header = {
.MagicKey = MAGIC_KEY,
.StartAddress = 0x080C0000, // Update_ABM: Take care of the startup address
.Length = 0xFFFFFFFF,
.ApplicationCRC32 = 0xFFFFFFFF,
.HeaderCRC32 = 0x2008751C // Update_ABM: Take care of the CRC value
};

Step 2:
Edit the linker_script.id file as show below.........

.abm ABSOLUTE(0x0801FFE0): AT(0x0801FFE0 | 0x04000000)
{
KEEP(*(.flash_abm))
} > FLASH_1_cached


3. How to map the array in "loader_0x080C0000.c" to address 0x080C0000?

Step 1:

Section needs to be created as shown below ..........

const unsigned char __attribute__((section(".abm_rawData"))) rawData[3788] =
{

Step 2:

Edit the linker_script.id file as show below.........

.abm_rawData (0x080C0000):
{
KEEP(*(.abm_rawData))
} > FLASH_1_cached
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi OMR,

I also would like to thank you for your contribution and sharing with regards to this ABM topic.

BR
Travis
0 Likes
Not applicable
Hello Travis,
Great job, could you please write an application note about this? Could you please create some figures for this application note. Many thanks. Thanks also to OMR.

Questions:
(1) Reference Manual Page 2608 XMC4500 : VMA = LMA & 0x04000000
Is this not the VMA = LMA | 0x04000000 ? I mean VMA and LMA has an address offset of 0x04000000.
(2) Where are the link symbols saved in Flash? For example, __initial_sp. I know that &__initial_sp gives the correct address in PSRAM (specified by linker script). But where is __initial_sp in flash saved ( i mean in the .hex file or the .bin file)?
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
shenj wrote:
Hello Travis,
Great job, could you please write an application note about this? Could you please create some figures for this application note. Many thanks. Thanks also to OMR.

Questions:
(1) Reference Manual Page 2608 XMC4500 : VMA = LMA & 0x04000000
Is this not the VMA = LMA | 0x04000000 ? I mean VMA and LMA has an address offset of 0x04000000.
(2) Where are the link symbols saved in Flash? For example, __initial_sp. I know that &__initial_sp gives the correct address in PSRAM (specified by linker script). But where is __initial_sp in flash saved ( i mean in the .hex file or the .bin file)?



Hi,

Yes, I will do that. And thanks for your feedback.

BR
Travis
0 Likes
Not applicable
Whats if the program is booted from ABM0 or AMB1, and then these is power down ? After 1 hour, power is on, the MCU should boot again. From where? a normal boot or a AMB boot?
0 Likes
User6793
Level 4
Level 4
In order for the ABM boot mode to kick in at Power on, the following criteria must be set:

1. Boot mode must be BMI: TCK & TMS on the CPU pulled high
2. The CPU BMI OTP word must have been programmed to ABM (see previous thread reference)

Note that if the ABM CRC check fails, the ROM bootloader will not start the CPU, but usually connecting a JTAG/SWI dongle takes the CPU into Normal boot option so one can recover.
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
shenj wrote:
Whats if the program is booted from ABM0 or AMB1, and then these is power down ? After 1 hour, power is on, the MCU should boot again. From where? a normal boot or a AMB boot?


It will be in normal mode, until you trigger a reset to ABM.
0 Likes
Not applicable
The ABM Headers ( which can be located at one of the two memory places) are also located in the flash space for .text, what if the .text of a firmware is so large that the space of flash_abm is partially or completely occupied by the .text? I think, the linker script needs to be adapted.
0 Likes
Not applicable
hi everyone...i am new to his forum. As per my experience Before you start using ABM, you must have the booter->APP jump mechanism working.The APP must contain its own 'load image' starting with a complete vector table and CPU set-up.
If it still fails, it could be because of interrupts used by the booter is not disabled before the jump. If not, the IRQ service routine is not found after the VTOR register is reloaded.

board assembly
0 Likes
90670
Level 4
Level 4
25 replies posted 25 sign-ins 10 questions asked

Hi everyone, is the CRC HeaderCRC32 in ABM1 same as ABM0 in the default example USBD_MS_BOOTLOADER_IAP? If not how can I calculate CRC header for ABM1? I not an expert about this. Hope to here from you guys.

0 Likes