Commit Graph

52 Commits

Author SHA1 Message Date
Warner Losh
a7fa2fb669 LOADER_foo_SUPPORTED 2017-10-16 03:59:52 +00:00
Warner Losh
6b9f688352 Move all the ficl common code into ficl.mk
There's a number of copies of basically identical code to enable
building forth in /boot/loader. Move it all into ficl.mk.
2017-10-16 03:59:44 +00:00
Warner Losh
7f20726e4b Move common/Makefile.inc to sys/boot/loader.mk.
Makefile.inc has a specific meaning in the tree, and
common/Makefile.inc doesn't quite fit into that. Rename it to
loader.mk and it will be a place to collect common things to all
/boot/loader programs there.

Sponsored by: Netflix
2017-10-16 03:59:28 +00:00
Warner Losh
a37f4eb659 Define prototype for exit and ensure references
Define a prototype for exit in stand.h. Provide a reference to exit in
a few conf.c files to ensure that its definition gets pulled in early.
Since exit() is a MD routine, it isn't defined in libsa. However,
libsa tends to be listed last and will soon have panic() in it which
calls exit(). The reference to exit early ensures that the MD exit is
available to satisfy linking for static libraries.
2017-10-12 15:16:22 +00:00
Warner Losh
b9b9a7c3a2 Rather than laying whack-a-mole with including the path to stand.h,
always include it. Remove places where we explicitly include it. This
also helps reduce the 'cut-and-paste' factor of these Makefiles.

Sponsored by: Netflix
2017-10-10 01:31:44 +00:00
Warner Losh
8f409b435a Define LIBSA* and use them instead of overloaded LIBSTAND
LIBSA is the current stand alone library. LIBSA32 is the 32-bit
version of the library. LIBSAU is the userboot version of libsa. Use
the proper define instead of the more generic define.

Sponsored by: Netflix
2017-10-09 22:12:46 +00:00
Warner Losh
eca8b9c449 Define SASRC and use it
Define SASRC to point to the current libstand sources. Include
../Makefile.inc early enough in a few places so we can .include
"${SASRC}/Makefile" and have it work. Create a new pass-up
Makefile.inc in sys/boot/userboot to allow this pattern to work.

Sponsored by: Netflix
2017-10-09 22:12:32 +00:00
John Baldwin
a0320759e7 Pass -N directly to ld via -Wl rather than passing it to the compiler driver.
In particular, clang doesn't accept -N.

Obtained from:	CheriBSD
Sponsored by:	DARPA / AFRL
2017-05-23 17:41:09 +00:00
Toomas Soome
c9296b3227 loader: F_READ/F_WRITE should be checked against masked flag
The work to make it possible to avoid bcache via using F_NORA modifier did
miss the fact that not all loader platforms are using the bcache, and so
it is possible the modifier is not cleared, as bcache strategy function is
not used.

For fix, we make sure the checks are dont with masked flag.

This patch does fix boot for platforms which do not use bcache.

Reported by:	emaste
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D10422
2017-04-18 18:07:54 +00:00
Toomas Soome
b91aad35da loader: remove open_disk cache
As we provide the disk size verification and correction via disk_ioctl
and disk state provided by disk_open(), we can not share the partition
state in disk_devdesc structure. Also the sharing does make a lot of sense
with ufs, as only one partition is open at any given time, but zfs pools
do keep the disk devices open.

To make sure we do get the correct information about the open device,
just remove the cache.

Reviewed by:	allanjude, smh
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9757
2017-03-16 12:04:43 +00:00
John Baldwin
0049360352 Use LDFLAGS with CC instead of _LDFLAGS.
This is a followup to r311458.  _LDFLAGS is for use with LD, whereas
LDFLAGS is for use with CC.
2017-02-22 23:58:54 +00:00
Brooks Davis
a692daff31 Remove "-Xassembler -G0" from CFLAGS.
-G0 is sufficent except on old version of clang (<3.8) and such versions
are unlikely to be generally useful on mips64.

