Commit Graph

459 Commits

Author SHA1 Message Date
Andrey V. Elsukov
584a9cf8bf Since we didn't break the loop, we should set i to -1 to start from the
beginning.

Submitted by:	Steven Hartland
MFC after:	1 week
2013-04-21 09:10:35 +00:00
Andriy Gapon
a77cf1025c strncmp for boot code: fix an off by one error
Before this change strncmp would access and _compare_ n+1 characters
in the case where the first n characters match.

MFC after:	5 days
2013-04-05 09:14:30 +00:00
Ian Lepore
7554e820bb 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.
2013-03-10 00:43:01 +00:00
Ian Lepore
dd9b8b36dd 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.
2013-03-09 23:05:19 +00:00
Ian Lepore
62e939ea17 Fix a typo that prevented booting a kernel that had virtual addresses in
the elf headers.
2013-02-27 19:59:41 +00:00
Ian Lepore
c6f9cfb723 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.
2013-02-26 03:24:45 +00:00
Tim Kientzle
6d4a620eba Fix the bug I introduced in r247045.
After digging through more carefully, it looks like there's
no real need to have the DTB in the module directory.
So we can simplify a lot:  Just copy DTB into local heap
for "fdt addr" and U-Boot integration, drop all the extra
COPYIN() calls.

I've left one final COPYIN() to update the in-kernel DTB
for consistency with how this code used to work, but I'm
no longer convinced it's appropriate here.

I've also remove the mem_load_raw() utility that I added
to boot/common/module.c with r247045 since it's no longer
necessary.
2013-02-25 01:50:04 +00:00
Tim Kientzle
3e256ed764 Add mem_load_raw() for loading data from another location in memory.
This will be used by some upcoming changes to loader(8) FDT
handling to allow it to use an FDT provided by an earlier
boot stage the same as an FDT loaded from disk.
2013-02-18 23:13:13 +00:00
Andrey V. Elsukov
c6e31e81e0 Add bootcamp support to the loader.
Tested by:	dchagin
MFC after:	1 week
2013-02-10 19:27:17 +00:00
Peter Grehan
fc1ae0bc42 Bring in some userboot changes from the bhyve branch to reduce diffs.
r238966
  Bump up the heap size to 1MB. With a few kernel modules, libstand
  zalloc and userboot seem to want to use ~600KB of heap space, which
  results in a segfault when malloc fails in bhyveload.

r241180
  Clarify comment about default number of FICL dictionary cells.

r241153
  Allow the number of FICL dictionary cells to be overridden.
  Loading a 7.3 ISO with userboot/amd64 takes up 10035 cells,
  overflowing the long-standing default of 10000.

  Bump userboot's value up to 15000 cells.

Reviewed by:	dteske (r238966,241180)
Obtained from:	NetApp
2013-01-08 03:27:37 +00:00
Devin Teske
6674efd728 Hook in new files menusets.4th and manual.
Approved by:	adrian (co-mentor) (implicit)
2012-11-07 02:14:03 +00:00
Alexander Motin
f7203ece6d Fix loader crash when some unhalted exception happens during include
command execution.  In case of such unhandled exception, vmReset() inside
ficlExecC() flushes the VM state.  Attempt to return back to Forth after
that cause garbage dereference with unexpected results.  To avoid that
situation call vmThrow() directly instead of expecting Forth to do it.
2012-10-26 16:32:20 +00:00
Alexander Motin
572dc5cfc5 Remove new-line characters from the include() errors to make it consistent
with the rest of code.
2012-10-25 15:45:32 +00:00
Andrey V. Elsukov
f06e6159c3 When loader tries to open GPT partition, but partition table is not GPT,
then try automatically detect an appropriate partition type.

PR:		kern/172550
Tested by:	Ralf Wenk
2012-10-22 11:01:43 +00:00
Andrey V. Elsukov
9add094157 Add the flags parameter to the disk_open() function and DISK_F_NOCACHE
flag, that disables the caching of partition tables metadata.
Use this flag for floppies in the libi386/biosdisk driver.
2012-10-21 12:14:58 +00:00
Andriy Gapon
4ecbcb6f49 boot/console: handle consoles that fail to probe
- clarify meaning of console flags
- perform i/o via a console only if both of the following conditions are met:
   o console is active (selected by user or config)
   o console flags that it can perform the operation
- warn if a chosen console can not work (the warning may go nowhere without
  working and active console, though)

Reviewed by:	jhb
Tested by:	Uffe Jakobsen <uffe@uffe.org>,
		Olivier Cochard-Labbe' <olivier@cochard.me>
