Question regarding Linking (GCC)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ja
Posts: 11
Joined: Thu Jan 24, 2013 4:53 pm

Question regarding Linking (GCC)

Post by ja »

Hi

I am trying to link two different architecture images into single image is it possible ?

For example if i have image0 which is ARM compliant and image1 which is MSA intel architecture compliant.
How i can create an image image2 = image0+image1 ?

I know that linker script takes the object file as part of section (text) input and
I was using objcopy to generate .bin to .obj for placing the images into appropriate location in case of ARM architecture.
Also, linker script takes the architecture specific flag for OUTPUT format but i am not sure if there is a way i can make the two images with different architecture support as piggy back images inside a final image ?


I know the workaround could be to just copy Opcodes for one of the image directly into memory but i am trying to find a better way ?

Thanks,
- Ja
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Question regarding Linking (GCC)

Post by AJ »

Hi,

You could achieve this with a library system (such as ar).

What exactly are you trying to achieve that would not be better dealt with by just having two completely separate binaries?

Cheers,
Adam
ja
Posts: 11
Joined: Thu Jan 24, 2013 4:53 pm

Re: Question regarding Linking (GCC)

Post by ja »

Hi,

" What exactly are you trying to achieve that would not be better dealt with by just having two completely separate binaries? "

I am trying to flash a single binary/image and it contains multiple images.
These images are dispersed by the main binary into memory after doing some initialization.
So in short i have one main initialization binary which has multiple binaries. There binaries are for specific purposes such as initializing specific cores, HW engines etc..

I am using bare metal code so there is no OS. Do you have any recommendation for such case ? I know simple workaround by just embedding the opcode into an array but it is not efficient.

Thanks,
Ja
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Question regarding Linking (GCC)

Post by Nessphoro »

Well, I suppose with ld you could make a section for each arch. and dump the file's contents in there (it will work rather nicely with bins) and then since ld can report you the addresses of sections in variables you could make it work.
ja
Posts: 11
Joined: Thu Jan 24, 2013 4:53 pm

Re: Question regarding Linking (GCC)

Post by ja »

Hi,

Do you have any example which i can refer ?
I tried making linker script but it just truncates the .bin file.

Thanks,
Ja
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Question regarding Linking (GCC)

Post by Nessphoro »

You could do this:

Code: Select all

ENTRY(...)
SECTIONS{
    . = SomeAddress;
    //Your sections and stuff...
    // This could be your bootstrap code, idk
    _ArmCodeStart=.;
    INCLUDE "arm.ld"; //Linker script for arm stuff
   _ArmCodeEnd=.;
    
   _IntelCodeStart=.;
    INCLUDE "x86.ld"; //Linker script for x86stuff
   _IntelCodeEnd=.;
}

You could generate the extra ld files for existing binaries using

Code: Select all

cat binary.bin | hexdump -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' > binary.ld
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Question regarding Linking (GCC)

Post by dozniak »

Just one question, if you're flashing a firmware, you know precisely what system that is, so unless it's a mixed ARM/Intel machine there's probably no point in having these images mixed together.
Learn to read.
Post Reply