Commit Graph

223 Commits

Author SHA1 Message Date
Toomas Soome
ca25195805 loader: crc32 is provided by libsa
Seems like leftover from moving crc32.c to libsa.
2020-03-04 18:38:09 +00:00
Warner Losh
a64f0b83e5 Move smbios.c to libsa.
smbios used to be an i386 only kinda weird quirk to the x86
architecture. But UEFI picked it up, dusted it off and now it's many
other locations. Make it base technology by moving it to libsa and
fixing up the compliation. The code has issues with unaligned access
still, but that will be addressed in a followup commit.

Differential Revision: https://reviews.freebsd.org/D23660
2020-02-20 00:46:22 +00:00
Warner Losh
ed2a65769a Create ptov() function.
Create a ptov() function. It's basically the same as the btx PTOV
macro, but works everywhere. smbios needs this to translate addresses,
but the translation differs between BIOS booting and EFI booting. Make
it a function so one smbios.o can be used everywhere. Provide
definitions for it in the two loaders affected.

Differential Revision: https://reviews.freebsd.org/D23660
2020-02-20 00:46:16 +00:00
Toomas Soome
7503958e4c zfsboot: vdev_read_pad2 does allocate buffer with wrong size
vdev_read_pad2() does read VDEV_PAD_SIZE of data, and will copy size bytes
of it, hence, we need buffer of VDEV_PAD_SIZE bytes.

Issue introduced in r357497.

Reported by:	se
2020-02-05 11:02:00 +00:00
Toomas Soome
a1746b2583 vdev_read_pad2: freeing wrong pointer
Shoud free previously allocated tmp buffer instead. Issue introduced in
r357497.

Reported by:	rpokala
2020-02-05 05:42:42 +00:00
Toomas Soome
4d297e7035 loader: rewrite zfs reader zap code to use malloc
First step on removing zfs_alloc.

Reviewed by:	delphij
Differential Revision:	https://reviews.freebsd.org/D23433
2020-02-04 07:37:55 +00:00
Toomas Soome
b0af1e20e6 loader: bc_add can not use any other probes than ah=0x4b
CD boot is broken for some systems since bioscd and biosdisk merge. The issue is that we can not use anything else than int 13 ah=0x4b to query cd information.

The patch does restore the same probe as was originally used in bioscd.c. Additionally extra buffer padding is used to avoid memory corruption caused by some systems.

PR:		234031
Reported by:	ultramage and others
MFC after:	1 day
2020-02-03 11:33:33 +00:00
Dimitry Andric
ae55765309 Work around assembler error from clang 10.0.0 in gptboot:
stand/i386/gptboot/gptldr.S:141:3: error: value of 36878 is too large for field of 2 bytes.
  jmp MEM_JMP # Start BTX
  ^

Use the same construct as in stand/i386/boot2/boot1.S, which ensures the
jump distance does not become too large.

MFC after:	3 days
2020-01-28 21:41:37 +00:00
Konstantin Belousov
2ee49fac82 Add support for Hygon Dhyana Family 18h processor.
As a new x86 CPU vendor, Chengdu Haiguang IC Design Co., Ltd (Hygon)
is a joint venture between AMD and Haiguang Information Technology Co.,
Ltd., aims at providing x86 processors for China server market.

The first generation Hygon processor(Dhyana) shares most architecture
with AMD's family 17h, but with different CPU vendor ID("HygonGenuine")
and PCI vendor ID(0x1d94) and family series number 18h(Hygon negotiated
with AMD to confirm that only Hygon use family 18h).

To enable Hygon Dhyana support in FreeBSD, add new definitions
HYGON_VENDOR_ID("HygonGenuine") and X86_VENDOR_HYGON(0x1d94) to identify
Hygon Dhyana CPU.

Initialize the CPU features(topology, local APIC ext, MSI, TSC, hwpstate,
MCA, DEBUG_CTL, etc) for amd64 and i386 mode by sharing the code path of
AMD family 17h.

The changes have been applied on FreeBSD 13.0-CURRENT and tested
successfully on Hygon Dhyana processor.

References:
[1] Linux kernel patches for Hygon Dhyana, merged in 4.20:

https://git.kernel.org/tip/c9661c1e80b609cd038db7c908e061f0535804ef

[2] MSR and CPUID definition:

https://www.amd.com/system/files/TechDocs/54945_PPR_Family_17h_Models_00h-0Fh.pdf

Submitted by:	Pu Wen <puwen@hygon.cn>
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D23163
2020-01-21 13:22:35 +00:00
Toomas Soome
aaeffe5b70 Backout 356693. The libsa malloc does provide necessary alignment and
memalign by 4 will reduce alignment for some platforms. Thanks for Ian for
pointing this out.
2020-01-13 20:02:27 +00:00
Toomas Soome
659bf32dfc loader: allocate properly aligned buffer for network packet
Use memalign(4, size) to ensure we have properly aligned buffer.