MFC after:	26 days
2012-10-06 20:01:17 +00:00
Andrey V. Elsukov
04773e8b75 Fix the style. 2012-09-30 13:17:33 +00:00
Andrey V. Elsukov
b3651aad67 Remember the file format of the last loaded module and try to use it for
next files.
2012-09-30 13:14:37 +00:00
Andrey V. Elsukov
089afddef4 Fix disk_cleanup() to work without DISK_DEBUG too. 2012-09-30 07:52:40 +00:00
Andrey V. Elsukov
f9cd8b07a4 Almost each time when loader opens a file, this leads to calling
disk_open(). Very often this is called several times for one file.
This leads to reading partition table metadata for each call. To
reduce the number of disk I/O we have a simple block cache, but it
is very dumb and more than half of I/O operations related to reading
metadata, misses this cache.

Introduce new cache layer to resolve this problem. It is independent
and doesn't need initialization like bcache, and will work by default
for all loaders which use the new DISK API. A successful disk_open()
call to each new disk or partition produces new entry in the cache.
Even more, when disk was already open, now opening of any nested
partitions does not require reading top level partition table.
So, if without this cache, partition table metadata was read around
20-50 times during boot, now it reads only once. This affects the booting
from GPT and MBR from the UFS.
2012-09-29 16:47:56 +00:00
Andrey V. Elsukov
88a0dd24bf Make the loader a bit smarter, when it tries to open disk and the slice
number is not exactly specified. When the disk has MBR, also try to read
BSD label after ptable_getpart() call. When the disk has GPT, also set
d_partition to 255.  Mostly, this is how it worked before.
2012-09-28 10:49:41 +00:00
Andreas Tobler
777813c555 Implement elfN(reloc) for powerpc. With this change the kernel is now able to
resolve dependencies of modules at boot time and load additional modules when
needed.

MFC after:	1 week
2012-09-21 18:21:31 +00:00
Tim Kientzle
181abccb96 The MBR data is not necessarily aligned. This is a problem on ARM. 2012-09-14 05:24:06 +00:00
Andriy Gapon
c0e2226ce5 boot: file_loadraw should strdup name argument
... the same way it's done for type argument.

MFC after:	2 weeks
2012-09-11 06:18:36 +00:00
Andreas Tobler
85fdca2d85 Fix loading of kernel modules at boot time for powerpc64.
Reported by:	Mathias Breuninger
MFC after:	1 week
2012-09-08 20:00:31 +00:00
Andrey V. Elsukov
a05f1f2028 Add comment why the code has been disabled.
Requested by:	rpaulo
2012-08-16 06:45:58 +00:00
Andrey V. Elsukov
4b81189aff Some BIOSes return incorrect number of sectors, make checks less
strictly, to do not lost some partitions.

Reported by:	swills@
2012-08-15 12:01:13 +00:00
Andrey V. Elsukov
deafa47873 Rework r239232 to unbreak ZFS detection on MBR slices. 2012-08-15 10:11:29 +00:00
Dag-Erling Smørgrav
e2082935f0 As discussed on -current, remove the hardcoded default maxswzone.
MFC after:	3 weeks
2012-08-14 17:01:21 +00:00
Andrey V. Elsukov
9131425146 Restore the old behaviour. If requested partition is a BSD slice,
but d_partition isn't explicitly set, then try to open BSD label and its
first partition.
2012-08-13 13:33:21 +00:00
Andrey V. Elsukov
baf3d8bfeb Remove colons from the debug message, device name returned by the
disk_fmtdev() already has the colons.
2012-08-13 13:10:50 +00:00
Andrey V. Elsukov
42b577fe76 Unbreak booting from the true dedicated disks.
When we open the disk, check the type of partition table, that has
been detected. If this is BSD label, then we assume this is DD mode.

Reported by:	dim@
2012-08-13 13:08:30 +00:00
Andrey V. Elsukov
e6232c0dea Add more debug messages. 2012-08-12 14:16:21 +00:00
Andrey V. Elsukov
06f2b92916 As it turned out, there are some installations, where BSD label
contains partitions with type zero. And it has worked.
So, allow detect these partitions.

Reported by:	glebius
2012-08-07 09:22:46 +00:00
Andrey V. Elsukov
a2bdef2a84 Fix start offset calculation for the EBR partitions. 2012-08-06 08:54:06 +00:00
Andrey V. Elsukov
2c6f04dc0a Introduce new API to work with disks from the loader's drivers.
It uses new API from the part.c to work with partition tables.

Update userboot's disk driver to use new API. Note that struct
loader_callbacks_v1 has changed.
2012-08-05 12:15:15 +00:00
Andrey V. Elsukov
a0ff532148 Create the interface to work with various partition tables from the
loader(8). The following partition tables are supported: BSD label, GPT,
MBR, EBR and VTOC8.
2012-08-05 11:29:44 +00:00
John Baldwin
32abc7ddc1 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
2012-06-20 21:06:51 +00:00
Gleb Kurtsou
491a40587d Use 32-bit ufs_ino_t instead of ino_t to keep boot2 small and prevent
unnecessary 64-bit math on 32-bit machines.

