History log of /freebsd-10.3-release/sys/boot/common/load_elf.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 296373 04-Mar-2016 marius

- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
builds.
- Update newvers.sh to reflect RC1.
- Update __FreeBSD_version to reflect 10.3.
- Update default pkg(8) configuration to use the quarterly branch.

Approved by: re (implicit)

# 295531 11-Feb-2016 smh

MFC r295356 (Partial)

Fix EFI platform build failures on arm.armeb

Approved by: re (marius)
Sponsored by: Multiplay


# 294981 28-Jan-2016 smh

MFC r281169, r293724, r293796, r294029, r294041, r294058

MFC r281169 (by andrew):
Make global variabled only used in this file static

MFC r294058:
Make common boot file_loadraw name parameter const

MFC r294041:
Remove unused reg param from fdt_fixup_memory

MFC r293724:
Enable warnings in EFI boot code

MFC r293796:
Fix typo in libefi.c

MFC r294029:
Only build EFI components on supported compilers

Sponsored by: Multiplay


# 294417 20-Jan-2016 royger

MFC r277215, r277291, r277418, r280953 and r280954:

loader: implement multiboot support for Xen Dom0

Note that only the subset of the multiboot specification needed in order to
boot a Xen Dom0 is implemented.

Sponsored by: Citrix Systems R&D


# 283505 25-May-2015 ian

MFC r277962, r277988, r282661, r282727, r282731, r283013, r283035:

Add support for booting relocatable kernels on PowerPC.

Add code to support loading relocatable kernels at offsets that are
not zero.

Move ubldr text section to the start of the output file, so that when you
create a stripped .bin file from it the entry point is the first byte of
the file. (Will allow "load $addr $file ; go $addr" in u-boot.)

Create a relocatable instance of ubldr for ARM (ubldr.bin).

Re-link ubldr when any of its libraries change.

An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.


# 274942 24-Nov-2014 grehan

MFC r274407

Fix incorrect reading of 32-bit modinfo by 64-bit loaders.

The various structures in the mod_metadata set of a FreeBSD kernel and
modules contain pointers. The FreeBSD loader correctly deals with a
mismatch in loader and kernel pointer size (e.g. 32-bit i386/ppc
loader, loading 64-bit amd64/ppc64 kernels), but wasn't dealing with
the inverse case where a 64-bit loader was loading a 32-bit kernel.


# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 248121 10-Mar-2013 ian

Attach the elf section headers to the loaded kernel as metadata, so
they can easily be used by later post-processing. When searching for
a compiled-in fdt blob, use the section headers to get the size and
location of the .dynsym section to do a symbol search.

This fixes a problem where the search could overshoot the symbol
table and wander into the string table. Sometimes that was harmless
and sometimes it lead to spurious panic messages about an offset
bigger than the module size.


# 248118 09-Mar-2013 ian

Since ubldr doesn't necessarily load a kernel at the physical address in the
elf headers, mask out the high nibble of that address. This effectly makes
the entry point the offset from the load address, and it gets adjusted for
the actual load address before jumping to it.

Masking the high nibble makes assumptions about memory layout that are true
for all the arm platforms we support right now, but it makes me uneasy.
This needs to be revisited.


# 247413 27-Feb-2013 ian

Fix a typo that prevented booting a kernel that had virtual addresses in
the elf headers.


# 247301 26-Feb-2013 ian

Adjust the arm kernel entry point address properly regardless of whether the
e_entry field holds a physical or a virtual address. Add a comment block
that explains the assumptions being made by the adjustment code.


# 240249 08-Sep-2012 andreast

Fix loading of kernel modules at boot time for powerpc64.

Reported by: Mathias Breuninger
MFC after: 1 week


# 237338 20-Jun-2012 jhb

Don't return an error if a kld does not contain any modules (e.g. a
kld that only contained a sysctl). The kernel linker allows such
modules, so the boot loader should not reject them.

MFC after: 2 weeks


# 223695 30-Jun-2011 dfr

