freebsd-nq/sys
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
..
amd64 Now userland POSIX semaphore is based on umtx. The kernel module 2010-09-24 09:04:16 +00:00
arm Add basic cpu_sleep() support for Marvell SoCs. This drops my SheevaPlug's 2010-09-18 16:57:05 +00:00
boot - Split code shared by almost any boot loader into separate files and 2010-09-24 19:49:12 +00:00
bsm
cam Decrease poll interval from 1000 to 100us. This significantly reduces 2010-09-22 05:17:18 +00:00
cddl zfs_map_page/zfs_unmap_page: do not use sched_pin() and SFB_CPUPRIVATE 2010-09-21 05:58:45 +00:00
compat Implement proc/$$/environment. 2010-09-16 07:56:34 +00:00
conf Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
contrib Add preliminary support for the Lanner MR-955. It boots multi-user but there 2010-09-19 09:19:38 +00:00
crypto Add support for CRYPTO_AES_XTS. 2010-09-23 11:57:25 +00:00
ddb One more use for _SIG_VALID. 2010-07-12 10:18:10 +00:00
dev Improve r56796; the reply handler actually may remove the request from 2010-09-24 16:40:46 +00:00
fs Modify devfs_fqpn() for future use in devfs path reference counting 2010-09-21 16:49:02 +00:00
gdb
geom Allow to configure GPT attributes. It shouldn't be allowed to set bootfailed 2010-09-24 19:33:47 +00:00
gnu Add dedicated routines to toggle lockmgr flags such as LK_NOSHARE and 2010-08-20 19:46:50 +00:00
i386 Now userland POSIX semaphore is based on umtx. The kernel module 2010-09-24 09:04:16 +00:00
ia64 bus_add_child: change type of order parameter to u_int 2010-09-10 11:19:03 +00:00
isa bus_add_child: change type of order parameter to u_int 2010-09-10 11:19:03 +00:00
kern kdb_backtrace: use stack_print_ddb instead of stack_print 2010-09-22 06:45:07 +00:00
kgssapi
libkern Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
mips o) Add bus_teardown_intr for pci and ciu. This allows the Promise SATA 2010-09-24 02:41:52 +00:00
modules Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
net - Expand scope of tun/tap softc locks to cover more softc fields and 2010-09-22 21:02:43 +00:00
net80211 Wrap remaining ieee80211_ratectl_node_init() calls missed in r211314. 2010-08-21 11:06:21 +00:00
netatalk
netgraph Fix typo 2010-08-02 22:26:08 +00:00
netinet Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
netinet6 IP_BINDANY is not correctly handled in getsockopt() case. 2010-09-24 14:38:54 +00:00
netipsec MFp4 @178283: 2010-05-24 16:27:47 +00:00
netipx
netnatm
netncp
netsmb
nfs Move sys/nfsclient/nfs_lock.c into sys/nfs and build it as a separate 2010-07-24 22:11:11 +00:00
nfsclient Do not fork nfsiod directly from the vop methods. This causes LORs between 2010-09-12 19:06:08 +00:00
nfsserver - When VFS_VGET() is not supported, switch to VOP_LOOKUP(). 2010-08-26 23:41:40 +00:00
nlm Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
opencrypto Add support for AES-XTS. 2010-09-23 11:52:32 +00:00
pc98 Now userland POSIX semaphore is based on umtx. The kernel module 2010-09-24 09:04:16 +00:00
pci Remove unnecessary controller reinitialization. 2010-08-24 18:52:24 +00:00
powerpc Now userland POSIX semaphore is based on umtx. The kernel module 2010-09-24 09:04:16 +00:00
rpc Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general 2010-09-24 15:01:45 +00:00
security Replace sbuf_overflowed() with sbuf_error(), which returns any error 2010-09-10 16:42:16 +00:00
sparc64 minor simplifications and cosmetics 2010-09-24 15:12:18 +00:00
sun4v Sync with other platforms: 2010-09-15 17:11:15 +00:00
sys Add three GPT attributes: 2010-09-24 19:31:08 +00:00
teken Make ^L with cons25 and origin mode bit more sane. 2010-08-09 18:07:15 +00:00
tools Add an extra comment to the SDT probes definition. This allows us to get 2010-08-22 11:18:57 +00:00
ufs Correct some non-code typos. 2010-09-17 09:14:40 +00:00
vm Replace an XXX comment with the appropriate code. 2010-09-20 20:41:59 +00:00
x86 Restore pre-r212778 optimization, skipping timer reprogramming when it is 2010-09-18 07:36:43 +00:00
xdr
xen
Makefile