Include some compiled code (.s19/.bin?) in a project using LCF

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

Include some compiled code (.s19/.bin?) in a project using LCF

Jump to solution
3,215 Views
FridgeFreezer
Senior Contributor I

Setup: MCF52259, CW7.2.

 

Following on from https://community.freescale.com/message/90348#90348  it looks like we really need to split our bootloader code from our main application code so that the two are separate and one doesn't affect the other (and it seems like good practice to keep them separate anyway).

 

So, what I believe is needed is:

- Create a new project with JUST our bootloader code (have now done)

- Compile the bootloader into an executable form (.s19 seems to be the standard output, .bin just seems to be an .s19 minus the "S")

- In our main project, configure the LCF to put this executable code into the correct place & ensure it's called first at startup.

 

I have spent all day reading threads about including files in LCF's in various ways, and although I think I can see how to include a random data file (EG a picture) into the LCF, but I cannot find any mention of how you can include a compiled .s19 in such a way that it is treated as executable, and the main project compiles/debugs happily with the lower sector of flash occupied by this "unknown" block of code.

 

This thread asks a similar question about how to create the executable in the fist place, but objcopy seems like a workaround rather than a solution:

https://community.freescale.com/message/62440#62440

 

This thread has an answer from CrasyCat which seems to use .elf / .a files, I can't see a way to generate these or how they work:

https://community.freescale.com/message/16403#16403

 

I have seen mention of building a project as a static library but no explanation of what happens when you do this / how it works.

 

This post seems to come quite close but doesn't go into much detail:

https://community.freescale.com/message/37148#37148

 

There seem to be little pieces of this jigsaw puzzle everywhere, but not quite enough for me to complete the picture :smileytongue:

Labels (1)
1 Solution
1,208 Views
stanish
NXP Employee
NXP Employee

Hi,

 

You can use INCLUDE linker command as mentioned by kef.

If you use CodeWarrior IDE project you need to:

 

1) add your binary file (e.g. mybinary.bin) into the project and make sure the file extension is defined as a resource file in "File Mappings" (ALT+F7 -> Target -> "File Mappings" -> "Flags" -> "Resource File"). The extension .bin should be already defined as a resource file by default.

 

2) modify the linker command file, create a memory segment where the binary file should be placed and add INCLUDE filename keyword in the SECTIONS part. e.g.:

 