Add a version of the FreeBSD bootloader which can run in userland, packaged
as a shared library. This is intended to be used by BHyVe to load FreeBSD
kernels into new virtual machines.


# 220311 03-Apr-2011 marcel

Add 2 new archsw interfaces:
1. arch_loadaddr - used by platform code to adjust the address at which
the object gets loaded. Implement PC98 using this new interface instead
of using conditional compilation. For ELF objects the ELF header is
passed as the data pointer. For raw files it's the filename. Note that
ELF objects are first considered as raw files.
2. arch_loadseg - used by platform code to keep track of actual segments,
so that (instruction) caches can be flushed or translations can be
created. Both the ELF header as well as the program header are passed
to allow platform code to treat the kernel proper differently from any
additional modules and to have all the relevant details of the loaded
segment (e.g. protection).


# 215811 25-Nov-2010 emaste

Give a bit of a hint of the failure (read != expected) but don't make
the error message needlessly more verbose.

Discussed with: attilio


# 215758 23-Nov-2010 attilio

Make this printfoutput more verbose.

Sponsored by: Sandvine Incorporated
Submitted by: Sandvine Incorporated
MFC after: 3 days


# 183878 14-Oct-2008 raj

Initial support of loader(8) for ARM machines running U-Boot.

This uses the common U-Boot support lib (sys/boot/uboot, already used on
FreeBSD/powerpc), and assumes the underlying firmware has the modern API for
stand-alone apps enabled in the config (CONFIG_API).

Only netbooting is supported at the moment.

Obtained from: Marvell, Semihalf


# 176484 23-Feb-2008 marcel

Add __elfN(relocation_offset). It holds the offset between the virtual
(link) address and the physical (load) address. Ideally, the mapping
between link and load addresses should be abstracted by the copyin(),
copyout() and readin() functions, so that we don't have to add kluges
in __elfN(loadimage)(). Then, we could also have paged virtual memory
for the kernel. This can be important under EFI, where you need to
allocate physical memory form the firmware if you want to work in all
scenarios.


# 163917 02-Nov-2006 ru

Unbreak compile with ELF_VERBOSE defined, and fix format warnings.


# 163914 02-Nov-2006 ru

Revert the last change. Masking only 2 MSBs of the virtual address
to get the physical address doesn't work for all values of KVA_PAGES,
while masking 8 MSBs works for all values of KVA_PAGES that are
multiple of 4 for non-PAE and 8 for PAE. (This leaves us limited
with 12MB for non-PAE kernels and 14MB for PAE kernels.)

To get things right, we'd need to subtract the KERNBASE from the
virtual address (but KERNBASE is not easy to figure out from here),
or have physical addresses set properly in the ELF headers.

Discussed with: jhb


# 163765 29-Oct-2006 ru

Because the BTX mini-kernel now uses flat memory mode and clients
are no longer limited to a virtual address space of 16 megabytes,
only mask high two bits of a virtual address. This allows to load
larger kernels (up to 1 gigabyte). Not masking addresses at all
was a bad idea on machines with less than >3G of memory -- kernels
are linked at 0xc0xxxxxx, and that would attempt to load a kernel
at above 3G. By masking only two highest bits we stay within the
safe limits while still allowing to boot larger kernels.

(This is a safer reimplmentation of sys/boot/i386/boot2/boot.2.c
rev. 1.71.)

Prodded by: jhb
Tested by: nyan (pc98)


# 158467 12-May-2006 jhb

Remove more Alpha bits from the boot code including fixing several
stale comments.


# 153504 18-Dec-2005 marcel

Make our ELF64 type definitions match standards. In particular this
means:
o Remove Elf64_Quarter,
o Redefine Elf64_Half to be 16-bit,
o Redefine Elf64_Word to be 32-bit,
o Add Elf64_Xword and Elf64_Sxword for 64-bit entities,
o Use Elf_Size in MI code to abstract the difference between
Elf32_Word and Elf64_Word.
o Add Elf_Ssize as the signed counterpart of Elf_Size.

MFC after: 2 weeks


