freebsd-src/stand/kboot
Mitchell Horne 8859960436 loader: always install help files
Address two issues with current help file logic:

The existing condition prevents the common help file from being
installed when there are no additional help files defined. This results
in no loader.help on EFI platforms, for example.

Second, due to the fact that we build and install multiple loader types,
each successive install will clobber the previous loader.help. The
result is that we could lose type-specific commands, or possibly list
them in loaders that do not have such commands.

Instead, give each loader type a uniquely named help file. The EFI
loader will look for /boot/loader.help.efi, userboot will look for
/boot/loader.help.userboot, etc. The interpreter variant has no effect
on which help file is loaded.

This leaves the old /boot/loader.help unused.

Some credit for the final approach goes to Mathieu <sigsys@gmail.com>
for their version of the fix in https://reviews.freebsd.org/D22951.

PR:		267134
Reported by:	Daniel O'Connor <darius@dons.net.au>
Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28591
2023-02-03 16:35:06 -04:00
..
arch kboot: Remove externs 2023-02-03 08:41:41 -07:00
conf.c kboot: Add support for ZFS volumes 2023-01-13 14:22:39 -07:00
crt1.c stand: Spell License correctly 2022-07-26 16:31:13 -06:00
host_syscall.h kboot: Assert errno is negative 2023-02-02 14:09:55 -07:00
host_syscalls.c kboot: Sort kexec_load alphabetically 2023-01-07 13:24:45 -07:00
hostcons.c kboot: Use (void) instead of () for functiosn with no args 2022-12-09 07:57:50 -07:00
hostdisk.c kboot: Probe all disks and partitions for a kernel 2023-02-03 08:41:38 -07:00
hostfs.c kboot: For hostfs, return better errors from read, where possible. 2023-02-02 13:06:31 -07:00
init.c kboot: add minmalist init functionality 2022-09-01 11:08:24 -06:00
kboot.h kboot: Don't need an arch pointer to get segments 2023-02-03 08:41:40 -07:00
kbootfdt.c kboot: Allow loading fdt from different sources 2022-12-08 22:07:52 -07:00
main.c kboot: Keep track of what's used in the segment 2023-02-03 08:41:41 -07:00
Makefile loader: always install help files 2023-02-03 16:35:06 -04:00
README kboot: Add readme 2022-12-03 12:48:45 -07:00
seg.c kboot: space_avail -- how much space exists from 'start' to end of segment 2023-02-03 08:41:39 -07:00
termios.c kboot: implement stripped down termios 2022-07-28 15:35:42 -06:00
termios.h kboot: implement stripped down termios 2022-07-28 15:35:42 -06:00
termios_gen.h kboot: Add missing license to termios 2022-12-04 13:31:06 -07:00
util.c kboot: Use unsigned long long. 2022-12-02 12:41:01 -07:00
version

So to make a Linux initrd:

(1) mkdir .../initrd
(2) mkdir -p .../initrd/boot/defaults
(3) cd src/stand; make install DESTDIR=.../initrd
(4) Copy kernel to .../initrd/boot/kernel
(5) cd .../initrd
(6) cp boot/loader.kboot init
(7) find . | sort | cpio -o -H newc | gzip > /tmp/initrd.cpio
(8) download or build your linux kernel
(9) qemu-system-x86_64 -kernel ~/vmlinuz-5.19.0-051900-generic \
	-initrd /tmp/initrd.cpio \
	-m 256m -nographic \
	-monitor telnet::4444,server,nowait -serial stdio \
	-append "console=ttyS0"
    (though you may need more than 256M of ram to actually boot FreeBSD and do
     anything interesting with it and the serial console to stdio bit hasn't
     been the most stable recipe lately).

Notes:
For #6 you might need to strip loader.kboot if you copy it directly and don't
	use make install.
For #7 the sort is important, and you may need LC_ALL=C for its invocation
For #7 gzip is but one of many methods, but it's the simplest to do.
For #9, this means we can automate it using methods from
	src/tools/boot/rootgen.sh when the time comes.
#9 also likely generalizes to other architectures
For #8, see https://kernel.ubuntu.com/~kernel-ppa/mainline/ to download
	a kernel suitable for testing... For arm, I've been using the
	non 64k page kernels and 5.19 seems to not suck.

aarch64:
qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \
	-kernel ~/linuxboot/arm64/kernel/boot/vmlinuz-5.19.0-051900-generic \
	-initrd ~/linuxboot/arm64/initrd.img -m 256m -nographic \
	-monitor telnet::4444,server,nowait -serial stdio \
	-append "console=ttyAMA0"

General

Add -g -G to have gdb stop and wait for the debugger. This is useful for
debugging the trampoline (hbreak will set a hardware break that's durable across
code changes).  If you set the breakpoint for the trampoline and it never hits,
then there's likely no RAM there and you got the PA to load to wrong. When
debugging the trampiline and up to that, use gdb /boot/loader. When debugging
the kernel, use kernel.full to get all the debugging. hbreak panic() is useful
on the latter since you'll see the original panic, not the panic you get from
there not being an early console.