Add bootloader in LCF

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

Add bootloader in LCF

Jump to solution
3,850 Views
sebasira
Senior Contributor I

Hello to all of you!

 

I'm working with CW v6.1 and MCF51QE. I've develop a bootloader and my firmware. Thery are two separate projects, but they have the same LCF.

 

What I'd like to do is add the bootloader to the application, so I can flash them both only once.

 

First, let's take a look at the LCF:

 

BootLoad     (RX)  : ORIGIN = 0x00000000  , LENGTH = 0x000021F0

myflash      (RX)  : ORIGIN = 0x00002600, LENGTH = 0x00000400

VectorReMap  (RX)  : ORIGIN = 0x00002A00, LENGTH = 0x00000400

code         (RX)  : ORIGIN = 0x00002E00, LENGTH = 0x0001D200

 

Bootload have the code for the bootloader

myflash stores non-volatile variables

VectorReMap is vector table re-allocation

code it has my firmware

 

As said before this is the same in both projects.

 

Then, in the project where I'd like to merge the bootloader, I add the following:

.text_bootload :

  {

  INCLUDE bootloader.bin

  } >> BootLoad

 

 

 

 

The problem is that the original bootloader's startup is at 0x410 (in the original project) but when I add the .bin file, I can see in the memory windows that routines are in another place (0x8EC) and 0x410 is blank. Why's that?

 

I'm breaking my head against the wall!!!

Labels (1)
Tags (3)
0 Kudos
1 Solution
2,481 Views
stanish
NXP Employee
NXP Employee

Hi SebaS,

This is indeed weird issue. I've checked the bootloader.bin where I can see the problem too.

So seems to be a bin file generation issue (you are using pretty old version of CodeWarrior v6.1). The srecord does not match with the binary file. I'd suggest to try to use a s-record converter to generate .bin out of bootloader.s19

You can use e.g. decoder tool. S-Record, Intel Hex and Binary Files | MCU on Eclipse

Anyway I'd recommend you to install the latest CodeWarrior classic available -> CodeWarrior for MCUs v6.3 (classic)

CodeWarrior for Microcontrollers (Classic IDE) - RS08/HC(S)08, ColdFire V1 Product Summary Page

Hope it will help,

Stan

View solution in original post

0 Kudos
20 Replies
2,481 Views
trytohelp
NXP Employee
NXP Employee

Hi,

The INCLUDE  command let you include a binary file in the output file.

      INCLUDE filename

If you include the bootloader directly using the INCLUDE instruction:

      INCLUDE bootloader.bin

for my understanding it should work.

I found some info about bootloader here:

AN2295: http://cache.freescale.com/files/microcontrollers/doc/app_note/AN2295.pdf

            11 Merging Bootloader and Application images

Forum: https://community.freescale.com/message/44789#44789

Regards

Pascal

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Hello Pascal!

I've seen AN2295 some time ago and I forget about it. According to the last pages of the AppNote, the merge is not the way I want it to be, instead it has a Windows application that merge two s19 files (one should be the bootloader and the other, the firmware itself).

What you suggest on your previous post is to put the INCLUDE bootloader.bin alone, outside any segment definition? I haven't try that, but I guess it is a good option

I'll try that and let you know.

Best regards!

SebaS

0 Kudos
2,481 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

INCLUDE is a Codewarrior linker command which can be used in any programmer that supported CW. PE-Micro Multilink supports this too.

Attached is a example I just made under CW6.3. in lcf file, there is a line of code " INCLUDE code.bin ". after compiling code, you can see code.bin is included in generated s19 file, starting from 0x00000410.

0 Kudos
2,481 Views
sebasira
Senior Contributor I

I still can not accomplish what I want. I do as you suggested and then compare the s19 files of the bootloader alone and the app+bootlaoder. As you would see, the bootloader starts at 0x410, but when merging with INCLUDE the same code that the bootlaoder has at 0x410 it has it some bytes after 0x8E0

Bootlaoder alone.s19:

S321000004104FEFFFE848EF430300044FF900800EF02C7C000000004E5600004BF9CE

App + Bootloader.s19:

S321000008E000002D2800000410000000FC4FEFFFE848EF430300044FF900800EF025

I'l attach:

- the LCF file (where I put the include)

- the bootlaoder.bin

- the bootloader.s19 so you can compare it

If you need anything else, please let me know!

Thank you for helping me!

Best regards,

SebaS

0 Kudos
2,481 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

can you please send me the entire project folder in zip? i need reproduce it on my side.

0 Kudos
2,481 Views
sebasira
Senior Contributor I

I'm sorry for the delay, but here it is.

Well, as I'm not authorized to share the complete project, I've made a blank project with the same LCF. For the problem is the same.

First, let me introduce you a little.

As you would see, the first to run is the chkBootloader routine. This is a simple  jump to the bootloader address (located at 0x410, or at least that's where it should be). The code executed there belongs to bootloader.bin. Basically, it tests if the condition to enter bootloader is set. If not, it should continue executing the user code. For the bootloader, 'continue executing the user code' means to jump to StartupEntry, inside VectorReMap.c.

As mentioned before, the problem is that the bootlaoder is not at 0x410. I also try a jump to 0x8XX (the value from 2 post ago) and nothing happens.

If you would like to get to know the bootloader, search the web for zmfbootloader. It's a serial bootloader for MCF51QE. I grab it and only modify the LCF file, wich is exactly the same as the one in the attached project, except for the INCLUDE statement.

0 Kudos
2,481 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

I checked your project bootloader.bin with UltraEdit, this is the content:

bootloader_bin.JPG

in you lcf file, you use INCLUDE command to include the bin content start from 0x410. after build the project, it insert to 0x410 well. see the generated project.abs.s19 file:

app+bootload_s19.JPG

so we can say that INCLUDE command has performed the function well.

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Hello again Jun!

Well, and how do you thnik I can solve my problem? Should I insert the bin file in another location so it would be EXACTLY as in the bootloader project?

Thanks!!!

SebaS

0 Kudos
2,481 Views
stanish
NXP Employee
NXP Employee

Hi sebasira,

The problem is probably related to the fact bootloader.bin includes some data prior to the address 0x410.

This is visible in bootloader.s19 which starts at adress 0x0000_0000. These are probably interrupt vectors starting at 0x0 to 0x198.

I'd suggest you to manually cut off the interrupt vectors (in case you don't use interrupts in the bootloader) from bootloader.bin file (I modified the file using hex editor - result is attached) and then try to rebuild/relink the project using the updated binary file.

Please make sure your app. does not contain any object placed into .BootLoad section because these will be placed at the beginning of memory segment "BootLoad". Your bootloader might be placed at different address in this case.

Regards,

Stan

2,481 Views
sebasira
Senior Contributor I

Stan!

We are almos there!!! So close!!!

I use the bin file you provide. If the condition to enter the bootloader is not met then it execute the user code and works like a charm. But If I'd like to enter in bootloading mode, then it crash. So I decided to step the ASM code until it crash and I've notice something very very odd that is causing the problem: INVALID OPCODE at assembler window.

So I load the bootloader alone to FLASH and then in memory window go to address 0x508 (where the invalid opcode was) and this is what I've got:

@0x508: 00 80 00 00 07 00 46 C0

Then, I load the code with the merged bin and at the same address, I've got:

@0x508: 00 80 00 00 00 00 05 0C 00 00 00 FC 07 00 46 C0


Notice that 8 bytes (in red) are added before what should really be there and that is the INVALID OPCODE. I open the bin file you provide, with and Hex editor, and find out that those byte are part of the bin. (If you'd like to open the bin file, go to address $508 - $401 = $F8 and there you'll see it).

Those bytes seems like some "mark", pointing to 0x50C. Then I open the bootloader S19 file and found out:

S321000004F04FF900800EF02C7C000000004E5600004BF90080000440C00080000090

S3210000050C070046C061FF0000009661FF0000005C717C008041FA0004D1FC000095

What's going on here?

I hope you can help me. Thank you very much!!!

Best regards,

SebaS

0 Kudos
2,482 Views
stanish
NXP Employee
NXP Employee