# 134458 28-Aug-2004 iedowse

Separate out the ELF relocation code from the ELF loader, and add
better relocation support for the amd64 and i386 platforms. This
should not result in any change in functionality, but moves a step
towards supporting the relocatable object file modules on amd64.

The same hack/trick as load_elf*.c uses is used here to simultaneously
support both elf32 and elf64 on amd64 and i386.


# 134441 28-Aug-2004 iedowse

Add a few helper functions for zeroing kernel space and reading
from specified file offsets. Make use of these in load_elf.c.


# 126837 11-Mar-2004 bde

Fixed a misspelling of 0 as NULL.


# 119483 25-Aug-2003 obrien

Use __FBSDID().
Also some minor style cleanups.


# 114937 12-May-2003 peter

Fix lookup of module metadata on amd64 systems. While this is in
common code, the non-trivial part is #ifdef'ed and only executes when
loading amd64 kernels. The rest is trivial but needed for the the amd64
case. (Two variables changed from char ** to Elf_Addr).

Approved by: re (amd64 "low-risk" stuff)


# 114379 01-May-2003 peter

Enable the i386 loader to load and run an amd64 kernel. If this puts
things over floppy size limits, I can exclude it for release builds or
something like that. Most of the changes are to get the load_elf.c file
into a seperate elf32_ or elf64_ namespace so that you can have two
ELF loaders present at once. Note that for 64 bit kernels, it actually
starts up the kernel already in 64 bit mode with paging enabled. This
is really easy because we have a known minimum feature set.

Of note is that for amd64, we have to pass in the bios int 15 0xe821
memory map because once in long mode, you absolutely cannot make VM86
calls. amd64 does not use 'struct bootinfo' at all. It is a pure loader
metadata startup, just like sparc64 and powerpc. Much of the
infrastructure to support this was adapted from sparc64.


# 113083 04-Apr-2003 phk

Libdisk does not need to include <sys/diskslice.h> any more.

Move the remaining bits of <sys/diskslice.h> to <i386/include/bootinfo.h>

Move i386/pc98 specific bits from <sys/reboot.h> to
<i386/include/bootinfo.h> as well.

Adjust includes in sys/boot accordingly.


# 109616 21-Jan-2003 jake

Fix module dependency (pre)loading on sparc64 by relocating the variables
read from the raw kld files.

Submitted by: Hartmut Brandt <brandt@fokus.gmd.de>
PR: 46870
Tested on: alpha (obrien), i386, sparc64


# 96310 10-May-2002 obrien

We don't need bootinfo any more, and sparc64 doesn't have it anyways.


# 94248 09-Apr-2002 jake

Fix another unsigned long used to index the symbol table which should be
Elf_Hashelt.


# 93922 06-Apr-2002 peter

Use the correct elf hash table entry type. This matches a similar fix
in the kernel side of things some time ago. The hash table entries are
always 32 bits wide, even on 64 bit machines.


# 83321 11-Sep-2001 peter

Implement the long-awaited module->file cache database. A userland
tool (kldxref(8)) keeps a cache of what modules and versions are inside
what .ko files. I have tested this on both Alpha and i386.

Submitted by: bp


# 78696 24-Jun-2001 dwmalone

Get rid of some constness warnings.


# 78465 19-Jun-2001 peter

Convert the elf loader to the new linker set layout for elf files.
This should make dependencies at load time work like before. Oops.

Noticed by: markm


# 78463 19-Jun-2001 peter

Fix some of the worst formatting bug (seperate commit)


# 64187 03-Aug-2000 jhb

Cleanup warnings. Most of these are signed/unsigned warnings, as well as
some added const's.


# 61353 07-Jun-2000 dcs

Remove residual printf.

Prodded by: msmith


# 60432 12-May-2000 bp

long != int on Alphas.


# 59854 01-May-2000 bp

Update loader logic to distinguish modules vs. files.
Add support for module metadata. The old way of dependancy
handling will be supported for a while.

Reviewed by: peter


# 57468 25-Feb-2000 bp