MFC after:	2 weeks
2020-01-13 18:22:54 +00:00
Toomas Soome
20698d1531 loader: bioscd probe can get sector size 0
With buggy BIOS, it may happen we get sector size reported 0 for cd, and then
the default 512 is used, which is quite wrong.

PR:		238749
2020-01-09 21:21:08 +00:00
Ian Lepore
42e08952bb In gptboot, don't assume a partition number is a single digit, 1-9. GPT
partitions can have 128 partitions, so parse contiguous digits and then
validate that the number is between 1-128 inclusive.

I'm not sure 128 is a hard limit in the GPT standard, but it's the common
number in use, and it's a better upper limit than 9.
2019-12-22 22:33:22 +00:00
Dimitry Andric
0b57cec536 Move all sources from the llvm project into contrib/llvm-project.
This uses the new layout of the upstream repository, which was recently
migrated to GitHub, and converted into a "monorepo".  That is, most of
the earlier separate sub-projects with their own branches and tags were
consolidated into one top-level directory, and are now branched and
tagged together.

Updating the vendor area to match this layout is next.
2019-12-20 19:53:05 +00:00
Warner Losh
7f5499972e Use symbolic names for int13 calls
For all the INT13 calls, use symbolic names instead of magic numbers. This makes
it easier to understand what the code is doing w/o a trip to google to find what
these numbers mean.
2019-12-16 21:52:12 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Toomas Soome
1113c41fef cstyle cleanup for i386_copy.c
No functional changes are intended.
2019-11-08 12:19:03 +00:00
Toomas Soome
e499793e76 Remove duplicate lz4 implementations
Port illumos change: https://www.illumos.org/issues/11667

