2003-07-11 15:13:53

by Jon Masters

[permalink] [raw]
Subject: Stripped binary insertion with the GNU Linker suggestions (fwd)

Hi,

I have a linker script which amongst other things contains:

MEMORY
{
sdram_linux : ORIGIN = 0x00500000, LENGTH = 4M
}

SECTIONS {

.linux :
{ linux_kernel } > sdram_linux

}

What I have is a stripped kernel image which I want to shove in to a
section in the output elf file though the Linker complains it does not
recognise the file format (as it perhaps should). I realise that the
above is not the correct way to do this - suggestions are very welcome.

I have seen other nasty ways to do this involving converting the image to
byte values in very large arrays or inserting literal byte values in to
the output file but there just has to be a generic method for inserting
an image in to the middle of an output file.

Cheers,

Jon.


2003-07-11 15:21:26

by Larry McVoy

[permalink] [raw]
Subject: Re: Stripped binary insertion with the GNU Linker suggestions (fwd)

On Fri, Jul 11, 2003 at 04:19:55PM +0100, Jon Masters wrote:
> I have seen other nasty ways to do this involving converting the image to
> byte values in very large arrays or inserting literal byte values in to
> the output file but there just has to be a generic method for inserting
> an image in to the middle of an output file.

No, there isn't, at least I haven't found one. The BK installer does
exactly what you want (and you can have the source if you like, BSD
license) on the platforms listed below. We had to play some nasty
games to make this work, I believe it was HP-UX which "knew" that your
array was full of zeros and did not allocate it, it did it at runtime.
Any sort of predictable pattern it figured out, the following fools it
for now:

unsigned char data_data[3866327] = {
255,
6,
1,
2,
3,
4,
255,
3,
9,
62,
255,
10,
4,
61,
255,
};

platforms that this technique works on:

alpha-glibc22-linux
alpha-osf5.1
arm-glibc21-linux
hppa-glibc22-linux
hppa-hpux
ia64-glibc22-linux
mips-glibc22-linux
mips-irix
mipsel-glibc20-linux
powerpc-aix
powerpc-darwin6.6
powerpc-glibc21-linux
sparc-glibc21-linux
sparc-solaris
x86-freebsd2.2.8
x86-freebsd3.2
x86-freebsd4.1
x86-glibc20-linux
x86-glibc21-linux
x86-glibc22-linux
x86-netbsd
x86-openbsd
x86-sco3.2v5.0.7
x86-solaris

--
---
Larry McVoy lm at bitmover.com http://www.bitmover.com/lm

2003-07-11 15:55:11

by Jon Masters

[permalink] [raw]
Subject: Re: Stripped binary insertion with the GNU Linker suggestions (fwd)

On Fri, 11 Jul 2003, Larry McVoy wrote:

> On Fri, Jul 11, 2003 at 04:19:55PM +0100, Jon Masters wrote:
> > I have seen other nasty ways to do this involving converting the image to
> > byte values in very large arrays or inserting literal byte values in to
> > the output file but there just has to be a generic method for inserting
> > an image in to the middle of an output file.
>
> No, there isn't, at least I haven't found one.

Arrgh! :-).

In that case I might take you up on the BK idea or write something using
bfd to munge the elf content - odd that it does not exist already.

The reason I want it is that I am creating a single elf output file which
is loaded in to SDRAM by a SystemACE chip and in order for that to work
correctly I need to give the appropriate tools a single elf input
containing everything where I want it to be loaded in memory.

Fun for the weekend I suppose... :-).

Jon.

2003-07-11 16:23:00

by Hollis Blanchard

[permalink] [raw]
Subject: Re: Stripped binary insertion with the GNU Linker suggestions (fwd)

On Friday, Jul 11, 2003, at 11:00 US/Central, Jon Masters wrote:
>
> The reason I want it is that I am creating a single elf output file
> which
> is loaded in to SDRAM by a SystemACE chip and in order for that to work
> correctly I need to give the appropriate tools a single elf input
> containing everything where I want it to be loaded in memory.

Not sure I understand the problem exactly, but I believe ppc32 kernels
do exactly what you want. Have a look at arch/ppc/boot/ld.script and
see __{image,ramdisk,sysmap}_begin . Also see how e.g.
arch/ppc/boot/prep/Makefile uses objcopy
--add-section=.image=vmlinux.gz .

The end result is taking an arbitrary file and stuffing it into an ELF
section, then using a linker script to provide the start and end
addresses of the file data.

--
Hollis Blanchard
IBM Linux Technology Center

2003-07-12 01:08:53

by Jon Masters

[permalink] [raw]
Subject: Re: Stripped binary insertion with the GNU Linker suggestions (fwd)

On Fri, 11 Jul 2003, Hollis Blanchard wrote:

> Not sure I understand the problem exactly, but I believe ppc32 kernels
> do exactly what you want. Have a look at arch/ppc/boot/ld.script and
> see __{image,ramdisk,sysmap}_begin . Also see how e.g.
> arch/ppc/boot/prep/Makefile uses objcopy
> --add-section=.image=vmlinux.gz .

I had another look at this tonight on the train and agree that this was
after all exactly what I want and I will need to use this "dummy" method
to force the kernel in to a single section before shoving it in to the
final ELF output image.

Jon.