l4-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

linker script to produce bootstrap device driver archive


From: Marcus Brinkmann
Subject: linker script to produce bootstrap device driver archive
Date: Wed, 24 Sep 2003 23:31:12 +0200
User-agent: Mutt/1.5.4i

Hi,

we will use a small archive of initial device drivers needed at bootstrap
(console, ide, ...) before the system is up and running.  Rather than to
have each driver be a module listed a GRUB, which would be a pain to
configure for a user, we better lump them all together into a single file.
Scripts can be used to take care of inter-module dependencies, for example.

The requirement is that in the file, each module/driver starts at a page
boundary, so it can be properly mapped into a task.  Also, you need to be
able to lookup a driver by name.

I looked at various archive formats and filesystems, and I was not
satisfied.  Streaming archives like tar and cpio use a header for each file,
wasting memory this way, and you can not specify an alignment (although we
could add padding files as the order is preserved).

There is one "archive" tool which has little overhead and allows you to
specify arbitrary alignments: GNU ld.  Not many might think of it as an
archive tool, but in fact it is, a clever one indeed.  Beside ELF and other
object formats, GNU supports a "binary" target that we can use for input.
The ELF format can be used for output.  For each file we use a section.
Section headers are easy to parse.  The advantages:

* The ELF format is defined for all architectures we want to use, and tools
  exist to manipulate it.  In fact, every arch you want to compile for comes
  with an appropriate ld, irregardless if you are cross compiling or not.
  As the content of the archive is arch dependent, it doesn't matter that
  the archive format is, too (in fact, as the ideal format depends on the
  pagesize, this is the case anyway).
* Arbitrary alignment can be specified.
* ELF doesn't have a lot of overhead, and parsing code exists.  In fact, the
  same program that "extracts" the modules from the archive also needs to
  know about ELF for other reasons (spawn operation).

There is one thing I don't like, and that is that ld puts the elf section
headers after the sections, while there is enough room before them because
we have to align the first section to the page boundary.  So if we don't
want to map the ELF section header with the last driver, we will waste in
most circumstances.  This could be micro-optimized with a simple utility
later-on.

Below you can find a linker script to produce such an archive.  Save as
"script" and then try:

$ echo hello > file1
$ echo bye > file2
$ ld -T script
$ objdump -x a.out

Thanks,
Marcus

/* These formats need to be extracted from the default linker script
   that can be retrieved from the ld --verbose output.  */
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)

 /* This must be defined to the minimal page size on the system.  */
page_size = 0x1000;

/* Our input files are normal binary files.  */
TARGET("binary")

/* We define a program header with only one segment beside the header.  */
PHDRS
{
  headers PT_PHDR FILEHDR PHDRS;
  file_list PT_LOAD;
}

/* One for each input file.  */
INPUT("file1")
INPUT("file2")

SECTIONS
{
  . = SIZEOF_HEADERS;

  file1 ALIGN(page_size): { "file1" } 
  file2 ALIGN(page_size): { "file2" }

  /* This moves the ELF section headers out of the last page of the
     last file as a precaution.  Might not be necessary.  */
  foo ALIGN(page_size): { BYTE(1) }

  /* Put all sections into the file_list segment.  */
  :file_list
}


-- 
`Rhubarb is no Egyptian god.' GNU      http://www.gnu.org    address@hidden
Marcus Brinkmann              The Hurd http://www.gnu.org/software/hurd/
address@hidden
http://www.marcus-brinkmann.de/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]