Move lz4.c out of zfs tree to opensolaris/common/lz4, adjust it to be
usable from kernel/stand/userland builds, so we can use just one single
source. Add lz4.h to declare lz4_compress() and lz4_decompress().

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D22037
2019-11-02 12:28:04 +00:00
Toomas Soome
0060947db1 loader: libi386/comconsole.c cstyle cleanup
Only cstyle, no functional changes.
2019-11-02 10:53:23 +00:00
Warner Losh
08b86a1a8a We don't support configuring serial PCI cards in EFI. Make this clearer in the
source rather than obfuscaring it behind NO_PCI (nothing else declares that,
so it's not making the ifdefs clearer).
2019-11-01 21:26:43 +00:00
Simon J. Gerraty
e9b148a318 Add support for hypervisor check on x86
Add ficl words for isvirtualized
and move ficl inb and outb words to ficl/x86/sysdep.c
so can be shared by i386 and amd64

Reviewed by:	imp bdrewery
MFC after:	1 week
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org/D22069
2019-10-24 20:02:48 +00:00
Toomas Soome
8074c5cc86 loader: fix indentation in efi_console and vidconsole
Remove extra tab.

Reported by:	yuripv
2019-09-25 07:36:35 +00:00
Toomas Soome
233ab015c0 loader: add teken.fg_color and teken.bg_color variables
Add settable variables to control teken default color attributes.
The supported colors are 0-7 or basic color names:
black, red, green, brown, blue, magenta, cyan, white.

The current implementation does add some duplication which will be addressed
later.
2019-09-25 07:09:25 +00:00
Toomas Soome
e7da26b6ca loader: vidconsole should set LINES and COLUMNS
Set LINES and COLUMNS based on terminal dimensions.
2019-09-10 21:53:42 +00:00
Toomas Soome
094b40659f loader: --gc-sections needs sections to work with
--gc-sections is not really useful unless we generate sections with
-ffunction-sections -fdata-sections

While there, i386/loader would win from --gc-sections too.
2019-09-08 19:39:45 +00:00
Toomas Soome
56758831fe loader: use teken teminal emulator for x86 and uefi
Replace mini cons25 emulator with teken, this does enable us proper console
terminal for loader and will make it possible to implement different
back end callbacks to draw to screen.

At this time we still only "draw" in text mode.
2019-09-05 22:15:50 +00:00
Kyle Evans
e1aa7047af stand: boot2: fix amd64-xtoolchain-gcc build
-Wno-missing-declarations is the GCC equivalent of
-Wno-missing-prototypes... this was overlooked in r351135.

MFC after:	3 days
X-MFC-With:	r351135
2019-08-23 01:16:12 +00:00
Kyle Evans
37ac567ea7 stand: boot2: fix build with xtoolchain-llvm90
ufsread.c grows a dependency on __ashldi3 with llvm90. Grab ashldi3.c out of
compiler-rt rather than trying to link against libsa (for now).
-Wno-missing-prototypes is necessary to compile ashldi3.c standalone.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21291
2019-08-16 20:07:43 +00:00
Ed Maste
0a062e5ff6 gptzfsboot: remove CLANG_NO_IAS
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler did not handle .codeNN directives.  Clang gained
support quite some time ago, so we can build stand/ with IAS.

In some cases there were small differences in generated object output.
In the case of gptzfsboot however using GNU as or Clang IAS to assemble
gptldr.S resulted in identical final gptzfsboot binary output.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D11115
2019-08-15 18:43:01 +00:00
Ed Maste
aa2dd958b4 stand: remove CLANG_NO_IAS from pxeldr
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
pxeldr, so CLANG_NO_IAS was not previously removed for those.

In the case of pxeldr the difference is that IAS adds a size override
prefix (67h) to three instructions to specify a 32-bit address, even
though the two high bytes are zero and the address fits in 16 bits.
this wastes three bytes per instruction and causes some additional nop
npadding to be required elsewhere in the object, but pxeboot is not
size-constrained so it doesn't matter.

Sponsored by:	The FreeBSD Foundation
2019-08-15 17:59:22 +00:00
Ed Maste
1596e9a43c stand: remove CLANG_NO_IAS from cdboot
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
cdboot, so CLANG_NO_IAS was not previously removed for those.

In the case of cdboot the difference is that IAS adds a size override
prefix (67h) to many instructions to specify a 32-bit address, even
though the two high bytes are zero.  This wastes three bytes per
instance, but as cdboot is not size-constrained it doesn't matter.
Padding is also different in one case; Clang used two one-byte nops
while GNU as used a single two-byte xchg %eax, %eax.  In any case, there
is no functional change.

Sponsored by:   The FreeBSD Foundation
2019-08-15 17:32:39 +00:00
Ed Maste
3a6c85abcb stand: remove CLANG_NO_IAS from boot2
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
boot2, so CLANG_NO_IAS was not previously removed for those.

In the case of boot2 the difference is that IAS produces a larger
encoding for one instruction (the testb at the beginning of read).

GNU as produces:

    2e    f6 06 b0 08       80

while IAS includes an address size override prefix (67) and produces:

    2e 67 f6 05 b3 08 00 00 80

This results in three fewer NOPs elsewhere in boot2 but no functional
change, so switch to IAS for boot2.

(We can separately pursue improved 16-bit IAS support with the LLVM
developers.)

Sponsored by:	The FreeBSD Foundation
2019-08-15 14:54:18 +00:00
Toomas Soome
b1b9326846 loader: support com.delphix:removing
We should support removing vdev from boot pool. Update loader zfs reader
to support com.delphix:removing.

Reviewed by:	allanjude
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D18901
2019-08-08 18:08:13 +00:00
Marcin Wojtas
435672e322 Verify files loaded in chain command.
The chain command can be used to chain load another binary.
If veriexec is enabled we should verify it first.
Note that on EFI systems the verification was already done
through firmware, assuming that Secure Boot was enabled there.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: sjg
MFC after: 1 week
Obtained from: Semihalf
Differential Revision: https://reviews.freebsd.org/D20952
2019-08-08 17:03:30 +00:00
Warner Losh
f5a95d9a07 Remove NAND and NANDFS support
NANDFS has been broken for years. Remove it. The NAND drivers that
remain are for ancient parts that are no longer relevant. They are
polled, have terrible performance and just for ancient arm
hardware. NAND parts have evolved significantly from this early work
and little to none of it would be relevant should someone need to
update to support raw nand. This code has been off by default for
years and has violated the vnode protocol leading to panics since it
was committed.

Numerous posts to arch@ and other locations have found no actual users
for this software.

Relnotes:	Yes
No Objection From: arch@
Differential Revision: https://reviews.freebsd.org/D20745
2019-06-25 04:50:09 +00:00
Warner Losh
de357a736d Eliminate unused uuid parameters from gptread and gptread_table. We
only need it for the gptfind() function, where it's used.
2019-06-05 02:34:58 +00:00
Warner Losh
63acab6a5b [zfsboot] Fix boot env back compat (#190)
* Fix boot env back compat

zfsboot must try zfsloader before loader in order to remain compatible
with boot environments created prior to zfs functionality being rolled
into loader proper.

* Improve comments in zfsboot

Explain the significance of the load path order, and put the comment
about looping through the paths in the appropriate scope.

Obtained From:  TrueNAS commit 4c60c62fcf0b6b6eac98ee8d46e7bbea64bc86f5
Submitted by: Ryan Moeller <ryan@freqlabs.com>
2019-06-03 19:10:46 +00:00
Xin LI
5e86bd6073 Remove kgzip and kgzldr.
PR:		183666, 229763
Submitted by:	Yoshihiro Ota <ota at j.email.ne.jp>
Differential Revision:	https://reviews.freebsd.org/D20248
2019-05-24 05:34:21 +00:00
Toomas Soome
82c29d4fde loader: use DPRINTF in biosdisk.c and define safe DPRINTF
r345066 did miss biosdisk.c.

Also define DPRINTF as ((void)0) for case we do not want debug printouts.

MFC after:	1 week
2019-05-09 13:12:43 +00:00
Toomas Soome
2a0e2c88db loader: no-TERM_EMU is broken now
If TERM_EMU is not defined, we do not have curx variable. Use conout mode
for efi and expose get_pos() for i386.
2019-05-09 12:14:52 +00:00
Toomas Soome
686d524bc9 loader: implement proper 8 char tab stops
The current console code is printing out 8 spaces for tab, calculate
the amount of spaces based on tab stops.
2019-05-09 10:37:57 +00:00
Ian Lepore
ba761eace4 Add a paragraph that mentions gptboot having an interactive mode, and
direct the user to the boot(8) manpage, which provides the details on that.
2019-04-30 18:48:20 +00:00
Toomas Soome
3a1f80e2d7 zfsboot: to detect disk size, use GPT information first
If we do have GPT on disk, read the disk size from it and do not
call int13.

Since int13 does report bogus informatiopn too often, rather trust the
partition table. We are using the same strategy with loader.

MFC after:	1 month
2019-04-30 17:45:22 +00:00
Toomas Soome
4914ee11ae loader: implement map-vdisk and unmap-vdisk commands
illumos update: https://www.illumos.org/issues/10598

Add map-vdisk and unmap-vdisk commands to create virtual disk interface on top of file. This will allow to use disk image from file system to load and start the kernel.

By mapping file, we create vdiskX device, the device will be listed by lsdev [-v] and can be accessed directly as ls vdisk0p1:/path or can be used as value for currdev variable.

vdisk strategy function does not use bcache as we have bcache used with backing file. vdisk can be unmapped when all consumers have closed the open files.

In first iteration we do not support the zfs images because zfs pools do keep the device open (there is no "zpool export" mechanism). Adding zfs support is relatively simple, we just need to run zfs disk probe after mapping is done.

Differential Revision:	https://reviews.freebsd.org/D19733
2019-04-26 17:58:44 +00:00
Ed Maste
698194ab24 stand: remove CLANG_NO_IAS from zfsldr
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.

Note that in some cases there are small differences in the generated
output, so CLANG_NO_IAS should be removed only after testing (or after
finding no differences in the output).  For zfsldr I compared objdump
output between GNU as- and Clang IAS-built zfsldr and .text was
identical (changes were limited to the object's ELF headers and debug
info).

Sponsored by:	The FreeBSD Foundation
2019-03-26 20:32:05 +00:00
Ian Lepore
14243f8de7 Distinguish between "no partition" and "choose best partition" with a constant.
The values of the d_slice and d_partition fields of a disk_devdesc have a
few values with special meanings in the disk_open() routine. Through various
evolutions of the loader code over time, a d_partition value of -1 has
meant both "use the first ufs partition found in the bsd label" and "don't
open a bsd partition at all, open the raw slice."

This defines a new special value of -2 to mean open the raw slice, and it
gives symbolic names to all the special values used in d_slice and
d_partition, and adjusts all existing uses of those fields to use the new
constants.

The phab review for this timed out without being accepted, but I'm still
citing it below because there is useful commentary there.

Differential Revision:	https://reviews.freebsd.org/D19262
2019-03-24 18:51:52 +00:00
John Baldwin
2e43efd0bb Drop "All rights reserved" from my copyright statements.
Reviewed by:	rgrimes
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19485
2019-03-06 22:11:45 +00:00
Simon J. Gerraty
8df8b2d3e5 Enable veriexec for loader
This relies on libbearssl and libsecureboot
to verify files read by loader in a maner equivalent
to how mac_veriexec

Note: disabled by default.
Use is initially expected to be by embeded vendors

Reviewed by:	emaste, imp
Sponsored by:	Juniper Networks
Differential Revision:	D16336
2019-02-26 06:22:10 +00:00
Patrick Kelsey
861729a32e Remove whole-disk vdev support from zfsboot
This is consistent with the removal of whole-disk vdev support from
libsa/zfs/zfs.c in r342151, and is part way to having the LBAs read
during probe be fully constrained by partition tables when present.

Reviewed by:	tsoome
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D19142
2019-02-17 03:52:44 +00:00
Ed Maste
bcf99d2d99 Add WITH_PIE knob to build Position Independent Executables
Building binaries as PIE allows the executable itself to be loaded at a
random address when ASLR is enabled (not just its shared libraries).

With this change PIE objects have a .pieo extension and INTERNALLIB
libraries libXXX_pie.a.

MK_PIE is disabled for some kerberos5 tools, Clang, and Subversion, as
they explicitly reference .a libraries in their Makefiles.  These can
be addressed on an individual basis later.  MK_PIE is also disabled for
rtld-elf because it is already position-independent using bespoke
Makefile rules.

Currently only dynamically linked binaries will be built as PIE.

Discussed with:	dim
Reviewed by:	kib
MFC after:	1 month
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18423
2019-02-15 22:22:38 +00:00
Warner Losh
52467047aa Regularize the Netflix copyright
Use recent best practices for Copyright form at the top of
the license:
1. Remove all the All Rights Reserved clauses on our stuff. Where we
   piggybacked others, use a separate line to make things clear.
2. Use "Netflix, Inc." everywhere.
3. Use a single line for the copyright for grep friendliness.
4. Use date ranges in all places for our stuff.

Approved by: Netflix Legal (who gave me the form), adrian@ (pmc files)
2019-02-04 21:28:25 +00:00
Oleksandr Tymoshenko
9883649c84 Add Dell Chromebook to the list of devices with E820 extmem quirk enabled
Just like for Acer C270 chromebook the E820 extmem workaround is required for
FreeBSD to boot on Dell chromebook.

PR:		204916
Submitted by:	Keith White <kwhite@site.uottawa.ca>
MFC after:	1 week
2019-01-14 01:30:48 +00:00
Warner Losh
2cd8f54b87 biospci_write_config args were backwards
biospci_write_config args swapped length and value to write. Some
hardware coped just fine, while other hardware had issues.

PR: 155441
Submitted by: longwitz at incore dot de
2019-01-08 20:01:56 +00:00
Matt Macy
fbeb31a26b MK_ZFS -> {MK_ZFS|MK_LOADER_ZFS}, this is so we can diable userland / kernel
ZFS but keep the boot-loaders when using ZoL port.

MFC after: 1 week
Reviewed by: rgrimes
Differential Revision: https://reviews.freebsd.org/D18739
2019-01-05 22:45:20 +00:00
Toomas Soome
a9f7119bb8 With buggy int13 ah=15, we can mis-identify the floppy devices.
We have no option than trust INT13 ah=08 return code during the init phase.

PR:		234460
Reported by:	Oleh Hushchenkov
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D18723
2019-01-05 07:20:00 +00:00
Toomas Soome
295586e818 i386_parsedev() needs to support fd devices
MFC after:	2 weeks
2019-01-02 20:31:15 +00:00
Toomas Soome
46aedfa274 Add Copyright.
Reported by:	Rodney W. Grimes
2018-12-30 15:34:12 +00:00
Toomas Soome
75772fa26e loader: create bio_alloc and bio_free for bios bounce buffer
We do have 16KB buffer space defined in pxe.c, move it to bio.c and implement
bio_alloc()/bio_free() interface to make it possible to use this space for
other BIOS calls (notably, from biosdisk.c).

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D17131
2018-12-30 09:35:47 +00:00
Ian Lepore
9631ae8267 Don't reference zfs-specific variables if LOADER_ZFS_SUPPORT is undefined
because the variables will be undefined too.

Reported by:	sjg@
Pointy hat:	ian@
2018-12-06 20:28:09 +00:00
Ian Lepore
7297dc4441 Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct.  Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.

To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args.  In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.

In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.

X-MFC after:	a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
Ed Maste
f7eb23ee34 stand/i386: rename .s to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and
(via rules in share/mk/bsd.suffixes.mk) are assembled with Clang's
Integrated Assembler (IAS).  Rename files in stand/i386 to .S to use
the integrated assembler.

Clang's IAS supports the defsym option (via -Wa,) but only with one
dash, not two.  As both -defsym and --defsym are accepted by GNU as,
use the former.

PR:		233611
Reviewed by:	tsoome
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18369
2018-12-03 19:16:34 +00:00
Ian Lepore
df108aafe9 Eliminate duplicated code and struct member definitions in the handoff
of args data between gptboot/zfsboot and loader(8).

Despite what seems like a lot of changes here, there are no actual
changes in behavior, or in the data layout in the structures involved.
This is just eliminating identical code pasted into multiple locations.

In detail, the changes are...

- Move struct zfs_boot_args definition from libsa/zfs/libzfs.h to
  i386/common/bootargs.h because it is specific to x86 booting and the
  handoff between zfsboot and loader, and has no relation to the zfs
  library code in general.

- The geli_boot_args and zfs_boot_args structs both contain an identical
  set of member variables containing geli information.  Extract this out
  to a new geli_boot_data struct, and embed it in the arg-passing structs.

- Provide new routines geli_import_boot_data() and geli_export_boot_data()
  that can be shared between gptboot, zfsboot, and loader instead of
  pasting identical code into several different .c files.

- Remove some checks for a NULL pointer that can never be true because the
  pointer being tested was set using pointer math (kargs + 1) and that can
  never result in NULL in this code.
2018-12-03 03:58:30 +00:00
Toomas Soome
cdff10360e loader: create separate lists for fd, cd and hd, merge bioscd with biosdisk
Create unified block IO implementation in BIOS version, like it is done in UEFI
side. Implement fd, disk and cd device lists, this will split floppy devices
from disks and will allow us to have consistent, predictable device naming
(modulo BIOS issues).

Differential Revision:	https://reviews.freebsd.org/D17888
2018-11-30 08:01:11 +00:00
Maxim Sobolev
55d5c94943 The libstand's panic() appends its own '\n' to the message, so that users of the API
don't need to supply one.

MFC after:	2 weeks
2018-11-29 18:37:48 +00:00
Ian Lepore
b92c2c907e Add comments describing the bootargs handoff between loader(8) and gptboot
or zfsboot, when loader(8) is the BTX loader.  No functional changes.
2018-11-28 18:09:42 +00:00
Ian Lepore
52c0ec1455 Restore the ability to override the disk unit/partition at the boot: prompt
in gptboot.

When arch-independent geli support was added, a new static 'gdsk' struct
was added, but there was still a static 'dsk' struct, and when you typed
in an alternate disk/partition, the string was parsed into that struct,
which was then never used for anything.  Now the string gets parsed into
gdsk.dsk, the struct that's actually used.

X-MFC after:	3 days
2018-11-27 16:16:38 +00:00
Guangyuan Yang
71cf0a4e29 Bump the date of pxeboot(8) manual page for r340917.
PR:		123484
MFC after:	5 days
2018-11-27 08:51:15 +00:00
Ed Maste
4f7c9c3e4e stand/i386/libi386: rename .s file to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and are
assembled with Clang's Integrated Assembler (IAS); rename pxetram.s to
.S to use IAS as well.

The generated .text is identical (the entire .o file is not, as Clang
adds debug info.)

PR:		205250, 233094
Sponsored by:	The FreeBSD Foundation
2018-11-26 19:29:18 +00:00
Ed Maste
e5b8bced3f btx: rename .s files to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and are
assembled with Clang's integrated assembler; rename two files in
stand/i386/btx/lib to .S to use IAS as well.

The generated .text is identical (the entire .o files are not, as Clang
adds debug info).

PR:		205250, 233094
Discussed with:	imp
Sponsored by:	The FreeBSD Foundation
2018-11-26 19:14:33 +00:00
Guangyuan Yang
2dfc267231 Update pxeboot(8) manual page to reflect the next-server change in the ISC DHCP v3 server.
PR:		123484
Submitted by:	edwin@mavetju.org
Reviewed by:	AllanJude
MFC after:	1 week
2018-11-25 09:37:57 +00:00
Ed Maste
76b6af6731 Disable build-id in i386 binary boot components
A user may enable build-id for all builds by adding
LDFLAGS=-Wl,--build-id=sha1 to /etc/make.conf.  In this case the build-id
note ends added up to mbr and pmbr's .text, which makes it too large (it
ends up being 532 bytes). To avoid this explicitly turn off build-id for
these components.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D15470
2018-11-23 13:50:18 +00:00
Ed Maste
02c4bf4391 stand: remove CLANG_NO_IAS from btx and gptboot
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.

Note that in some cases there are small differences in the generated
output, so CLANG_NO_IAS should be removed only after testing (or after
finding no differences in the output).

PR:		205250, 233094
Sponsored by:	The FreeBSD Foundation
2018-11-20 16:54:42 +00:00
Toomas Soome
53e3fbee09 loader: always set media size from partition.
The disk access is validated by using partition table definitions, therefore
we have no need for if statements, just set the disk size.

Of course the partition table itself may be incorrect/inconsistent, but if
so, we are in trouble anyhow.

Differential Revision:	https://reviews.freebsd.org/D17822
2018-11-07 11:14:22 +00:00
Toomas Soome
0d0ffe4faa loader: biosdisk should check if the media is present
The bd_print/bd_open/bd_strategy need to make sure the device does have
media, before getting into performing IO operations. Some systems can
hung if the device without a media is accessed.

Reported by:	yuripv
2018-11-02 11:41:58 +00:00
Toomas Soome
c50609fc32 loader: do not probe floppy devices for zfs
The subject is telling it all.
2018-11-02 09:47:18 +00:00
Toomas Soome
09312399a7 loader: issue edd probe before legacy ah=08 and detect no media
while probing for drives, use int13 extended info before standard one and
provide workaround for case we are not getting needed information in case
of floppy drive.

In case of INT13 errors, there are (at least) 3 error codes appearing in case
of missin media - 20h, 31h and 80h. Flag the no media and do not print an
error.

Differential Revision:	https://reviews.freebsd.org/D17667
2018-10-31 16:42:40 +00:00
Toomas Soome
8b7db46557 loader: biosdisk interface should be able to cope with 4k sectors
The 4kn support in current bios specific biosdisk.c is broken, as the code
is only implementing the support for the 512B sector size.

This work is building the support for custom size sectors, we still do assume
the requested data to be multiple of 512B blocks and we only do address the
biosdisk.c interface here.

For reference, see also:
https://www.illumos.org/issues/8303
https://www.illumos.org/rb/r/547

As the GELI is moved above biosdisk "layer", the GELI should just work

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D11174
2018-10-23 14:44:32 +00:00
Ed Maste
188b0da1ce libi386: remove CLANG_NO_IAS workaround
Clang's Integrated Assembler was previously disabled for i386 with the
note that it "doesn't grok .codeNN directives yet."  This is no longer
the case (and hasn't been for some time), and the assembled output .text
is identical between gas and IAS.

MFC after:	2 months
Sponsored by:	The FreeBSD Foundation
2018-10-20 22:35:06 +00:00
Toomas Soome
45a3e13ca8 loader: bios loader should allow to chain load a file
The current chain command does accept only device, allow also a file to be used,
such as /boot/pmbr or /boot/mbr (or stored third party MBR/VBR block).

Also fix file descriptor leak.
2018-08-22 10:04:42 +00:00
Toomas Soome
e7da951ee5 libi386: bd_io_workaround() is to be called for reads only
bd_io() can perform either reads or writes, we only need bd_io_workaround()
for reads.
2018-08-16 07:13:36 +00:00
Toomas Soome
8000f383bb libi386: small style updates in biosdisk
Use break instead of return in for loop, as done earlier. Insert and remove
some blank lines. No functional changes intended.
2018-08-16 06:50:53 +00:00
Toomas Soome
799bbc25b9 libi386: use BD_RD and BR_WR constants
Use BD_RD and BD_WR instead of 0 and 1.

Reported by:	ian
2018-08-15 22:40:09 +00:00
Toomas Soome
462d81dd3f libi386: remove bd_read() and bd_write() wrappers
Those wroappers are nice, but do not really add much value.
2018-08-15 22:25:05 +00:00
Toomas Soome
4273aef54d libi386: remove BD_SUPPORT_FRAGS
BD_SUPPORT_FRAGS is preprocessor knob to allow partial reads in bioscd/biosdisk
level. However, we already have support for partial reads in bcache, and there
is no need to have duplication via preprocessor controls.

Note that bioscd/biosdisk interface is assumed to perform IO in 512B blocks,
so the only translation we have to do is 512 <-> native block size.

Differential Revision:	https://reviews.freebsd.org/D16600
2018-08-15 21:21:16 +00:00
Warner Losh
9d45c24cc4 Create a loader for each interpreter for x86 BIOS and all EFI
Create loader_{4th,lua,simp}{,.efi}. All of these are installed by
default. Create LOADER_DEFAULT_INTERP to specify the default
interpreter when no other is specified. LOADER_INTERP is the current
interpreter language building. Turn building of lua on by default to
match 4th. simploader is a simplified loader build w/o any interpreter
language (but with a simple loader).  This is the historic behavir you
got with WITHOUT_FORTH. Make a hard link to the default loader. This
has to be a hard link rather than the more desirable soft link because
older zfsboot blocks don't support symlinks.

RelNotes: Yes
Differential Revision: https://reviews.freebsd.org/D16705
2018-08-14 18:44:41 +00:00
Kyle Evans
456a4ad51e libi386: Fix typo in pxe.h
PR:		207337
Submitted by:	Tony Narlock <tony@git-pull.com>
MFC after:	1 week
2018-08-09 03:45:47 +00:00
Kyle Evans
4e6c8e6d83 isoboot, gptboot: Fix WITHOUT_LOADER_GELI (gptboot) and isoboot in general
gptboot was broken when r316078 added the LOADER_GELI_SUPPORT #ifdef to
not pass geliargs via __exec.  KARGS_FLAGS_EXTARG must not be used if we're
not going to pass an additional argument to __exec.

PR:		228151
Submitted by:	guyyur@gmail.com
MFC after:	1 week
2018-08-09 02:06:25 +00:00
Toomas Soome
8750586c61 loader: bd_open() should cleanup from disk_open() error
Since bd_open() does early increment for reference counter and bcache
allocation, it also should undo those in case of the error.

Also remove unused variables rdev, g_err.
2018-08-05 19:17:07 +00:00
Toomas Soome
d1e22b8f08 loader: 337353 did miss to rename 2 write instances
2 write instances got somehow missed.
2018-08-05 18:24:35 +00:00
Toomas Soome
7bb45e615a loader: cstyle cleanup for biosdisk.c
Also switch u_int to uint32_t. Also replace "write" by "dowrite".
No functional changes intended.
2018-08-05 18:19:40 +00:00
Kristof Provost
5abe8cb6de zfsboot: Fix startup crash
On a FreeNAS mini XL, with geli encrypted drives the loader crashed in
geli_read().

When we iterate over the list of disks and allocate the zfsdsk structures we
don’t zero out the gdev pointer. In one case that resulted in geli_read()
(called on the bogus pointer) dividing by zero.

Use calloc() to ensure the zfsdsk structure is always zeroed, so the pointer is
initialised to NULL. As a side benefit it gets rid of one #ifdef
LOADER_GELI_SUPPORT.
2018-08-05 11:15:28 +00:00
Toomas Soome
d11ef379f0 loader: biosdisk.c has leftover geli header.
A small cleanup, remove unneeded #include.
2018-08-04 20:04:40 +00:00
Xin LI
3848ff5cac In r337271, we limited the sector number to the lower of calculated
number and CHS based number.  However, on some systems, BIOS would
report 0 in CHS fields, making the system to think there is 0 sectors.

Add a check before comparing the calculated total with bd_sectors.

Reviewed by:	tsoome, cy
Differential Revision:	https://reviews.freebsd.org/D16577
2018-08-04 14:13:09 +00:00
Cy Schubert
ca237cc5e1 Some drives report a geometry that is inconsisetent with the total
number of sectors reported through the BIOS. Cylinders * heads *
sectors may not necessarily be equal to the total number of sectors
reported through int13h function 48h.

An example of this is when a Mediasonic HD3-U2B PATA to USB enclosure
with a 80 GB disk is attached. Loader hangs at line 506 of
stand/i386/libi386/biosdisk.c while attempting to read sectors beyond
the end of the disk, sector 156906855. I discovered that the Mediasonic
enclosure was reporting the disk with 9767 cylinders, 255 heads, 63
sectors/track. That's 156906855 sectors. However camcontrol and
Windows 10 both report report the disk having 156301488 sectors, not
the calculated value. At line 280 biosdisk.c sets the sectors to the
higher of either bd->bd_sectors or the total calculated at line 276
(156906855) instead of the lower and correct value of 156301488 reported
by int 13h 48h.

This was tested on all three of my Mediasonic HD3-U2B PATA to USB
enclosures.

Instead of using the higher of bd_sectors (returned by int13h) or the
calculated value, this patch uses the lower and safer of the values.

Reviewed by:	tsoome@
Differential Revision:	https://reviews.freebsd.org/D16577
2018-08-03 19:11:00 +00:00
Warner Losh
3b74102205 Older zfs boot blocks don't support symlinks. install the link to
zfsloader as a hard link. While newer ones do, the whole point of the
link was to transition to the new world order smoothly. A hard link is
less flexible, but it works and will result in fewer bumps. Adjust
UPDATING entry to match.
2018-07-23 06:04:05 +00:00
Warner Losh
fdcfd483e3 NM and OBJCOPY are already defined for all builds. There's no need to
conditionally define them here.
2018-07-20 05:17:56 +00:00
Warner Losh
1a14a0bfb7 Eliminate zfsloader man page.
Remove all cross references to zfsloader.8 and /boot/zfsloader.
Move ZFS specific info into loader.8.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D16361
2018-07-20 05:17:49 +00:00
Warner Losh
060679ef9c Collapse zfsloader functionality back down into loader.
We no longer really need a separate zfsloader. It was useful when we
were first supporting ZFS and had limited ability to properly boot off
of ZFS without the special boot loader. Now that the boot loader has
matured, go the way loader.efi pioneered and just build one
binary. Change the name of the loader to load in the secondary boot
blocks to be just /boot/loader. Provide a symbolic link from zfsloader
to loader so people who have not upgraded their boot blocks are not
affected. This has the happy benefit of making coexistence easier as
well (fewer binaries in the matrix).

Discussed with: allanjude@, kevans@
RelNotes: Yes
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D16361
2018-07-20 05:17:37 +00:00
Li-Wen Hsu
ceab45b744 zfsboot: fix build with WITHOUT_LOADER_GELI
Reviewed by:	ian
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D16292
2018-07-16 19:21:50 +00:00
Warner Losh
bb50079093 Catch up to the inflate renaming. 2018-07-13 20:08:18 +00:00