Reported by:	sbruno
Sponsored by:	DARPA, AFRL
2017-01-29 11:52:36 +00:00
Alexander Kabaev
f20a27e327 Use compiler driver to link BERI boot loaders
Do not hardcode elf64-tradbigmips as output format in BERI linker scrips.
Unfortunately, in-tree toolchain and external newer versions of binutils
mean two different things under that. When creating elf binaries using
external toolchain, gcc uses elf64-tradbigmips-freebsd and so linker
script file has to match in order for ld to be able to create the final loader
binary.

Rather than trying to guess, remove hardcoded output format directive from
the linker directive files and use CC to invoke the linker instead.

Reviewed by:	brooks
Differential Revision:	https://reviews.freebsd.org/D9050
2017-01-05 19:17:14 +00:00
Toomas Soome
1ecc859193 dosfs support in libstand is broken since r298230
Apparently the libstand dosfs optimization is a bit too optimistic
and did introduce possible memory corruption.

This patch is backing out the bad part and since this results in
dosfs reading full blocks now, we can also remove extra offset argument
from dv_strategy callback.

The analysis of the issue and the backout patch is provided by Mikhail Kupchik.

PR:		214423
Submitted by:	Mikhail Kupchik
Reported by:	Mikhail Kupchik
Reviewed by:	bapt, allanjude
Approved by:	allanjude (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D8644
2016-12-30 19:06:29 +00:00
Ed Maste
bc814587a9 Deduplicate loader vers.c Makefile rules
The Makefile rule to create vers.c for loader version info was
previously duplicated in each of the various loader Makefiles.
Instead, share a common rule in Makefile.inc.

Reviewed by:	bapt
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8841
2016-12-19 14:40:59 +00:00
Ed Maste
0bf23e313e Reduce boot loader version string duplication
Instead of repeating "%s, Revision %s" "(%s %s)" in each loader, just
create the full version string in vers.c

Reviewed by:	bapt
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8823
2016-12-18 13:57:23 +00:00
Toomas Soome
77d81a4dab lsdev device name section headers should be printed by dv_print callback.
lsdev command does walk over devsw list, prints list element name and
will use dv_print() callback to print the device list.
Unfortunately this approach will add unneeded noise when there are no
particular devices detected.

To remove "empty" device section headers, the dv_print() callback
should print the header instead.

In addition, fixed dv_print callback for md module.

Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D8551
2016-11-19 08:54:21 +00:00
Toomas Soome
00dbeb59ad loader: beri_sdcard_disk_print() needs to return int.
The https://reviews.freebsd.org/rS308434 did change the return type for
dv_print callbacks, but the return type for beri_sdcard_disk_print()
was left unchanged, causing compile errors.

Reported by:	cy
Reviewed by:	brooks, rstone, allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D8515
2016-11-17 18:38:35 +00:00
Toomas Soome
cbd6713146 Loader paged/pageable data is not always paged.
This change does modify devsw dv_print() to return the int value,
enabling walkers to interrupt the walk on non zero value from dv_print().

This will allow the pager_print actually to stop displaying data on
user input, and additionally pager is used in various *dev_print callbacks,
where it was missing.

For test, lsdev [-v] command should display data by screenfuls and should
stop when the key 'q' is pressed on pager prompt.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D5461
2016-11-08 06:50:18 +00:00
Ruslan Bukin
5bca221511 Add full softfloat and hardfloat support for MIPS.
This adds new target architectures for hardfloat:
mipselhf mipshf mips64elhf mips64hf.

Tested in QEMU only.

Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D8376
2016-10-31 15:33:58 +00:00
Warner Losh
a2cb5fddcd Create a new linker set, Xficl_compile_set which contains a list of
functions to call at the appropriate time to register new forth
words. In the past we've done this with ifdef soup, but now if the
file is included in the build, we'll get the new forth words.

Use this new functionality to move the pci bios stuff out of loader.c
by moving it to biospci.c.

Move the pnp functionality to common/pnp.c.

Move the inb/outb forth words to the i386 sysdep.c file where their
implementation is defined.

Adjust the efi linker scripts and build machinery to cope.

his should be an invisible change to forth scripts and user
experience.

Differential Revision: https://reviews.freebsd.org/D8145
2016-10-14 16:23:12 +00:00
Baptiste Daroussin
1b46e63d3c Stop closing the network device when netbooting for loaders using the common
dev_net.c code.

The NETIF_OPEN_CLOSE_ONCE flag was added in r201932 to prevent that behaviour
on some architectures (sparc64 and powerpc64) the default was left to always
open and close the device for each open and close of a file by the loader
because it was necessary for u-boot on arm.

Since it has been added, the flag was turned on for every arches including the
u-boot loader for arm.

This also fixes netbooting on RPi3 (tested by gonzo@)

For the loader.efi it greatly speeds up netbooting

Reviewed by:	emaste, gonzo, tsoome
Approved by:	gonzo
MFC after:	1 month
Sponsored by:	Gandi.net
Differential Revision:	https://reviews.freebsd.org/D8230
2016-10-13 22:43:49 +00:00
Ed Maste
8aa5c6cfeb remove CONSTRUCTORS from MIPS uboot linker script
The linker script CONSTRUCTORS keyword is only meaningful "when linking
object file formats which do not support arbitrary sections, such as
ECOFF and XCOFF"[1] and is ignored for other object file formats.

LLVM's lld does not yet accept (and ignore) CONSTRUCTORS, so just remove
CONSTRUCTORS from the linker script as it has no effect.

[1] https://sourceware.org/binutils/docs/ld/Output-Section-Keywords.html
2016-09-03 13:01:37 +00:00
Pedro F. Giffuni
d9c9c81c08 sys: use our roundup2/rounddown2() macros when param.h is available.
rounddown2 tends to produce longer lines than the original code
and when the code has a high indentation level it was not really
advantageous to do the replacement.

This tries to strike a balance between readability using the macros
and flexibility of having the expressions, so not everything is
converted.
2016-04-21 19:57:40 +00:00
Pedro F. Giffuni
2464bbf05a sys/boot: use our nitems() macro when it is available through param.h.
No functional change, only trivial cases are done in this sweep,

Discussed in:	freebsd-current
2016-04-19 23:44:33 +00:00
Allan Jude
87ed2b7f5a A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.

Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.

Submitted by:	Toomas Soome <tsoome@me.com>
Reviewed by:	delphij (previous version), emaste (previous version)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
Stanislav Galabov
a1b701d82b This review aims at introducing ubldr (loader with U-Boot interface) for MIPS
(32 and 64-bit, LE and BE).
The changes were tested with QEMU's 'mips' target.

Most of the implementation was lifted from the ARM version, the appropriate
MIPS-specific things were implemented.

With these changes I am able to go all the way through the u-boot->ubldr->kernel
boot chain in QEMU on all combinations of bit-ness and endian-ness.

For the tests I've used FAT32 disk images (as FAT32 is supported by U-boot),
which include /boot/kernel/kernel and /boot/kernel/ubldr.bin

In U-boot I do:
fatload ide 0 <LOAD_ADDR> /boot/kernel/ubldr.bin; go <LOAD_ADDR>
where LOAD_ADDR is 80800000 for 32-bit and ffffffff80800000 for 64-bit

Then it's the usual ubldr that takes over and loads and starts a kernel.

Approved by:	adrian (mentor)
Sponsored by:	Smartcom - Bulgaria AD
Differential Revision:	https://reviews.freebsd.org/D5313
2016-02-29 07:47:04 +00:00
Stanislav Galabov
8b2db3b713 Currently BERI's loader is including the 32-bit version of the FICL MIPS sysdep.h (sys/boot/ficl/mips/sysdep.h) instead of the 64-bit version (sys/boot/ficl/mips64/sysdep.h).
Although this may not be an issue in practice, it would be more correct if the 64-bit version was used. Also, using the 64-bit version would make it easier to add support for 64-bit ubldr on MIPS.

Approved by:	adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D5310
2016-02-26 08:06:25 +00:00
Warner Losh
6422ac8292 Fix mistake when transitioning to the new defines with ZFS loader. I
hate adding yet another define, but it is the lessor of the evil
choices available. Kill another evil by removing PATH_BOOT3 and
replacing it with PATH_LOADER or PATH_LOADER_ZFS as appropriate.

PR: 206659
2016-01-27 16:36:18 +00:00
Warner Losh
545ed21a78 Remove static from these two. They slipped through the cracks.
MFC After: 1 week
2016-01-26 18:39:30 +00:00
Warner Losh
5063232c10 RBX_ defines are in rbx.h, move it there.
Differential Revision: https://reviews.freebsd.org/D5038
2016-01-26 06:26:44 +00:00
Warner Losh
5bbc34e185 Move all the separate copies of the same strings into paths.h. There's
nothing machine specific about these.

Differential Revision: https://reviews.freebsd.org/D5038
2016-01-26 06:26:19 +00:00
Ed Maste
7a73d15e90 Increase BERI boot components section alignment to 16
The .text, .bss, and .data sections claimed 16-byte alignment, but were
only aligned to 8 by the linker script.

Discovered with elfcopy(1) from elftoolchain, which performs validation
absent from the binutils strip(1). ELF tool chain ticket #512.

Reported by:	brooks
Reviewed by:	brooks
Sponsored by:	DARPA, AFRL
2016-01-20 18:35:43 +00:00
Allan Jude
9322ac3f6e Remove guards around overwriting loader.rc and menu.rc
There have been .local version of each for user modifications for some time
This allows users to receive future updates to these files

PR:		183765
Submitted by:	Bertram Scharpf, Nikolai Lifanov (patch)
Reviewed by:	dteske, loos, eadler
Approved by:	bapt (mentor)
MFC after:	1 month
Relnotes:	yes
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3176
2015-08-06 16:07:27 +00:00
Baptiste Daroussin
27823c59c5 Fix fallouts from r284590
Reported by:	kib
2015-06-19 14:20:21 +00:00
Jung-uk Kim
33962e683d Fix mips build, really. :-( 2015-04-03 02:31:59 +00:00
Jung-uk Kim
11823c5f1e Revert .PATH changes to fix mips build.
Reported by:	bz
Pointy hat to:	jkim
2015-04-03 02:27:40 +00:00
Jung-uk Kim
bf64b1d71c Install newly added brand-*.4th and logo-*.4th files and reduce duplication.
Reviewed by:	dteske
Pointy hat to:	dteske
2015-04-02 20:07:05 +00:00
Dimitry Andric
76e2c537bc Ensure the cross assembler, linker and objcopy are used for the build32
stage, just like for the regular world stage.

Reviewed by:	rodrigc, imp, bapt, emaste
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D2187
2015-04-02 06:58:17 +00:00
Ed Maste
672aa7f472 Increase BERI loader section alignment to 16
The .text, .bss, and .data sections claimed 16-byte alignment, but were
only aligned to 8 by the linker script.

Discovered with strip(1) from elftoolchain, which performs validation
absent from the binutils strip(1).

Sponsored by:	DARPA, AFRL
2014-12-03 14:04:57 +00:00
Bryan Drewery
5608fd23c2 Revert r267233 for now. PIE support needs to be reworked.
1. 50+% of NO_PIE use is fixed by adding -fPIC to INTERNALLIB and other
   build-only utility libraries.
2. Another 40% is fixed by generating _pic.a variants of various libraries.
3. Some of the NO_PIE use is a bit absurd as it is disabling PIE (and ASLR)
   where it never would work anyhow, such as csu or loader. This suggests
   there may be better ways of adding support to the tree. Many of these
   cases can be fixed such that -fPIE will work but there is really no
   reason to have it in those cases.
4. Some of the uses are working around hacks done to some Makefiles that are
   really building libraries but have been using bsd.prog.mk because the code
   is cleaner. Had they been using bsd.lib.mk then NO_PIE would not have
   been needed.

We likely do want to enable PIE by default (opt-out) for non-tree consumers
(such as ports). For in-tree though we probably want to only enable PIE
(opt-in) for common attack targets such as remote service daemons and setuid
utilities. This is also a great performance compromise since ASLR is expected
to reduce performance. As such it does not make sense to enable it in all
utilities such as ls(1) that have little benefit to having it enabled.

Reported by:	kib
2014-08-19 15:04:32 +00:00
Marcel Moolenaar
7fe0b4f160 Give loaders more control over the Forth initialization process. In
particular, allow loaders to define the name of the RC script the
interpreter needs to use. Use this new-found control to have the
PXE loader (when compiled with TFTP support and not NFS support)
read from ${bootfile}.4th, where ${bootfile} is the name of the
file fetched by the PXE firmware.

The normal startup process involves reading the following files:
1.  /boot/boot.4th
2.  /boot/loader.rc or alternatively /boot/boot.conf

When these come from a FreeBSD-defined file system, this is all
good. But when we boot over the network, subdirectories and fixed
file names are often painful to administrators and there's really
no way for them to change the behaviour of the loader.

Obtained from:	Juniper Networks, Inc.
2014-07-27 16:12:51 +00:00
Simon J. Gerraty
5b6dc2efc9 Reviewed by: imp
LDFLAGS is supposed to be given to CC not LD.
Define _LDFLAGS as a filtered version of LDFLAGS safe to give to LD
2014-07-26 04:38:09 +00:00
Bryan Drewery
864c53ead8 In preparation for ASLR [1] support add WITH_PIE to support building with -fPIE.
This is currently an opt-in build flag. Once ASLR support is ready and stable
it should changed to opt-out and be enabled by default along with ASLR.

Each application Makefile uses opt-out to ensure that ASLR will be enabled by
default in new directories when the system is compiled with PIE/ASLR. [2]

Mark known build failures as NO_PIE for now.

The only known runtime failure was rtld.

[1] http://www.bsdcan.org/2014/schedule/events/452.en.html
Submitted by:		Shawn Webb <lattera@gmail.com>
Discussed between:	des@ and Shawn Webb [2]
2014-06-08 17:29:31 +00:00
Hans Petter Selasky
b589760a6f Add optional support for USB to BERI loader. Fix the linker script so
that the garbage collection feature can be used when linking.

Sponsored by:	DARPA, AFRL
2014-05-30 16:47:54 +00:00
Hans Petter Selasky
6cdd2fc633 Fix delay() function in the BERI loader code.
Reviewed by:	brooks @
Sponsored by:	DARPA, AFRL
2014-05-30 13:53:37 +00:00
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Warner Losh
3bdf775801 NO_MAN= has been deprecated in favor of MAN= for some time, go ahead
and finish the job. ncurses is now the only Makefile in the tree that
uses it since it wasn't a simple mechanical change, and will be
addressed in a future commit.
2014-04-13 05:21:56 +00:00
Robert Watson
d4b64c8983 Build the BERI boot loader on 64-bit MIPS (but not 32-bit MIPS). While
these binaries aren't immediately useful on other MIPSes, still build them
as part of mips64 world in order to expose them to tinderbox.

MFC after:	3 weeks
Sponsored by:	DARPA, AFRL
2014-02-23 22:20:52 +00:00
Robert Watson
b1bdbe9d09 Temporarily unhook BERI boot loader from the build until 32-bit MIPS
properly excludes building our 64-bit only boot-loader adaptation.
2014-02-19 23:09:25 +00:00