Sponsored by:	Google Summer of Code 2011
2012-05-25 09:36:39 +00:00
Warren Block
344c81a166 Fixes to man8 groff mandoc style, usage mistakes, or typos.
PR:		168016
Submitted by:	Nobuyuki Koganemaru
Approved by:	gjb
MFC after:	3 days
2012-05-24 02:24:03 +00:00
Andriy Gapon
0da23ac99d zfs boot: try to set vfs.root.mountfrom from currdev as a fallback
This way with the new zfsloader there is no need to explicitly set zfs
root filesystem either via vfs.root.mountfrom or fstab.
It should be automatically picked up from currdev which is by default
is set from bootfs.

Tested by:	Florian Wagner <florian@wagner-flo.net> (x86)
MFC after:	1 month
2012-05-12 09:07:41 +00:00
Andriy Gapon
1702e62f67 zfsboot/zfsloader: support accessing filesystems within a pool
In zfs loader zfs device name format now is "zfs:pool/fs",
fully qualified file path is "zfs:pool/fs:/path/to/file"
loader allows accessing files from various pools and filesystems as well
as changing currdev to a different pool/filesystem.

zfsboot accepts kernel/loader name in a format pool:fs:path/to/file or,
as before, pool:path/to/file; in the latter case a default filesystem
is used (pool root or bootfs).  zfsboot passes guids of the selected
pool and dataset to zfsloader to be used as its defaults.

zfs support should be architecture independent and is provided
in a separate library, but architectures wishing to use this zfs support
still have to provide some glue code and their devdesc should be
compatible with zfs_devdesc.
arch_zfs_probe method is used to discover all disk devices that may
be part of ZFS pool(s).

libi386 unconditionally includes zfs support, but some zfs-specific
functions are stubbed out as weak symbols.  The strong definitions
are provided in libzfsboot.
This change mean that the size of i386_devspec becomes larger
to match zfs_devspec.

Backward-compatibility shims are provided for recently added sparc64
zfs boot support.  Currently that architecture still works the old
way and does not support the new features.

TODO:
- clear up pool root filesystem vs pool bootfs filesystem distinction
- update sparc64 support
- set vfs.root.mountfrom based on currdev (for zfs)

Mid-future TODO:
- loader sub-menu for selecting alternative boot environment

Distant future TODO:
- support accessing snapshots, using a snapshot as readonly root

Reviewed by:	marius (sparc64),
		Gavin Mu <gavin.mu@gmail.com> (sparc64)
Tested by:	Florian Wagner <florian@wagner-flo.net> (x86),
		marius (sparc64)
No objections:	fs@, hackers@
MFC after:	1 month
2012-05-12 09:03:30 +00:00
Andriy Gapon
5ef10e566c sys/boot: add common CTASSERT definition 2012-05-09 07:55:42 +00:00
Marius Strobl
1a7f270047 Add multiple inclusion protection.
PR:		165025
Submitted by:	Gavin Mu
MFC after:	1 week
2012-04-29 15:54:40 +00:00
Andrey V. Elsukov
9dd5659756 Read backup GPT header from the last LBA only when primary GPT header and
table aren't valid. If they are ok, use hdr_lba_alt value to read backup
header. This will make gptboot happy when GPT used atop of some GEOM
provider, e.g. GEOM_MIRROR.

Reviewed by:	pjd
MFC after:	2 weeks
2012-04-12 12:37:53 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Marius Strobl
f7b9ae0882 Remove second consts in r233288 in order to appease C++ compilers.
While at it, remove some style(9) bugs in libkern.h.

Submitted by:	kan
2012-03-26 18:22:04 +00:00
Marius Strobl
cc0c154ffb Declare the CRC lookup-tables const as they hardly should change at
run-time.
2012-03-21 20:55:21 +00:00
Marius Strobl
6c2b936bbb Declare some variables static in order to reduce the object size and
redo r232822 in a less hackish way. The latter now no longer breaks
compiling the x86 boot2 with clang.

MFC after:	1 week
2012-03-18 02:19:30 +00:00
Marius Strobl
fe245df2da Fix a bug introduced in r223938; on big-endian machines coping a 32-bit
quantum bytewise to the address of a 64-bit variable results in writing
to the "wrong" 32-bit half so adjust the address accordingly. This fix
is implemented in a hackish way for two reasons:
o in order to be able to get it into 8.3 with zero impact on the little-
  endian architectures where this bug has no effect and
o to avoid blowing the x86 boot2 out of the water again when compiling
  it with clang, which all sane versions of this fix tested do.
This change fixes booting from UFS1 file systems on big-endian machines.

MFC after:	3 days
2012-03-11 13:39:19 +00:00