Hi SebaS,

This is indeed weird issue. I've checked the bootloader.bin where I can see the problem too.

So seems to be a bin file generation issue (you are using pretty old version of CodeWarrior v6.1). The srecord does not match with the binary file. I'd suggest to try to use a s-record converter to generate .bin out of bootloader.s19

You can use e.g. decoder tool. S-Record, Intel Hex and Binary Files | MCU on Eclipse

Anyway I'd recommend you to install the latest CodeWarrior classic available -> CodeWarrior for MCUs v6.3 (classic)

CodeWarrior for Microcontrollers (Classic IDE) - RS08/HC(S)08, ColdFire V1 Product Summary Page

Hope it will help,

Stan

0 Kudos
2,481 Views
sebasira
Senior Contributor I

The BIN generated from the S19 worked just fine!

If you can't provide me a solution to CW v6.1/v6.3 I guess I'll have to keep using the burner.exe as described on the link you provide. I'll keep this thread open for a few days. After that if no solution to CW is found, I'll mark you previous post as the correct answer because it really is a solution to my problem!

Best Regards!

SebaS

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Stan!

I've installed CW v6.3 and I opened the bin file with the hex editor and it has this same issue, but in another address... I don't know how to explain it, I think it is better for you to see it, but I can tell that at address $FC those 8 bytes are also added but the other bytes 00 07 46 are at some bytes before. I'll attach the s19 and bin from CW v6.3, inside the rar file.

Can you confirm if CW v6.3 indeed has the same issue with the bin generation?

With the burner.exe, the .bin generated from .S19 is totally different and 'seems' fine. But I can not test it right now, because I'm not phisically where the device is, I'm controlling the PC remotely and I can not "push" the button to enter bootloading mode. Once I'm there I'll test it and post again.

Thanks for giving me a hand with this!!

SebaS

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Hello!

About the difference between the S19 file and the BIN, maybe they are not extacly the same because I was doing some changes from psot to post, while trying to solve this. So, I attached a rar file containing the S19 and the BIN file generated upon the same build.

I'll have to check, but I think I also have CW v6.3 installed because some time ago I need to test a project wich requiered that version of codewarrior. If it is not installed, I will install it and try with it.

Now, I'll test the burner.exe from my CW v6.1 installation an see what happen. I'll let you know how this goes.

Thank you very much!

SebaS

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Hello Stan!

Thanks for your input! I think the same way about "the bootloader includes some data prior to the address 0x410.". I'd be very glad to try what you said, but I can't seem to find the attachment. Could you upload it again?

I don not have an hex editor, I'll get one if this change works.


Thanks one more time!


Best Regards,


SebaS


EDIT:

WOW! Now it has magically appear on your post. No need to upload it again.

0 Kudos
2,481 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

this is regarding the bootloader usage, pls summit a SR to Freescale support team.

0 Kudos
2,481 Views
sebasira
Senior Contributor I

Hi Jun!

I don't know what a SR is. Can you tell me?

But I was hoping someone here, in the community can help me or guide me to achieve what I want to to

Thanks!

SebaS

0 Kudos
2,481 Views
trytohelp
NXP Employee
NXP Employee

Hi SebaS,

SR is a Service Request.

The Service Request is the system used by Freescale Support team to investigate a problem.

You can post it via the Freescale Web site.

  - Go to following URL: http://www.freescale.com/TechSupport

  - Click on Create a Service Request. You will come to a login page.

  - If you are already registered with Freescale (using the Forum, subscribed to newsletter, ...) use your Freescale login and password. Otherwise, Click on "Register Now" to get registered.

  - You can submit your request through the web from there.

Regards

Pascal

0 Kudos
2,481 Views
sebasira
Senior Contributor I

No problem Jun!

I'll send it in a couple of hours (I don't have it right here, is in another office)

0 Kudos
2,481 Views
trytohelp
NXP Employee
NXP Employee

Hi Seba,

I don't have lot of experiences with merging application.

INCLUDE feature can be used inside or outside a section.

However most of time I see the bootloader merging code was inside sections.

Pascal


0 Kudos