AnsweredAssumed Answered

Custom bootloader application for the MPC5604B

Question asked by Markus Ren on May 17, 2014

Hi,

 

I'm currently working on a custom bootloader application for the MPC5604BxLQ microcontroller,

which is on the TRK-MPC5604B Board.

As an IDE I am using Codewarrior for MCU Version 10.5 on Windows 7 64-bit professional.

 

The goal of the bootloader application is to be able to store up to 3 different applications in the

codeflash (512KB CodeFlash), that can be executed by the bootloader.

The layout of the codeflash should look like this in the end:

 

Memory_segments_in_codeflash.PNG.png

 

I limit the application size at 110KB for the moment (an AppSlots is about 125KB).

 

So far I am able to receive arbitrary binary files (UART) and write the binary data to a

selected AppSlot with its starting address. I verified the written data by using the memory

browser while debugging the bootloader application.

 

 

Furthermore I created an application, that does some LED blinking by using an

interrupt timer (PIT) or by simply polling a timer (decided by a define directive).

Let's call this application the test-app.

 

 

-------------------------------------------------

Some background information:

-------------------------------------------------

During my bachelor thesis I implemented a bootloader application for the STM32F4-microcontroller

by STMicroelectronics. Back then I used an application note, as

well as an example project regarding In-Application-Programming by STMicroelectronics as a starting point.

 

 

In the end it came down to this:

 

1) For the test-app:

- tell the linker to build for the starting address of the intended AppSlot

(back then it meant to change the linker address from 0x08000000 to 0x08010000 in the IDE CoIDE)

- right after entering the main routine of the test-app, offset the interrupt vector table to 0x08010000

 

 

2) For the bootloader (the actual jump to the test-app):

- disable all interrupts

- jump to the test-app by doing the following routine (pretty much taken from the example by ST)

 

// Prepare the Jump_To_Application()-function

id (*Jump_To_Application)(void);

uint32_t JumpAddress = *(volatile uint32_t *)(APP_SLOT_START_ADDRESS + 4);

Jump_To_Application = (void(*)(void))JumpAddress;

// Init test-app's Stack Pointer

__set_MSP(*(volatile uint32_t *) APP_SLOT_START_ADDRESS);

// Jump to the test-app

Jump_To_Application();

 

 

(to this day I am not entirely sure why the JumpAddress is offset by 4)

 

 

// __set_MSP(...) was a library function

 

/** \brief  Set Main Stack Pointer

  This function assigns the given value to the Main Stack Pointer (MSP).

  \param [in]    topOfMainStack  Main Stack Pointer value to set

*/

static __INLINE void __set_MSP(uint32_t topOfMainStack)

{

  register uint32_t __regMainStackPointer     __ASM("msp");

  __regMainStackPointer = topOfMainStack;

}

 

 

--------------------------------------------------------------------------

 

 

With the background of my bachelor thesis I assumed that implementing a bootloader application on this specific controller

would not be that different.

 

------------------------------------------------------------------------------------------------------

So right now I need to solve the following two tasks for this project:

------------------------------------------------------------------------------------------------------

 

1) Alter and build the test-app for a specific AppSlot (let's say AppSlot 1).

 

2) Launch the flashed test-app using the bootloader.

 

-------------------------

What I did so far:

-------------------------

regarding 1)

- Setting the linker to build the test-app for AppSlot 1:

I looked at the linker control file (.lcf), which is provided by creating a project with the project wizard of codewarrior.

In particular the one for running an application in FLASH. In the memory section, I offset every entry by 0x00020000.

The resulting file is shown in attachment 1.

Furthermore I offset the "ROM Image Address" and "RAM Buffer Address of ROM Image" by 0x00020000 as well.

The result can be seen in attachment 2.

The test-app built fine with these settings and a binary was output.

 

 

- offsetting the interrupt vector table:

I could not find anything on this in the reference manual, so I don't know how this would be done.

But I'm fairly sure that something has to be done about this, as the vector table of the bootloader application

needs to be seperate of the one of a flashed application.

 

 

 

 

regarding 2)

- The actual JumpAddress is not really clear to me.

   Is there an offset needed relative to the starting address of AppSlot 1?

  

- Furthermore I'm not entirely sure on why or where the stack pointer is moved, let alone on how one would do it in this case for this controller.

  

 

 

It may very well be that I'm completely overlooking something or doing something wrong.

In general the flashed applications need to be fully independant of the bootloader once they have taken over.

 

I am asking these questions as I can't progress.

I could not find application notes or other documentation on this matter regarding this controller.

 

 

Some help would be greatly appreciated!

 

BTW: I'm doing this project as part of my master degree (not the actual thesis). Furthemore this is my first project on a freescale controller, so I don't consider myself an expert.

Original Attachment has been moved to: attachment_1_MPC5604B_FLASH_AppSlot_1.lcf.zip

Outcomes