Fix the loader to handle module dependencies properly. More fixes
will be provided after modmetadata appears in the kernel.

Reviewed by: msmith
Approved by: jkh


# 50477 28-Aug-1999 peter

$Id$ -> $FreeBSD$


# 44069 15-Feb-1999 tegge

Enable load of i386 ELF kernels with larger KVA range (e.g. starting at
0xe0100000u or 0xc0100000u instead of the usual 0xf0100000u).


# 42288 04-Jan-1999 peter

Don't forget a trailing \n when loading a kernel that has been stripped.
(This might make ELF_VERBOSE look funny, but I'm tempted to delete that
anyway)


# 40465 17-Oct-1998 peter

Load the first page of the file and use the headers in it. This should
avoid the need to seek back to offset zero which is causing trouble on
the Alpha with a gzipped kernel.


# 40429 16-Oct-1998 peter

"fix" the gzipped kernel load problem by having the loader check that it
can seek back to the first PT_LOAD and doing a close/reopen if it cannot.
This is because the first PT_LOAD section includes the ELF headers.
This fixes gzipped kernels on the i386, it should solve mike's problem
for the Alpha.


# 40414 15-Oct-1998 dfr

Change some printfs so that ELF_VERBOSE prints meaningful values on the alpha.


# 40327 14-Oct-1998 peter

Tweak the output one more time again. The kernel or module pathname
is useful, and usually fits all on one line with the load sizes.


# 40291 13-Oct-1998 peter

Make the ELF load messages cleaner.


# 40254 12-Oct-1998 peter

Only print kernel entry point during load.
Drastically quieten down the verbose load progress messages. They were
more useful for debugging than anything, but are beyond a joke when loading
a few dozen modules.
Simplify the ELF extended symbol table load format. Just take the main
symbol table and the string table that corresponds. This is what we will
be getting local symbols from. (needed for the alpha stack tracebacks).
Use the (optional) full symbol tables in lookups. This means we have to
furhter distinguish between symbols that can come from the dynamic linking
table and the complete table.
The alpha boot code now needs to be adapted as ddb/db_elf.c cannot use
the simpler format.
I have not implemented loading the extended symbol tables from the syscall
interface yet, just for preloaded modules.
I am not sure about the symbol resolution. I *think* it's possible that
a local symbol can be found in preference to a global, depending on the
search sequence and dependency tree.


# 40143 09-Oct-1998 peter

Implement preloading for elf modules
- get dependency info from PT_DYNAMIC's DT_NEEDED tags.
- store MODINFOMD_DYNAMIC for the kernel's later use
setenv kernelname when we have it
Fix firstaddr/lastaddr calculation (duh! :-)
Explicitly skip string table with section names in it.


# 39887 02-Oct-1998 peter

First shot at loading elf symbols. Things are a bit strange because
of the ..umm.. "wierd" way binutils lays out the file. The section
headers are nearly at the end of the file and this is a problem when
loading from a .gz file which can't seek backwards (or has a limited
reverse seek, ~2K from memory).

This is intended to be compatable with the ddb/db_elf.c code and the
alpha/libalpha/elf_freebsd.c layout. I've studied these (which are NetBSD
derived) but did it a bit differently. Naturally the process is similar
since it's supposed to end up with the same result.


# 39830 30-Sep-1998 peter

ELF loader, part 1. It works with ELF kernels generated on the i386
so far, and should probably be able to be made to work for the alpha
without too much trouble once it's connected up and my assumptions tested.

I think (but have not tested) it will also load "old" ELF kernels that
were not linked with DYNAMIC headers.

The module glue is yet to come. (oh fun.. :-)

It does not explicitly load symbols [yet]. The _DYNAMIC data contains a
runtime symbol set that ddb can use via ddb/db_kld.c. It'll be missing
some detail that stabs normally provides (eg: number of args to a function,
line numbers, etc). On the other hand, those minimal symbols will always
be available even on a stripped kernel.

This is mostly stolen from load_aout.c with some ideas from
alpha/libalpha/elf_freebsd.c.