MEMORY {
   vectorram   (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000500
   code        (RX)  : ORIGIN = 0x20000500, LENGTH = 0x00004000
   my_boot     (RX)  : ORIGIN = 0x20004500, LENGTH = 0x00000B00
   userram     (RWX) : ORIGIN = 0x20005000, LENGTH = 0x00001800
}


SECTIONS {
...

    .bootloader:
    {
        INCLUDE mybinary.bin
    } > my_boot

...

 

If you build the project you should see something like this in the .xmap file:

 

# .bootloader

# 20004500 00000017 (Included file: mybinary.bin)

 

 

Stanish

View solution in original post

0 Kudos
13 Replies
1,208 Views
FridgeFreezer
Senior Contributor I

I like that I got 1 Kudos for that post but no reply :smileysurprised: not sure what that means!

 

Further research suggests that I can't compile the bootloader as a library as it doesn't contain any externally callable functions and needs to be at an absolute address in flash, and then jump out to another absolute address in flash which it can't call by function name.

 

Any help (still) gratefully appreciated! 

0 Kudos
1,208 Views
kef
Specialist I

It probably means that your request is important to someone else? Also you collected some usefull information.

 

I also would like to know how to include *.s19 or *.hex in final executeable. It is easy to do in CW for S08 or for S12. There you add HEXFILE filename.s19 to PRM file and linker does its work. CW 6.3 for MCUs help files mention LCF INCLUDE ddirective, but it is not clear how to use it. I tried to include bootloader S records, but was unable to make it working.

 

Yes, of course there should be ablosute address linkage between booloader and application. Bootloader may assume that there's exceptions vectors or jump table at some fixed address. Bootloader either vectors all exceptions (except start address) to applications jump table, then jumps to start address when appropriate. Or, bootloader/application may copy applications vectors table to RAM and use VBR register to change vectors base address...

0 Kudos
1,208 Views
FridgeFreezer
Senior Contributor I

A possible work-around (I will not call it a solution as it's not very elegant) is to modify both projects so that the main project has nothing whatsoever to do with the bootloader, it just has the LCF configured to reserve/block the bottom sector of flash where the bootloader lives. Then do the same thing with the bootloader project, and just manually join the .s19's together when required.

 

Our need to have one "complete" .s19 is because the customer programs boards at the factory via BDM from an .s19, so they need boot + main in one file to give the full software package. When we do an upgrade on an older board in the field, only the main part of the "latest issue" .s19 is applied / needed. We want to avoid having two separate.s19's (one for the factory, one for upgrade) as it gets confusing for everyone.

0 Kudos
1,208 Views
kef
Specialist I

Yes, one may concatenate two S files, removing S9 record(s) from resulting file. But it will make debugging way more difficult. On S08/S19 HEXFiLE directive makes automatic boot+application concatenation. Then Burner script is edited to produce two output S-files, one which includes all addresses, another one includes all addresses except bootloader area. Just Run click for debugging, just make click for 1) full and 2) upgrade-only S-records files. For Coldfire it would be nice to at least include booloader binary in ELF and S-file, so that debugging is easy. The question is how to use and if it is possible to use LCF INCLUDE directive to include bootloader binary.

0 Kudos
1,208 Views
bshaw
Contributor III

I've been trying the same thing without luck yet,  so I'm watching this thread. 

 

I need to include eTPU and FPGA code in my application so I can load them up when needed,  would be real smooth to just include the binary files in the link at a specified flash address.  Currently it is done with a python script that reads the binary file and outputs a C source file with a constant-initialized array.  Kind of klunky but it works.

 

Bill

0 Kudos
1,209 Views
stanish
NXP Employee
NXP Employee

Hi,

 

You can use INCLUDE linker command as mentioned by kef.

If you use CodeWarrior IDE project you need to:

 

1) add your binary file (e.g. mybinary.bin) into the project and make sure the file extension is defined as a resource file in "File Mappings" (ALT+F7 -> Target -> "File Mappings" -> "Flags" -> "Resource File"). The extension .bin should be already defined as a resource file by default.

 

2) modify the linker command file, create a memory segment where the binary file should be placed and add INCLUDE filename keyword in the SECTIONS part. e.g.:

 

