Boot-loader, Application and Start-up code

cancel
Showing results for 
Search instead for 
Did you mean: 

Boot-loader, Application and Start-up code

1,214 Views
quynguyen
Contributor I

Hello everyone,

I read AN4723 and built separately bootloader and application in 2 projects for S12ZVML. Both of them have start-up Code.

In Linkerfile of bootloader I added application, i.e HEXFILE Application.sx

In source code of bootloader I let the µC jump to the application.

 

If the pointer APPLICATION_START_ADD points to main function of application, everything works well.

If the pointer APPLICATION_START_ADD points to the beginning of flash of application, it jumps to Start-up Code of application. After executing function DoZeroOut, it returns to the programm of bootloader (line FF8018). The function DoCopyDown or main of application below will not be executed.

152649_152649.pngpastedImage_2.png

Because the address of the main function of application will be changed from time to time, I'm thinking about a solution, i.e.:

- Define fixed address for main function of application. Then jump from bootloader to this address

- Somehow disable Start-up of application. Jump from bootloader to the beginning of flash

- Somehow let start-up code of application execute completely.

 

Can someone please give me an idea to solve this problem.

Thank you so much.

Labels (1)
6 Replies

202 Views
RadekS
NXP Employee
NXP Employee

Hi Quy,

You are right, the linker place DoZeroOut() function as the first object in the flash by default.

Unfortunately, I didn’t found till now any direct way how to simple place _Startup code on Flash start address. I suppose that there is some nice solution, but I am not sure now where.

I created “simple” workaround:

I just placed additional code at Flash start address which contains just jump to the _Startup entry point.

This solution (rather say workaround) takes 4 bytes from Flash and 1.5 bus cycles of execution time.

Please look at the example of modifications in attached application prm linker file.

Note: I didn’t test it with bootloader yet, I just checked generated *.sx file. Please take it as a source for your inspiration.

Note: I suppose that Application never ends (except reset). In opposite side, we have to use JSR instruction (0xBB) instead JMP for stacking return address and we cannot reuse Bootloader RAM content in the application.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

202 Views
xiaohui200808
Contributor III

Hi

    I am also debug the S12ZVC Bootloader ON CANBUs. But my applications always run wrong when loaded into MCU by CAN. Could you send me some  reference code,Please!

0 Kudos

202 Views
RadekS
NXP Employee
NXP Employee

Hi xiaohui,

Did you implement one of the proposed modifications (in prm or start12z file) in your application project?

See attached example codes.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

202 Views
quynguyen
Contributor I

Hi Radek,

Thank you for your reply.

I did change startup code a little bit with function prototype and _Startup function is always at the top of Flash.

pastedImage_6.png

By the way, could you please tell me any way to calculate the length of code in linker file and then insert to ROM ?

Now I'm using

      APP_CODE_LENGTH = READ_ONLY 0xFFCFFC TO 0xFFCFFD FILL 0x4F 0xFC;

I just want to let the linker find the actual code size instead of using fixed value 0x4FFC here.

0 Kudos

202 Views
RadekS
NXP Employee
NXP Employee

Hi Quy,

You are right, you found it (change order of DoZeroOut(), DoCopyDown() and _Startup() functions in starts12z.c file).

I tested this approach yesterday as first, but it didn’t work on my side. Now it works.

Thank you.

Idea: We could create dummy function and manage that they will be placed as last and store the pointer to this function into some place in the flash.

I created the dummy.c (and dummy.h) file with dummy_func() function. After that, I changed the link to order that dummy.c is linked as last.

dummy func.png

In prm file, we could define vector at the specific address which will point to this function. For example:

VECTOR ADDRESS 0xFFF7FD dummy_func

Note: place for this vector (0xFFF7FD to 0xFFF7FF) has to be excluded from ROM segment.

What is not solved yet?

  1. By default, the DEFAULT_ROM is placed prior COPY segment. And modifying this order do not work on my side yet.
  2. We could add offset to function address (for example VECTOR ADDRESS 0xFFF7FD dummy_func OFFSET 6), but it seems that this offset cannot be negative. Therefore, we cannot subtract flash base address for getting code size.

Attached is example project with comments.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

202 Views
RadekS
NXP Employee
NXP Employee

Hi Quy,

BTW: This points me to the _startupData structure.

It seems that _startupData.toCopyDownBeg contains

4 bytes with number N of CopyDown bytes

3 bytes for RAM address

N bytes of data

4 bytes of zeros

So we could use the pointer to _startupData.toCopyDownBeg + 11 bytes + N bytes – Flash base address and this way we could get the length of used Flash.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos