freebsd-dev/sys/boot/common
Pawel Jakub Dawidek a0e2fdedd1 - Split code shared by almost any boot loader into separate files and
clean up most layering violations:

	sys/boot/i386/common/rbx.h:

		RBX_* defines
		OPT_SET()
		OPT_CHECK()

	sys/boot/common/util.[ch]:

		memcpy()
		memset()
		memcmp()
		bcpy()
		bzero()
		bcmp()
		strcmp()
		strncmp() [new]
		strcpy()
		strcat()
		strchr()
		strlen()
		printf()

	sys/boot/i386/common/cons.[ch]:

		ioctrl
		putc()
		xputc()
		putchar()
		getc()
		xgetc()
		keyhit() [now takes number of seconds as an argument]
		getstr()

	sys/boot/i386/common/drv.[ch]:

		struct dsk
		drvread()
		drvwrite() [new]
		drvsize() [new]

	sys/boot/common/crc32.[ch] [new]

	sys/boot/common/gpt.[ch] [new]

- Teach gptboot and gptzfsboot about new files. I haven't touched the
  rest, but there is still a lot of code duplication to be removed.

- Implement full GPT support. Currently we just read primary header and
  partition table and don't care about checksums, etc. After this change we
  verify checksums of primary header and primary partition table and if
  there is a problem we fall back to backup header and backup partition
  table.

- Clean up most messages to use prefix of boot program, so in case of an
  error we know where the error comes from, eg.:

	gptboot: unable to read primary GPT header

- If we can't boot, print boot prompt only once and not every five
  seconds.

- Honour newly added GPT attributes:

	bootme - this is bootable partition
	bootonce - try to boot from this partition only once
	bootfailed - we failed to boot from this partition

- Change boot order of gptboot to the following:

	1. Try to boot from all the partitions that have both 'bootme'
	   and 'bootonce' attributes one by one.
	2. Try to boot from all the partitions that have only 'bootme'
	   attribute one by one.
	3. If there are no partitions with 'bootme' attribute, boot from
	   the first UFS partition.

- The 'bootonce' functionality is implemented in the following way:

	1. Walk through all the partitions and when 'bootonce'
	   attribute is found without 'bootme' attribute, remove
	   'bootonce' attribute and set 'bootfailed' attribute.
	   'bootonce' attribute alone means that we tried to boot from
	   this partition, but boot failed after leaving gptboot and
	   machine was restarted.
	2. Find partition with both 'bootme' and 'bootonce' attributes.
	3. Remove 'bootme' attribute.
	4. Try to execute /boot/loader or /boot/kernel/kernel from that
	   partition. If succeeded we stop here.
	5. If execution failed, remove 'bootonce' and set 'bootfailed'.
	6. Go to 2.

   If whole boot succeeded there is new /etc/rc.d/gptboot script coming
   that will log all partitions that we failed to boot from (the ones with
   'bootfailed' attribute) and will remove this attribute. It will also
   find partition with 'bootonce' attribute - this is the partition we
   booted from successfully. The script will log success and remove the
   attribute.

   All the GPT updates we do here goes to both primary and backup GPT if
   they are valid. We don't touch headers or partition tables when
   checksum doesn't match.

Reviewed by:	arch (Message-ID: <20100917234542.GE1902@garage.freebsd.pl>)
Obtained from:	Wheel Systems Sp. z o.o. http://www.wheelsystems.com
MFC after:	2 weeks
2010-09-24 19:49:12 +00:00
..
bcache.c
boot.c Introduce a new option (BOOT_PROMPT_123) that lets enter the boot prompt 2009-11-12 01:30:17 +00:00
bootstrap.h Remove file system support based on the simple file system protocol 2010-01-09 22:54:29 +00:00
commands.c Close a file descriptor leak in an error case. 2009-10-28 10:06:27 +00:00
console.c
crc32.c - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
crc32.h - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
dev_net.c - Add code allowing a network device to only be open and closed once 2010-01-09 21:23:39 +00:00
dev_net.h
devopen.c Show info about net devices in loader's 'lsdev' command. While there fix style. 2008-09-03 17:41:44 +00:00
gpt.c - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
gpt.h - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
help.common Replace a rarely used "depuration" with "debugging". 2006-10-13 20:48:17 +00:00
interp_backslash.c
interp_forth.c
interp_parse.c
interp.c As reported in kern/118222, pxeboot in RELENG7 (and presumably 2008-11-20 14:57:09 +00:00
isapnp.c
isapnp.h
load_elf32_obj.c
load_elf32.c
load_elf64_obj.c
load_elf64.c
load_elf_obj.c completely ignore zero-sized elf sections in modules of elf object type (amd64) 2010-07-23 17:07:51 +00:00
load_elf.c Initial support of loader(8) for ARM machines running U-Boot. 2008-10-14 10:11:14 +00:00
loader.8 mdoc: make sure to pass at least one argument to quotation macros 2010-08-02 13:11:35 +00:00
ls.c
Makefile.inc Fix build of ppc32 loader. 2010-08-25 16:23:50 +00:00
md.c Add support for memory disk (md). The size of the memory disk 2009-12-13 01:20:32 +00:00
merge_help.awk Ignore a sub-topic match if it is inside the command description. 2006-09-28 19:06:20 +00:00
misc.c Setting a variable to the same value twice doesn't actually make it 2008-08-04 06:39:52 +00:00
module.c Formatting nit 2010-05-10 18:23:00 +00:00
newvers.sh
panic.c Fix WARNS=2 warnings. 2006-09-29 20:57:38 +00:00
pnp.c Garbage collect the code for auto-loading modules based on ISAPNP IDs, 2007-01-07 22:25:45 +00:00
reloc_elf32.c
reloc_elf64.c
reloc_elf.c
ufsread.c Replace structure assignments with explicity memcpy calls. This allows 2010-08-24 12:56:45 +00:00
util.c - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
util.h - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00