public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
* Linking with binary files
@ 2000-10-03 16:40 Michael K. Elwood
  2000-10-04  6:29 ` Daris A Nevil
  0 siblings, 1 reply; 4+ messages in thread
From: Michael K. Elwood @ 2000-10-03 16:40 UTC (permalink / raw)
  To: crossgcc

Somebody recently asked about linking straight binary files (BDF
type=binary) into their programs. Somebody else said that LD should be
able to do this.

My curiosity was sufficiently piqued, so I tried it (using the TARGET
command and various other schemes), but I can't get it to work. Before I
wade into the sources, does somebody else out there know how to get this
to work? A snip of example command file would be great.

Thanks.

MKE

-- 
**********************************************************
Michael K. Elwood                     mkelwood@qsicorp.com
QSI Corporation

The fourth(?) Law of Thermodynamics:
     (Work in Theory) <= (Work in Practice)
**********************************************************

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Linking with binary files
  2000-10-03 16:40 Linking with binary files Michael K. Elwood
@ 2000-10-04  6:29 ` Daris A Nevil
  0 siblings, 0 replies; 4+ messages in thread
From: Daris A Nevil @ 2000-10-04  6:29 UTC (permalink / raw)
  To: mkelwood; +Cc: crossgcc

You can link binary files by first converting them to .elf format
(at least for the PPC architecture, not sure about wintel).
Here is a snippet of how this is done, using objcopy.  This is
from the QSLinux makefile.

Enjoy,
Daris Nevil

zvmlinux: $(OBJECTS) vmlinux.gz qs850.lds
#
# build the boot loader image and then compute the offset into it
# for the kernel image
# Convert the vmlinux.gz to elf format.  Merge the vmlinux.gz kernel
# into the linked boot program.  Re-adjust the VMA of the .data section
# to match the LMA, where it is loaded into flash.  This allows the
# visionIce 'convert' utility to see it, because 'convert' only seems
# to look at the VMA when loading modules.
# Finally, make a binary image that can be burned into flash by the
# SNMC "ff" program.
#
        $(OBJCOPY) --input-target=binary --output-target=elf32-powerpc \
                vmlinux.gz vmlinux.gz.elf
        $(LD) $(ZLINKFLAGS) -o $@ $(OBJECTS) -T qs850.lds -M \
                > zvmlinux.map
        $(OBJCOPY) --change-section-vma .data=`sh lma $(OBJDUMP) $@
data` \
                $@ $@.elf
        cp $@.elf $(TOPDIR)/$@.elf
        $(OBJCOPY) --input-target=elf32-powerpc --output-target=binary \
                $@.elf $@.bin
        cp $@.bin $(TOPDIR)/$@.bin

"Michael K. Elwood" wrote:
> 
> Somebody recently asked about linking straight binary files (BDF
> type=binary) into their programs. Somebody else said that LD should be
> able to do this.
> 
> My curiosity was sufficiently piqued, so I tried it (using the TARGET
> command and various other schemes), but I can't get it to work. Before I
> wade into the sources, does somebody else out there know how to get this
> to work? A snip of example command file would be great.
> 
> Thanks.
> 
> MKE
> 
> --
> **********************************************************
> Michael K. Elwood                     mkelwood@qsicorp.com
> QSI Corporation
> 
> The fourth(?) Law of Thermodynamics:
>      (Work in Theory) <= (Work in Practice)
> **********************************************************
> 
> ------
> Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

-- 
Daris A Nevil
Simple Network Magic Corporation
401 Kentucky Lane
McKinney, TX 75069
214-793-7757
dnevil@snmc.com
www.snmc.com
quickstack.com
qslinux.org

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Linking with binary files
  2000-10-04  9:06 Michael K. Elwood