MEMORY {
   vectorram   (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000500
   code        (RX)  : ORIGIN = 0x20000500, LENGTH = 0x00004000
   my_boot     (RX)  : ORIGIN = 0x20004500, LENGTH = 0x00000B00
   userram     (RWX) : ORIGIN = 0x20005000, LENGTH = 0x00001800
}


SECTIONS {
...

    .bootloader:
    {
        INCLUDE mybinary.bin
    } > my_boot

...

 

If you build the project you should see something like this in the .xmap file:

 

# .bootloader

# 20004500 00000017 (Included file: mybinary.bin)

 

 

Stanish

0 Kudos
1,208 Views
FridgeFreezer
Senior Contributor I

Sorry to ask a question the dissappear - I had to fix some more urgent problems before returning to this one.

 

Stanish - your reply is exactly what I was hoping for, lthough I did have to fiddle a bit to make it compile without errors. I will describe what I did in the hope someone may find it useful.

 

I defined the filetype as Stanish described, but the detail is that it must be flagged as a resource file, with compiler set to none.

 

Because I don't have a .BIN file of the exact version of bootloader code we are using, I generated a BIN by using the debugger to save memory as a BIN, https://community.freescale.com/message/59178#59178.

 

In my LCF I redefined a couple of lines, this was the original for my project (main & bootloader compiled together in same project):

 

MEMORY
{
 vectorflash(RX) : ORIGIN = 0x00000000, LENGTH = 0x00000418
 bootcode    (RX): ORIGIN = 0x00000420, LENGTH = 0x00003BE0
 flash   (RX)   : ORIGIN = 0x00004010, LENGTH = 0x0007BFF0
 vectorram(RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000400
 sram (RWX)  : ORIGIN = 0x20000400, LENGTH = 0x0000FC00
 ipsbar  (RWX)  : ORIGIN = 0x40000000, LENGTH = 0x0
}
#############
    .vectorflash :    {        mcf5225x_vectors.s (.text)    } > vectorflash        // Store in vectorflash     .bootcode: {   ___Boot_START   = .;  Bootloader.c (.text)  Bootloader.c (.rodata)  . = ALIGN (0x4);  ___Boot_END     =.;  } > bootcode  // Store in bootcode#################___FLASH  = ADDR(.vectorflash);

 

Becomes simply:

 

MEMORY
{
 bootcode    (RX): ORIGIN = 0x00000000, LENGTH = 0x00004000
       flash   (RX)   : ORIGIN = 0x00004010, LENGTH = 0x0007BFF0
 sram (RWX)  : ORIGIN = 0x20000400, LENGTH = 0x0000FC00
 ipsbar  (RWX)  : ORIGIN = 0x40000000, LENGTH = 0x0
}###############SECTIONS {  .bootcode: {   ___Boot_START   = .;  INCLUDE mabe_04_bootloader.bin  . = ALIGN (0x4);  ___Boot_END     =.;  } > bootcode  // Store in bootcode###################### ___FLASH  = ADDR(.bootcode);

 

 

As the bootloader project includes the mcf5225x_vectors.s file anyway (and they are the same) I have just deleted it from the main project .LCF - I suspect this is wrong and that I should move it to the offset for the main code (0x4000) but being a bit unfamiliar with the nitty gritty I don't want to change too much at one time. When I can formulate a sensible question about how to do it I'll probably come back and bug everyone again :smileywink:

mcf5225x_vectors.s
0 Kudos
1,208 Views
bshaw
Contributor III

Is INCLUDE something that only works in certain versions?  I'm getting an error "linker command file INCLUDE is missing from project."

 

I'm using IDE V5.9 and CW for MPC55xx V2.2.1 build 80310.

 

in my MEMORY I have:

  etpu_program:           org = 0x00080000,   len = 0x0001fffc

 

and in my SECTIONS I have:

  .etpu_area :      /* include the etpu code and define labels so we can reference it later */
     {
         _eTPUStart = .;
         INCLUDE etpu_program.cod
         _eTPUEnd = .;
     } > etpu_program

Best,

 

Bill

 

0 Kudos
1,208 Views
bshaw
Contributor III

In my case the 'INCLUDE' is unnecessary (in fact,  causes an error). 

 

 in my SECTIONS I have:

  .etpu_area :      /* include the etpu code and define labels so we can reference it later */
     {
         _eTPUStart = .;
         etpu_program.cod
         _eTPUEnd = .;
     } > etpu_program

This places the etpu code in the correct area of flash and properly defines its boundries for my project.

 

Thanks for the help, gang!

 

Best,

 

Bill

0 Kudos
1,208 Views
stanish
NXP Employee
NXP Employee

hi Bill,

 

Thanks, you are right. This approach indeed works with PowerPC Linker.

But there are some differences between these two linkers. E.g. PowerPC one does not support INCLUDE (as you observed) and ColdFire one does not support the syntax you posted.

 

Regards

 

Stanish

 

 

0 Kudos
1,208 Views
kef
Specialist I

Dear Stanish,

 

could you explain, please, why LCF INCLUDE isn't working in CW6.3 for MCUs? I copied mybinary.bin into every subfolder I found in project's folders tree. Linker still complains:

 

Link Error   : Linker command file error at line 120
File not found: mybinary.bin

Link failed.

 

Last time I tried to include binary, I think I tried copying bin file to library folder, to one of PATH environment variables folder. Nothing worked.

0 Kudos
1,208 Views
stanish
NXP Employee
NXP Employee

Hi kef,

 

You perhaps haven't added the binary file directly into CodeWarrior IDE project window - "Files" tab (see attached screenshot).

I've just tested with CW for MCUs v6.3 and it works.

 

Stanish

1,208 Views
kef
Specialist I

Thanks! That was the problem. I thought I read your instructions correctly. Indeed I missed to add bin file to the project like a source file, so that it is visible in project window tree. It's working.

0 Kudos