@ 2000-10-04  9:20 ` Daris A Nevil
  0 siblings, 0 replies; 4+ messages in thread
From: Daris A Nevil @ 2000-10-04  9:20 UTC (permalink / raw)
  To: mkelwood; +Cc: crossgcc

Hi Michael,

Well, I do get a warning message with the PPC binutils.  Here is what it
looks like:

/usr/local/bin/powerpc-snmc-linux-gnu-objcopy --input-target=binary
--output-tar
get=elf32-powerpc \
        vmlinux.gz vmlinux.gz.elf
/usr/local/bin/powerpc-snmc-linux-gnu-objcopy: Warning: Output file
cannot repre
sent architecture UNKNOWN! 


Seems that I remember having problems making this work for PPC also.  I
had to go in and specify the output format, and not just rely on the
default output type. You may have some luck if you look at the
parameters and specify everything explicitly.

Now that I think about it a little more, it seems that it was in the
linker that I had to spell things out, at least regarding options.  Here
is what the linker command ends up looking like:

/usr/local/bin/powerpc-snmc-linux-gnu-ld --format elf32-powerpc -m
elf32ppc -g -
o zvmlinux init_qs850.o misc.o cmdline.o zlib.o embed_config.o
watchdog.o vsprin
tf.o string.o ctype.o printk.o ../drivers/char/smccons.o
../drivers/char/scccons
.o ../kernel/brg.o ../kernel/qspin.o ramtest.o hwinit.o stubs.o -T
qs850.lds -M
\
> zvmlinux.map

Notice that I use both the "--format" and the "-m" specifier.  I'm not
sure it totally necessary, but thats what I had to do to get it to work.

Daris


"Michael K. Elwood" wrote:
> 
> Thanks for the info, Daris.
> 
> My binutils are built for the mips-tx39-elf target. Objcopy will indeed
> convert a binary to what looks like an elf file, but then BFD fails to
> recognize the it as legitimate; I get a "File format not recognized"
> when I reference the created elf file. Linking with this file fails, and
> I also can't objcopy the file back to binary (or to any other format).
> Always get the same "File format not recognized" error.
> 
> There is a note in the binary.c source file in BFD which states that
> binary is supported for output only, not input. And yet it seems to do
> the conversion, and the QSLinux build is obviously working. Strange. I
> wonder what is different.
> 
> Any ideas?
> 
> MKE
> 
> Daris Nevil wrote:
> 
> >You can link binary files by first converting them to .elf format
> >(at least for the PPC architecture, not sure about wintel).
> >Here is a snippet of how this is done, using objcopy.  This is
> >from the QSLinux makefile.
> >zvmlinux: $(OBJECTS) vmlinux.gz qs850.lds
> >#
> ># build the boot loader image and then compute the offset into it
> ># for the kernel image
> ># Convert the vmlinux.gz to elf format.  Merge the vmlinux.gz kernel
> ># into the linked boot program.  Re-adjust the VMA of the .data section
> ># to match the LMA, where it is loaded into flash.  This allows the
> ># visionIce 'convert' utility to see it, because 'convert' only seems
> ># to look at the VMA when loading modules.
> ># Finally, make a binary image that can be burned into flash by the
> ># SNMC "ff" program.
> >#
> >        $(OBJCOPY) --input-target=binary --output-target=elf32-powerpc \
> >                vmlinux.gz vmlinux.gz.elf
> >        $(LD) $(ZLINKFLAGS) -o $@ $(OBJECTS) -T qs850.lds -M \
> >                > zvmlinux.map
> >        $(OBJCOPY) --change-section-vma .data=`sh lma $(OBJDUMP) $@
> >data` \
> >                $@ $@.elf
> >        cp $@.elf $(TOPDIR)/$@.elf
> >        $(OBJCOPY) --input-target=elf32-powerpc --output-target=binary \
> >                $@.elf $@.bin
> >        cp $@.bin $(TOPDIR)/$@.bin
> 
> --
> **********************************************************
> Michael K. Elwood                     mkelwood@qsicorp.com
> QSI Corporation
> 
> The fourth(?) Law of Thermodynamics:
>      (Work in Theory) <= (Work in Practice)
> **********************************************************
> 
> ------
> Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

-- 
Daris A Nevil
Simple Network Magic Corporation
401 Kentucky Lane
McKinney, TX 75069
214-793-7757
dnevil@snmc.com
www.snmc.com
quickstack.com
qslinux.org

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Linking with binary files
@ 2000-10-04  9:06 Michael K. Elwood
  2000-10-04  9:20 ` Daris A Nevil
  0 siblings, 1 reply; 4+ messages in thread
From: Michael K. Elwood @ 2000-10-04  9:06 UTC (permalink / raw)
  To: dnevil, crossgcc

Thanks for the info, Daris.

My binutils are built for the mips-tx39-elf target. Objcopy will indeed
convert a binary to what looks like an elf file, but then BFD fails to
recognize the it as legitimate; I get a "File format not recognized"
when I reference the created elf file. Linking with this file fails, and
I also can't objcopy the file back to binary (or to any other format).
Always get the same "File format not recognized" error.

There is a note in the binary.c source file in BFD which states that
binary is supported for output only, not input. And yet it seems to do
the conversion, and the QSLinux build is obviously working. Strange. I
wonder what is different.

Any ideas?

MKE

Daris Nevil wrote:

>You can link binary files by first converting them to .elf format
>(at least for the PPC architecture, not sure about wintel).
>Here is a snippet of how this is done, using objcopy.  This is
>from the QSLinux makefile.
>zvmlinux: $(OBJECTS) vmlinux.gz qs850.lds
>#
># build the boot loader image and then compute the offset into it
># for the kernel image
># Convert the vmlinux.gz to elf format.  Merge the vmlinux.gz kernel
># into the linked boot program.  Re-adjust the VMA of the .data section
># to match the LMA, where it is loaded into flash.  This allows the
># visionIce 'convert' utility to see it, because 'convert' only seems
># to look at the VMA when loading modules.
># Finally, make a binary image that can be burned into flash by the
># SNMC "ff" program.
>#
>        $(OBJCOPY) --input-target=binary --output-target=elf32-powerpc \
>                vmlinux.gz vmlinux.gz.elf
>        $(LD) $(ZLINKFLAGS) -o $@ $(OBJECTS) -T qs850.lds -M \
>                > zvmlinux.map
>        $(OBJCOPY) --change-section-vma .data=`sh lma $(OBJDUMP) $@
>data` \
>                $@ $@.elf
>        cp $@.elf $(TOPDIR)/$@.elf
>        $(OBJCOPY) --input-target=elf32-powerpc --output-target=binary \
>                $@.elf $@.bin
>        cp $@.bin $(TOPDIR)/$@.bin


-- 
**********************************************************
Michael K. Elwood                     mkelwood@qsicorp.com
QSI Corporation

The fourth(?) Law of Thermodynamics:
     (Work in Theory) <= (Work in Practice)
**********************************************************

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-10-04  9:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-03 16:40 Linking with binary files Michael K. Elwood
2000-10-04  6:29 ` Daris A Nevil
2000-10-04  9:06 Michael K. Elwood
2000-10-04  9:20 ` Daris A Nevil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).