]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
Remove stubdom directory
authorWei Liu <wei.liu2@citrix.com>
Wed, 9 Mar 2016 17:41:06 +0000 (17:41 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 15 Mar 2016 16:32:35 +0000 (16:32 +0000)
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Wei Liu <liuw@liuw.name>
97 files changed:
stubdom/Makefile [deleted file]
stubdom/c/Makefile [deleted file]
stubdom/c/main.c [deleted file]
stubdom/c/minios.cfg [deleted file]
stubdom/caml/Makefile [deleted file]
stubdom/caml/hello.ml [deleted file]
stubdom/caml/main-caml.c [deleted file]
stubdom/caml/minios.cfg [deleted file]
stubdom/configure [deleted file]
stubdom/configure.ac [deleted file]
stubdom/grub.patches/00cvs [deleted file]
stubdom/grub.patches/10graphics.diff [deleted file]
stubdom/grub.patches/11graphics-keyboard.diff [deleted file]
stubdom/grub.patches/20print_func.diff [deleted file]
stubdom/grub.patches/30savedefault.diff [deleted file]
stubdom/grub.patches/40ext3_256byte_inode.diff [deleted file]
stubdom/grub.patches/50fs_fulldisk.diff [deleted file]
stubdom/grub.patches/60ext4.diff [deleted file]
stubdom/grub.patches/61btrfs.diff [deleted file]
stubdom/grub.patches/70compiler_warnings.diff [deleted file]
stubdom/grub.patches/99minios [deleted file]
stubdom/grub/Makefile [deleted file]
stubdom/grub/boot-x86_32.S [deleted file]
stubdom/grub/boot-x86_64.S [deleted file]
stubdom/grub/config.h [deleted file]
stubdom/grub/kexec.c [deleted file]
stubdom/grub/mini-os.c [deleted file]
stubdom/grub/mini-os.h [deleted file]
stubdom/grub/minios.cfg [deleted file]
stubdom/grub/osdep.h [deleted file]
stubdom/ioemu-minios.cfg [deleted file]
stubdom/libpci.config.h [deleted file]
stubdom/libpci.config.mak [deleted file]
stubdom/lwip.dhcp_create_request-hwaddr_len.patch [deleted file]
stubdom/lwip.patch-cvs [deleted file]
stubdom/newlib-chk.patch [deleted file]
stubdom/newlib-stdint-size_max-fix-from-1.17.0.patch [deleted file]
stubdom/newlib.patch [deleted file]
stubdom/ocaml.patch [deleted file]
stubdom/pciutils.patch [deleted file]
stubdom/polarssl.patch [deleted file]
stubdom/stubdom-dm [deleted file]
stubdom/tpmemu-0.7.4.patch [deleted file]
stubdom/vtpm-bufsize.patch [deleted file]
stubdom/vtpm-cmake-Wextra.patch [deleted file]
stubdom/vtpm-deepquote-anyloc.patch [deleted file]
stubdom/vtpm-deepquote.patch [deleted file]
stubdom/vtpm-locality.patch [deleted file]
stubdom/vtpm-parent-sign-ek.patch [deleted file]
stubdom/vtpm/Makefile [deleted file]
stubdom/vtpm/minios.cfg [deleted file]
stubdom/vtpm/vtpm.c [deleted file]
stubdom/vtpm/vtpm.h [deleted file]
stubdom/vtpm/vtpm_cmd.c [deleted file]
stubdom/vtpm/vtpm_cmd.h [deleted file]
stubdom/vtpm/vtpm_pcrs.c [deleted file]
stubdom/vtpm/vtpm_pcrs.h [deleted file]
stubdom/vtpm/vtpmblk.c [deleted file]
stubdom/vtpm/vtpmblk.h [deleted file]
stubdom/vtpmmgr/Makefile [deleted file]
stubdom/vtpmmgr/calc.pl [deleted file]
stubdom/vtpmmgr/common_types.h [deleted file]
stubdom/vtpmmgr/disk_crypto.c [deleted file]
stubdom/vtpmmgr/disk_crypto.h [deleted file]
stubdom/vtpmmgr/disk_format.h [deleted file]
stubdom/vtpmmgr/disk_io.c [deleted file]
stubdom/vtpmmgr/disk_io.h [deleted file]
stubdom/vtpmmgr/disk_read.c [deleted file]
stubdom/vtpmmgr/disk_tpm.c [deleted file]
stubdom/vtpmmgr/disk_tpm.h [deleted file]
stubdom/vtpmmgr/disk_write.c [deleted file]
stubdom/vtpmmgr/endian_int.h [deleted file]
stubdom/vtpmmgr/init.c [deleted file]
stubdom/vtpmmgr/log.c [deleted file]
stubdom/vtpmmgr/log.h [deleted file]
stubdom/vtpmmgr/manage-vtpmmgr.pl [deleted file]
stubdom/vtpmmgr/marshal.h [deleted file]
stubdom/vtpmmgr/mgmt_authority.c [deleted file]
stubdom/vtpmmgr/mgmt_authority.h [deleted file]
stubdom/vtpmmgr/minios.cfg [deleted file]
stubdom/vtpmmgr/tcg.h [deleted file]
stubdom/vtpmmgr/tpm.c [deleted file]
stubdom/vtpmmgr/tpm.h [deleted file]
stubdom/vtpmmgr/tpm2.c [deleted file]
stubdom/vtpmmgr/tpm2.h [deleted file]
stubdom/vtpmmgr/tpm2_marshal.h [deleted file]
stubdom/vtpmmgr/tpm2_types.h [deleted file]
stubdom/vtpmmgr/tpmrsa.c [deleted file]
stubdom/vtpmmgr/tpmrsa.h [deleted file]
stubdom/vtpmmgr/uuid.h [deleted file]
stubdom/vtpmmgr/vtpm_cmd_handler.c [deleted file]
stubdom/vtpmmgr/vtpm_disk.c [deleted file]
stubdom/vtpmmgr/vtpm_disk.h [deleted file]
stubdom/vtpmmgr/vtpm_manager.h [deleted file]
stubdom/vtpmmgr/vtpmmgr.c [deleted file]
stubdom/vtpmmgr/vtpmmgr.h [deleted file]
stubdom/xenstore-minios.cfg [deleted file]

diff --git a/stubdom/Makefile b/stubdom/Makefile
deleted file mode 100644 (file)
index 2044d76..0000000
+++ /dev/null
@@ -1,646 +0,0 @@
-XEN_ROOT = $(CURDIR)/..
-MINI_OS = $(XEN_ROOT)/extras/mini-os
-
-export XEN_ROOT
-export XEN_OS=MiniOS
-
-export stubdom=y
-export debug=y
-
-ifeq (,$(findstring clean,$(MAKECMDGOALS)))
-  ifeq ($(wildcard $(MINI_OS)/Config.mk),)
-    $(error Please run `make mini-os-dir' in top-level directory)
-  endif
-  include $(XEN_ROOT)/Config.mk
-endif
-
--include $(XEN_ROOT)/config/Stubdom.mk
-
-GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
-ifeq ($(XEN_TARGET_ARCH),x86_32)
-GNU_TARGET_ARCH:=i686
-endif
-
-ifeq ($(GNU_TARGET_ARCH), i686)
-TARGET_CFLAGS=
-NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
-STUBDOM_SUPPORTED=1
-endif
-ifeq ($(GNU_TARGET_ARCH), x86_64)
-TARGET_CFLAGS=-mno-red-zone
-NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
-STUBDOM_SUPPORTED=1
-endif
-
-CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
-CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
-
-# Disable PIE/SSP if GCC supports them. They can break us.
-TARGET_CFLAGS += $(CFLAGS)
-TARGET_CPPFLAGS += $(CPPFLAGS)
-$(call cc-options-add,TARGET_CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
-
-# Do not use host headers and libs
-GCC_INSTALL = $(shell LANG=C gcc -print-search-dirs | sed -n -e 's/install: \(.*\)/\1/p')
-TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
-TARGET_CPPFLAGS += -nostdinc
-TARGET_CPPFLAGS += -isystem $(MINI_OS)/include/posix
-TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
-TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
-TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include
-TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include/ipv4
-TARGET_CPPFLAGS += -I$(CURDIR)/include
-TARGET_CPPFLAGS += -I$(XEN_ROOT)/xen/include
-
-TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
-
-TARGETS=$(STUBDOM_TARGETS)
-
-STUBDOMPATH="stubdompath.sh"
-genpath-target = $(call buildmakevars2file,$(STUBDOMPATH))
-$(eval $(genpath-target))
-
-.PHONY: all
-all: build
-ifeq ($(STUBDOM_SUPPORTED),1)
-build: $(STUBDOMPATH) $(STUBDOM_BUILD)
-else
-build: $(STUBDOMPATH)
-endif
-
-##############
-# Cross-newlib
-##############
-
-newlib-$(NEWLIB_VERSION).tar.gz:
-       $(FETCHER) $@ $(NEWLIB_URL)/$@
-
-newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
-       tar xzf $<
-       patch -d $@ -p0 < newlib.patch
-       patch -d $@ -p0 < newlib-chk.patch
-       patch -d $@ -p1 < newlib-stdint-size_max-fix-from-1.17.0.patch
-       find $@ -type f | xargs perl -i.bak \
-               -pe 's/\b_(tzname|daylight|timezone)\b/$$1/g'
-       touch $@
-
-NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
-.PHONY: cross-newlib
-cross-newlib: $(NEWLIB_STAMPFILE)
-$(NEWLIB_STAMPFILE): mk-headers-$(XEN_TARGET_ARCH) newlib-$(NEWLIB_VERSION)
-       mkdir -p newlib-$(XEN_TARGET_ARCH)
-       ( cd newlib-$(XEN_TARGET_ARCH) && \
-         CC_FOR_TARGET="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(NEWLIB_CFLAGS)" AR_FOR_TARGET=$(AR) LD_FOR_TARGET=$(LD) RANLIB_FOR_TARGET=$(RANLIB) ../newlib-$(NEWLIB_VERSION)/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long --disable-multilib && \
-         $(MAKE) DESTDIR= && \
-         $(MAKE) DESTDIR= install )
-
-############
-# Cross-zlib
-############
-
-zlib-$(ZLIB_VERSION).tar.gz:
-       $(FETCHER) $@ $(ZLIB_URL)/$@
-
-zlib-$(XEN_TARGET_ARCH): zlib-$(ZLIB_VERSION).tar.gz 
-       tar xzf $<
-       mv zlib-$(ZLIB_VERSION) $@
-
-ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
-.PHONY: cross-zlib
-cross-zlib: $(ZLIB_STAMPFILE)
-$(ZLIB_STAMPFILE): zlib-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       ( cd $< && \
-         CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
-         $(MAKE) DESTDIR= libz.a && \
-         $(MAKE) DESTDIR= install )
-
-##############
-# Cross-libpci
-##############
-
-pciutils-$(LIBPCI_VERSION).tar.bz2:
-       $(FETCHER) $@ $(LIBPCI_URL)/$@
-
-pciutils-$(XEN_TARGET_ARCH): pciutils-$(LIBPCI_VERSION).tar.bz2
-       tar xjf $<
-       mv pciutils-$(LIBPCI_VERSION) $@
-       patch -d $@ -p1 < pciutils.patch
-       touch $@
-
-LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
-.PHONY: cross-libpci
-cross-libpci: $(LIBPCI_STAMPFILE)
-$(LIBPCI_STAMPFILE): pciutils-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) $(ZLIB_STAMPFILE)
-       ( cd $< && \
-         cp ../libpci.config.h lib/config.h && \
-         chmod u+w lib/config.h && \
-         echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
-         ln -sf ../../libpci.config.mak lib/config.mk && \
-         $(MAKE) DESTDIR= CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(call realpath,$(MINI_OS)/include)" lib/libpci.a && \
-         $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
-         $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
-         $(INSTALL_DATA) lib/config.h lib/header.h lib/pci.h lib/types.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
-       )
-
-######
-# lwIP
-######
-
-lwip-$(LWIP_VERSION).tar.gz:
-       $(FETCHER) $@ $(LWIP_URL)/$@
-
-lwip-$(XEN_TARGET_ARCH): lwip-$(LWIP_VERSION).tar.gz
-       tar xzf $<
-       mv lwip $@
-       patch -d $@ -p0 < lwip.patch-cvs
-       patch -d $@ -p0 < lwip.dhcp_create_request-hwaddr_len.patch
-       touch $@
-
-#############
-# cross-gmp
-#############
-gmp-$(GMP_VERSION).tar.bz2:
-       $(FETCHER) $@ $(GMP_URL)/$@
-
-.PHONY: cross-gmp
-ifeq ($(XEN_TARGET_ARCH), x86_32)
-   GMPEXT=ABI=32
-endif
-gmp-$(XEN_TARGET_ARCH): gmp-$(GMP_VERSION).tar.bz2 $(NEWLIB_STAMPFILE)
-       tar xjf $<
-       rm $@ -rf || :
-       mv gmp-$(GMP_VERSION) $@
-       #patch -d $@ -p0 < gmp.patch
-       cd $@; CPPFLAGS="-isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include $(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" CC=$(CC) $(GMPEXT) ./configure --disable-shared --enable-static --disable-fft --without-readline --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf
-       sed -i 's/#define HAVE_OBSTACK_VPRINTF 1/\/\/#define HAVE_OBSTACK_VPRINTF 1/' $@/config.h
-       touch $@
-
-GMP_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libgmp.a
-cross-gmp: $(GMP_STAMPFILE)
-$(GMP_STAMPFILE): gmp-$(XEN_TARGET_ARCH)
-       ( cd $< && \
-         $(MAKE) && \
-         $(MAKE) DESTDIR= install )
-
-#############
-# cross-polarssl
-#############
-polarssl-$(POLARSSL_VERSION)-gpl.tgz:
-       $(FETCHER) $@ $(POLARSSL_URL)/$@
-
-polarssl-$(XEN_TARGET_ARCH): polarssl-$(POLARSSL_VERSION)-gpl.tgz
-       tar xzf $<
-       mv polarssl-$(POLARSSL_VERSION) $@
-       patch -d $@ -p1 < polarssl.patch
-       touch $@
-
-POLARSSL_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpolarssl.a
-cross-polarssl: $(POLARSSL_STAMPFILE)
-$(POLARSSL_STAMPFILE): polarssl-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) lwip-$(XEN_TARGET_ARCH)
-        ( cd $</library && \
-          make CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I $(realpath $(MINI_OS)/include)" && \
-          mkdir -p $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include && \
-          cp -r ../include/* $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include && \
-          mkdir -p $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib && \
-          $(INSTALL_DATA) libpolarssl.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ )
-
-#############
-# cross-tpmemu
-#############
-tpm_emulator-$(TPMEMU_VERSION).tar.gz:
-       $(FETCHER) $@ $(TPMEMU_URL)/$@
-
-tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz
-       @if [ ! -f "$(CMAKE)" ]; then echo "cmake not installed! Install it and then rerun ./configure!"; false; fi
-       tar xzf $<
-       mv tpm_emulator-$(TPMEMU_VERSION) $@
-       patch -d $@ -p1 < tpmemu-$(TPMEMU_VERSION).patch;
-       patch -d $@ -p1 < vtpm-bufsize.patch
-       patch -d $@ -p1 < vtpm-locality.patch
-       patch -d $@ -p1 < vtpm-parent-sign-ek.patch
-       patch -d $@ -p1 < vtpm-deepquote.patch
-       patch -d $@ -p1 < vtpm-deepquote-anyloc.patch
-       patch -d $@ -p1 < vtpm-cmake-Wextra.patch
-       mkdir $@/build
-       cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement"
-       touch $@
-
-TPMEMU_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libtpm.a
-$(TPMEMU_STAMPFILE): tpm_emulator-$(XEN_TARGET_ARCH) $(GMP_STAMPFILE)
-       ( cd $</build && make VERBOSE=1 tpm_crypto tpm  )
-       cp $</build/crypto/libtpm_crypto.a $(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libtpm_crypto.a
-       cp $</build/tpm/libtpm.a $(TPMEMU_STAMPFILE)
-
-.PHONY: cross-tpmemu
-cross-tpmemu: $(TPMEMU_STAMPFILE)
-
-#############
-# Cross-ocaml
-#############
-
-CAMLLIB = $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ocaml
-OCAML_STAMPFILE=$(CAMLLIB)/.dirstamp
-
-ocaml-$(OCAML_VERSION).tar.gz:
-       $(FETCHER) $@ $(OCAML_URL)/$@
-
-ocaml-$(XEN_TARGET_ARCH)/.dirstamp: ocaml-$(OCAML_VERSION).tar.gz ocaml.patch
-       tar xzf $<
-       cd ocaml-$(OCAML_VERSION) && patch -p0 < ../ocaml.patch
-       rm -rf ocaml-$(XEN_TARGET_ARCH)
-       mv ocaml-$(OCAML_VERSION) ocaml-$(XEN_TARGET_ARCH)
-       touch $@
-
-MINIOS_HASNOT=IPV6 INET_ATON
-
-.PHONY: cross-ocaml
-cross-ocaml: $(OCAML_STAMPFILE)
-$(OCAML_STAMPFILE): ocaml-$(XEN_TARGET_ARCH)/.dirstamp
-       cd ocaml-$(XEN_TARGET_ARCH) &&  ./configure -prefix $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf \
-               -no-pthread -no-shared-libs -no-tk -no-curses \
-               -cc "$(CC) -U_FORTIFY_SOURCE -fno-stack-protector -mno-red-zone"
-       $(foreach i,$(MINIOS_HASNOT),sed -i 's,^\(#define HAS_$(i)\),//\1,' ocaml-$(XEN_TARGET_ARCH)/config/s.h ; )
-       $(MAKE) DESTDIR= -C ocaml-$(XEN_TARGET_ARCH) world
-       $(MAKE) DESTDIR= -C ocaml-$(XEN_TARGET_ARCH) opt
-       $(MAKE) -C ocaml-$(XEN_TARGET_ARCH) install
-       touch $@
-
-#######
-# Links
-#######
-
-.PHONY: $(CROSS_ROOT)
-$(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
-
-QEMU_ROOT := $(shell if [ -d "$(QEMU_TRADITIONAL_LOC)" ]; then echo "$(QEMU_TRADITIONAL_LOC)"; else echo .; fi)
-
-ifneq ($(filter ioemu,$(STUBDOM_TARGETS)),)
-IOEMU_LINKFARM_TARGET := ioemu/linkfarm.stamp
-endif
-
-ifeq ($(QEMU_ROOT),.)
-$(XEN_ROOT)/tools/qemu-xen-traditional-dir:
-       $(MAKE) DESTDIR= -C $(XEN_ROOT)/tools qemu-xen-traditional-dir-find
-
-ioemu/linkfarm.stamp: $(XEN_ROOT)/tools/qemu-xen-traditional-dir
-       mkdir -p ioemu
-       set -e;                                                                 \
-       $(buildmakevars2shellvars);                                             \
-       cd ioemu;                                                               \
-       src="$$XEN_ROOT/tools/qemu-xen-traditional-dir"; export src;            \
-       (cd $$src && find * -type d -print) | xargs mkdir -p;                   \
-       (cd $$src && find *     ! -type l  -type f  $(addprefix ! -name ,       \
-                       '*.[oda1]' 'config-*' config.mak qemu-dm qemu-img-xen   \
-                       '*.html' '*.pod'                                        \
-                       )) |                                                    \
-           while read f; do rm -f "$$f"; ln -s "$$src/$$f" "$$f"; done
-       touch ioemu/linkfarm.stamp
-else
-export QEMU_ROOT
-
-ioemu/linkfarm.stamp:
-       mkdir -p ioemu
-       touch ioemu/linkfarm.stamp
-endif
-
-mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
-       $(MAKE) -C $(XEN_ROOT)/tools/include
-       mkdir -p include/xen && \
-          ln -sf $(wildcard $(XEN_ROOT)/xen/include/public/*.h) include/xen && \
-          ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 hvm io xsm) include/xen && \
-          ( [ -h include/xen/sys ] || ln -sf $(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \
-          ( [ -h include/xen/libelf ] || ln -sf $(XEN_ROOT)/tools/include/xen/libelf include/xen/libelf ) && \
-         mkdir -p include/xen-foreign && \
-         ln -sf $(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*) include/xen-foreign/ && \
-         $(MAKE) DESTDIR= -C include/xen-foreign/ && \
-         ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
-       mkdir -p libs-$(XEN_TARGET_ARCH)/toollog/include
-       [ -h libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/toollog && \
-         ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
-       mkdir -p libs-$(XEN_TARGET_ARCH)/evtchn/include
-       [ -h libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/evtchn && \
-         ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
-       mkdir -p libs-$(XEN_TARGET_ARCH)/gnttab/include
-       [ -h libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/gnttab && \
-         ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . )
-       mkdir -p libs-$(XEN_TARGET_ARCH)/call/include
-       [ -h libs-$(XEN_TARGET_ARCH)/call/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/call && \
-         ln -sf $(XEN_ROOT)/tools/libs/call/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
-       mkdir -p libs-$(XEN_TARGET_ARCH)/foreignmemory/include
-       [ -h libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/foreignmemory && \
-         ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/Makefile . )
-       mkdir -p libxc-$(XEN_TARGET_ARCH)/include
-       [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
-         ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/libxc/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/libxc/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/libxc/Makefile . )
-       mkdir -p xenstore/include
-       [ -h xenstore/Makefile ] || ( cd xenstore && \
-         ln -sf $(XEN_ROOT)/tools/xenstore/*.c . && \
-         ln -sf $(XEN_ROOT)/tools/xenstore/*.h . && \
-         ln -sf $(XEN_ROOT)/tools/xenstore/include/*.h include/ && \
-         ln -sf $(XEN_ROOT)/tools/xenstore/Makefile . )
-       $(MAKE) DESTDIR= -C $(MINI_OS) links
-       touch mk-headers-$(XEN_TARGET_ARCH)
-
-TARGETS_MINIOS=$(addprefix mini-os-$(XEN_TARGET_ARCH)-,$(TARGETS))
-$(TARGETS_MINIOS): mini-os-%:
-       [ -d $@ ] || \
-       for i in $$(cd $(MINI_OS) ; find . -type d) ; do \
-                mkdir -p $@/$$i ; \
-       done
-
-#######
-# libxentoollog
-#######
-
-.PHONY: libxentoollog
-libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
-libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
-
-#######
-# libxenevtchn
-#######
-
-.PHONY: libxenevtchn
-libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
-libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
-
-#######
-# libxengnttab
-#######
-
-.PHONY: libxengnttab
-libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
-libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
-
-#######
-# libxencall
-#######
-
-.PHONY: libxencall
-libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
-libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
-
-#######
-# libxenforeignmemory
-#######
-
-.PHONY: libxenforeignmemory
-libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
-libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
-
-#######
-# libxc
-#######
-
-.PHONY: libxc
-libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory cross-zlib
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
-
- libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
-
-#######
-# ioemu
-#######
-
-.PHONY: ioemu
-ioemu: cross-zlib cross-libpci libxc
-       [ -f ioemu/config-host.mak ] || \
-         ( $(buildmakevars2shellvars); \
-           cd ioemu ; \
-           LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) \
-           TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
-           TARGET_CFLAGS="$(TARGET_CFLAGS)" \
-           TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
-           $(QEMU_ROOT)/xen-setup-stubdom )
-       $(MAKE) DESTDIR= -C ioemu -f $(QEMU_ROOT)/Makefile
-
-######
-# caml
-######
-
-.PHONY: caml
-caml: $(CROSS_ROOT)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) OCAMLC_CROSS_PREFIX=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/bin/
-
-###
-# C
-###
-
-.PHONY: c
-c: $(CROSS_ROOT)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) 
-
-######
-# VTPM
-######
-
-.PHONY: vtpm
-vtpm: cross-polarssl cross-tpmemu
-       XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
-
-######
-# VTPMMGR
-######
-
-.PHONY: vtpmmgr
-vtpmmgr: cross-polarssl
-       XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
-
-######
-# Grub
-######
-
-grub-$(GRUB_VERSION).tar.gz:
-       $(FETCHER) $@ $(GRUB_URL)/$@
-
-grub-upstream: grub-$(GRUB_VERSION).tar.gz
-       tar xzf $<
-       mv grub-$(GRUB_VERSION) $@
-       for i in grub.patches/* ; do \
-               patch -d $@ -p1 < $$i || exit 1; \
-       done
-
-.PHONY: grub
-grub: cross-polarssl grub-upstream $(CROSS_ROOT)
-       mkdir -p grub-$(XEN_TARGET_ARCH)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
-
-##########
-# xenstore
-##########
-
-.PHONY: xenstore
-xenstore: $(CROSS_ROOT)
-       CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ xenstored.a CONFIG_STUBDOM=y
-
-########
-# minios
-########
-
-.PHONY: ioemu-stubdom
-ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
-ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/ioemu-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
-
-.PHONY: caml-stubdom
-caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc cross-ocaml caml
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/caml/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
-
-.PHONY: c-stubdom
-c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/c/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
-
-.PHONY: vtpm-stubdom
-vtpm-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpm vtpm
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpm/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpm/vtpm.a" APP_LDLIBS="-ltpm -ltpm_crypto -lgmp -lpolarssl"
-
-.PHONY: vtpmmgr-stubdom
-vtpmmgr-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpmmgr vtpmmgr
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpmmgr/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpmmgr/vtpmmgr.a" APP_LDLIBS="-lm -lpolarssl"
-
-.PHONY: pv-grub
-pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/grub/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
-
-.PHONY: xenstore-stubdom
-xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
-       DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/xenstore-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/xenstore/xenstored.a
-
-#########
-# install
-#########
-
-ifeq ($(STUBDOM_SUPPORTED),1)
-install: $(STUBDOMPATH) $(STUBDOM_INSTALL)
-else
-install: $(STUBDOMPATH)
-endif
-
-install-ioemu: ioemu-stubdom
-       $(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC_BIN)"
-       $(INSTALL_PROG) stubdom-dm "$(DESTDIR)$(LIBEXEC_BIN)"
-       $(INSTALL_DATA) stubdompath.sh "$(DESTDIR)$(LIBEXEC_BIN)"
-       $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
-       $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/ioemu-stubdom.gz"
-
-install-grub: pv-grub
-       $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
-       $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
-
-install-c: c-stubdom
-
-install-caml: caml-stubdom
-
-install-xenstore: xenstore-stubdom
-       $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
-       $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-xenstore/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/xenstore-stubdom.gz"
-
-install-vtpm: vtpm-stubdom
-       $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
-       $(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-vtpm/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/vtpm-stubdom.gz"
-
-install-vtpmmgr: vtpmmgr-stubdom
-       $(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
-       $(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-vtpmmgr/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/vtpmmgr-stubdom.gz"
-
-#######
-# clean
-#######
-
-# Only clean the libxc/ioemu/mini-os part
-.PHONY: clean
-clean:
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-ioemu
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-c
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstore
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpm
-       rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpmmgr
-       $(MAKE) DESTDIR= -C caml clean
-       $(MAKE) DESTDIR= -C c clean
-       $(MAKE) -C vtpm clean
-       $(MAKE) -C vtpmmgr clean
-       rm -fr grub-$(XEN_TARGET_ARCH)
-       rm -f $(STUBDOMPATH)
-       [ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
-       [ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
-       [ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
-       [ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
-       [ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory clean
-       [ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
-       -[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
-       -[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
-
-# clean the cross-compilation result
-.PHONY: crossclean
-crossclean: clean
-       rm -fr $(CROSS_ROOT)
-       rm -fr newlib-$(XEN_TARGET_ARCH)
-       rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
-       rm -fr libs-$(XEN_TARGET_ARCH)
-       rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
-       rm -fr gmp-$(XEN_TARGET_ARCH)
-       rm -fr polarssl-$(XEN_TARGET_ARCH)
-       rm -fr openssl-$(XEN_TARGET_ARCH)
-       rm -fr tpm_emulator-$(XEN_TARGET_ARCH)
-       rm -f mk-headers-$(XEN_TARGET_ARCH)
-       rm -fr ocaml-$(XEN_TARGET_ARCH)
-       rm -fr include
-
-# clean patched sources
-.PHONY: patchclean
-patchclean: crossclean
-       rm -fr newlib-$(NEWLIB_VERSION)
-       rm -fr gmp-$(XEN_TARGET_ARCH)
-       rm -fr polarssl-$(XEN_TARGET_ARCH)
-       rm -fr openssl-$(XEN_TARGET_ARCH)
-       rm -fr tpm_emulator-$(XEN_TARGET_ARCH)
-       rm -fr lwip-$(XEN_TARGET_ARCH)
-       rm -fr grub-upstream
-
-# clean downloads
-.PHONY: downloadclean
-downloadclean: patchclean
-       rm -f newlib-$(NEWLIB_VERSION).tar.gz
-       rm -f zlib-$(ZLIB_VERSION).tar.gz
-       rm -f gmp-$(GMP_VERSION).tar.gz
-       rm -f tpm_emulator-$(TPMEMU_VERSION).tar.gz
-       rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
-       rm -f grub-$(GRUB_VERSION).tar.gz
-       rm -f lwip-$(LWIP_VERSION).tar.gz
-       rm -f ocaml-$(OCAML_VERSION).tar.gz
-       rm -f polarssl-$(POLARSSL_VERSION)-gpl.tgz
-       rm -f openssl-$(POLARSSL_VERSION)-gpl.tgz
-
-.PHONY: distclean
-distclean: downloadclean
-       rm -rf config.log config.status config.cache autom4te.cache ../config/Stubdom.mk
-
-ifeq (,$(findstring clean,$(MAKECMDGOALS)))
-$(XEN_ROOT)/config/Stubdom.mk:
-       $(error You have to run ./configure before building or installing stubdom)
-endif
diff --git a/stubdom/c/Makefile b/stubdom/c/Makefile
deleted file mode 100644 (file)
index b252dca..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-XEN_ROOT = $(CURDIR)/../..
-
-ifeq (,$(findstring clean,$(MAKECMDGOALS)))
-include $(XEN_ROOT)/Config.mk
-endif
-
-all: main.a
-
-main.a: main.o 
-       $(AR) cr $@ $^
-
-clean:
-       rm -f *.a *.o
diff --git a/stubdom/c/main.c b/stubdom/c/main.c
deleted file mode 100644 (file)
index f97a0f7..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-
-int main(void) {
-        sleep(2);
-        printf("Hello, world!\n");
-        return 0;
-}
diff --git a/stubdom/c/minios.cfg b/stubdom/c/minios.cfg
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/stubdom/caml/Makefile b/stubdom/caml/Makefile
deleted file mode 100644 (file)
index f550de1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-XEN_ROOT = $(CURDIR)/../..
-
-ifeq (,$(findstring clean,$(MAKECMDGOALS)))
-include $(XEN_ROOT)/Config.mk
-endif
-
-CAMLLIB = $(shell $(OCAMLC_CROSS_PREFIX)ocamlc -where)
-DEF_CPPFLAGS += -I$(CAMLLIB)
-
-OCAMLOPT=$(OCAMLC_CROSS_PREFIX)ocamlopt
-
-OBJS := hello.cmx
-LIBS := 
-
-all: main-caml.o caml.o
-
-%.cmx: %.ml
-       $(OCAMLOPT) -c $< -o $@
-
-caml.o: $(OBJS)
-       $(OCAMLOPT) $(LIBS) $^ -output-obj -o $@
-
-clean:
-       rm -f *.a *.o *.cmx *.cmi
diff --git a/stubdom/caml/hello.ml b/stubdom/caml/hello.ml
deleted file mode 100644 (file)
index 3a71811..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-let main arg =
-  Printf.printf "Hello, world!\n%!."
-
-let _ = Callback.register "main" main
diff --git a/stubdom/caml/main-caml.c b/stubdom/caml/main-caml.c
deleted file mode 100644 (file)
index dd55aca..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Caml bootstrap
- *
- * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, January 2008
- */
-
-#include <stdio.h>
-#include <errno.h>
-
-#include <caml/mlvalues.h>
-#include <caml/callback.h>
-#include <unistd.h>
-
-/* Ugly binary compatibility with Linux */
-FILE *_stderr asm("stderr");
-int *__errno_location;
-/* Will probably break everything, probably need to fetch from glibc */
-void *__ctype_b_loc;
-
-int main(int argc, char *argv[], char *envp[])
-{
-    value *val;
-
-    /* Get current thread's value */
-    _stderr = stderr;
-    __errno_location = &errno;
-
-    printf("starting caml\n");
-
-    /* Wait before things might hang up */
-    sleep(1);
-
-    caml_startup(argv);
-    val = caml_named_value("main");
-    if (!val) {
-        printf("Couldn't find Caml main");
-        return 1;
-    }
-    caml_callback(*val, Val_int(0));
-    printf("callback returned\n");
-    return 0;
-}
diff --git a/stubdom/caml/minios.cfg b/stubdom/caml/minios.cfg
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/stubdom/configure b/stubdom/configure
deleted file mode 100755 (executable)
index 5b9c609..0000000
+++ /dev/null
@@ -1,4800 +0,0 @@
-#! /bin/sh
-# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Xen Hypervisor Stub Domains 4.7.
-#
-# Report bugs to <xen-devel@lists.xen.org>.
-#
-#
-# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
-#
-#
-# This configure script is free software; the Free Software Foundation
-# gives unlimited permission to copy, distribute and modify it.
-## -------------------- ##
-## M4sh Initialization. ##
-## -------------------- ##
-
-# Be more Bourne compatible
-DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
-  emulate sh
-  NULLCMD=:
-  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '${1+"$@"}'='"$@"'
-  setopt NO_GLOB_SUBST
-else
-  case `(set -o) 2>/dev/null` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
-esac
-fi
-
-
-as_nl='
-'
-export as_nl
-# Printing a long string crashes Solaris 7 /usr/bin/printf.
-as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
-# Prefer a ksh shell builtin over an external printf program on Solaris,
-# but without wasting forks for bash or zsh.
-if test -z "$BASH_VERSION$ZSH_VERSION" \
-    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='print -r --'
-  as_echo_n='print -rn --'
-elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='printf %s\n'
-  as_echo_n='printf %s'
-else
-  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
-    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
-    as_echo_n='/usr/ucb/echo -n'
-  else
-    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
-    as_echo_n_body='eval
-      arg=$1;
-      case $arg in #(
-      *"$as_nl"*)
-       expr "X$arg" : "X\\(.*\\)$as_nl";
-       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
-      esac;
-      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
-    '
-    export as_echo_n_body
-    as_echo_n='sh -c $as_echo_n_body as_echo'
-  fi
-  export as_echo_body
-  as_echo='sh -c $as_echo_body as_echo'
-fi
-
-# The user is always right.
-if test "${PATH_SEPARATOR+set}" != set; then
-  PATH_SEPARATOR=:
-  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
-    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
-      PATH_SEPARATOR=';'
-  }
-fi
-
-
-# IFS
-# We need space, tab and new line, in precisely that order.  Quoting is
-# there to prevent editors from complaining about space-tab.
-# (If _AS_PATH_WALK were called with IFS unset, it would disable word
-# splitting by setting IFS to empty value.)
-IFS=" ""       $as_nl"
-
-# Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
-case $0 in #((
-  *[\\/]* ) as_myself=$0 ;;
-  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-  done
-IFS=$as_save_IFS
-
-     ;;
-esac
-# We did not find ourselves, most probably we were run as `sh COMMAND'
-# in which case we are not to be found in the path.
-if test "x$as_myself" = x; then
-  as_myself=$0
-fi
-if test ! -f "$as_myself"; then
-  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  exit 1
-fi
-
-# Unset variables that we do not need and which cause bugs (e.g. in
-# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
-# suppresses any "Segmentation fault" message there.  '((' could
-# trigger a bug in pdksh 5.2.14.
-for as_var in BASH_ENV ENV MAIL MAILPATH
-do eval test x\${$as_var+set} = xset \
-  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
-done
-PS1='$ '
-PS2='> '
-PS4='+ '
-
-# NLS nuisances.
-LC_ALL=C
-export LC_ALL
-LANGUAGE=C
-export LANGUAGE
-
-# CDPATH.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-# Use a proper internal environment variable to ensure we don't fall
-  # into an infinite loop, continuously re-executing ourselves.
-  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
-    _as_can_reexec=no; export _as_can_reexec;
-    # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
-esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-as_fn_exit 255
-  fi
-  # We don't want this to propagate to other subprocesses.
-          { _as_can_reexec=; unset _as_can_reexec;}
-if test "x$CONFIG_SHELL" = x; then
-  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
-  emulate sh
-  NULLCMD=:
-  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '\${1+\"\$@\"}'='\"\$@\"'
-  setopt NO_GLOB_SUBST
-else
-  case \`(set -o) 2>/dev/null\` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
-esac
-fi
-"
-  as_required="as_fn_return () { (exit \$1); }
-as_fn_success () { as_fn_return 0; }
-as_fn_failure () { as_fn_return 1; }
-as_fn_ret_success () { return 0; }
-as_fn_ret_failure () { return 1; }
-
-exitcode=0
-as_fn_success || { exitcode=1; echo as_fn_success failed.; }
-as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
-as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
-as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
-if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
-
-else
-  exitcode=1; echo positional parameters were not saved.
-fi
-test x\$exitcode = x0 || exit 1
-test -x / || exit 1"
-  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
-  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
-  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
-  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1"
-  if (eval "$as_required") 2>/dev/null; then :
-  as_have_required=yes
-else
-  as_have_required=no
-fi
-  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
-
-else
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_found=false
-for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  as_found=:
-  case $as_dir in #(
-        /*)
-          for as_base in sh bash ksh sh5; do
-            # Try only shells that exist, to save several forks.
-            as_shell=$as_dir/$as_base
-            if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
-                   { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
-  CONFIG_SHELL=$as_shell as_have_required=yes
-                  if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
-  break 2
-fi
-fi
-          done;;
-       esac
-  as_found=false
-done
-$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
-             { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
-  CONFIG_SHELL=$SHELL as_have_required=yes
-fi; }
-IFS=$as_save_IFS
-
-
-      if test "x$CONFIG_SHELL" != x; then :
-  export CONFIG_SHELL
-             # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
-esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-exit 255
-fi
-
-    if test x$as_have_required = xno; then :
-  $as_echo "$0: This script requires a shell more modern than all"
-  $as_echo "$0: the shells that I found on your system."
-  if test x${ZSH_VERSION+set} = xset ; then
-    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
-    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
-  else
-    $as_echo "$0: Please tell bug-autoconf@gnu.org and
-$0: xen-devel@lists.xen.org about your system, including
-$0: any error possibly output before this message. Then
-$0: install a modern shell, or manually run the script
-$0: under such a shell if you do have one."
-  fi
-  exit 1
-fi
-fi
-fi
-SHELL=${CONFIG_SHELL-/bin/sh}
-export SHELL
-# Unset more variables known to interfere with behavior of common tools.
-CLICOLOR_FORCE= GREP_OPTIONS=
-unset CLICOLOR_FORCE GREP_OPTIONS
-
-## --------------------- ##
-## M4sh Shell Functions. ##
-## --------------------- ##
-# as_fn_unset VAR
-# ---------------
-# Portably unset VAR.
-as_fn_unset ()
-{
-  { eval $1=; unset $1;}
-}
-as_unset=as_fn_unset
-
-# as_fn_set_status STATUS
-# -----------------------
-# Set $? to STATUS, without forking.
-as_fn_set_status ()
-{
-  return $1
-} # as_fn_set_status
-
-# as_fn_exit STATUS
-# -----------------
-# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
-as_fn_exit ()
-{
-  set +e
-  as_fn_set_status $1
-  exit $1
-} # as_fn_exit
-
-# as_fn_mkdir_p
-# -------------
-# Create "$as_dir" as a directory, including parents if necessary.
-as_fn_mkdir_p ()
-{
-
-  case $as_dir in #(
-  -*) as_dir=./$as_dir;;
-  esac
-  test -d "$as_dir" || eval $as_mkdir_p || {
-    as_dirs=
-    while :; do
-      case $as_dir in #(
-      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
-      *) as_qdir=$as_dir;;
-      esac
-      as_dirs="'$as_qdir' $as_dirs"
-      as_dir=`$as_dirname -- "$as_dir" ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-        X"$as_dir" : 'X\(//\)[^/]' \| \
-        X"$as_dir" : 'X\(//\)$' \| \
-        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)[^/].*/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-      test -d "$as_dir" && break
-    done
-    test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
-
-
-} # as_fn_mkdir_p
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-# as_fn_append VAR VALUE
-# ----------------------
-# Append the text in VALUE to the end of the definition contained in VAR. Take
-# advantage of any shell optimizations that allow amortized linear growth over
-# repeated appends, instead of the typical quadratic growth present in naive
-# implementations.
-if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
-  eval 'as_fn_append ()
-  {
-    eval $1+=\$2
-  }'
-else
-  as_fn_append ()
-  {
-    eval $1=\$$1\$2
-  }
-fi # as_fn_append
-
-# as_fn_arith ARG...
-# ------------------
-# Perform arithmetic evaluation on the ARGs, and store the result in the
-# global $as_val. Take advantage of shells that can avoid forks. The arguments
-# must be portable across $(()) and expr.
-if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
-  eval 'as_fn_arith ()
-  {
-    as_val=$(( $* ))
-  }'
-else
-  as_fn_arith ()
-  {
-    as_val=`expr "$@" || test $? -eq 1`
-  }
-fi # as_fn_arith
-
-
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
-# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
-# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
-as_fn_error ()
-{
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
-  as_fn_exit $as_status
-} # as_fn_error
-
-if expr a : '\(a\)' >/dev/null 2>&1 &&
-   test "X`expr 00001 : '.*\(...\)'`" = X001; then
-  as_expr=expr
-else
-  as_expr=false
-fi
-
-if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
-  as_basename=basename
-else
-  as_basename=false
-fi
-
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
-else
-  as_dirname=false
-fi
-
-as_me=`$as_basename -- "$0" ||
-$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
-        X"$0" : 'X\(//\)$' \| \
-        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X/"$0" |
-    sed '/^.*\/\([^/][^/]*\)\/*$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
-
-
-  as_lineno_1=$LINENO as_lineno_1a=$LINENO
-  as_lineno_2=$LINENO as_lineno_2a=$LINENO
-  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
-  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
-  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
-  sed -n '
-    p
-    /[$]LINENO/=
-  ' <$as_myself |
-    sed '
-      s/[$]LINENO.*/&-/
-      t lineno
-      b
-      :lineno
-      N
-      :loop
-      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
-      t loop
-      s/-\n.*//
-    ' >$as_me.lineno &&
-  chmod +x "$as_me.lineno" ||
-    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
-
-  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
-  # already done that, so ensure we don't try to do so again and fall
-  # in an infinite loop.  This has already happened in practice.
-  _as_can_reexec=no; export _as_can_reexec
-  # Don't try to exec as it changes $[0], causing all sort of problems
-  # (the dirname of $[0] is not the place where we might find the
-  # original and so on.  Autoconf is especially sensitive to this).
-  . "./$as_me.lineno"
-  # Exit status is that of the last command.
-  exit
-}
-
-ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in #(((((
--n*)
-  case `echo 'xy\c'` in
-  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
-  xy)  ECHO_C='\c';;
-  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
-       ECHO_T='        ';;
-  esac;;
-*)
-  ECHO_N='-n';;
-esac
-
-rm -f conf$$ conf$$.exe conf$$.file
-if test -d conf$$.dir; then
-  rm -f conf$$.dir/conf$$.file
-else
-  rm -f conf$$.dir
-  mkdir conf$$.dir 2>/dev/null
-fi
-if (echo >conf$$.file) 2>/dev/null; then
-  if ln -s conf$$.file conf$$ 2>/dev/null; then
-    as_ln_s='ln -s'
-    # ... but there are two gotchas:
-    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
-    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
-    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
-  elif ln conf$$.file conf$$ 2>/dev/null; then
-    as_ln_s=ln
-  else
-    as_ln_s='cp -pR'
-  fi
-else
-  as_ln_s='cp -pR'
-fi
-rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
-rmdir conf$$.dir 2>/dev/null
-
-if mkdir -p . 2>/dev/null; then
-  as_mkdir_p='mkdir -p "$as_dir"'
-else
-  test -d ./-p && rmdir ./-p
-  as_mkdir_p=false
-fi
-
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
-
-# Sed expression to map a string onto a valid CPP name.
-as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
-
-# Sed expression to map a string onto a valid variable name.
-as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
-
-
-test -n "$DJDIR" || exec 7<&0 </dev/null
-exec 6>&1
-
-# Name of the host.
-# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
-# so uname gets run too.
-ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
-
-#
-# Initializations.
-#
-ac_default_prefix=/usr/local
-ac_clean_files=
-ac_config_libobj_dir=.
-LIBOBJS=
-cross_compiling=no
-subdirs=
-MFLAGS=
-MAKEFLAGS=
-
-# Identity of this package.
-PACKAGE_NAME='Xen Hypervisor Stub Domains'
-PACKAGE_TARNAME='xen'
-PACKAGE_VERSION='4.7'
-PACKAGE_STRING='Xen Hypervisor Stub Domains 4.7'
-PACKAGE_BUGREPORT='xen-devel@lists.xen.org'
-PACKAGE_URL='http://www.xen.org/'
-
-ac_unique_file="xenstore-minios.cfg"
-ac_subst_vars='LTLIBOBJS
-LIBOBJS
-STUBDOM_INSTALL
-STUBDOM_BUILD
-STUBDOM_TARGETS
-ioemu
-vtpmmgr
-vtpm
-TPMEMU_VERSION
-TPMEMU_URL
-POLARSSL_VERSION
-POLARSSL_URL
-GMP_VERSION
-GMP_URL
-OCAML_VERSION
-OCAML_URL
-GRUB_VERSION
-GRUB_URL
-LWIP_VERSION
-LWIP_URL
-NEWLIB_VERSION
-NEWLIB_URL
-LIBPCI_VERSION
-LIBPCI_URL
-ZLIB_VERSION
-ZLIB_URL
-INSTALL_DATA
-INSTALL_SCRIPT
-INSTALL_PROGRAM
-SET_MAKE
-OBJEXT
-EXEEXT
-ac_ct_CC
-CPPFLAGS
-LDFLAGS
-CFLAGS
-CC
-FETCHER
-FTP
-WGET
-CMAKE
-extfiles
-debug
-xenstore
-grub
-caml
-c
-host_os
-host_vendor
-host_cpu
-host
-build_os
-build_vendor
-build_cpu
-build
-target_alias
-host_alias
-build_alias
-LIBS
-ECHO_T
-ECHO_N
-ECHO_C
-DEFS
-mandir
-localedir
-libdir
-psdir
-pdfdir
-dvidir
-htmldir
-infodir
-docdir
-oldincludedir
-includedir
-localstatedir
-sharedstatedir
-sysconfdir
-datadir
-datarootdir
-libexecdir
-sbindir
-bindir
-program_transform_name
-prefix
-exec_prefix
-PACKAGE_URL
-PACKAGE_BUGREPORT
-PACKAGE_STRING
-PACKAGE_VERSION
-PACKAGE_TARNAME
-PACKAGE_NAME
-PATH_SEPARATOR
-SHELL'
-ac_subst_files=''
-ac_user_opts='
-enable_option_checking
-enable_ioemu_stubdom
-enable_c_stubdom
-enable_caml_stubdom
-enable_pv_grub
-enable_xenstore_stubdom
-enable_vtpm_stubdom
-enable_vtpmmgr_stubdom
-enable_qemu_traditional
-enable_debug
-enable_extfiles
-'
-      ac_precious_vars='build_alias
-host_alias
-target_alias
-CMAKE
-CC
-CFLAGS
-LDFLAGS
-LIBS
-CPPFLAGS
-ZLIB_URL
-LIBPCI_URL
-NEWLIB_URL
-LWIP_URL
-GRUB_URL
-OCAML_URL
-GMP_URL
-POLARSSL_URL
-TPMEMU_URL'
-
-
-# Initialize some variables set by options.
-ac_init_help=
-ac_init_version=false
-ac_unrecognized_opts=
-ac_unrecognized_sep=
-# The variables have the same names as the options, with
-# dashes changed to underlines.
-cache_file=/dev/null
-exec_prefix=NONE
-no_create=
-no_recursion=
-prefix=NONE
-program_prefix=NONE
-program_suffix=NONE
-program_transform_name=s,x,x,
-silent=
-site=
-srcdir=
-verbose=
-x_includes=NONE
-x_libraries=NONE
-
-# Installation directory options.
-# These are left unexpanded so users can "make install exec_prefix=/foo"
-# and all the variables that are supposed to be based on exec_prefix
-# by default will actually change.
-# Use braces instead of parens because sh, perl, etc. also accept them.
-# (The list follows the same order as the GNU Coding Standards.)
-bindir='${exec_prefix}/bin'
-sbindir='${exec_prefix}/sbin'
-libexecdir='${exec_prefix}/libexec'
-datarootdir='${prefix}/share'
-datadir='${datarootdir}'
-sysconfdir='${prefix}/etc'
-sharedstatedir='${prefix}/com'
-localstatedir='${prefix}/var'
-includedir='${prefix}/include'
-oldincludedir='/usr/include'
-docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
-infodir='${datarootdir}/info'
-htmldir='${docdir}'
-dvidir='${docdir}'
-pdfdir='${docdir}'
-psdir='${docdir}'
-libdir='${exec_prefix}/lib'
-localedir='${datarootdir}/locale'
-mandir='${datarootdir}/man'
-
-ac_prev=
-ac_dashdash=
-for ac_option
-do
-  # If the previous option needs an argument, assign it.
-  if test -n "$ac_prev"; then
-    eval $ac_prev=\$ac_option
-    ac_prev=
-    continue
-  fi
-
-  case $ac_option in
-  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
-  *=)   ac_optarg= ;;
-  *)    ac_optarg=yes ;;
-  esac
-
-  # Accept the important Cygnus configure options, so we can diagnose typos.
-
-  case $ac_dashdash$ac_option in
-  --)
-    ac_dashdash=yes ;;
-
-  -bindir | --bindir | --bindi | --bind | --bin | --bi)
-    ac_prev=bindir ;;
-  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
-    bindir=$ac_optarg ;;
-
-  -build | --build | --buil | --bui | --bu)
-    ac_prev=build_alias ;;
-  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
-    build_alias=$ac_optarg ;;
-
-  -cache-file | --cache-file | --cache-fil | --cache-fi \
-  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
-    ac_prev=cache_file ;;
-  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
-  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
-    cache_file=$ac_optarg ;;
-
-  --config-cache | -C)
-    cache_file=config.cache ;;
-
-  -datadir | --datadir | --datadi | --datad)
-    ac_prev=datadir ;;
-  -datadir=* | --datadir=* | --datadi=* | --datad=*)
-    datadir=$ac_optarg ;;
-
-  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
-  | --dataroo | --dataro | --datar)
-    ac_prev=datarootdir ;;
-  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
-  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
-    datarootdir=$ac_optarg ;;
-
-  -disable-* | --disable-*)
-    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
-    # Reject names that are not valid shell variable names.
-    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid feature name: $ac_useropt"
-    ac_useropt_orig=$ac_useropt
-    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
-    case $ac_user_opts in
-      *"
-"enable_$ac_useropt"
-"*) ;;
-      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
-        ac_unrecognized_sep=', ';;
-    esac
-    eval enable_$ac_useropt=no ;;
-
-  -docdir | --docdir | --docdi | --doc | --do)
-    ac_prev=docdir ;;
-  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
-    docdir=$ac_optarg ;;
-
-  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
-    ac_prev=dvidir ;;
-  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
-    dvidir=$ac_optarg ;;
-
-  -enable-* | --enable-*)
-    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
-    # Reject names that are not valid shell variable names.
-    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid feature name: $ac_useropt"
-    ac_useropt_orig=$ac_useropt
-    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
-    case $ac_user_opts in
-      *"
-"enable_$ac_useropt"
-"*) ;;
-      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
-        ac_unrecognized_sep=', ';;
-    esac
-    eval enable_$ac_useropt=\$ac_optarg ;;
-
-  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
-  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
-  | --exec | --exe | --ex)
-    ac_prev=exec_prefix ;;
-  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
-  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
-  | --exec=* | --exe=* | --ex=*)
-    exec_prefix=$ac_optarg ;;
-
-  -gas | --gas | --ga | --g)
-    # Obsolete; use --with-gas.
-    with_gas=yes ;;
-
-  -help | --help | --hel | --he | -h)
-    ac_init_help=long ;;
-  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
-    ac_init_help=recursive ;;
-  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
-    ac_init_help=short ;;
-
-  -host | --host | --hos | --ho)
-    ac_prev=host_alias ;;
-  -host=* | --host=* | --hos=* | --ho=*)
-    host_alias=$ac_optarg ;;
-
-  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
-    ac_prev=htmldir ;;
-  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
-  | --ht=*)
-    htmldir=$ac_optarg ;;
-
-  -includedir | --includedir | --includedi | --included | --include \
-  | --includ | --inclu | --incl | --inc)
-    ac_prev=includedir ;;
-  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
-  | --includ=* | --inclu=* | --incl=* | --inc=*)
-    includedir=$ac_optarg ;;
-
-  -infodir | --infodir | --infodi | --infod | --info | --inf)
-    ac_prev=infodir ;;
-  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
-    infodir=$ac_optarg ;;
-
-  -libdir | --libdir | --libdi | --libd)
-    ac_prev=libdir ;;
-  -libdir=* | --libdir=* | --libdi=* | --libd=*)
-    libdir=$ac_optarg ;;
-
-  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
-  | --libexe | --libex | --libe)
-    ac_prev=libexecdir ;;
-  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
-  | --libexe=* | --libex=* | --libe=*)
-    libexecdir=$ac_optarg ;;
-
-  -localedir | --localedir | --localedi | --localed | --locale)
-    ac_prev=localedir ;;
-  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
-    localedir=$ac_optarg ;;
-
-  -localstatedir | --localstatedir | --localstatedi | --localstated \
-  | --localstate | --localstat | --localsta | --localst | --locals)
-    ac_prev=localstatedir ;;
-  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
-  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
-    localstatedir=$ac_optarg ;;
-
-  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
-    ac_prev=mandir ;;
-  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
-    mandir=$ac_optarg ;;
-
-  -nfp | --nfp | --nf)
-    # Obsolete; use --without-fp.
-    with_fp=no ;;
-
-  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
-  | --no-cr | --no-c | -n)
-    no_create=yes ;;
-
-  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
-  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
-    no_recursion=yes ;;
-
-  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
-  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
-  | --oldin | --oldi | --old | --ol | --o)
-    ac_prev=oldincludedir ;;
-  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
-  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
-  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
-    oldincludedir=$ac_optarg ;;
-
-  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
-    ac_prev=prefix ;;
-  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
-    prefix=$ac_optarg ;;
-
-  -program-prefix | --program-prefix | --program-prefi | --program-pref \
-  | --program-pre | --program-pr | --program-p)
-    ac_prev=program_prefix ;;
-  -program-prefix=* | --program-prefix=* | --program-prefi=* \
-  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
-    program_prefix=$ac_optarg ;;
-
-  -program-suffix | --program-suffix | --program-suffi | --program-suff \
-  | --program-suf | --program-su | --program-s)
-    ac_prev=program_suffix ;;
-  -program-suffix=* | --program-suffix=* | --program-suffi=* \
-  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
-    program_suffix=$ac_optarg ;;
-
-  -program-transform-name | --program-transform-name \
-  | --program-transform-nam | --program-transform-na \
-  | --program-transform-n | --program-transform- \
-  | --program-transform | --program-transfor \
-  | --program-transfo | --program-transf \
-  | --program-trans | --program-tran \
-  | --progr-tra | --program-tr | --program-t)
-    ac_prev=program_transform_name ;;
-  -program-transform-name=* | --program-transform-name=* \
-  | --program-transform-nam=* | --program-transform-na=* \
-  | --program-transform-n=* | --program-transform-=* \
-  | --program-transform=* | --program-transfor=* \
-  | --program-transfo=* | --program-transf=* \
-  | --program-trans=* | --program-tran=* \
-  | --progr-tra=* | --program-tr=* | --program-t=*)
-    program_transform_name=$ac_optarg ;;
-
-  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
-    ac_prev=pdfdir ;;
-  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
-    pdfdir=$ac_optarg ;;
-
-  -psdir | --psdir | --psdi | --psd | --ps)
-    ac_prev=psdir ;;
-  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
-    psdir=$ac_optarg ;;
-
-  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
-  | -silent | --silent | --silen | --sile | --sil)
-    silent=yes ;;
-
-  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
-    ac_prev=sbindir ;;
-  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
-  | --sbi=* | --sb=*)
-    sbindir=$ac_optarg ;;
-
-  -sharedstatedir | --sharedstatedir | --sharedstatedi \
-  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
-  | --sharedst | --shareds | --shared | --share | --shar \
-  | --sha | --sh)
-    ac_prev=sharedstatedir ;;
-  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
-  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
-  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
-  | --sha=* | --sh=*)
-    sharedstatedir=$ac_optarg ;;
-
-  -site | --site | --sit)
-    ac_prev=site ;;
-  -site=* | --site=* | --sit=*)
-    site=$ac_optarg ;;
-
-  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
-    ac_prev=srcdir ;;
-  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
-    srcdir=$ac_optarg ;;
-
-  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
-  | --syscon | --sysco | --sysc | --sys | --sy)
-    ac_prev=sysconfdir ;;
-  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
-  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
-    sysconfdir=$ac_optarg ;;
-
-  -target | --target | --targe | --targ | --tar | --ta | --t)
-    ac_prev=target_alias ;;
-  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
-    target_alias=$ac_optarg ;;
-
-  -v | -verbose | --verbose | --verbos | --verbo | --verb)
-    verbose=yes ;;
-
-  -version | --version | --versio | --versi | --vers | -V)
-    ac_init_version=: ;;
-
-  -with-* | --with-*)
-    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
-    # Reject names that are not valid shell variable names.
-    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid package name: $ac_useropt"
-    ac_useropt_orig=$ac_useropt
-    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
-    case $ac_user_opts in
-      *"
-"with_$ac_useropt"
-"*) ;;
-      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
-        ac_unrecognized_sep=', ';;
-    esac
-    eval with_$ac_useropt=\$ac_optarg ;;
-
-  -without-* | --without-*)
-    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
-    # Reject names that are not valid shell variable names.
-    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
-      as_fn_error $? "invalid package name: $ac_useropt"
-    ac_useropt_orig=$ac_useropt
-    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
-    case $ac_user_opts in
-      *"
-"with_$ac_useropt"
-"*) ;;
-      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
-        ac_unrecognized_sep=', ';;
-    esac
-    eval with_$ac_useropt=no ;;
-
-  --x)
-    # Obsolete; use --with-x.
-    with_x=yes ;;
-
-  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
-  | --x-incl | --x-inc | --x-in | --x-i)
-    ac_prev=x_includes ;;
-  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
-  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
-    x_includes=$ac_optarg ;;
-
-  -x-libraries | --x-libraries | --x-librarie | --x-librari \
-  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
-    ac_prev=x_libraries ;;
-  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
-  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
-    x_libraries=$ac_optarg ;;
-
-  -*) as_fn_error $? "unrecognized option: \`$ac_option'
-Try \`$0 --help' for more information"
-    ;;
-
-  *=*)
-    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
-    # Reject names that are not valid shell variable names.
-    case $ac_envvar in #(
-      '' | [0-9]* | *[!_$as_cr_alnum]* )
-      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
-    esac
-    eval $ac_envvar=\$ac_optarg
-    export $ac_envvar ;;
-
-  *)
-    # FIXME: should be removed in autoconf 3.0.
-    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
-    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
-    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
-    ;;
-
-  esac
-done
-
-if test -n "$ac_prev"; then
-  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
-  as_fn_error $? "missing argument to $ac_option"
-fi
-
-if test -n "$ac_unrecognized_opts"; then
-  case $enable_option_checking in
-    no) ;;
-    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
-    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
-  esac
-fi
-
-# Check all directory arguments for consistency.
-for ac_var in  exec_prefix prefix bindir sbindir libexecdir datarootdir \
-               datadir sysconfdir sharedstatedir localstatedir includedir \
-               oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-               libdir localedir mandir
-do
-  eval ac_val=\$$ac_var
-  # Remove trailing slashes.
-  case $ac_val in
-    */ )
-      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
-      eval $ac_var=\$ac_val;;
-  esac
-  # Be sure to have absolute directory names.
-  case $ac_val in
-    [\\/$]* | ?:[\\/]* )  continue;;
-    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
-  esac
-  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
-done
-
-# There might be people who depend on the old broken behavior: `$host'
-# used to hold the argument of --host etc.
-# FIXME: To remove some day.
-build=$build_alias
-host=$host_alias
-target=$target_alias
-
-# FIXME: To remove some day.
-if test "x$host_alias" != x; then
-  if test "x$build_alias" = x; then
-    cross_compiling=maybe
-  elif test "x$build_alias" != "x$host_alias"; then
-    cross_compiling=yes
-  fi
-fi
-
-ac_tool_prefix=
-test -n "$host_alias" && ac_tool_prefix=$host_alias-
-
-test "$silent" = yes && exec 6>/dev/null
-
-
-ac_pwd=`pwd` && test -n "$ac_pwd" &&
-ac_ls_di=`ls -di .` &&
-ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
-  as_fn_error $? "working directory cannot be determined"
-test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
-  as_fn_error $? "pwd does not report name of working directory"
-
-
-# Find the source files, if location was not specified.
-if test -z "$srcdir"; then
-  ac_srcdir_defaulted=yes
-  # Try the directory containing this script, then the parent directory.
-  ac_confdir=`$as_dirname -- "$as_myself" ||
-$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-        X"$as_myself" : 'X\(//\)[^/]' \| \
-        X"$as_myself" : 'X\(//\)$' \| \
-        X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$as_myself" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)[^/].*/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-  srcdir=$ac_confdir
-  if test ! -r "$srcdir/$ac_unique_file"; then
-    srcdir=..
-  fi
-else
-  ac_srcdir_defaulted=no
-fi
-if test ! -r "$srcdir/$ac_unique_file"; then
-  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
-  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
-fi
-ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
-ac_abs_confdir=`(
-       cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
-       pwd)`
-# When building in place, set srcdir=.
-if test "$ac_abs_confdir" = "$ac_pwd"; then
-  srcdir=.
-fi
-# Remove unnecessary trailing slashes from srcdir.
-# Double slashes in file names in object file debugging info
-# mess up M-x gdb in Emacs.
-case $srcdir in
-*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
-esac
-for ac_var in $ac_precious_vars; do
-  eval ac_env_${ac_var}_set=\${${ac_var}+set}
-  eval ac_env_${ac_var}_value=\$${ac_var}
-  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
-  eval ac_cv_env_${ac_var}_value=\$${ac_var}
-done
-
-#
-# Report the --help message.
-#
-if test "$ac_init_help" = "long"; then
-  # Omit some internal or obsolete options to make the list less imposing.
-  # This message is too long to be a string in the A/UX 3.1 sh.
-  cat <<_ACEOF
-\`configure' configures Xen Hypervisor Stub Domains 4.7 to adapt to many kinds of systems.
-
-Usage: $0 [OPTION]... [VAR=VALUE]...
-
-To assign environment variables (e.g., CC, CFLAGS...), specify them as
-VAR=VALUE.  See below for descriptions of some of the useful variables.
-
-Defaults for the options are specified in brackets.
-
-Configuration:
-  -h, --help              display this help and exit
-      --help=short        display options specific to this package
-      --help=recursive    display the short help of all the included packages
-  -V, --version           display version information and exit
-  -q, --quiet, --silent   do not print \`checking ...' messages
-      --cache-file=FILE   cache test results in FILE [disabled]
-  -C, --config-cache      alias for \`--cache-file=config.cache'
-  -n, --no-create         do not create output files
-      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
-
-Installation directories:
-  --prefix=PREFIX         install architecture-independent files in PREFIX
-                          [$ac_default_prefix]
-  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
-                          [PREFIX]
-
-By default, \`make install' will install all the files in
-\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
-an installation prefix other than \`$ac_default_prefix' using \`--prefix',
-for instance \`--prefix=\$HOME'.
-
-For better control, use the options below.
-
-Fine tuning of the installation directories:
-  --bindir=DIR            user executables [EPREFIX/bin]
-  --sbindir=DIR           system admin executables [EPREFIX/sbin]
-  --libexecdir=DIR        program executables [EPREFIX/libexec]
-  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
-  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
-  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --libdir=DIR            object code libraries [EPREFIX/lib]
-  --includedir=DIR        C header files [PREFIX/include]
-  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
-  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
-  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
-  --infodir=DIR           info documentation [DATAROOTDIR/info]
-  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
-  --mandir=DIR            man documentation [DATAROOTDIR/man]
-  --docdir=DIR            documentation root [DATAROOTDIR/doc/xen]
-  --htmldir=DIR           html documentation [DOCDIR]
-  --dvidir=DIR            dvi documentation [DOCDIR]
-  --pdfdir=DIR            pdf documentation [DOCDIR]
-  --psdir=DIR             ps documentation [DOCDIR]
-_ACEOF
-
-  cat <<\_ACEOF
-
-System types:
-  --build=BUILD     configure for building on BUILD [guessed]
-  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
-_ACEOF
-fi
-
-if test -n "$ac_init_help"; then
-  case $ac_init_help in
-     short | recursive ) echo "Configuration of Xen Hypervisor Stub Domains 4.7:";;
-   esac
-  cat <<\_ACEOF
-
-Optional Features:
-  --disable-option-checking  ignore unrecognized --enable/--with options
-  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
-  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --enable-ioemu-stubdom  Build and install ioemu-stubdom
-  --enable-c-stubdom      Build and install c-stubdom (default is DISABLED)
-  --enable-caml-stubdom   Build and install caml-stubdom (default is DISABLED)
-  --disable-pv-grub       Build and install pv-grub (default is ENABLED)
-  --disable-xenstore-stubdom
-                          Build and install xenstore-stubdom (default is
-                          ENABLED)
-  --enable-vtpm-stubdom   Build and install vtpm-stubdom
-  --enable-vtpmmgr-stubdom
-                          Build and install vtpmmgr-stubdom
-
-  --disable-debug         Disable debug build of stubdom (default is ENABLED)
-  --disable-extfiles      Use xen extfiles repository for libraries (default
-                          is ENABLED)
-
-Some influential environment variables:
-  CMAKE       Path to the cmake program
-  CC          C compiler command
-  CFLAGS      C compiler flags
-  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
-              nonstandard directory <lib dir>
-  LIBS        libraries to pass to the linker, e.g. -l<library>
-  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
-              you have headers in a nonstandard directory <include dir>
-  ZLIB_URL    Download url for zlib
-  LIBPCI_URL  Download url for libpci
-  NEWLIB_URL  Download url for newlib
-  LWIP_URL    Download url for lwip
-  GRUB_URL    Download url for grub
-  OCAML_URL   Download url for ocaml
-  GMP_URL     Download url for libgmp
-  POLARSSL_URL
-              Download url for polarssl
-  TPMEMU_URL  Download url for berlios tpm emulator
-
-Use these variables to override the choices made by `configure' or to help
-it to find libraries and programs with nonstandard names/locations.
-
-Report bugs to <xen-devel@lists.xen.org>.
-Xen Hypervisor Stub Domains home page: <http://www.xen.org/>.
-_ACEOF
-ac_status=$?
-fi
-
-if test "$ac_init_help" = "recursive"; then
-  # If there are subdirs, report their specific --help.
-  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
-    test -d "$ac_dir" ||
-      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
-      continue
-    ac_builddir=.
-
-case "$ac_dir" in
-.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
-*)
-  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
-  # A ".." for each directory in $ac_dir_suffix.
-  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
-  case $ac_top_builddir_sub in
-  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
-  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
-  esac ;;
-esac
-ac_abs_top_builddir=$ac_pwd
-ac_abs_builddir=$ac_pwd$ac_dir_suffix
-# for backward compatibility:
-ac_top_builddir=$ac_top_build_prefix
-
-case $srcdir in
-  .)  # We are building in place.
-    ac_srcdir=.
-    ac_top_srcdir=$ac_top_builddir_sub
-    ac_abs_top_srcdir=$ac_pwd ;;
-  [\\/]* | ?:[\\/]* )  # Absolute name.
-    ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir
-    ac_abs_top_srcdir=$srcdir ;;
-  *) # Relative name.
-    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_build_prefix$srcdir
-    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
-esac
-ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
-
-    cd "$ac_dir" || { ac_status=$?; continue; }
-    # Check for guested configure.
-    if test -f "$ac_srcdir/configure.gnu"; then
-      echo &&
-      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
-    elif test -f "$ac_srcdir/configure"; then
-      echo &&
-      $SHELL "$ac_srcdir/configure" --help=recursive
-    else
-      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
-    fi || ac_status=$?
-    cd "$ac_pwd" || { ac_status=$?; break; }
-  done
-fi
-
-test -n "$ac_init_help" && exit $ac_status
-if $ac_init_version; then
-  cat <<\_ACEOF
-Xen Hypervisor Stub Domains configure 4.7
-generated by GNU Autoconf 2.69
-
-Copyright (C) 2012 Free Software Foundation, Inc.
-This configure script is free software; the Free Software Foundation
-gives unlimited permission to copy, distribute and modify it.
-_ACEOF
-  exit
-fi
-
-## ------------------------ ##
-## Autoconf initialization. ##
-## ------------------------ ##
-
-# ac_fn_c_try_compile LINENO
-# --------------------------
-# Try to compile conftest.$ac_ext, and return whether this succeeded.
-ac_fn_c_try_compile ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext
-  if { { ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compile") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-        test -z "$ac_c_werror_flag" ||
-        test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-       ac_retval=1
-fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_c_try_compile
-cat >config.log <<_ACEOF
-This file contains any messages produced by compilers while
-running configure, to aid debugging if configure makes a mistake.
-
-It was created by Xen Hypervisor Stub Domains $as_me 4.7, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
-
-  $ $0 $@
-
-_ACEOF
-exec 5>>config.log
-{
-cat <<_ASUNAME
-## --------- ##
-## Platform. ##
-## --------- ##
-
-hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
-uname -m = `(uname -m) 2>/dev/null || echo unknown`
-uname -r = `(uname -r) 2>/dev/null || echo unknown`
-uname -s = `(uname -s) 2>/dev/null || echo unknown`
-uname -v = `(uname -v) 2>/dev/null || echo unknown`
-
-/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
-/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
-
-/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
-/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
-/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
-/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
-/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
-/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
-/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
-
-_ASUNAME
-
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    $as_echo "PATH: $as_dir"
-  done
-IFS=$as_save_IFS
-
-} >&5
-
-cat >&5 <<_ACEOF
-
-
-## ----------- ##
-## Core tests. ##
-## ----------- ##
-
-_ACEOF
-
-
-# Keep a trace of the command line.
-# Strip out --no-create and --no-recursion so they do not pile up.
-# Strip out --silent because we don't want to record it for future runs.
-# Also quote any args containing shell meta-characters.
-# Make two passes to allow for proper duplicate-argument suppression.
-ac_configure_args=
-ac_configure_args0=
-ac_configure_args1=
-ac_must_keep_next=false
-for ac_pass in 1 2
-do
-  for ac_arg
-  do
-    case $ac_arg in
-    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
-    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
-    | -silent | --silent | --silen | --sile | --sil)
-      continue ;;
-    *\'*)
-      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
-    esac
-    case $ac_pass in
-    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
-    2)
-      as_fn_append ac_configure_args1 " '$ac_arg'"
-      if test $ac_must_keep_next = true; then
-       ac_must_keep_next=false # Got value, back to normal.
-      else
-       case $ac_arg in
-         *=* | --config-cache | -C | -disable-* | --disable-* \
-         | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
-         | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
-         | -with-* | --with-* | -without-* | --without-* | --x)
-           case "$ac_configure_args0 " in
-             "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
-           esac
-           ;;
-         -* ) ac_must_keep_next=true ;;
-       esac
-      fi
-      as_fn_append ac_configure_args " '$ac_arg'"
-      ;;
-    esac
-  done
-done
-{ ac_configure_args0=; unset ac_configure_args0;}
-{ ac_configure_args1=; unset ac_configure_args1;}
-
-# When interrupted or exit'd, cleanup temporary files, and complete
-# config.log.  We remove comments because anyway the quotes in there
-# would cause problems or look ugly.
-# WARNING: Use '\'' to represent an apostrophe within the trap.
-# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
-trap 'exit_status=$?
-  # Save into config.log some information that might help in debugging.
-  {
-    echo
-
-    $as_echo "## ---------------- ##
-## Cache variables. ##
-## ---------------- ##"
-    echo
-    # The following way of writing the cache mishandles newlines in values,
-(
-  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
-    eval ac_val=\$$ac_var
-    case $ac_val in #(
-    *${as_nl}*)
-      case $ac_var in #(
-      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
-$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
-      esac
-      case $ac_var in #(
-      _ | IFS | as_nl) ;; #(
-      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
-      *) { eval $ac_var=; unset $ac_var;} ;;
-      esac ;;
-    esac
-  done
-  (set) 2>&1 |
-    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
-    *${as_nl}ac_space=\ *)
-      sed -n \
-       "s/'\''/'\''\\\\'\'''\''/g;
-         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
-      ;; #(
-    *)
-      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
-      ;;
-    esac |
-    sort
-)
-    echo
-
-    $as_echo "## ----------------- ##
-## Output variables. ##
-## ----------------- ##"
-    echo
-    for ac_var in $ac_subst_vars
-    do
-      eval ac_val=\$$ac_var
-      case $ac_val in
-      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
-      esac
-      $as_echo "$ac_var='\''$ac_val'\''"
-    done | sort
-    echo
-
-    if test -n "$ac_subst_files"; then
-      $as_echo "## ------------------- ##
-## File substitutions. ##
-## ------------------- ##"
-      echo
-      for ac_var in $ac_subst_files
-      do
-       eval ac_val=\$$ac_var
-       case $ac_val in
-       *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
-       esac
-       $as_echo "$ac_var='\''$ac_val'\''"
-      done | sort
-      echo
-    fi
-
-    if test -s confdefs.h; then
-      $as_echo "## ----------- ##
-## confdefs.h. ##
-## ----------- ##"
-      echo
-      cat confdefs.h
-      echo
-    fi
-    test "$ac_signal" != 0 &&
-      $as_echo "$as_me: caught signal $ac_signal"
-    $as_echo "$as_me: exit $exit_status"
-  } >&5
-  rm -f core *.core core.conftest.* &&
-    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
-    exit $exit_status
-' 0
-for ac_signal in 1 2 13 15; do
-  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
-done
-ac_signal=0
-
-# confdefs.h avoids OS command line length limits that DEFS can exceed.
-rm -f -r conftest* confdefs.h
-
-$as_echo "/* confdefs.h */" > confdefs.h
-
-# Predefined preprocessor variables.
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_NAME "$PACKAGE_NAME"
-_ACEOF
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
-_ACEOF
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_VERSION "$PACKAGE_VERSION"
-_ACEOF
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_STRING "$PACKAGE_STRING"
-_ACEOF
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
-_ACEOF
-
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_URL "$PACKAGE_URL"
-_ACEOF
-
-
-# Let the site file select an alternate cache file if it wants to.
-# Prefer an explicitly selected file to automatically selected ones.
-ac_site_file1=NONE
-ac_site_file2=NONE
-if test -n "$CONFIG_SITE"; then
-  # We do not want a PATH search for config.site.
-  case $CONFIG_SITE in #((
-    -*)  ac_site_file1=./$CONFIG_SITE;;
-    */*) ac_site_file1=$CONFIG_SITE;;
-    *)   ac_site_file1=./$CONFIG_SITE;;
-  esac
-elif test "x$prefix" != xNONE; then
-  ac_site_file1=$prefix/share/config.site
-  ac_site_file2=$prefix/etc/config.site
-else
-  ac_site_file1=$ac_default_prefix/share/config.site
-  ac_site_file2=$ac_default_prefix/etc/config.site
-fi
-for ac_site_file in "$ac_site_file1" "$ac_site_file2"
-do
-  test "x$ac_site_file" = xNONE && continue
-  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
-$as_echo "$as_me: loading site script $ac_site_file" >&6;}
-    sed 's/^/| /' "$ac_site_file" >&5
-    . "$ac_site_file" \
-      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "failed to load site script $ac_site_file
-See \`config.log' for more details" "$LINENO" 5; }
-  fi
-done
-
-if test -r "$cache_file"; then
-  # Some versions of bash will fail to source /dev/null (special files
-  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
-  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
-$as_echo "$as_me: loading cache $cache_file" >&6;}
-    case $cache_file in
-      [\\/]* | ?:[\\/]* ) . "$cache_file";;
-      *)                      . "./$cache_file";;
-    esac
-  fi
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
-$as_echo "$as_me: creating cache $cache_file" >&6;}
-  >$cache_file
-fi
-
-# Check that the precious variables saved in the cache have kept the same
-# value.
-ac_cache_corrupted=false
-for ac_var in $ac_precious_vars; do
-  eval ac_old_set=\$ac_cv_env_${ac_var}_set
-  eval ac_new_set=\$ac_env_${ac_var}_set
-  eval ac_old_val=\$ac_cv_env_${ac_var}_value
-  eval ac_new_val=\$ac_env_${ac_var}_value
-  case $ac_old_set,$ac_new_set in
-    set,)
-      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
-$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
-      ac_cache_corrupted=: ;;
-    ,set)
-      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
-$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
-      ac_cache_corrupted=: ;;
-    ,);;
-    *)
-      if test "x$ac_old_val" != "x$ac_new_val"; then
-       # differences in whitespace do not lead to failure.
-       ac_old_val_w=`echo x $ac_old_val`
-       ac_new_val_w=`echo x $ac_new_val`
-       if test "$ac_old_val_w" != "$ac_new_val_w"; then
-         { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
-$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
-         ac_cache_corrupted=:
-       else
-         { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
-$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
-         eval $ac_var=\$ac_old_val
-       fi
-       { $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
-$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
-       { $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
-$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
-      fi;;
-  esac
-  # Pass precious variables to config.status.
-  if test "$ac_new_set" = set; then
-    case $ac_new_val in
-    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
-    *) ac_arg=$ac_var=$ac_new_val ;;
-    esac
-    case " $ac_configure_args " in
-      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
-      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
-    esac
-  fi
-done
-if $ac_cache_corrupted; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
-$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
-  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
-fi
-## -------------------- ##
-## Main body of script. ##
-## -------------------- ##
-
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-
-
-ac_config_files="$ac_config_files ../config/Stubdom.mk"
-
-ac_aux_dir=
-for ac_dir in ../ "$srcdir"/../; do
-  if test -f "$ac_dir/install-sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install-sh -c"
-    break
-  elif test -f "$ac_dir/install.sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install.sh -c"
-    break
-  elif test -f "$ac_dir/shtool"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/shtool install -c"
-    break
-  fi
-done
-if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in ../ \"$srcdir\"/../" "$LINENO" 5
-fi
-
-# These three variables are undocumented and unsupported,
-# and are intended to be withdrawn in a future Autoconf release.
-# They can cause serious problems if a builder's source tree is in a directory
-# whose full name contains unusual characters.
-ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
-ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
-ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
-
-
-
-# Make sure we can run config.sub.
-$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
-  as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
-$as_echo_n "checking build system type... " >&6; }
-if ${ac_cv_build+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_build_alias=$build_alias
-test "x$ac_build_alias" = x &&
-  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
-test "x$ac_build_alias" = x &&
-  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
-ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
-  as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
-$as_echo "$ac_cv_build" >&6; }
-case $ac_cv_build in
-*-*-*) ;;
-*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
-esac
-build=$ac_cv_build
-ac_save_IFS=$IFS; IFS='-'
-set x $ac_cv_build
-shift
-build_cpu=$1
-build_vendor=$2
-shift; shift
-# Remember, the first character of IFS is used to create $*,
-# except with old shells:
-build_os=$*
-IFS=$ac_save_IFS
-case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
-$as_echo_n "checking host system type... " >&6; }
-if ${ac_cv_host+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test "x$host_alias" = x; then
-  ac_cv_host=$ac_cv_build
-else
-  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
-    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
-$as_echo "$ac_cv_host" >&6; }
-case $ac_cv_host in
-*-*-*) ;;
-*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
-esac
-host=$ac_cv_host
-ac_save_IFS=$IFS; IFS='-'
-set x $ac_cv_host
-shift
-host_cpu=$1
-host_vendor=$2
-shift; shift
-# Remember, the first character of IFS is used to create $*,
-# except with old shells:
-host_os=$*
-IFS=$ac_save_IFS
-case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
-
-
-
-# M4 Macro includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-# Enable/disable stub domains
-
-# Check whether --enable-ioemu-stubdom was given.
-if test "${enable_ioemu_stubdom+set}" = set; then :
-  enableval=$enable_ioemu_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-ioemu=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS ioemu"
-STUBDOM_BUILD="$STUBDOM_BUILD ioemu-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-ioemu"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-ioemu=n
-
-
-fi
-
-fi
-
-
-fi
-
-
-
-# Check whether --enable-c-stubdom was given.
-if test "${enable_c_stubdom+set}" = set; then :
-  enableval=$enable_c_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-c=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS c"
-STUBDOM_BUILD="$STUBDOM_BUILD c-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-c"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-c=n
-
-
-fi
-
-fi
-
-
-else
-
-
-c=n
-
-
-fi
-
-
-
-
-# Check whether --enable-caml-stubdom was given.
-if test "${enable_caml_stubdom+set}" = set; then :
-  enableval=$enable_caml_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-caml=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS caml"
-STUBDOM_BUILD="$STUBDOM_BUILD caml-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-caml"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-caml=n
-
-
-fi
-
-fi
-
-
-else
-
-
-caml=n
-
-
-fi
-
-
-
-
-# Check whether --enable-pv-grub was given.
-if test "${enable_pv_grub+set}" = set; then :
-  enableval=$enable_pv_grub;
-
-if test "x$enableval" = "xyes"; then :
-
-
-grub=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS grub"
-STUBDOM_BUILD="$STUBDOM_BUILD pv-grub"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-grub"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-grub=n
-
-
-fi
-
-fi
-
-
-else
-
-
-grub=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS grub"
-STUBDOM_BUILD="$STUBDOM_BUILD pv-grub"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-grub"
-
-
-fi
-
-
-
-
-# Check whether --enable-xenstore-stubdom was given.
-if test "${enable_xenstore_stubdom+set}" = set; then :
-  enableval=$enable_xenstore_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-xenstore=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS xenstore"
-STUBDOM_BUILD="$STUBDOM_BUILD xenstore-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-xenstore"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-xenstore=n
-
-
-fi
-
-fi
-
-
-else
-
-
-xenstore=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS xenstore"
-STUBDOM_BUILD="$STUBDOM_BUILD xenstore-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-xenstore"
-
-
-fi
-
-
-
-
-# Check whether --enable-vtpm-stubdom was given.
-if test "${enable_vtpm_stubdom+set}" = set; then :
-  enableval=$enable_vtpm_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-vtpm=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS vtpm"
-STUBDOM_BUILD="$STUBDOM_BUILD vtpm-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-vtpm"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-vtpm=n
-
-
-fi
-
-fi
-
-
-fi
-
-
-
-# Check whether --enable-vtpmmgr-stubdom was given.
-if test "${enable_vtpmmgr_stubdom+set}" = set; then :
-  enableval=$enable_vtpmmgr_stubdom;
-
-if test "x$enableval" = "xyes"; then :
-
-
-vtpmmgr=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS vtpmmgr"
-STUBDOM_BUILD="$STUBDOM_BUILD vtpmmgr-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-vtpmmgr"
-
-
-else
-
-if test "x$enableval" = "xno"; then :
-
-
-vtpmmgr=n
-
-
-fi
-
-fi
-
-
-fi
-
-
-
-# Check whether --enable-qemu-traditional was given.
-if test "${enable_qemu_traditional+set}" = set; then :
-  enableval=$enable_qemu_traditional;
-else
-
-    case "$host_cpu" in
-        i[3456]86|x86_64)
-           enable_qemu_traditional="yes";;
-        *) enable_qemu_traditional="no";;
-    esac
-
-fi
-
-if test "x$enable_qemu_traditional" = "xyes"; then :
-
-    qemu_traditional=y
-else
-
-    qemu_traditional=n
-
-fi
-if test "x$ioemu" = "x"; then :
-
-    ioemu=$qemu_traditional
-
-fi
-echo "x$ioemu$qemu_traditional"
-if test "x$ioemu$qemu_traditional" = "xyn"; then :
-
-    as_fn_error $? "IOEMU stubdomain requires qemu-traditional" "$LINENO" 5
-
-fi
-
-
-# Check whether --enable-debug was given.
-if test "${enable_debug+set}" = set; then :
-  enableval=$enable_debug;
-fi
-
-
-if test "x$enable_debug" = "xno"; then :
-
-    ax_cv_debug="n"
-
-elif test "x$enable_debug" = "xyes"; then :
-
-    ax_cv_debug="y"
-
-elif test -z $ax_cv_debug; then :
-
-    ax_cv_debug="y"
-
-fi
-debug=$ax_cv_debug
-
-
-
-# Check whether --enable-extfiles was given.
-if test "${enable_extfiles+set}" = set; then :
-  enableval=$enable_extfiles;
-fi
-
-
-if test "x$enable_extfiles" = "xno"; then :
-
-    ax_cv_extfiles="n"
-
-elif test "x$enable_extfiles" = "xyes"; then :
-
-    ax_cv_extfiles="y"
-
-elif test -z $ax_cv_extfiles; then :
-
-    ax_cv_extfiles="y"
-
-fi
-extfiles=$ax_cv_extfiles
-
-
-
-
-
-# Extract the first word of "wget", so it can be a program name with args.
-set dummy wget; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_WGET+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $WGET in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_WGET="$WGET" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_WGET="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-  test -z "$ac_cv_path_WGET" && ac_cv_path_WGET="no"
-  ;;
-esac
-fi
-WGET=$ac_cv_path_WGET
-if test -n "$WGET"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WGET" >&5
-$as_echo "$WGET" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-if test x"$WGET" != x"no"; then :
-
-    FETCHER="$WGET -c -O"
-
-else
-
-    # Extract the first word of "ftp", so it can be a program name with args.
-set dummy ftp; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_FTP+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $FTP in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_FTP="$FTP" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_FTP="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-  test -z "$ac_cv_path_FTP" && ac_cv_path_FTP="no"
-  ;;
-esac
-fi
-FTP=$ac_cv_path_FTP
-if test -n "$FTP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FTP" >&5
-$as_echo "$FTP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-    if test x"$FTP" != x"no"; then :
-
-        FETCHER="$FTP -o"
-
-else
-
-        as_fn_error $? "cannot find wget or ftp" "$LINENO" 5
-
-fi
-
-fi
-
-
-
-# Checks for programs.
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}gcc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}gcc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$ac_cv_prog_CC"; then
-  ac_ct_CC=$CC
-  # Extract the first word of "gcc", so it can be a program name with args.
-set dummy gcc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_CC="gcc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_CC=$ac_cv_prog_ac_ct_CC
-if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
-$as_echo "$ac_ct_CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-  if test "x$ac_ct_CC" = x; then
-    CC=""
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    CC=$ac_ct_CC
-  fi
-else
-  CC="$ac_cv_prog_CC"
-fi
-
-if test -z "$CC"; then
-          if test -n "$ac_tool_prefix"; then
-    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
-set dummy ${ac_tool_prefix}cc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="${ac_tool_prefix}cc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-  fi
-fi
-if test -z "$CC"; then
-  # Extract the first word of "cc", so it can be a program name with args.
-set dummy cc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-  ac_prog_rejected=no
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
-       ac_prog_rejected=yes
-       continue
-     fi
-    ac_cv_prog_CC="cc"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-if test $ac_prog_rejected = yes; then
-  # We found a bogon in the path, so make sure we never use it.
-  set dummy $ac_cv_prog_CC
-  shift
-  if test $# != 0; then
-    # We chose a different compiler from the bogus one.
-    # However, it has the same basename, so the bogon will be chosen
-    # first if we set CC to just the basename; use the full file name.
-    shift
-    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
-  fi
-fi
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$CC"; then
-  if test -n "$ac_tool_prefix"; then
-  for ac_prog in cl.exe
-  do
-    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
-set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$CC"; then
-  ac_cv_prog_CC="$CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-CC=$ac_cv_prog_CC
-if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
-$as_echo "$CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-    test -n "$CC" && break
-  done
-fi
-if test -z "$CC"; then
-  ac_ct_CC=$CC
-  for ac_prog in cl.exe
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_CC"; then
-  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_CC="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_CC=$ac_cv_prog_ac_ct_CC
-if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
-$as_echo "$ac_ct_CC" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-  test -n "$ac_ct_CC" && break
-done
-
-  if test "x$ac_ct_CC" = x; then
-    CC=""
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    CC=$ac_ct_CC
-  fi
-fi
-
-fi
-
-
-test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5; }
-
-# Provide some information about the compiler.
-$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
-set X $ac_compile
-ac_compiler=$2
-for ac_option in --version -v -V -qversion; do
-  { { ac_try="$ac_compiler $ac_option >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    sed '10a\
-... rest of stderr output deleted ...
-         10q' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-  fi
-  rm -f conftest.er1 conftest.err
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-done
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-ac_clean_files_save=$ac_clean_files
-ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
-# Try to create an executable without -o first, disregard a.out.
-# It will help us diagnose broken compilers, and finding out an intuition
-# of exeext.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
-$as_echo_n "checking whether the C compiler works... " >&6; }
-ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
-
-# The possible output files:
-ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
-
-ac_rmfiles=
-for ac_file in $ac_files
-do
-  case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
-    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
-  esac
-done
-rm -f $ac_rmfiles
-
-if { { ac_try="$ac_link_default"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link_default") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
-  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
-# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
-# in a Makefile.  We should not override ac_cv_exeext if it was cached,
-# so that the user can short-circuit this test for compilers unknown to
-# Autoconf.
-for ac_file in $ac_files ''
-do
-  test -f "$ac_file" || continue
-  case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
-       ;;
-    [ab].out )
-       # We found the default executable, but exeext='' is most
-       # certainly right.
-       break;;
-    *.* )
-       if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
-       then :; else
-          ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-       fi
-       # We set ac_cv_exeext here because the later test for it is not
-       # safe: cross compilers may not add the suffix if given an `-o'
-       # argument, so we may need to know it at that point already.
-       # Even if this section looks crufty: it has the advantage of
-       # actually working.
-       break;;
-    * )
-       break;;
-  esac
-done
-test "$ac_cv_exeext" = no && ac_cv_exeext=
-
-else
-  ac_file=''
-fi
-if test -z "$ac_file"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-$as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "C compiler cannot create executables
-See \`config.log' for more details" "$LINENO" 5; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
-$as_echo_n "checking for C compiler default output file name... " >&6; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
-$as_echo "$ac_file" >&6; }
-ac_exeext=$ac_cv_exeext
-
-rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
-ac_clean_files=$ac_clean_files_save
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
-$as_echo_n "checking for suffix of executables... " >&6; }
-if { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
-  # If both `conftest.exe' and `conftest' are `present' (well, observable)
-# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
-# work properly (i.e., refer to `conftest.exe'), while it won't with
-# `rm'.
-for ac_file in conftest.exe conftest conftest.*; do
-  test -f "$ac_file" || continue
-  case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
-    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-         break;;
-    * ) break;;
-  esac
-done
-else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details" "$LINENO" 5; }
-fi
-rm -f conftest conftest$ac_cv_exeext
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
-$as_echo "$ac_cv_exeext" >&6; }
-
-rm -f conftest.$ac_ext
-EXEEXT=$ac_cv_exeext
-ac_exeext=$EXEEXT
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <stdio.h>
-int
-main ()
-{
-FILE *f = fopen ("conftest.out", "w");
- return ferror (f) || fclose (f) != 0;
-
-  ;
-  return 0;
-}
-_ACEOF
-ac_clean_files="$ac_clean_files conftest.out"
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
-$as_echo_n "checking whether we are cross compiling... " >&6; }
-if test "$cross_compiling" != yes; then
-  { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-  if { ac_try='./conftest$ac_cv_exeext'
-  { { case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-    cross_compiling=no
-  else
-    if test "$cross_compiling" = maybe; then
-       cross_compiling=yes
-    else
-       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run C compiled programs.
-If you meant to cross compile, use \`--host'.
-See \`config.log' for more details" "$LINENO" 5; }
-    fi
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
-$as_echo "$cross_compiling" >&6; }
-
-rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
-ac_clean_files=$ac_clean_files_save
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
-$as_echo_n "checking for suffix of object files... " >&6; }
-if ${ac_cv_objext+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.o conftest.obj
-if { { ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compile") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
-  for ac_file in conftest.o conftest.obj conftest.*; do
-  test -f "$ac_file" || continue;
-  case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
-    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
-       break;;
-  esac
-done
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of object files: cannot compile
-See \`config.log' for more details" "$LINENO" 5; }
-fi
-rm -f conftest.$ac_cv_objext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
-$as_echo "$ac_cv_objext" >&6; }
-OBJEXT=$ac_cv_objext
-ac_objext=$OBJEXT
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
-$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
-if ${ac_cv_c_compiler_gnu+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-#ifndef __GNUC__
-       choke me
-#endif
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_compiler_gnu=yes
-else
-  ac_compiler_gnu=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_cv_c_compiler_gnu=$ac_compiler_gnu
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
-$as_echo "$ac_cv_c_compiler_gnu" >&6; }
-if test $ac_compiler_gnu = yes; then
-  GCC=yes
-else
-  GCC=
-fi
-ac_test_CFLAGS=${CFLAGS+set}
-ac_save_CFLAGS=$CFLAGS
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
-$as_echo_n "checking whether $CC accepts -g... " >&6; }
-if ${ac_cv_prog_cc_g+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_save_c_werror_flag=$ac_c_werror_flag
-   ac_c_werror_flag=yes
-   ac_cv_prog_cc_g=no
-   CFLAGS="-g"
-   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv_prog_cc_g=yes
-else
-  CFLAGS=""
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-else
-  ac_c_werror_flag=$ac_save_c_werror_flag
-        CFLAGS="-g"
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv_prog_cc_g=yes
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-   ac_c_werror_flag=$ac_save_c_werror_flag
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
-$as_echo "$ac_cv_prog_cc_g" >&6; }
-if test "$ac_test_CFLAGS" = set; then
-  CFLAGS=$ac_save_CFLAGS
-elif test $ac_cv_prog_cc_g = yes; then
-  if test "$GCC" = yes; then
-    CFLAGS="-g -O2"
-  else
-    CFLAGS="-g"
-  fi
-else
-  if test "$GCC" = yes; then
-    CFLAGS="-O2"
-  else
-    CFLAGS=
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
-$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
-if ${ac_cv_prog_cc_c89+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_cv_prog_cc_c89=no
-ac_save_CC=$CC
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <stdarg.h>
-#include <stdio.h>
-struct stat;
-/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
-struct buf { int x; };
-FILE * (*rcsopen) (struct buf *, struct stat *, int);
-static char *e (p, i)
-     char **p;
-     int i;
-{
-  return p[i];
-}
-static char *f (char * (*g) (char **, int), char **p, ...)
-{
-  char *s;
-  va_list v;
-  va_start (v,p);
-  s = g (p, va_arg (v,int));
-  va_end (v);
-  return s;
-}
-
-/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
-   function prototypes and stuff, but not '\xHH' hex character constants.
-   These don't provoke an error unfortunately, instead are silently treated
-   as 'x'.  The following induces an error, until -std is added to get
-   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
-   array size at least.  It's necessary to write '\x00'==0 to get something
-   that's true only with -std.  */
-int osf4_cc_array ['\x00' == 0 ? 1 : -1];
-
-/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
-   inside strings and character constants.  */
-#define FOO(x) 'x'
-int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
-
-int test (int i, double x);
-struct s1 {int (*f) (int a);};
-struct s2 {int (*f) (double a);};
-int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
-int argc;
-char **argv;
-int
-main ()
-{
-return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
-  ;
-  return 0;
-}
-_ACEOF
-for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
-       -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
-do
-  CC="$ac_save_CC $ac_arg"
-  if ac_fn_c_try_compile "$LINENO"; then :
-  ac_cv_prog_cc_c89=$ac_arg
-fi
-rm -f core conftest.err conftest.$ac_objext
-  test "x$ac_cv_prog_cc_c89" != "xno" && break
-done
-rm -f conftest.$ac_ext
-CC=$ac_save_CC
-
-fi
-# AC_CACHE_VAL
-case "x$ac_cv_prog_cc_c89" in
-  x)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
-$as_echo "none needed" >&6; } ;;
-  xno)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
-$as_echo "unsupported" >&6; } ;;
-  *)
-    CC="$CC $ac_cv_prog_cc_c89"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
-$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
-esac
-if test "x$ac_cv_prog_cc_c89" != xno; then :
-
-fi
-
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
-$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
-set x ${MAKE-make}
-ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
-if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat >conftest.make <<\_ACEOF
-SHELL = /bin/sh
-all:
-       @echo '@@@%%%=$(MAKE)=@@@%%%'
-_ACEOF
-# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
-case `${MAKE-make} -f conftest.make 2>/dev/null` in
-  *@@@%%%=?*=@@@%%%*)
-    eval ac_cv_prog_make_${ac_make}_set=yes;;
-  *)
-    eval ac_cv_prog_make_${ac_make}_set=no;;
-esac
-rm -f conftest.make
-fi
-if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-  SET_MAKE=
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-  SET_MAKE="MAKE=${MAKE-make}"
-fi
-
-# Find a good install program.  We prefer a C program (faster),
-# so one script is as good as another.  But avoid the broken or
-# incompatible versions:
-# SysV /etc/install, /usr/sbin/install
-# SunOS /usr/etc/install
-# IRIX /sbin/install
-# AIX /bin/install
-# AmigaOS /C/install, which installs bootblocks on floppy discs
-# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
-# AFS /usr/afsws/bin/install, which mishandles nonexistent args
-# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
-# OS/2's system install, which has a completely different semantic
-# ./install, which can be erroneously created by make from ./install.sh.
-# Reject install programs that cannot install multiple files.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
-$as_echo_n "checking for a BSD-compatible install... " >&6; }
-if test -z "$INSTALL"; then
-if ${ac_cv_path_install+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    # Account for people who put trailing slashes in PATH elements.
-case $as_dir/ in #((
-  ./ | .// | /[cC]/* | \
-  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
-  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
-  /usr/ucb/* ) ;;
-  *)
-    # OSF1 and SCO ODT 3.0 have their own names for install.
-    # Don't use installbsd from OSF since it installs stuff as root
-    # by default.
-    for ac_prog in ginstall scoinst install; do
-      for ac_exec_ext in '' $ac_executable_extensions; do
-       if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
-         if test $ac_prog = install &&
-           grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
-           # AIX install.  It has an incompatible calling convention.
-           :
-         elif test $ac_prog = install &&
-           grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
-           # program-specific install script used by HP pwplus--don't use.
-           :
-         else
-           rm -rf conftest.one conftest.two conftest.dir
-           echo one > conftest.one
-           echo two > conftest.two
-           mkdir conftest.dir
-           if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
-             test -s conftest.one && test -s conftest.two &&
-             test -s conftest.dir/conftest.one &&
-             test -s conftest.dir/conftest.two
-           then
-             ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
-             break 3
-           fi
-         fi
-       fi
-      done
-    done
-    ;;
-esac
-
-  done
-IFS=$as_save_IFS
-
-rm -rf conftest.one conftest.two conftest.dir
-
-fi
-  if test "${ac_cv_path_install+set}" = set; then
-    INSTALL=$ac_cv_path_install
-  else
-    # As a last resort, use the slow shell script.  Don't cache a
-    # value for INSTALL within a source directory, because that will
-    # break other packages using the cache if that directory is
-    # removed, or if the value is a relative name.
-    INSTALL=$ac_install_sh
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
-$as_echo "$INSTALL" >&6; }
-
-# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
-# It thinks the first close brace ends the variable substitution.
-test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
-
-test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
-
-test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
-
-
-# Checks for programs that depend on a feature
-
-if test "x$vtpm" = "xy"; then :
-  # Extract the first word of "cmake", so it can be a program name with args.
-set dummy cmake; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_CMAKE+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $CMAKE in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_CMAKE="$CMAKE" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_CMAKE="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-  test -z "$ac_cv_path_CMAKE" && ac_cv_path_CMAKE="no"
-  ;;
-esac
-fi
-CMAKE=$ac_cv_path_CMAKE
-if test -n "$CMAKE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CMAKE" >&5
-$as_echo "$CMAKE" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-if test x"${CMAKE}" = x"no"
-then
-    as_fn_error $? "Unable to find cmake, please install cmake" "$LINENO" 5
-fi
-else
-
-if test "x$vtpm" = "xn"; then :
-
-CMAKE="/cmake-disabled-in-configure-script"
-
-else
-
-# Extract the first word of "cmake", so it can be a program name with args.
-set dummy cmake; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_CMAKE+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  case $CMAKE in
-  [\\/]* | ?:[\\/]*)
-  ac_cv_path_CMAKE="$CMAKE" # Let the user override the test with a path.
-  ;;
-  *)
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_path_CMAKE="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-  test -z "$ac_cv_path_CMAKE" && ac_cv_path_CMAKE="no"
-  ;;
-esac
-fi
-CMAKE=$ac_cv_path_CMAKE
-if test -n "$CMAKE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CMAKE" >&5
-$as_echo "$CMAKE" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-if test x"${CMAKE}" = "xno"; then :
-
-vtpm=n
-CMAKE="/cmake-disabled-in-configure-script"
-
-fi
-
-fi
-
-fi
-
-
-
-# Stubdom libraries version and url setup
-
-
-if test "x$ZLIB_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  ZLIB_URL=\$\(XEN_EXTFILES_URL\)
-else
-  ZLIB_URL="http://www.zlib.net"
-fi
-
-fi
-ZLIB_VERSION="1.2.3"
-
-
-
-
-
-if test "x$LIBPCI_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  LIBPCI_URL=\$\(XEN_EXTFILES_URL\)
-else
-  LIBPCI_URL="http://www.kernel.org/pub/software/utils/pciutils"
-fi
-
-fi
-LIBPCI_VERSION="2.2.9"
-
-
-
-
-
-if test "x$NEWLIB_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  NEWLIB_URL=\$\(XEN_EXTFILES_URL\)
-else
-  NEWLIB_URL="ftp://sources.redhat.com/pub/newlib"
-fi
-
-fi
-NEWLIB_VERSION="1.16.0"
-
-
-
-
-
-if test "x$LWIP_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  LWIP_URL=\$\(XEN_EXTFILES_URL\)
-else
-  LWIP_URL="http://download.savannah.gnu.org/releases/lwip"
-fi
-
-fi
-LWIP_VERSION="1.3.0"
-
-
-
-
-
-if test "x$GRUB_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  GRUB_URL=\$\(XEN_EXTFILES_URL\)
-else
-  GRUB_URL="http://alpha.gnu.org/gnu/grub"
-fi
-
-fi
-GRUB_VERSION="0.97"
-
-
-
-
-
-if test "x$OCAML_URL" = "x"; then :
-
-       OCAML_URL="http://caml.inria.fr/pub/distrib/ocaml-3.11"
-
-fi
-OCAML_VERSION="3.11.0"
-
-
-
-
-
-if test "x$GMP_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  GMP_URL=\$\(XEN_EXTFILES_URL\)
-else
-  GMP_URL="ftp://ftp.gmplib.org/pub/gmp-4.3.2"
-fi
-
-fi
-GMP_VERSION="4.3.2"
-
-
-
-
-
-if test "x$POLARSSL_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  POLARSSL_URL=\$\(XEN_EXTFILES_URL\)
-else
-  POLARSSL_URL="http://polarssl.org/code/releases"
-fi
-
-fi
-POLARSSL_VERSION="1.1.4"
-
-
-
-
-
-if test "x$TPMEMU_URL" = "x"; then :
-
-       if test "x$extfiles" = "xy"; then :
-  TPMEMU_URL=\$\(XEN_EXTFILES_URL\)
-else
-  TPMEMU_URL="http://download.berlios.de/tpm-emulator"
-fi
-
-fi
-TPMEMU_VERSION="0.7.4"
-
-
-
-
-#These stubdoms should be enabled if the dependent one is
-
-if test "x$vtpmmgr" = "x" && test "x$vtpm" = "xn"; then :
-
-vtpmmgr="n"
-
-fi
-
-
-#Conditionally enable these stubdoms based on the presense of dependencies
-
-if test "x$vtpm" = "xy" || test "x$vtpm" = "x"; then :
-
-
-vtpm=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS vtpm"
-STUBDOM_BUILD="$STUBDOM_BUILD vtpm-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-vtpm"
-
-
-else
-
-
-vtpm=n
-
-
-fi
-
-
-
-if test "x$vtpmmgr" = "xy" || test "x$vtpmmgr" = "x"; then :
-
-
-vtpmmgr=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS vtpmmgr"
-STUBDOM_BUILD="$STUBDOM_BUILD vtpmmgr-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-vtpmmgr"
-
-
-else
-
-
-vtpmmgr=n
-
-
-fi
-
-
-
-if test "x$ioemu" = "xy" || test "x$ioemu" = "x"; then :
-
-
-ioemu=y
-STUBDOM_TARGETS="$STUBDOM_TARGETS ioemu"
-STUBDOM_BUILD="$STUBDOM_BUILD ioemu-stubdom"
-STUBDOM_INSTALL="$STUBDOM_INSTALL install-ioemu"
-
-
-else
-
-
-ioemu=n
-
-
-fi
-
-
-
-
-
-
-
-echo "Will build the following stub domains:"
-for x in $STUBDOM_BUILD; do
-       echo "  $x"
-done
-
-cat >confcache <<\_ACEOF
-# This file is a shell script that caches the results of configure
-# tests run on this system so they can be shared between configure
-# scripts and configure runs, see configure's option --config-cache.
-# It is not useful on other systems.  If it contains results you don't
-# want to keep, you may remove or edit it.
-#
-# config.status only pays attention to the cache file if you give it
-# the --recheck option to rerun configure.
-#
-# `ac_cv_env_foo' variables (set or unset) will be overridden when
-# loading this file, other *unset* `ac_cv_foo' will be assigned the
-# following values.
-
-_ACEOF
-
-# The following way of writing the cache mishandles newlines in values,
-# but we know of no workaround that is simple, portable, and efficient.
-# So, we kill variables containing newlines.
-# Ultrix sh set writes to stderr and can't be redirected directly,
-# and sets the high bit in the cache file unless we assign to the vars.
-(
-  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
-    eval ac_val=\$$ac_var
-    case $ac_val in #(
-    *${as_nl}*)
-      case $ac_var in #(
-      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
-$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
-      esac
-      case $ac_var in #(
-      _ | IFS | as_nl) ;; #(
-      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
-      *) { eval $ac_var=; unset $ac_var;} ;;
-      esac ;;
-    esac
-  done
-
-  (set) 2>&1 |
-    case $as_nl`(ac_space=' '; set) 2>&1` in #(
-    *${as_nl}ac_space=\ *)
-      # `set' does not quote correctly, so add quotes: double-quote
-      # substitution turns \\\\ into \\, and sed turns \\ into \.
-      sed -n \
-       "s/'/'\\\\''/g;
-         s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
-      ;; #(
-    *)
-      # `set' quotes correctly as required by POSIX, so do not add quotes.
-      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
-      ;;
-    esac |
-    sort
-) |
-  sed '
-     /^ac_cv_env_/b end
-     t clear
-     :clear
-     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
-     t end
-     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
-     :end' >>confcache
-if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
-  if test -w "$cache_file"; then
-    if test "x$cache_file" != "x/dev/null"; then
-      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
-$as_echo "$as_me: updating cache $cache_file" >&6;}
-      if test ! -f "$cache_file" || test -h "$cache_file"; then
-       cat confcache >"$cache_file"
-      else
-        case $cache_file in #(
-        */* | ?:*)
-         mv -f confcache "$cache_file"$$ &&
-         mv -f "$cache_file"$$ "$cache_file" ;; #(
-        *)
-         mv -f confcache "$cache_file" ;;
-       esac
-      fi
-    fi
-  else
-    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
-$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
-  fi
-fi
-rm -f confcache
-
-test "x$prefix" = xNONE && prefix=$ac_default_prefix
-# Let make expand exec_prefix.
-test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-
-# Transform confdefs.h into DEFS.
-# Protect against shell expansion while executing Makefile rules.
-# Protect against Makefile macro expansion.
-#
-# If the first sed substitution is executed (which looks for macros that
-# take arguments), then branch to the quote section.  Otherwise,
-# look for a macro that doesn't take arguments.
-ac_script='
-:mline
-/\\$/{
- N
- s,\\\n,,
- b mline
-}
-t clear
-:clear
-s/^[    ]*#[    ]*define[       ][      ]*\([^  (][^    (]*([^)]*)\)[   ]*\(.*\)/-D\1=\2/g
-t quote
-s/^[    ]*#[    ]*define[       ][      ]*\([^  ][^     ]*\)[   ]*\(.*\)/-D\1=\2/g
-t quote
-b any
-:quote
-s/[     `~#$^&*(){}\\|;'\''"<>?]/\\&/g
-s/\[/\\&/g
-s/\]/\\&/g
-s/\$/$$/g
-H
-:any
-${
-       g
-       s/^\n//
-       s/\n/ /g
-       p
-}
-'
-DEFS=`sed -n "$ac_script" confdefs.h`
-
-
-ac_libobjs=
-ac_ltlibobjs=
-U=
-for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
-  # 1. Remove the extension, and $U if already installed.
-  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
-  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
-  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
-  #    will be set to the directory where LIBOBJS objects are built.
-  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
-  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
-done
-LIBOBJS=$ac_libobjs
-
-LTLIBOBJS=$ac_ltlibobjs
-
-
-
-: "${CONFIG_STATUS=./config.status}"
-ac_write_fail=0
-ac_clean_files_save=$ac_clean_files
-ac_clean_files="$ac_clean_files $CONFIG_STATUS"
-{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
-$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
-as_write_fail=0
-cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
-#! $SHELL
-# Generated by $as_me.
-# Run this file to recreate the current configuration.
-# Compiler output produced by configure, useful for debugging
-# configure, is in config.log if it exists.
-
-debug=false
-ac_cs_recheck=false
-ac_cs_silent=false
-
-SHELL=\${CONFIG_SHELL-$SHELL}
-export SHELL
-_ASEOF
-cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
-## -------------------- ##
-## M4sh Initialization. ##
-## -------------------- ##
-
-# Be more Bourne compatible
-DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
-  emulate sh
-  NULLCMD=:
-  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '${1+"$@"}'='"$@"'
-  setopt NO_GLOB_SUBST
-else
-  case `(set -o) 2>/dev/null` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
-esac
-fi
-
-
-as_nl='
-'
-export as_nl
-# Printing a long string crashes Solaris 7 /usr/bin/printf.
-as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
-as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
-# Prefer a ksh shell builtin over an external printf program on Solaris,
-# but without wasting forks for bash or zsh.
-if test -z "$BASH_VERSION$ZSH_VERSION" \
-    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='print -r --'
-  as_echo_n='print -rn --'
-elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
-  as_echo='printf %s\n'
-  as_echo_n='printf %s'
-else
-  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
-    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
-    as_echo_n='/usr/ucb/echo -n'
-  else
-    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
-    as_echo_n_body='eval
-      arg=$1;
-      case $arg in #(
-      *"$as_nl"*)
-       expr "X$arg" : "X\\(.*\\)$as_nl";
-       arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
-      esac;
-      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
-    '
-    export as_echo_n_body
-    as_echo_n='sh -c $as_echo_n_body as_echo'
-  fi
-  export as_echo_body
-  as_echo='sh -c $as_echo_body as_echo'
-fi
-
-# The user is always right.
-if test "${PATH_SEPARATOR+set}" != set; then
-  PATH_SEPARATOR=:
-  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
-    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
-      PATH_SEPARATOR=';'
-  }
-fi
-
-
-# IFS
-# We need space, tab and new line, in precisely that order.  Quoting is
-# there to prevent editors from complaining about space-tab.
-# (If _AS_PATH_WALK were called with IFS unset, it would disable word
-# splitting by setting IFS to empty value.)
-IFS=" ""       $as_nl"
-
-# Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
-case $0 in #((
-  *[\\/]* ) as_myself=$0 ;;
-  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-  done
-IFS=$as_save_IFS
-
-     ;;
-esac
-# We did not find ourselves, most probably we were run as `sh COMMAND'
-# in which case we are not to be found in the path.
-if test "x$as_myself" = x; then
-  as_myself=$0
-fi
-if test ! -f "$as_myself"; then
-  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  exit 1
-fi
-
-# Unset variables that we do not need and which cause bugs (e.g. in
-# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
-# suppresses any "Segmentation fault" message there.  '((' could
-# trigger a bug in pdksh 5.2.14.
-for as_var in BASH_ENV ENV MAIL MAILPATH
-do eval test x\${$as_var+set} = xset \
-  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
-done
-PS1='$ '
-PS2='> '
-PS4='+ '
-
-# NLS nuisances.
-LC_ALL=C
-export LC_ALL
-LANGUAGE=C
-export LANGUAGE
-
-# CDPATH.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
-# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
-# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
-as_fn_error ()
-{
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
-  as_fn_exit $as_status
-} # as_fn_error
-
-
-# as_fn_set_status STATUS
-# -----------------------
-# Set $? to STATUS, without forking.
-as_fn_set_status ()
-{
-  return $1
-} # as_fn_set_status
-
-# as_fn_exit STATUS
-# -----------------
-# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
-as_fn_exit ()
-{
-  set +e
-  as_fn_set_status $1
-  exit $1
-} # as_fn_exit
-
-# as_fn_unset VAR
-# ---------------
-# Portably unset VAR.
-as_fn_unset ()
-{
-  { eval $1=; unset $1;}
-}
-as_unset=as_fn_unset
-# as_fn_append VAR VALUE
-# ----------------------
-# Append the text in VALUE to the end of the definition contained in VAR. Take
-# advantage of any shell optimizations that allow amortized linear growth over
-# repeated appends, instead of the typical quadratic growth present in naive
-# implementations.
-if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
-  eval 'as_fn_append ()
-  {
-    eval $1+=\$2
-  }'
-else
-  as_fn_append ()
-  {
-    eval $1=\$$1\$2
-  }
-fi # as_fn_append
-
-# as_fn_arith ARG...
-# ------------------
-# Perform arithmetic evaluation on the ARGs, and store the result in the
-# global $as_val. Take advantage of shells that can avoid forks. The arguments
-# must be portable across $(()) and expr.
-if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
-  eval 'as_fn_arith ()
-  {
-    as_val=$(( $* ))
-  }'
-else
-  as_fn_arith ()
-  {
-    as_val=`expr "$@" || test $? -eq 1`
-  }
-fi # as_fn_arith
-
-
-if expr a : '\(a\)' >/dev/null 2>&1 &&
-   test "X`expr 00001 : '.*\(...\)'`" = X001; then
-  as_expr=expr
-else
-  as_expr=false
-fi
-
-if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
-  as_basename=basename
-else
-  as_basename=false
-fi
-
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
-else
-  as_dirname=false
-fi
-
-as_me=`$as_basename -- "$0" ||
-$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
-        X"$0" : 'X\(//\)$' \| \
-        X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X/"$0" |
-    sed '/^.*\/\([^/][^/]*\)\/*$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\/\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
-
-ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in #(((((
--n*)
-  case `echo 'xy\c'` in
-  *c*) ECHO_T='        ';;     # ECHO_T is single tab character.
-  xy)  ECHO_C='\c';;
-  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
-       ECHO_T='        ';;
-  esac;;
-*)
-  ECHO_N='-n';;
-esac
-
-rm -f conf$$ conf$$.exe conf$$.file
-if test -d conf$$.dir; then
-  rm -f conf$$.dir/conf$$.file
-else
-  rm -f conf$$.dir
-  mkdir conf$$.dir 2>/dev/null
-fi
-if (echo >conf$$.file) 2>/dev/null; then
-  if ln -s conf$$.file conf$$ 2>/dev/null; then
-    as_ln_s='ln -s'
-    # ... but there are two gotchas:
-    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
-    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
-    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
-  elif ln conf$$.file conf$$ 2>/dev/null; then
-    as_ln_s=ln
-  else
-    as_ln_s='cp -pR'
-  fi
-else
-  as_ln_s='cp -pR'
-fi
-rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
-rmdir conf$$.dir 2>/dev/null
-
-
-# as_fn_mkdir_p
-# -------------
-# Create "$as_dir" as a directory, including parents if necessary.
-as_fn_mkdir_p ()
-{
-
-  case $as_dir in #(
-  -*) as_dir=./$as_dir;;
-  esac
-  test -d "$as_dir" || eval $as_mkdir_p || {
-    as_dirs=
-    while :; do
-      case $as_dir in #(
-      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
-      *) as_qdir=$as_dir;;
-      esac
-      as_dirs="'$as_qdir' $as_dirs"
-      as_dir=`$as_dirname -- "$as_dir" ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-        X"$as_dir" : 'X\(//\)[^/]' \| \
-        X"$as_dir" : 'X\(//\)$' \| \
-        X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)[^/].*/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-      test -d "$as_dir" && break
-    done
-    test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
-
-
-} # as_fn_mkdir_p
-if mkdir -p . 2>/dev/null; then
-  as_mkdir_p='mkdir -p "$as_dir"'
-else
-  test -d ./-p && rmdir ./-p
-  as_mkdir_p=false
-fi
-
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
-
-# Sed expression to map a string onto a valid CPP name.
-as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
-
-# Sed expression to map a string onto a valid variable name.
-as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
-
-
-exec 6>&1
-## ----------------------------------- ##
-## Main body of $CONFIG_STATUS script. ##
-## ----------------------------------- ##
-_ASEOF
-test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-# Save the log message, to keep $0 and so on meaningful, and to
-# report actual input values of CONFIG_FILES etc. instead of their
-# values after options handling.
-ac_log="
-This file was extended by Xen Hypervisor Stub Domains $as_me 4.7, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
-
-  CONFIG_FILES    = $CONFIG_FILES
-  CONFIG_HEADERS  = $CONFIG_HEADERS
-  CONFIG_LINKS    = $CONFIG_LINKS
-  CONFIG_COMMANDS = $CONFIG_COMMANDS
-  $ $0 $@
-
-on `(hostname || uname -n) 2>/dev/null | sed 1q`
-"
-
-_ACEOF
-
-case $ac_config_files in *"
-"*) set x $ac_config_files; shift; ac_config_files=$*;;
-esac
-
-
-
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-# Files that config.status was made for.
-config_files="$ac_config_files"
-
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-ac_cs_usage="\
-\`$as_me' instantiates files and other configuration actions
-from templates according to the current configuration.  Unless the files
-and actions are specified as TAGs, all are instantiated by default.
-
-Usage: $0 [OPTION]... [TAG]...
-
-  -h, --help       print this help, then exit
-  -V, --version    print version number and configuration settings, then exit
-      --config     print configuration, then exit
-  -q, --quiet, --silent
-                   do not print progress messages
-  -d, --debug      don't remove temporary files
-      --recheck    update $as_me by reconfiguring in the same conditions
-      --file=FILE[:TEMPLATE]
-                   instantiate the configuration file FILE
-
-Configuration files:
-$config_files
-
-Report bugs to <xen-devel@lists.xen.org>.
-Xen Hypervisor Stub Domains home page: <http://www.xen.org/>."
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
-ac_cs_version="\\
-Xen Hypervisor Stub Domains config.status 4.7
-configured by $0, generated by GNU Autoconf 2.69,
-  with options \\"\$ac_cs_config\\"
-
-Copyright (C) 2012 Free Software Foundation, Inc.
-This config.status script is free software; the Free Software Foundation
-gives unlimited permission to copy, distribute and modify it."
-
-ac_pwd='$ac_pwd'
-srcdir='$srcdir'
-INSTALL='$INSTALL'
-test -n "\$AWK" || AWK=awk
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-# The default lists apply if the user does not specify any file.
-ac_need_defaults=:
-while test $# != 0
-do
-  case $1 in
-  --*=?*)
-    ac_option=`expr "X$1" : 'X\([^=]*\)='`
-    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
-    ac_shift=:
-    ;;
-  --*=)
-    ac_option=`expr "X$1" : 'X\([^=]*\)='`
-    ac_optarg=
-    ac_shift=:
-    ;;
-  *)
-    ac_option=$1
-    ac_optarg=$2
-    ac_shift=shift
-    ;;
-  esac
-
-  case $ac_option in
-  # Handling of the options.
-  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
-    ac_cs_recheck=: ;;
-  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
-    $as_echo "$ac_cs_version"; exit ;;
-  --config | --confi | --conf | --con | --co | --c )
-    $as_echo "$ac_cs_config"; exit ;;
-  --debug | --debu | --deb | --de | --d | -d )
-    debug=: ;;
-  --file | --fil | --fi | --f )
-    $ac_shift
-    case $ac_optarg in
-    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
-    '') as_fn_error $? "missing file argument" ;;
-    esac
-    as_fn_append CONFIG_FILES " '$ac_optarg'"
-    ac_need_defaults=false;;
-  --he | --h |  --help | --hel | -h )
-    $as_echo "$ac_cs_usage"; exit ;;
-  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
-  | -silent | --silent | --silen | --sile | --sil | --si | --s)
-    ac_cs_silent=: ;;
-
-  # This is an error.
-  -*) as_fn_error $? "unrecognized option: \`$1'
-Try \`$0 --help' for more information." ;;
-
-  *) as_fn_append ac_config_targets " $1"
-     ac_need_defaults=false ;;
-
-  esac
-  shift
-done
-
-ac_configure_extra_args=
-
-if $ac_cs_silent; then
-  exec 6>/dev/null
-  ac_configure_extra_args="$ac_configure_extra_args --silent"
-fi
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-if \$ac_cs_recheck; then
-  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
-  shift
-  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
-  CONFIG_SHELL='$SHELL'
-  export CONFIG_SHELL
-  exec "\$@"
-fi
-
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-exec 5>>config.log
-{
-  echo
-  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
-## Running $as_me. ##
-_ASBOX
-  $as_echo "$ac_log"
-} >&5
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-
-# Handling of arguments.
-for ac_config_target in $ac_config_targets
-do
-  case $ac_config_target in
-    "../config/Stubdom.mk") CONFIG_FILES="$CONFIG_FILES ../config/Stubdom.mk" ;;
-
-  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
-  esac
-done
-
-
-# If the user did not use the arguments to specify the items to instantiate,
-# then the envvar interface is used.  Set only those that are not.
-# We use the long form for the default assignment because of an extremely
-# bizarre bug on SunOS 4.1.3.
-if $ac_need_defaults; then
-  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
-fi
-
-# Have a temporary directory for convenience.  Make it in the build tree
-# simply because there is no reason against having it here, and in addition,
-# creating and moving files from /tmp can sometimes cause problems.
-# Hook for its removal unless debugging.
-# Note that there is a small window in which the directory will not be cleaned:
-# after its creation but before its name has been assigned to `$tmp'.
-$debug ||
-{
-  tmp= ac_tmp=
-  trap 'exit_status=$?
-  : "${ac_tmp:=$tmp}"
-  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
-' 0
-  trap 'as_fn_exit 1' 1 2 13 15
-}
-# Create a (secure) tmp directory for tmp files.
-
-{
-  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
-  test -d "$tmp"
-}  ||
-{
-  tmp=./conf$$-$RANDOM
-  (umask 077 && mkdir "$tmp")
-} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
-ac_tmp=$tmp
-
-# Set up the scripts for CONFIG_FILES section.
-# No need to generate them if there are no CONFIG_FILES.
-# This happens for instance with `./config.status config.h'.
-if test -n "$CONFIG_FILES"; then
-
-
-ac_cr=`echo X | tr X '\015'`
-# On cygwin, bash can eat \r inside `` if the user requested igncr.
-# But we know of no other shell where ac_cr would be empty at this
-# point, so we can use a bashism as a fallback.
-if test "x$ac_cr" = x; then
-  eval ac_cr=\$\'\\r\'
-fi
-ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
-if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
-  ac_cs_awk_cr='\\r'
-else
-  ac_cs_awk_cr=$ac_cr
-fi
-
-echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
-_ACEOF
-
-
-{
-  echo "cat >conf$$subs.awk <<_ACEOF" &&
-  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
-  echo "_ACEOF"
-} >conf$$subs.sh ||
-  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
-ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
-ac_delim='%!_!# '
-for ac_last_try in false false false false false :; do
-  . ./conf$$subs.sh ||
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
-
-  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
-  if test $ac_delim_n = $ac_delim_num; then
-    break
-  elif $ac_last_try; then
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
-  else
-    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
-  fi
-done
-rm -f conf$$subs.sh
-
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
-_ACEOF
-sed -n '
-h
-s/^/S["/; s/!.*/"]=/
-p
-g
-s/^[^!]*!//
-:repl
-t repl
-s/'"$ac_delim"'$//
-t delim
-:nl
-h
-s/\(.\{148\}\)..*/\1/
-t more1
-s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
-p
-n
-b repl
-:more1
-s/["\\]/\\&/g; s/^/"/; s/$/"\\/
-p
-g
-s/.\{148\}//
-t nl
-:delim
-h
-s/\(.\{148\}\)..*/\1/
-t more2
-s/["\\]/\\&/g; s/^/"/; s/$/"/
-p
-b
-:more2
-s/["\\]/\\&/g; s/^/"/; s/$/"\\/
-p
-g
-s/.\{148\}//
-t delim
-' <conf$$subs.awk | sed '
-/^[^""]/{
-  N
-  s/\n//
-}
-' >>$CONFIG_STATUS || ac_write_fail=1
-rm -f conf$$subs.awk
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-_ACAWK
-cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
-  for (key in S) S_is_set[key] = 1
-  FS = "\a"
-
-}
-{
-  line = $ 0
-  nfields = split(line, field, "@")
-  substed = 0
-  len = length(field[1])
-  for (i = 2; i < nfields; i++) {
-    key = field[i]
-    keylen = length(key)
-    if (S_is_set[key]) {
-      value = S[key]
-      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
-      len += length(value) + length(field[++i])
-      substed = 1
-    } else
-      len += 1 + keylen
-  }
-
-  print line
-}
-
-_ACAWK
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
-  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
-else
-  cat
-fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
-  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
-_ACEOF
-
-# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
-# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
-# trailing colons and then remove the whole line if VPATH becomes empty
-# (actually we leave an empty line to preserve line numbers).
-if test "x$srcdir" = x.; then
-  ac_vpsub='/^[         ]*VPATH[        ]*=[    ]*/{
-h
-s///
-s/^/:/
-s/[     ]*$/:/
-s/:\$(srcdir):/:/g
-s/:\${srcdir}:/:/g
-s/:@srcdir@:/:/g
-s/^:*//
-s/:*$//
-x
-s/\(=[  ]*\).*/\1/
-G
-s/\n//
-s/^[^=]*=[      ]*$//
-}'
-fi
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-fi # test -n "$CONFIG_FILES"
-
-
-eval set X "  :F $CONFIG_FILES      "
-shift
-for ac_tag
-do
-  case $ac_tag in
-  :[FHLC]) ac_mode=$ac_tag; continue;;
-  esac
-  case $ac_mode$ac_tag in
-  :[FHL]*:*);;
-  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
-  :[FH]-) ac_tag=-:-;;
-  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
-  esac
-  ac_save_IFS=$IFS
-  IFS=:
-  set x $ac_tag
-  IFS=$ac_save_IFS
-  shift
-  ac_file=$1
-  shift
-
-  case $ac_mode in
-  :L) ac_source=$1;;
-  :[FH])
-    ac_file_inputs=
-    for ac_f
-    do
-      case $ac_f in
-      -) ac_f="$ac_tmp/stdin";;
-      *) # Look for the file first in the build tree, then in the source tree
-        # (if the path is not absolute).  The absolute path cannot be DOS-style,
-        # because $ac_f cannot contain `:'.
-        test -f "$ac_f" ||
-          case $ac_f in
-          [\\/$]*) false;;
-          *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
-          esac ||
-          as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
-      esac
-      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
-      as_fn_append ac_file_inputs " '$ac_f'"
-    done
-
-    # Let's still pretend it is `configure' which instantiates (i.e., don't
-    # use $as_me), people would be surprised to read:
-    #    /* config.h.  Generated by config.status.  */
-    configure_input='Generated from '`
-         $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
-       `' by configure.'
-    if test x"$ac_file" != x-; then
-      configure_input="$ac_file.  $configure_input"
-      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
-$as_echo "$as_me: creating $ac_file" >&6;}
-    fi
-    # Neutralize special characters interpreted by sed in replacement strings.
-    case $configure_input in #(
-    *\&* | *\|* | *\\* )
-       ac_sed_conf_input=`$as_echo "$configure_input" |
-       sed 's/[\\\\&|]/\\\\&/g'`;; #(
-    *) ac_sed_conf_input=$configure_input;;
-    esac
-
-    case $ac_tag in
-    *:-:* | *:-) cat >"$ac_tmp/stdin" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
-    esac
-    ;;
-  esac
-
-  ac_dir=`$as_dirname -- "$ac_file" ||
-$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-        X"$ac_file" : 'X\(//\)[^/]' \| \
-        X"$ac_file" : 'X\(//\)$' \| \
-        X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$ac_file" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)[^/].*/{
-           s//\1/
-           q
-         }
-         /^X\(\/\/\)$/{
-           s//\1/
-           q
-         }
-         /^X\(\/\).*/{
-           s//\1/
-           q
-         }
-         s/.*/./; q'`
-  as_dir="$ac_dir"; as_fn_mkdir_p
-  ac_builddir=.
-
-case "$ac_dir" in
-.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
-*)
-  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
-  # A ".." for each directory in $ac_dir_suffix.
-  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
-  case $ac_top_builddir_sub in
-  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
-  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
-  esac ;;
-esac
-ac_abs_top_builddir=$ac_pwd
-ac_abs_builddir=$ac_pwd$ac_dir_suffix
-# for backward compatibility:
-ac_top_builddir=$ac_top_build_prefix
-
-case $srcdir in
-  .)  # We are building in place.
-    ac_srcdir=.
-    ac_top_srcdir=$ac_top_builddir_sub
-    ac_abs_top_srcdir=$ac_pwd ;;
-  [\\/]* | ?:[\\/]* )  # Absolute name.
-    ac_srcdir=$srcdir$ac_dir_suffix;
-    ac_top_srcdir=$srcdir
-    ac_abs_top_srcdir=$srcdir ;;
-  *) # Relative name.
-    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
-    ac_top_srcdir=$ac_top_build_prefix$srcdir
-    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
-esac
-ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
-
-
-  case $ac_mode in
-  :F)
-  #
-  # CONFIG_FILE
-  #
-
-  case $INSTALL in
-  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
-  *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;;
-  esac
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-# If the template does not know about datarootdir, expand it.
-# FIXME: This hack should be removed a few years after 2.60.
-ac_datarootdir_hack=; ac_datarootdir_seen=
-ac_sed_dataroot='
-/datarootdir/ {
-  p
-  q
-}
-/@datadir@/p
-/@docdir@/p
-/@infodir@/p
-/@localedir@/p
-/@mandir@/p'
-case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
-*datarootdir*) ac_datarootdir_seen=yes;;
-*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
-$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-  ac_datarootdir_hack='
-  s&@datadir@&$datadir&g
-  s&@docdir@&$docdir&g
-  s&@infodir@&$infodir&g
-  s&@localedir@&$localedir&g
-  s&@mandir@&$mandir&g
-  s&\\\${datarootdir}&$datarootdir&g' ;;
-esac
-_ACEOF
-
-# Neutralize VPATH when `$srcdir' = `.'.
-# Shell code in configure.ac might set extrasub.
-# FIXME: do we really want to maintain this feature?
-cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-ac_sed_extra="$ac_vpsub
-$extrasub
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-:t
-/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
-s|@configure_input@|$ac_sed_conf_input|;t t
-s&@top_builddir@&$ac_top_builddir_sub&;t t
-s&@top_build_prefix@&$ac_top_build_prefix&;t t
-s&@srcdir@&$ac_srcdir&;t t
-s&@abs_srcdir@&$ac_abs_srcdir&;t t
-s&@top_srcdir@&$ac_top_srcdir&;t t
-s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
-s&@builddir@&$ac_builddir&;t t
-s&@abs_builddir@&$ac_abs_builddir&;t t
-s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
-s&@INSTALL@&$ac_INSTALL&;t t
-$ac_datarootdir_hack
-"
-eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
-  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
-
-test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
-  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
-  { ac_out=`sed -n '/^[         ]*datarootdir[  ]*:*=/p' \
-      "$ac_tmp/out"`; test -z "$ac_out"; } &&
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&5
-$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&2;}
-
-  rm -f "$ac_tmp/stdin"
-  case $ac_file in
-  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
-  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
-  esac \
-  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
- ;;
-
-
-
-  esac
-
-done # for ac_tag
-
-
-as_fn_exit 0
-_ACEOF
-ac_clean_files=$ac_clean_files_save
-
-test $ac_write_fail = 0 ||
-  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
-
-
-# configure is writing to config.log, and then calls config.status.
-# config.status does its own redirection, appending to config.log.
-# Unfortunately, on DOS this fails, as config.log is still kept open
-# by configure, so config.status won't be able to write to it; its
-# output is simply discarded.  So we exec the FD to /dev/null,
-# effectively closing config.log, so it can be properly (re)opened and
-# appended to by config.status.  When coming back to configure, we
-# need to make the FD available again.
-if test "$no_create" != yes; then
-  ac_cs_success=:
-  ac_config_status_args=
-  test "$silent" = yes &&
-    ac_config_status_args="$ac_config_status_args --quiet"
-  exec 5>/dev/null
-  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
-  exec 5>>config.log
-  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
-  # would make configure fail if this is the last instruction.
-  $ac_cs_success || as_fn_exit 1
-fi
-if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
-$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
-fi
-
diff --git a/stubdom/configure.ac b/stubdom/configure.ac
deleted file mode 100644 (file)
index 9fec853..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-#                                               -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
-
-AC_PREREQ([2.67])
-AC_INIT([Xen Hypervisor Stub Domains], m4_esyscmd([../version.sh ../xen/Makefile]),
-    [xen-devel@lists.xen.org], [xen], [http://www.xen.org/])
-AC_CONFIG_SRCDIR([xenstore-minios.cfg])
-AC_CONFIG_FILES([../config/Stubdom.mk])
-AC_CONFIG_AUX_DIR([../])
-
-AC_CANONICAL_HOST
-
-# M4 Macro includes
-m4_include([../m4/stubdom.m4])
-m4_include([../m4/features.m4])
-m4_include([../m4/path_or_fail.m4])
-m4_include([../m4/depends.m4])
-m4_include([../m4/fetcher.m4])
-
-# Enable/disable stub domains
-AX_STUBDOM_CONDITIONAL([ioemu-stubdom], [ioemu])
-AX_STUBDOM_DEFAULT_DISABLE([c-stubdom], [c])
-AX_STUBDOM_DEFAULT_DISABLE([caml-stubdom], [caml])
-AX_STUBDOM_DEFAULT_ENABLE([pv-grub], [grub])
-AX_STUBDOM_DEFAULT_ENABLE([xenstore-stubdom], [xenstore])
-AX_STUBDOM_CONDITIONAL([vtpm-stubdom], [vtpm])
-AX_STUBDOM_CONDITIONAL([vtpmmgr-stubdom], [vtpmmgr])
-
-AC_ARG_ENABLE([qemu-traditional],,,[
-    case "$host_cpu" in
-        i[[3456]]86|x86_64)
-           enable_qemu_traditional="yes";;
-        *) enable_qemu_traditional="no";;
-    esac
-])
-AS_IF([test "x$enable_qemu_traditional" = "xyes"], [
-    qemu_traditional=y],[
-    qemu_traditional=n
-])
-AS_IF([test "x$ioemu" = "x"], [
-    ioemu=$qemu_traditional
-])
-echo "x$ioemu$qemu_traditional"
-AS_IF([test "x$ioemu$qemu_traditional" = "xyn"], [
-    AC_MSG_ERROR(IOEMU stubdomain requires qemu-traditional)
-])
-
-AX_ARG_DEFAULT_ENABLE([debug], [Disable debug build of stubdom])
-AX_ARG_DEFAULT_ENABLE([extfiles], [Use xen extfiles repository for libraries])
-
-AC_ARG_VAR([CMAKE], [Path to the cmake program])
-AX_CHECK_FETCHER
-
-# Checks for programs.
-AC_PROG_CC
-AC_PROG_MAKE_SET
-AC_PROG_INSTALL
-
-# Checks for programs that depend on a feature
-AX_DEPENDS_PATH_PROG([vtpm], [CMAKE], [cmake])
-
-# Stubdom libraries version and url setup
-AX_STUBDOM_LIB([ZLIB], [zlib], [1.2.3], [http://www.zlib.net])
-AX_STUBDOM_LIB([LIBPCI], [libpci], [2.2.9], [http://www.kernel.org/pub/software/utils/pciutils])
-AX_STUBDOM_LIB([NEWLIB], [newlib], [1.16.0], [ftp://sources.redhat.com/pub/newlib])
-AX_STUBDOM_LIB([LWIP], [lwip], [1.3.0], [http://download.savannah.gnu.org/releases/lwip])
-AX_STUBDOM_LIB([GRUB], [grub], [0.97], [http://alpha.gnu.org/gnu/grub])
-AX_STUBDOM_LIB_NOEXT([OCAML], [ocaml], [3.11.0], [http://caml.inria.fr/pub/distrib/ocaml-3.11])
-AX_STUBDOM_LIB([GMP], [libgmp], [4.3.2], [ftp://ftp.gmplib.org/pub/gmp-4.3.2])
-AX_STUBDOM_LIB([POLARSSL], [polarssl], [1.1.4], [http://polarssl.org/code/releases])
-AX_STUBDOM_LIB([TPMEMU], [berlios tpm emulator], [0.7.4], [http://download.berlios.de/tpm-emulator])
-
-#These stubdoms should be enabled if the dependent one is
-AX_STUBDOM_AUTO_DEPENDS([vtpmmgr], [vtpm])
-
-#Conditionally enable these stubdoms based on the presense of dependencies
-AX_STUBDOM_CONDITIONAL_FINISH([vtpm-stubdom], [vtpm])
-AX_STUBDOM_CONDITIONAL_FINISH([vtpmmgr-stubdom], [vtpmmgr])
-AX_STUBDOM_CONDITIONAL_FINISH([ioemu-stubdom], [ioemu])
-
-AX_STUBDOM_FINISH
-AC_OUTPUT()
diff --git a/stubdom/grub.patches/00cvs b/stubdom/grub.patches/00cvs
deleted file mode 100644 (file)
index 7947306..0000000
+++ /dev/null
@@ -1,1382 +0,0 @@
-diff -uprN grub-0.97/acinclude.m4 grub/acinclude.m4
---- grub-0.97/acinclude.m4     2004-04-27 21:48:06.000000000 +0100
-+++ grub/acinclude.m4  2007-11-05 01:29:46.000000000 +0000
-@@ -57,7 +57,7 @@ else
- fi
- grub_cv_prog_objcopy_absolute=yes
- for link_addr in 2000 8000 7C00; do
--  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
-+  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
-   else
-     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
-   fi
-diff -uprN grub-0.97/ChangeLog grub/ChangeLog
---- grub-0.97/ChangeLog        2005-05-08 03:47:02.000000000 +0100
-+++ grub/ChangeLog     2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,127 @@
-+2008-05-20  Robert Millan  <rmh@aybabtu.com>
-+
-+      * netboot/cs89x0.c: Fix license violation.
-+      * netboot/cs89x0.h: Likewise.
-+
-+2008-04-10  Pavel Roskin  <proski@gnu.org>
-+
-+      * configure.ac: Always use "_cv_" in cache variables for
-+      compatibility with Autoconf 2.62.
-+
-+2008-03-28  Robert Millan  <rmh@aybabtu.com>
-+
-+      Surpass 1 TiB disk addressing limit.  Note: there are no plans to handle
-+      the 2 TiB disk limit in GRUB Legacy, since that would need considerable
-+      rework.  If you have >2TiB disks, use GRUB 2 instead.
-+
-+      * grub/asmstub.c (biosdisk): Add unsigned qualifier to `sector'.
-+      * stage2/bios.c (biosdisk): Likewise.
-+      * stage2/disk_io.c (rawread, devread, rawwrite, devwrite): Likewise.
-+      * stage2/shared.h (rawread, devread, rawwrite, devwrite): Likewise.
-+      * lib/device.c (get_drive_geometry): Replace BLKGETSIZE with
-+      BLKGETSIZE64.
-+
-+2007-10-29  Pavel Roskin  <proski@gnu.org>
-+
-+      * configure.ac: Test if '--build-id=none' is supported by the
-+      linker and add it to LDFLAGS if possible.  Build ID causes
-+      objcopy to generate huge binary files.
-+      * aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Use LDFLAGS when
-+      linking, so that build ID doesn't break the test.
-+      * stage1/Makefile.am: Preserve LDFLAGS, use stage1_exec_LDFLAGS.
-+
-+2007-02-22  Pavel Roskin  <proski@gnu.org>
-+
-+      * stage2/iso9660.h: Remove unnecessary packed attributes.
-+
-+2007-02-22  Robert Millan  <rmh@aybabtu.com>
-+
-+      * util/mkbimage: Update my email address, and remove my name from
-+      some places where unnecessary credit is given.
-+
-+2006-09-10  Pavel Roskin  <proski@gnu.org>
-+
-+      * netboot/natsemi.c: Fix compile error with gcc 4.1.1.  Cast
-+      cannot make a variable volatile - it should be declared as such.
-+      * netboot/sis900.c: Likewise.
-+
-+2006-09-08  Pavel Roskin  <proski@gnu.org>
-+
-+      * netboot/etherboot.h: Remove incorrect extern declarations of
-+      the variables later declared static.  Move BOOTP_DATA_ADDR ...
-+      * netboot/main.c: ... here.  Eliminate end_of_rfc1533 - it's
-+      write-only.
-+
-+2006-06-24  Yoshinori K. Okuji  <okuji@enbug.org>
-+
-+      * docs/grub.texi: Changed the license term to the GNU Free
-+      Documentation License 1.2.
-+
-+      * docs/multiboot.texi: Reformatted to show the license term
-+      and the version number explicitly.
-+      
-+      * docs/fdl.texi: New file.
-+      
-+      * docs/Makefile.am (grub_TEXINFOS): Added fdl.texi.
-+
-+2006-06-24  Robert Millan  <robertmh@gnu.org>
-+
-+      * lib/device.c (write_to_partition): /dev/ataraid/ and /dev/rd/
-+      partitions have a "p" prefix.  Add it.
-+
-+2006-06-24  Robert Millan  <robertmh@gnu.org>
-+
-+      * lib/device.c (get_i2o_disk_name): New function.
-+      (init_device_map) [__linux__]: Add support for I2O devices.
-+
-+2006-05-02  Pavel Roskin  <proski@gnu.org>
-+
-+      * stage2/stage2.c (run_menu): Fix "savedefault" to save only top
-+      level menu positions.  Remember current position when calling a
-+      submenu.  Don't recalculate it when booting from a submenu.
-+
-+      * grub/main.c (main): Make sure the boot drive number doesn't
-+      exceed 255.
-+
-+2006-05-02  Vesa Jaaskelainen  <chaac@nic.fi>
-+
-+      * stage2/shared.h (vbe_mode): Back ported aligment fix from GRUB 2
-+      to GRUB Legacy.  Problem reported by Gerardo Richarte.
-+
-+2006-04-23  Robert Millan  <robertmh@gnu.org>
-+
-+      * grub/asmstub.c (get_diskinfo): Optimize sysctl routine.
-+
-+2006-04-20  Robert Millan  <robertmh@gnu.org>
-+
-+      Fixes for kernel of FreeBSD:
-+      * grub/asmstub.c (get_diskinfo): Toggle "kern.geom.debugflags" sysctl
-+      before opening a device for writing.
-+      * util/grub-install.in: Devices don't have this "r" prefix anymore.
-+
-+2006-04-16  Yoshinori K. Okuji  <okuji@enbug.org>
-+
-+      * docs/multiboot.texi: Correct the offset of address
-+      fields. Reported by Jeroen Dekkers.
-+
-+2006-03-21  Yoshinori K. Okuji  <okuji@enbug.org>
-+
-+      * stage2/builtins.c (setup_func): Specify the size of DEVICE to
-+      grub_strncat instead of a strange number 256. Reported by Vitaly
-+      Fertman <vitaly@namesys.com>.
-+
-+2005-09-29  Yoshinori K. Okuji  <okuji@enbug.org>
-+
-+      * docs/multiboot.texi: Fix a bug in the byte order of
-+      boot_device. I hope this won't affect any OS image.
-+      Increased the version number to 0.6.94.
-+
-+2005-09-28  Yoshinori K. Okuji  <okuji@enbug.org>
-+
-+      * stage2/boot.c (load_image): Even if an OS image is an ELF
-+      object, use the a.out kludge if MULTIBOOT_AOUT_KLUDGE is
-+      specified.
-+
- 2005-05-08  Yoshinori K. Okuji  <okuji@enbug.org>
-       * configure.ac (AC_INIT): Upgraded to 0.97.
-diff -uprN grub-0.97/configure grub/configure
---- grub-0.97/configure        2005-05-08 03:48:12.000000000 +0100
-+++ grub/configure     2007-11-05 01:29:46.000000000 +0000
-@@ -3694,6 +3694,64 @@ if test "x$undef_flag" = xyes; then
-   CPPFLAGS="$CPPFLAGS -Wundef"
- fi
-+# Check if build ID can be disabled in the linker
-+echo "$as_me:$LINENO: checking whether linker accepts \`--build-id=none'" >&5
-+echo $ECHO_N "checking whether linker accepts \`--build-id=none'... $ECHO_C" >&6
-+save_LDFLAGS="$LDFLAGS"
-+LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+cat >conftest.$ac_ext <<_ACEOF
-+/* confdefs.h.  */
-+_ACEOF
-+cat confdefs.h >>conftest.$ac_ext
-+cat >>conftest.$ac_ext <<_ACEOF
-+/* end confdefs.h.  */
-+
-+int
-+main ()
-+{
-+
-+  ;
-+  return 0;
-+}
-+_ACEOF
-+rm -f conftest.$ac_objext conftest$ac_exeext
-+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-+  (eval $ac_link) 2>conftest.er1
-+  ac_status=$?
-+  grep -v '^ *+' conftest.er1 >conftest.err
-+  rm -f conftest.er1
-+  cat conftest.err >&5
-+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+  (exit $ac_status); } &&
-+       { ac_try='test -z "$ac_c_werror_flag"
-+                       || test ! -s conftest.err'
-+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-+  (eval $ac_try) 2>&5
-+  ac_status=$?
-+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+  (exit $ac_status); }; } &&
-+       { ac_try='test -s conftest$ac_exeext'
-+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-+  (eval $ac_try) 2>&5
-+  ac_status=$?
-+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-+  (exit $ac_status); }; }; then
-+  build_id_flag=yes
-+else
-+  echo "$as_me: failed program was:" >&5
-+sed 's/^/| /' conftest.$ac_ext >&5
-+
-+build_id_flag=no
-+fi
-+rm -f conftest.err conftest.$ac_objext \
-+      conftest$ac_exeext conftest.$ac_ext
-+echo "$as_me:$LINENO: result: $build_id_flag" >&5
-+echo "${ECHO_T}$build_id_flag" >&6
-+LDFLAGS="$save_LDFLAGS"
-+if test "x$build_id_flag" = xyes; then
-+  LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+fi
-+
- if test "x$with_binutils" != x; then
-   # Extract the first word of "objcopy", so it can be a program name with args.
- set dummy objcopy; ac_word=$2
-@@ -3892,7 +3950,7 @@ echo "$as_me: error: ${CC-cc} cannot com
- fi
- grub_cv_prog_objcopy_absolute=yes
- for link_addr in 2000 8000 7C00; do
--  if { ac_try='${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec'
-+  if { ac_try='${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec'
-   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-   (eval $ac_try) 2>&5
-   ac_status=$?
-diff -uprN grub-0.97/configure.ac grub/configure.ac
---- grub-0.97/configure.ac     2005-05-08 03:36:03.000000000 +0100
-+++ grub/configure.ac  2008-04-10 23:26:50.000000000 +0100
-@@ -86,13 +86,13 @@ if test "x$ac_cv_prog_gcc" = xyes; then
-     fi
-     STAGE1_CFLAGS="-O2"
-     GRUB_CFLAGS="-O2"
--    AC_CACHE_CHECK([whether optimization for size works], size_flag, [
-+    AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
-       saved_CFLAGS=$CFLAGS
-       CFLAGS="-Os -g"
--      AC_TRY_COMPILE(, , size_flag=yes, size_flag=no)
-+      AC_TRY_COMPILE(, , grub_cv_cc_Os=yes, grub_cv_cc_Os=no)
-       CFLAGS=$saved_CFLAGS
-     ])
--    if test "x$size_flag" = xyes; then
-+    if test "x$grub_cv_cc_Os" = xyes; then
-       STAGE2_CFLAGS="-Os"
-     else
-       STAGE2_CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops"
-@@ -100,16 +100,16 @@ if test "x$ac_cv_prog_gcc" = xyes; then
-     # OpenBSD has a GCC extension for protecting applications from
-     # stack smashing attacks, but GRUB doesn't want this feature.
-     AC_CACHE_CHECK([whether gcc has -fno-stack-protector],
--                 no_stack_protector_flag, [
-+                 grub_cv_cc_no_stack_protector, [
-       saved_CFLAGS=$CFLAGS
-       CFLAGS="-fno-stack-protector"
-       AC_TRY_COMPILE(,
-                    ,
--                   no_stack_protector_flag=yes,
--                   no_stack_protector_flag=no)
-+                   grub_cv_cc_no_stack_protector=yes,
-+                   grub_cv_cc_no_stack_protector=no)
-       CFLAGS=$saved_CFLAGS
-     ])
--    if test "x$no_stack_protector_flag" = xyes; then
-+    if test "x$grub_cv_cc_no_stack_protector" = xyes; then
-       STAGE2_CFLAGS="$STAGE2_CFLAGS -fno-stack-protector"
-     fi
-   fi
-@@ -123,33 +123,44 @@ AC_SUBST(GRUB_CFLAGS)
- CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused -Wshadow"
- CPPFLAGS="$CPPFLAGS -Wpointer-arith"
--AC_CACHE_CHECK([whether -Wundef works], undef_flag, [
-+AC_CACHE_CHECK([whether -Wundef works], grub_cv_cc_Wundef, [
-   saved_CPPFLAGS="$CPPFLAGS"
-   CPPFLAGS="-Wundef"
--  AC_TRY_COMPILE(, , undef_flag=yes, undef_flag=no)
-+  AC_TRY_COMPILE(, , grub_cv_cc_Wundef=yes, grub_cv_cc_Wundef=no)
-   CPPFLAGS="$saved_CPPFLAGS"
- ])
- # The options `-falign-*' are supported by gcc 3.0 or later.
- # Probably it is sufficient to only check for -falign-loops.
--AC_CACHE_CHECK([whether -falign-loops works], [falign_loop_flag], [
-+AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
-   saved_CPPFLAGS="$CPPFLAGS"
-   CPPFLAGS="-falign-loops=1"
--  AC_TRY_COMPILE(, , [falign_loop_flag=yes], [falign_loop_flag=no])
-+  AC_TRY_COMPILE(, , [grub_cv_cc_falign_loop=yes], [grub_cv_cc_falign_loop=no])
-   CPPFLAGS="$saved_CPPFLAGS"
- ])
- # Force no alignment to save space.
--if test "x$falign_loop_flag" = xyes; then
-+if test "x$grub_cv_cc_falign_loop" = xyes; then
-   CPPFLAGS="$CPPFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
- else
-   CPPFLAGS="$CPPFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
- fi
--if test "x$undef_flag" = xyes; then
-+if test "x$grub_cv_cc_Wundef" = xyes; then
-   CPPFLAGS="$CPPFLAGS -Wundef"
- fi
-+# Check if build ID can be disabled in the linker
-+AC_MSG_CHECKING([whether linker accepts `--build-id=none'])
-+save_LDFLAGS="$LDFLAGS"
-+LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+AC_TRY_LINK(, , build_id_flag=yes, build_id_flag=no)
-+AC_MSG_RESULT([$build_id_flag])
-+LDFLAGS="$save_LDFLAGS"
-+if test "x$build_id_flag" = xyes; then
-+  LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-+fi
-+
- if test "x$with_binutils" != x; then
- dnl  AC_PATH_TOOL(OBJCOPY, objcopy, , "$with_binutils:$PATH")
-   AC_PATH_PROG(OBJCOPY, objcopy, , "$with_binutils:$PATH")
-diff -uprN grub-0.97/docs/grub.8 grub/docs/grub.8
---- grub-0.97/docs/grub.8      2005-05-08 03:48:56.000000000 +0100
-+++ grub/docs/grub.8   2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
--.TH GRUB "8" "May 2005" "grub (GNU GRUB 0.97)" FSF
-+.TH GRUB "8" "June 2006" "grub (GNU GRUB 0.97)" FSF
- .SH NAME
- grub \- the grub shell
- .SH SYNOPSIS
-diff -uprN grub-0.97/docs/grub-install.8 grub/docs/grub-install.8
---- grub-0.97/docs/grub-install.8      2005-05-08 03:48:56.000000000 +0100
-+++ grub/docs/grub-install.8   2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
--.TH GRUB-INSTALL "8" "May 2005" "grub-install (GNU GRUB 0.97)" FSF
-+.TH GRUB-INSTALL "8" "June 2006" "grub-install (GNU GRUB 0.97)" FSF
- .SH NAME
- grub-install \- install GRUB on your drive
- .SH SYNOPSIS
-diff -uprN grub-0.97/docs/grub-md5-crypt.8 grub/docs/grub-md5-crypt.8
---- grub-0.97/docs/grub-md5-crypt.8    2005-05-08 03:48:56.000000000 +0100
-+++ grub/docs/grub-md5-crypt.8 2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
--.TH GRUB-MD5-CRYPT "8" "May 2005" "grub-md5-crypt (GNU GRUB )" FSF
-+.TH GRUB-MD5-CRYPT "8" "June 2006" "grub-md5-crypt (GNU GRUB )" FSF
- .SH NAME
- grub-md5-crypt \- Encrypt a password in MD5 format
- .SH SYNOPSIS
-diff -uprN grub-0.97/docs/grub-terminfo.8 grub/docs/grub-terminfo.8
---- grub-0.97/docs/grub-terminfo.8     2005-05-08 03:48:56.000000000 +0100
-+++ grub/docs/grub-terminfo.8  2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
--.TH GRUB-TERMINFO "8" "May 2005" "grub-terminfo (GNU GRUB 0.97)" FSF
-+.TH GRUB-TERMINFO "8" "June 2006" "grub-terminfo (GNU GRUB 0.97)" FSF
- .SH NAME
- grub-terminfo \- Generate a terminfo command from a terminfo name
- .SH SYNOPSIS
-diff -uprN grub-0.97/docs/grub.texi grub/docs/grub.texi
---- grub-0.97/docs/grub.texi   2005-05-08 03:59:59.000000000 +0100
-+++ grub/docs/grub.texi        2006-06-24 15:40:02.000000000 +0100
-@@ -2,22 +2,41 @@
- @c -*-texinfo-*-
- @c %**start of header
- @setfilename grub.info
--@settitle GRUB Manual
--@c %**end of header
--
- @include version.texi
--
-+@settitle GNU GRUB Manual @value{VERSION}
- @c Unify all our little indices for now.
- @syncodeindex fn cp
- @syncodeindex vr cp
- @syncodeindex ky cp
- @syncodeindex pg cp
- @syncodeindex tp cp
-+@c %**end of header
- @footnotestyle separate
- @paragraphindent 3
- @finalout
-+@copying
-+This manual is for GNU GRUB (version @value{VERSION},
-+@value{UPDATED}).
-+
-+Copyright @copyright{} 1999,2000,2001,2002,2004,2006 Free Software Foundation, Inc.
-+
-+@quotation
-+Permission is granted to copy, distribute and/or modify this document
-+under the terms of the GNU Free Documentation License, Version 1.2 or
-+any later version published by the Free Software Foundation; with no
-+Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
-+and with the Back-Cover Texts as in (a) below.  A copy of the
-+license is included in the section entitled ``GNU Free Documentation
-+License.''
-+
-+(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
-+this GNU Manual, like GNU software.  Copies published by the Free
-+Software Foundation raise funds for GNU development.''
-+@end quotation
-+@end copying
-+
- @dircategory Kernel
- @direntry
- * GRUB: (grub).                 The GRand Unified Bootloader
-@@ -34,53 +53,16 @@
- @setchapternewpage odd
--@ifinfo
--Copyright @copyright{} 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
--
--Permission is granted to make and distribute verbatim copies of
--this manual provided the copyright notice and this permission notice
--are preserved on all copies.
--
--@ignore
--Permission is granted to process this file through TeX and print the
--results, provided the printed document carries a copying permission
--notice identical to this one except for the removal of this paragraph
--(this paragraph not being relevant to the printed manual).
--
--@end ignore
--
--Permission is granted to copy and distribute modified versions of this
--manual under the conditions for verbatim copying, provided also that
--the entire resulting derived work is distributed under the terms of a
--permission notice identical to this one.
--
--Permission is granted to copy and distribute translations of this manual
--into another language, under the above conditions for modified versions.
--@end ifinfo
--
- @titlepage
- @sp 10
--@title the GRUB manual
-+@title the GNU GRUB manual
- @subtitle The GRand Unified Bootloader, version @value{VERSION}, @value{UPDATED}.
- @author Gordon Matzigkeit
- @author Yoshinori K. Okuji
- @c The following two commands start the copyright page.
- @page
- @vskip 0pt plus 1filll
--Copyright @copyright{} 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
--
--Permission is granted to make and distribute verbatim copies of
--this manual provided the copyright notice and this permission notice
--are preserved on all copies.
--Permission is granted to copy and distribute modified versions of this
--manual under the conditions for verbatim copying, provided that the entire
--resulting derived work is distributed under the terms of a permission
--notice identical to this one.
--
--Permission is granted to copy and distribute translations of this manual
--into another language, under the above conditions for modified versions,
--except that this permission notice may be stated in a translation approved
--by Free Software Foundation.
-+@insertcopying
- @end titlepage
- @c Output the table of contents at the beginning.
-@@ -91,12 +73,14 @@ by Free Software Foundation.
- @ifnottex
- @node Top
--@top GRUB manual
-+@top GNU GRUB manual
- This is the documentation of GNU GRUB, the GRand Unified Bootloader,
- a flexible and powerful boot loader program for @sc{pc}s.
- This edition documents version @value{VERSION}.
-+
-+@insertcopying
- @end ifnottex
- @menu
-@@ -124,6 +108,7 @@ This edition documents version @value{VE
- * Reporting bugs::              Where you should send a bug report
- * Future::                      Some future plans on GRUB
- * Internals::                   Hacking GRUB
-+* Copying This Manual::         Copying This Manual
- * Index::
- @end menu
-@@ -3965,6 +3950,16 @@ homepage}.
- @include internals.texi
-+@node Copying This Manual
-+@appendix Copying This Manual
-+
-+@menu
-+* GNU Free Documentation License::  License for copying this manual.
-+@end menu
-+
-+@include fdl.texi
-+
-+
- @node Index
- @unnumbered Index
-diff -uprN grub-0.97/docs/Makefile.am grub/docs/Makefile.am
---- grub-0.97/docs/Makefile.am 2003-07-09 12:45:35.000000000 +0100
-+++ grub/docs/Makefile.am      2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- info_TEXINFOS = grub.texi multiboot.texi
--grub_TEXINFOS = internals.texi
-+grub_TEXINFOS = internals.texi fdl.texi
- EXAMPLES = boot.S kernel.c multiboot.h
- multiboot_TEXINFOS = boot.S.texi kernel.c.texi multiboot.h.texi
- man_MANS = grub.8 mbchk.1 grub-install.8 grub-md5-crypt.8 grub-terminfo.8
-diff -uprN grub-0.97/docs/Makefile.in grub/docs/Makefile.in
---- grub-0.97/docs/Makefile.in 2005-05-08 03:42:34.000000000 +0100
-+++ grub/docs/Makefile.in      2006-06-24 15:40:02.000000000 +0100
-@@ -202,7 +202,7 @@ sharedstatedir = @sharedstatedir@
- sysconfdir = @sysconfdir@
- target_alias = @target_alias@
- info_TEXINFOS = grub.texi multiboot.texi
--grub_TEXINFOS = internals.texi
-+grub_TEXINFOS = internals.texi fdl.texi
- EXAMPLES = boot.S kernel.c multiboot.h
- multiboot_TEXINFOS = boot.S.texi kernel.c.texi multiboot.h.texi
- man_MANS = grub.8 mbchk.1 grub-install.8 grub-md5-crypt.8 grub-terminfo.8
-diff -uprN grub-0.97/docs/mbchk.1 grub/docs/mbchk.1
---- grub-0.97/docs/mbchk.1     2005-05-08 03:48:56.000000000 +0100
-+++ grub/docs/mbchk.1  2006-06-24 15:40:02.000000000 +0100
-@@ -1,5 +1,5 @@
- .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
--.TH MBCHK "1" "May 2005" "mbchk (GNU GRUB 0.97)" FSF
-+.TH MBCHK "1" "June 2006" "mbchk (GNU GRUB 0.97)" FSF
- .SH NAME
- mbchk \- check the format of a Multiboot kernel
- .SH SYNOPSIS
-diff -uprN grub-0.97/docs/multiboot.texi grub/docs/multiboot.texi
---- grub-0.97/docs/multiboot.texi      2003-07-09 12:45:36.000000000 +0100
-+++ grub/docs/multiboot.texi   2006-06-24 15:40:02.000000000 +0100
-@@ -1,32 +1,28 @@
- \input texinfo @c -*-texinfo-*-
--@c -*-texinfo-*-
- @c %**start of header
- @setfilename multiboot.info
--@settitle Multiboot Specification
--@c %**end of header
--
-+@set VERSION 0.6.95
-+@settitle Multiboot Specification version @value{VERSION}
- @c Unify all our little indices for now.
- @syncodeindex fn cp
- @syncodeindex vr cp
- @syncodeindex ky cp
- @syncodeindex pg cp
- @syncodeindex tp cp
-+@c %**end of header
- @footnotestyle separate
- @paragraphindent 3
- @finalout
-+@copying
-+Copyright @copyright{} 1995,96 Bryan Ford <baford@@cs.utah.edu>
--@dircategory Kernel
--@direntry
--* Multiboot Specification: (multiboot).               Multiboot Specification.
--@end direntry
-+Copyright @copyright{} 1995,96 Erich Stefan Boleyn <erich@@uruk.org>
--@ifinfo
--Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
--Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
--Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
-+Copyright @copyright{} 1999,2000,2001,2002,2005,2006 Free Software Foundation, Inc.
-+@quotation
- Permission is granted to make and distribute verbatim copies of
- this manual provided the copyright notice and this permission notice
- are preserved on all copies.
-@@ -36,7 +32,6 @@ Permission is granted to process this fi
- results, provided the printed document carries a copying permission
- notice identical to this one except for the removal of this paragraph
- (this paragraph not being relevant to the printed manual).
--
- @end ignore
- Permission is granted to copy and distribute modified versions of this
-@@ -45,31 +40,23 @@ the entire resulting derived work is dis
- permission notice identical to this one.
- Permission is granted to copy and distribute translations of this manual
--into another language, under the above conditions for modified versions.
--@end ifinfo
-+into another language, under the above conditions for modified
-+versions.
-+@end quotation
-+@end copying
-+
-+@dircategory Kernel
-+@direntry
-+* Multiboot Specification: (multiboot).               Multiboot Specification.
-+@end direntry
- @titlepage
- @sp 10
--@title The Multiboot Specification
-+@title The Multiboot Specification version @value{VERSION}
- @author Yoshinori K. Okuji, Bryan Ford, Erich Stefan Boleyn, Kunihiro Ishiguro
- @page
--
- @vskip 0pt plus 1filll
--Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
--Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
--Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
--
--Permission is granted to make and distribute verbatim copies of
--this manual provided the copyright notice and this permission notice
--are preserved on all copies.
--
--Permission is granted to copy and distribute modified versions of this
--manual under the conditions for verbatim copying, provided also that
--the entire resulting derived work is distributed under the terms of a
--permission notice identical to this one.
--
--Permission is granted to copy and distribute translations of this manual
--into another language, under the above conditions for modified versions.
-+@insertcopying
- @end titlepage
- @finalout
-@@ -80,7 +67,9 @@ into another language, under the above c
- @top Multiboot Specification
- This file documents Multiboot Specification, the proposal for the boot
--sequence standard. This edition documents version 0.6.93.
-+sequence standard. This edition documents version @value{VERSION}.
-+
-+@insertcopying
- @end ifnottex
- @menu
-@@ -426,7 +415,7 @@ mode table (@pxref{Boot information form
- kernel.
- If bit 16 in the @samp{flags} word is set, then the fields at offsets
--8-24 in the Multiboot header are valid, and the boot loader should use
-+12-28 in the Multiboot header are valid, and the boot loader should use
- them instead of the fields in the actual executable header to calculate
- where to load the OS image. This information does not need to be
- provided if the kernel image is in @sc{elf} format, but it @emph{must}
-@@ -677,7 +666,7 @@ follows:
- @example
- @group
- +-------+-------+-------+-------+
--| drive | part1 | part2 | part3 |
-+| part3 | part2 | part1 | drive |
- +-------+-------+-------+-------+
- @end group
- @end example
-@@ -1197,6 +1186,17 @@ Rewritten, using more strict words.
- @item
- The maintainer changes to the GNU GRUB maintainer team
- @email{bug-grub@@gnu.org}, from Bryan Ford and Erich Stefan Boleyn.
-+
-+@item
-+The byte order of the @samp{boot_device} in Multiboot information is
-+reversed. This was a mistake.
-+
-+@item
-+The offset of the address fields were wrong.
-+
-+@item
-+The format is adapted to a newer Texinfo, and the version number is
-+specified more explicitly in the title.
- @end itemize
- @item 0.6
-diff -uprN grub-0.97/grub/asmstub.c grub/grub/asmstub.c
---- grub-0.97/grub/asmstub.c   2005-02-16 20:45:14.000000000 +0000
-+++ grub/grub/asmstub.c        2008-03-28 13:22:28.000000000 +0000
-@@ -55,6 +55,10 @@ int grub_stage2 (void);
- # endif /* ! BLKFLSBUF */
- #endif /* __linux__ */
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+# include <sys/sysctl.h>
-+#endif
-+
- /* We want to prevent any circularararity in our stubs, as well as
-    libc name clashes. */
- #define WITHOUT_LIBC_STUBS 1
-@@ -777,7 +781,39 @@ get_diskinfo (int drive, struct geometry
-       /* Open read/write, or read-only if that failed. */
-       if (! read_only)
--      disks[drive].flags = open (devname, O_RDWR);
-+      {
-+/* By default, kernel of FreeBSD does not allow overwriting MBR */
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+#define GEOM_SYSCTL   "kern.geom.debugflags"
-+        int old_flags, flags;
-+        size_t sizeof_int = sizeof (int);
-+
-+        if (sysctlbyname (GEOM_SYSCTL, &old_flags, &sizeof_int, NULL, 0) != 0)
-+          grub_printf ("failed to get " GEOM_SYSCTL "sysctl: %s\n", strerror (errno));
-+
-+        if ((old_flags & 0x10) == 0)
-+          {
-+            /* "allow foot shooting", see geom(4) */
-+            flags = old_flags | 0x10;
-+
-+            if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &flags, sizeof (int)) != 0)
-+              {
-+                flags = old_flags;
-+                grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", strerror (errno));
-+              }
-+          }
-+        else
-+          flags = old_flags;
-+#endif
-+        disks[drive].flags = open (devname, O_RDWR);
-+#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-+        if (flags != old_flags)
-+          {
-+            if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &old_flags, sizeof (int)) != 0)
-+              grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", strerror (errno));
-+          }
-+#endif
-+      }
-       if (disks[drive].flags == -1)
-       {
-@@ -926,7 +962,7 @@ hex_dump (void *buf, size_t size)
- int
- biosdisk (int subfunc, int drive, struct geometry *geometry,
--        int sector, int nsec, int segment)
-+        unsigned int sector, int nsec, int segment)
- {
-   char *buf;
-   int fd = geometry->flags;
-diff -uprN grub-0.97/grub/main.c grub/grub/main.c
---- grub-0.97/grub/main.c      2003-07-09 12:45:36.000000000 +0100
-+++ grub/grub/main.c   2006-05-05 22:43:46.000000000 +0100
-@@ -32,6 +32,7 @@ int grub_stage2 (void);
- #define WITHOUT_LIBC_STUBS 1
- #include <shared.h>
- #include <term.h>
-+#include <device.h>
- char *program_name = 0;
- int use_config_file = 1;
-@@ -192,6 +193,12 @@ main (int argc, char **argv)
-             perror ("strtoul");
-             exit (1);
-           }
-+        if (boot_drive >= NUM_DISKS)
-+          {
-+            fprintf (stderr, "boot_drive should be from 0 to %d\n",
-+                     NUM_DISKS - 1);
-+            exit (1);
-+          }
-         break;
-       case OPT_NO_CONFIG_FILE:
-diff -uprN grub-0.97/lib/device.c grub/lib/device.c
---- grub-0.97/lib/device.c     2005-03-28 00:14:25.000000000 +0100
-+++ grub/lib/device.c  2008-03-28 13:22:28.000000000 +0000
-@@ -69,9 +69,9 @@ struct hd_geometry
- # ifndef CDROM_GET_CAPABILITY
- #  define CDROM_GET_CAPABILITY        0x5331  /* get capabilities */
- # endif /* ! CDROM_GET_CAPABILITY */
--# ifndef BLKGETSIZE
--#  define BLKGETSIZE  _IO(0x12,96)    /* return device size */
--# endif /* ! BLKGETSIZE */
-+# ifndef BLKGETSIZE64
-+#  define BLKGETSIZE64        _IOR(0x12,114,size_t)   /* return device size */
-+# endif /* ! BLKGETSIZE64 */
- #endif /* __linux__ */
- /* Use __FreeBSD_kernel__ instead of __FreeBSD__ for compatibility with
-@@ -152,19 +152,19 @@ get_drive_geometry (struct geometry *geo
-   /* Linux */
-   {
-     struct hd_geometry hdg;
--    unsigned long nr;
-+    unsigned long long nr;
-     
-     if (ioctl (fd, HDIO_GETGEO, &hdg))
-       goto fail;
--    if (ioctl (fd, BLKGETSIZE, &nr))
-+    if (ioctl (fd, BLKGETSIZE64, &nr))
-       goto fail;
-     
-     /* Got the geometry, so save it. */
-     geom->cylinders = hdg.cylinders;
-     geom->heads = hdg.heads;
-     geom->sectors = hdg.sectors;
--    geom->total_sectors = nr;
-+    geom->total_sectors = nr / 512;
-     
-     goto success;
-   }
-@@ -407,6 +407,12 @@ get_ataraid_disk_name (char *name, int u
- {
-   sprintf (name, "/dev/ataraid/d%c", unit + '0');
- }
-+
-+static void
-+get_i2o_disk_name (char *name, char unit)
-+{
-+  sprintf (name, "/dev/i2o/hd%c", unit);
-+}
- #endif
- /* Check if DEVICE can be read. If an error occurs, return zero,
-@@ -801,6 +807,29 @@ init_device_map (char ***map, const char
-         }
-       }
-   }
-+    
-+  /* This is for I2O - we have /dev/i2o/hd<logical drive><partition> */
-+  {
-+    int unit;
-+
-+    for (unit = 'a'; unit < 'f'; unit++)
-+      {
-+        char name[24];
-+    
-+        get_i2o_disk_name (name, unit);
-+        if (check_device (name))
-+          {
-+              (*map)[num_hd + 0x80] = strdup (name);
-+                  assert ((*map)[num_hd + 0x80]);
-+                  
-+          /* If the device map file is opened, write the map.  */
-+               if (fp)
-+                     fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
-+                     
-+          num_hd++;
-+          }
-+      }
-+  }
- #endif /* __linux__ */
-   
-   /* OK, close the device map file if opened.  */
-@@ -861,6 +890,12 @@ write_to_partition (char **map, int driv
-       if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
-       strcpy (dev + strlen(dev) - 5, "/part");
-     }
-+  else
-+    {
-+      if ((strncmp (dev, "/dev/ataraid/", 13) == 0) ||
-+         (strncmp (dev, "/dev/rd/", 8) == 0))
-+        strcpy (dev + strlen(dev), "p");
-+    }
-   sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
-   
-   /* Open the partition.  */
-diff -uprN grub-0.97/netboot/3c509.c grub/netboot/3c509.c
---- grub-0.97/netboot/3c509.c  2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/3c509.c       2002-01-02 21:56:40.000000000 +0000
-@@ -18,7 +18,7 @@ Author: Martin Renters.
- 3c509 support added by Serge Babkin (babkin@hq.icb.chel.su)
--$Id: 3c509.c,v 1.4 2002/01/02 21:56:40 okuji Exp $
-+$Id: 3c509.c 609 2002-01-02 21:56:40Z okuji $
- ***************************************************************************/
-diff -uprN grub-0.97/netboot/cs89x0.c grub/netboot/cs89x0.c
---- grub-0.97/netboot/cs89x0.c 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/cs89x0.c      2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,21 @@
-+/**
-+   Per an email message from Russ Nelson <nelson@crynwr.com> on
-+   18 March 2008 this file is now licensed under GPL Version 2.
-+
-+   From: Russ Nelson <nelson@crynwr.com>
-+   Date: Tue, 18 Mar 2008 12:42:00 -0400
-+   Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
-+   -- quote from email
-+   As copyright holder, if I say it doesn't conflict with the GPL,
-+   then it doesn't conflict with the GPL.
-+
-+   However, there's no point in causing people's brains to overheat,
-+   so yes, I grant permission for the code to be relicensed under the
-+   GPLv2.  Please make sure that this change in licensing makes its
-+   way upstream.  -russ
-+   -- quote from email
-+**/
-+
- /* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for etherboot. */
- /*
-   Permission is granted to distribute the enclosed cs89x0.[ch] driver
-diff -uprN grub-0.97/netboot/cs89x0.h grub/netboot/cs89x0.h
---- grub-0.97/netboot/cs89x0.h 2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/cs89x0.h      2008-05-20 12:04:18.000000000 +0100
-@@ -1,3 +1,21 @@
-+/**
-+   Per an email message from Russ Nelson <nelson@crynwr.com> on
-+   18 March 2008 this file is now licensed under GPL Version 2.
-+
-+   From: Russ Nelson <nelson@crynwr.com>
-+   Date: Tue, 18 Mar 2008 12:42:00 -0400
-+   Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
-+   -- quote from email
-+   As copyright holder, if I say it doesn't conflict with the GPL,
-+   then it doesn't conflict with the GPL.
-+
-+   However, there's no point in causing people's brains to overheat,
-+   so yes, I grant permission for the code to be relicensed under the
-+   GPLv2.  Please make sure that this change in licensing makes its
-+   way upstream.  -russ
-+   -- quote from email
-+**/
-+
- /*  Copyright, 1988-1992, Russell Nelson, Crynwr Software
-    This program is free software; you can redistribute it and/or modify
-diff -uprN grub-0.97/netboot/etherboot.h grub/netboot/etherboot.h
---- grub-0.97/netboot/etherboot.h      2003-07-09 12:45:37.000000000 +0100
-+++ grub/netboot/etherboot.h   2006-09-08 13:56:22.000000000 +0100
-@@ -531,9 +531,6 @@ extern int ip_abort;
- extern int network_ready;
- extern struct rom_info rom;
- extern struct arptable_t arptable[MAX_ARP];
--extern struct bootpd_t bootp_data;
--#define       BOOTP_DATA_ADDR (&bootp_data)
--extern unsigned char *end_of_rfc1533;
- /* config.c */
- extern struct nic nic;
-diff -uprN grub-0.97/netboot/main.c grub/netboot/main.c
---- grub-0.97/netboot/main.c   2004-05-20 23:19:33.000000000 +0100
-+++ grub/netboot/main.c        2006-09-08 13:56:22.000000000 +0100
-@@ -56,7 +56,8 @@ static int vendorext_isvalid;
- static unsigned long netmask;
- static struct bootpd_t bootp_data;
- static unsigned long xid;
--static unsigned char *end_of_rfc1533 = NULL;
-+
-+#define       BOOTP_DATA_ADDR (&bootp_data)
- #ifndef       NO_DHCP_SUPPORT
- #endif /* NO_DHCP_SUPPORT */
-@@ -967,7 +968,6 @@ decode_rfc1533 (unsigned char *p, int bl
-   
-   if (block == 0)
-     {
--      end_of_rfc1533 = NULL;
-       vendorext_isvalid = 0;
-       
-       if (grub_memcmp (p, rfc1533_cookie, 4))
-@@ -1021,7 +1021,7 @@ decode_rfc1533 (unsigned char *p, int bl
-       }
-       else if (c == RFC1533_END)
-       {
--        end_of_rfc1533 = endp = p;
-+        endp = p;
-         continue;
-       }
-       else if (c == RFC1533_NETMASK)
-diff -uprN grub-0.97/netboot/natsemi.c grub/netboot/natsemi.c
---- grub-0.97/netboot/natsemi.c        2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/natsemi.c     2006-09-10 08:26:10.000000000 +0100
-@@ -608,7 +608,7 @@ natsemi_transmit(struct nic  *nic,
-                const char  *p)     /* Packet */
- {
-     u32 status, to, nstype;
--    u32 tx_status;
-+    volatile u32 tx_status;
-     
-     /* Stop the transmitter */
-     outl(TxOff, ioaddr + ChipCmd);
-@@ -647,7 +647,7 @@ natsemi_transmit(struct nic  *nic,
-     to = currticks() + TX_TIMEOUT;
--    while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < to))
-+    while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
-         /* wait */ ;
-     if (currticks() >= to) {
-diff -uprN grub-0.97/netboot/sis900.c grub/netboot/sis900.c
---- grub-0.97/netboot/sis900.c 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sis900.c      2006-09-10 08:26:10.000000000 +0100
-@@ -901,7 +901,7 @@ sis900_transmit(struct nic  *nic,
-                 const char  *p)     /* Packet */
- {
-     u32 status, to, nstype;
--    u32 tx_status;
-+    volatile u32 tx_status;
-     
-     /* Stop the transmitter */
-     outl(TxDIS, ioaddr + cr);
-@@ -940,7 +940,7 @@ sis900_transmit(struct nic  *nic,
-     to = currticks() + TX_TIMEOUT;
--    while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < to))
-+    while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
-         /* wait */ ;
-     if (currticks() >= to) {
-diff -uprN grub-0.97/netboot/sk_g16.c grub/netboot/sk_g16.c
---- grub-0.97/netboot/sk_g16.c 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sk_g16.c      2002-01-02 21:56:40.000000000 +0000
-@@ -13,12 +13,12 @@ Changes to make it work with Etherboot b
-  *
-  * Module         : sk_g16.c
-  *
-- * Version        : $Revision: 1.4 $
-+ * Version        : $Revision: 609 $
-  *
-  * Author         : Patrick J.D. Weichmann
-  *
-  * Date Created   : 94/05/26
-- * Last Updated   : $Date: 2002/01/02 21:56:40 $
-+ * Last Updated   : $Date: 2002-01-02 21:56:40 +0000 (mer 02 jan 2002) $
-  *
-  * Description    : Schneider & Koch G16 Ethernet Device Driver for
-  *                  Linux Kernel >= 1.1.22
-diff -uprN grub-0.97/netboot/sk_g16.h grub/netboot/sk_g16.h
---- grub-0.97/netboot/sk_g16.h 2003-07-09 12:45:38.000000000 +0100
-+++ grub/netboot/sk_g16.h      2000-07-29 20:22:54.000000000 +0100
-@@ -4,7 +4,7 @@
-  * of the GNU Public License, incorporated herein by reference.
-  *
-  * Module         : sk_g16.h
-- * Version        : $Revision: 1.3 $
-+ * Version        : $Revision: 388 $
-  *
-  * Author         : M.Hipp (mhipp@student.uni-tuebingen.de)
-  * changes by     : Patrick J.D. Weichmann
-@@ -15,8 +15,8 @@
-  *                  the am7990 (LANCE) chip used for writing a
-  *                  network device driver which uses this chip
-  *
-- * $Log: sk_g16.h,v $
-- * Revision 1.3  2000/07/29 19:22:54  okuji
-+ * $Log$
-+ * Revision 1.3  2000-07-29 19:22:54  okuji
-  * update the network support to etherboot-4.6.4.
-  *
- -*/
-diff -uprN grub-0.97/stage1/Makefile.am grub/stage1/Makefile.am
---- grub-0.97/stage1/Makefile.am       2004-07-16 12:44:56.000000000 +0100
-+++ grub/stage1/Makefile.am    2007-11-05 01:29:46.000000000 +0000
-@@ -5,7 +5,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
- # We can't use builtins or standard includes.
- AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
--LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
-+stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
- noinst_PROGRAMS = stage1.exec
- stage1_exec_SOURCES = stage1.S stage1.h
-diff -uprN grub-0.97/stage1/Makefile.in grub/stage1/Makefile.in
---- grub-0.97/stage1/Makefile.in       2005-05-08 03:42:36.000000000 +0100
-+++ grub/stage1/Makefile.in    2007-11-05 01:29:46.000000000 +0000
-@@ -110,7 +110,7 @@ INSTALL_DATA = @INSTALL_DATA@
- INSTALL_PROGRAM = @INSTALL_PROGRAM@
- INSTALL_SCRIPT = @INSTALL_SCRIPT@
- INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
--LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
-+LDFLAGS = @LDFLAGS@
- LIBOBJS = @LIBOBJS@
- LIBS = @LIBS@
- LTLIBOBJS = @LTLIBOBJS@
-@@ -188,6 +188,7 @@ CLEANFILES = $(nodist_pkglib_DATA)
- # We can't use builtins or standard includes.
- AM_CCASFLAGS = $(STAGE1_CFLAGS) -fno-builtin -nostdinc
-+stage1_exec_LDFLAGS = -nostdlib -Wl,-N,-Ttext,7C00
- stage1_exec_SOURCES = stage1.S stage1.h
- SUFFIXES = .exec
- all: all-am
-diff -uprN grub-0.97/stage2/bios.c grub/stage2/bios.c
---- grub-0.97/stage2/bios.c    2004-03-27 16:34:04.000000000 +0000
-+++ grub/stage2/bios.c 2008-03-28 13:22:28.000000000 +0000
-@@ -47,7 +47,7 @@ extern int get_diskinfo_floppy (int driv
-    return the error number. Otherwise, return 0.  */
- int
- biosdisk (int read, int drive, struct geometry *geometry,
--        int sector, int nsec, int segment)
-+        unsigned int sector, int nsec, int segment)
- {
-   int err;
-   
-diff -uprN grub-0.97/stage2/boot.c grub/stage2/boot.c
---- grub-0.97/stage2/boot.c    2004-03-30 12:44:08.000000000 +0100
-+++ grub/stage2/boot.c 2005-09-28 22:47:55.000000000 +0100
-@@ -1,7 +1,7 @@
- /* boot.c - load and bootstrap a kernel */
- /*
-  *  GRUB  --  GRand Unified Bootloader
-- *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
-+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005  Free Software Foundation, Inc.
-  *
-  *  This program is free software; you can redistribute it and/or modify
-  *  it under the terms of the GNU General Public License as published by
-@@ -96,7 +96,7 @@ load_image (char *kernel, char *arg, ker
-   lh = (struct linux_kernel_header *) buffer;
-   
-   /* ELF loading supported if multiboot, FreeBSD and NetBSD.  */
--  if ((type == KERNEL_TYPE_MULTIBOOT
-+  if (((type == KERNEL_TYPE_MULTIBOOT && ! (flags & MULTIBOOT_AOUT_KLUDGE))
-        || pu.elf->e_ident[EI_OSABI] == ELFOSABI_FREEBSD
-        || grub_strcmp (pu.elf->e_ident + EI_BRAND, "FreeBSD") == 0
-        || suggested_type == KERNEL_TYPE_NETBSD)
-diff -uprN grub-0.97/stage2/builtins.c grub/stage2/builtins.c
---- grub-0.97/stage2/builtins.c        2005-02-15 21:58:23.000000000 +0000
-+++ grub/stage2/builtins.c     2006-03-21 20:51:58.000000000 +0000
-@@ -3830,15 +3830,15 @@ setup_func (char *arg, int flags)
-       {
-         char tmp[16];
-         grub_sprintf (tmp, ",%d", (partition >> 16) & 0xFF);
--        grub_strncat (device, tmp, 256);
-+        grub_strncat (device, tmp, sizeof (device));
-       }
-       if ((partition & 0x00FF00) != 0x00FF00)
-       {
-         char tmp[16];
-         grub_sprintf (tmp, ",%c", 'a' + ((partition >> 8) & 0xFF));
--        grub_strncat (device, tmp, 256);
-+        grub_strncat (device, tmp, sizeof (device));
-       }
--      grub_strncat (device, ")", 256);
-+      grub_strncat (device, ")", sizeof (device));
-     }
-   
-   int embed_stage1_5 (char *stage1_5, int drive, int partition)
-diff -uprN grub-0.97/stage2/disk_io.c grub/stage2/disk_io.c
---- grub-0.97/stage2/disk_io.c 2004-05-23 17:35:24.000000000 +0100
-+++ grub/stage2/disk_io.c      2008-03-28 13:22:28.000000000 +0000
-@@ -137,7 +137,7 @@ log2 (unsigned long word)
- }
- int
--rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
-+rawread (int drive, unsigned int sector, int byte_offset, int byte_len, char *buf)
- {
-   int slen, sectors_per_vtrack;
-   int sector_size_bits = log2 (buf_geom.sector_size);
-@@ -261,7 +261,7 @@ rawread (int drive, int sector, int byte
-        */
-       if (disk_read_func)
-       {
--        int sector_num = sector;
-+        unsigned int sector_num = sector;
-         int length = buf_geom.sector_size - byte_offset;
-         if (length > size)
-           length = size;
-@@ -291,7 +291,7 @@ rawread (int drive, int sector, int byte
- int
--devread (int sector, int byte_offset, int byte_len, char *buf)
-+devread (unsigned int sector, int byte_offset, int byte_len, char *buf)
- {
-   /*
-    *  Check partition boundaries
-@@ -330,7 +330,7 @@ devread (int sector, int byte_offset, in
- #ifndef STAGE1_5
- int
--rawwrite (int drive, int sector, char *buf)
-+rawwrite (int drive, unsigned int sector, char *buf)
- {
-   if (sector == 0)
-     {
-@@ -363,7 +363,7 @@ rawwrite (int drive, int sector, char *b
- }
- int
--devwrite (int sector, int sector_count, char *buf)
-+devwrite (unsigned int sector, int sector_count, char *buf)
- {
- #if defined(GRUB_UTIL) && defined(__linux__)
-   if (current_partition != 0xFFFFFF
-diff -uprN grub-0.97/stage2/fsys_ffs.c grub/stage2/fsys_ffs.c
---- grub-0.97/stage2/fsys_ffs.c        2003-07-09 12:45:52.000000000 +0100
-+++ grub/stage2/fsys_ffs.c     2001-11-12 06:57:29.000000000 +0000
-@@ -50,7 +50,7 @@
-  * the rights to redistribute these changes.
-  *
-  *    from: Mach, Revision 2.2  92/04/04  11:35:49  rpd
-- *    $Id: fsys_ffs.c,v 1.10 2001/11/12 06:57:29 okuji Exp $
-+ *    $Id: fsys_ffs.c 594 2001-11-12 06:57:29Z okuji $
-  */
- #ifdef FSYS_FFS
-diff -uprN grub-0.97/stage2/fsys_ufs2.c grub/stage2/fsys_ufs2.c
---- grub-0.97/stage2/fsys_ufs2.c       2004-06-19 13:17:52.000000000 +0100
-+++ grub/stage2/fsys_ufs2.c    2004-06-19 13:17:52.000000000 +0100
-@@ -51,7 +51,7 @@
-  * the rights to redistribute these changes.
-  *
-  *    from: Mach, Revision 2.2  92/04/04  11:35:49  rpd
-- *    $Id: fsys_ufs2.c,v 1.2 2004/06/19 12:17:52 okuji Exp $
-+ *    $Id: fsys_ufs2.c 841 2004-06-19 12:17:52Z okuji $
-  */
- #ifdef FSYS_UFS2
-diff -uprN grub-0.97/stage2/imgact_aout.h grub/stage2/imgact_aout.h
---- grub-0.97/stage2/imgact_aout.h     2003-07-09 12:45:53.000000000 +0100
-+++ grub/stage2/imgact_aout.h  1999-06-24 01:03:29.000000000 +0100
-@@ -32,7 +32,7 @@
-  * SUCH DAMAGE.
-  *
-  *    from: @(#)exec.h        8.1 (Berkeley) 6/11/93
-- *    $Id: imgact_aout.h,v 1.1 1999/06/24 00:03:22 okuji Exp $
-+ *    $Id: imgact_aout.h 98 1999-06-24 00:03:29Z okuji $
-  */
- /*
-  *  11/23/95 - Kludge to get "ntohl" null macro added.  -- ESB
-diff -uprN grub-0.97/stage2/iso9660.h grub/stage2/iso9660.h
---- grub-0.97/stage2/iso9660.h 2004-03-27 16:02:38.000000000 +0000
-+++ grub/stage2/iso9660.h      2007-02-22 23:40:25.000000000 +0000
-@@ -73,11 +73,11 @@ typedef    union {
- typedef       struct __iso_16bit {
-   u_int16_t l, b;
--} iso_16bit_t __attribute__ ((packed));
-+} iso_16bit_t;
- typedef       struct __iso_32bit {
-   u_int32_t l, b;
--} iso_32bit_t __attribute__ ((packed));
-+} iso_32bit_t;
- typedef u_int8_t              iso_date_t[7];
-diff -uprN grub-0.97/stage2/shared.h grub/stage2/shared.h
---- grub-0.97/stage2/shared.h  2004-06-19 17:40:09.000000000 +0100
-+++ grub/stage2/shared.h       2008-03-28 13:22:28.000000000 +0000
-@@ -499,7 +499,11 @@ struct vbe_mode
-   unsigned char linear_reserved_field_position;
-   unsigned long max_pixel_clock;
--  unsigned char reserved3[189];
-+  /* Reserved field to make structure to be 256 bytes long, VESA BIOS 
-+     Extension 3.0 Specification says to reserve 189 bytes here but 
-+     that doesn't make structure to be 256 bytes.  So additional one is 
-+     added here.  */
-+  unsigned char reserved3[189 + 1];
- } __attribute__ ((packed));
-@@ -807,7 +811,7 @@ int checkkey (void);
- /* Low-level disk I/O */
- int get_diskinfo (int drive, struct geometry *geometry);
- int biosdisk (int subfunc, int drive, struct geometry *geometry,
--            int sector, int nsec, int segment);
-+            unsigned int sector, int nsec, int segment);
- void stop_floppy (void);
- /* Command-line interface functions. */
-@@ -920,10 +924,10 @@ int gunzip_test_header (void);
- int gunzip_read (char *buf, int len);
- #endif /* NO_DECOMPRESSION */
--int rawread (int drive, int sector, int byte_offset, int byte_len, char *buf);
--int devread (int sector, int byte_offset, int byte_len, char *buf);
--int rawwrite (int drive, int sector, char *buf);
--int devwrite (int sector, int sector_len, char *buf);
-+int rawread (int drive, unsigned int sector, int byte_offset, int byte_len, char *buf);
-+int devread (unsigned int sector, int byte_offset, int byte_len, char *buf);
-+int rawwrite (int drive, unsigned int sector, char *buf);
-+int devwrite (unsigned int sector, int sector_len, char *buf);
- /* Parse a device string and initialize the global parameters. */
- char *set_device (char *device);
-diff -uprN grub-0.97/stage2/stage2.c grub/stage2/stage2.c
---- grub-0.97/stage2/stage2.c  2005-03-19 17:51:57.000000000 +0000
-+++ grub/stage2/stage2.c       2006-05-05 23:06:31.000000000 +0100
-@@ -651,7 +651,10 @@ restart:
-                 *(new_heap++) = 0;
-                 if (config_entries)
--                  run_menu (heap, NULL, new_num_entries, new_heap, 0);
-+                  {
-+                    current_entryno = first_entry + entryno;
-+                    run_menu (heap, NULL, new_num_entries, new_heap, 0);
-+                  }
-                 else
-                   {
-                     cls ();
-@@ -727,7 +730,8 @@ restart:
-       cur_entry = get_entry (config_entries, first_entry + entryno, 1);
-       /* Set CURRENT_ENTRYNO for the command "savedefault".  */
--      current_entryno = first_entry + entryno;
-+      if (config_entries)
-+      current_entryno = first_entry + entryno;
-       
-       if (run_script (cur_entry, heap))
-       {
-diff -uprN grub-0.97/stage2/tparm.c grub/stage2/tparm.c
---- grub-0.97/stage2/tparm.c   2003-07-09 12:45:53.000000000 +0100
-+++ grub/stage2/tparm.c        2002-11-29 20:39:24.000000000 +0000
-@@ -63,7 +63,7 @@ typedef char grub_bool;
- #define MAX_FORMAT_LEN 256
- #define max(a,b) ((a) > (b) ? (a) : (b))
--//MODULE_ID("$Id: tparm.c,v 1.1 2002/11/29 20:39:24 okuji Exp $")
-+//MODULE_ID("$Id: tparm.c 708 2002-11-29 20:39:24Z okuji $")
- /*
-  *    char *
-diff -uprN grub-0.97/stamp-h.in grub/stamp-h.in
---- grub-0.97/stamp-h.in       1970-01-01 01:00:00.000000000 +0100
-+++ grub/stamp-h.in    1999-09-13 14:32:31.000000000 +0100
-@@ -0,0 +1 @@
-+timestamp
-diff -uprN grub-0.97/THANKS grub/THANKS
---- grub-0.97/THANKS   2005-05-08 03:17:43.000000000 +0100
-+++ grub/THANKS        2006-03-21 20:51:58.000000000 +0000
-@@ -121,3 +121,4 @@ Vesa Jaaskelainen <jaaskela@tietomyrsky.
- Yedidyah Bar-David <didi@post.tau.ac.il>
- Yury V. Umanets <umka@namesys.com>
- Yuri Zaporogets <yuriz@ukr.net>
-+Vitaly Fertman <vitaly@namesys.com>
-diff -uprN grub-0.97/util/grub-install.in grub/util/grub-install.in
---- grub-0.97/util/grub-install.in     2004-07-24 19:57:31.000000000 +0100
-+++ grub/util/grub-install.in  2006-04-20 14:46:46.000000000 +0100
-@@ -112,8 +112,8 @@ convert () {
-       tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
-       tmp_part=`echo "$1" | sed "s%$tmp_disk%%"` ;;
-     freebsd* | kfreebsd*-gnu)
--      tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%r\1%' \
--                          | sed 's%r\{0,1\}\(da[0-9]*\).*$%r\1%'`
-+      tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%\1%' \
-+                          | sed 's%r\{0,1\}\(da[0-9]*\).*$%\1%'`
-       tmp_part=`echo "$1" \
-           | sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" \
-                   | sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%"`
-diff -uprN grub-0.97/util/mkbimage grub/util/mkbimage
---- grub-0.97/util/mkbimage    2004-07-24 19:57:31.000000000 +0100
-+++ grub/util/mkbimage 2007-02-22 16:01:03.000000000 +0000
-@@ -1,7 +1,7 @@
- #!/bin/sh
- # MaKe a Bootable IMAGE --- 1.44, 2.88 and El Torito no-emulation mode
- # C) 2001,2002,2003 Thierry Laronde <tlaronde@polynum.org>
--# C) 2001,2002,2003 Robert Millan <robertmh@gnu.org>
-+# C) 2001,2002,2003 Robert Millan <rmh@aybabtu.com>
- # This program is free software; you can redistribute it and/or modify
-@@ -19,7 +19,7 @@
- # program's maintainer or write to: The Free Software Foundation,
- # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
--# $Id: mkbimage,v 1.19 2004/07/21 14:43:04 robertmh Exp $
-+# $Id: mkbimage 1233 2007-02-22 16:01:03Z robertmh $
- # Global variables
- tarfile=
-@@ -58,7 +58,7 @@ stage2_os_name=
- # Name by which this script was invoked.
- program=`echo "$0" | sed -e 's/[^\/]*\///g'`
--version_number='$Revision: 1.19 $'
-+version_number='$Revision: 1233 $'
- usage="
- Usage: $program [-hVF] [-t TYPE] [-d DIRECTORY] [-s FS_TYPE] -f TAR_FILE
-@@ -94,15 +94,13 @@ Options:
-           display Version information and exit
- Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@polynum.org>. 
--Copyright (c) 2001,2002 Robert Millan <zeratul2@wanadoo.es>.
- GPLed."
- version="mkbimage $version_number
--Written by Thierry Laronde and Robert Millan.
-+Written by Thierry Laronde.
- Copyright (c) 2001,2002,2003 Thierry Laronde <tlaronde@polynum.org>.
--Copyright (c) 2001,2002,2003 Robert Millan <zeratul2@wanadoo.es>.
- This is free software under the GPL version 2 or later; see the source for 
- copying conditions.  There is NO warranty, not even for MERCHANTABILITY or 
diff --git a/stubdom/grub.patches/10graphics.diff b/stubdom/grub.patches/10graphics.diff
deleted file mode 100644 (file)
index 5ee2852..0000000
+++ /dev/null
@@ -1,2297 +0,0 @@
-diff -Naur grub-0.97.orig/configure.ac grub-0.97/configure.ac
---- grub-0.97.orig/configure.ac        2005-05-07 23:36:03.000000000 -0300
-+++ grub-0.97/configure.ac     2005-06-12 20:56:49.000000000 -0300
-@@ -595,6 +595,11 @@
-   [  --enable-diskless       enable diskless support])
- AM_CONDITIONAL(DISKLESS_SUPPORT, test "x$enable_diskless" = xyes)
-+dnl Graphical splashscreen support
-+AC_ARG_ENABLE(graphics,
-+  [  --disable-graphics      disable graphics terminal support])
-+AM_CONDITIONAL(GRAPHICS_SUPPORT, test "x$enable_graphics" != xno)
-+
- dnl Hercules terminal
- AC_ARG_ENABLE(hercules,
-   [  --disable-hercules      disable hercules terminal support])
-diff -Naur grub-0.97.orig/stage2/asm.S grub-0.97/stage2/asm.S
---- grub-0.97.orig/stage2/asm.S        2004-06-19 13:55:22.000000000 -0300
-+++ grub-0.97/stage2/asm.S     2005-06-13 14:05:31.000000000 -0300
-@@ -2216,7 +2216,304 @@
-       pop     %ebx
-       pop     %ebp
-       ret
--              
-+
-+
-+/* graphics mode functions */
-+#ifdef SUPPORT_GRAPHICS
-+VARIABLE(cursorX)
-+.word 0
-+VARIABLE(cursorY)
-+.word 0
-+VARIABLE(cursorCount)
-+.word 0
-+VARIABLE(cursorBuf)
-+.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-+
-+
-+/*
-+ * set_int1c_handler(void)
-+ */
-+ENTRY(set_int1c_handler)
-+      pushl   %edi
-+
-+      /* save the original int1c handler */
-+      movl    $0x70, %edi
-+      movw    (%edi), %ax
-+      movw    %ax, ABS(int1c_offset)
-+      movw    2(%edi), %ax
-+      movw    %ax, ABS(int1c_segment)
-+
-+      /* save the new int1c handler */
-+      movw    $ABS(int1c_handler), %ax
-+      movw    %ax, (%edi)
-+      xorw    %ax, %ax
-+      movw    %ax, 2(%edi)
-+
-+      popl    %edi
-+      ret
-+
-+
-+/*
-+ * unset_int1c_handler(void)
-+ */
-+ENTRY(unset_int1c_handler)
-+      pushl   %edi
-+
-+      /* check if int1c_handler is set */
-+      movl    $0x70, %edi
-+      movw    $ABS(int1c_handler), %ax
-+      cmpw    %ax, (%edi)
-+      jne     int1c_1
-+      xorw    %ax, %ax
-+      cmpw    %ax, 2(%edi)
-+      jne     int1c_1
-+
-+      /* restore the original */
-+      movw    ABS(int1c_offset), %ax
-+      movw    %ax, (%edi)
-+      movw    ABS(int1c_segment), %ax
-+      movw    %ax, 2(%edi)
-+
-+int1c_1:
-+      popl    %edi
-+      ret
-+
-+
-+/*
-+ * blinks graphics cursor
-+ */
-+      .code16
-+write_data:
-+      movw    $0, %ax
-+      movw    %ax, %ds
-+
-+      mov     $0xA000, %ax            /* video in es:di */
-+      mov     %ax, %es
-+      mov     $80, %ax
-+      movw    $ABS(cursorY), %si
-+      mov     %ds:(%si), %bx
-+      mul     %bx
-+      movw    $ABS(cursorX), %si
-+      mov     %ds:(%si), %bx
-+      shr     $3, %bx                 /* %bx /= 8 */
-+      add     %bx, %ax
-+      mov     %ax, %di
-+
-+      movw    $ABS(cursorBuf), %si    /* fontBuf in ds:si */
-+
-+      /* prepare for data moving */
-+      mov     $16, %dx                /* altura da fonte */
-+      mov     $80, %bx                /* bytes por linha */
-+
-+write_loop:
-+      movb    %ds:(%si), %al
-+      xorb    $0xff, %al
-+      movb    %al, %ds:(%si)          /* invert cursorBuf */
-+      movb    %al, %es:(%di)          /* write to video */
-+      add     %bx, %di
-+      inc     %si
-+      dec     %dx
-+      jg      write_loop
-+      ret
-+
-+int1c_handler:
-+      pusha
-+      mov     $0, %ax
-+      mov     %ax, %ds
-+      mov     $ABS(cursorCount), %si
-+      mov     %ds:(%si), %ax
-+      inc     %ax
-+      mov     %ax, %ds:(%si)
-+      cmp     $9, %ax
-+      jne     int1c_done
-+
-+      mov     $0, %ax
-+      mov     %ax, %ds:(%si)
-+      call    write_data
-+
-+int1c_done:
-+      popa
-+      iret
-+      /* call previous int1c handler */
-+      /* ljmp */
-+      .byte   0xea
-+int1c_offset:  .word   0
-+int1c_segment: .word   0
-+      .code32
-+
-+
-+/*
-+ * unsigned char set_videomode(unsigned char mode)
-+ * BIOS call "INT 10H Function 0h" to set video mode
-+ *    Call with       %ah = 0x0
-+ *                    %al = video mode
-+ *  Returns old videomode.
-+ */
-+ENTRY(set_videomode)
-+      pushl   %ebp
-+      movl    %esp,%ebp
-+      pushl   %ebx
-+      pushl   %ecx
-+
-+      movb    8(%ebp), %cl
-+
-+      call    EXT_C(prot_to_real)
-+      .code16
-+
-+      xorb    %al, %al
-+      movb    $0xf, %ah
-+      int     $0x10                   /* Get Current Video mode */
-+      movb    %al, %ch
-+      xorb    %ah, %ah
-+      movb    %cl, %al
-+      int     $0x10                   /* Set Video mode */
-+
-+      DATA32  call    EXT_C(real_to_prot)
-+      .code32
-+
-+      xorl    %eax, %eax
-+      movb    %ch, %al
-+
-+      popl    %ecx
-+      popl    %ebx
-+      popl    %ebp
-+      ret
-+
-+
-+/*
-+ * int get_videomode()
-+ * BIOS call "INT 10H Function 0Fh" to get current video mode
-+ *    Call with       %al = 0x0
-+ *                    %ah = 0xF
-+ *    Returns current videomode.
-+ */
-+ENTRY(get_videomode)
-+      pushl   %ebp
-+      movl    %esp,%ebp
-+      pushl   %ebx
-+      pushl   %ecx
-+
-+      call    EXT_C(prot_to_real)
-+      .code16
-+
-+      xorb    %al, %al
-+      movb    $0xF, %ah
-+      int     $0x10                   /* Get Current Video mode */
-+      movb    %al, %cl        /* For now we only want display mode */
-+
-+      DATA32  call    EXT_C(real_to_prot)
-+      .code32
-+
-+      xorl    %eax, %eax
-+      movb    %cl, %al
-+
-+      popl    %ecx
-+      popl    %ebx
-+      popl    %ebp
-+      ret
-+
-+
-+/*
-+ * unsigned char * graphics_get_font()
-+ * BIOS call "INT 10H Function 11h" to set font
-+ *      Call with       %ah = 0x11
-+ */
-+ENTRY(graphics_get_font)
-+      push    %ebp
-+      push    %ebx
-+      push    %ecx
-+      push    %edx
-+
-+      call    EXT_C(prot_to_real)
-+      .code16
-+
-+      movw    $0x1130, %ax
-+      movb    $6, %bh         /* font 8x16 */
-+      int     $0x10
-+      movw    %bp, %dx
-+      movw    %es, %cx
-+
-+      DATA32  call    EXT_C(real_to_prot)
-+      .code32
-+
-+      xorl    %eax, %eax
-+      movw    %cx, %ax
-+      shll    $4, %eax
-+      movw    %dx, %ax
-+
-+      pop     %edx
-+      pop     %ecx
-+      pop     %ebx
-+      pop     %ebp
-+      ret
-+
-+
-+/*
-+ * graphics_set_palette(index, red, green, blue)
-+ * BIOS call "INT 10H Function 10h" to set individual dac register
-+ *    Call with       %ah = 0x10
-+ *                    %bx = register number
-+ *                    %ch = new value for green (0-63)
-+ *                    %cl = new value for blue (0-63)
-+ *                    %dh = new value for red (0-63)
-+ */
-+
-+ENTRY(graphics_set_palette)
-+      push    %ebp
-+      push    %eax
-+      push    %ebx
-+      push    %ecx
-+      push    %edx
-+
-+      movw    $0x3c8, %bx             /* address write mode register */
-+
-+      /* wait vertical retrace */
-+      movw    $0x3da, %dx
-+l1b:
-+      inb     %dx, %al        /* wait vertical active display */
-+      test    $8, %al
-+      jnz     l1b
-+
-+l2b:
-+      inb     %dx, %al        /* wait vertical retrace */
-+      test    $8, %al
-+      jnz     l2b
-+
-+      mov     %bx, %dx
-+      movb    0x18(%esp), %al         /* index */
-+      outb    %al, %dx
-+      inc     %dx
-+
-+      movb    0x1c(%esp), %al         /* red */
-+      outb    %al, %dx
-+
-+      movb    0x20(%esp), %al         /* green */
-+      outb    %al, %dx
-+
-+      movb    0x24(%esp), %al         /* blue */
-+      outb    %al, %dx
-+
-+      movw    0x18(%esp), %bx
-+
-+      call    EXT_C(prot_to_real)
-+      .code16
-+
-+      movb    %bl, %bh
-+      movw    $0x1000, %ax
-+      int     $0x10
-+
-+      DATA32  call    EXT_C(real_to_prot)
-+      .code32
-+
-+      pop     %edx
-+      pop     %ecx
-+      pop     %ebx
-+      pop     %eax
-+      pop     %ebp
-+      ret
-+#endif /* SUPPORT_GRAPHICS */
-+
-+
- /*
-  * getrtsecs()
-  *    if a seconds value can be read, read it and return it (BCD),
-diff -Naur grub-0.97.orig/stage2/builtins.c grub-0.97/stage2/builtins.c
---- grub-0.97.orig/stage2/builtins.c   2005-02-15 19:58:23.000000000 -0200
-+++ grub-0.97/stage2/builtins.c        2005-06-13 18:44:03.000000000 -0300
-@@ -28,6 +28,10 @@
- #include <filesys.h>
- #include <term.h>
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
- #ifdef SUPPORT_NETBOOT
- # define GRUB 1
- # include <etherboot.h>
-@@ -237,12 +241,22 @@
- static int
- boot_func (char *arg, int flags)
- {
-+  struct term_entry *prev_term = current_term;
-   /* Clear the int15 handler if we can boot the kernel successfully.
-      This assumes that the boot code never fails only if KERNEL_TYPE is
-      not KERNEL_TYPE_NONE. Is this assumption is bad?  */
-   if (kernel_type != KERNEL_TYPE_NONE)
-     unset_int15_handler ();
-+  /* if our terminal needed initialization, we should shut it down
-+   * before booting the kernel, but we want to save what it was so
-+   * we can come back if needed */
-+  if (current_term->shutdown) 
-+    {
-+      current_term->shutdown();
-+      current_term = term_table; /* assumption: console is first */
-+    }
-+
- #ifdef SUPPORT_NETBOOT
-   /* Shut down the networking.  */
-   cleanup_net ();
-@@ -306,6 +320,13 @@
-       return 1;
-     }
-+  /* if we get back here, we should go back to what our term was before */
-+  current_term = prev_term;
-+  if (current_term->startup)
-+      /* if our terminal fails to initialize, fall back to console since
-+       * it should always work */
-+      if (current_term->startup() == 0)
-+          current_term = term_table; /* we know that console is first */
-   return 0;
- }
-@@ -852,6 +873,251 @@
- };
- #endif /* SUPPORT_NETBOOT */
-+#ifdef SUPPORT_GRAPHICS
-+\f
-+static int splashimage_func(char *arg, int flags) {
-+  int i;
-+    
-+  /* filename can only be 256 characters due to our buffer size */
-+  if (grub_strlen(arg) > 256) {
-+    grub_printf("Splash image filename too large\n");
-+    grub_printf("Press any key to continue...");
-+    getkey();
-+    return 1;
-+  }
-+
-+  /* get rid of TERM_NEED_INIT from the graphics terminal. */
-+  for (i = 0; term_table[i].name; i++) {
-+    if (grub_strcmp (term_table[i].name, "graphics") == 0) {
-+      term_table[i].flags &= ~TERM_NEED_INIT;
-+      break;
-+    }
-+  }
-+
-+  graphics_set_splash(arg);
-+
-+  if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+    graphics_end();
-+    if (graphics_init() == 0) {
-+      /* Fallback to default term */
-+      current_term = term_table;
-+      max_lines = current_term->max_lines;
-+      if (current_term->cls)
-+        current_term->cls();
-+      grub_printf("Failed to set splash image and/or graphics mode\n");
-+      return 1;
-+    }
-+    graphics_cls();
-+  }
-+
-+  if (flags == BUILTIN_MENU)
-+    current_term = term_table + i;
-+
-+  return 0;
-+}
-+
-+static struct builtin builtin_splashimage =
-+{
-+  "splashimage",
-+  splashimage_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "splashimage FILE",
-+  "Load FILE as the background image when in graphics mode."
-+};
-+
-+\f
-+/* shade */
-+static int
-+shade_func(char *arg, int flags)
-+{
-+    int new_shade;
-+
-+    if (!arg || safe_parse_maxint(&arg, &new_shade) == 0)
-+       return (1);
-+
-+    if (shade != new_shade) {
-+       shade = new_shade;
-+       if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+           graphics_end();
-+           graphics_init();
-+           graphics_cls();
-+       }
-+    }
-+
-+    return 0;
-+}
-+
-+static struct builtin builtin_shade =
-+{
-+  "shade",
-+  shade_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "shade INTEGER",
-+  "If set to 0, disables the use of shaded text, else enables it."
-+};
-+
-+\f
-+/* foreground */
-+static int
-+foreground_func(char *arg, int flags)
-+{
-+    if (grub_strlen(arg) == 6) {
-+      int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+      int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+      int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+      foreground = (r << 16) | (g << 8) | b;
-+      if (graphics_inited)
-+          graphics_set_palette(15, r, g, b);
-+
-+      return 0;
-+    }
-+
-+    return 1;
-+}
-+
-+static struct builtin builtin_foreground =
-+{
-+  "foreground",
-+  foreground_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "foreground RRGGBB",
-+  "Sets the foreground color when in graphics mode."
-+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+\f
-+/* background */
-+static int
-+background_func(char *arg, int flags)
-+{
-+    if (grub_strlen(arg) == 6) {
-+      int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+      int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+      int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+      background = (r << 16) | (g << 8) | b;
-+      if (graphics_inited)
-+          graphics_set_palette(0, r, g, b);
-+      return 0;
-+    }
-+
-+    return 1;
-+}
-+
-+static struct builtin builtin_background =
-+{
-+  "background",
-+  background_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "background RRGGBB",
-+  "Sets the background color when in graphics mode."
-+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+\f
-+/* border */
-+static int
-+border_func(char *arg, int flags)
-+{
-+    if (grub_strlen(arg) == 6) {
-+       int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
-+       int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
-+       int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
-+
-+       window_border = (r << 16) | (g << 8) | b;
-+       if (graphics_inited)
-+           graphics_set_palette(0x11, r, g, b);
-+
-+       return 0;
-+    }
-+
-+    return 1;
-+}
-+
-+static struct builtin builtin_border =
-+{
-+  "border",
-+  border_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "border RRGGBB",
-+  "Sets the border video color when in graphics mode."
-+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
-+};
-+
-+\f
-+/* viewport */
-+static int
-+viewport_func (char *arg, int flags)
-+{
-+    int i;
-+    int x0 = 0, y0 = 0, x1 = 80, y1 = 30;
-+    int *pos[4] = { &x0, &y0, &x1, &y1 };
-+
-+    if (!arg)
-+       return (1);
-+    for (i = 0; i < 4; i++) {
-+       if (!*arg)
-+           return (1);
-+    while (*arg && (*arg == ' ' || *arg == '\t'))
-+           ++arg;
-+       if (!safe_parse_maxint(&arg, pos[i]))
-+           return (1);
-+       while (*arg && (*arg != ' ' && *arg != '\t'))
-+           ++arg;
-+    }
-+
-+    /* minimum size is 65 colums and 16 rows */
-+    if (x0 > x1 - 66 || y0 > y1 - 16 || x0 < 0 || y0 < 0 || x1 > 80 || y1 > 30)
-+       return 1;
-+
-+    view_x0 = x0;
-+    view_y0 = y0;
-+    view_x1 = x1;
-+    view_y1 = y1;
-+
-+    if (flags == BUILTIN_CMDLINE && graphics_inited) {
-+       graphics_end();
-+       graphics_init();
-+       graphics_cls();
-+    }
-+
-+    return 0;
-+}
-+
-+static struct builtin builtin_viewport =
-+{
-+  "viewport",
-+  viewport_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
-+  "viewport x0 y0 x1 y1",
-+  "Changes grub internals to output text in the window defined by"
-+  " four parameters. The x and y parameters are 0 based. This option"
-+  " only works with the graphics interface."
-+};
-+
-+#endif /* SUPPORT_GRAPHICS */
-+
-+\f
-+/* clear */
-+static int 
-+clear_func() 
-+{
-+  if (current_term->cls)
-+    current_term->cls();
-+
-+  return 0;
-+}
-+
-+static struct builtin builtin_clear =
-+{
-+  "clear",
-+  clear_func,
-+  BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
-+  "clear",
-+  "Clear the screen"
-+};
-+
\f
- /* displayapm */
- static int
-@@ -1454,14 +1720,20 @@
\f
- /* help */
--#define MAX_SHORT_DOC_LEN     39
--#define MAX_LONG_DOC_LEN      66
--
- static int
- help_func (char *arg, int flags)
- {
--  int all = 0;
--  
-+  int all = 0, max_short_doc_len, max_long_doc_len;
-+  max_short_doc_len = 39;
-+  max_long_doc_len = 66;
-+#ifdef SUPPORT_GRAPHICS
-+  if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1) == 0)
-+    {
-+      max_short_doc_len = (view_x1 - view_x0 + 1) / 2 - 1;
-+      max_long_doc_len = (view_x1 - view_x0) - 14;
-+    }
-+#endif
-+
-   if (grub_memcmp (arg, "--all", sizeof ("--all") - 1) == 0)
-     {
-       all = 1;
-@@ -1491,13 +1763,13 @@
-         len = grub_strlen ((*builtin)->short_doc);
-         /* If the length of SHORT_DOC is too long, truncate it.  */
--        if (len > MAX_SHORT_DOC_LEN - 1)
--          len = MAX_SHORT_DOC_LEN - 1;
-+        if (len > max_short_doc_len - 1)
-+          len = max_short_doc_len - 1;
-         for (i = 0; i < len; i++)
-           grub_putchar ((*builtin)->short_doc[i]);
--        for (; i < MAX_SHORT_DOC_LEN; i++)
-+        for (; i < max_short_doc_len; i++)
-           grub_putchar (' ');
-         if (! left)
-@@ -1546,10 +1818,10 @@
-                     int i;
-                     /* If LEN is too long, fold DOC.  */
--                    if (len > MAX_LONG_DOC_LEN)
-+                    if (len > max_long_doc_len)
-                       {
-                         /* Fold this line at the position of a space.  */
--                        for (len = MAX_LONG_DOC_LEN; len > 0; len--)
-+                        for (len = max_long_doc_len; len > 0; len--)
-                           if (doc[len - 1] == ' ')
-                             break;
-                       }
-@@ -4085,7 +4357,7 @@
- };
\f
--#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES)
-+#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) || defined(SUPPORT_GRAPHICS)
- /* terminal */
- static int
- terminal_func (char *arg, int flags)
-@@ -4244,17 +4516,29 @@
-  end:
-   current_term = term_table + default_term;
-   current_term->flags = term_flags;
--  
-+
-   if (lines)
-     max_lines = lines;
-   else
--    /* 24 would be a good default value.  */
--    max_lines = 24;
--  
-+    max_lines = current_term->max_lines;
-+
-   /* If the interface is currently the command-line,
-      restart it to repaint the screen.  */
--  if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
-+  if ((current_term != prev_term) && (flags & BUILTIN_CMDLINE)){
-+    if (prev_term->shutdown)
-+      prev_term->shutdown();
-+    if (current_term->startup) {
-+      /* If startup fails, return to previous term */
-+      if (current_term->startup() == 0) {
-+        current_term = prev_term;
-+        max_lines = current_term->max_lines;
-+        if (current_term->cls) {
-+          current_term->cls();
-+        }
-+      }
-+    }
-     grub_longjmp (restart_cmdline_env, 0);
-+  }
-   
-   return 0;
- }
-@@ -4264,7 +4548,7 @@
-   "terminal",
-   terminal_func,
-   BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
--  "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial] [hercules]",
-+  "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial] [hercules] [graphics]",
-   "Select a terminal. When multiple terminals are specified, wait until"
-   " you push any key to continue. If both console and serial are specified,"
-   " the terminal to which you input a key first will be selected. If no"
-@@ -4276,7 +4560,7 @@
-   " seconds. The option --lines specifies the maximum number of lines."
-   " The option --silent is used to suppress messages."
- };
--#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
-+#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES || SUPPORT_GRAPHICS */
\f
- #ifdef SUPPORT_SERIAL
-@@ -4795,13 +5079,20 @@
- /* The table of builtin commands. Sorted in dictionary order.  */
- struct builtin *builtin_table[] =
- {
-+#ifdef SUPPORT_GRAPHICS
-+  &builtin_background,
-+#endif
-   &builtin_blocklist,
-   &builtin_boot,
- #ifdef SUPPORT_NETBOOT
-   &builtin_bootp,
- #endif /* SUPPORT_NETBOOT */
-+#ifdef SUPPORT_GRAPHICS
-+  &builtin_border,
-+#endif
-   &builtin_cat,
-   &builtin_chainloader,
-+  &builtin_clear,
-   &builtin_cmp,
-   &builtin_color,
-   &builtin_configfile,
-@@ -4821,6 +5112,9 @@
-   &builtin_embed,
-   &builtin_fallback,
-   &builtin_find,
-+#ifdef SUPPORT_GRAPHICS
-+  &builtin_foreground,
-+#endif
-   &builtin_fstest,
-   &builtin_geometry,
-   &builtin_halt,
-@@ -4864,9 +5158,13 @@
- #endif /* SUPPORT_SERIAL */
-   &builtin_setkey,
-   &builtin_setup,
--#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES)
-+#ifdef SUPPORT_GRAPHICS
-+  &builtin_shade,
-+  &builtin_splashimage,
-+#endif /* SUPPORT_GRAPHICS */
-+#if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) || defined(SUPPORT_GRAPHICS)
-   &builtin_terminal,
--#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
-+#endif /* SUPPORT_SERIAL || SUPPORT_HERCULES || SUPPORT_GRAPHICS */
- #ifdef SUPPORT_SERIAL
-   &builtin_terminfo,
- #endif /* SUPPORT_SERIAL */
-@@ -4880,5 +5178,8 @@
-   &builtin_unhide,
-   &builtin_uppermem,
-   &builtin_vbeprobe,
-+#ifdef SUPPORT_GRAPHICS
-+  &builtin_viewport,
-+#endif
-   0
- };
-diff -Naur grub-0.97.orig/stage2/char_io.c grub-0.97/stage2/char_io.c
---- grub-0.97.orig/stage2/char_io.c    2005-02-01 18:51:23.000000000 -0200
-+++ grub-0.97/stage2/char_io.c 2005-06-12 20:56:49.000000000 -0300
-@@ -29,12 +29,17 @@
- # include <serial.h>
- #endif
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
- #ifndef STAGE1_5
- struct term_entry term_table[] =
-   {
-     {
-       "console",
-       0,
-+      24,
-       console_putchar,
-       console_checkkey,
-       console_getkey,
-@@ -43,13 +48,16 @@
-       console_cls,
-       console_setcolorstate,
-       console_setcolor,
--      console_setcursor
-+      console_setcursor,
-+      0, 
-+      0
-     },
- #ifdef SUPPORT_SERIAL
-     {
-       "serial",
-       /* A serial device must be initialized.  */
-       TERM_NEED_INIT,
-+      24,
-       serial_putchar,
-       serial_checkkey,
-       serial_getkey,
-@@ -58,6 +66,8 @@
-       serial_cls,
-       serial_setcolorstate,
-       0,
-+      0,
-+      0, 
-       0
-     },
- #endif /* SUPPORT_SERIAL */
-@@ -65,6 +75,7 @@
-     {
-       "hercules",
-       0,
-+      24,
-       hercules_putchar,
-       console_checkkey,
-       console_getkey,
-@@ -73,11 +84,30 @@
-       hercules_cls,
-       hercules_setcolorstate,
-       hercules_setcolor,
--      hercules_setcursor
-+      hercules_setcursor,
-+      0,
-+      0
-     },      
- #endif /* SUPPORT_HERCULES */
-+#ifdef SUPPORT_GRAPHICS
-+    { "graphics",
-+      TERM_NEED_INIT, /* flags */
-+      30, /* number of lines */
-+      graphics_putchar, /* putchar */
-+      console_checkkey, /* checkkey */
-+      console_getkey, /* getkey */
-+      graphics_getxy, /* getxy */
-+      graphics_gotoxy, /* gotoxy */
-+      graphics_cls, /* cls */
-+      graphics_setcolorstate, /* setcolorstate */
-+      graphics_setcolor, /* setcolor */
-+      graphics_setcursor, /* nocursor */
-+      graphics_init, /* initialize */
-+      graphics_end /* shutdown */
-+    },
-+#endif /* SUPPORT_GRAPHICS */
-     /* This must be the last entry.  */
--    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-+    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-   };
- /* This must be console.  */
-@@ -305,9 +335,10 @@
-   /* XXX: These should be defined in shared.h, but I leave these here,
-      until this code is freezed.  */
--#define CMDLINE_WIDTH 78
- #define CMDLINE_MARGIN        10
--  
-+
-+  /* command-line limits */
-+  int cmdline_width = 78, col_start = 0;
-   int xpos, lpos, c, section;
-   /* The length of PROMPT.  */
-   int plen;
-@@ -338,7 +369,7 @@
-       
-       /* If the cursor is in the first section, display the first section
-        instead of the second.  */
--      if (section == 1 && plen + lpos < CMDLINE_WIDTH)
-+      if (section == 1 && plen + lpos < cmdline_width)
-       cl_refresh (1, 0);
-       else if (xpos - count < 1)
-       cl_refresh (1, 0);
-@@ -354,7 +385,7 @@
-               grub_putchar ('\b');
-           }
-         else
--          gotoxy (xpos, getxy () & 0xFF);
-+          gotoxy (xpos + col_start, getxy () & 0xFF);
-       }
-     }
-@@ -364,7 +395,7 @@
-       lpos += count;
-       /* If the cursor goes outside, scroll the screen to the right.  */
--      if (xpos + count >= CMDLINE_WIDTH)
-+      if (xpos + count >= cmdline_width)
-       cl_refresh (1, 0);
-       else
-       {
-@@ -383,7 +414,7 @@
-               }
-           }
-         else
--          gotoxy (xpos, getxy () & 0xFF);
-+          gotoxy (xpos + col_start, getxy () & 0xFF);
-       }
-     }
-@@ -398,14 +429,14 @@
-       if (full)
-       {
-         /* Recompute the section number.  */
--        if (lpos + plen < CMDLINE_WIDTH)
-+        if (lpos + plen < cmdline_width)
-           section = 0;
-         else
--          section = ((lpos + plen - CMDLINE_WIDTH)
--                     / (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN) + 1);
-+          section = ((lpos + plen - cmdline_width)
-+                     / (cmdline_width - 1 - CMDLINE_MARGIN) + 1);
-         /* From the start to the end.  */
--        len = CMDLINE_WIDTH;
-+        len = cmdline_width;
-         pos = 0;
-         grub_putchar ('\r');
-@@ -445,8 +476,8 @@
-         if (! full)
-           offset = xpos - 1;
-         
--        start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
--                 + CMDLINE_WIDTH - plen - CMDLINE_MARGIN);
-+        start = ((section - 1) * (cmdline_width - 1 - CMDLINE_MARGIN)
-+                 + cmdline_width - plen - CMDLINE_MARGIN);
-         xpos = lpos + 1 - start;
-         start += offset;
-       }
-@@ -471,7 +502,7 @@
-       
-       /* If the cursor is at the last position, put `>' or a space,
-        depending on if there are more characters in BUF.  */
--      if (pos == CMDLINE_WIDTH)
-+      if (pos == cmdline_width)
-       {
-         if (start + len < llen)
-           grub_putchar ('>');
-@@ -488,7 +519,7 @@
-           grub_putchar ('\b');
-       }
-       else
--      gotoxy (xpos, getxy () & 0xFF);
-+      gotoxy (xpos + col_start, getxy () & 0xFF);
-     }
-   /* Initialize the command-line.  */
-@@ -518,10 +549,10 @@
-         
-         llen += l;
-         lpos += l;
--        if (xpos + l >= CMDLINE_WIDTH)
-+        if (xpos + l >= cmdline_width)
-           cl_refresh (1, 0);
--        else if (xpos + l + llen - lpos > CMDLINE_WIDTH)
--          cl_refresh (0, CMDLINE_WIDTH - xpos);
-+        else if (xpos + l + llen - lpos > cmdline_width)
-+          cl_refresh (0, cmdline_width - xpos);
-         else
-           cl_refresh (0, l + llen - lpos);
-       }
-@@ -533,12 +564,22 @@
-       grub_memmove (buf + lpos, buf + lpos + count, llen - count + 1);
-       llen -= count;
-       
--      if (xpos + llen + count - lpos > CMDLINE_WIDTH)
--      cl_refresh (0, CMDLINE_WIDTH - xpos);
-+      if (xpos + llen + count - lpos > cmdline_width)
-+      cl_refresh (0, cmdline_width - xpos);
-       else
-       cl_refresh (0, llen + count - lpos);
-     }
-+  max_lines = current_term->max_lines;
-+#ifdef SUPPORT_GRAPHICS
-+  if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1) == 0)
-+    {
-+      cmdline_width = (view_x1 - view_x0) - 2;
-+      col_start = view_x0;
-+      max_lines = view_y1 - view_y0;
-+    }
-+#endif
-+
-   plen = grub_strlen (prompt);
-   llen = grub_strlen (cmdline);
-@@ -1006,6 +1047,48 @@
- }
- #endif /* ! STAGE1_5 */
-+#ifndef STAGE1_5
-+/* Internal pager.  */
-+int
-+do_more (void)
-+{
-+  if (count_lines >= 0)
-+    {
-+      count_lines++;
-+      if (count_lines >= max_lines - 2)
-+        {
-+          int tmp;
-+
-+          /* It's important to disable the feature temporarily, because
-+             the following grub_printf call will print newlines.  */
-+          count_lines = -1;
-+
-+          grub_printf("\n");
-+          if (current_term->setcolorstate)
-+            current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
-+
-+          grub_printf ("[Hit return to continue]");
-+
-+          if (current_term->setcolorstate)
-+            current_term->setcolorstate (COLOR_STATE_NORMAL);
-+
-+
-+          do
-+            {
-+              tmp = ASCII_CHAR (getkey ());
-+            }
-+          while (tmp != '\n' && tmp != '\r');
-+          grub_printf ("\r                        \r");
-+
-+          /* Restart to count lines.  */
-+          count_lines = 0;
-+          return 1;
-+        }
-+    }
-+  return 0;
-+}
-+#endif
-+
- /* Display an ASCII character.  */
- void
- grub_putchar (int c)
-@@ -1034,38 +1117,11 @@
-   if (c == '\n')
-     {
-+      int flag;
-       /* Internal `more'-like feature.  */
--      if (count_lines >= 0)
--      {
--        count_lines++;
--        if (count_lines >= max_lines - 2)
--          {
--            int tmp;
--            
--            /* It's important to disable the feature temporarily, because
--               the following grub_printf call will print newlines.  */
--            count_lines = -1;
--
--            if (current_term->setcolorstate)
--              current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
--            
--            grub_printf ("\n[Hit return to continue]");
--
--            if (current_term->setcolorstate)
--              current_term->setcolorstate (COLOR_STATE_NORMAL);
--            
--            do
--              {
--                tmp = ASCII_CHAR (getkey ());
--              }
--            while (tmp != '\n' && tmp != '\r');
--            grub_printf ("\r                        \r");
--            
--            /* Restart to count lines.  */
--            count_lines = 0;
--            return;
--          }
--      }
-+      flag = do_more ();
-+      if (flag)
-+        return;
-     }
-   current_term->putchar (c);
-@@ -1090,7 +1146,7 @@
- cls (void)
- {
-   /* If the terminal is dumb, there is no way to clean the terminal.  */
--  if (current_term->flags & TERM_DUMB)
-+  if (current_term->flags & TERM_DUMB) 
-     grub_putchar ('\n');
-   else
-     current_term->cls ();
-@@ -1217,6 +1273,16 @@
-   return ! errnum;
- }
-+void
-+grub_memcpy(void *dest, const void *src, int len)
-+{
-+  int i;
-+  register char *d = (char*)dest, *s = (char*)src;
-+
-+  for (i = 0; i < len; i++)
-+    d[i] = s[i];
-+}
-+
- void *
- grub_memmove (void *to, const void *from, int len)
- {
-diff -Naur grub-0.97.orig/stage2/cmdline.c grub-0.97/stage2/cmdline.c
---- grub-0.97.orig/stage2/cmdline.c    2004-08-16 20:23:01.000000000 -0300
-+++ grub-0.97/stage2/cmdline.c 2005-06-12 20:56:49.000000000 -0300
-@@ -50,10 +50,11 @@
- void
- print_cmdline_message (int forever)
- {
--  printf (" [ Minimal BASH-like line editing is supported.  For the first word, TAB\n"
--        "   lists possible command completions.  Anywhere else TAB lists the possible\n"
--        "   completions of a device/filename.%s ]\n",
--        (forever ? "" : "  ESC at any time exits."));
-+  grub_printf("       [ Minimal BASH-like line editing is supported.   For\n"
-+              "         the   first   word,  TAB  lists  possible  command\n"
-+              "         completions.  Anywhere else TAB lists the possible\n"
-+              "         completions of a device/filename.%s ]\n",
-+              (forever ? "" : "  ESC at any time\n         exits."));
- }
- /* Find the builtin whose command name is COMMAND and return the
-diff -Naur grub-0.97.orig/stage2/graphics.c grub-0.97/stage2/graphics.c
---- grub-0.97.orig/stage2/graphics.c   1969-12-31 21:00:00.000000000 -0300
-+++ grub-0.97/stage2/graphics.c        2005-06-13 19:13:31.000000000 -0300
-@@ -0,0 +1,584 @@
-+/*
-+ * graphics.c - graphics mode support for GRUB
-+ * Implemented as a terminal type by Jeremy Katz <katzj@redhat.com> based
-+ * on a patch by Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
-+ * Options and enhancements made by Herton Ronaldo Krzesinski
-+ * <herton@mandriva.com>
-+ *
-+ *  GRUB  --  GRand Unified Bootloader
-+ *  Copyright (C) 2001,2002  Red Hat, Inc.
-+ *  Portions copyright (C) 2000  Conectiva, Inc.
-+ *
-+ *  This program is free software; you can redistribute it and/or modify
-+ *  it under the terms of the GNU General Public License as published by
-+ *  the Free Software Foundation; either version 2 of the License, or
-+ *  (at your option) any later version.
-+ *
-+ *  This program is distributed in the hope that it will be useful,
-+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ *  GNU General Public License for more details.
-+ *
-+ *  You should have received a copy of the GNU General Public License
-+ *  along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+#ifdef SUPPORT_GRAPHICS
-+
-+#include <term.h>
-+#include <shared.h>
-+#include <graphics.h>
-+
-+int saved_videomode;
-+unsigned char *font8x16;
-+
-+int graphics_inited = 0;
-+static char splashimage[256];
-+
-+int shade = 1, no_cursor = 0;
-+
-+#define VSHADOW VSHADOW1
-+unsigned char VSHADOW1[38400];
-+unsigned char VSHADOW2[38400];
-+unsigned char VSHADOW4[38400];
-+unsigned char VSHADOW8[38400];
-+
-+/* define the default viewable area */
-+int view_x0 = 0;
-+int view_y0 = 0;
-+int view_x1 = 80;
-+int view_y1 = 30;
-+
-+/* text buffer has to be kept around so that we can write things as we
-+ * scroll and the like */
-+unsigned short text[80 * 30];
-+
-+/* graphics options */
-+int foreground = (63 << 16) | (63 << 8) | (63), background = 0, window_border = 0;
-+
-+/* current position */
-+static int fontx = 0;
-+static int fonty = 0;
-+
-+/* global state so that we don't try to recursively scroll or cursor */
-+static int no_scroll = 0;
-+
-+/* color state */
-+static int graphics_standard_color = A_NORMAL;
-+static int graphics_normal_color = A_NORMAL;
-+static int graphics_highlight_color = A_REVERSE;
-+static int graphics_current_color = A_NORMAL;
-+static color_state graphics_color_state = COLOR_STATE_STANDARD;
-+
-+static inline void outb(unsigned short port, unsigned char val)
-+{
-+    __asm __volatile ("outb %0,%1"::"a" (val), "d" (port));
-+}
-+
-+static void MapMask(int value) {
-+    outb(0x3c4, 2);
-+    outb(0x3c5, value);
-+}
-+
-+/* bit mask register */
-+static void BitMask(int value) {
-+    outb(0x3ce, 8);
-+    outb(0x3cf, value);
-+}
-+
-+/* move the graphics cursor location to col, row */
-+static void graphics_setxy(int col, int row) {
-+    if (col >= view_x0 && col < view_x1) {
-+        fontx = col;
-+        cursorX = col << 3;
-+    }
-+    if (row >= view_y0 && row < view_y1) {
-+        fonty = row;
-+        cursorY = row << 4;
-+    }
-+}
-+
-+/* scroll the screen */
-+static void graphics_scroll() {
-+    int i, j, k;
-+
-+    /* we don't want to scroll recursively... that would be bad */
-+    if (no_scroll)
-+        return;
-+    no_scroll = 1;
-+
-+    /* disable pager temporarily */
-+    k = count_lines;
-+    count_lines = -1;
-+    
-+    /* move everything up a line */
-+    for (j = view_y0 + 1; j < view_y1; j++) {
-+        graphics_gotoxy(view_x0, j - 1);
-+        for (i = view_x0; i < view_x1; i++) {
-+            graphics_putchar(text[j * 80 + i]);
-+        }
-+    }
-+
-+    /* last line should be blank */
-+    graphics_gotoxy(view_x0, view_y1 - 1);
-+    for (i = view_x0; i < view_x1; i++)
-+        graphics_putchar(' ');
-+    graphics_setxy(view_x0, view_y1 - 1);
-+
-+    count_lines = k;
-+
-+    no_scroll = 0;
-+}
-+
-+/* Set the splash image */
-+void graphics_set_splash(char *splashfile) {
-+    grub_strcpy(splashimage, splashfile);
-+}
-+
-+/* Get the current splash image */
-+char *graphics_get_splash(void) {
-+    return splashimage;
-+}
-+
-+/* 
-+ * Initialize a vga16 graphics display with the palette based off of
-+ * the image in splashimage.  If the image doesn't exist, leave graphics
-+ * mode. The mode initiated is 12h. From "Ralf Brown's Interrupt List":
-+ *      text/ text pixel   pixel   colors disply scrn  system
-+ *      grph resol  box  resolution       pages  addr
-+ * 12h   G   80x30  8x16  640x480  16/256K  .    A000  VGA,ATI VIP
-+ *       G   80x30  8x16  640x480  16/64    .    A000  ATI EGA Wonder
-+ *       G     .     .    640x480  16       .      .   UltraVision+256K EGA
-+ */
-+int graphics_init()
-+{
-+    if (!graphics_inited) {
-+        saved_videomode = set_videomode(0x12);
-+        if (get_videomode() != 0x12) {
-+            set_videomode(saved_videomode);
-+            return 0;
-+        }
-+        graphics_inited = 1;
-+    }
-+    else
-+        return 1;
-+
-+    font8x16 = (unsigned char*)graphics_get_font();
-+
-+    /* make sure that the highlight color is set correctly */
-+    graphics_highlight_color = ((graphics_normal_color >> 4) | 
-+                                ((graphics_normal_color & 0xf) << 4));
-+
-+    graphics_cls();
-+
-+    if (!read_image(splashimage)) {
-+        grub_printf("Failed to read splash image (%s)\n", splashimage);
-+        grub_printf("Press any key to continue...");
-+        getkey();
-+        set_videomode(saved_videomode);
-+        graphics_inited = 0;
-+        return 0;
-+    }
-+
-+    set_int1c_handler();
-+
-+    return 1;
-+}
-+
-+/* Leave graphics mode */
-+void graphics_end(void)
-+{
-+    if (graphics_inited) {
-+        unset_int1c_handler();
-+        set_videomode(saved_videomode);
-+        graphics_inited = 0;
-+        no_cursor = 0;
-+    }
-+}
-+
-+/* Print ch on the screen.  Handle any needed scrolling or the like */
-+void graphics_putchar(int ch) {
-+    ch &= 0xff;
-+
-+    graphics_cursor(0);
-+
-+    if (ch == '\n') {
-+        if (fonty + 1 < view_y1)
-+            graphics_setxy(fontx, fonty + 1);
-+        else
-+            graphics_scroll();
-+        graphics_cursor(1);
-+        return;
-+    } else if (ch == '\r') {
-+        graphics_setxy(view_x0, fonty);
-+        graphics_cursor(1);
-+        return;
-+    }
-+
-+    graphics_cursor(0);
-+
-+    text[fonty * 80 + fontx] = ch;
-+    text[fonty * 80 + fontx] &= 0x00ff;
-+    if (graphics_current_color & 0xf0)
-+        text[fonty * 80 + fontx] |= 0x100;
-+
-+    graphics_cursor(0);
-+
-+    if ((fontx + 1) >= view_x1) {
-+        graphics_setxy(view_x0, fonty);
-+        if (fonty + 1 < view_y1)
-+            graphics_setxy(view_x0, fonty + 1);
-+        else
-+            graphics_scroll();
-+        graphics_cursor(1);
-+        do_more ();
-+        graphics_cursor(0);
-+    } else {
-+        graphics_setxy(fontx + 1, fonty);
-+    }
-+
-+    graphics_cursor(1);
-+}
-+
-+/* get the current location of the cursor */
-+int graphics_getxy(void) {
-+    return (fontx << 8) | fonty;
-+}
-+
-+void graphics_gotoxy(int x, int y) {
-+    graphics_cursor(0);
-+
-+    graphics_setxy(x, y);
-+
-+    graphics_cursor(1);
-+}
-+
-+void graphics_cls(void) {
-+    int i;
-+    unsigned char *mem, *s1, *s2, *s4, *s8;
-+
-+    graphics_cursor(0);
-+    graphics_gotoxy(view_x0, view_y0);
-+
-+    mem = (unsigned char*)VIDEOMEM;
-+    s1 = (unsigned char*)VSHADOW1;
-+    s2 = (unsigned char*)VSHADOW2;
-+    s4 = (unsigned char*)VSHADOW4;
-+    s8 = (unsigned char*)VSHADOW8;
-+
-+    for (i = 0; i < 80 * 30; i++)
-+        text[i] = ' ';
-+    graphics_cursor(1);
-+
-+    BitMask(0xff);
-+
-+    /* plane 1 */
-+    MapMask(1);
-+    grub_memcpy(mem, s1, 38400);
-+
-+    /* plane 2 */
-+    MapMask(2);
-+    grub_memcpy(mem, s2, 38400);
-+
-+    /* plane 3 */
-+    MapMask(4);
-+    grub_memcpy(mem, s4, 38400);
-+
-+    /* plane 4 */
-+    MapMask(8);
-+    grub_memcpy(mem, s8, 38400);
-+
-+    MapMask(15);
-+
-+    if (no_cursor) {
-+        no_cursor = 0;
-+        set_int1c_handler();
-+    }
-+}
-+
-+void graphics_setcolorstate (color_state state) {
-+    switch (state) {
-+    case COLOR_STATE_STANDARD:
-+        graphics_current_color = graphics_standard_color;
-+        break;
-+    case COLOR_STATE_NORMAL:
-+        graphics_current_color = graphics_normal_color;
-+        break;
-+    case COLOR_STATE_HIGHLIGHT:
-+        graphics_current_color = graphics_highlight_color;
-+        break;
-+    default:
-+        graphics_current_color = graphics_standard_color;
-+        break;
-+    }
-+
-+    graphics_color_state = state;
-+}
-+
-+void graphics_setcolor (int normal_color, int highlight_color) {
-+    graphics_normal_color = normal_color;
-+    graphics_highlight_color = highlight_color;
-+
-+    graphics_setcolorstate (graphics_color_state);
-+}
-+
-+int graphics_setcursor (int on) {
-+    if (!no_cursor && !on) {
-+        no_cursor = 1;
-+        unset_int1c_handler();
-+        graphics_cursor(0);
-+    }
-+    else if(no_cursor && on) {
-+        no_cursor = 0;
-+        set_int1c_handler();
-+        graphics_cursor(1);
-+    }
-+    return 0;
-+}
-+
-+/* Read in the splashscreen image and set the palette up appropriately.
-+ * Format of splashscreen is an xpm (can be gzipped) with 16 colors and
-+ * 640x480. */
-+int read_image(char *s)
-+{
-+    char buf[32], pal[16], c;
-+    unsigned char base, mask, *s1, *s2, *s4, *s8;
-+    unsigned i, len, idx, colors, x, y, width, height;
-+
-+    if (!grub_open(s))
-+        return 0;
-+
-+    /* read header */
-+    if (!grub_read((char*)&buf, 10) || grub_memcmp(buf, "/* XPM */\n", 10)) {
-+        grub_close();
-+        return 0;
-+    }
-+    
-+    /* parse info */
-+    while (grub_read(&c, 1)) {
-+        if (c == '"')
-+            break;
-+    }
-+
-+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+        ;
-+
-+    i = 0;
-+    width = c - '0';
-+    while (grub_read(&c, 1)) {
-+        if (c >= '0' && c <= '9')
-+            width = width * 10 + c - '0';
-+        else
-+            break;
-+    }
-+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+        ;
-+
-+    height = c - '0';
-+    while (grub_read(&c, 1)) {
-+        if (c >= '0' && c <= '9')
-+            height = height * 10 + c - '0';
-+        else
-+            break;
-+    }
-+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
-+        ;
-+
-+    colors = c - '0';
-+    while (grub_read(&c, 1)) {
-+        if (c >= '0' && c <= '9')
-+            colors = colors * 10 + c - '0';
-+        else
-+            break;
-+    }
-+
-+    base = 0;
-+    while (grub_read(&c, 1) && c != '"')
-+        ;
-+
-+    /* palette */
-+    for (i = 0, idx = 1; i < colors; i++) {
-+        len = 0;
-+
-+        while (grub_read(&c, 1) && c != '"')
-+            ;
-+        grub_read(&c, 1);       /* char */
-+        base = c;
-+        grub_read(buf, 4);      /* \t c # */
-+
-+        while (grub_read(&c, 1) && c != '"') {
-+            if (len < sizeof(buf))
-+                buf[len++] = c;
-+        }
-+
-+        if (len == 6 && idx < 15) {
-+            int r = ((hex(buf[0]) << 4) | hex(buf[1])) >> 2;
-+            int g = ((hex(buf[2]) << 4) | hex(buf[3])) >> 2;
-+            int b = ((hex(buf[4]) << 4) | hex(buf[5])) >> 2;
-+
-+            pal[idx] = base;
-+            graphics_set_palette(idx, r, g, b);
-+            ++idx;
-+        }
-+    }
-+
-+    x = y = len = 0;
-+
-+    s1 = (unsigned char*)VSHADOW1;
-+    s2 = (unsigned char*)VSHADOW2;
-+    s4 = (unsigned char*)VSHADOW4;
-+    s8 = (unsigned char*)VSHADOW8;
-+
-+    for (i = 0; i < 38400; i++)
-+        s1[i] = s2[i] = s4[i] = s8[i] = 0;
-+
-+    /* parse xpm data */
-+    while (y < height) {
-+        while (1) {
-+            if (!grub_read(&c, 1)) {
-+                grub_close();
-+                return 0;
-+            }
-+            if (c == '"')
-+                break;
-+        }
-+
-+        while (grub_read(&c, 1) && c != '"') {
-+            for (i = 1; i < 15; i++)
-+                if (pal[i] == c) {
-+                    c = i;
-+                    break;
-+                }
-+
-+            mask = 0x80 >> (x & 7);
-+            if (c & 1)
-+                s1[len + (x >> 3)] |= mask;
-+            if (c & 2)
-+                s2[len + (x >> 3)] |= mask;
-+            if (c & 4)
-+                s4[len + (x >> 3)] |= mask;
-+            if (c & 8)
-+                s8[len + (x >> 3)] |= mask;
-+
-+            if (++x >= 640) {
-+                x = 0;
-+
-+                if (y < 480)
-+                    len += 80;
-+                ++y;
-+            }
-+        }
-+    }
-+
-+    grub_close();
-+
-+    graphics_set_palette(0, (background >> 16), (background >> 8) & 63, 
-+                background & 63);
-+    graphics_set_palette(15, (foreground >> 16), (foreground >> 8) & 63, 
-+                foreground & 63);
-+    graphics_set_palette(0x11, (window_border >> 16), (window_border >> 8) & 63, 
-+                         window_border & 63);
-+
-+    return 1;
-+}
-+
-+/* Convert a character which is a hex digit to the appropriate integer */
-+int hex(int v)
-+{
-+    if (v >= 'A' && v <= 'F')
-+        return (v - 'A' + 10);
-+    if (v >= 'a' && v <= 'f')
-+        return (v - 'a' + 10);
-+    return (v - '0');
-+}
-+
-+void graphics_cursor(int set) {
-+    unsigned char *pat, *mem, *ptr, chr[16 << 2];
-+    int i, ch, invert, offset;
-+
-+    if (set && (no_cursor || no_scroll))
-+        return;
-+
-+    offset = cursorY * 80 + fontx;
-+    ch = text[fonty * 80 + fontx] & 0xff;
-+    invert = (text[fonty * 80 + fontx] & 0xff00) != 0;
-+    pat = font8x16 + (ch << 4);
-+
-+    mem = (unsigned char*)VIDEOMEM + offset;
-+
-+    if (!set) {
-+        for (i = 0; i < 16; i++) {
-+            unsigned char mask = pat[i];
-+
-+            if (!invert) {
-+                chr[i     ] = ((unsigned char*)VSHADOW1)[offset];
-+                chr[16 + i] = ((unsigned char*)VSHADOW2)[offset];
-+                chr[32 + i] = ((unsigned char*)VSHADOW4)[offset];
-+                chr[48 + i] = ((unsigned char*)VSHADOW8)[offset];
-+
-+                if (shade) {
-+                    if (ch == DISP_VERT || ch == DISP_LL ||
-+                        ch == DISP_UR || ch == DISP_LR) {
-+                        unsigned char pmask = ~(pat[i] >> 1);
-+
-+                        chr[i     ] &= pmask;
-+                        chr[16 + i] &= pmask;
-+                        chr[32 + i] &= pmask;
-+                        chr[48 + i] &= pmask;
-+                    }
-+                    if (i > 0 && ch != DISP_VERT) {
-+                        unsigned char pmask = ~(pat[i - 1] >> 1);
-+
-+                        chr[i     ] &= pmask;
-+                        chr[16 + i] &= pmask;
-+                        chr[32 + i] &= pmask;
-+                        chr[48 + i] &= pmask;
-+                        if (ch == DISP_HORIZ || ch == DISP_UR || ch == DISP_LR) {
-+                            pmask = ~pat[i - 1];
-+
-+                            chr[i     ] &= pmask;
-+                            chr[16 + i] &= pmask;
-+                            chr[32 + i] &= pmask;
-+                            chr[48 + i] &= pmask;
-+                        }
-+                    }
-+                }
-+                chr[i     ] |= mask;
-+                chr[16 + i] |= mask;
-+                chr[32 + i] |= mask;
-+                chr[48 + i] |= mask;
-+
-+                offset += 80;
-+            }
-+            else {
-+                chr[i     ] = mask;
-+                chr[16 + i] = mask;
-+                chr[32 + i] = mask;
-+                chr[48 + i] = mask;
-+            }
-+        }
-+    }
-+    else {
-+        MapMask(15);
-+        ptr = mem;
-+        for (i = 0; i < 16; i++, ptr += 80) {
-+            cursorBuf[i] = pat[i];
-+            *ptr = ~pat[i];
-+        }
-+        return;
-+    }
-+
-+    offset = 0;
-+    for (i = 1; i < 16; i <<= 1, offset += 16) {
-+        int j;
-+
-+        MapMask(i);
-+        ptr = mem;
-+        for (j = 0; j < 16; j++, ptr += 80)
-+            *ptr = chr[j + offset];
-+    }
-+
-+    MapMask(15);
-+}
-+
-+#endif /* SUPPORT_GRAPHICS */
-diff -Naur grub-0.97.orig/stage2/graphics.h grub-0.97/stage2/graphics.h
---- grub-0.97.orig/stage2/graphics.h   1969-12-31 21:00:00.000000000 -0300
-+++ grub-0.97/stage2/graphics.h        2005-06-12 20:56:49.000000000 -0300
-@@ -0,0 +1,43 @@
-+/* graphics.h - graphics console interface */
-+/*
-+ *  GRUB  --  GRand Unified Bootloader
-+ *  Copyright (C) 2002  Free Software Foundation, Inc.
-+ *
-+ *  This program is free software; you can redistribute it and/or modify
-+ *  it under the terms of the GNU General Public License as published by
-+ *  the Free Software Foundation; either version 2 of the License, or
-+ *  (at your option) any later version.
-+ *
-+ *  This program is distributed in the hope that it will be useful,
-+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ *  GNU General Public License for more details.
-+ *
-+ *  You should have received a copy of the GNU General Public License
-+ *  along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+#ifndef GRAPHICS_H
-+#define GRAPHICS_H
-+
-+/* magic constant */
-+#define VIDEOMEM 0xA0000
-+
-+/* function prototypes */
-+char *graphics_get_splash(void);
-+
-+int read_image(char *s);
-+void graphics_cursor(int set);
-+
-+/* function prototypes for asm functions */
-+void * graphics_get_font();
-+void graphics_set_palette(int idx, int red, int green, int blue);
-+void set_int1c_handler();
-+void unset_int1c_handler();
-+
-+extern short cursorX, cursorY;
-+extern char cursorBuf[16];
-+extern int shade;
-+extern int view_x0, view_y0, view_x1, view_y1;
-+
-+#endif /* GRAPHICS_H */
-diff -Naur grub-0.97.orig/stage2/Makefile.am grub-0.97/stage2/Makefile.am
---- grub-0.97.orig/stage2/Makefile.am  2005-02-02 18:37:35.000000000 -0200
-+++ grub-0.97/stage2/Makefile.am       2005-06-12 20:56:49.000000000 -0300
-@@ -7,7 +7,7 @@
-         fat.h filesys.h freebsd.h fs.h hercules.h i386-elf.h \
-       imgact_aout.h iso9660.h jfs.h mb_header.h mb_info.h md5.h \
-       nbi.h pc_slice.h serial.h shared.h smp-imps.h term.h \
--      terminfo.h tparm.h nbi.h ufs2.h vstafs.h xfs.h
-+      terminfo.h tparm.h nbi.h ufs2.h vstafs.h xfs.h graphics.h
- EXTRA_DIST = setjmp.S apm.S $(noinst_SCRIPTS)
- # For <stage1.h>.
-@@ -19,7 +19,7 @@
-       disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
-       fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
-       fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c stage2.c \
--      terminfo.c tparm.c
-+      terminfo.c tparm.c graphics.c
- libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
-       -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-       -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
-@@ -79,8 +79,14 @@
- HERCULES_FLAGS =
- endif
-+if GRAPHICS_SUPPORT
-+GRAPHICS_FLAGS = -DSUPPORT_GRAPHICS=1
-+else
-+GRAPHICS_FLAGS =
-+endif
-+
- STAGE2_COMPILE = $(STAGE2_CFLAGS) -fno-builtin -nostdinc \
--      $(NETBOOT_FLAGS) $(SERIAL_FLAGS) $(HERCULES_FLAGS)
-+      $(NETBOOT_FLAGS) $(SERIAL_FLAGS) $(HERCULES_FLAGS) $(GRAPHICS_FLAGS)
- STAGE1_5_LINK = -nostdlib -Wl,-N -Wl,-Ttext -Wl,2000
- STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DNO_DECOMPRESSION=1 -DSTAGE1_5=1
-@@ -90,7 +96,8 @@
-       cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
-       fsys_fat.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
-       fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c gunzip.c \
--      hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c
-+      hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c \
-+      graphics.c
- pre_stage2_exec_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
-diff -Naur grub-0.97.orig/stage2/shared.h grub-0.97/stage2/shared.h
---- grub-0.97.orig/stage2/shared.h     2004-06-19 13:40:09.000000000 -0300
-+++ grub-0.97/stage2/shared.h  2005-06-12 20:56:49.000000000 -0300
-@@ -792,6 +792,11 @@
- /* Set the cursor position. */
- void gotoxy (int x, int y);
-+/* Internal pager
-+   Returns 1 = if pager was used
-+           0 = if pager wasn't used  */
-+int do_more (void);
-+
- /* Displays an ASCII character.  IBM displays will translate some
-    characters to special graphical ones (see the DISP_* constants). */
- void grub_putchar (int c);
-@@ -871,6 +876,7 @@
- int grub_tolower (int c);
- int grub_isspace (int c);
- int grub_strncat (char *s1, const char *s2, int n);
-+void grub_memcpy(void *dest, const void *src, int len);
- void *grub_memmove (void *to, const void *from, int len);
- void *grub_memset (void *start, int c, int len);
- int grub_strncat (char *s1, const char *s2, int n);
-diff -Naur grub-0.97.orig/stage2/stage2.c grub-0.97/stage2/stage2.c
---- grub-0.97.orig/stage2/stage2.c     2005-03-19 14:51:57.000000000 -0300
-+++ grub-0.97/stage2/stage2.c  2005-06-13 22:38:08.000000000 -0300
-@@ -20,6 +20,12 @@
- #include <shared.h>
- #include <term.h>
-+#ifdef SUPPORT_GRAPHICS
-+# include <graphics.h>
-+#endif
-+
-+int col_start, col_end, row_start, box_size;
-+
- grub_jmp_buf restart_env;
- #if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
-@@ -105,13 +111,13 @@
-   if (highlight && current_term->setcolorstate)
-     current_term->setcolorstate (COLOR_STATE_HIGHLIGHT);
--  gotoxy (2, y);
-+  gotoxy (2 + col_start, y);
-   grub_putchar (' ');
--  for (x = 3; x < 75; x++)
-+  for (x = 3 + col_start; x < (col_end - 5); x++)
-     {
--      if (*entry && x <= 72)
-+      if (*entry && x <= (col_end - 8))
-       {
--        if (x == 72)
-+        if (x == (col_end - 8))
-           grub_putchar (DISP_RIGHT);
-         else
-           grub_putchar (*entry++);
-@@ -119,7 +125,7 @@
-       else
-       grub_putchar (' ');
-     }
--  gotoxy (74, y);
-+  gotoxy ((col_end - 6), y);
-   if (current_term->setcolorstate)
-     current_term->setcolorstate (COLOR_STATE_STANDARD);
-@@ -131,7 +137,7 @@
- {
-   int i;
-   
--  gotoxy (77, y + 1);
-+  gotoxy ((col_end - 3), y + 1);
-   if (first)
-     grub_putchar (DISP_UP);
-@@ -151,14 +157,14 @@
-       menu_entries++;
-     }
--  gotoxy (77, y + size);
-+  gotoxy ((col_end - 3), y + size);
-   if (*menu_entries)
-     grub_putchar (DISP_DOWN);
-   else
-     grub_putchar (' ');
--  gotoxy (74, y + entryno + 1);
-+  gotoxy ((col_end - 6), y + entryno + 1);
- }
- static void
-@@ -196,30 +202,30 @@
-   if (current_term->setcolorstate)
-     current_term->setcolorstate (COLOR_STATE_NORMAL);
-   
--  gotoxy (1, y);
-+  gotoxy (1 + col_start, y);
-   grub_putchar (DISP_UL);
--  for (i = 0; i < 73; i++)
-+  for (i = col_start; i < (col_end - 7); i++)
-     grub_putchar (DISP_HORIZ);
-   grub_putchar (DISP_UR);
-   i = 1;
-   while (1)
-     {
--      gotoxy (1, y + i);
-+      gotoxy (1 + col_start, y + i);
-       if (i > size)
-       break;
-       
-       grub_putchar (DISP_VERT);
--      gotoxy (75, y + i);
-+      gotoxy ((col_end - 5), y + i);
-       grub_putchar (DISP_VERT);
-       i++;
-     }
-   grub_putchar (DISP_LL);
--  for (i = 0; i < 73; i++)
-+  for (i = col_start; i < (col_end - 7); i++)
-     grub_putchar (DISP_HORIZ);
-   grub_putchar (DISP_LR);
-@@ -233,6 +239,7 @@
- {
-   int c, time1, time2 = -1, first_entry = 0;
-   char *cur_entry = 0;
-+  struct term_entry *prev_term = NULL;
-   /*
-    *  Main loop for menu UI.
-@@ -250,6 +257,22 @@
-       }
-     }
-+  col_start = 0;
-+  col_end = 80;
-+  row_start = 0;
-+  box_size = 12;
-+  /* if we're using viewport we need to make sure to setup
-+     coordinates correctly.  */
-+#ifdef SUPPORT_GRAPHICS
-+  if (grub_memcmp (current_term->name, "graphics", sizeof ("graphics") - 1) == 0)
-+    {
-+      col_start = view_x0;
-+      col_end = view_x1;
-+      row_start = view_y0;
-+      box_size = (view_y1 - view_y0) - 13;
-+    }
-+#endif
-+
-   /* If the timeout was expired or wasn't set, force to show the menu
-      interface. */
-   if (grub_timeout < 0)
-@@ -302,36 +325,36 @@
-       if (current_term->flags & TERM_DUMB)
-       print_entries_raw (num_entries, first_entry, menu_entries);
-       else
--      print_border (3, 12);
-+      print_border (3 + row_start, box_size);
-       grub_printf ("\n\
--      Use the %c and %c keys to select which entry is highlighted.\n",
-+    Use the %c and %c keys to select which entry is highlighted.\n",
-                  DISP_UP, DISP_DOWN);
-       
-       if (! auth && password)
-       {
-         printf ("\
--      Press enter to boot the selected OS or \'p\' to enter a\n\
--      password to unlock the next set of features.");
-+    Press enter to boot the selected OS or \'p\' to enter a\n\
-+    password to unlock the next set of features.");
-       }
-       else
-       {
-         if (config_entries)
-           printf ("\
--      Press enter to boot the selected OS, \'e\' to edit the\n\
--      commands before booting, or \'c\' for a command-line.");
-+    Press enter to boot the selected OS, \'e\' to edit the\n\
-+    commands before booting, or \'c\' for a command-line.");
-         else
-           printf ("\
--      Press \'b\' to boot, \'e\' to edit the selected command in the\n\
--      boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
--      after (\'O\' for before) the selected line, \'d\' to remove the\n\
--      selected line, or escape to go back to the main menu.");
-+    Press \'b\' to boot, \'e\' to edit the selected command in the\n\
-+    boot sequence, \'c\' for a command-line, \'o\' to open a new line\n\
-+    after (\'O\' for before) the selected line, \'d\' to remove the\n\
-+    selected line, or escape to go back to the main menu.");
-       }
-       if (current_term->flags & TERM_DUMB)
-       grub_printf ("\n\nThe selected entry is %d ", entryno);
-       else
--      print_entries (3, 12, first_entry, entryno, menu_entries);
-+      print_entries (3 + row_start, box_size, first_entry, entryno, menu_entries);
-     }
-   /* XX using RT clock now, need to initialize value */
-@@ -358,10 +381,10 @@
-                          entryno, grub_timeout);
-         else
-           {
--            gotoxy (3, 22);
--            grub_printf ("The highlighted entry will be booted automatically in %d seconds.    ",
-+            gotoxy (3 + col_start, 10 + box_size + row_start);
-+            grub_printf (" The highlighted entry will be booted automatically in %d seconds.   ",
-                          grub_timeout);
--            gotoxy (74, 4 + entryno);
-+            gotoxy ((col_end - 6), 4 + entryno + row_start);
-         }
-         
-         grub_timeout--;
-@@ -387,12 +410,12 @@
-             if (current_term->flags & TERM_DUMB)
-               grub_putchar ('\r');
-             else
--              gotoxy (3, 22);
-+              gotoxy (3 + col_start, 10 + box_size + row_start);
-             printf ("                                                                    ");
-             grub_timeout = -1;
-             fallback_entryno = -1;
-             if (! (current_term->flags & TERM_DUMB))
--              gotoxy (74, 4 + entryno);
-+              gotoxy ((col_end - 6), 4 + entryno + row_start);
-           }
-         /* We told them above (at least in SUPPORT_SERIAL) to use
-@@ -408,12 +431,12 @@
-               {
-                 if (entryno > 0)
-                   {
--                    print_entry (4 + entryno, 0,
-+                    print_entry (4 + entryno + row_start, 0,
-                                  get_entry (menu_entries,
-                                             first_entry + entryno,
-                                             0));
-                     entryno--;
--                    print_entry (4 + entryno, 1,
-+                    print_entry (4 + entryno + row_start, 1,
-                                  get_entry (menu_entries,
-                                             first_entry + entryno,
-                                             0));
-@@ -421,7 +444,7 @@
-                 else if (first_entry > 0)
-                   {
-                     first_entry--;
--                    print_entries (3, 12, first_entry, entryno,
-+                    print_entries (3 + row_start, box_size, first_entry, entryno,
-                                    menu_entries);
-                   }
-               }
-@@ -433,29 +456,29 @@
-               entryno++;
-             else
-               {
--                if (entryno < 11)
-+                if (entryno < (box_size - 1))
-                   {
--                    print_entry (4 + entryno, 0,
-+                    print_entry (4 + entryno + row_start, 0,
-                                  get_entry (menu_entries,
-                                             first_entry + entryno,
-                                             0));
-                     entryno++;
--                    print_entry (4 + entryno, 1,
-+                    print_entry (4 + entryno + row_start, 1,
-                                  get_entry (menu_entries,
-                                             first_entry + entryno,
-                                             0));
-                 }
--              else if (num_entries > 12 + first_entry)
-+              else if (num_entries > box_size + first_entry)
-                 {
-                   first_entry++;
--                  print_entries (3, 12, first_entry, entryno, menu_entries);
-+                  print_entries (3 + row_start, box_size, first_entry, entryno, menu_entries);
-                 }
-               }
-           }
-         else if (c == 7)
-           {
-             /* Page Up */
--            first_entry -= 12;
-+            first_entry -= box_size;
-             if (first_entry < 0)
-               {
-                 entryno += first_entry;
-@@ -463,20 +486,20 @@
-                 if (entryno < 0)
-                   entryno = 0;
-               }
--            print_entries (3, 12, first_entry, entryno, menu_entries);
-+            print_entries (3 + row_start, box_size, first_entry, entryno, menu_entries);
-           }
-         else if (c == 3)
-           {
-             /* Page Down */
--            first_entry += 12;
-+            first_entry += box_size;
-             if (first_entry + entryno + 1 >= num_entries)
-               {
--                first_entry = num_entries - 12;
-+                first_entry = num_entries - box_size;
-                 if (first_entry < 0)
-                   first_entry = 0;
-                 entryno = num_entries - first_entry - 1;
-               }
--            print_entries (3, 12, first_entry, entryno, menu_entries);
-+            print_entries (3 + row_start, box_size, first_entry, entryno, menu_entries);
-           }
-         if (config_entries)
-@@ -489,7 +512,7 @@
-             if ((c == 'd') || (c == 'o') || (c == 'O'))
-               {
-                 if (! (current_term->flags & TERM_DUMB))
--                  print_entry (4 + entryno, 0,
-+                  print_entry (4 + entryno + row_start, 0,
-                                get_entry (menu_entries,
-                                           first_entry + entryno,
-                                           0));
-@@ -537,7 +560,7 @@
-                     if (entryno >= num_entries)
-                       entryno--;
--                    if (first_entry && num_entries < 12 + first_entry)
-+                    if (first_entry && num_entries < box_size + first_entry)
-                       first_entry--;
-                   }
-@@ -549,7 +572,7 @@
-                     grub_printf ("\n");
-                   }
-                 else
--                  print_entries (3, 12, first_entry, entryno, menu_entries);
-+                  print_entries (3 + row_start, box_size, first_entry, entryno, menu_entries);
-               }
-             cur_entry = menu_entries;
-@@ -570,7 +593,7 @@
-                 if (current_term->flags & TERM_DUMB)
-                   grub_printf ("\r                                    ");
-                 else
--                  gotoxy (1, 21);
-+                  gotoxy (1 + col_start, 9 + box_size + row_start);
-                 /* Wipe out the previously entered password */
-                 grub_memset (entered, 0, sizeof (entered));
-@@ -714,6 +737,15 @@
-   
-   cls ();
-   setcursor (1);
-+  /* if our terminal needed initialization, we should shut it down
-+   * before booting the kernel, but we want to save what it was so
-+   * we can come back if needed */
-+  prev_term = current_term;
-+  if (current_term->shutdown) 
-+    {
-+      current_term->shutdown();
-+      current_term = term_table; /* assumption: console is first */
-+    }
-   
-   while (1)
-     {
-@@ -748,6 +780,13 @@
-       break;
-     }
-+  /* if we get back here, we should go back to what our term was before */
-+  current_term = prev_term;
-+  if (current_term->startup)
-+      /* if our terminal fails to initialize, fall back to console since
-+       * it should always work */
-+      if (current_term->startup() == 0)
-+          current_term = term_table; /* we know that console is first */
-   show_menu = 1;
-   goto restart;
- }
-@@ -1050,6 +1089,16 @@
-         while (is_preset);
-       }
-+      /* go ahead and make sure the terminal is setup */
-+      if (current_term->startup)
-+      {
-+        /* If initialization fails, go back to default terminal */
-+        if (current_term->startup() == 0)
-+                {
-+                    current_term = term_table;
-+                }
-+      }
-+
-       if (! num_entries)
-       {
-         /* If no acceptable config file, goto command-line, starting
-diff -Naur grub-0.97.orig/stage2/term.h grub-0.97/stage2/term.h
---- grub-0.97.orig/stage2/term.h       2003-07-09 08:45:53.000000000 -0300
-+++ grub-0.97/stage2/term.h    2005-06-13 14:07:40.000000000 -0300
-@@ -60,6 +60,8 @@
-   const char *name;
-   /* The feature flags defined above.  */
-   unsigned long flags;
-+  /* Default for maximum number of lines if not specified */
-+  unsigned short max_lines;
-   /* Put a character.  */
-   void (*putchar) (int c);
-   /* Check if any input character is available.  */
-@@ -79,6 +81,10 @@
-   void (*setcolor) (int normal_color, int highlight_color);
-   /* Turn on/off the cursor.  */
-   int (*setcursor) (int on);
-+  /* function to start a terminal */
-+  int (*startup) (void);
-+  /* function to use to shutdown a terminal */
-+  void (*shutdown) (void);
- };
- /* This lists up available terminals.  */
-@@ -124,4 +130,24 @@
- int hercules_setcursor (int on);
- #endif
-+#ifdef SUPPORT_GRAPHICS
-+extern int foreground, background, window_border, graphics_inited, saved_videomode;
-+
-+void graphics_set_splash(char *splashfile);
-+int set_videomode(int mode);
-+int get_videomode(void);
-+void graphics_putchar (int c);
-+int graphics_getxy(void);
-+void graphics_gotoxy(int x, int y);
-+void graphics_cls(void);
-+void graphics_setcolorstate (color_state state);
-+void graphics_setcolor (int normal_color, int highlight_color);
-+int graphics_setcursor (int on);
-+int graphics_init(void);
-+void graphics_end(void);
-+
-+int hex(int v);
-+void graphics_set_palette(int idx, int red, int green, int blue);
-+#endif /* SUPPORT_GRAPHICS */
-+
- #endif /* ! GRUB_TERM_HEADER */
diff --git a/stubdom/grub.patches/11graphics-keyboard.diff b/stubdom/grub.patches/11graphics-keyboard.diff
deleted file mode 100644 (file)
index fe17b20..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/stage2/stage2.c b/stage2/stage2.c
-index 9d9fcc3..8353a3b 100644
---- a/stage2/stage2.c
-+++ b/stage2/stage2.c
-@@ -395,7 +395,7 @@ restart:
-        pressed.  
-        This avoids polling (relevant in the grub-shell and later on
-        in grub if interrupt driven I/O is done).  */
--      if (checkkey () >= 0 || grub_timeout < 0)
-+      if (checkkey () > 0 || grub_timeout < 0)
-       {
-         /* Key was pressed, show which entry is selected before GETKEY,
-            since we're comming in here also on GRUB_TIMEOUT == -1 and
diff --git a/stubdom/grub.patches/20print_func.diff b/stubdom/grub.patches/20print_func.diff
deleted file mode 100644 (file)
index ec9da0e..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-2006-01-05  Otavio Salvador  <otavio@debian.org>
-
-       * Rediff.
-
-2005-16-10  Samuel Thibault  <samuel.thibault@ens-lyon.org>
-
-       * docs/grub.texi: Added print command description.
-       * stage2/builtins.c(print_func): New function.
-       (builtin_print): New variable.
-       (builtin_table): Added builtin_print in table.
-
-Debian Status Following:
-   Added by: Otavio Salvador
-       Date: 2006-01-05
-
-diff -Nur grub-0.97-bkp/docs/grub.texi grub-0.97/docs/grub.texi
---- grub-0.97-bkp/docs/grub.texi       2006-01-05 10:59:05.564347912 -0200
-+++ grub-0.97/docs/grub.texi   2006-01-05 11:18:59.033912960 -0200
-@@ -2685,6 +2685,7 @@
- * module::                      Load a module
- * modulenounzip::               Load a module without decompression
- * pause::                       Wait for a key press
-+* print::                       Print a message
- * quit::                        Exit from the grub shell
- * reboot::                      Reboot your computer
- * read::                        Read data from memory
-@@ -3091,6 +3092,16 @@
- @end deffn
-+@node print
-+@subsection print
-+
-+@deffn Command print message @dots{}
-+Print the @var{message}. Note that placing @key{^G} (ASCII code 7) in the
-+message will cause the speaker to emit the standard beep sound, which is
-+useful for visually impaired people.
-+@end deffn
-+
-+
- @node quit
- @subsection quit
-diff -Nur grub-0.97-bkp/stage2/builtins.c grub-0.97/stage2/builtins.c
---- grub-0.97-bkp/stage2/builtins.c    2006-01-05 10:59:05.550350040 -0200
-+++ grub-0.97/stage2/builtins.c        2006-01-05 11:19:28.422445224 -0200
-@@ -2323,6 +2323,25 @@
-   "Probe I/O ports used for the drive DRIVE."
- };
-+/* print */
-+static int
-+print_func (char *arg, int flags)
-+{
-+  printf("%s\n", arg);
-+
-+  return 0;
-+}
-+
-+static struct builtin builtin_print =
-+{
-+  "print",
-+  print_func,
-+  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_NO_ECHO,
-+  "print [MESSAGE ...]",
-+  "Print MESSAGE."
-+};
-+
-+
\f
- /* kernel */
- static int
-@@ -4848,6 +4867,7 @@
-   &builtin_parttype,
-   &builtin_password,
-   &builtin_pause,
-+  &builtin_print,
- #ifdef GRUB_UTIL
-   &builtin_quit,
- #endif /* GRUB_UTIL */
diff --git a/stubdom/grub.patches/30savedefault.diff b/stubdom/grub.patches/30savedefault.diff
deleted file mode 100644 (file)
index 2902b87..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-Index: grub/stage2/builtins.c
-===================================================================
---- grub.orig/stage2/builtins.c        2008-06-02 18:06:08.942580000 +0100
-+++ grub/stage2/builtins.c     2008-06-06 18:35:07.548390000 +0100
-@@ -86,6 +86,10 @@
-    inside other functions.  */
- static int configfile_func (char *arg, int flags);
-+static int savedefault_helper (char *arg, int flags);
-+
-+static int savedefault_shell (char *arg, int flags);
-+
- /* Initialize the data for builtins.  */
- void
- init_builtins (void)
-@@ -3512,7 +3516,109 @@
- static int
- savedefault_func (char *arg, int flags)
- {
--#if !defined(SUPPORT_DISKLESS) && !defined(GRUB_UTIL)
-+#if !defined(SUPPORT_DISKLESS)
-+  #if !defined(GRUB_UTIL)
-+      return savedefault_helper(arg, flags);
-+  #else
-+      return savedefault_shell(arg, flags);
-+  #endif
-+#else /* !SUPPORT_DISKLESS */ 
-+  errnum = ERR_UNRECOGNIZED;
-+  return 1;
-+#endif /* !SUPPORT_DISKLESS */
-+}
-+
-+#if !defined(SUPPORT_DISKLESS) && defined(GRUB_UTIL)
-+/* savedefault_shell */
-+static int
-+savedefault_shell(char *arg, int flags)
-+ {
-+  int once_only = 0;
-+  int new_default;
-+  int curr_default = -1;
-+  int curr_prev_default = -1;
-+  int new_prev_default = -1;
-+  FILE *fp;
-+  size_t bytes = 10;
-+  char line[bytes];
-+  char *default_file = (char *) DEFAULT_FILE_BUF;
-+  char buf[bytes];
-+  int i;
-+  
-+  while (1)
-+    {
-+      if (grub_memcmp ("--default=", arg, sizeof ("--default=") - 1) == 0)
-+        {
-+          char *p = arg + sizeof ("--default=") - 1;
-+          if (! safe_parse_maxint (&p, &new_default))
-+            return 1;
-+          arg = skip_to (0, arg);
-+        }
-+      else if (grub_memcmp ("--once", arg, sizeof ("--once") - 1) == 0)
-+        {
-+         once_only = 1;
-+         arg = skip_to (0, arg);
-+      }
-+      else
-+        break;
-+    }
-+
-+  *default_file = 0;
-+  grub_strncat (default_file, config_file, DEFAULT_FILE_BUFLEN);
-+  for (i = grub_strlen(default_file); i >= 0; i--)
-+    if (default_file[i] == '/')
-+    {
-+      i++;
-+      break;
-+    }
-+  default_file[i] = 0;
-+  grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
-+
-+  if(!(fp = fopen(default_file,"r")))
-+    {
-+      errnum = ERR_READ;
-+      goto fail;
-+    }
-+  
-+  fgets(line, bytes, fp);
-+  fclose(fp);
-+ 
-+  sscanf(line, "%d:%d", &curr_prev_default, &curr_default);
-+     
-+  if(curr_default != -1)
-+    new_prev_default = curr_default;
-+  else
-+    {
-+      if(curr_prev_default != -1)
-+        new_prev_default = curr_prev_default;
-+      else
-+        new_prev_default = 0;
-+    }
-+     
-+  if(once_only)
-+    sprintf(buf, "%d:%d", new_prev_default, new_default);
-+  else
-+    sprintf(buf, "%d", new_default);
-+
-+  if(!(fp = fopen(default_file,"w")))
-+    {
-+      errnum = ERR_READ;
-+      goto fail;
-+    }
-+     
-+  fprintf(fp, buf);   
-+     
-+fail:
-+  fclose(fp);
-+  return errnum;
-+}
-+#endif
-+
-+/* savedefault_helper */
-+static int
-+savedefault_helper (char *arg, int flags)
-+{
-+#if !defined(SUPPORT_DISKLESS)
-   unsigned long tmp_drive = saved_drive;
-   unsigned long tmp_partition = saved_partition;
-   char *default_file = (char *) DEFAULT_FILE_BUF;
-@@ -3588,22 +3694,26 @@
-       
-       disk_read_hook = disk_read_savesect_func;
-       len = grub_read (buf, sizeof (buf));
-+      buf[9]='\0';/* Make sure grub_strstr() below terminates */
-       disk_read_hook = 0;
-       grub_close ();
-       
--      if (len != sizeof (buf))
--      {
--        /* This is too small. Do not modify the file manually, please!  */
--        errnum = ERR_READ;
--        goto fail;
--      }
--
-       if (sector_count > 2)
-       {
-         /* Is this possible?! Too fragmented!  */
-         errnum = ERR_FSYS_CORRUPT;
-         goto fail;
-       }
-+
-+      char *tmp;
-+      if((tmp = grub_strstr(buf, ":")) != NULL)
-+      {
-+       int f_len = grub_strlen(buf) - grub_strlen(tmp);
-+       char *def;
-+       buf[f_len] = '\0';
-+       def = buf;
-+       safe_parse_maxint (&def, &entryno);
-+      }
-       
-       /* Set up a string to be written.  */
-       grub_memset (buf, '\n', sizeof (buf));
-Index: grub/stage2/stage2.c
-===================================================================
---- grub.orig/stage2/stage2.c  2008-06-02 18:06:08.858579000 +0100
-+++ grub/stage2/stage2.c       2008-06-06 18:04:03.585354000 +0100
-@@ -49,7 +49,8 @@
-     return 0;
- #endif /* GRUB_UTIL */
-   
--  preset_menu_offset = 0;
-+  if (preset_menu_offset)
-+    return 0;
-   return preset_menu != 0;
- }
-@@ -934,7 +935,11 @@
-             len = grub_read (buf, sizeof (buf));
-             if (len > 0)
-               {
-+                char *tmp;
-                 buf[sizeof (buf) - 1] = 0;
-+                if((tmp = grub_strstr(p, ":")) != NULL)
-+                  p = tmp + 1;
-+                
-                 safe_parse_maxint (&p, &saved_entryno);
-               }
diff --git a/stubdom/grub.patches/40ext3_256byte_inode.diff b/stubdom/grub.patches/40ext3_256byte_inode.diff
deleted file mode 100644 (file)
index 0c40854..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-
-Patch from Red Hat. See #463236, #463123.
-
-Index: grub/stage2/fsys_ext2fs.c
-===================================================================
---- grub.orig/stage2/fsys_ext2fs.c     2008-05-27 18:47:19.045183000 +0100
-+++ grub/stage2/fsys_ext2fs.c  2008-05-27 19:09:21.293187000 +0100
-@@ -79,7 +79,52 @@
-     __u32 s_rev_level;                /* Revision level */
-     __u16 s_def_resuid;               /* Default uid for reserved blocks */
-     __u16 s_def_resgid;               /* Default gid for reserved blocks */
--    __u32 s_reserved[235];    /* Padding to the end of the block */
-+    /*
-+     * These fields are for EXT2_DYNAMIC_REV superblocks only.
-+     *
-+     * Note: the difference between the compatible feature set and
-+     * the incompatible feature set is that if there is a bit set
-+     * in the incompatible feature set that the kernel doesn't
-+     * know about, it should refuse to mount the filesystem.
-+     *
-+     * e2fsck's requirements are more strict; if it doesn't know
-+     * about a feature in either the compatible or incompatible
-+     * feature set, it must abort and not try to meddle with
-+     * things it doesn't understand...
-+     */
-+    __u32 s_first_ino;                /* First non-reserved inode */
-+    __u16 s_inode_size;               /* size of inode structure */
-+    __u16 s_block_group_nr;   /* block group # of this superblock */
-+    __u32 s_feature_compat;   /* compatible feature set */
-+    __u32 s_feature_incompat; /* incompatible feature set */
-+    __u32 s_feature_ro_compat;        /* readonly-compatible feature set */
-+    __u8  s_uuid[16];         /* 128-bit uuid for volume */
-+    char  s_volume_name[16];  /* volume name */
-+    char  s_last_mounted[64]; /* directory where last mounted */
-+    __u32 s_algorithm_usage_bitmap; /* For compression */
-+    /*
-+     * Performance hints.  Directory preallocation should only
-+     * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
-+     */
-+    __u8  s_prealloc_blocks;  /* Nr of blocks to try to preallocate*/
-+    __u8  s_prealloc_dir_blocks;      /* Nr to preallocate for dirs */
-+    __u16 s_reserved_gdt_blocks;/* Per group table for online growth */
-+    /*
-+     * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
-+     */
-+    __u8 s_journal_uuid[16];  /* uuid of journal superblock */
-+    __u32 s_journal_inum;     /* inode number of journal file */
-+    __u32 s_journal_dev;      /* device number of journal file */
-+    __u32 s_last_orphan;      /* start of list of inodes to delete */
-+    __u32 s_hash_seed[4];     /* HTREE hash seed */
-+    __u8  s_def_hash_version; /* Default hash version to use */
-+    __u8  s_jnl_backup_type;  /* Default type of journal backup */
-+    __u16 s_reserved_word_pad;
-+    __u32 s_default_mount_opts;
-+    __u32 s_first_meta_bg;    /* First metablock group */
-+    __u32 s_mkfs_time;                /* When the filesystem was created */
-+    __u32 s_jnl_blocks[17];   /* Backup of the journal inode */
-+    __u32 s_reserved[172];    /* Padding to the end of the block */
-   };
- struct ext2_group_desc
-@@ -218,6 +263,9 @@
- #define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
- #define EXT2_ADDR_PER_BLOCK_BITS(s)           (log2(EXT2_ADDR_PER_BLOCK(s)))
-+#define EXT2_INODE_SIZE(s)            (SUPERBLOCK->s_inode_size)
-+#define EXT2_INODES_PER_BLOCK(s)      (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
-+
- /* linux/ext2_fs.h */
- #define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
- /* kind of from ext2/super.c */
-@@ -242,7 +290,14 @@
- static __inline__ unsigned long
- ffz (unsigned long word)
- {
--  __asm__ ("bsfl %1,%0"
-+  __asm__ ("bsf"
-+#ifdef __i386__
-+                "l"
-+#endif
-+#ifdef __x86_64__
-+                "q"
-+#endif
-+                " %1,%0"
- :        "=r" (word)
- :        "r" (~word));
-   return word;
-@@ -553,7 +608,7 @@
-       gdp = GROUP_DESC;
-       ino_blk = gdp[desc].bg_inode_table +
-       (((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
--       >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
-+       >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
- #ifdef E2DEBUG
-       printf ("inode table fsblock=%d\n", ino_blk);
- #endif /* E2DEBUG */
-@@ -565,13 +620,12 @@
-       /* reset indirect blocks! */
-       mapblock2 = mapblock1 = -1;
--      raw_inode = INODE +
--      ((current_ino - 1)
--       & (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
-+      raw_inode = (struct ext2_inode *)((char *)INODE +
-+      ((current_ino - 1) & (EXT2_INODES_PER_BLOCK (SUPERBLOCK) - 1)) *
-+      EXT2_INODE_SIZE (SUPERBLOCK));
- #ifdef E2DEBUG
-       printf ("ipb=%d, sizeof(inode)=%d\n",
--            (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
--            sizeof (struct ext2_inode));
-+            EXT2_INODES_PER_BLOCK (SUPERBLOCK), EXT2_INODE_SIZE (SUPERBLOCK));
-       printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
-       printf ("offset into inode table block=%d\n", (int) raw_inode - (int) INODE);
-       for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
diff --git a/stubdom/grub.patches/50fs_fulldisk.diff b/stubdom/grub.patches/50fs_fulldisk.diff
deleted file mode 100644 (file)
index d0fbb07..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-diff -urN grub-0.97.orig/stage2/fsys_ext2fs.c grub-0.97/stage2/fsys_ext2fs.c
---- grub-0.97.orig/stage2/fsys_ext2fs.c        2004-08-08 18:19:18.000000000 +0000
-+++ grub-0.97/stage2/fsys_ext2fs.c     2008-09-16 19:31:15.000000000 +0000
-@@ -254,7 +254,7 @@
- {
-   int retval = 1;
--  if ((((current_drive & 0x80) || (current_slice != 0))
-+  if ((((current_slice != 0))
-        && (current_slice != PC_SLICE_TYPE_EXT2FS)
-        && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
-        && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
-diff -urN grub-0.97.orig/stage2/fsys_fat.c grub-0.97/stage2/fsys_fat.c
---- grub-0.97.orig/stage2/fsys_fat.c   2005-03-15 16:52:00.000000000 +0000
-+++ grub-0.97/stage2/fsys_fat.c        2008-09-16 19:31:26.000000000 +0000
-@@ -70,7 +70,7 @@
-   __u32 magic, first_fat;
-   
-   /* Check partition type for harddisk */
--  if (((current_drive & 0x80) || (current_slice != 0))
-+  if (((current_slice != 0))
-       && ! IS_PC_SLICE_TYPE_FAT (current_slice)
-       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_MSDOS)))
-     return 0;
-diff -urN grub-0.97.orig/stage2/fsys_ffs.c grub-0.97/stage2/fsys_ffs.c
---- grub-0.97.orig/stage2/fsys_ffs.c   2003-07-09 11:45:52.000000000 +0000
-+++ grub-0.97/stage2/fsys_ffs.c        2008-09-16 19:31:32.000000000 +0000
-@@ -82,7 +82,7 @@
- {
-   int retval = 1;
--  if ((((current_drive & 0x80) || (current_slice != 0))
-+  if ((((current_slice != 0))
-        && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_BSDFFS))
-       || part_length < (SBLOCK + (SBSIZE / DEV_BSIZE))
-       || !devread (SBLOCK, 0, SBSIZE, (char *) SUPERBLOCK)
-diff -urN grub-0.97.orig/stage2/fsys_minix.c grub-0.97/stage2/fsys_minix.c
---- grub-0.97.orig/stage2/fsys_minix.c 2003-07-09 11:45:53.000000000 +0000
-+++ grub-0.97/stage2/fsys_minix.c      2008-09-16 19:32:01.000000000 +0000
-@@ -160,7 +160,7 @@
- int
- minix_mount (void)
- {
--  if (((current_drive & 0x80) || current_slice != 0)
-+  if ((current_slice != 0)
-       && ! IS_PC_SLICE_TYPE_MINIX (current_slice)
-       && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER))
-     return 0;                 /* The partition is not of MINIX type */
-diff -urN grub-0.97.orig/stage2/fsys_ufs2.c grub-0.97/stage2/fsys_ufs2.c
---- grub-0.97.orig/stage2/fsys_ufs2.c  2004-06-19 12:17:52.000000000 +0000
-+++ grub-0.97/stage2/fsys_ufs2.c       2008-09-16 19:32:32.000000000 +0000
-@@ -87,7 +87,7 @@
-   sblockloc = -1;
-   type = 0;
-   
--  if (! (((current_drive & 0x80) || (current_slice != 0))
-+  if (! (((current_slice != 0))
-        && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_BSDFFS)))
-     {
-       for (i = 0; sblock_try[i] != -1; ++i)
-diff -urN grub-0.97.orig/stage2/fsys_vstafs.c grub-0.97/stage2/fsys_vstafs.c
---- grub-0.97.orig/stage2/fsys_vstafs.c        2003-07-09 11:45:53.000000000 +0000
-+++ grub-0.97/stage2/fsys_vstafs.c     2008-09-16 19:32:39.000000000 +0000
-@@ -47,7 +47,7 @@
- {
-   int retval = 1;
-   
--  if( (((current_drive & 0x80) || (current_slice != 0))
-+  if( (((current_slice != 0))
-        && current_slice != PC_SLICE_TYPE_VSTAFS)
-       ||  ! devread (0, 0, BLOCK_SIZE, (char *) FSYS_BUF)
-       ||  FIRST_SECTOR->fs_magic != 0xDEADFACE)
diff --git a/stubdom/grub.patches/60ext4.diff b/stubdom/grub.patches/60ext4.diff
deleted file mode 100644 (file)
index c71cfe1..0000000
+++ /dev/null
@@ -1,474 +0,0 @@
-Index: grub-0.97/stage2/fsys_ext2fs.c
-===================================================================
---- grub-0.97.orig/stage2/fsys_ext2fs.c
-+++ grub-0.97/stage2/fsys_ext2fs.c
-@@ -41,6 +41,7 @@ typedef __signed__ short __s16;
- typedef unsigned short __u16;
- typedef __signed__ int __s32;
- typedef unsigned int __u32;
-+typedef unsigned long long __u64;
- /*
-  * Constants relative to the data blocks, from ext2_fs.h
-@@ -51,7 +52,7 @@ typedef unsigned int __u32;
- #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
- #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
--/* include/linux/ext2_fs.h */
-+/* lib/ext2fs/ext2_fs.h from e2fsprogs */
- struct ext2_super_block
-   {
-     __u32 s_inodes_count;     /* Inodes count */
-@@ -61,9 +62,9 @@ struct ext2_super_block
-     __u32 s_free_inodes_count;        /* Free inodes count */
-     __u32 s_first_data_block; /* First Data Block */
-     __u32 s_log_block_size;   /* Block size */
--    __s32 s_log_frag_size;    /* Fragment size */
-+    __s32 s_obso_log_frag_size;       /* Obsoleted Fragment size */
-     __u32 s_blocks_per_group; /* # Blocks per group */
--    __u32 s_frags_per_group;  /* # Fragments per group */
-+    __u32 s_obso_frags_per_group;     /* Obsoleted Fragments per group */
-     __u32 s_inodes_per_group; /* # Inodes per group */
-     __u32 s_mtime;            /* Mount time */
-     __u32 s_wtime;            /* Write time */
-@@ -72,7 +73,7 @@ struct ext2_super_block
-     __u16 s_magic;            /* Magic signature */
-     __u16 s_state;            /* File system state */
-     __u16 s_errors;           /* Behaviour when detecting errors */
--    __u16 s_pad;
-+    __u16 s_minor_rev_level;  /* minor revision level */
-     __u32 s_lastcheck;                /* time of last check */
-     __u32 s_checkinterval;    /* max. time between checks */
-     __u32 s_creator_os;               /* OS */
-@@ -119,15 +120,29 @@ struct ext2_super_block
-     __u32 s_hash_seed[4];     /* HTREE hash seed */
-     __u8  s_def_hash_version; /* Default hash version to use */
-     __u8  s_jnl_backup_type;  /* Default type of journal backup */
--    __u16 s_reserved_word_pad;
-+    __u16 s_desc_size;                /* size of group descriptor */
-     __u32 s_default_mount_opts;
-     __u32 s_first_meta_bg;    /* First metablock group */
-     __u32 s_mkfs_time;                /* When the filesystem was created */
-     __u32 s_jnl_blocks[17];   /* Backup of the journal inode */
--    __u32 s_reserved[172];    /* Padding to the end of the block */
--  };
-+    /* 64bit desc support valid if EXT4_FEATURE_INCOMPAT_64BIT */
-+    __u32 s_blocks_count_hi;  /* Blocks count */
-+    __u32 s_r_blocks_count_hi;        /* Reserved blocks count */
-+    __u32 s_free_blocks_count_hi; /* Free blocks count */
-+    __u16 s_min_extra_isize;  /* All inodes have at least # bytes */
-+    __u16 s_max_extra_isize;  /* New inodes should reverve # bytes */
-+    __u32 s_flags;            /* Miscellaneous flags */
-+    __u16 s_raid_stride;      /* Raid stride */
-+    __u16 s_mmp_interval;     /* # seconds to wait MMP checking */
-+    __u64 s_mmp_block;                /* Block for multi-mount protection */
-+    __u32 s_raid_stripe_width;        /* Blocks on all data disks (N*stride)*/
-+    __u8  s_log_groups_per_flex;/* FLEX_BG group size*/
-+    __u8  s_reserved_char_pad;
-+    __u16 s_reserved_pad;
-+    __u32 s_reserved[162];    /* Padding to the end of the block */
-+};
--struct ext2_group_desc
-+struct ext4_group_desc
-   {
-     __u32 bg_block_bitmap;    /* Blocks bitmap block */
-     __u32 bg_inode_bitmap;    /* Inodes bitmap block */
-@@ -135,8 +150,18 @@ struct ext2_group_desc
-     __u16 bg_free_blocks_count;       /* Free blocks count */
-     __u16 bg_free_inodes_count;       /* Free inodes count */
-     __u16 bg_used_dirs_count; /* Directories count */
--    __u16 bg_pad;
--    __u32 bg_reserved[3];
-+    __u16 bg_flags;           /* EXT4_BG_flags (INODE_UNINIT, etc) */
-+    __u32 bg_reserved[2];             /* Likely block/inode bitmap checksum */
-+    __u16 bg_itable_unused;   /* Unused inodes count */
-+    __u16 bg_checksum;                /* crc16(sb_uuid+group+desc) */
-+    __u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
-+    __u32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
-+    __u32 bg_inode_table_hi;  /* Inodes table block MSB */
-+    __u16 bg_free_blocks_count_hi;/* Free blocks count MSB */
-+    __u16 bg_free_inodes_count_hi;/* Free inodes count MSB */
-+    __u16 bg_used_dirs_count_hi;      /* Directories count MSB */
-+    __u16 bg_itable_unused_hi;        /* Unused inodes count MSB */
-+    __u32 bg_reserved2[3];
-   };
- struct ext2_inode
-@@ -174,22 +199,22 @@ struct ext2_inode
-     __u32 i_block[EXT2_N_BLOCKS];     /* 40: Pointers to blocks */
-     __u32 i_version;          /* File version (for NFS) */
-     __u32 i_file_acl;         /* File ACL */
--    __u32 i_dir_acl;          /* Directory ACL */
--    __u32 i_faddr;            /* Fragment address */
-+    __u32 i_size_high;
-+    __u32 i_obso_faddr;               /* Obsoleted fragment address */
-     union
-       {
-       struct
-         {
--          __u8 l_i_frag;      /* Fragment number */
--          __u8 l_i_fsize;     /* Fragment size */
--          __u16 i_pad1;
--          __u32 l_i_reserved2[2];
-+              __u16   l_i_blocks_high; /* were l_i_reserved1 */
-+              __u16   l_i_file_acl_high;
-+              __u16   l_i_uid_high;   /* these 2 fields */
-+              __u16   l_i_gid_high;   /* were reserved2[0] */
-+              __u32   l_i_reserved2;
-         }
-       linux2;
-       struct
-         {
--          __u8 h_i_frag;      /* Fragment number */
--          __u8 h_i_fsize;     /* Fragment size */
-+              __u16   h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
-           __u16 h_i_mode_high;
-           __u16 h_i_uid_high;
-           __u16 h_i_gid_high;
-@@ -198,16 +223,36 @@ struct ext2_inode
-       hurd2;
-       struct
-         {
--          __u8 m_i_frag;      /* Fragment number */
--          __u8 m_i_fsize;     /* Fragment size */
--          __u16 m_pad1;
-+              __u16   h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
-+              __u16   m_i_file_acl_high;
-           __u32 m_i_reserved2[2];
-         }
-       masix2;
-       }
-     osd2;                     /* OS dependent 2 */
-+      __u16   i_extra_isize;
-+      __u16   i_pad1;
-+      __u32  i_ctime_extra;  /* extra Change time      (nsec << 2 | epoch) */
-+      __u32  i_mtime_extra;  /* extra Modification time(nsec << 2 | epoch) */
-+      __u32  i_atime_extra;  /* extra Access time      (nsec << 2 | epoch) */
-+      __u32  i_crtime;       /* File Creation time */
-+      __u32  i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
-+      __u32  i_version_hi;    /* high 32 bits for 64-bit version */
-   };
-+#define EXT4_FEATURE_INCOMPAT_EXTENTS         0x0040 /* extents support */
-+#define EXT4_FEATURE_INCOMPAT_64BIT                   0x0080 /* grub not supported*/
-+#define EXT4_FEATURE_INCOMPAT_MMP           0x0100
-+#define EXT4_FEATURE_INCOMPAT_FLEX_BG         0x0200
-+
-+#define EXT4_HAS_INCOMPAT_FEATURE(sb,mask)                    \
-+      ( sb->s_feature_incompat & mask )
-+
-+#define EXT4_EXTENTS_FL               0x00080000 /* Inode uses extents */
-+#define EXT4_HUGE_FILE_FL     0x00040000 /* Set to each huge file */
-+
-+#define EXT4_MIN_DESC_SIZE                    32
-+
- /* linux/limits.h */
- #define NAME_MAX         255  /* # chars in a file name */
-@@ -225,6 +270,57 @@ struct ext2_dir_entry
-     char name[EXT2_NAME_LEN]; /* File name */
-   };
-+/* linux/ext4_fs_extents.h */
-+/* This is the extent on-disk structure.
-+ * It's used at the bottom of the tree.
-+ */
-+struct ext4_extent
-+  {
-+      __u32  ee_block;   /* first logical block extent covers */
-+      __u16  ee_len;     /* number of blocks covered by extent */
-+      __u16  ee_start_hi;    /* high 16 bits of physical block */
-+      __u32  ee_start_lo;    /* low 32 bits of physical block */
-+  };
-+
-+/*
-+ * This is index on-disk structure.
-+ * It's used at all the levels except the bottom.
-+ */
-+struct ext4_extent_idx
-+  {
-+    __u32  ei_block;   /* index covers logical blocks from 'block' */
-+    __u32  ei_leaf_lo; /* pointer to the physical block of the next *
-+                           * level. leaf or next index could be there */
-+    __u16  ei_leaf_hi; /* high 16 bits of physical block */
-+    __u16  ei_unused;
-+  };
-+
-+/*
-+ * Each block (leaves and indexes), even inode-stored has header.
-+ */
-+struct ext4_extent_header
-+  {
-+    __u16  eh_magic;   /* probably will support different formats */
-+    __u16  eh_entries; /* number of valid entries */
-+    __u16  eh_max;     /* capacity of store in entries */
-+    __u16  eh_depth;   /* has tree real underlying blocks? */
-+    __u32  eh_generation;  /* generation of the tree */
-+  };
-+
-+#define EXT4_EXT_MAGIC      (0xf30a)
-+#define EXT_FIRST_EXTENT(__hdr__) \
-+    ((struct ext4_extent *) (((char *) (__hdr__)) +     \
-+                 sizeof(struct ext4_extent_header)))
-+#define EXT_FIRST_INDEX(__hdr__) \
-+    ((struct ext4_extent_idx *) (((char *) (__hdr__)) + \
-+                 sizeof(struct ext4_extent_header)))
-+#define EXT_LAST_EXTENT(__hdr__) \
-+    (EXT_FIRST_EXTENT((__hdr__)) + (__u16)((__hdr__)->eh_entries) - 1)
-+#define EXT_LAST_INDEX(__hdr__) \
-+    (EXT_FIRST_INDEX((__hdr__)) + (__u16)((__hdr__)->eh_entries) - 1)
-+
-+
-+
- /* linux/ext2fs.h */
- /*
-  * EXT2_DIR_PAD defines the directory entries boundaries
-@@ -271,8 +367,17 @@ struct ext2_dir_entry
- /* kind of from ext2/super.c */
- #define EXT2_BLOCK_SIZE(s)    (1 << EXT2_BLOCK_SIZE_BITS(s))
- /* linux/ext2fs.h */
-+/* sizeof(struct ext2_group_desc) is changed in ext4
-+ * in kernel code, ext2/3 uses sizeof(struct ext2_group_desc) to calculate
-+ * number of desc per block, while ext4 uses superblock->s_desc_size in stead
-+ * superblock->s_desc_size is not available in ext2/3
-+ * */
-+#define EXT2_DESC_SIZE(s) \
-+      (EXT4_HAS_INCOMPAT_FEATURE(s,EXT4_FEATURE_INCOMPAT_64BIT)? \
-+      s->s_desc_size : EXT4_MIN_DESC_SIZE)
- #define EXT2_DESC_PER_BLOCK(s) \
--     (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
-+      (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s))
-+
- /* linux/stat.h */
- #define S_IFMT  00170000
- #define S_IFLNK  0120000
-@@ -434,6 +539,122 @@ ext2fs_block_map (int logical_block)
-     [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
- }
-+/* extent binary search index
-+ * find closest index in the current level extent tree
-+ * kind of from ext4_ext_binsearch_idx in ext4/extents.c
-+ */
-+static struct ext4_extent_idx*
-+ext4_ext_binsearch_idx(struct ext4_extent_header* eh, int logical_block)
-+{
-+  struct ext4_extent_idx *r, *l, *m;
-+  l = EXT_FIRST_INDEX(eh) + 1;
-+  r = EXT_LAST_INDEX(eh);
-+  while (l <= r)
-+    {
-+        m = l + (r - l) / 2;
-+        if (logical_block < m->ei_block)
-+                r = m - 1;
-+        else
-+                l = m + 1;
-+      }
-+  return (struct ext4_extent_idx*)(l - 1);
-+}
-+
-+/* extent binary search
-+ * find closest extent in the leaf level
-+ * kind of from ext4_ext_binsearch in ext4/extents.c
-+ */
-+static struct ext4_extent*
-+ext4_ext_binsearch(struct ext4_extent_header* eh, int logical_block)
-+{
-+  struct ext4_extent *r, *l, *m;
-+  l = EXT_FIRST_EXTENT(eh) + 1;
-+  r = EXT_LAST_EXTENT(eh);
-+  while (l <= r)
-+    {
-+        m = l + (r - l) / 2;
-+        if (logical_block < m->ee_block)
-+                r = m - 1;
-+        else
-+                l = m + 1;
-+      }
-+  return (struct ext4_extent*)(l - 1);
-+}
-+
-+/* Maps extents enabled logical block into physical block via an inode.
-+ * EXT4_HUGE_FILE_FL should be checked before calling this.
-+ */
-+static int
-+ext4fs_block_map (int logical_block)
-+{
-+  struct ext4_extent_header *eh;
-+  struct ext4_extent *ex, *extent;
-+  struct ext4_extent_idx *ei, *index;
-+  int depth;
-+  int i;
-+
-+#ifdef E2DEBUG
-+  unsigned char *i;
-+  for (i = (unsigned char *) INODE;
-+       i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
-+       i++)
-+    {
-+      printf ("%c", "0123456789abcdef"[*i >> 4]);
-+      printf ("%c", "0123456789abcdef"[*i % 16]);
-+      if (!((i + 1 - (unsigned char *) INODE) % 16))
-+      {
-+        printf ("\n");
-+      }
-+      else
-+      {
-+        printf (" ");
-+      }
-+    }
-+  printf ("logical block %d\n", logical_block);
-+#endif /* E2DEBUG */
-+  eh = (struct ext4_extent_header*)INODE->i_block;
-+  if (eh->eh_magic != EXT4_EXT_MAGIC)
-+  {
-+          errnum = ERR_FSYS_CORRUPT;
-+          return -1;
-+  }
-+  while((depth = eh->eh_depth) != 0)
-+      { /* extent index */
-+        if (eh->eh_magic != EXT4_EXT_MAGIC)
-+        {
-+                errnum = ERR_FSYS_CORRUPT;
-+                return -1;
-+        }
-+        ei = ext4_ext_binsearch_idx(eh, logical_block);
-+        if (ei->ei_leaf_hi)
-+      {/* 64bit physical block number not supported */
-+        errnum = ERR_FILELENGTH;
-+        return -1;
-+      }
-+        if (!ext2_rdfsb(ei->ei_leaf_lo, DATABLOCK1))
-+      {
-+        errnum = ERR_FSYS_CORRUPT;
-+        return -1;
-+      }
-+        eh = (struct ext4_extent_header*)DATABLOCK1;
-+      }
-+
-+  /* depth==0, we come to the leaf */
-+  ex = ext4_ext_binsearch(eh, logical_block);
-+  if (ex->ee_start_hi)
-+      {/* 64bit physical block number not supported */
-+        errnum = ERR_FILELENGTH;
-+        return -1;
-+      }
-+  if ((ex->ee_block + ex->ee_len) < logical_block)
-+      {
-+        errnum = ERR_FSYS_CORRUPT;
-+        return -1;
-+      }
-+  return ex->ee_start_lo + logical_block - ex->ee_block;
-+
-+}
-+
- /* preconditions: all preconds of ext2fs_block_map */
- int
- ext2fs_read (char *buf, int len)
-@@ -468,6 +689,11 @@ ext2fs_read (char *buf, int len)
-       /* find the (logical) block component of our location */
-       logical_block = filepos >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
-       offset = filepos & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
-+      /* map extents enabled logical block number to physical fs on-disk block number */
-+      if (EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK,EXT4_FEATURE_INCOMPAT_EXTENTS)
-+                    && INODE->i_flags & EXT4_EXTENTS_FL)
-+          map = ext4fs_block_map (logical_block);
-+      else
-       map = ext2fs_block_map (logical_block);
- #ifdef E2DEBUG
-       printf ("map=%d\n", map);
-@@ -552,7 +778,7 @@ ext2fs_dir (char *dirname)
-   int desc;                   /* index within that group */
-   int ino_blk;                        /* fs pointer of the inode's information */
-   int str_chk = 0;            /* used to hold the results of a string compare */
--  struct ext2_group_desc *gdp;
-+  struct ext4_group_desc *ext4_gdp;
-   struct ext2_inode *raw_inode;       /* inode info corresponding to current_ino */
-   char linkbuf[PATH_MAX];     /* buffer for following symbolic links */
-@@ -598,8 +824,15 @@ ext2fs_dir (char *dirname)
-       {
-         return 0;
-       }
--      gdp = GROUP_DESC;
--      ino_blk = gdp[desc].bg_inode_table +
-+        ext4_gdp = (struct ext4_group_desc *)( (__u8*)GROUP_DESC +
-+                                      desc * EXT2_DESC_SIZE(SUPERBLOCK));
-+        if (EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK, EXT4_FEATURE_INCOMPAT_64BIT)
-+              && (! ext4_gdp->bg_inode_table_hi))
-+      {/* 64bit itable not supported */
-+        errnum = ERR_FILELENGTH;
-+        return -1;
-+      }
-+      ino_blk = ext4_gdp->bg_inode_table +
-       (((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
-        >> log2 (EXT2_INODES_PER_BLOCK (SUPERBLOCK)));
- #ifdef E2DEBUG
-@@ -676,7 +909,10 @@ ext2fs_dir (char *dirname)
-           }
-         linkbuf[filemax + len] = '\0';
--        /* Read the symlink data. */
-+        /* Read the symlink data.
-+         * Slow symlink is extents enabled
-+         * But since grub_read invokes ext2fs_read, nothing to change here
-+         */
-         if (! ext2_is_fast_symlink ())
-           {
-             /* Read the necessary blocks, and reset the file pointer. */
-@@ -687,7 +923,9 @@ ext2fs_dir (char *dirname)
-           }
-         else
-           {
--            /* Copy the data directly from the inode. */
-+            /* Copy the data directly from the inode.
-+             * Fast symlink is not extents enabled
-+             */
-             len = filemax;
-             memmove (linkbuf, (char *) INODE->i_block, len);
-           }
-@@ -721,6 +959,13 @@ ext2fs_dir (char *dirname)
-             errnum = ERR_BAD_FILETYPE;
-             return 0;
-           }
-+        /* if file is too large, just stop and report an error*/
-+        if ( (INODE->i_flags & EXT4_HUGE_FILE_FL) && !(INODE->i_size_high))
-+          {
-+                /* file too large, stop reading */
-+                errnum = ERR_FILELENGTH;
-+                return 0;
-+          }
-         filemax = (INODE->i_size);
-         return 1;
-@@ -775,17 +1020,28 @@ ext2fs_dir (char *dirname)
-           }
-         /* else, find the (logical) block component of our location */
-+        /* ext4 logical block number the same as ext2/3 */
-         blk = loc >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
-         /* we know which logical block of the directory entry we are looking
-            for, now we have to translate that to the physical (fs) block on
-            the disk */
-+        /* map extents enabled logical block number to physical fs on-disk block number */
-+        if (EXT4_HAS_INCOMPAT_FEATURE(SUPERBLOCK,EXT4_FEATURE_INCOMPAT_EXTENTS)
-+                        && INODE->i_flags & EXT4_EXTENTS_FL)
-+              map = ext4fs_block_map (blk);
-+        else
-         map = ext2fs_block_map (blk);
- #ifdef E2DEBUG
-         printf ("fs block=%d\n", map);
- #endif /* E2DEBUG */
-         mapblock2 = -1;
--        if ((map < 0) || !ext2_rdfsb (map, DATABLOCK2))
-+        if (map < 0)
-+        {
-+            *rest = ch;
-+            return 0;
-+        }
-+          if (!ext2_rdfsb (map, DATABLOCK2))
-           {
-             errnum = ERR_FSYS_CORRUPT;
-             *rest = ch;
diff --git a/stubdom/grub.patches/61btrfs.diff b/stubdom/grub.patches/61btrfs.diff
deleted file mode 100644 (file)
index c831a10..0000000
+++ /dev/null
@@ -1,3510 +0,0 @@
-diff -up grub-upstream.wip/AUTHORS.btrfs grub-upstream.wip/AUTHORS
---- grub-upstream.wip/AUTHORS.btrfs    2004-03-27 16:25:17.000000000 +0000
-+++ grub-upstream.wip/AUTHORS  2012-03-20 05:07:09.000000000 +0000
-@@ -41,6 +41,8 @@ Kristoffer Branemyr added VSTa filesyste
- Serguei Tzukanov added JFS and XFS support.
-+Edward Shishkin added Btrfs support.
-+
- Jason Thomas added Linux DAC960 support and support for hiding/unhiding
- logical partitions, and did a significant bugfix for the terminal stuff.
-diff -up grub-upstream.wip/configure.ac.btrfs grub-upstream.wip/configure.ac
---- grub-upstream.wip/configure.ac.btrfs       2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/configure.ac     2012-03-20 05:07:09.000000000 +0000
-@@ -274,6 +274,13 @@ if test x"$enable_reiserfs" != xno; then
-   FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_REISERFS=1"
- fi
-+AC_ARG_ENABLE(btrfs,
-+  [  --disable-btrfs         disable BtrFS support in Stage 2])
-+
-+if test x"$enable_btrfs" != xno; then
-+  FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_BTRFS=1"
-+fi
-+
- AC_ARG_ENABLE(vstafs,
-   [  --disable-vstafs        disable VSTa FS support in Stage 2])
-diff -up grub-upstream.wip/docs/grub.texi.btrfs grub-upstream.wip/docs/grub.texi
---- grub-upstream.wip/docs/grub.texi.btrfs     2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/docs/grub.texi   2012-03-20 05:07:09.000000000 +0000
-@@ -1761,6 +1761,7 @@ itself. Usually, this is put in a filesy
- @itemx jfs_stage1_5
- @itemx minix_stage1_5
- @itemx reiserfs_stage1_5
-+@itemx btrfs_stage1_5
- @itemx vstafs_stage1_5
- @itemx xfs_stage1_5
-diff -up grub-upstream.wip/grub/Makefile.am.btrfs grub-upstream.wip/grub/Makefile.am
---- grub-upstream.wip/grub/Makefile.am.btrfs   2005-02-02 20:38:19.000000000 +0000
-+++ grub-upstream.wip/grub/Makefile.am 2012-03-20 05:07:09.000000000 +0000
-@@ -8,7 +8,7 @@ endif
- AM_CPPFLAGS = -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-       -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
--      -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-+      -DFSYS_BTRFS=1 -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-       -DUSE_MD5_PASSWORDS=1 -DSUPPORT_HERCULES=1 \
-       $(SERIAL_FLAGS) -I$(top_srcdir)/stage2 \
-       -I$(top_srcdir)/stage1 -I$(top_srcdir)/lib
-diff -up grub-upstream.wip/INSTALL.btrfs grub-upstream.wip/INSTALL
---- grub-upstream.wip/INSTALL.btrfs    2005-05-08 02:43:15.000000000 +0000
-+++ grub-upstream.wip/INSTALL  2012-03-20 05:07:09.000000000 +0000
-@@ -207,6 +207,9 @@ operates.
- `--disable-reiserfs'
-      Omit the ReiserFS support in Stage 2.
-+`--disable-btrfs'
-+     Omit the BtrFS support in Stage 2.
-+
- `--disable-vstafs'
-      Omit the VSTa filesystem support in Stage 2.
-diff -up /dev/null grub-upstream.wip/stage2/btrfs.h
---- /dev/null  2009-06-03 06:46:26.160951000 +0000
-+++ grub-upstream.wip/stage2/btrfs.h   2012-03-20 05:07:09.000000000 +0000
-@@ -0,0 +1,1413 @@
-+/* btrfs.h - an extraction from btrfs-progs-0.18/ctree.h into one file
-+ *
-+ * Copyright (C) 2007 Oracle.  All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public
-+ * License v2 as published by the Free Software Foundation.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-+ * General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public
-+ * License along with this program; If not, see <http://www.gnu.org/licenses/>
-+ */
-+
-+/* include/asm-i386/types.h */
-+
-+typedef __signed__ char __s8;
-+typedef unsigned char __u8;
-+typedef __signed__ short __s16;
-+typedef unsigned short __u16;
-+typedef __signed__ int __s32;
-+typedef unsigned int __u32;
-+typedef unsigned long long __u64;
-+typedef __signed__ long long __s64;
-+
-+typedef __s8 s8;
-+typedef __u8 u8;
-+typedef __u16 u16;
-+typedef __u32 u32;
-+typedef __u64 u64;
-+typedef __s64 s64;
-+
-+#define __bitwise
-+
-+typedef u16 __bitwise __le16;
-+typedef u32 __bitwise __le32;
-+typedef u64 __bitwise __le64;
-+
-+/* linux/posix_type.h */
-+typedef long linux_off_t;
-+
-+/* linux/little_endian.h */
-+#define cpu_to_le64(x) ((__u64) (x))
-+#define le64_to_cpu(x) ((__u64) (x))
-+#define cpu_to_le32(x) ((__u32) (x))
-+#define le32_to_cpu(x) ((__u32) (x))
-+#define cpu_to_le16(x) ((__u16) (x))
-+#define le16_to_cpu(x) ((__u16) (x))
-+#define le8_to_cpu(x) ((__u8) (x))
-+#define cpu_to_le8(x) ((__u8) (x))
-+
-+/* linux/stat.h */
-+#define S_IFMT  00170000
-+#define S_IFLNK  0120000
-+#define S_IFREG  0100000
-+#define S_IFDIR  0040000
-+#define S_ISLNK(m)     (((m) & S_IFMT) == S_IFLNK)
-+#define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
-+#define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
-+
-+struct btrfs_root;
-+#define BTRFS_MAGIC "_BHRfS_M"
-+
-+#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
-+#define BTRFS_SUPER_INFO_SIZE 4096
-+
-+#define BTRFS_SUPER_MIRROR_MAX  3
-+#define BTRFS_SUPER_MIRROR_SHIFT 12
-+
-+#define PATH_MAX                1024   /* include/linux/limits.h */
-+#define MAX_LINK_COUNT             5   /* number of symbolic links
-+                                          to follow */
-+#define BTRFS_MAX_LEVEL 8
-+#define BTRFS_ROOT_TREE_OBJECTID 1ULL
-+#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
-+#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
-+#define BTRFS_DEV_TREE_OBJECTID 4ULL
-+#define BTRFS_FS_TREE_OBJECTID 5ULL
-+#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
-+#define BTRFS_CSUM_TREE_OBJECTID 7ULL
-+
-+#define BTRFS_ORPHAN_OBJECTID -5ULL
-+#define BTRFS_TREE_LOG_OBJECTID -6ULL
-+#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
-+#define BTRFS_TREE_RELOC_OBJECTID -8ULL
-+#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
-+#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
-+
-+#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
-+#define BTRFS_FIRST_FREE_OBJECTID 256ULL
-+#define BTRFS_LAST_FREE_OBJECTID -256ULL
-+#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
-+#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
-+
-+
-+#define BTRFS_NAME_LEN 255
-+#define BTRFS_CSUM_SIZE 32
-+#define BTRFS_CSUM_TYPE_CRC32  0
-+
-+static int btrfs_csum_sizes[] = { 4, 0 };
-+
-+/* four bytes for CRC32 */
-+#define BTRFS_CRC32_SIZE 4
-+#define BTRFS_EMPTY_DIR_SIZE 0
-+
-+#define BTRFS_FT_UNKNOWN       0
-+#define BTRFS_FT_REG_FILE      1
-+#define BTRFS_FT_DIR           2
-+#define BTRFS_FT_CHRDEV                3
-+#define BTRFS_FT_BLKDEV                4
-+#define BTRFS_FT_FIFO          5
-+#define BTRFS_FT_SOCK          6
-+#define BTRFS_FT_SYMLINK       7
-+#define BTRFS_FT_XATTR         8
-+#define BTRFS_FT_MAX           9
-+
-+#define BTRFS_UUID_SIZE 16
-+
-+#define BTRFS_DEFAULT_NUM_DEVICES     1
-+#define BTRFS_DEFAULT_NODE_SIZE       4096
-+#define BTRFS_DEFAULT_LEAF_SIZE       4096
-+#define BTRFS_NUM_CACHED_DEVICES      128
-+
-+#define WARN_ON(c)
-+#define cassert(cond) ({ switch (-1) { case (cond): case 0: break; } })
-+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-+
-+#define offsetof(type, memb) \
-+       ((unsigned long)(&((type *)0)->memb))
-+
-+struct btrfs_disk_key {
-+       __le64 objectid;
-+       u8 type;
-+       __le64 offset;
-+} __attribute__ ((__packed__));
-+
-+/* cpu key */
-+struct btrfs_key {
-+       u64 objectid;
-+       u8 type;
-+       u64 offset;
-+} __attribute__ ((__packed__));
-+
-+/* this represents a divice in a chunk tree */
-+struct btrfs_dev_item {
-+       __le64 devid; /* internal device id */
-+       __le64 total_bytes; /* size of the device */
-+       __le64 bytes_used;
-+       __le32 io_align; /* optimal io alignment */
-+       __le32 io_width; /* optimal io width */
-+       __le32 sector_size; /* minimal io size */
-+       __le64 type; /* type and info about this device */
-+       __le64 generation; /* expected generation */
-+        __le64 start_offset; /* of the partition on a device */
-+
-+       /* info for allocation decisions */
-+       __le32 dev_group;
-+
-+        u8 seek_speed; /* 0-100 (100 is fastest) */
-+       u8 bandwidth;  /* 0-100 (100 is fastest) */
-+
-+        u8 uuid[BTRFS_UUID_SIZE]; /* dev uuid generated by btrfs */
-+       u8 fsid[BTRFS_UUID_SIZE]; /* uuid of the host FS */
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_stripe {
-+       __le64 devid;
-+       __le64 offset;
-+       u8 dev_uuid[BTRFS_UUID_SIZE];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_chunk {
-+       /* size of this chunk in bytes */
-+       __le64 length;
-+       __le64 owner; /* objectid of the root referincing this chunk */
-+       __le64 stripe_len;
-+       __le64 type;
-+       __le32 io_align; /* optimal io alignment for this chunk */
-+       __le32 io_width; /* optimal io width for this chunk */
-+       __le32 sector_size; /* minimal io size for this chunk */
-+       __le16 num_stripes;
-+       __le16 sub_stripes; /* sub stripes (for raid10) */
-+       struct btrfs_stripe stripe;
-+} __attribute__ ((__packed__));
-+
-+static inline unsigned long btrfs_chunk_item_size(int num_stripes)
-+{
-+       return sizeof(struct btrfs_chunk) +
-+               sizeof(struct btrfs_stripe) * (num_stripes - 1);
-+}
-+
-+#define BTRFS_FSID_SIZE 16
-+#define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
-+
-+struct btrfs_header {
-+       /* these first four must match the super block */
-+       u8 csum[BTRFS_CSUM_SIZE];
-+       u8 fsid[BTRFS_FSID_SIZE]; /* uuid of the host fs */
-+       __le64 bytenr; /* which block this node is supposed to live in */
-+       __le64 flags;
-+
-+       /* allowed to be different from the super from here on down */
-+       u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
-+       __le64 generation;
-+       __le64 owner;
-+       __le32 nritems;
-+       u8 level;
-+} __attribute__ ((__packed__));
-+
-+#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
-+                               sizeof(struct btrfs_header)) / \
-+                               sizeof(struct btrfs_key_ptr))
-+#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
-+#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
-+#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
-+                                       sizeof(struct btrfs_item) - \
-+                                       sizeof(struct btrfs_file_extent_item))
-+
-+#define BTRFS_SUPER_FLAG_SEEDING       (1ULL << 32)
-+#define BTRFS_SUPER_FLAG_METADUMP      (1ULL << 33)
-+
-+/*
-+ * a portion of superblock which is used
-+ * for chunk translation (up to 14 chunks
-+ * with 3 stripes each.
-+ */
-+#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
-+#define BTRFS_LABEL_SIZE 256
-+
-+/*
-+ * the super block basically lists the main trees of the FS
-+ * it currently lacks any block count etc etc
-+ */
-+
-+struct btrfs_super_block {
-+       u8 csum[BTRFS_CSUM_SIZE];
-+       /* the first 3 fields must match struct btrfs_header */
-+       u8 fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
-+       __le64 bytenr; /* this block number */
-+       __le64 flags;
-+
-+       /* allowed to be different from the btrfs_header from here own down */
-+       __le64 magic;
-+       __le64 generation;
-+       __le64 root;        /* tree root */
-+       __le64 chunk_root;
-+       __le64 log_root;
-+
-+       /* this will help find the new super based on the log root */
-+       __le64 log_root_transid;
-+       __le64 total_bytes;
-+       __le64 bytes_used;
-+       __le64 root_dir_objectid;
-+       __le64 num_devices;
-+       __le32 sectorsize;
-+       __le32 nodesize;
-+       __le32 leafsize;
-+       __le32 stripesize;
-+       __le32 sys_chunk_array_size;
-+       __le64 chunk_root_generation;
-+       __le64 compat_flags;
-+       __le64 compat_ro_flags;
-+       __le64 incompat_flags;
-+       __le16 csum_type;
-+       u8 root_level;
-+       u8 chunk_root_level;
-+       u8 log_root_level;
-+       struct btrfs_dev_item dev_item;
-+
-+       char label[BTRFS_LABEL_SIZE];
-+
-+       /* future expansion */
-+       __le64 reserved[32];
-+       u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * Compat flags that we support.  If any incompat flags are set other than the
-+ * ones specified below then we will fail to mount
-+ */
-+#define BTRFS_FEATURE_COMPAT_SUPP      0x0
-+#define BTRFS_FEATURE_COMPAT_RO_SUPP   0x0
-+#define BTRFS_FEATURE_INCOMPAT_SUPP    0x0
-+
-+/* Item header for per-leaf lookup */
-+struct btrfs_item {
-+       struct btrfs_disk_key key;
-+       __le32 offset;
-+       __le32 size;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * Format of the leaves:
-+ * [item0, item1....itemN] [free space] [dataN...data1, data0]
-+ */
-+struct btrfs_leaf {
-+       struct btrfs_header header;
-+       struct btrfs_item items[];
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * keys-pointers pairs for per-node (non-leaf) lookup
-+ */
-+struct btrfs_key_ptr {
-+       struct btrfs_disk_key key;
-+       __le64 blockptr;
-+       __le64 generation;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_node {
-+       struct btrfs_header header;
-+       struct btrfs_key_ptr ptrs[];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_device {
-+      /* the internal btrfs device id */
-+      u64 devid;
-+      /* the internal grub device representation */
-+      unsigned long drive;
-+      unsigned long part;
-+      unsigned long length;
-+};
-+
-+struct extent_buffer {
-+       /* metadata */
-+       struct btrfs_device dev;
-+       u64 start;
-+       u64 dev_bytenr;
-+       u32 len;
-+       /* data */
-+       char *data;
-+};
-+
-+static inline void read_extent_buffer(struct extent_buffer *eb,
-+                                     void *dst, unsigned long start,
-+                                     unsigned long len)
-+{
-+       memcpy(dst, eb->data + start, len);
-+}
-+
-+static inline void write_extent_buffer(struct extent_buffer *eb,
-+                                      const void *src, unsigned long start,
-+                                      unsigned long len)
-+{
-+       memcpy(eb->data + start, src, len);
-+}
-+
-+/*
-+ * NOTE:
-+ * don't increase a number of levels for grub-0.97!
-+ */
-+typedef enum {
-+       FIRST_EXTERNAL_LOOKUP_POOL,
-+       SECOND_EXTERNAL_LOOKUP_POOL,
-+       INTERNAL_LOOKUP_POOL,
-+       LAST_LOOKUP_POOL
-+} lookup_pool_id;
-+
-+/*             Relationship between lookup pools:
-+ *  depth
-+ *
-+ *    ^             +----> INTERNAL <----+
-+ *    |             |                    |
-+ *    |             |                    |
-+ *    -        FIRST_EXTERNAL     SECOND_EXTERNAL
-+ */
-+
-+struct btrfs_path {
-+       lookup_pool_id lpid;
-+       struct extent_buffer nodes[BTRFS_MAX_LEVEL];
-+       int slots[BTRFS_MAX_LEVEL];
-+};
-+
-+/*
-+ * items in the extent btree are used to record the objectid of the
-+ * owner of the block and the number of references
-+ */
-+struct btrfs_extent_item {
-+       __le32 refs;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_extent_ref {
-+       __le64 root;
-+       __le64 generation;
-+       __le64 objectid;
-+       __le32 num_refs;
-+} __attribute__ ((__packed__));
-+
-+/* dev extents record free space on individual devices.  The owner
-+ * field points back to the chunk allocation mapping tree that allocated
-+ * the extent.  The chunk tree uuid field is a way to double check the owner
-+ */
-+struct btrfs_dev_extent {
-+       __le64 chunk_tree;
-+       __le64 chunk_objectid;
-+       __le64 chunk_offset;
-+       __le64 length;
-+       u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_inode_ref {
-+       __le64 index;
-+       __le16 name_len;
-+       /* name goes here */
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_timespec {
-+       __le64 sec;
-+       __le32 nsec;
-+} __attribute__ ((__packed__));
-+
-+typedef enum {
-+       BTRFS_COMPRESS_NONE = 0,
-+       BTRFS_COMPRESS_ZLIB = 1,
-+       BTRFS_COMPRESS_LAST = 2,
-+} btrfs_compression_type;
-+
-+/* we don't understand any encryption methods right now */
-+typedef enum {
-+       BTRFS_ENCRYPTION_NONE = 0,
-+       BTRFS_ENCRYPTION_LAST = 1,
-+} btrfs_encryption_type;
-+
-+struct btrfs_inode_item {
-+       /* nfs style generation number */
-+       __le64 generation;
-+       /* transid that last touched this inode */
-+       __le64 transid;
-+       __le64 size;
-+       __le64 nbytes;
-+       __le64 block_group;
-+       __le32 nlink;
-+       __le32 uid;
-+       __le32 gid;
-+       __le32 mode;
-+       __le64 rdev;
-+       __le64 flags;
-+
-+       /* modification sequence number for NFS */
-+       __le64 sequence;
-+
-+       /*
-+        * a little future expansion, for more than this we can
-+        * just grow the inode item and version it
-+        */
-+       __le64 reserved[4];
-+       struct btrfs_timespec atime;
-+       struct btrfs_timespec ctime;
-+       struct btrfs_timespec mtime;
-+       struct btrfs_timespec otime;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_dir_item {
-+       struct btrfs_disk_key location;
-+       __le64 transid;
-+       __le16 data_len;
-+       __le16 name_len;
-+       u8 type;
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_root_item {
-+       struct btrfs_inode_item inode;
-+       __le64 generation;
-+       __le64 root_dirid;
-+       __le64 bytenr;
-+       __le64 byte_limit;
-+       __le64 bytes_used;
-+       __le64 last_snapshot;
-+       __le64 flags;
-+       __le32 refs;
-+       struct btrfs_disk_key drop_progress;
-+       u8 drop_level;
-+       u8 level;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * this is used for both forward and backward root refs
-+ */
-+struct btrfs_root_ref {
-+       __le64 dirid;
-+       __le64 sequence;
-+       __le16 name_len;
-+} __attribute__ ((__packed__));
-+
-+#define BTRFS_FILE_EXTENT_INLINE 0
-+#define BTRFS_FILE_EXTENT_REG 1
-+#define BTRFS_FILE_EXTENT_PREALLOC 2
-+
-+struct btrfs_file_extent_item {
-+       /*
-+        * transaction id that created this extent
-+        */
-+       __le64 generation;
-+       /*
-+        * max number of bytes to hold this extent in ram
-+        * when we split a compressed extent we can't know how big
-+        * each of the resulting pieces will be.  So, this is
-+        * an upper limit on the size of the extent in ram instead of
-+        * an exact limit.
-+        */
-+       __le64 ram_bytes;
-+
-+       /*
-+        * 32 bits for the various ways we might encode the data,
-+        * including compression and encryption.  If any of these
-+        * are set to something a given disk format doesn't understand
-+        * it is treated like an incompat flag for reading and writing,
-+        * but not for stat.
-+        */
-+       u8 compression;
-+       u8 encryption;
-+       __le16 other_encoding; /* spare for later use */
-+
-+       /* are we inline data or a real extent? */
-+       u8 type;
-+
-+       /*
-+        * disk space consumed by the extent, checksum blocks are included
-+        * in these numbers
-+        */
-+       __le64 disk_bytenr;
-+       __le64 disk_num_bytes;
-+       /*
-+        * the logical offset in file blocks (no csums)
-+        * this extent record is for.  This allows a file extent to point
-+        * into the middle of an existing extent on disk, sharing it
-+        * between two snapshots (useful if some bytes in the middle of the
-+        * extent have changed
-+        */
-+       __le64 offset;
-+       /*
-+        * the logical number of file blocks (no csums included)
-+        */
-+       __le64 num_bytes;
-+
-+} __attribute__ ((__packed__));
-+
-+struct btrfs_csum_item {
-+       u8 csum;
-+} __attribute__ ((__packed__));
-+
-+/* tag for the radix tree of block groups in ram */
-+#define BTRFS_BLOCK_GROUP_DATA     (1 << 0)
-+#define BTRFS_BLOCK_GROUP_SYSTEM   (1 << 1)
-+#define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
-+#define BTRFS_BLOCK_GROUP_RAID0    (1 << 3)
-+#define BTRFS_BLOCK_GROUP_RAID1    (1 << 4)
-+#define BTRFS_BLOCK_GROUP_DUP     (1 << 5)
-+#define BTRFS_BLOCK_GROUP_RAID10   (1 << 6)
-+
-+struct btrfs_block_group_item {
-+       __le64 used;
-+       __le64 chunk_objectid;
-+       __le64 flags;
-+} __attribute__ ((__packed__));
-+
-+/*
-+ * in ram representation of the tree.  extent_root is used for all allocations
-+ * and for the extent tree extent_root root.
-+ */
-+struct btrfs_root {
-+       struct extent_buffer   node;
-+       char                   data[4096];
-+       struct btrfs_root_item root_item;
-+       u64 objectid;
-+       
-+       /* data allocations are done in sectorsize units */
-+       u32 sectorsize;
-+
-+       /* node allocations are done in nodesize units */
-+       u32 nodesize;
-+
-+       /* leaf allocations are done in leafsize units */
-+       u32 leafsize;
-+
-+       /* leaf allocations are done in leafsize units */
-+       u32 stripesize;
-+};
-+
-+struct btrfs_file_info {
-+      struct btrfs_key key;
-+};
-+
-+struct btrfs_root;
-+struct btrfs_fs_devices;
-+struct btrfs_fs_info {
-+       u8 fsid[BTRFS_FSID_SIZE];
-+       struct btrfs_root fs_root;
-+       struct btrfs_root tree_root;
-+       struct btrfs_root chunk_root;
-+
-+       struct btrfs_file_info file_info; /* currently opened file */
-+       struct btrfs_path paths [LAST_LOOKUP_POOL];
-+
-+       char mbr[SECTOR_SIZE];
-+
-+       int sb_mirror;
-+       u64 sb_transid;
-+       struct btrfs_device sb_dev;
-+       struct btrfs_super_block sb_copy;
-+
-+       struct btrfs_device devices[BTRFS_NUM_CACHED_DEVICES + 1];
-+};
-+
-+/*
-+ * inode items have the data typically returned from stat and store other
-+ * info about object characteristics.  There is one for every file and dir in
-+ * the FS
-+ */
-+#define BTRFS_INODE_ITEM_KEY           1
-+#define BTRFS_INODE_REF_KEY            12
-+#define BTRFS_XATTR_ITEM_KEY           24
-+#define BTRFS_ORPHAN_ITEM_KEY          48
-+
-+#define BTRFS_DIR_LOG_ITEM_KEY  60
-+#define BTRFS_DIR_LOG_INDEX_KEY 72
-+/*
-+ * dir items are the name -> inode pointers in a directory.  There is one
-+ * for every name in a directory.
-+ */
-+#define BTRFS_DIR_ITEM_KEY     84
-+#define BTRFS_DIR_INDEX_KEY    96
-+
-+/*
-+ * extent data is for file data
-+ */
-+#define BTRFS_EXTENT_DATA_KEY  108
-+
-+/*
-+ * csum items have the checksums for data in the extents
-+ */
-+#define BTRFS_CSUM_ITEM_KEY    120
-+/*
-+ * extent csums are stored in a separate tree and hold csums for
-+ * an entire extent on disk.
-+ */
-+#define BTRFS_EXTENT_CSUM_KEY  128
-+
-+/*
-+ * root items point to tree roots.  There are typically in the root
-+ * tree used by the super block to find all the other trees
-+ */
-+#define BTRFS_ROOT_ITEM_KEY    132
-+
-+/*
-+ * root backrefs tie subvols and snapshots to the directory entries that
-+ * reference them
-+ */
-+#define BTRFS_ROOT_BACKREF_KEY 144
-+
-+/*
-+ * root refs make a fast index for listing all of the snapshots and
-+ * subvolumes referenced by a given root.  They point directly to the
-+ * directory item in the root that references the subvol
-+ */
-+#define BTRFS_ROOT_REF_KEY     156
-+
-+/*
-++ * extent items are in the extent map tree.  These record which blocks
-++ * are used, and how many references there are to each block
-++ */
-+#define BTRFS_EXTENT_ITEM_KEY  168
-+#define BTRFS_EXTENT_REF_KEY   180
-+
-+/*
-+ * block groups give us hints into the extent allocation trees.  Which
-+ * blocks are free etc etc
-+ */
-+#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
-+
-+#define BTRFS_DEV_EXTENT_KEY   204
-+#define BTRFS_DEV_ITEM_KEY     216
-+#define BTRFS_CHUNK_ITEM_KEY   228
-+
-+/*
-+ * string items are for debugging.  They just store a short string of
-+ * data in the FS
-+ */
-+#define BTRFS_STRING_ITEM_KEY  253
-+/*
-+ * Inode flags
-+ */
-+#define BTRFS_INODE_NODATASUM          (1 << 0)
-+#define BTRFS_INODE_NODATACOW          (1 << 1)
-+#define BTRFS_INODE_READONLY           (1 << 2)
-+
-+#define read_eb_member(eb, ptr, type, member, result) (                        \
-+       read_extent_buffer(eb, (char *)(result),                        \
-+                          ((unsigned long)(ptr)) +                     \
-+                           offsetof(type, member),                     \
-+                          sizeof(((type *)0)->member)))
-+
-+#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)            \
-+static inline u##bits btrfs_##name(struct extent_buffer *eb)           \
-+{                                                                      \
-+       struct btrfs_header *h = (struct btrfs_header *)eb->data;       \
-+       return le##bits##_to_cpu(h->member);                            \
-+}                                                                      \
-+static inline void btrfs_set_##name(struct extent_buffer *eb,          \
-+                                   u##bits val)                        \
-+{                                                                      \
-+       struct btrfs_header *h = (struct btrfs_header *)eb->data;       \
-+       h->member = cpu_to_le##bits(val);                               \
-+}
-+
-+#define BTRFS_SETGET_FUNCS(name, type, member, bits)                   \
-+static inline u##bits btrfs_##name(struct extent_buffer *eb,           \
-+                                  type *s)                             \
-+{                                                                      \
-+       unsigned long offset = (unsigned long)s;                        \
-+       type *p = (type *) (eb->data + offset);                         \
-+       return le##bits##_to_cpu(p->member);                            \
-+}                                                                      \
-+static inline void btrfs_set_##name(struct extent_buffer *eb,          \
-+                                   type *s, u##bits val)               \
-+{                                                                      \
-+       unsigned long offset = (unsigned long)s;                        \
-+       type *p = (type *) (eb->data + offset);                         \
-+       p->member = cpu_to_le##bits(val);                               \
-+}
-+
-+#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)             \
-+static inline u##bits btrfs_##name(type *s)                            \
-+{                                                                      \
-+       return le##bits##_to_cpu(s->member);                            \
-+}                                                                      \
-+static inline void btrfs_set_##name(type *s, u##bits val)              \
-+{                                                                      \
-+       s->member = cpu_to_le##bits(val);                               \
-+}
-+
-+BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
-+BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
-+BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
-+BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
-+BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
-+BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
-+                  start_offset, 64);
-+BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
-+BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
-+BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
-+BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
-+BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
-+BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
-+                        total_bytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
-+                        bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
-+                        io_align, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
-+                        io_width, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
-+                        sector_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
-+                        dev_group, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
-+                        seek_speed, 8);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
-+                        bandwidth, 8);
-+BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
-+                        generation, 64);
-+
-+static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
-+{
-+       return (char *)d + offsetof(struct btrfs_dev_item, uuid);
-+}
-+
-+static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
-+{
-+       return (char *)d + offsetof(struct btrfs_dev_item, fsid);
-+}
-+
-+BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
-+BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
-+BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
-+BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
-+BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
-+BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
-+BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
-+BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
-+BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
-+BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
-+BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
-+
-+static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
-+{
-+       return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
-+}
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
-+                        stripe_len, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
-+                        io_align, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
-+                        io_width, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
-+                        sector_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
-+                        num_stripes, 16);
-+BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
-+                        sub_stripes, 16);
-+BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
-+
-+static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
-+                                                  int nr)
-+{
-+       unsigned long offset = (unsigned long)c;
-+       offset += offsetof(struct btrfs_chunk, stripe);
-+       offset += nr * sizeof(struct btrfs_stripe);
-+       return (struct btrfs_stripe *)offset;
-+}
-+
-+static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
-+{
-+       return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
-+                                        struct btrfs_chunk *c, int nr)
-+{
-+       return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
-+                                            struct btrfs_chunk *c, int nr,
-+                                            u64 val)
-+{
-+       btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
-+}
-+
-+static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
-+                                        struct btrfs_chunk *c, int nr)
-+{
-+       return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
-+}
-+
-+static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
-+                                            struct btrfs_chunk *c, int nr,
-+                                            u64 val)
-+{
-+       btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
-+}
-+
-+/* struct btrfs_block_group_item */
-+BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
-+                        used, 64);
-+BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
-+                        used, 64);
-+BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
-+                       struct btrfs_block_group_item, chunk_objectid, 64);
-+
-+BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
-+                  struct btrfs_block_group_item, chunk_objectid, 64);
-+BTRFS_SETGET_FUNCS(disk_block_group_flags,
-+                  struct btrfs_block_group_item, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(block_group_flags,
-+                       struct btrfs_block_group_item, flags, 64);
-+
-+/* struct btrfs_inode_ref */
-+BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
-+BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
-+
-+/* struct btrfs_inode_item */
-+BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
-+BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
-+BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
-+BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
-+BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
-+BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
-+BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
-+BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
-+BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
-+BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
-+BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
-+                        struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence,
-+                        struct btrfs_inode_item, generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
-+                        struct btrfs_inode_item, size, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
-+                        struct btrfs_inode_item, nbytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
-+                        struct btrfs_inode_item, block_group, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
-+                        struct btrfs_inode_item, nlink, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
-+                        struct btrfs_inode_item, uid, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
-+                        struct btrfs_inode_item, gid, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
-+                        struct btrfs_inode_item, mode, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
-+                        struct btrfs_inode_item, rdev, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
-+                        struct btrfs_inode_item, flags, 64);
-+
-+BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
-+BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
-+                        sec, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
-+                        nsec, 32);
-+
-+/* struct btrfs_dev_extent */
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
-+                  chunk_tree, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
-+                  chunk_objectid, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
-+                  chunk_offset, 64);
-+BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
-+
-+static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
-+{
-+       unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
-+       return (u8 *)((unsigned long)dev + ptr);
-+}
-+
-+/* struct btrfs_extent_ref */
-+BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
-+BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
-+BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
-+BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
-+
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
-+                        generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
-+                        objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
-+                        num_refs, 32);
-+
-+/* struct btrfs_extent_item */
-+BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
-+BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
-+                        refs, 32);
-+
-+/* struct btrfs_node */
-+BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
-+BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
-+
-+static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
-+{
-+       unsigned long ptr;
-+       ptr = offsetof(struct btrfs_node, ptrs) +
-+               sizeof(struct btrfs_key_ptr) * nr;
-+       return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
-+}
-+
-+static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
-+                                          int nr, u64 val)
-+{
-+       unsigned long ptr;
-+       ptr = offsetof(struct btrfs_node, ptrs) +
-+               sizeof(struct btrfs_key_ptr) * nr;
-+       btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
-+}
-+
-+static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
-+{
-+       unsigned long ptr;
-+       ptr = offsetof(struct btrfs_node, ptrs) +
-+               sizeof(struct btrfs_key_ptr) * nr;
-+       return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
-+}
-+
-+static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
-+                                                int nr, u64 val)
-+{
-+       unsigned long ptr;
-+       ptr = offsetof(struct btrfs_node, ptrs) +
-+               sizeof(struct btrfs_key_ptr) * nr;
-+       btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
-+}
-+
-+static inline unsigned long btrfs_node_key_ptr_offset(int nr)
-+{
-+       return offsetof(struct btrfs_node, ptrs) +
-+               sizeof(struct btrfs_key_ptr) * nr;
-+}
-+
-+static inline void btrfs_node_key(struct extent_buffer *eb,
-+                                 struct btrfs_disk_key *disk_key, int nr)
-+{
-+       unsigned long ptr;
-+       ptr = btrfs_node_key_ptr_offset(nr);
-+       read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
-+                      struct btrfs_key_ptr, key, disk_key);
-+}
-+
-+/* struct btrfs_item */
-+BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
-+BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
-+
-+static inline unsigned long btrfs_item_nr_offset(int nr)
-+{
-+       return offsetof(struct btrfs_leaf, items) +
-+               sizeof(struct btrfs_item) * nr;
-+}
-+
-+static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
-+                                              int nr)
-+{
-+       return (struct btrfs_item *)btrfs_item_nr_offset(nr);
-+}
-+
-+static inline u32 btrfs_item_end(struct extent_buffer *eb,
-+                                struct btrfs_item *item)
-+{
-+       return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
-+}
-+
-+static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
-+{
-+       return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
-+{
-+       return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
-+{
-+       return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
-+}
-+
-+static inline void btrfs_item_key(struct extent_buffer *eb,
-+                          struct btrfs_disk_key *disk_key, int nr)
-+{
-+       struct btrfs_item *item = btrfs_item_nr(eb, nr);
-+       read_eb_member(eb, item, struct btrfs_item, key, disk_key);
-+}
-+
-+/*
-+ * struct btrfs_root_ref
-+ */
-+BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
-+BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
-+BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
-+
-+/* struct btrfs_dir_item */
-+BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
-+BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
-+BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
-+BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
-+
-+static inline void btrfs_dir_item_key(struct extent_buffer *eb,
-+                                     struct btrfs_dir_item *item,
-+                                     struct btrfs_disk_key *key)
-+{
-+       read_eb_member(eb, item, struct btrfs_dir_item, location, key);
-+}
-+
-+/* struct btrfs_disk_key */
-+BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
-+                        objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
-+BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
-+
-+static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
-+                                        struct btrfs_disk_key *disk)
-+{
-+       cpu->offset = le64_to_cpu(disk->offset);
-+       cpu->type = disk->type;
-+       cpu->objectid = le64_to_cpu(disk->objectid);
-+}
-+
-+static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
-+                                        struct btrfs_key *cpu)
-+{
-+       disk->offset = cpu_to_le64(cpu->offset);
-+       disk->type = cpu->type;
-+       disk->objectid = cpu_to_le64(cpu->objectid);
-+}
-+
-+static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
-+                                 struct btrfs_key *key, int nr)
-+{
-+       struct btrfs_disk_key disk_key;
-+       btrfs_node_key(eb, &disk_key, nr);
-+       btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
-+                                 struct btrfs_key *key, int nr)
-+{
-+       struct btrfs_disk_key disk_key;
-+       btrfs_item_key(eb, &disk_key, nr);
-+       btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
-+                                     struct btrfs_dir_item *item,
-+                                     struct btrfs_key *key)
-+{
-+       struct btrfs_disk_key disk_key;
-+       btrfs_dir_item_key(eb, item, &disk_key);
-+       btrfs_disk_key_to_cpu(key, &disk_key);
-+}
-+
-+static inline u8 btrfs_key_type(struct btrfs_key *key)
-+{
-+       return key->type;
-+}
-+
-+static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
-+{
-+       key->type = val;
-+}
-+
-+static inline u64 btrfs_super_devid(struct btrfs_super_block *disk_super)
-+{
-+      return le64_to_cpu(disk_super->dev_item.devid);
-+}
-+
-+/* struct btrfs_header */
-+BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
-+                         generation, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
-+BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
-+BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
-+
-+/* struct btrfs_root_item */
-+BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
-+                  generation, 64);
-+BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
-+BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
-+BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
-+
-+BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
-+                        generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
-+BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
-+BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
-+BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
-+                        last_snapshot, 64);
-+
-+/* struct btrfs_super_block */
-+
-+BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
-+                        generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
-+                        struct btrfs_super_block, sys_chunk_array_size, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
-+                        struct btrfs_super_block, chunk_root_generation, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
-+                        root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
-+                        chunk_root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
-+                        chunk_root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
-+                        log_root, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
-+                        log_root_transid, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
-+                        log_root_level, 8);
-+BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
-+                        total_bytes, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
-+                        bytes_used, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
-+                        sectorsize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
-+                        nodesize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
-+                        leafsize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
-+                        stripesize, 32);
-+BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
-+                        root_dir_objectid, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
-+                        num_devices, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
-+                        compat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
-+                        compat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
-+                        incompat_flags, 64);
-+BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
-+                        csum_type, 16);
-+
-+static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
-+{
-+       int t = btrfs_super_csum_type(s);
-+       //BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
-+       return btrfs_csum_sizes[t];
-+}
-+
-+static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
-+{
-+       return offsetof(struct btrfs_leaf, items);
-+}
-+
-+/* struct btrfs_file_extent_item */
-+BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
-+
-+static inline unsigned long btrfs_file_extent_inline_start(struct
-+                                                  btrfs_file_extent_item *e)
-+{
-+       unsigned long offset = (unsigned long)e;
-+       offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
-+       return offset;
-+}
-+
-+static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
-+{
-+       return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
-+}
-+
-+BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
-+                  disk_bytenr, 64);
-+BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
-+                  generation, 64);
-+BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
-+                  disk_num_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
-+                 offset, 64);
-+BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
-+                  num_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
-+                  ram_bytes, 64);
-+BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
-+                  compression, 8);
-+BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
-+                  encryption, 8);
-+BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
-+                  other_encoding, 16);
-+
-+/* this returns the number of file bytes represented by the inline item.
-+ * If an item is compressed, this is the uncompressed size
-+ */
-+static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
-+                                       struct btrfs_file_extent_item *e)
-+{
-+       return btrfs_file_extent_ram_bytes(eb, e);
-+}
-+
-+/*
-+ * this returns the number of bytes used by the item on disk, minus the
-+ * size of any extent headers.  If a file is compressed on disk, this is
-+ * the compressed size
-+ */
-+static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
-+                                                   struct btrfs_item *e)
-+{
-+       unsigned long offset;
-+       offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
-+       return btrfs_item_size(eb, e) - offset;
-+}
-+
-+static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
-+       if (level == 0)
-+               return root->leafsize;
-+       return root->nodesize;
-+}
-+
-+static inline u32 btrfs_root_level_size(struct btrfs_super_block *sb) {
-+       return btrfs_super_root_level(sb) == 0 ?
-+               btrfs_super_leafsize(sb) :
-+               btrfs_super_nodesize(sb);
-+}
-+
-+static inline u32 btrfs_chunk_root_level_size(struct btrfs_super_block *sb) {
-+       return btrfs_super_chunk_root_level(sb) == 0 ?
-+               btrfs_super_leafsize(sb) :
-+               btrfs_super_nodesize(sb);
-+}
-+
-+/* helper function to cast into the data area of the leaf. */
-+#define btrfs_item_ptr(leaf, slot, type) \
-+       ((type *)(btrfs_leaf_data(leaf) + \
-+       btrfs_item_offset_nr(leaf, slot)))
-+
-+#define btrfs_item_ptr_offset(leaf, slot) \
-+       ((unsigned long)(btrfs_leaf_data(leaf) + \
-+       btrfs_item_offset_nr(leaf, slot)))
-+
-+/*volumes.h */
-+
-+struct btrfs_fs_devices {
-+       u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
-+
-+       /* the device with this id has the most recent coyp of the super */
-+       u64 latest_devid;
-+       u64 latest_trans;
-+       u64 lowest_devid;
-+       int latest_bdev;
-+       int lowest_bdev;
-+       int seeding;
-+       struct btrfs_fs_devices *seed;
-+};
-+
-+struct btrfs_bio_stripe {
-+      struct btrfs_device dev;
-+      u64 physical;
-+};
-+
-+#define MAX_NRSTRIPES 8
-+struct btrfs_multi_bio {
-+       int error;
-+       int num_stripes;
-+       struct btrfs_bio_stripe stripes[MAX_NRSTRIPES];
-+};
-+
-+#define btrfs_multi_bio_size(n) (sizeof(struct btrfs_multi_bio) + \
-+                           (sizeof(struct btrfs_bio_stripe) * (n)))
-+
-+static int aux_tree_lookup(struct btrfs_root *root,
-+                          struct btrfs_key *key,
-+                          struct btrfs_path *path);
-+
-+struct cache_extent {
-+       u64 start;
-+       u64 size;
-+};
-+
-+struct map_lookup {
-+       struct cache_extent ce;
-+       u64 type;
-+       int io_align;
-+       int io_width;
-+       int stripe_len;
-+       int sector_size;
-+       int num_stripes;
-+       int sub_stripes;
-+        struct btrfs_bio_stripe stripes[MAX_NRSTRIPES];
-+};
-+
-+/* "VFS" things */
-+
-+/* file types recognized by grub */
-+typedef enum {
-+       BTRFS_REGULAR_FILE,
-+       BTRFS_DIRECTORY_FILE,
-+       BTRFS_SYMLINK_FILE,
-+       BTRFS_UNKNOWN_FILE
-+} btrfs_file_type;
-+
-+static inline int coord_is_root(struct btrfs_root *root,
-+                               struct btrfs_path *path)
-+{
-+       return btrfs_header_bytenr(&path->nodes[0]) ==
-+               btrfs_header_bytenr(&root->node);
-+}
-+
-+static inline btrfs_file_type btrfs_get_file_type (int mode)
-+{
-+       if (S_ISLNK(mode))
-+               return BTRFS_SYMLINK_FILE;
-+       if (S_ISREG(mode))
-+               return BTRFS_REGULAR_FILE;
-+       if (S_ISDIR(mode))
-+               return BTRFS_DIRECTORY_FILE;
-+       return BTRFS_UNKNOWN_FILE;
-+}
-+
-+#define min_t(type,x,y)                                                       \
-+       ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
-+#define max_t(type,x,y)                                                       \
-+       ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
-+
-+
-+int sys_array_lookup(struct map_lookup *map, u64 logical);
-+int tree_chunk_lookup(struct map_lookup *map,
-+                     u64 logical);
-+int __btrfs_map_block(u64 logical, u64 *length,
-+                     struct btrfs_multi_bio *multi_ret, int mirror_num);
-+int read_tree_block(struct btrfs_root *root,
-+                   struct extent_buffer *eb,
-+                   u64 bytenr, /* logical */
-+                   u32 blocksize,
-+                   u64 parent_transid,
-+                   lookup_pool_id lpid);
-+int check_read_chunk(struct btrfs_key *key,
-+                    struct extent_buffer *leaf,
-+                    struct btrfs_chunk *chunk,
-+                    struct map_lookup *map,
-+                    u64 logical);
-+/*
-+  Local variables:
-+  c-indentation-style: "K&R"
-+  mode-name: "LC"
-+  c-basic-offset: 8
-+  tab-width: 8
-+  fill-column: 80
-+  scroll-step: 1
-+  End:
-+*/
-\ No newline at end of file
-diff -up grub-upstream.wip/stage2/builtins.c.btrfs grub-upstream.wip/stage2/builtins.c
---- grub-upstream.wip/stage2/builtins.c.btrfs  2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/stage2/builtins.c        2012-03-20 05:11:13.000000000 +0000
-@@ -2456,6 +2456,16 @@ install_func (char *arg, int flags)
-         else
- #endif /* GRUB_UTIL */
-           {
-+            /*
-+             * FIXME: Ugly hack.
-+             * Do not write to btrfs partition
-+             * without a help of the file system!
-+             */
-+            if (!strcmp(fsys_table[fsys_type].name, "btrfs"))
-+              {
-+                errnum = ERR_BAD_ARGUMENT;
-+                goto fail;
-+              }
-             if (! devwrite (saved_sector - part_start, 1, stage2_buffer))
-               goto fail;
-           }
-@@ -4281,6 +4291,7 @@ setup_func (char *arg, int flags)
-     {"jfs",      "/jfs_stage1_5"},
-     {"minix",    "/minix_stage1_5"},
-     {"reiserfs", "/reiserfs_stage1_5"},
-+    {"btrfs",    "/btrfs_stage1_5"},
-     {"vstafs",   "/vstafs_stage1_5"},
-     {"xfs",      "/xfs_stage1_5"}
-   };
-diff -up grub-upstream.wip/stage2/disk_io.c.btrfs grub-upstream.wip/stage2/disk_io.c
---- grub-upstream.wip/stage2/disk_io.c.btrfs   2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/stage2/disk_io.c 2012-03-20 05:07:09.000000000 +0000
-@@ -78,6 +78,9 @@ struct fsys_entry fsys_table[NUM_FSYS + 
- # ifdef FSYS_ISO9660
-   {"iso9660", iso9660_mount, iso9660_read, iso9660_dir, 0, 0},
- # endif
-+# ifdef FSYS_BTRFS
-+  {"btrfs", btrfs_mount, btrfs_read, btrfs_dir, 0, btrfs_embed},
-+# endif
-   /* XX FFS should come last as it's superblock is commonly crossing tracks
-      on floppies from track 1 to 2, while others only use 1.  */
- # ifdef FSYS_FFS
-diff -up grub-upstream.wip/stage2/filesys.h.btrfs grub-upstream.wip/stage2/filesys.h
---- grub-upstream.wip/stage2/filesys.h.btrfs   2004-05-14 19:36:43.000000000 +0000
-+++ grub-upstream.wip/stage2/filesys.h 2012-03-20 05:07:09.000000000 +0000
-@@ -77,6 +77,16 @@ int reiserfs_embed (int *start_sector, i
- #define FSYS_REISERFS_NUM 0
- #endif
-+#ifdef FSYS_BTRFS
-+#define FSYS_BTRFS_NUM 1
-+int btrfs_mount (void);
-+int btrfs_read (char *buf, int len);
-+int btrfs_dir (char *dirname);
-+int btrfs_embed (int *start_sector, int needed_sectors);
-+#else
-+#define FSYS_BTRFS_NUM 0
-+#endif
-+
- #ifdef FSYS_VSTAFS
- #define FSYS_VSTAFS_NUM 1
- int vstafs_mount (void);
-@@ -127,8 +137,8 @@ int iso9660_dir (char *dirname);
- #ifndef NUM_FSYS
- #define NUM_FSYS      \
-   (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM     \
--   + FSYS_REISERFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM + FSYS_XFS_NUM        \
--   + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
-+   + FSYS_REISERFS_NUM + FSYS_BTRFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM \
-+   + FSYS_XFS_NUM + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM)
- #endif
- /* defines for the block filesystem info area */
-diff -up /dev/null grub-upstream.wip/stage2/fsys_btrfs.c
---- /dev/null  2009-06-03 06:46:26.160951000 +0000
-+++ grub-upstream.wip/stage2/fsys_btrfs.c      2012-03-20 05:07:09.000000000 +0000
-@@ -0,0 +1,1820 @@
-+/* fsys_btrfs.c - an implementation for the Btrfs filesystem
-+ *
-+ * Copyright 2009 Red Hat, Inc.  All rights reserved.
-+ *
-+ * This program is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 2 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+#ifdef FSYS_BTRFS
-+
-+#include "shared.h"
-+#include "filesys.h"
-+#include "btrfs.h"
-+
-+#define BTRFS_VERBOSE 0
-+
-+/* Cache layouts */
-+
-+#define LOOKUP_CACHE_BUF_SIZE   (4096)
-+#define LOOKUP_CACHE_SIZE       (LOOKUP_CACHE_BUF_SIZE * LAST_LOOKUP_POOL)
-+#define BTRFS_FS_INFO                                                 \
-+      ((struct btrfs_fs_info *)((unsigned long)FSYS_BUF +             \
-+                                LOOKUP_CACHE_SIZE))
-+#define BTRFS_CACHE_SIZE         (sizeof(struct btrfs_fs_info) +      \
-+                                LOOKUP_CACHE_SIZE)
-+#define BTRFS_TREE_ROOT          (&BTRFS_FS_INFO->tree_root)
-+#define BTRFS_CHUNK_ROOT         (&BTRFS_FS_INFO->chunk_root)
-+#define BTRFS_FS_ROOT            (&BTRFS_FS_INFO->fs_root)
-+#define BTRFS_SUPER              (&BTRFS_FS_INFO->sb_copy)
-+#define BTRFS_DEVICES            (&BTRFS_FS_INFO->devices[0])
-+#define BTRFS_FILE_INFO          (&BTRFS_FS_INFO->file_info)
-+#define BTRFS_FILE_INFO_KEY      (&BTRFS_FILE_INFO->key)
-+
-+#define BTRFS_VOLATILE_DEV_CACHE                                      \
-+      (&BTRFS_FS_INFO->devices[BTRFS_NUM_CACHED_DEVICES])
-+
-+#define LOOKUP_CACHE_BUF(id) ((char *)((unsigned long)FSYS_BUF +      \
-+                                     id * LOOKUP_CACHE_BUF_SIZE))
-+
-+#define noop   do {; } while (0)
-+
-+#if BTRFS_VERBOSE
-+#define btrfs_msg(format, ...) printf(format , ## __VA_ARGS__)
-+#else
-+#define btrfs_msg(format, args...) noop
-+#endif
-+
-+/* compile-time check to make sure we don't overlap
-+   filesystem buffer */
-+static inline void check_btrfs_cache_size(void)
-+{
-+      cassert(BTRFS_CACHE_SIZE <= FSYS_BUFLEN);
-+}
-+
-+static inline u64 btrfs_sb_offset(int mirror)
-+{
-+      u64 start = 16 * 1024;
-+      if (mirror)
-+              return start << (BTRFS_SUPER_MIRROR_SHIFT * mirror);
-+      return BTRFS_SUPER_INFO_OFFSET;
-+}
-+
-+static inline char *grab_lookup_cache(lookup_pool_id lpid)
-+{
-+      char *buf = LOOKUP_CACHE_BUF(lpid);
-+      memset(buf, 0, LOOKUP_CACHE_BUF_SIZE);
-+      return buf;
-+}
-+
-+static inline struct btrfs_path *btrfs_grab_path(lookup_pool_id lpid)
-+{
-+      return &BTRFS_FS_INFO->paths[lpid];
-+}
-+
-+static inline void btrfs_set_path_key(struct btrfs_path *path,
-+                                    struct btrfs_key *key)
-+{
-+      btrfs_item_key_to_cpu(&path->nodes[0],
-+                            key,
-+                            path->slots[0]);
-+}
-+
-+static inline void btrfs_update_file_info(struct btrfs_path *path)
-+{
-+      btrfs_set_path_key(path, BTRFS_FILE_INFO_KEY);
-+}
-+
-+static inline void btrfs_set_root_dir_key(struct btrfs_key *key)
-+{
-+      key->objectid = BTRFS_FIRST_FREE_OBJECTID;
-+      btrfs_set_key_type(key, BTRFS_INODE_ITEM_KEY);
-+      key->offset = 0;
-+}
-+
-+static inline void copy_extent_buffer(struct extent_buffer *dst,
-+                                    struct extent_buffer *src)
-+{
-+      char *data = dst->data;
-+      memcpy(dst, src, sizeof(*dst));
-+      memcpy(data, src->data, 4096);
-+      dst->data = data;
-+}
-+
-+static inline void move_extent_buffer(struct extent_buffer *dst,
-+                                    struct extent_buffer *src)
-+{
-+      memcpy(dst, src, sizeof(*dst));
-+}
-+
-+static inline void init_btrfs_root (struct btrfs_root *root)
-+{
-+      root->node.data = root->data;
-+}
-+
-+static inline void init_btrfs_path(lookup_pool_id lpid)
-+{
-+      struct btrfs_path *path;
-+      path = btrfs_grab_path(lpid);
-+      path->lpid = lpid;
-+}
-+
-+static inline void init_btrfs_info(void)
-+{
-+      int i;
-+      
-+      memset(BTRFS_FS_INFO, 0, sizeof(struct btrfs_fs_info));
-+      for(i = 0; i < LAST_LOOKUP_POOL; i++)
-+              init_btrfs_path(i);
-+      init_btrfs_root(BTRFS_TREE_ROOT);
-+      init_btrfs_root(BTRFS_CHUNK_ROOT);
-+      init_btrfs_root(BTRFS_FS_ROOT);
-+}
-+
-+static void setup_root(struct btrfs_root *root,
-+                     u32 nodesize,
-+                     u32 leafsize,
-+                     u32 sectorsize,
-+                     u32 stripesize,
-+                     u64 objectid)
-+{
-+      root->nodesize = nodesize;
-+      root->leafsize = leafsize;
-+      root->sectorsize = sectorsize;
-+      root->stripesize = stripesize;
-+      root->objectid = objectid;
-+}
-+
-+/*
-+ * Pick up the latest root of a
-+ * tree with specified @objectid
-+ */
-+static int btrfs_find_last_root(struct btrfs_root *tree_root,
-+                              u64 objectid,
-+                              struct btrfs_root_item *item,
-+                              lookup_pool_id lpid)
-+{
-+      int ret;
-+      int slot;
-+      struct btrfs_key search_key;
-+      struct btrfs_key found_key;
-+      struct btrfs_path *path;
-+
-+      search_key.objectid = objectid;
-+      search_key.type = BTRFS_ROOT_ITEM_KEY;
-+      search_key.offset = (u64)-1;
-+      path = btrfs_grab_path(lpid);
-+
-+      ret = aux_tree_lookup(tree_root, &search_key, path);
-+      if (ret < 0)
-+              return 1;
-+      slot = path->slots[0];
-+      WARN_ON(slot == 0);
-+      slot -= 1;
-+      btrfs_item_key_to_cpu(&path->nodes[0], &found_key, slot);
-+      if (found_key.objectid != objectid)
-+              return 1;
-+      
-+      read_extent_buffer(&path->nodes[0], item,
-+                         btrfs_item_ptr_offset(&path->nodes[0], slot),
-+                         sizeof(*item));
-+      return 0;
-+}
-+
-+static int find_setup_root(struct btrfs_root *tree_root,
-+                         u32 nodesize,
-+                         u32 leafsize,
-+                         u32 sectorsize,
-+                         u32 stripesize,
-+                         u64 objectid,
-+                         struct btrfs_root *dest_root,
-+                         u64 bytenr,
-+                         u32 blocksize,
-+                         u64 generation,
-+                         lookup_pool_id lpid)
-+{
-+      int ret;
-+      struct extent_buffer eb;
-+
-+      setup_root(dest_root,
-+                 nodesize,
-+                 leafsize,
-+                 sectorsize,
-+                 stripesize,
-+                 objectid);
-+      if (tree_root) {
-+              /*
-+               * pick up the latest version
-+               * of the root we want to set up
-+               */
-+              ret = btrfs_find_last_root(tree_root, objectid,
-+                                         &dest_root->root_item,
-+                                         lpid);
-+              if (ret)
-+                      return ret;
-+              bytenr = btrfs_root_bytenr(&dest_root->root_item);
-+              blocksize = btrfs_level_size(dest_root,
-+                                     btrfs_root_level(&dest_root->root_item));
-+              generation = btrfs_root_generation(&dest_root->root_item);
-+      }
-+      ret = read_tree_block(dest_root,
-+                            &eb,
-+                            bytenr,
-+                            blocksize,
-+                            generation,
-+                            lpid);
-+      if (!ret)
-+              return 1;
-+      copy_extent_buffer(&dest_root->node, &eb);
-+      return 0;
-+}
-+
-+static inline int btrfs_strncmp(const char *cs, const char *ct, int count)
-+{
-+      signed char __res = 0;
-+
-+      while (count) {
-+              if ((__res = *cs - *ct++) != 0 || !*cs++)
-+                      break;
-+              count--;
-+      }
-+      return __res;
-+}
-+
-+/*
-+ * the same as devread, but accepts
-+ * device number, start and length.
-+ */
-+static int btrfs_devread(unsigned long drive, unsigned long part,
-+                       unsigned long dev_len, int sector,
-+                       int byte_offset, int byte_len, char *buf)
-+{
-+      if (sector < 0
-+          || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
-+              >= dev_len)) {
-+              errnum = ERR_OUTSIDE_PART;
-+              return 0;
-+      }
-+      sector += byte_offset >> SECTOR_BITS;
-+      byte_offset &= SECTOR_SIZE - 1;
-+#if !defined(STAGE1_5)
-+      if (disk_read_hook && debug)
-+              printf ("<%d, %d, %d>", sector, byte_offset, byte_len);
-+#endif /* !STAGE1_5 */
-+      return rawread(drive, part + sector, byte_offset,
-+                     byte_len, buf);
-+}
-+
-+static int btrfs_check_super(void)
-+{
-+      struct btrfs_super_block *sb = BTRFS_SUPER;
-+
-+      if (sb->nodesize != BTRFS_DEFAULT_NODE_SIZE) {
-+              btrfs_msg("Btrfs node size (%d) != %d unsupported\n",
-+                        sb->nodesize, BTRFS_DEFAULT_NODE_SIZE);
-+              goto error;
-+      }
-+      if (sb->leafsize != BTRFS_DEFAULT_LEAF_SIZE) {
-+              btrfs_msg("Btrfs leaf size (%d) != %d unsupported\n",
-+                        sb->leafsize, BTRFS_DEFAULT_LEAF_SIZE);
-+              goto error;
-+      }
-+      
-+      return 0;
-+error:
-+      return 1;
-+}
-+
-+/* lift the super block */
-+static int btrfs_uptodate_super_copy(struct btrfs_fs_info *fs)
-+{
-+      errnum = ERR_NONE;
-+      btrfs_devread(BTRFS_FS_INFO->sb_dev.drive,
-+                    BTRFS_FS_INFO->sb_dev.part,
-+                    BTRFS_FS_INFO->sb_dev.length,
-+                    btrfs_sb_offset(BTRFS_FS_INFO->sb_mirror) >> SECTOR_BITS,
-+                    0,
-+                    sizeof(struct btrfs_super_block),
-+                    (char *)BTRFS_SUPER);
-+      return btrfs_check_super();
-+}
-+  
-+/*
-+ * Looking for a btrfs super block by magic, @fsid and @devid
-+ * (the last two ones are optional). Update latest transid (if
-+ * any). Return 0, if such super block was found. Otherwise,
-+ * return 1.
-+ *
-+ * NOTE:
-+ * After calling this function the sb_copy of global btrfs_fs_info
-+ * can contain garbage, so the caller is responsible for this to be
-+ * uptodate (see the function btrfs_uptodate_super_copy()).
-+ */
-+static int btrfs_find_super(struct btrfs_device *dev, char *fsid, u64 *devid)
-+{
-+      int i, ret;
-+      int found = 0;
-+
-+      for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-+              ret = btrfs_devread(dev->drive,
-+                                  dev->part,
-+                                  dev->length,
-+                                  btrfs_sb_offset(i) >> SECTOR_BITS,
-+                                  0,
-+                                  sizeof(struct btrfs_super_block),
-+                                  (char *)BTRFS_SUPER);
-+              if (!ret) {
-+                      if (errnum == ERR_OUTSIDE_PART) {
-+                              errnum = ERR_NONE;
-+                              break;
-+                      } else {
-+                              errnum = ERR_NONE;
-+                              continue;
-+                      }
-+              }
-+              if (btrfs_super_bytenr(BTRFS_SUPER) != btrfs_sb_offset(i) ||
-+                  btrfs_strncmp((char *)(&BTRFS_SUPER->magic),
-+                                BTRFS_MAGIC,
-+                                sizeof(BTRFS_SUPER->magic)))
-+                      continue;
-+              if (fsid &&
-+                  btrfs_strncmp(fsid,
-+                                (char *)BTRFS_SUPER->fsid,
-+                                BTRFS_FSID_SIZE))
-+                      return 1;
-+              if (devid &&
-+                  *devid != btrfs_super_devid(BTRFS_SUPER))
-+                      return 1;
-+              found = 1;
-+              dev->devid = btrfs_super_devid(BTRFS_SUPER);
-+
-+              if (btrfs_super_generation(BTRFS_SUPER) >
-+                  BTRFS_FS_INFO->sb_transid) {
-+                      BTRFS_FS_INFO->sb_transid =
-+                              btrfs_super_generation(BTRFS_SUPER);
-+                      BTRFS_FS_INFO->sb_mirror = i;
-+                      BTRFS_FS_INFO->sb_dev.devid =
-+                              btrfs_super_devid(BTRFS_SUPER);
-+                      BTRFS_FS_INFO->sb_dev.drive = dev->drive;
-+                      BTRFS_FS_INFO->sb_dev.part = dev->part;
-+                      BTRFS_FS_INFO->sb_dev.length = dev->length;
-+              }
-+      }
-+      return !found;
-+}
-+
-+/*
-+ * "Discern" a btrfs device by fsid and
-+ * optionaly by devid (if lookup is set).
-+ * Populate persistent device cache (if
-+ * there are free slots).
-+ */
-+static int btrfs_discerner(struct btrfs_device **dev, int lookup)
-+{
-+      if (btrfs_find_super(*dev,
-+                           (char *)BTRFS_FS_INFO->fsid,
-+                           (lookup ? &(*dev)->devid : 0)))
-+              /* not found */
-+              return 0;
-+      if (*dev < BTRFS_VOLATILE_DEV_CACHE) {
-+              /* populate persistent device cache */
-+              memcpy(*dev + 1, *dev, sizeof(struct btrfs_device));
-+              (*dev)++;
-+      }
-+      return 1;
-+}
-+
-+/*
-+ * Scan available grub devices and call discerner
-+ * for them. Return a number of discerned devices
-+ * The scanner was stolen from print_completions().
-+ *
-+ * Preconditions:
-+ * The global structure btrfs_fs_info contains
-+ * the latest valid version of btrfs superblock
-+ * (the field @sb_copy)
-+ */
-+static u64 scan_grub_devices(struct btrfs_device *dev,
-+                           int (*discerner)(struct btrfs_device **, int),
-+                           int lookup)
-+{
-+      int i, j;
-+      u64 count = 0;
-+      struct geometry geom;
-+
-+      for (i = 0; i < 2; i++)
-+              for (j = 0; j < 8; j++) {
-+                      unsigned long part = 0xFFFFFF;
-+                      int type, entry, gpt_count, gpt_size;
-+                      unsigned long offset, ext_offset, gpt_offset;
-+
-+                      dev->drive = (i * 0x80) + j;
-+                      if (get_diskinfo(dev->drive, &geom))
-+                              continue;
-+                      while (1) {
-+                              int ret;
-+                              buf_drive = -1;
-+                              errnum = ERR_NONE;
-+                              ret = next_partition(dev->drive, 0xFFFFFF,
-+                                                   &part, &type, &dev->part,
-+                                                   &dev->length, &offset,
-+                                                   &entry, &ext_offset,
-+                                                   &gpt_offset, &gpt_count,
-+                                                   &gpt_size,
-+                                                   BTRFS_FS_INFO->mbr);
-+                              if (!ret)
-+                                      break;
-+                              if (discerner(&dev, lookup)) {
-+                                      count++;
-+                                      if (lookup)
-+                                              goto exit;
-+                              }
-+                      }
-+              }
-+#if 0
-+      errnum = ERR_NONE;
-+      if (cdrom_drive != GRUB_INVALID_DRIVE &&
-+          !get_diskinfo(cdrom_drive, &geom)) {
-+              dev->drive = cdrom_drive;
-+              dev->part = 0;
-+              dev->length = geom.total_sectors;
-+              if (discerner(&dev, lookup)) {
-+                      count++;
-+                      if (lookup)
-+                              goto exit;
-+              }
-+      }
-+#ifdef SUPPORT_NETBOOT
-+      errnum = ERR_NONE;
-+      if (network_ready &&
-+          !get_diskinfo(NETWORK_DRIVE, &geom)) {
-+              dev->drive = NETWORK_DRIVE;
-+              dev->part = 0;
-+              dev->length = geom.total_sectors;
-+              if (discerner(&dev, lookup)) {
-+                      count++;
-+                      if (lookup)
-+                              goto exit;
-+              }
-+      }
-+#endif /* SUPPORT_NETBOOT */
-+#endif /* 0 */
-+ exit:
-+      return count;
-+}
-+
-+#if 0
-+static int btrfs_next_item(struct btrfs_root *root,
-+                         struct btrfs_path *path);
-+
-+/*
-+ * Scan the chunk tree for dev items
-+ * and call a seeker for all of them.
-+ * Preconditions: chunk root is installed
-+ * to the global btrfs_fs_info.
-+ */
-+static int scan_dev_tree(struct btrfs_device* (*seeker)(u64))
-+{
-+      int ret;
-+      u64 num_devices = 0;
-+      struct btrfs_key key;
-+      struct btrfs_key found_key;
-+      struct btrfs_path *path;
-+      struct btrfs_root *root;
-+
-+      root = BTRFS_CHUNK_ROOT;
-+      path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+      key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
-+      key.type = 0;
-+      key.offset = 0;
-+
-+      ret = aux_tree_lookup(root, &key, path);
-+      if (ret == -1)
-+              goto corrupted;
-+      while (1) {
-+              struct btrfs_device *result;
-+              struct btrfs_dev_item *dev_item;
-+
-+              btrfs_item_key_to_cpu(&path->nodes[0],
-+                                    &found_key,
-+                                    path->slots[0]);
-+              if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID)
-+                      break;
-+              dev_item = btrfs_item_ptr(&path->nodes[0],
-+                                        path->slots[0],
-+                                        struct btrfs_dev_item);
-+              result = seeker(btrfs_device_id(&path->nodes[0], dev_item));
-+              if (result == NULL) {
-+                      btrfs_msg("Btrfs device %llu is not available\n",
-+                                btrfs_device_id(&path->nodes[0], dev_item));
-+                      goto missed_dev;
-+              }
-+              num_devices++;
-+              ret = btrfs_next_item(root, path);
-+              if (ret)
-+                      break;
-+      }
-+      if (num_devices == btrfs_super_num_devices(BTRFS_SUPER))
-+              return 0;
-+ corrupted:
-+      errnum = ERR_FSYS_CORRUPT;
-+      return 1;
-+ missed_dev:
-+      errnum = ERR_FSYS_MOUNT;
-+      return 1;
-+}
-+#endif /* 0 */
-+
-+/*
-+ * Find a grub btrfs device by devid.
-+ * Preconditions: global btrfs_fs_info
-+ * contains a copy of btrfs super block.
-+ *
-+ * Return pointer to the cached device on success.
-+ * Otherwise return NULL.
-+ */
-+static struct btrfs_device *btrfs_lookup_device(u64 devid)
-+{
-+      int i, result;
-+      struct btrfs_device *cdev;
-+
-+      for (i = 0; i < BTRFS_NUM_CACHED_DEVICES; i++) {
-+              cdev = &BTRFS_DEVICES[i];
-+              if (cdev->devid == devid)
-+                      goto found_in_cache;
-+              if (cdev->devid == 0)
-+                      goto not_found_in_cache;
-+      }
-+not_found_in_cache:
-+      cdev = BTRFS_VOLATILE_DEV_CACHE;
-+      cdev->devid = devid;
-+      result = scan_grub_devices(cdev,
-+                                 btrfs_discerner,
-+                                 1);
-+      if (result == 0)
-+              /*
-+               * At mount time we have figured out that
-+               * number of available devices is not less
-+               * then number of devices recorded in the
-+               * super block. Hence we treat this case as
-+               * file system corruption.
-+               */
-+              goto corrupt;
-+      result = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+      if (result)
-+              goto corrupt;
-+found_in_cache:
-+      return cdev;
-+corrupt:
-+      errnum = ERR_FSYS_CORRUPT;
-+      return NULL;
-+}
-+
-+static int btrfs_find_device(struct btrfs_device *dev)
-+{
-+      struct btrfs_device *cdev;
-+
-+      if (btrfs_super_num_devices(BTRFS_SUPER) == 1) {
-+              dev->drive = current_drive;
-+              dev->part = part_start;
-+              dev->length = part_length;
-+              return 0;
-+      }
-+      cdev = btrfs_lookup_device(dev->devid);
-+      if (cdev == NULL)
-+              return 1;
-+      dev->drive  = cdev->drive;
-+      dev->part   = cdev->part;
-+      dev->length = cdev->length;
-+      return 0;
-+}
-+
-+static inline void init_btrfs_volatile_dev_cache(void)
-+{
-+      BTRFS_VOLATILE_DEV_CACHE->devid = 0;
-+      BTRFS_VOLATILE_DEV_CACHE->drive = current_drive;
-+      BTRFS_VOLATILE_DEV_CACHE->part = part_start;
-+      BTRFS_VOLATILE_DEV_CACHE->length = part_length;
-+}
-+
-+/*
-+ * check availability of btrfs devices
-+ * and populate the persistent device cache
-+ */
-+static int btrfs_check_devices(void)
-+{
-+      u64 num_dev;
-+
-+      if (btrfs_super_num_devices(BTRFS_SUPER) == 1)
-+              return 0;
-+      num_dev = scan_grub_devices(BTRFS_DEVICES,
-+                                  btrfs_discerner, 0);
-+      if (btrfs_uptodate_super_copy(BTRFS_FS_INFO))
-+              return 1;
-+      if (num_dev < btrfs_super_num_devices(BTRFS_SUPER)) {
-+              btrfs_msg("Some (%llu) Btrfs devices is not available\n",
-+                        btrfs_super_num_devices(BTRFS_SUPER) - num_dev);
-+              return 1;
-+      }
-+      return 0;
-+}
-+
-+int btrfs_mount(void)
-+{
-+      int ret;
-+
-+      check_btrfs_cache_size();
-+      init_btrfs_info();
-+      init_btrfs_volatile_dev_cache();
-+
-+      ret = btrfs_find_super(BTRFS_VOLATILE_DEV_CACHE, NULL, NULL);
-+      if (ret) {
-+              btrfs_msg("Drive %lu, partition %lu: no Btrfs metadata\n",
-+                        current_drive, part_start);
-+              goto error;
-+      }
-+      ret = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+      if (ret)
-+              goto error;
-+      BTRFS_FS_INFO->sb_transid =
-+              btrfs_super_generation(BTRFS_SUPER);
-+      memcpy(BTRFS_FS_INFO->fsid,
-+             BTRFS_SUPER->fsid,
-+             BTRFS_FSID_SIZE);
-+      ret = btrfs_check_devices();
-+      if (ret)
-+              goto error;
-+      /* setup chunk root */
-+      ret = find_setup_root(NULL,
-+                            btrfs_super_nodesize(BTRFS_SUPER),
-+                            btrfs_super_leafsize(BTRFS_SUPER),
-+                            btrfs_super_sectorsize(BTRFS_SUPER),
-+                            btrfs_super_stripesize(BTRFS_SUPER),
-+                            BTRFS_CHUNK_TREE_OBJECTID,
-+                            BTRFS_CHUNK_ROOT,
-+                            btrfs_super_chunk_root(BTRFS_SUPER),
-+                            btrfs_chunk_root_level_size(BTRFS_SUPER),
-+                            btrfs_super_chunk_root_generation(BTRFS_SUPER),
-+                            FIRST_EXTERNAL_LOOKUP_POOL);
-+      if (ret)
-+              return 0;
-+      /* setup tree root */
-+      ret = find_setup_root(NULL,
-+                            btrfs_super_nodesize(BTRFS_SUPER),
-+                            btrfs_super_leafsize(BTRFS_SUPER),
-+                            btrfs_super_sectorsize(BTRFS_SUPER),
-+                            btrfs_super_stripesize(BTRFS_SUPER),
-+                            BTRFS_ROOT_TREE_OBJECTID,
-+                            BTRFS_TREE_ROOT,
-+                            btrfs_super_root(BTRFS_SUPER),
-+                            btrfs_root_level_size(BTRFS_SUPER),
-+                            btrfs_super_generation(BTRFS_SUPER),
-+                            FIRST_EXTERNAL_LOOKUP_POOL);
-+      if (ret)
-+              return 0;
-+      /* setup fs_root */
-+      ret = find_setup_root(BTRFS_TREE_ROOT,
-+                            btrfs_super_nodesize(BTRFS_SUPER),
-+                            btrfs_super_leafsize(BTRFS_SUPER),
-+                            btrfs_super_sectorsize(BTRFS_SUPER),
-+                            btrfs_super_stripesize(BTRFS_SUPER),
-+                            BTRFS_FS_TREE_OBJECTID,
-+                            BTRFS_FS_ROOT,
-+                            0,
-+                            0,
-+                            0,
-+                            FIRST_EXTERNAL_LOOKUP_POOL);
-+      return !ret;
-+
-+error:
-+      errnum = ERR_FSYS_MOUNT;
-+      return 0;
-+}
-+
-+/*
-+ * Check, whether @chunk is the map for a
-+ * block with @logical block number.
-+ * If yes, then fill the @map.
-+ * Return 1 on affirmative result,
-+ * otherwise return 0.
-+ */
-+int check_read_chunk(struct btrfs_key *key,
-+                          struct extent_buffer *leaf,
-+                          struct btrfs_chunk *chunk,
-+                          struct map_lookup *map,
-+                          u64 logical)
-+{
-+      int i, ret;
-+      u64 chunk_start;
-+      u64 chunk_size;
-+      int num_stripes;
-+
-+      chunk_start = key->offset;
-+      chunk_size = btrfs_chunk_length(leaf, chunk);
-+
-+      if (logical + 1 > chunk_start + chunk_size ||
-+          logical < chunk_start)
-+              /* not a fit */
-+              return 0;
-+      num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
-+      map->ce.start = chunk_start;
-+      map->ce.size = chunk_size;
-+      map->num_stripes = num_stripes;
-+      map->io_width = btrfs_chunk_io_width(leaf, chunk);
-+      map->io_align = btrfs_chunk_io_align(leaf, chunk);
-+      map->sector_size = btrfs_chunk_sector_size(leaf, chunk);
-+      map->stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
-+      map->type = btrfs_chunk_type(leaf, chunk);
-+      map->sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk);
-+
-+      for (i = 0; i < num_stripes; i++) {
-+              map->stripes[i].physical =
-+                      btrfs_stripe_offset_nr(leaf, chunk, i);
-+              map->stripes[i].dev.devid =
-+                      btrfs_stripe_devid_nr(leaf, chunk, i);
-+              ret = btrfs_find_device(&map->stripes[i].dev);
-+              if (ret)
-+                      return 0;
-+      }
-+      return 1;
-+}
-+
-+static void init_extent_buffer(struct extent_buffer *eb,
-+                             struct btrfs_device *dev,
-+                             u64 logical,
-+                             u32 blocksize,
-+                             u64 physical,
-+                             lookup_pool_id lpid)
-+{
-+      if (dev)
-+              memcpy(&eb->dev, dev, sizeof(*dev));
-+      eb->start = logical;
-+      eb->len = blocksize;
-+      eb->dev_bytenr = physical;
-+      eb->data = grab_lookup_cache(lpid);
-+}
-+
-+/*
-+ * Search for a map by logical offset in sys array.
-+ * Return -1 on errors;
-+ * Return 1 if the map is found,
-+ * Return 0 if the map is not found.
-+ */
-+int sys_array_lookup(struct map_lookup *map, u64 logical)
-+{
-+      struct extent_buffer sb;
-+      struct btrfs_disk_key *disk_key;
-+      struct btrfs_chunk *chunk;
-+      struct btrfs_key key;
-+      u32 num_stripes;
-+      u32 array_size;
-+      u32 len = 0;
-+      u8 *ptr;
-+      unsigned long sb_ptr;
-+      u32 cur;
-+      int ret;
-+      int i = 0;
-+
-+      sb.data = (char *)BTRFS_SUPER;
-+      array_size = btrfs_super_sys_array_size(BTRFS_SUPER);
-+
-+      ptr = BTRFS_SUPER->sys_chunk_array;
-+      sb_ptr = offsetof(struct btrfs_super_block, sys_chunk_array);
-+      cur = 0;
-+
-+      while (cur < array_size) {
-+              disk_key = (struct btrfs_disk_key *)ptr;
-+              btrfs_disk_key_to_cpu(&key, disk_key);
-+
-+              len = sizeof(*disk_key);
-+              ptr += len;
-+              sb_ptr += len;
-+              cur += len;
-+
-+              if (key.type == BTRFS_CHUNK_ITEM_KEY) {
-+                      chunk = (struct btrfs_chunk *)sb_ptr;
-+                      ret = check_read_chunk(&key, &sb,
-+                                             chunk, map, logical);
-+                      if (ret)
-+                              /* map is found */
-+                              return ret;
-+                      num_stripes = btrfs_chunk_num_stripes(&sb, chunk);
-+                      len = btrfs_chunk_item_size(num_stripes);
-+              } else {
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      return -1;
-+              }
-+              ptr += len;
-+              sb_ptr += len;
-+              cur += len;
-+              i++;
-+      }
-+      return 0;
-+}
-+
-+/*
-+ * Search for a map by logical offset in the chunk tree.
-+ * Return 1 if map is found, otherwise return 0.
-+ */
-+static int chunk_tree_lookup(struct map_lookup *map,
-+                           u64 logical)
-+{
-+      int ret;
-+      int slot;
-+      struct extent_buffer *leaf;
-+      struct btrfs_key key;
-+      struct btrfs_key found_key;
-+      struct btrfs_chunk *chunk;
-+      struct btrfs_path *path;
-+
-+      path = btrfs_grab_path(INTERNAL_LOOKUP_POOL);
-+
-+      key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
-+      key.offset = logical;
-+      key.type = BTRFS_CHUNK_ITEM_KEY;
-+
-+      ret = aux_tree_lookup(BTRFS_CHUNK_ROOT, &key, path);
-+      if (ret < 0)
-+              return 0;
-+      leaf = &path->nodes[0];
-+      slot = path->slots[0];
-+      if (ret == 1) {
-+              WARN_ON(slot == 0);
-+              slot -= 1;
-+      }
-+      btrfs_item_key_to_cpu(leaf, &found_key, slot);
-+      if (found_key.type != BTRFS_CHUNK_ITEM_KEY)
-+              return 0;
-+      chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
-+      return check_read_chunk(&found_key, leaf,
-+                              chunk, map, logical);
-+}
-+
-+/*
-+ * Btrfs logical/physical block mapper.
-+ * Look for an appropriate map-extent and
-+ * perform a translation. Return 1 on errors.
-+ */
-+static int btrfs_map_block(u64 logical, u64 *length,
-+                         struct btrfs_multi_bio *multi,
-+                         int mirror_num)
-+{
-+      struct map_lookup map;
-+      u64 offset;
-+      u64 stripe_offset;
-+      u64 stripe_nr;
-+      struct cache_extent *ce;
-+      int stripe_index;
-+      int i;
-+      int ret;
-+
-+      memset(&map, 0, sizeof(map));
-+      ret = sys_array_lookup(&map, logical);
-+      if (ret == -1) {
-+              errnum = ERR_FSYS_CORRUPT;
-+              return 1;
-+      }
-+      if (ret == 0) {
-+              ret = chunk_tree_lookup(&map, logical);
-+              if (!ret) {
-+                      /* something should be found! */
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      return 1;
-+              }
-+      }
-+      /* do translation */
-+      ce = &map.ce;
-+
-+      offset = logical - ce->start;
-+      stripe_nr = offset / map.stripe_len;
-+      stripe_offset = stripe_nr * map.stripe_len;
-+      WARN_ON(offset < stripe_offset);
-+
-+      stripe_offset = offset - stripe_offset;
-+
-+      if (map.type & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
-+                       BTRFS_BLOCK_GROUP_RAID10 |
-+                       BTRFS_BLOCK_GROUP_DUP)) {
-+              *length = min_t(u64, ce->size - offset,
-+                            map.stripe_len - stripe_offset);
-+      } else {
-+              *length = ce->size - offset;
-+      }
-+      multi->num_stripes = 1;
-+      stripe_index = 0;
-+      if (map.type & BTRFS_BLOCK_GROUP_RAID1) {
-+              if (mirror_num)
-+                      stripe_index = mirror_num - 1;
-+              else
-+                      stripe_index = stripe_nr % map.num_stripes;
-+      } else if (map.type & BTRFS_BLOCK_GROUP_RAID10) {
-+              int factor = map.num_stripes / map.sub_stripes;
-+
-+              stripe_index = stripe_nr % factor;
-+              stripe_index *= map.sub_stripes;
-+
-+              if (mirror_num)
-+                      stripe_index += mirror_num - 1;
-+              else
-+                      stripe_index = stripe_nr % map.sub_stripes;
-+
-+              stripe_nr = stripe_nr / factor;
-+      } else if (map.type & BTRFS_BLOCK_GROUP_DUP) {
-+              if (mirror_num)
-+                      stripe_index = mirror_num - 1;
-+      } else {
-+              stripe_index = stripe_nr % map.num_stripes;
-+              stripe_nr = stripe_nr / map.num_stripes;
-+      }
-+      WARN_ON(stripe_index >= map.num_stripes);
-+
-+      for (i = 0; i < multi->num_stripes; i++) {
-+              asm("" : "+r"(multi));
-+              multi->stripes[i].physical =
-+                      map.stripes[stripe_index].physical + stripe_offset +
-+                      stripe_nr * map.stripe_len;
-+              memcpy(&multi->stripes[i].dev,
-+                     &map.stripes[stripe_index].dev,
-+                     sizeof(struct btrfs_device));
-+              stripe_index++;
-+      }
-+      return 0;
-+}
-+
-+static u64 read_data_extent(u64 logical_start, u64 to_read, char *pos)
-+{
-+      int ret;
-+      u64 length;
-+      struct btrfs_multi_bio multi;
-+
-+      while (to_read) {
-+              ret = btrfs_map_block(logical_start, &length, &multi, 0);
-+              if (ret) {
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      return ret;
-+              }
-+              if (length > to_read)
-+                      length = to_read;
-+              disk_read_func = disk_read_hook;
-+              ret = btrfs_devread(multi.stripes[0].dev.drive,
-+                                  multi.stripes[0].dev.part,
-+                                  multi.stripes[0].dev.length,
-+                                  multi.stripes[0].physical >> SECTOR_BITS,
-+                                  logical_start & ((u64)SECTOR_SIZE - 1),
-+                                  length,
-+                                  pos);
-+              disk_read_func = NULL;
-+              if (!ret)
-+                      return 1;
-+              btrfs_msg("BTRFS data extent: read %llu bytes\n", length);
-+              to_read -= length;
-+              pos += length;
-+              logical_start += length;
-+      }
-+      return 0;
-+}
-+
-+static int read_extent_from_disk(struct extent_buffer *eb)
-+{
-+      WARN_ON(eb->dev_bytenr % SECTOR_BITS);
-+      return btrfs_devread(eb->dev.drive,
-+                           eb->dev.part,
-+                           eb->dev.length,
-+                           eb->dev_bytenr >> SECTOR_BITS,
-+                           0,
-+                           eb->len,
-+                           eb->data);
-+}
-+
-+static int verify_parent_transid(struct extent_buffer *eb, u64 parent_transid)
-+{
-+      return parent_transid && (btrfs_header_generation(eb) != parent_transid);
-+}
-+
-+static int btrfs_num_copies(u64 logical, u64 len)
-+{
-+      return 1;
-+}
-+
-+static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
-+{
-+      return 0;
-+}
-+
-+static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
-+                  int verify)
-+{
-+      return 0;
-+}
-+
-+/*
-+ * Read a block of logical number @bytenr
-+ * from disk to buffer @eb.
-+ * Return 1 on success.
-+ */
-+int read_tree_block(struct btrfs_root *root,
-+                  struct extent_buffer *eb,
-+                  u64 bytenr, /* logical */
-+                  u32 blocksize,
-+                  u64 parent_transid,
-+                  lookup_pool_id lpid)
-+{
-+      int ret;
-+      int dev_nr;
-+      u64 length;
-+      struct btrfs_multi_bio multi;
-+      int mirror_num = 0;
-+      int num_copies;
-+
-+      dev_nr = 0;
-+      length = blocksize;
-+      while (1) {
-+              ret = btrfs_map_block(bytenr,
-+                                    &length, &multi, mirror_num);
-+              if (ret) {
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      return 0;
-+              }
-+              init_extent_buffer(eb,
-+                                 &multi.stripes[0].dev,
-+                                 bytenr,
-+                                 blocksize,
-+                                 multi.stripes[0].physical,
-+                                 lpid);
-+
-+              ret = read_extent_from_disk(eb);
-+              if (ret &&
-+                  check_tree_block(root, eb) == 0 &&
-+                  csum_tree_block(root, eb, 1) == 0 &&
-+                  verify_parent_transid(eb, parent_transid) == 0)
-+                      return 1;
-+
-+              num_copies = btrfs_num_copies(eb->start, eb->len);
-+              if (num_copies == 1)
-+                      break;
-+              mirror_num++;
-+              if (mirror_num > num_copies)
-+                      break;
-+      }
-+      return 0;
-+}
-+
-+/*
-+ * Read a child pointed by @slot node pointer
-+ * of @parent. Put the result to @parent.
-+ * Return 1 on success.
-+ */
-+static int parent2child(struct btrfs_root *root,
-+                      struct extent_buffer *parent,
-+                      int slot,
-+                      lookup_pool_id lpid)
-+{
-+      int level;
-+
-+      WARN_ON(slot < 0);
-+      WARN_ON(slot >= btrfs_header_nritems(parent));
-+
-+      level = btrfs_header_level(parent);
-+      WARN_ON(level <= 0);
-+
-+      return read_tree_block(root,
-+                             parent,
-+                             btrfs_node_blockptr(parent, slot),
-+                             btrfs_level_size(root, level - 1),
-+                             btrfs_node_ptr_generation(parent, slot),
-+                             lpid);
-+}
-+
-+static int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
-+{
-+      struct btrfs_key k1;
-+
-+      btrfs_disk_key_to_cpu(&k1, disk);
-+
-+      if (k1.objectid > k2->objectid)
-+              return 1;
-+      if (k1.objectid < k2->objectid)
-+              return -1;
-+      if (k1.type > k2->type)
-+              return 1;
-+      if (k1.type < k2->type)
-+              return -1;
-+      if (k1.offset > k2->offset)
-+              return 1;
-+      if (k1.offset < k2->offset)
-+              return -1;
-+      return 0;
-+}
-+
-+static int bin_search(struct extent_buffer *eb, unsigned long p,
-+                    int item_size, struct btrfs_key *key,
-+                    int max, int *slot)
-+{
-+      int low = 0;
-+      int high = max;
-+      int mid;
-+      int ret;
-+      unsigned long offset;
-+      struct btrfs_disk_key *tmp;
-+
-+      while(low < high) {
-+              mid = (low + high) / 2;
-+              offset = p + mid * item_size;
-+
-+              tmp = (struct btrfs_disk_key *)(eb->data + offset);
-+              ret = btrfs_comp_keys(tmp, key);
-+
-+              if (ret < 0)
-+                      low = mid + 1;
-+              else if (ret > 0)
-+                      high = mid;
-+              else {
-+                      *slot = mid;
-+                      return 0;
-+              }
-+      }
-+      *slot = low;
-+      return 1;
-+}
-+
-+/* look for a key in a node */
-+static int node_lookup(struct extent_buffer *eb,
-+                     struct btrfs_key *key,
-+                     int *slot)
-+{
-+      if (btrfs_header_level(eb) == 0) {
-+              return bin_search(eb,
-+                                offsetof(struct btrfs_leaf, items),
-+                                sizeof(struct btrfs_item),
-+                                key, btrfs_header_nritems(eb),
-+                                slot);
-+      } else {
-+              return bin_search(eb,
-+                                offsetof(struct btrfs_node, ptrs),
-+                                sizeof(struct btrfs_key_ptr),
-+                                key, btrfs_header_nritems(eb),
-+                                slot);
-+      }
-+      return -1;
-+}
-+
-+static inline int check_node(struct extent_buffer *buf, int slot)
-+{
-+      return 0;
-+}
-+
-+/*
-+ * Look for an item by key in read-only tree.
-+ * Return 0, if key was found. Return -1 on io errors.
-+ *
-+ * Preconditions: btrfs_mount already executed.
-+ * Postconditions: if returned value is non-negative,
-+ * then path[0] represents the found position in the
-+ * tree. All components of the @path from leaf to root
-+ * are valid except their data buffers (only path[0]
-+ * has valid attached data buffer).
-+ */
-+
-+int aux_tree_lookup(struct btrfs_root *root,
-+                  struct btrfs_key *key,
-+                  struct btrfs_path *path)
-+{
-+      int ret;
-+      int slot = 0;
-+      int level;
-+      struct extent_buffer node;
-+      init_extent_buffer(&node,
-+                         NULL,
-+                         0,
-+                         0,
-+                         0,
-+                         path->lpid);
-+      copy_extent_buffer(&node, &root->node);
-+      do {
-+              level = btrfs_header_level(&node);
-+              ret = check_node(&node, slot);
-+              if (ret)
-+                      return -1;
-+              move_extent_buffer(&path->nodes[level],
-+                                 &node);
-+              ret = node_lookup(&node, key, &slot);
-+              if (ret < 0)
-+                      return ret;
-+              if (level) {
-+                      /*
-+                       * non-leaf,
-+                       * jump to the next level
-+                       */
-+                      if (ret && slot > 0)
-+                              slot -= 1;
-+                      ret = parent2child(root, &node, slot, path->lpid);
-+                      if (ret == 0)
-+                              return -1;
-+              }
-+              path->slots[level] = slot;
-+      } while (level);
-+      return ret;
-+}
-+
-+static int readup_buffer(struct extent_buffer *buf, lookup_pool_id lpid)
-+{
-+      buf->data = grab_lookup_cache(lpid);
-+      return read_extent_from_disk(buf);
-+}
-+
-+/*
-+ * Find the next leaf in accordance with tree order;
-+ * walk up the tree as far as required to find it.
-+ * Returns 0 if something was found, or 1 if there
-+ * are no greater leaves. Returns < 0 on io errors.
-+ *
-+ * Preconditions: all @path components from leaf to
-+ * root have valid meta-data fields. path[0] has a
-+ * valid attached data buffer with initial leaf.
-+ * Postcondition: the same as above, but path[0] has
-+ * an attached data buffer with the next leaf.
-+ */
-+static int btrfs_next_leaf(struct btrfs_root *root,
-+                         struct btrfs_path *path)
-+{
-+      int res;
-+      int slot;
-+      int level = 1;
-+      struct extent_buffer *buf;
-+
-+      while(level < BTRFS_MAX_LEVEL) {
-+              buf = &path->nodes[level];
-+              slot = path->slots[level] + 1;
-+              /*
-+               * lift data on this level
-+               */
-+              res = readup_buffer(buf, path->lpid);
-+              if (!res)
-+                      break;
-+              if (slot >= btrfs_header_nritems(buf)) {
-+                      /* alas, go to parent (if any) */
-+                      level++;
-+                      res = 1;
-+                      continue;
-+              }
-+              break;
-+      }
-+      if (!res)
-+              return 1;
-+      /*
-+       * At this level slot points to
-+       * the subtree we are interested in.
-+       */
-+      path->slots[level] = slot;
-+      while(level) {
-+              struct extent_buffer tmp;
-+              move_extent_buffer(&tmp, &path->nodes[level]);
-+              res = parent2child(root, &tmp, slot, path->lpid);
-+              if (res == 0)
-+                      return -1;
-+              level --;
-+              slot = 0;
-+              move_extent_buffer(&path->nodes[level], &tmp);
-+              path->slots[level] = slot;
-+      }
-+      return 0;
-+}
-+
-+/* Preconditions: path is valid, data buffer
-+ * is attached to leaf node.
-+ * Postcondition: path is updated to point to
-+ * the next position with respect to the tree
-+ * order.
-+ *
-+ * Return -1 on io errors.
-+ * Return 0, if next item was found.
-+ * Return 1, if next item wasn't found (no more items).
-+ */
-+static int btrfs_next_item(struct btrfs_root *root,
-+                         struct btrfs_path *path)
-+{
-+      WARN_ON(path->slots[0] >= btrfs_header_nritems(&path->nodes[0]));
-+
-+      path->slots[0] += 1;
-+
-+      if (path->slots[0] < btrfs_header_nritems(&path->nodes[0]))
-+              return 0;
-+      if (coord_is_root(root, path))
-+              /* no more items */
-+              return 1;
-+      return btrfs_next_leaf(root, path);
-+}
-+
-+/*
-+ * check if we can reuse results of previous
-+ * search for read operation
-+ */
-+static int path_is_valid(struct btrfs_path *path,
-+                       struct btrfs_key *key, u64 offset)
-+{
-+      btrfs_item_key_to_cpu(&path->nodes[0],
-+                            key,
-+                            path->slots[0]);
-+      if (BTRFS_FILE_INFO_KEY->objectid != key->objectid)
-+              return 0;
-+      if (btrfs_key_type(key) == BTRFS_INODE_ITEM_KEY)
-+              return 1;
-+      if (btrfs_key_type(key) != BTRFS_EXTENT_DATA_KEY)
-+              return 0;
-+      return BTRFS_FILE_INFO_KEY->offset <= offset;
-+}
-+
-+/* ->read_func() */
-+int btrfs_read(char *buf, int len)
-+{
-+      int ret;
-+      struct btrfs_root *fs_root;
-+      struct btrfs_path *path;
-+      struct btrfs_key  path_key;
-+      u64 ioff;
-+      u64 bytes;
-+      int to_read;
-+      char *pos = buf;
-+
-+      fs_root = BTRFS_FS_ROOT;
-+      path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+
-+      if (!path_is_valid(path, &path_key, filepos)) {
-+              ret = aux_tree_lookup(fs_root, BTRFS_FILE_INFO_KEY, path);
-+              if (ret < 0)
-+                      errnum = ERR_FSYS_CORRUPT;
-+      }
-+      while (!errnum) {
-+              struct btrfs_item *item;
-+              struct btrfs_file_extent_item *fi;
-+              u64 from;
-+
-+              btrfs_item_key_to_cpu(&path->nodes[0],
-+                                    &path_key,
-+                                    path->slots[0]);
-+              if (BTRFS_FILE_INFO_KEY->objectid != path_key.objectid)
-+                      break;
-+              if (btrfs_key_type(&path_key) != BTRFS_EXTENT_DATA_KEY)
-+                      goto next;
-+              /*
-+               * current position is extent item
-+               */
-+              item = btrfs_item_nr(&path->nodes[0], path->slots[0]);
-+              fi = btrfs_item_ptr(&path->nodes[0],
-+                                  path->slots[0],
-+                                  struct btrfs_file_extent_item);
-+              if (btrfs_file_extent_compression(&path->nodes[0], fi)) {
-+                     btrfs_msg("Btrfs transparent compression unsupported\n");
-+                     errnum = ERR_BAD_FILETYPE;
-+                     goto exit;
-+              }
-+              ioff = filepos - path_key.offset;
-+
-+              switch (btrfs_file_extent_type(&path->nodes[0], fi)) {
-+              case BTRFS_FILE_EXTENT_INLINE:
-+                      bytes = btrfs_file_extent_inline_item_len(&path->
-+                                                                nodes[0],
-+                                                                item);
-+                      if (path_key.offset + bytes < filepos)
-+                              goto next;
-+                      to_read = bytes - ioff;
-+                      if (to_read > len)
-+                              to_read = len;
-+                      from = ioff + btrfs_file_extent_inline_start(fi);
-+                      if (disk_read_hook != NULL) {
-+                              disk_read_func = disk_read_hook;
-+                              ret = btrfs_devread(path->nodes[0].dev.drive,
-+                                                  path->nodes[0].dev.part,
-+                                                  path->nodes[0].dev.length,
-+                                                  path->nodes[0].dev_bytenr >>
-+                                                  SECTOR_BITS,
-+                                                  from,
-+                                                  to_read,
-+                                                  pos);
-+                              disk_read_func = NULL;
-+                              if (ret)
-+                                      goto exit;
-+                      } else
-+                              memcpy(pos,
-+                                     path->nodes[0].data + from,
-+                                     to_read);
-+                      btrfs_msg("BTRFS inline extent: read %d bytes pos %d\n",
-+                                to_read, filepos);
-+                      break;
-+              case BTRFS_FILE_EXTENT_REG:
-+                      bytes = btrfs_file_extent_num_bytes(&path->nodes[0],
-+                                                          fi);
-+                      if (path_key.offset + bytes < filepos)
-+                              goto next;
-+                      to_read = bytes - ioff;
-+                      if (to_read > len)
-+                              to_read = len;
-+                      from = ioff +
-+                              btrfs_file_extent_disk_bytenr(&path->nodes[0],
-+                                                            fi) +
-+                              btrfs_file_extent_offset(&path->nodes[0],
-+                                                       fi);
-+                      ret = read_data_extent(from, to_read, pos);
-+                      if (ret)
-+                              goto exit;
-+                      break;
-+              case BTRFS_FILE_EXTENT_PREALLOC:
-+                      btrfs_msg("Btrfs preallocated extents unsupported\n");
-+                      errnum = ERR_BAD_FILETYPE;
-+                      goto exit;
-+              default:
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      goto exit;
-+              }
-+              len -= to_read;
-+              pos += to_read;
-+              filepos += to_read;
-+              if (len == 0)
-+                      break;
-+              /* not everything was read */
-+      next:
-+              ret = btrfs_next_item(fs_root, path);
-+              if (ret < 0) {
-+                      errnum = ERR_FSYS_CORRUPT;
-+                      break;
-+              }
-+              btrfs_update_file_info(path);
-+              continue;
-+      }
-+exit:
-+      return errnum ? 0 : pos - buf;
-+}
-+
-+static int btrfs_follow_link(struct btrfs_root *root,
-+                           struct btrfs_path *path,
-+                           char **dirname, char *linkbuf,
-+                           int *link_count,
-+                           struct btrfs_inode_item *sd)
-+{
-+      int ret;
-+      int len;
-+      char *name = *dirname;
-+
-+      if (++(*link_count) > MAX_LINK_COUNT) {
-+              errnum = ERR_SYMLINK_LOOP;
-+              return 0;
-+      }
-+      /* calculate remaining name size */
-+      filemax = btrfs_inode_size(&path->nodes[0], sd);
-+      for (len = 0;
-+           name[len] && isspace(name[len]);
-+           len ++);
-+
-+      if (filemax + len > PATH_MAX - 1) {
-+              errnum = ERR_FILELENGTH;
-+              return 0;
-+      }
-+      grub_memmove(linkbuf + filemax, name, len + 1);
-+      btrfs_update_file_info(path);
-+      filepos = 0;
-+      /* extract symlink content */
-+      while (1) {
-+              u64 oid = BTRFS_FILE_INFO_KEY->objectid;
-+              ret = btrfs_next_item(root, path);
-+              if (ret)
-+                      break;
-+              btrfs_update_file_info(path);
-+              if (oid != BTRFS_FILE_INFO_KEY->objectid)
-+                      break;
-+              if (btrfs_key_type(BTRFS_FILE_INFO_KEY) ==
-+                  BTRFS_EXTENT_DATA_KEY)
-+                      goto found;
-+      }
-+      /* no target was found */
-+      errnum = ERR_FSYS_CORRUPT;
-+      return 0;
-+found:
-+      /* fill the rest of linkbuf with the content */
-+      ret = btrfs_read(linkbuf, filemax);
-+      if (ret != filemax) {
-+              errnum = ERR_FSYS_CORRUPT;
-+              return 0;
-+      }
-+      return 1;
-+}
-+
-+static int update_fs_root(struct btrfs_root *fs_root,
-+                        struct btrfs_key *location)
-+{
-+      int ret;
-+      struct btrfs_root *tree_root;
-+
-+      if (location->offset != (u64)-1)
-+              return 0;
-+      tree_root = &BTRFS_FS_INFO->tree_root;
-+      ret = find_setup_root(tree_root,
-+                            tree_root->nodesize,
-+                            tree_root->leafsize,
-+                            tree_root->sectorsize,
-+                            tree_root->stripesize,
-+                            location->objectid,
-+                            fs_root,
-+                            0,
-+                            0,
-+                            0,
-+                            SECOND_EXTERNAL_LOOKUP_POOL);
-+      if (ret)
-+              return ret;
-+      location->objectid = btrfs_root_dirid(&fs_root->root_item);
-+      btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
-+      location->offset = 0;
-+      return 0;
-+}
-+
-+#ifndef STAGE1_5
-+static inline void update_possibilities(void)
-+{
-+      if (print_possibilities > 0)
-+              print_possibilities =
-+                      -print_possibilities;
-+}
-+#endif
-+
-+/*
-+ * Look for a directory item by name.
-+ * Print possibilities, if needed.
-+ * Postconditions: on success @sd_key points
-+ * to the key contained in the directory entry.
-+ */
-+static int btrfs_de_index_by_name(struct btrfs_root *root,
-+                                struct btrfs_path *path,
-+                                char **dirname,
-+                                struct btrfs_key *sd_key)
-+{
-+      char ch;
-+      int ret;
-+      char *rest;
-+      struct btrfs_dir_item *di;
-+#ifndef STAGE1_5
-+      int do_possibilities = 0;
-+#endif
-+      for (; **dirname == '/'; (*dirname)++);
-+      for (rest = *dirname;
-+           (ch = *rest) && !isspace(ch) && ch != '/';
-+           rest++);
-+      *rest = 0; /* for substrung() */
-+#ifndef STAGE1_5
-+      if (print_possibilities && ch != '/')
-+              do_possibilities = 1;
-+#endif
-+      /* scan a directory */
-+      while (1) {
-+              u32 total;
-+              u32 cur = 0;
-+              u32 len;
-+              struct btrfs_key di_key;
-+              struct btrfs_disk_key location;
-+              struct btrfs_item *item;
-+
-+              /* extract next dir entry */
-+              ret = btrfs_next_item(root, path);
-+              if (ret)
-+                      break;
-+              item = btrfs_item_nr(&path->nodes[0],
-+                                   path->slots[0]);
-+              btrfs_item_key_to_cpu(&path->nodes[0],
-+                                    &di_key,
-+                                    path->slots[0]);
-+              if (di_key.objectid != sd_key->objectid)
-+                      /* no more entries */
-+                      break;
-+              di = btrfs_item_ptr(&path->nodes[0],
-+                                  path->slots[0],
-+                                  struct btrfs_dir_item);
-+              /*
-+               * working around special cases:
-+               * btrfs doesn't maintain directory entries
-+               * which contain names "." and ".."
-+               */
-+              if (!substring(".", *dirname)) {
-+#ifndef STAGE1_5
-+                      if (do_possibilities) {
-+                              update_possibilities();
-+                              return 1;
-+                      }
-+#endif
-+                      goto found;
-+              }
-+              if (!substring("..", *dirname)) {
-+                      if (di_key.type != BTRFS_INODE_REF_KEY)
-+                              continue;
-+                      sd_key->objectid = di_key.offset;
-+                      btrfs_set_key_type(sd_key, BTRFS_INODE_ITEM_KEY);
-+                      sd_key->offset = 0;
-+#ifndef STAGE1_5
-+                      if (do_possibilities) {
-+                              update_possibilities();
-+                              return 1;
-+                      }
-+#endif
-+                      goto found;
-+              }
-+              if (di_key.type != BTRFS_DIR_ITEM_KEY)
-+                      continue;
-+              total = btrfs_item_size(&path->nodes[0], item);
-+              /* scan a directory item */
-+              while (cur < total) {
-+                      char tmp;
-+                      int result;
-+                      char *filename;
-+                      char *end_of_name;
-+                      int name_len;
-+                      int data_len;
-+
-+                      btrfs_dir_item_key(&path->nodes[0], di, &location);
-+
-+                      name_len = btrfs_dir_name_len(&path->nodes[0], di);
-+                      data_len = btrfs_dir_data_len(&path->nodes[0], di);
-+
-+                      WARN_ON(name_len > BTRFS_NAME_LEN);
-+
-+                      filename = (char *)(path->nodes[0].data +
-+                                          (unsigned long)(di + 1));
-+                      end_of_name = filename + name_len;
-+                      /*
-+                       * working around not null-terminated
-+                       * directory names in btrfs: just
-+                       * a short-term overwrite of the
-+                       * cache with the following rollback
-+                       * of the change.
-+                       */
-+                      tmp = *end_of_name;
-+                      *end_of_name = 0;
-+                      result = substring(*dirname, filename);
-+                      *end_of_name = tmp;
-+#ifndef STAGE1_5
-+                      if (do_possibilities) {
-+                              if (result <= 0) {
-+                                      update_possibilities();
-+                                      *end_of_name = 0;
-+                                      print_a_completion(filename);
-+                                      *end_of_name = tmp;
-+                              }
-+                      }
-+                      else
-+#endif
-+                              if (result == 0) {
-+                                    btrfs_dir_item_key_to_cpu(&path->nodes[0],
-+                                                              di, sd_key);
-+                                    goto found;
-+                              }
-+                      len = sizeof(*di) + name_len + data_len;
-+                      di = (struct btrfs_dir_item *)((char *)di + len);
-+                      cur += len;
-+              }
-+      }
-+#ifndef STAGE1_5
-+      if (print_possibilities < 0)
-+              return 1;
-+#endif
-+      errnum = ERR_FILE_NOT_FOUND;
-+      *rest = ch;
-+      return 0;
-+ found:
-+      *rest = ch;
-+      *dirname = rest;
-+      return 1;
-+}
-+
-+/*
-+ * ->dir_func().
-+ * Postcondition: on a non-zero return BTRFS_FS_INFO
-+ * contains the latest fs_root of file's subvolume.
-+ * BTRFS_FS_INFO points to a subvolume of a file we
-+ * were trying to look up.
-+ * BTRFS_FILE_INFO contains info of the file we were
-+ * trying to look up.
-+ */
-+
-+int btrfs_dir(char *dirname)
-+{
-+      int ret;
-+      int mode;
-+      u64 size;
-+      int linkcount = 0;
-+      char linkbuf[PATH_MAX];
-+
-+      struct btrfs_path *path;
-+      struct btrfs_root *root;
-+
-+      struct btrfs_key sd_key;
-+      struct btrfs_inode_item *sd;
-+      struct btrfs_key parent_sd_key;
-+
-+      root = BTRFS_FS_ROOT;
-+      path = btrfs_grab_path(FIRST_EXTERNAL_LOOKUP_POOL);
-+
-+      btrfs_set_root_dir_key(&sd_key);
-+      while (1) {
-+              struct extent_buffer *leaf;
-+              ret = aux_tree_lookup(root, &sd_key, path);
-+              if (ret)
-+                      return 0;
-+              leaf = &path->nodes[0];
-+              sd = btrfs_item_ptr(leaf,
-+                                  path->slots[0],
-+                                  struct btrfs_inode_item);
-+              mode = btrfs_inode_mode(leaf, sd);
-+              size = btrfs_inode_size(leaf, sd);
-+              switch (btrfs_get_file_type(mode)) {
-+              case BTRFS_SYMLINK_FILE:
-+                      ret = btrfs_follow_link(root,
-+                                              path,
-+                                              &dirname,
-+                                              linkbuf,
-+                                              &linkcount,
-+                                              sd);
-+                      if (!ret)
-+                              return 0;
-+                      dirname = linkbuf;
-+                      if (*dirname == '/')
-+                              /* absolute name */
-+                              btrfs_set_root_dir_key(&sd_key);
-+                      else
-+                              memcpy(&sd_key, &parent_sd_key,
-+                                     sizeof(sd_key));
-+                      continue;
-+              case BTRFS_REGULAR_FILE:
-+                      /*
-+                       * normally we want to exit here
-+                       */
-+                      if (*dirname && !isspace (*dirname)) {
-+                              errnum = ERR_BAD_FILETYPE;
-+                              return 0;
-+                      }
-+                      filepos = 0;
-+                      filemax = btrfs_inode_size(leaf, sd);
-+                      btrfs_update_file_info(path);
-+                      return 1;
-+              case BTRFS_DIRECTORY_FILE:
-+                      memcpy(&parent_sd_key, &sd_key, sizeof(sd_key));
-+                      ret = btrfs_de_index_by_name(root,
-+                                                   path,
-+                                                   &dirname,
-+                                                   &sd_key);
-+                      if (!ret)
-+                              return 0;
-+#ifndef STAGE1_5
-+                      if (print_possibilities < 0)
-+                              return 1;
-+#endif
-+                      /*
-+                       * update fs_tree:
-+                       * subvolume stuff goes here
-+                       */
-+                      ret = update_fs_root(root, &sd_key);
-+                      if (ret)
-+                              return 0;
-+                      continue;
-+              case BTRFS_UNKNOWN_FILE:
-+              default:
-+                      btrfs_msg("Btrfs: bad file type\n");
-+                      errnum = ERR_BAD_FILETYPE;
-+                      return 0;
-+              }
-+      }
-+}
-+
-+int btrfs_embed(int *start_sector, int needed_sectors)
-+{
-+      int ret;
-+      init_btrfs_info();
-+      init_btrfs_volatile_dev_cache();
-+
-+      ret = btrfs_find_super(BTRFS_VOLATILE_DEV_CACHE, NULL, NULL);
-+      if (ret)
-+              return 0;
-+      ret = btrfs_uptodate_super_copy(BTRFS_FS_INFO);
-+      if (ret)
-+              return 0;
-+      *start_sector = 1; /* reserve first sector for stage1 */
-+      return needed_sectors <=
-+              ((BTRFS_SUPER_INFO_OFFSET >> SECTOR_BITS) - 1);
-+}
-+#endif /* FSYS_BTRFS */
-+
-+/*
-+  Local variables:
-+  c-indentation-style: "K&R"
-+  mode-name: "LC"
-+  c-basic-offset: 8
-+  tab-width: 8
-+  fill-column: 80
-+  scroll-step: 1
-+  End:
-+*/
-diff -up grub-upstream.wip/stage2/Makefile.am.btrfs grub-upstream.wip/stage2/Makefile.am
---- grub-upstream.wip/stage2/Makefile.am.btrfs 2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/stage2/Makefile.am       2012-03-20 05:07:09.000000000 +0000
-@@ -17,13 +17,13 @@ INCLUDES = -I$(top_srcdir)/stage1
- noinst_LIBRARIES = libgrub.a
- libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
-       disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ffs.c fsys_iso9660.c \
--      fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
-+      fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_btrfs.c fsys_ufs2.c \
-       fsys_vstafs.c fsys_xfs.c gunzip.c md5.c serial.c stage2.c \
-       terminfo.c tparm.c graphics.c
- libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \
-       -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \
-       -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \
--      -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-+      -DFSYS_BTRFS=1 -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \
-       -DUSE_MD5_PASSWORDS=1 -DSUPPORT_SERIAL=1 -DSUPPORT_HERCULES=1
- # Stage 2 and Stage 1.5's.
-@@ -34,24 +34,26 @@ EXTRA_PROGRAMS = nbloader.exec pxeloader
- if DISKLESS_SUPPORT
- pkglib_DATA = stage2 stage2_eltorito e2fs_stage1_5 fat_stage1_5 \
-       ffs_stage1_5 iso9660_stage1_5 jfs_stage1_5 minix_stage1_5 \
--      reiserfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 xfs_stage1_5 \
--      nbgrub pxegrub
-+      reiserfs_stage1_5 btrfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 \
-+      xfs_stage1_5 nbgrub pxegrub
- noinst_DATA = pre_stage2 start start_eltorito nbloader pxeloader diskless
- noinst_PROGRAMS = pre_stage2.exec start.exec start_eltorito.exec \
-       e2fs_stage1_5.exec fat_stage1_5.exec ffs_stage1_5.exec \
-       iso9660_stage1_5.exec jfs_stage1_5.exec minix_stage1_5.exec \
--      reiserfs_stage1_5.exec ufs2_stage1_5.exec vstafs_stage1_5.exec \
--      xfs_stage1_5.exec nbloader.exec pxeloader.exec diskless.exec
-+      reiserfs_stage1_5.exec btrfs_stage1_5.exec ufs2_stage1_5.exec \
-+      vstafs_stage1_5.exec xfs_stage1_5.exec nbloader.exec \
-+      pxeloader.exec diskless.exec
- else
- pkglib_DATA = stage2 stage2_eltorito e2fs_stage1_5 fat_stage1_5 \
-       ffs_stage1_5 iso9660_stage1_5 jfs_stage1_5 minix_stage1_5 \
--      reiserfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 xfs_stage1_5
-+      reiserfs_stage1_5 btrfs_stage1_5 ufs2_stage1_5 vstafs_stage1_5 \
-+      xfs_stage1_5
- noinst_DATA = pre_stage2 start start_eltorito
- noinst_PROGRAMS = pre_stage2.exec start.exec start_eltorito.exec \
-       e2fs_stage1_5.exec fat_stage1_5.exec ffs_stage1_5.exec \
-       iso9660_stage1_5.exec jfs_stage1_5.exec minix_stage1_5.exec \
--      reiserfs_stage1_5.exec ufs2_stage1_5.exec vstafs_stage1_5.exec \
--      xfs_stage1_5.exec
-+      reiserfs_stage1_5.exec btrfs_stage1_5.exec ufs2_stage1_5.exec \
-+      vstafs_stage1_5.exec xfs_stage1_5.exec
- endif
- MOSTLYCLEANFILES = $(noinst_PROGRAMS)
-@@ -95,15 +97,17 @@ STAGE1_5_COMPILE = $(STAGE2_COMPILE) -DN
- pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
-       cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
-       fsys_fat.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
--      fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c gunzip.c \
--      hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c \
--      graphics.c
-+      fsys_reiserfs.c fsys_btrfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c \
-+      gunzip.c hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c \
-+      tparm.c graphics.c
- pre_stage2_exec_CFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS)
- pre_stage2_exec_LDFLAGS = $(PRE_STAGE2_LINK)
- if NETBOOT_SUPPORT
--pre_stage2_exec_LDADD = ../netboot/libdrivers.a
-+pre_stage2_exec_LDADD = ../netboot/libdrivers.a -lgcc
-+else
-+pre_stage2_exec_LDADD = -lgcc
- endif
- if DISKLESS_SUPPORT
-@@ -197,6 +201,16 @@ reiserfs_stage1_5_exec_CCASFLAGS = $(STA
-       -DNO_BLOCK_FILES=1
- reiserfs_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
-+# For btrfs_stage1_5 target.
-+btrfs_stage1_5_exec_SOURCES = start.S asm.S common.c char_io.c \
-+       disk_io.c stage1_5.c fsys_btrfs.c bios.c
-+btrfs_stage1_5_exec_CFLAGS = $(STAGE1_5_COMPILE) -DFSYS_BTRFS=1 \
-+       -DNO_BLOCK_FILES=1
-+btrfs_stage1_5_exec_CCASFLAGS = $(STAGE1_5_COMPILE) -DFSYS_BTRFS=1 \
-+       -DNO_BLOCK_FILES=1
-+btrfs_stage1_5_exec_LDFLAGS = $(STAGE1_5_LINK)
-+btrfs_stage1_5_exec_LDADD = -lgcc
-+
- # For vstafs_stage1_5 target.
- vstafs_stage1_5_exec_SOURCES = start.S asm.S common.c char_io.c \
-       disk_io.c stage1_5.c fsys_vstafs.c bios.c
-@@ -240,7 +254,7 @@ diskless_exec_CFLAGS = $(STAGE2_COMPILE)
- diskless_exec_CCASFLAGS = $(STAGE2_COMPILE) $(FSYS_CFLAGS) \
-       -DSUPPORT_DISKLESS=1
- diskless_exec_LDFLAGS = $(PRE_STAGE2_LINK)
--diskless_exec_LDADD = ../netboot/libdrivers.a
-+diskless_exec_LDADD = ../netboot/libdrivers.a -lgcc
- diskless_size.h: diskless
-       -rm -f $@
-diff -up grub-upstream.wip/stage2/shared.h.btrfs grub-upstream.wip/stage2/shared.h
---- grub-upstream.wip/stage2/shared.h.btrfs    2012-03-20 05:06:49.000000000 +0000
-+++ grub-upstream.wip/stage2/shared.h  2012-03-20 05:07:09.000000000 +0000
-@@ -207,11 +207,12 @@ extern char *grub_scratch_mem;
- #define STAGE2_ID_FAT_STAGE1_5                3
- #define STAGE2_ID_MINIX_STAGE1_5      4
- #define STAGE2_ID_REISERFS_STAGE1_5   5
--#define STAGE2_ID_VSTAFS_STAGE1_5     6
--#define STAGE2_ID_JFS_STAGE1_5                7
--#define STAGE2_ID_XFS_STAGE1_5                8
--#define STAGE2_ID_ISO9660_STAGE1_5    9
--#define STAGE2_ID_UFS2_STAGE1_5               10
-+#define STAGE2_ID_BTRFS_STAGE1_5      6
-+#define STAGE2_ID_VSTAFS_STAGE1_5     7
-+#define STAGE2_ID_JFS_STAGE1_5                8
-+#define STAGE2_ID_XFS_STAGE1_5                9
-+#define STAGE2_ID_ISO9660_STAGE1_5    10
-+#define STAGE2_ID_UFS2_STAGE1_5               11
- #ifndef STAGE1_5
- # define STAGE2_ID    STAGE2_ID_STAGE2
-@@ -226,6 +227,8 @@ extern char *grub_scratch_mem;
- #  define STAGE2_ID   STAGE2_ID_MINIX_STAGE1_5
- # elif defined(FSYS_REISERFS)
- #  define STAGE2_ID   STAGE2_ID_REISERFS_STAGE1_5
-+# elif defined(FSYS_BTRFS)
-+#  define STAGE2_ID   STAGE2_ID_BTRFS_STAGE1_5
- # elif defined(FSYS_VSTAFS)
- #  define STAGE2_ID   STAGE2_ID_VSTAFS_STAGE1_5
- # elif defined(FSYS_JFS)
diff --git a/stubdom/grub.patches/70compiler_warnings.diff b/stubdom/grub.patches/70compiler_warnings.diff
deleted file mode 100644 (file)
index 15181fc..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-[ 1436s] ../grub-upstream/netboot/fsys_tftp.c:213: warning: operation on 'block' may be undefined
-[ 1437s] ../grub-upstream/netboot/main.c:444: warning: operation on 'block' may be undefined
-
-[ 1234s] E: xen sequence-point ../grub-upstream/netboot/fsys_tftp.c:213
-[ 1234s] E: xen sequence-point ../grub-upstream/netboot/main.c:444
-
----
- netboot/fsys_tftp.c |    5 ++++-
- netboot/main.c      |    5 ++++-
- 2 files changed, 8 insertions(+), 2 deletions(-)
-
-Index: grub-0.97/netboot/fsys_tftp.c
-===================================================================
---- grub-0.97.orig/netboot/fsys_tftp.c
-+++ grub-0.97/netboot/fsys_tftp.c
-@@ -209,8 +209,11 @@ buf_fill (int abort)
-       break;
-       if ((block || bcounter) && (block != prevblock + (unsigned short) 1))
-+      {
-+            block = prevblock;
-       /* Block order should be continuous */
--      tp.u.ack.block = htons (block = prevblock);
-+      tp.u.ack.block = htons (block);
-+      }
-       
-       /* Should be continuous.  */
-       tp.opcode = abort ? htons (TFTP_ERROR) : htons (TFTP_ACK);
-Index: grub-0.97/netboot/main.c
-===================================================================
---- grub-0.97.orig/netboot/main.c
-+++ grub-0.97/netboot/main.c
-@@ -440,8 +440,11 @@ tftp (const char *name, int (*fnc) (unsi
-       break;
-       
-       if ((block || bcounter) && (block != prevblock + 1))
-+      {
-+            block = prevblock;
-       /* Block order should be continuous */
--      tp.u.ack.block = htons (block = prevblock);
-+      tp.u.ack.block = htons (block);
-+      }
-       
-       /* Should be continuous.  */
-       tp.opcode = htons (TFTP_ACK);
diff --git a/stubdom/grub.patches/99minios b/stubdom/grub.patches/99minios
deleted file mode 100644 (file)
index d9b1913..0000000
+++ /dev/null
@@ -1,1570 +0,0 @@
-Index: grub/stage2/builtins.c
-===================================================================
---- grub.orig/stage2/builtins.c        2008-06-16 15:18:14.649009000 +0100
-+++ grub/stage2/builtins.c     2008-06-16 15:18:14.719009000 +0100
-@@ -45,8 +45,10 @@
- #ifdef GRUB_UTIL
- # include <device.h>
- #else /* ! GRUB_UTIL */
-+#ifndef __MINIOS
- # include <apic.h>
- # include <smp-imps.h>
-+#endif
- #endif /* ! GRUB_UTIL */
- #ifdef USE_MD5_PASSWORDS
-@@ -246,11 +248,13 @@
- boot_func (char *arg, int flags)
- {
-   struct term_entry *prev_term = current_term;
-+#ifndef __MINIOS__
-   /* Clear the int15 handler if we can boot the kernel successfully.
-      This assumes that the boot code never fails only if KERNEL_TYPE is
-      not KERNEL_TYPE_NONE. Is this assumption is bad?  */
-   if (kernel_type != KERNEL_TYPE_NONE)
-     unset_int15_handler ();
-+#endif
-   /* if our terminal needed initialization, we should shut it down
-    * before booting the kernel, but we want to save what it was so
-@@ -261,13 +265,21 @@
-       current_term = term_table; /* assumption: console is first */
-     }
-+#ifndef __MINIOS__
- #ifdef SUPPORT_NETBOOT
-   /* Shut down the networking.  */
-   cleanup_net ();
- #endif
-+#endif
-   
-   switch (kernel_type)
-     {
-+#ifdef __MINIOS__
-+    case KERNEL_TYPE_PV:
-+      /* Paravirtualized */
-+      pv_boot();
-+      break;
-+#else
-     case KERNEL_TYPE_FREEBSD:
-     case KERNEL_TYPE_NETBSD:
-       /* *BSD */
-@@ -319,6 +331,7 @@
-       multi_boot ((int) entry_addr, (int) &mbi);
-       break;
-+#endif
-     default:
-       errnum = ERR_BOOT_COMMAND;
-       return 1;
-@@ -1123,6 +1136,7 @@
- };
\f
-+#ifndef __MINIOS__
- /* displayapm */
- static int
- displayapm_func (char *arg, int flags)
-@@ -1163,8 +1177,10 @@
-   "displayapm",
-   "Display APM BIOS information."
- };
-+#endif
\f
-+#ifndef __MINIOS__
- /* displaymem */
- static int
- displaymem_func (char *arg, int flags)
-@@ -1218,6 +1234,7 @@
-   "Display what GRUB thinks the system address space map of the"
-   " machine is, including all regions of physical RAM installed."
- };
-+#endif
\f
- /* dump FROM TO */
-@@ -1280,6 +1297,7 @@
- #endif /* GRUB_UTIL */
\f
-+#ifndef __MINIOS__
- static char embed_info[32];
- /* embed */
- /* Embed a Stage 1.5 in the first cylinder after MBR or in the
-@@ -1413,6 +1431,7 @@
-   " is a drive, or in the \"bootloader\" area if DEVICE is a FFS partition."
-   " Print the number of sectors which STAGE1_5 occupies if successful."
- };
-+#endif
\f
- /* fallback */
-@@ -1956,6 +1975,7 @@
- #endif /* SUPPORT_NETBOOT */
\f
-+#ifndef __MINIOS__
- /* impsprobe */
- static int
- impsprobe_func (char *arg, int flags)
-@@ -1982,6 +2002,7 @@
-   " configuration table and boot the various CPUs which are found into"
-   " a tight loop."
- };
-+#endif
\f
- /* initrd */
-@@ -1992,6 +2013,7 @@
-     {
-     case KERNEL_TYPE_LINUX:
-     case KERNEL_TYPE_BIG_LINUX:
-+    case KERNEL_TYPE_PV:
-       if (! load_initrd (arg))
-       return 1;
-       break;
-@@ -2015,6 +2037,7 @@
- };
\f
-+#ifndef __MINIOS__
- /* install */
- static int
- install_func (char *arg, int flags)
-@@ -2555,8 +2578,10 @@
-   " for LBA mode. If the option `--stage2' is specified, rewrite the Stage"
-   " 2 via your OS's filesystem instead of the raw device."
- };
-+#endif
\f
-+#ifndef __MINIOS__
- /* ioprobe */
- static int
- ioprobe_func (char *arg, int flags)
-@@ -2598,6 +2623,7 @@
-   "ioprobe DRIVE",
-   "Probe I/O ports used for the drive DRIVE."
- };
-+#endif
- /* print */
- static int
-@@ -2910,6 +2910,7 @@
-   switch (kernel_type)
-     {
-     case KERNEL_TYPE_MULTIBOOT:
-+    case KERNEL_TYPE_PV:
-       if (mb_cmdline + len + 1 > (char *) MB_CMDLINE_BUF + MB_CMDLINE_BUFLEN)
-       {
-         errnum = ERR_WONT_FIT;
-@@ -3776,6 +3802,7 @@
- };
\f
-+#ifndef __MINIOS__
- #ifdef SUPPORT_SERIAL
- /* serial */
- static int
-@@ -3927,8 +3954,10 @@
-   " default values are COM1, 9600, 8N1."
- };
- #endif /* SUPPORT_SERIAL */
-+#endif
\f
-+#ifndef __MINIOS__
- /* setkey */
- struct keysym
- {
-@@ -4174,8 +4203,10 @@
-   " is a digit), and delete. If no argument is specified, reset key"
-   " mappings."
- };
-+#endif
\f
-+#ifndef __MINIOS__
- /* setup */
- static int
- setup_func (char *arg, int flags)
-@@ -4484,6 +4515,7 @@
-   " partition where GRUB images reside, specify the option `--stage2'"
-   " to tell GRUB the file name under your OS."
- };
-+#endif
\f
- #if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES) || defined(SUPPORT_GRAPHICS)
-@@ -4788,6 +4820,7 @@
- #endif /* SUPPORT_SERIAL */
-         
\f
-+#ifndef __MINIOS__
- /* testload */
- static int
- testload_func (char *arg, int flags)
-@@ -4874,8 +4907,10 @@
-   " consistent offset error. If this test succeeds, then a good next"
-   " step is to try loading a kernel."
- };
-+#endif
\f
-+#ifndef __MINIOS__
- /* testvbe MODE */
- static int
- testvbe_func (char *arg, int flags)
-@@ -4979,6 +5014,7 @@
-   "testvbe MODE",
-   "Test the VBE mode MODE. Hit any key to return."
- };
-+#endif
\f
- #ifdef SUPPORT_NETBOOT
-@@ -5075,6 +5111,7 @@
- };
\f
-+#ifndef __MINIOS__
- /* uppermem */
- static int
- uppermem_func (char *arg, int flags)
-@@ -5095,8 +5132,10 @@
-   "Force GRUB to assume that only KBYTES kilobytes of upper memory are"
-   " installed.  Any system address range maps are discarded."
- };
-+#endif
\f
-+#ifndef __MINIOS__
- /* vbeprobe */
- static int
- vbeprobe_func (char *arg, int flags)
-@@ -5203,6 +5242,7 @@
-   "Probe VBE information. If the mode number MODE is specified, show only"
-   " the information about only the mode."
- };
-+#endif
-   
\f
- /* The table of builtin commands. Sorted in dictionary order.  */
-@@ -5233,12 +5273,16 @@
- #ifdef SUPPORT_NETBOOT
-   &builtin_dhcp,
- #endif /* SUPPORT_NETBOOT */
-+#ifndef __MINIOS__
-   &builtin_displayapm,
-   &builtin_displaymem,
-+#endif
- #ifdef GRUB_UTIL
-   &builtin_dump,
- #endif /* GRUB_UTIL */
-+#ifndef __MINIOS__
-   &builtin_embed,
-+#endif
-   &builtin_fallback,
-   &builtin_find,
- #ifdef SUPPORT_GRAPHICS
-@@ -5253,10 +5297,14 @@
- #ifdef SUPPORT_NETBOOT
-   &builtin_ifconfig,
- #endif /* SUPPORT_NETBOOT */
-+#ifndef __MINIOS__
-   &builtin_impsprobe,
-+#endif
-   &builtin_initrd,
-+#ifndef __MINIOS__
-   &builtin_install,
-   &builtin_ioprobe,
-+#endif
-   &builtin_kernel,
-   &builtin_lock,
-   &builtin_makeactive,
-@@ -5283,11 +5331,13 @@
-   &builtin_root,
-   &builtin_rootnoverify,
-   &builtin_savedefault,
-+#ifndef __MINIOS__
- #ifdef SUPPORT_SERIAL
-   &builtin_serial,
- #endif /* SUPPORT_SERIAL */
-   &builtin_setkey,
-   &builtin_setup,
-+#endif
- #ifdef SUPPORT_GRAPHICS
-   &builtin_shade,
-   &builtin_splashimage,
-@@ -5298,16 +5348,20 @@
- #ifdef SUPPORT_SERIAL
-   &builtin_terminfo,
- #endif /* SUPPORT_SERIAL */
-+#ifndef __MINIOS__
-   &builtin_testload,
-   &builtin_testvbe,
-+#endif
- #ifdef SUPPORT_NETBOOT
-   &builtin_tftpserver,
- #endif /* SUPPORT_NETBOOT */
-   &builtin_timeout,
-   &builtin_title,
-   &builtin_unhide,
-+#ifndef __MINIOS__
-   &builtin_uppermem,
-   &builtin_vbeprobe,
-+#endif
- #ifdef SUPPORT_GRAPHICS
-   &builtin_viewport,
- #endif
-Index: grub/stage2/char_io.c
-===================================================================
---- grub.orig/stage2/char_io.c 2008-06-16 15:18:14.516009000 +0100
-+++ grub/stage2/char_io.c      2008-06-16 15:18:14.726009000 +0100
-@@ -20,6 +20,7 @@
- #include <shared.h>
- #include <term.h>
-+#include <stdarg.h>
- #ifdef SUPPORT_HERCULES
- # include <hercules.h>
-@@ -36,6 +37,7 @@
- #ifndef STAGE1_5
- struct term_entry term_table[] =
-   {
-+#ifdef SUPPORT_CONSOLE
-     {
-       "console",
-       0,
-@@ -52,6 +54,7 @@
-       0, 
-       0
-     },
-+#endif
- #ifdef SUPPORT_SERIAL
-     {
-       "serial",
-@@ -131,9 +134,9 @@
- }
- char *
--convert_to_ascii (char *buf, int c,...)
-+convert_to_ascii (char *buf, int c, int _num)
- {
--  unsigned long num = *((&c) + 1), mult = 10;
-+  unsigned long num = _num, mult = 10;
-   char *ptr = buf;
- #ifndef STAGE1_5
-@@ -182,11 +185,11 @@
- void
- grub_printf (const char *format,...)
- {
--  int *dataptr = (int *) &format;
-+  va_list ap;
-   char c, str[16];
--  
--  dataptr++;
-+  va_start(ap, format);
-+  
-   while ((c = *(format++)) != 0)
-     {
-       if (c != '%')
-@@ -200,21 +203,32 @@
-         case 'X':
- #endif
-         case 'u':
--          *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
-+        {
-+          unsigned i = va_arg(ap, unsigned);
-+          *convert_to_ascii (str, c, i) = 0;
-           grub_putstr (str);
-           break;
-+          }
- #ifndef STAGE1_5
-         case 'c':
--          grub_putchar ((*(dataptr++)) & 0xff);
-+        {
-+          int c = va_arg(ap, int);
-+          grub_putchar (c & 0xff);
-           break;
-+        }
-         case 's':
--          grub_putstr ((char *) *(dataptr++));
-+        {
-+          char *s = va_arg(ap, char*);
-+          grub_putstr (s);
-           break;
-+        }
- #endif
-         }
-     }
-+
-+  va_end(ap);
- }
- #ifndef STAGE1_5
-@@ -223,11 +237,11 @@
- {
-   /* XXX hohmuth
-      ugly hack -- should unify with printf() */
--  int *dataptr = (int *) &format;
-+  va_list ap;
-   char c, *ptr, str[16];
-   char *bp = buffer;
--  dataptr++;
-+  va_start(ap, format);
-   while ((c = *format++) != 0)
-     {
-@@ -237,20 +251,27 @@
-       switch (c = *(format++))
-         {
-         case 'd': case 'u': case 'x':
--          *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
-+        {
-+          unsigned i = va_arg(ap, unsigned);
-+          *convert_to_ascii (str, c, i) = 0;
-           ptr = str;
-           while (*ptr)
-             *bp++ = *(ptr++); /* putchar(*(ptr++)); */
-           break;
-+        }
--        case 'c': *bp++ = (*(dataptr++))&0xff;
-+        case 'c':
-+        {
-+          int c = va_arg(ap, int);
-+          *bp++ = c&0xff;
-           /* putchar((*(dataptr++))&0xff); */
-           break;
-+        }
-         case 's':
--          ptr = (char *) (*(dataptr++));
-+          ptr = va_arg(ap, char *);
-           while ((c = *ptr++) != 0)
-             *bp++ = c; /* putchar(c); */
-@@ -258,6 +279,8 @@
-         }
-     }
-+  va_end(ap);
-+
-   *bp = 0;
-   return bp - buffer;
- }
-@@ -1263,12 +1286,14 @@
-     return ! errnum;
- #endif /* GRUB_UTIL */
-+#ifndef __MINIOS__
-   if ((addr < RAW_ADDR (0x1000))
-       || (addr < RAW_ADDR (0x100000)
-         && RAW_ADDR (mbi.mem_lower * 1024) < (addr + len))
-       || (addr >= RAW_ADDR (0x100000)
-         && RAW_ADDR (mbi.mem_upper * 1024) < ((addr - 0x100000) + len)))
-     errnum = ERR_WONT_FIT;
-+#endif
-   return ! errnum;
- }
-@@ -1342,7 +1367,7 @@
- }
- #endif /* ! STAGE1_5 */
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- # undef memcpy
- /* GCC emits references to memcpy() for struct copies etc.  */
- void *memcpy (void *dest, const void *src, int n)  __attribute__ ((alias ("grub_memmove")));
-Index: grub/stage2/disk_io.c
-===================================================================
---- grub.orig/stage2/disk_io.c 2008-06-16 15:18:03.327932000 +0100
-+++ grub/stage2/disk_io.c      2008-06-16 15:18:14.733009000 +0100
-@@ -130,7 +130,14 @@
- static inline unsigned long
- log2 (unsigned long word)
- {
--  asm volatile ("bsfl %1,%0"
-+  asm volatile ("bsf"
-+#ifdef __i386__
-+                "l"
-+#endif
-+#ifdef __x86_64__
-+                "q"
-+#endif  
-+                " %1,%0"
-               : "=r" (word)
-               : "r" (word));
-   return word;
-Index: grub/stage2/fsys_fat.c
-===================================================================
---- grub.orig/stage2/fsys_fat.c        2008-06-16 15:18:03.337934000 +0100
-+++ grub/stage2/fsys_fat.c     2008-06-16 15:18:14.737009000 +0100
-@@ -57,7 +57,14 @@
- static __inline__ unsigned long
- log2 (unsigned long word)
- {
--  __asm__ ("bsfl %1,%0"
-+  __asm__ ("bsf"
-+#ifdef __i386__
-+                "l"
-+#endif
-+#ifdef __x86_64__
-+                "q"
-+#endif
-+                " %1,%0"
-          : "=r" (word)
-          : "r" (word));
-   return word;
-Index: grub/stage2/pc_slice.h
-===================================================================
---- grub.orig/stage2/pc_slice.h        2008-06-16 15:18:03.347932000 +0100
-+++ grub/stage2/pc_slice.h     2008-06-16 15:18:14.746009000 +0100
-@@ -38,50 +38,50 @@
-  */
- #define PC_MBR_CHECK_SIG(mbr_ptr) \
--  ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
-+  ( *( (unsigned short *) (((long) mbr_ptr) + PC_MBR_SIG_OFFSET) ) \
-    == PC_MBR_SIGNATURE )
- #define PC_MBR_SIG(mbr_ptr) \
--  ( *( (unsigned short *) (((int) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
-+  ( *( (unsigned short *) (((long) mbr_ptr) + PC_MBR_SIG_OFFSET) ) )
- #define PC_SLICE_FLAG(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET \
-                         + (part << 4)) ) )
- #define PC_SLICE_HEAD(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 1 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 1 \
-                         + (part << 4)) ) )
- #define PC_SLICE_SEC(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 2 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 2 \
-                         + (part << 4)) ) )
- #define PC_SLICE_CYL(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 3 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 3 \
-                         + (part << 4)) ) )
- #define PC_SLICE_TYPE(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 4 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 4 \
-                         + (part << 4)) ) )
- #define PC_SLICE_EHEAD(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 5 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 5 \
-                         + (part << 4)) ) )
- #define PC_SLICE_ESEC(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 6 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 6 \
-                         + (part << 4)) ) )
- #define PC_SLICE_ECYL(mbr_ptr, part) \
--  ( *( (unsigned char *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 7 \
-+  ( *( (unsigned char *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 7 \
-                         + (part << 4)) ) )
- #define PC_SLICE_START(mbr_ptr, part) \
--  ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 8 \
-+  ( *( (unsigned long *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 8 \
-                         + (part << 4)) ) )
- #define PC_SLICE_LENGTH(mbr_ptr, part) \
--  ( *( (unsigned long *) (((int) mbr_ptr) + PC_SLICE_OFFSET + 12 \
-+  ( *( (unsigned long *) (((long) mbr_ptr) + PC_SLICE_OFFSET + 12 \
-                         + (part << 4)) ) )
-Index: grub/stage2/shared.h
-===================================================================
---- grub.orig/stage2/shared.h  2008-06-16 15:18:14.537009000 +0100
-+++ grub/stage2/shared.h       2008-06-17 14:25:08.443906000 +0100
-@@ -39,6 +39,10 @@
- extern char *grub_scratch_mem;
- # define RAW_ADDR(x) ((x) + (int) grub_scratch_mem)
- # define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4)
-+#elif defined(__MINIOS__)
-+extern char grub_scratch_mem[];
-+# define RAW_ADDR(x) ((x) + (int) grub_scratch_mem)
-+# define RAW_SEG(x) (RAW_ADDR ((x) << 4) >> 4)
- #else
- # define RAW_ADDR(x) (x)
- # define RAW_SEG(x) (x)
-@@ -707,7 +711,9 @@
- /* Halt the system, using APM if possible. If NO_APM is true, don't use
-    APM even if it is available.  */
-+#ifndef __MINIOS__
- void grub_halt (int no_apm) __attribute__ ((noreturn));
-+#endif
- /* Copy MAP to the drive map and set up int13_handler.  */
- void set_int13_handler (unsigned short *map);
-@@ -857,7 +863,8 @@
-   KERNEL_TYPE_BIG_LINUX,      /* Big Linux.  */
-   KERNEL_TYPE_FREEBSD,                /* FreeBSD.  */
-   KERNEL_TYPE_NETBSD,         /* NetBSD.  */
--  KERNEL_TYPE_CHAINLOADER     /* Chainloader.  */
-+  KERNEL_TYPE_CHAINLOADER,    /* Chainloader.  */
-+  KERNEL_TYPE_PV              /* Paravirtualized.  */
- }
- kernel_t;
-@@ -890,7 +897,7 @@
- int grub_strlen (const char *str);
- char *grub_strcpy (char *dest, const char *src);
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- typedef unsigned long grub_jmp_buf[6];
- #else
- /* In the grub shell, use the libc jmp_buf instead.  */
-@@ -898,7 +905,7 @@
- # define grub_jmp_buf jmp_buf
- #endif
--#ifdef GRUB_UTIL
-+#if defined(GRUB_UTIL) || defined(__MINIOS__)
- # define grub_setjmp  setjmp
- # define grub_longjmp longjmp
- #else /* ! GRUB_UTIL */
-@@ -914,7 +921,7 @@
- /* misc */
- void init_page (void);
- void print_error (void);
--char *convert_to_ascii (char *buf, int c, ...);
-+char *convert_to_ascii (char *buf, int c, int num);
- int get_cmdline (char *prompt, char *cmdline, int maxlen,
-                int echo_char, int history);
- int substring (const char *s1, const char *s2);
-Index: grub/netboot/etherboot.h
-===================================================================
---- grub.orig/netboot/etherboot.h      2008-06-16 15:18:03.446934000 +0100
-+++ grub/netboot/etherboot.h   2008-06-16 15:18:14.760009000 +0100
-@@ -246,7 +246,7 @@
- typedef struct
- {
--  unsigned long       s_addr;
-+  unsigned int        s_addr;
- }
- in_addr;
-@@ -302,7 +302,7 @@
-   char bp_htype;
-   char bp_hlen;
-   char bp_hops;
--  unsigned long bp_xid;
-+  unsigned int bp_xid;
-   unsigned short bp_secs;
-   unsigned short unused;
-   in_addr bp_ciaddr;
-@@ -411,25 +411,25 @@
-     
-     struct
-     {
--      long id;
--      long type;
--      long rpcvers;
--      long prog;
--      long vers;
--      long proc;
--      long data[1];
-+      int id;
-+      int type;
-+      int rpcvers;
-+      int prog;
-+      int vers;
-+      int proc;
-+      int data[1];
-     }
-     call;
-     
-     struct
-     {
--      long id;
--      long type;
--      long rstatus;
--      long verifier;
--      long v2;
--      long astatus;
--      long data[1];
-+      int id;
-+      int type;
-+      int rstatus;
-+      int verifier;
-+      int v2;
-+      int astatus;
-+      int data[1];
-     }
-     reply;
-   }
-@@ -517,7 +517,9 @@
- /* misc.c */
- extern void twiddle (void);
-+#ifndef __MINIOS__
- extern void sleep (int secs);
-+#endif
- extern int getdec (char **s);
- extern void etherboot_printf (const char *, ...);
- extern int etherboot_sprintf (char *, const char *, ...);
-Index: grub/stage2/common.c
-===================================================================
---- grub.orig/stage2/common.c  2008-06-16 15:18:03.366934000 +0100
-+++ grub/stage2/common.c       2008-06-16 15:18:14.764009000 +0100
-@@ -137,6 +137,7 @@
- }
- #endif /* ! STAGE1_5 */
-+#ifndef __MINIOS__
- /* This queries for BIOS information.  */
- void
- init_bios_info (void)
-@@ -335,3 +336,4 @@
-   /* Start main routine here.  */
-   cmain ();
- }
-+#endif
-Index: grub/stage2/serial.c
-===================================================================
---- grub.orig/stage2/serial.c  2008-06-16 15:18:03.376934000 +0100
-+++ grub/stage2/serial.c       2008-06-16 15:18:14.769009000 +0100
-@@ -37,7 +37,7 @@
\f
- /* Hardware-dependent definitions.  */
--#ifndef GRUB_UTIL
-+#if !defined(GRUB_UTIL) && !defined(__MINIOS__)
- /* The structure for speed vs. divisor.  */
- struct divisor
- {
-@@ -222,6 +222,8 @@
-       {('3' | ('~' << 8)), 4},
-       {('5' | ('~' << 8)), 7},
-       {('6' | ('~' << 8)), 3},
-+      {('7' | ('~' << 8)), 1},
-+      {('8' | ('~' << 8)), 5},
-     };
-   
-   /* The buffer must start with ``ESC [''.  */
-Index: grub/stage2/tparm.c
-===================================================================
---- grub.orig/stage2/tparm.c   2008-06-16 15:18:03.390933000 +0100
-+++ grub/stage2/tparm.c        2008-06-16 15:18:14.774010000 +0100
-@@ -48,6 +48,7 @@
- #include "shared.h"
- #include "tparm.h"
-+#include <stdarg.h>
- /*
-  * Common/troublesome character definitions
-@@ -320,7 +321,7 @@
- #define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
- static inline char *
--tparam_internal(const char *string, int *dataptr)
-+tparam_internal(const char *string, va_list ap)
- {
- #define NUM_VARS 26
-     char *p_is_s[9];
-@@ -461,9 +462,9 @@
-        * a char* and an int may not be the same size on the stack.
-        */
-       if (p_is_s[i] != 0) {
--        p_is_s[i] = (char *)(*(dataptr++));
-+        p_is_s[i] = va_arg(ap, char *);
-       } else {
--        param[i] = (int)(*(dataptr++));
-+        param[i] = va_arg(ap, int);
-       }
-     }
-@@ -716,11 +717,13 @@
- grub_tparm(const char *string,...)
- {
-     char *result;
--    int *dataptr = (int *) &string;
-+    va_list ap;
--    dataptr++;
-+    va_start(ap, string);
--    result = tparam_internal(string, dataptr);
-+    result = tparam_internal(string, ap);
-+
-+    va_end(ap);
-     return result;
- }
-Index: grub/stage2/fsys_iso9660.c
-===================================================================
---- grub.orig/stage2/fsys_iso9660.c    2008-06-16 15:18:03.400933000 +0100
-+++ grub/stage2/fsys_iso9660.c 2008-06-16 15:18:14.779009000 +0100
-@@ -59,7 +59,14 @@
- static inline unsigned long
- log2 (unsigned long word)
- {
--  asm volatile ("bsfl %1,%0"
-+  asm volatile ("bsf"
-+#ifdef __i386__
-+                "l"
-+#endif
-+#ifdef __x86_64__
-+                "q"
-+#endif
-+                " %1,%0"
-               :          "=r" (word)
-               :          "r" (word));
-   return word;
-Index: grub/stage2/fsys_reiserfs.c
-===================================================================
---- grub.orig/stage2/fsys_reiserfs.c   2008-06-16 15:18:03.410933000 +0100
-+++ grub/stage2/fsys_reiserfs.c        2008-06-20 18:33:52.002100000 +0100
-@@ -224,8 +224,8 @@
- struct disk_child
- {
--  unsigned long       dc_block_number;              /* Disk child's block number. */
--  unsigned short      dc_size;                            /* Disk child's used space.   */
-+  __u32       dc_block_number;              /* Disk child's block number. */
-+  __u16      dc_size;                     /* Disk child's used space.   */
- };
- #define DC_SIZE (sizeof (struct disk_child))
-@@ -369,7 +369,14 @@
- static __inline__ unsigned long
- log2 (unsigned long word)
- {
--  __asm__ ("bsfl %1,%0"
-+  __asm__ ("bsf"
-+#ifdef __i386__
-+                "l"
-+#endif
-+#ifdef __x86_64__
-+                "q"
-+#endif
-+                " %1,%0"
-          : "=r" (word)
-          : "r" (word));
-   return word;
-Index: grub/netboot/misc.c
-===================================================================
---- grub.orig/netboot/misc.c   2008-06-16 15:18:03.456934000 +0100
-+++ grub/netboot/misc.c        2008-06-16 15:18:14.790009000 +0100
-@@ -21,7 +21,9 @@
- #define GRUB  1
- #include <etherboot.h>
-+#include <stdarg.h>
-+#ifndef __MINIOS__
- void
- sleep (int secs)
- {
-@@ -30,6 +32,7 @@
-   while (currticks () < tmo)
-     ;
- }
-+#endif
- void
- twiddle (void)
-@@ -71,7 +74,7 @@
-       Note: width specification not supported
- **************************************************************************/
- static int
--etherboot_vsprintf (char *buf, const char *fmt, const int *dp)
-+etherboot_vsprintf (char *buf, const char *fmt, va_list ap)
- {
-   char *p, *s;
-   
-@@ -86,7 +89,7 @@
-       
-       if (*++fmt == 's')
-       {
--        for (p = (char *) *dp++; *p != '\0'; p++)
-+        for (p = va_arg(ap, char *); *p != '\0'; p++)
-           buf ? *s++ = *p : grub_putchar (*p);
-       }
-       else
-@@ -121,11 +124,9 @@
-         if ((*fmt | 0x20) == 'x')
-           {
-             /* With x86 gcc, sizeof(long) == sizeof(int) */
--            const long *lp = (const long *) dp;
--            long h = *lp++;
-+            long h = va_arg(ap, int);
-             int ncase = (*fmt & 0x20);
-             
--            dp = (const int *) lp;
-             if (alt)
-               {
-                 *q++ = '0';
-@@ -136,7 +137,7 @@
-           }
-         else if (*fmt == 'd')
-           {
--            int i = *dp++;
-+            int i = va_arg(ap, int);
-             char *r;
-             
-             if (i < 0)
-@@ -171,10 +172,8 @@
-               unsigned char   c[4];
-             }
-             u;
--            const long *lp = (const long *) dp;
-             
--            u.l = *lp++;
--            dp = (const int *) lp;
-+            u.l = va_arg(ap, int);
-             
-             for (r = &u.c[0]; r < &u.c[4]; ++r)
-               q += etherboot_sprintf (q, "%d.", *r);
-@@ -184,7 +183,7 @@
-         else if (*fmt == '!')
-           {
-             char *r;
--            p = (char *) *dp++;
-+            p = va_arg(ap, char *);
-             
-             for (r = p + ETH_ALEN; p < r; ++p)
-               q += etherboot_sprintf (q, "%hhX:", *p);
-@@ -192,7 +191,7 @@
-             --q;
-           }
-         else if (*fmt == 'c')
--          *q++ = *dp++;
-+          *q++ = va_arg(ap, int);
-         else
-           *q++ = *fmt;
-         
-@@ -211,13 +210,21 @@
- int
- etherboot_sprintf (char *buf, const char *fmt, ...)
- {
--  return etherboot_vsprintf (buf, fmt, ((const int *) &fmt) + 1);
-+  va_list ap;
-+  int ret;
-+  va_start(ap, fmt);
-+  ret = etherboot_vsprintf (buf, fmt, ap);
-+  va_end(ap);
-+  return ret;
- }
- void
- etherboot_printf (const char *fmt, ...)
- {
--  (void) etherboot_vsprintf (0, fmt, ((const int *) &fmt) + 1);
-+  va_list ap;
-+  va_start(ap, fmt);
-+  etherboot_vsprintf (0, fmt, ap);
-+  va_end(ap);
- }
- int
-Index: grub/netboot/main.c
-===================================================================
---- grub.orig/netboot/main.c   2008-06-16 15:18:03.470932000 +0100
-+++ grub/netboot/main.c        2008-06-16 15:18:14.797009000 +0100
-@@ -55,7 +55,7 @@
- static int vendorext_isvalid;
- static unsigned long netmask;
- static struct bootpd_t bootp_data;
--static unsigned long xid;
-+static unsigned int xid;
- #define       BOOTP_DATA_ADDR (&bootp_data)
-@@ -778,7 +778,7 @@
-             arpreply = (struct arprequest *) &nic.packet[ETH_HLEN];
-             
--            if (arpreply->opcode == htons (ARP_REPLY)
-+            if (arpreply->opcode == htons (ARP_REPLY) && ptr
-                 && ! grub_memcmp (arpreply->sipaddr, ptr, sizeof (in_addr))
-                 && type == AWAIT_ARP)
-               {
-@@ -827,7 +827,7 @@
-           {
-             arpreply = (struct arprequest *) &nic.packet[ETH_HLEN];
-             
--            if (arpreply->opcode == htons (RARP_REPLY)
-+            if (arpreply->opcode == htons (RARP_REPLY) && ptr
-                 && ! grub_memcmp (arpreply->thwaddr, ptr, ETH_ALEN))
-               {
-                 grub_memmove ((char *) arptable[ARP_SERVER].node,
-@@ -1135,7 +1135,7 @@
- long
- rfc2131_sleep_interval (int base, int exp)
- {
--  static long seed = 0;
-+  static unsigned seed = 0;
-   long q;
-   unsigned long tmo;
-   
-Index: grub/stage2/graphics.c
-===================================================================
---- grub.orig/stage2/graphics.c        2008-06-16 15:18:14.524009000 +0100
-+++ grub/stage2/graphics.c     2008-06-17 14:29:05.204328000 +0100
-@@ -30,7 +30,29 @@
- #include <shared.h>
- #include <graphics.h>
-+#ifdef __MINIOS__
-+#include <stdint.h>
-+typedef uint8_t Bit8u;
-+#include <vgafonts.h>
-+#include <fbfront.h>
-+#include <malloc.h>
-+#define set_int1c_handler() (void)0
-+#define unset_int1c_handler() (void)0
-+static uint32_t *VIDEOMEM;
-+static struct fbfront_dev *fb_dev;
-+static uint32_t palette[17];
-+short cursorX, cursorY;
-+/* TODO: blink */
-+uint32_t cursorBuf32[16*8];
-+#define WIDTH 640
-+#define HEIGHT 480
-+#define DEPTH 32
-+#define RAMSIZE (WIDTH * HEIGHT * (DEPTH / 8))
-+#else
-+#define fbfront_update(dev, x, y, w, h) (void)0
- int saved_videomode;
-+#endif
-+
- unsigned char *font8x16;
- int graphics_inited = 0;
-@@ -38,11 +60,15 @@
- int shade = 1, no_cursor = 0;
-+#ifdef __MINIOS__
-+uint32_t VSHADOW[RAMSIZE];
-+#else
- #define VSHADOW VSHADOW1
- unsigned char VSHADOW1[38400];
- unsigned char VSHADOW2[38400];
- unsigned char VSHADOW4[38400];
- unsigned char VSHADOW8[38400];
-+#endif
- /* define the default viewable area */
- int view_x0 = 0;
-@@ -129,6 +155,8 @@
-     count_lines = k;
-     no_scroll = 0;
-+
-+    fbfront_update(fb_dev, view_x0 * 8, view_y0 * 16, (view_x1 - view_x0) * 8, (view_y1 - view_y0) * 16);
- }
- /* Set the splash image */
-@@ -154,17 +182,29 @@
- int graphics_init()
- {
-     if (!graphics_inited) {
-+#ifdef __MINIOS__
-+      VIDEOMEM = memalign(PAGE_SIZE, RAMSIZE);
-+      if (!(fb_dev = fb_open(VIDEOMEM, WIDTH, HEIGHT, DEPTH))) {
-+          free(VIDEOMEM);
-+          return 0;
-+      }
-+#else
-         saved_videomode = set_videomode(0x12);
-         if (get_videomode() != 0x12) {
-             set_videomode(saved_videomode);
-             return 0;
-         }
-+#endif
-         graphics_inited = 1;
-     }
-     else
-         return 1;
-+#ifdef __MINIOS__
-+    font8x16 = vgafont16;
-+#else
-     font8x16 = (unsigned char*)graphics_get_font();
-+#endif
-     /* make sure that the highlight color is set correctly */
-     graphics_highlight_color = ((graphics_normal_color >> 4) | 
-@@ -176,7 +216,11 @@
-         grub_printf("Failed to read splash image (%s)\n", splashimage);
-         grub_printf("Press any key to continue...");
-         getkey();
-+#ifdef __MINIOS__
-+      fb_close();
-+#else
-         set_videomode(saved_videomode);
-+#endif
-         graphics_inited = 0;
-         return 0;
-     }
-@@ -190,8 +234,13 @@
- void graphics_end(void)
- {
-     if (graphics_inited) {
-+#ifdef __MINIOS__
-+      fb_close();
-+      free(VIDEOMEM);
-+#else
-         unset_int1c_handler();
-         set_videomode(saved_videomode);
-+#endif
-         graphics_inited = 0;
-         no_cursor = 0;
-     }
-@@ -204,15 +253,19 @@
-     graphics_cursor(0);
-     if (ch == '\n') {
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-         if (fonty + 1 < view_y1)
-             graphics_setxy(fontx, fonty + 1);
-         else
-             graphics_scroll();
-         graphics_cursor(1);
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-         return;
-     } else if (ch == '\r') {
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-         graphics_setxy(view_x0, fonty);
-         graphics_cursor(1);
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-         return;
-     }
-@@ -224,6 +277,7 @@
-         text[fonty * 80 + fontx] |= 0x100;
-     graphics_cursor(0);
-+    fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-     if ((fontx + 1) >= view_x1) {
-         graphics_setxy(view_x0, fonty);
-@@ -232,13 +286,16 @@
-         else
-             graphics_scroll();
-         graphics_cursor(1);
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-         do_more ();
-         graphics_cursor(0);
-+      fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-     } else {
-         graphics_setxy(fontx + 1, fonty);
-     }
-     graphics_cursor(1);
-+    fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- }
- /* get the current location of the cursor */
-@@ -248,10 +305,12 @@
- void graphics_gotoxy(int x, int y) {
-     graphics_cursor(0);
-+    fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
-     graphics_setxy(x, y);
-     graphics_cursor(1);
-+    fbfront_update(fb_dev, cursorX, cursorY, 8, 16);
- }
- void graphics_cls(void) {
-@@ -262,15 +321,21 @@
-     graphics_gotoxy(view_x0, view_y0);
-     mem = (unsigned char*)VIDEOMEM;
-+#ifndef __MINIOS__
-     s1 = (unsigned char*)VSHADOW1;
-     s2 = (unsigned char*)VSHADOW2;
-     s4 = (unsigned char*)VSHADOW4;
-     s8 = (unsigned char*)VSHADOW8;
-+#endif
-     for (i = 0; i < 80 * 30; i++)
-         text[i] = ' ';
-     graphics_cursor(1);
-+#ifdef __MINIOS__
-+    memcpy(mem, VSHADOW, RAMSIZE);
-+    fbfront_update(fb_dev, 0, 0, 640, 480);
-+#else
-     BitMask(0xff);
-     /* plane 1 */
-@@ -290,6 +355,7 @@
-     grub_memcpy(mem, s8, 38400);
-     MapMask(15);
-+#endif
-     if (no_cursor) {
-         no_cursor = 0;
-@@ -337,6 +403,11 @@
-     return 0;
- }
-+void graphics_set_palette(int idx, int red, int green, int blue)
-+{
-+    palette[idx] = (red << (16 + 2)) | (green << (8 + 2)) | (blue << 2);
-+}
-+
- /* Read in the splashscreen image and set the palette up appropriately.
-  * Format of splashscreen is an xpm (can be gzipped) with 16 colors and
-  * 640x480. */
-@@ -413,18 +484,19 @@
-         }
-         if (len == 6 && idx < 15) {
--            int r = ((hex(buf[0]) << 4) | hex(buf[1])) >> 2;
--            int g = ((hex(buf[2]) << 4) | hex(buf[3])) >> 2;
--            int b = ((hex(buf[4]) << 4) | hex(buf[5])) >> 2;
-+            int r = ((hex(buf[0]) << 4) | hex(buf[1]));
-+            int g = ((hex(buf[2]) << 4) | hex(buf[3]));
-+            int b = ((hex(buf[4]) << 4) | hex(buf[5]));
-             pal[idx] = base;
--            graphics_set_palette(idx, r, g, b);
-+            graphics_set_palette(idx, r / 4, g / 4, b / 4);
-             ++idx;
-         }
-     }
-     x = y = len = 0;
-+#ifndef __MINIOS__
-     s1 = (unsigned char*)VSHADOW1;
-     s2 = (unsigned char*)VSHADOW2;
-     s4 = (unsigned char*)VSHADOW4;
-@@ -432,6 +504,7 @@
-     for (i = 0; i < 38400; i++)
-         s1[i] = s2[i] = s4[i] = s8[i] = 0;
-+#endif
-     /* parse xpm data */
-     while (y < height) {
-@@ -451,6 +524,9 @@
-                     break;
-                 }
-+#ifdef __MINIOS__
-+          VSHADOW[x + y * 640] = palette[i];
-+#else
-             mask = 0x80 >> (x & 7);
-             if (c & 1)
-                 s1[len + (x >> 3)] |= mask;
-@@ -460,6 +536,7 @@
-                 s4[len + (x >> 3)] |= mask;
-             if (c & 8)
-                 s8[len + (x >> 3)] |= mask;
-+#endif
-             if (++x >= 640) {
-                 x = 0;
-@@ -494,7 +571,13 @@
- }
- void graphics_cursor(int set) {
--    unsigned char *pat, *mem, *ptr, chr[16 << 2];
-+    unsigned char *pat;
-+#ifdef __MINIOS__
-+    uint32_t *mem, *ptr, chr[16 * 8];
-+    int j;
-+#else
-+    unsigned char *mem, *ptr, chr[16 << 2];
-+#endif
-     int i, ch, invert, offset;
-     if (set && (no_cursor || no_scroll))
-@@ -505,71 +588,127 @@
-     invert = (text[fonty * 80 + fontx] & 0xff00) != 0;
-     pat = font8x16 + (ch << 4);
--    mem = (unsigned char*)VIDEOMEM + offset;
-+    mem = (unsigned char*)VIDEOMEM + offset
-+#ifdef __MINIOS__
-+      * 8 * 4
-+#endif
-+      ;
-     if (!set) {
-         for (i = 0; i < 16; i++) {
-             unsigned char mask = pat[i];
-             if (!invert) {
-+#ifdef __MINIOS__
-+              memcpy(chr + i * 8, VSHADOW + offset * 8, 8 * 4);
-+#else
-                 chr[i     ] = ((unsigned char*)VSHADOW1)[offset];
-                 chr[16 + i] = ((unsigned char*)VSHADOW2)[offset];
-                 chr[32 + i] = ((unsigned char*)VSHADOW4)[offset];
-                 chr[48 + i] = ((unsigned char*)VSHADOW8)[offset];
-+#endif
-                 if (shade) {
-                     if (ch == DISP_VERT || ch == DISP_LL ||
-                         ch == DISP_UR || ch == DISP_LR) {
-                         unsigned char pmask = ~(pat[i] >> 1);
-+#ifdef __MINIOS__
-+                      for (j = 0; j < 8; j++)
-+                          if (!(pmask & (1U << j)))
-+                              chr[i * 8 + (7 - j)] = palette[0];
-+#else
-                         chr[i     ] &= pmask;
-                         chr[16 + i] &= pmask;
-                         chr[32 + i] &= pmask;
-                         chr[48 + i] &= pmask;
-+#endif
-                     }
-                     if (i > 0 && ch != DISP_VERT) {
-                         unsigned char pmask = ~(pat[i - 1] >> 1);
-+#ifdef __MINIOS__
-+                      for (j = 0; j < 8; j++)
-+                          if (!(pmask & (1U << j)))
-+                              chr[i * 8 + (7 - j)] = palette[0];
-+#else
-                         chr[i     ] &= pmask;
-                         chr[16 + i] &= pmask;
-                         chr[32 + i] &= pmask;
-                         chr[48 + i] &= pmask;
-+#endif
-                         if (ch == DISP_HORIZ || ch == DISP_UR || ch == DISP_LR) {
-                             pmask = ~pat[i - 1];
-+#ifdef __MINIOS__
-+                          for (j = 0; j < 8; j++)
-+                              if (!(pmask & (1U << j)))
-+                                  chr[i * 8 + (7 - j)] = palette[0];
-+#else
-                             chr[i     ] &= pmask;
-                             chr[16 + i] &= pmask;
-                             chr[32 + i] &= pmask;
-                             chr[48 + i] &= pmask;
-+#endif
-                         }
-                     }
-                 }
-+#ifdef __MINIOS__
-+              for (j = 0; j < 8; j++)
-+                  if (mask & (1U << j))
-+                      chr[i * 8 + (7 - j)] = palette[15];
-+#else
-                 chr[i     ] |= mask;
-                 chr[16 + i] |= mask;
-                 chr[32 + i] |= mask;
-                 chr[48 + i] |= mask;
-+#endif
-                 offset += 80;
-             }
-             else {
-+#ifdef __MINIOS__
-+              for (j = 0; j < 8; j++)
-+                  if (mask & (1U << j))
-+                      chr[i * 8 + (7 - j)] = palette[15];
-+                  else
-+                      chr[i * 8 + (7 - j)] = palette[0];
-+#else
-                 chr[i     ] = mask;
-                 chr[16 + i] = mask;
-                 chr[32 + i] = mask;
-                 chr[48 + i] = mask;
-+#endif
-             }
-         }
-     }
-     else {
-+#ifdef __MINIOS__
-+        ptr = mem;
-+        for (i = 0; i < 16; i++, ptr += 80 * 8)
-+          for (j = 0; j < 8; j++) {
-+              if (pat[i] & (1U << (7 - j)))
-+                  cursorBuf32[i * 8 + j] = ptr[j] = palette[0];
-+              else
-+                  cursorBuf32[i * 8 + j] = ptr[j] = palette[15];
-+          }
-+#else
-         MapMask(15);
-         ptr = mem;
-         for (i = 0; i < 16; i++, ptr += 80) {
-             cursorBuf[i] = pat[i];
-             *ptr = ~pat[i];
-         }
-+#endif
-         return;
-     }
-     offset = 0;
-+#ifdef __MINIOS__
-+    ptr = mem;
-+    for (j = 0; j < 16; j++, ptr += 80 * 8)
-+      memcpy(ptr, chr + j * 8 + offset * 8, 8 * 4);
-+#else
-     for (i = 1; i < 16; i <<= 1, offset += 16) {
-         int j;
-@@ -580,6 +719,7 @@
-     }
-     MapMask(15);
-+#endif
- }
- #endif /* SUPPORT_GRAPHICS */
-Index: grub/stage2/graphics.h
-===================================================================
---- grub.orig/stage2/graphics.h        2008-06-16 15:18:14.527010000 +0100
-+++ grub/stage2/graphics.h     2008-06-16 15:18:14.805010000 +0100
-@@ -21,8 +21,10 @@
- #ifndef GRAPHICS_H
- #define GRAPHICS_H
-+#ifndef __MINIOS__
- /* magic constant */
- #define VIDEOMEM 0xA0000
-+#endif
- /* function prototypes */
- char *graphics_get_splash(void);
-Index: grub/stage2/stage2.c
-===================================================================
---- grub.orig/stage2/stage2.c  2008-06-17 11:06:47.873523000 +0100
-+++ grub/stage2/stage2.c       2008-06-17 11:07:05.225628000 +0100
-@@ -31,10 +31,10 @@
- #if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
- # if defined(PRESET_MENU_STRING)
--static const char *preset_menu = PRESET_MENU_STRING;
-+const char *preset_menu = PRESET_MENU_STRING;
- # elif defined(SUPPORT_DISKLESS)
- /* Execute the command "bootp" automatically.  */
--static const char *preset_menu = "bootp\n";
-+const char *preset_menu = "bootp\n";
- # endif /* SUPPORT_DISKLESS */
- static int preset_menu_offset;
-Index: grub/stage2/fsys_xfs.c
-===================================================================
-RCS file: /sources/grub/grub/stage2/fsys_xfs.c,v
-retrieving revision 1.5
-diff -u -p -r1.5 fsys_xfs.c
---- grub/stage2/fsys_xfs.c     8 May 2005 02:18:14 -0000       1.5
-+++ grub/stage2/fsys_xfs.c     10 Jul 2008 13:09:50 -0000
-@@ -101,7 +101,7 @@ static inline __const__ xfs_uint16_t
- le16 (xfs_uint16_t x)
- {
-       __asm__("xchgb %b0,%h0" \
--              : "=q" (x) \
-+              : "=Q" (x) \
-               :  "0" (x)); \
-               return x;
- }
-@@ -109,9 +109,9 @@ le16 (xfs_uint16_t x)
- static inline __const__ xfs_uint32_t
- le32 (xfs_uint32_t x)
- {
--#if 0
-+#if 1
-         /* 386 doesn't have bswap.  */
--      __asm__("bswap %0" : "=r" (x) : "0" (x));
-+      __asm__("bswapl %k0" : "=r" (x) : "0" (x));
- #else
-       /* This is slower but this works on all x86 architectures.  */
-       __asm__("xchgb %b0, %h0" \
---- grub.orig/stage2/gunzip.c  2010-03-07 23:03:34.000000000 +0100
-+++ grub/stage2/gunzip.c       2010-03-07 23:05:36.000000000 +0100
-@@ -141,7 +141,7 @@
- static int gzip_filemax;
- static int gzip_fsmax;
- static int saved_filepos;
--static unsigned long gzip_crc;
-+static unsigned int gzip_crc;
- /* internal extra variables for use of inflate code */
- static int block_type;
-@@ -157,7 +157,7 @@
-  *  Linear allocator.
-  */
--static unsigned long linalloc_topaddr;
-+static unsigned int linalloc_topaddr;
- static void *
- linalloc (int size)
-@@ -253,7 +253,7 @@
- typedef unsigned char uch;
- typedef unsigned short ush;
--typedef unsigned long ulg;
-+typedef unsigned int ulg;
- /*
-  *  Window Size
-@@ -316,8 +316,8 @@
-       return 0;
-     }
--  gzip_crc = *((unsigned long *) buf);
--  gzip_fsmax = gzip_filemax = *((unsigned long *) (buf + 4));
-+  gzip_crc = *((unsigned int *) buf);
-+  gzip_fsmax = gzip_filemax = *((unsigned int *) (buf + 4));
-   initialize_tables ();
-diff -ur grub.orig/stage2/fsys_iso9660.c grub-upstream/stage2/fsys_iso9660.c
---- grub.orig/stage2/fsys_iso9660.c    2010-03-07 23:39:00.000000000 +0100
-+++ grub/stage2/fsys_iso9660.c 2010-03-07 23:39:56.000000000 +0100
-@@ -43,7 +43,7 @@
- /* iso fs inode data in memory */
- struct iso_inode_info {
--  unsigned long file_start;
-+  unsigned int file_start;
- };
- #define ISO_SUPER     \
-@@ -88,12 +88,12 @@
-   if (byte_len <= 0)
-     return 1;
--  sector += (byte_offset >> sector_size_lg2);
--  byte_offset &= (buf_geom.sector_size - 1);
-   asm volatile ("shl%L0 %1,%0"
-               : "=r"(sector)
-               : "Ic"((int8_t)(ISO_SECTOR_BITS - sector_size_lg2)),
-               "0"(sector));
-+  sector += (byte_offset >> sector_size_lg2);
-+  byte_offset &= (buf_geom.sector_size - 1);
- #if !defined(STAGE1_5)
-   if (disk_read_hook && debug)
diff --git a/stubdom/grub/Makefile b/stubdom/grub/Makefile
deleted file mode 100644 (file)
index 26dff45..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-XEN_ROOT = $(CURDIR)/../..
-
-include $(XEN_ROOT)/Config.mk
-vpath %.c ../grub-upstream
-
-BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
-
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/include
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include -I$(XEN_ROOT)/tools/include -I.
-DEF_CPPFLAGS += -I../grub-upstream/stage1
-DEF_CPPFLAGS += -I../grub-upstream/stage2
-DEF_CPPFLAGS += -I../grub-upstream/netboot
-DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/firmware/vgabios
-DEF_CPPFLAGS += -DWITHOUT_LIBC_STUBS
-DEF_CPPFLAGS += -DSUPPORT_NETBOOT
-DEF_CPPFLAGS += -DSUPPORT_GRAPHICS
-DEF_CPPFLAGS += -DSUPPORT_SERIAL
-DEF_CPPFLAGS += -DPRESET_MENU_STRING='""'
-DEF_CPPFLAGS += -DPACKAGE='"grubdom"' -DVERSION='"0.97"'
-
-all: $(OBJ_DIR)/main.a
-
-STAGE2_SOURCES=builtins.c char_io.c cmdline.c common.c console.c disk_io.c graphics.c gunzip.c md5.c serial.c stage2.c terminfo.c tparm.c
-
-NETBOOT_SOURCES=fsys_tftp.c main.c misc.c
-CPPFLAGS += -DFSYS_TFTP=1
-
-STAGE2_SOURCES+=fsys_ext2fs.c
-CPPFLAGS += -DFSYS_EXT2FS=1
-
-STAGE2_SOURCES+=fsys_fat.c
-CPPFLAGS += -DFSYS_FAT=1
-
-STAGE2_SOURCES+=fsys_ffs.c
-CPPFLAGS += -DFSYS_FFS=1
-
-STAGE2_SOURCES+=fsys_iso9660.c
-CPPFLAGS += -DFSYS_ISO9660=1
-
-STAGE2_SOURCES+=fsys_jfs.c
-CPPFLAGS += -DFSYS_JFS=1
-
-STAGE2_SOURCES+=fsys_minix.c
-CPPFLAGS += -DFSYS_MINIX=1
-
-STAGE2_SOURCES+=fsys_reiserfs.c
-CPPFLAGS += -DFSYS_REISERFS=1
-
-STAGE2_SOURCES+=fsys_ufs2.c
-CPPFLAGS += -DFSYS_UFS2=1
-
-STAGE2_SOURCES+=fsys_vstafs.c
-CPPFLAGS += -DFSYS_VSTAFS=1
-
-STAGE2_SOURCES+=fsys_xfs.c
-CPPFLAGS += -DFSYS_XFS=1
-
-STAGE2_SOURCES:=$(addprefix stage2/,$(STAGE2_SOURCES))
-NETBOOT_SOURCES:=$(addprefix netboot/,$(NETBOOT_SOURCES))
-
-$(BOOT): DEF_CPPFLAGS+=-D__ASSEMBLY__
-
-PV_GRUB_SOURCES = kexec.c mini-os.c
-PV_GRUB_SOURCES += ../polarssl-$(XEN_TARGET_ARCH)/library/sha1.o
-
-SOURCES = $(NETBOOT_SOURCES) $(STAGE2_SOURCES) $(PV_GRUB_SOURCES)
-
-OBJS = $(addprefix $(OBJ_DIR)/,$(SOURCES:.c=.o))
-
-$(OBJ_DIR)/dirs:
-       mkdir -p $(OBJ_DIR)/netboot $(OBJ_DIR)/stage2
-       touch $@
-
-$(OBJS): $(OBJ_DIR)/dirs
-
-$(OBJ_DIR)/main.a: $(BOOT) $(OBJS)
-       $(AR) cr $@ $^
-
-$(OBJ_DIR)/%.o: %.c
-       $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
-
-$(OBJ_DIR)/%.o: %.S
-       $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
-
-clean:
-       rm -fr dirs *.a *.o stage2 netboot
diff --git a/stubdom/grub/boot-x86_32.S b/stubdom/grub/boot-x86_32.S
deleted file mode 100644 (file)
index c95fd30..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#include <os.h>
-#include <arch_limits.h>
-#include <xen/arch-x86_32.h>
-
-/* For simplicity, we keep all of this into just one data page */
-.data
-.globl _boot_page
-_boot_page:
-        .align __PAGE_SIZE
-
-/*
- * The following data is initialized from C code
- */
-
-/* Pte of this page */
-.globl _boot_page_entry
-_boot_page_entry:
-_boot_page_entry_lo:
-        .long 0
-_boot_page_entry_hi:
-        .long 0
-
-/* mmuext_op structure */
-/* Set new page directory */
-_boot_mmuext:
-        /* Op # */
-        .long MMUEXT_NEW_BASEPTR
-
-        /* MFN of target page table directory */
-.globl _boot_pdmfn
-_boot_pdmfn:
-        .long 0
-
-        /* Unused */
-        .long 0
-
-/* Unpin old page directory */
-        /* Op # */
-        .long MMUEXT_UNPIN_TABLE
-
-        /* MFN of old page table directory */
-.globl _boot_oldpdmfn
-_boot_oldpdmfn:
-        .long 0
-
-        /* Unused */
-        .long 0
-
-/* Target stack address, also target virtual address of this page */
-.globl _boot_stack
-_boot_stack:
-        .long 0
-        .long __KERNEL_SS
-.globl _boot_target
-_boot_target:
-        .long 0
-
-/* Target start info */
-.globl _boot_start_info
-_boot_start_info:
-        .long 0
-
-/* Target start address */
-.globl _boot_start
-_boot_start:
-        .long 0
-
-/*
- * Boot target OS, does not return
- */
-.globl _boot
-_boot:
-        /* Project ourselves at the target place. */
-        movl    _boot_target, %ebx
-        movl    %ebx, %ebp     /* also keep it in ebp for relative addressing */
-        movl    _boot_page_entry_lo, %ecx
-        movl    _boot_page_entry_hi, %edx
-        movl    $2, %esi /* UVMF_INVLPG */
-        movl    $__HYPERVISOR_update_va_mapping, %eax
-        int     $0x82
-        testl   %eax, %eax
-        jz      0f
-        ud2
-
-0:
-        /* Go there. */
-        movl    $(0f - _boot_page), %eax
-        movl    _boot_target, %ebx
-        addl    %ebx, %eax
-        jmpl    *%eax
-0:
-        
-        /* Load target page table and unpin old page table.  */
-        /* We shouldn't have any problem since in the new page table our page is
-           mapped at the same place.  */
-        leal    (_boot_mmuext-_boot_page)(%ebp), %ebx
-        movl    $2, %ecx
-        xorl    %edx, %edx
-        movl    $0x7FF0, %esi /* DOMID_SELF */
-        movl    $__HYPERVISOR_mmuext_op, %eax
-        int     $0x82
-        testl   %eax, %eax
-        jns     0f
-        ud2
-
-0:
-        /* Initialize registers.  */
-        lss     (_boot_stack-_boot_page)(%ebp), %esp
-        movl    (_boot_start_info-_boot_page)(%ebp), %esi
-
-        /* Jump!  */
-        jmpl    *(_boot_start-_boot_page)(%ebp)
diff --git a/stubdom/grub/boot-x86_64.S b/stubdom/grub/boot-x86_64.S
deleted file mode 100644 (file)
index 2eae6c3..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-#include <os.h>
-#include <arch_limits.h>
-#include <xen/arch-x86_64.h>
-
-/* For simplicity, we keep all of this into just one data page */
-.data
-.globl _boot_page
-_boot_page:
-        .align __PAGE_SIZE
-
-/*
- * The following data is initialized from C code
- */
-
-/* Pte of this page */
-.globl _boot_page_entry
-_boot_page_entry:
-        .quad 0
-
-/* mmuext_op structure */
-/* Set new page directory */
-_boot_mmuext:
-        /* Op # */
-        .long MMUEXT_NEW_BASEPTR
-        .long 0 /* pad */
-
-        /* MFN of target page table directory */
-.globl _boot_pdmfn
-_boot_pdmfn:
-        .quad 0
-
-        /* Unused */
-        .quad 0
-
-/* Unpin old page directory */
-        /* Op # */
-        .long MMUEXT_UNPIN_TABLE
-        .long 0 /* pad */
-
-        /* MFN of old page table directory */
-.globl _boot_oldpdmfn
-_boot_oldpdmfn:
-        .quad 0
-
-        /* Unused */
-        .quad 0
-
-/* Target stack address, also target virtual address of this page */
-.globl _boot_stack
-_boot_stack:
-        .quad 0
-.globl _boot_target
-_boot_target:
-        .quad 0
-
-/* Target start info */
-.globl _boot_start_info
-_boot_start_info:
-        .quad 0
-
-/* Target start address */
-.globl _boot_start
-_boot_start:
-        .quad 0
-
-/*
- * Boot target OS, does not return
- */
-.globl _boot
-_boot:
-        /* Project ourselves at the target place. */
-        movq    _boot_target, %rdi
-        movq    _boot_page_entry, %rsi
-        movq    $2, %rdx /* UVMF_INVLPG */
-        movq    $__HYPERVISOR_update_va_mapping, %rax
-        syscall
-        testq   %rax, %rax
-        jz      0f
-        ud2
-
-0:
-        /* Go there. */
-        movq    $(0f - _boot_page), %rax
-        movq    _boot_target, %rbx
-        addq    %rbx, %rax
-        jmpq    *%rax
-0:
-        
-        /* Load target page table and unpin old page table.  */
-        /* We shouldn't have any problem since in the new page table our page is
-           mapped at the same place.  */
-        leaq    _boot_mmuext(%rip), %rdi
-        movq    $2, %rsi
-        xorq    %rdx, %rdx
-        movq    $0x7FF0, %r10 /* DOMID_SELF */
-        movq    $__HYPERVISOR_mmuext_op, %rax
-        syscall
-        testq   %rax, %rax
-        jns     0f
-        ud2
-
-0:
-        /* Initialize registers.  */
-        movq    _boot_stack(%rip), %rsp
-        movq    _boot_start_info(%rip), %rsi
-
-        /* Jump!  */
-        jmpq    *_boot_start(%rip)
diff --git a/stubdom/grub/config.h b/stubdom/grub/config.h
deleted file mode 100644 (file)
index 15a6583..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <stdio.h>
-#undef putchar
-#include <ctype.h>
-#include <string.h>
-#include <kernel.h>
-#define debug _debug
-#define grub_halt(a) do_exit()
-#define printf grub_printf
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags);
-struct fbfront_dev *fb_open(void *fb, int width, int height, int depth);
-void fb_close(void);
-void pv_boot (void);
diff --git a/stubdom/grub/kexec.c b/stubdom/grub/kexec.c
deleted file mode 100644 (file)
index 8fd9ff9..0000000
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * This supports booting another PV kernel from Mini-OS
- *
- * The idea is to setup it using libxc, answer to day0 memory allocation
- * requests, and using a trampoline boot page to switch to the new page table.
- *
- * The procedure of the boot page is:
- * - map itself at the target position (that may overwrite some C stuff, but we
- *   do not care any more)
- * - jump there
- * - switch to the target page table
- * - unpin the old page table
- * - jump to the new kernel
- *
- * Samuel Thibault <Samuel.Thibault@eu.citrix.com>, May 2008
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-
-#include <xenctrl.h>
-#include <xc_dom.h>
-
-#include <kernel.h>
-#include <console.h>
-#include <os.h>
-#include <blkfront.h>
-#include <netfront.h>
-#include <fbfront.h>
-#include <tpmfront.h>
-#include <shared.h>
-#include <byteswap.h>
-
-#include "mini-os.h"
-
-#if 0
-#define DEBUG(fmt, ...) printk(fmt, ## __VA_ARGS__)
-#else
-#define DEBUG(fmt, ...) (void)0
-#endif
-
-/* Assembly boot page from boot.S */
-extern void _boot_page;
-extern pgentry_t _boot_page_entry;
-extern unsigned long _boot_pdmfn;
-extern unsigned long _boot_stack, _boot_target, _boot_start_info, _boot_start;
-extern xen_pfn_t _boot_oldpdmfn;
-extern void _boot(void);
-
-static unsigned long *pages;
-static unsigned long *pages_mfns;
-static xen_pfn_t *pages_moved2pfns;
-static unsigned long allocated;
-
-int pin_table(xc_interface *xc_handle, unsigned int type, unsigned long mfn,
-              domid_t dom);
-
-#define TPM_TAG_RQU_COMMAND 0xC1
-#define TPM_ORD_Extend 20
-
-struct pcr_extend_cmd {
-       uint16_t tag;
-       uint32_t size;
-       uint32_t ord;
-
-       uint32_t pcr;
-       unsigned char hash[20];
-} __attribute__((packed));
-
-struct pcr_extend_rsp {
-       uint16_t tag;
-       uint32_t size;
-       uint32_t status;
-
-       unsigned char hash[20];
-} __attribute__((packed));
-
-/* Not imported from polarssl's header since the prototype unhelpfully defines
- * the input as unsigned char, which causes pointer type mismatches */
-void sha1(const void *input, size_t ilen, unsigned char output[20]);
-
-/* We need mfn to appear as target_pfn, so exchange with the MFN there */
-static void do_exchange(struct xc_dom_image *dom, xen_pfn_t target_pfn, xen_pfn_t source_mfn)
-{
-    xen_pfn_t source_pfn;
-    xen_pfn_t target_mfn;
-
-    for (source_pfn = 0; source_pfn < start_info.nr_pages; source_pfn++)
-        if (dom->p2m_host[source_pfn] == source_mfn)
-            break;
-    ASSERT(source_pfn < start_info.nr_pages);
-
-    target_mfn = dom->p2m_host[target_pfn];
-
-    /* Put target MFN at source PFN */
-    dom->p2m_host[source_pfn] = target_mfn;
-
-    /* Put source MFN at target PFN */
-    dom->p2m_host[target_pfn] = source_mfn;
-}
-
-int kexec_allocate(struct xc_dom_image *dom)
-{
-    unsigned long new_allocated = dom->pfn_alloc_end - dom->rambase_pfn;
-    unsigned long i;
-
-    pages = realloc(pages, new_allocated * sizeof(*pages));
-    pages_mfns = realloc(pages_mfns, new_allocated * sizeof(*pages_mfns));
-    pages_moved2pfns = realloc(pages_moved2pfns, new_allocated * sizeof(*pages_moved2pfns));
-    for (i = allocated; i < new_allocated; i++) {
-        /* Exchange old page of PFN i with a newly allocated page.  */
-        xen_pfn_t old_mfn = dom->p2m_host[i];
-        xen_pfn_t new_pfn;
-        xen_pfn_t new_mfn;
-
-        pages[i] = alloc_page();
-        memset((void*) pages[i], 0, PAGE_SIZE);
-        new_pfn = PHYS_PFN(to_phys(pages[i]));
-        pages_mfns[i] = new_mfn = pfn_to_mfn(new_pfn);
-
-       /*
-        * If PFN of newly allocated page (new_pfn) is less then currently
-        * requested PFN (i) then look for relevant PFN/MFN pair. In this
-        * situation dom->p2m_host[new_pfn] no longer contains proper MFN
-        * because original page with new_pfn was moved earlier
-        * to different location.
-        */
-       for (; new_pfn < i; new_pfn = pages_moved2pfns[new_pfn]);
-
-       /* Store destination PFN of currently requested page. */
-       pages_moved2pfns[i] = new_pfn;
-
-        /* Put old page at new PFN */
-        dom->p2m_host[new_pfn] = old_mfn;
-
-        /* Put new page at PFN i */
-        dom->p2m_host[i] = new_mfn;
-    }
-
-    allocated = new_allocated;
-
-    return 0;
-}
-
-/* Filled from mini-os command line or left as NULL */
-char *vtpm_label;
-
-static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline)
-{
-       struct tpmfront_dev* tpm = init_tpmfront(NULL);
-       struct pcr_extend_rsp *resp;
-       size_t resplen = 0;
-       struct pcr_extend_cmd cmd;
-       int rv;
-
-       /*
-        * If vtpm_label was specified on the command line, require a vTPM to be
-        * attached and for the domain providing the vTPM to have the given
-        * label.
-        */
-       if (vtpm_label) {
-               char ctx[128];
-               if (!tpm) {
-                       printf("No TPM found and vtpm_label specified, aborting!\n");
-                       do_exit();
-               }
-               rv = evtchn_get_peercontext(tpm->evtchn, ctx, sizeof(ctx) - 1);
-               if (rv < 0) {
-                       printf("Could not verify vtpm_label: %d\n", rv);
-                       do_exit();
-               }
-               ctx[127] = 0;
-               rv = strcmp(ctx, vtpm_label);
-               if (rv && vtpm_label[0] == '*') {
-                       int match_len = strlen(vtpm_label) - 1;
-                       int offset = strlen(ctx) - match_len;
-                       if (offset > 0)
-                               rv = strcmp(ctx + offset, vtpm_label + 1);
-               }
-
-               if (rv) {
-                       printf("Mismatched vtpm_label: '%s' != '%s'\n", ctx, vtpm_label);
-                       do_exit();
-               }
-       } else if (!tpm) {
-               return;
-       }
-
-       cmd.tag = bswap_16(TPM_TAG_RQU_COMMAND);
-       cmd.size = bswap_32(sizeof(cmd));
-       cmd.ord = bswap_32(TPM_ORD_Extend);
-       cmd.pcr = bswap_32(4); // PCR #4 for kernel
-       sha1(dom->kernel_blob, dom->kernel_size, cmd.hash);
-
-       rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp, &resplen);
-       ASSERT(rv == 0 && resp->status == 0);
-
-       cmd.pcr = bswap_32(5); // PCR #5 for cmdline
-       sha1(cmdline, strlen(cmdline), cmd.hash);
-       rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp, &resplen);
-       ASSERT(rv == 0 && resp->status == 0);
-
-       cmd.pcr = bswap_32(5); // PCR #5 for initrd
-       sha1(dom->ramdisk_blob, dom->ramdisk_size, cmd.hash);
-       rv = tpmfront_cmd(tpm, (void*)&cmd, sizeof(cmd), (void*)&resp, &resplen);
-       ASSERT(rv == 0 && resp->status == 0);
-
-       shutdown_tpmfront(tpm);
-}
-
-void kexec(void *kernel, long kernel_size, void *module, long module_size, char *cmdline, unsigned long flags)
-{
-    struct xc_dom_image *dom;
-    int rc;
-    domid_t domid = DOMID_SELF;
-    xen_pfn_t pfn;
-    xc_interface *xc_handle;
-    unsigned long i;
-    void *seg;
-    xen_pfn_t boot_page_mfn = virt_to_mfn(&_boot_page);
-    char features[] = "";
-    struct mmu_update *m2p_updates;
-    unsigned long nr_m2p_updates;
-
-    DEBUG("booting with cmdline %s\n", cmdline);
-    xc_handle = xc_interface_open(0,0,0);
-
-    dom = xc_dom_allocate(xc_handle, cmdline, features);
-    dom->allocate = kexec_allocate;
-
-    /* We are using guest owned memory, therefore no limits. */
-    xc_dom_kernel_max_size(dom, 0);
-    xc_dom_ramdisk_max_size(dom, 0);
-
-    dom->kernel_blob = kernel;
-    dom->kernel_size = kernel_size;
-
-    dom->ramdisk_blob = module;
-    dom->ramdisk_size = module_size;
-
-    dom->flags = flags;
-    dom->console_evtchn = start_info.console.domU.evtchn;
-    dom->xenstore_evtchn = start_info.store_evtchn;
-
-    tpm_hash2pcr(dom, cmdline);
-
-    if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 ) {
-        grub_printf("xc_dom_boot_xen_init returned %d\n", rc);
-        errnum = ERR_BOOT_FAILURE;
-        goto out;
-    }
-    if ( (rc = xc_dom_parse_image(dom)) != 0 ) {
-        grub_printf("xc_dom_parse_image returned %d\n", rc);
-        errnum = ERR_BOOT_FAILURE;
-        goto out;
-    }
-
-#ifdef __i386__
-    if (strcmp(dom->guest_type, "xen-3.0-x86_32p")) {
-        grub_printf("can only boot x86 32 PAE kernels, not %s\n", dom->guest_type);
-        errnum = ERR_EXEC_FORMAT;
-        goto out;
-    }
-#endif
-#ifdef __x86_64__
-    if (strcmp(dom->guest_type, "xen-3.0-x86_64")) {
-        grub_printf("can only boot x86 64 kernels, not %s\n", dom->guest_type);
-        errnum = ERR_EXEC_FORMAT;
-        goto out;
-    }
-#endif
-
-    /* equivalent of xc_dom_mem_init */
-    if (xc_dom_set_arch_hooks(dom)) {
-        grub_printf("xc_dom_set_arch_hooks failed\n");
-        errnum = ERR_EXEC_FORMAT;
-        goto out;
-    }
-    dom->total_pages = start_info.nr_pages;
-
-    /* equivalent of arch_setup_meminit */
-    dom->p2m_size = dom->total_pages;
-
-    /* setup initial p2m */
-    dom->p2m_host = malloc(sizeof(*dom->p2m_host) * dom->p2m_size);
-
-    /* Start with our current P2M */
-    for (i = 0; i < dom->p2m_size; i++)
-        dom->p2m_host[i] = pfn_to_mfn(i);
-
-    if ( (rc = xc_dom_build_image(dom)) != 0 ) {
-        grub_printf("xc_dom_build_image returned %d\n", rc);
-        errnum = ERR_BOOT_FAILURE;
-        goto out;
-    }
-
-    /* copy hypercall page */
-    /* TODO: domctl instead, but requires privileges */
-    if (dom->parms.virt_hypercall != -1) {
-        pfn = PHYS_PFN(dom->parms.virt_hypercall - dom->parms.virt_base);
-        memcpy((void *) pages[pfn], hypercall_page, PAGE_SIZE);
-    }
-
-    /* Equivalent of xc_dom_boot_image */
-    dom->shared_info_mfn = PHYS_PFN(start_info.shared_info);
-
-    if (!xc_dom_compat_check(dom)) {
-        grub_printf("xc_dom_compat_check failed\n");
-        errnum = ERR_EXEC_FORMAT;
-        goto out;
-    }
-
-    /* Move current console, xenstore and boot MFNs to the allocated place */
-    do_exchange(dom, dom->console_pfn, start_info.console.domU.mfn);
-    do_exchange(dom, dom->xenstore_pfn, start_info.store_mfn);
-    DEBUG("virt base at %llx\n", dom->parms.virt_base);
-    DEBUG("bootstack_pfn %lx\n", dom->bootstack_pfn);
-    _boot_target = dom->parms.virt_base + PFN_PHYS(dom->bootstack_pfn);
-    DEBUG("_boot_target %lx\n", _boot_target);
-    do_exchange(dom, PHYS_PFN(_boot_target - dom->parms.virt_base),
-            virt_to_mfn(&_boot_page));
-
-    /* Make sure the bootstrap page table does not RW-map any of our current
-     * page table frames */
-    if ( (rc = xc_dom_update_guest_p2m(dom))) {
-        grub_printf("xc_dom_update_guest_p2m returned %d\n", rc);
-        errnum = ERR_BOOT_FAILURE;
-        goto out;
-    }
-
-    if ( dom->arch_hooks->setup_pgtables )
-        if ( (rc = dom->arch_hooks->setup_pgtables(dom))) {
-            grub_printf("setup_pgtables returned %d\n", rc);
-            errnum = ERR_BOOT_FAILURE;
-            goto out;
-        }
-
-    /* start info page */
-#undef start_info
-    if ( dom->arch_hooks->start_info )
-        dom->arch_hooks->start_info(dom);
-#define start_info (start_info_union.start_info)
-
-    xc_dom_log_memory_footprint(dom);
-
-    /* Unmap libxc's projection of the boot page table */
-    seg = xc_dom_seg_to_ptr(dom, &dom->pgtables_seg);
-    munmap(seg, dom->pgtables_seg.vend - dom->pgtables_seg.vstart);
-
-    /* Unmap day0 pages to avoid having a r/w mapping of the future page table */
-    for (pfn = 0; pfn < allocated; pfn++)
-        munmap((void*) pages[pfn], PAGE_SIZE);
-
-    /* Pin the boot page table base */
-    if ( (rc = pin_table(dom->xch,
-#ifdef __i386__
-                MMUEXT_PIN_L3_TABLE,
-#endif
-#ifdef __x86_64__
-                MMUEXT_PIN_L4_TABLE,
-#endif
-                xc_dom_p2m(dom, dom->pgtables_seg.pfn),
-                dom->guest_domid)) != 0 ) {
-        grub_printf("pin_table(%lx) returned %d\n", xc_dom_p2m(dom,
-                    dom->pgtables_seg.pfn), rc);
-        errnum = ERR_BOOT_FAILURE;
-        goto out_remap;
-    }
-
-    /* We populate the Mini-OS page table here so that boot.S can just call
-     * update_va_mapping to project itself there.  */
-    need_pgt(_boot_target);
-    DEBUG("day0 pages %lx\n", allocated);
-    DEBUG("boot target page %lx\n", _boot_target);
-    DEBUG("boot page %p\n", &_boot_page);
-    DEBUG("boot page mfn %lx\n", boot_page_mfn);
-    _boot_page_entry = PFN_PHYS(boot_page_mfn) | L1_PROT;
-    DEBUG("boot page entry %llx\n", _boot_page_entry);
-    _boot_oldpdmfn = virt_to_mfn(start_info.pt_base);
-    DEBUG("boot old pd mfn %lx\n", _boot_oldpdmfn);
-    DEBUG("boot pd virt %lx\n", dom->pgtables_seg.vstart);
-    _boot_pdmfn = dom->p2m_host[PHYS_PFN(dom->pgtables_seg.vstart - dom->parms.virt_base)];
-    DEBUG("boot pd mfn %lx\n", _boot_pdmfn);
-    _boot_stack = _boot_target + PAGE_SIZE;
-    DEBUG("boot stack %lx\n", _boot_stack);
-    _boot_start_info = dom->parms.virt_base + PFN_PHYS(dom->start_info_pfn);
-    DEBUG("boot start info %lx\n", _boot_start_info);
-    _boot_start = dom->parms.virt_entry;
-    DEBUG("boot start %lx\n", _boot_start);
-
-    /* Keep only useful entries */
-    for (nr_m2p_updates = pfn = 0; pfn < start_info.nr_pages; pfn++)
-        if (dom->p2m_host[pfn] != pfn_to_mfn(pfn))
-            nr_m2p_updates++;
-
-    m2p_updates = malloc(sizeof(*m2p_updates) * nr_m2p_updates);
-    for (i = pfn = 0; pfn < start_info.nr_pages; pfn++)
-        if (dom->p2m_host[pfn] != pfn_to_mfn(pfn)) {
-            m2p_updates[i].ptr = PFN_PHYS(dom->p2m_host[pfn]) | MMU_MACHPHYS_UPDATE;
-            m2p_updates[i].val = pfn;
-            i++;
-        }
-
-    for (i = 0; i < blk_nb; i++)
-        shutdown_blkfront(blk_dev[i]);
-    if (net_dev)
-        shutdown_netfront(net_dev);
-    if (kbd_dev)
-        shutdown_kbdfront(kbd_dev);
-    stop_kernel();
-
-    /* Update M2P */
-    if ((rc = HYPERVISOR_mmu_update(m2p_updates, nr_m2p_updates, NULL, DOMID_SELF)) < 0) {
-        xprintk("Could not update M2P\n");
-        ASSERT(0);
-    }
-
-    xprintk("go!\n");
-
-    /* Jump to trampoline boot page */
-    _boot();
-
-    ASSERT(0);
-
-out_remap:
-    for (pfn = 0; pfn < allocated; pfn++)
-        do_map_frames(pages[pfn], &pages_mfns[pfn], 1, 0, 0, DOMID_SELF, 0, L1_PROT);
-out:
-    xc_dom_release(dom);
-    for (pfn = 0; pfn < allocated; pfn++)
-        free_page((void*)pages[pfn]);
-    free(pages);
-    free(pages_mfns);
-    pages = NULL;
-    pages_mfns = NULL;
-    allocated = 0;
-    xc_interface_close(xc_handle );
-}
diff --git a/stubdom/grub/mini-os.c b/stubdom/grub/mini-os.c
deleted file mode 100644 (file)
index 4fc052a..0000000
+++ /dev/null
@@ -1,771 +0,0 @@
-/*
- * Mini-OS support for GRUB.
- *
- * Samuel Thibault <Samuel.Thibault@eu.citrix.com>, May 2008
- */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <unistd.h>
-
-#include <hypervisor.h>
-#include <blkfront.h>
-#include <netfront.h>
-#include <fbfront.h>
-#include <semaphore.h>
-
-#include <osdep.h>
-#include <shared.h>
-#include <nic.h>
-#include <etherboot.h>
-#include <terminfo.h>
-#include <term.h>
-
-#include "mini-os.h"
-
-extern const char *preset_menu;
-char config_file[DEFAULT_FILE_BUFLEN] = "(hd0,0)/boot/grub/menu.lst";
-unsigned long boot_drive = NETWORK_DRIVE;
-unsigned long install_partition = 0xFFFFFF;
-
-char version_string[] = VERSION;
-
-/* Variables from asm.S */
-int saved_entryno;
-
-/*
- * Disk
- */
-
-struct blkfront_dev **blk_dev;
-int blk_nb;
-static struct blkfront_info *blk_info;
-
-static int vbdcmp(const void *_vbd1, const void *_vbd2) {
-    char *vbd1 = *(char **)_vbd1;
-    char *vbd2 = *(char **)_vbd2;
-    int vbdn1 = atoi(vbd1);
-    int vbdn2 = atoi(vbd2);
-    return vbdn1 - vbdn2;
-}
-
-void init_disk (void)
-{
-    char **list;
-    char *msg;
-    int i;
-    char *path;
-
-    msg = xenbus_ls(XBT_NIL, "device/vbd", &list);
-    if (msg) {
-        printk("Error %s while reading list of disks\n", msg);
-        free(msg);
-        return;
-    }
-    blk_nb = 0;
-    while (list[blk_nb])
-        blk_nb++;
-    blk_dev = malloc(blk_nb * sizeof(*blk_dev));
-    blk_info = malloc(blk_nb * sizeof(*blk_info));
-
-    qsort(list, blk_nb, sizeof(*list), vbdcmp);
-
-    for (i = 0; i < blk_nb; i++) {
-        printk("vbd %s is hd%d\n", list[i], i);
-        asprintf(&path, "device/vbd/%s", list[i]);
-        blk_dev[i] = init_blkfront(path, &blk_info[i]);
-        free(path);
-        free(list[i]);
-    }
-}
-
-/* Return the geometry of DRIVE in GEOMETRY. If an error occurs, return
-   non-zero, otherwise zero.  */
-int get_diskinfo (int drive, struct geometry *geometry)
-{
-    int i;
-    if (!(drive & 0x80))
-        return -1;
-
-    i = drive - 0x80;
-    if (i >= blk_nb)
-        return -1;
-
-    /* Bogus geometry */
-    geometry->cylinders = 65535;
-    geometry->heads = 255;
-    geometry->sectors = 63;
-
-    geometry->total_sectors = blk_info[i].sectors;
-    geometry->sector_size = blk_info[i].sector_size;
-    geometry->flags = BIOSDISK_FLAG_LBA_EXTENSION;
-    if (blk_info[i].info & VDISK_CDROM)
-        geometry->flags |= BIOSDISK_FLAG_CDROM;
-    return 0;
-}
-
-/* Read/write NSEC sectors starting from SECTOR in DRIVE disk with GEOMETRY
-   from/into SEGMENT segment. If READ is BIOSDISK_READ, then read it,
-   else if READ is BIOSDISK_WRITE, then write it. If an geometry error
-   occurs, return BIOSDISK_ERROR_GEOMETRY, and if other error occurs, then
-   return the error number. Otherwise, return 0.  */
-int
-biosdisk (int read, int drive, struct geometry *geometry,
-          unsigned int sector, int nsec, int segment)
-{
-    void *addr = (void *) ((unsigned long)segment << 4);
-    struct blkfront_aiocb aiocb;
-    int i;
-
-    if (!(drive & 0x80))
-        return -1;
-
-    i = drive - 0x80;
-    if (i >= blk_nb)
-        return -1;
-
-    if (sector + nsec > geometry->total_sectors)
-      return -1;
-
-    aiocb.aio_dev = blk_dev[i];
-    aiocb.aio_buf = addr;
-    aiocb.aio_nbytes = (size_t)nsec * blk_info[i].sector_size;
-    aiocb.aio_offset = (off_t)sector * blk_info[i].sector_size;
-    aiocb.aio_cb = NULL;
-
-    blkfront_io(&aiocb, read == BIOSDISK_WRITE);
-
-    return 0;
-}
-
-static int
-load_file(char *name, void **ptr, long *size)
-{
-    char *buf = NULL;
-    int allocated = 1 * 1024 * 1024;
-    int len, filled = 0;
-
-    if (!grub_open (name))
-        return -1;
-
-    buf = malloc(allocated);
-
-    errnum = 0;
-    while (1) {
-        len = grub_read (buf + filled, allocated - filled);
-        if (! len) {
-            if (!errnum)
-                break;
-            grub_close ();
-            return -1;
-        }
-        filled += len;
-        if (filled < allocated)
-            break;
-        allocated *= 2;
-        buf = realloc(buf, allocated);
-    }
-    grub_close ();
-    *ptr = buf;
-    *size = filled;
-    return 0;
-}
-
-void *kernel_image, *module_image;
-long  kernel_size, module_size;
-char *kernel_arg, *module_arg;
-void *multiboot_next_module;
-struct xen_multiboot_mod_list *multiboot_next_module_header;
-
-kernel_t
-load_image (char *kernel, char *arg, kernel_t suggested_type,
-            unsigned long load_flags)
-{
-    arg = skip_to(0, arg);
-    if (kernel_image)
-        free(kernel_image);
-    kernel_image = NULL;
-    if (load_file (kernel, &kernel_image, &kernel_size))
-        return KERNEL_TYPE_NONE;
-    if (kernel_arg)
-        free(kernel_arg);
-    kernel_arg = strdup(arg);
-    return KERNEL_TYPE_PV;
-}
-
-int
-load_initrd (char *initrd)
-{
-    if (module_image)
-        free(module_image);
-    module_image = NULL;
-    multiboot_next_module = NULL;
-    multiboot_next_module_header = NULL;
-    load_file (initrd, &module_image, &module_size);
-    return ! errnum;
-}
-
-int
-load_module (char *module, char *arg)
-{
-    void *new_module, *new_module_image;
-    long new_module_size, rounded_new_module_size;
-
-    if (load_file (module, &new_module, &new_module_size))
-        return 0;
-    if (strlen(arg) >= PAGE_SIZE) {
-        /* Too big module command line */
-        errnum = ERR_WONT_FIT;
-        return 0;
-    }
-    rounded_new_module_size = (new_module_size + PAGE_SIZE - 1) & PAGE_MASK;
-
-    if (module_image && !multiboot_next_module_header) {
-        /* Initrd already loaded, drop it */
-        free(module_image);
-        if (module_arg)
-            free(module_arg);
-        module_image = NULL;
-    }
-    if (!module_image)
-        /* Reserve one page for the header */
-        multiboot_next_module = (void*) PAGE_SIZE;
-
-    /* Allocate more room for the new module plus its arg */
-    new_module_image = realloc(module_image,
-            (multiboot_next_module - module_image) + rounded_new_module_size + PAGE_SIZE);
-
-    /* Update pointers */
-    multiboot_next_module += new_module_image - module_image;
-    multiboot_next_module_header = (void*) multiboot_next_module_header + (new_module_image - module_image);
-    module_image = new_module_image;
-
-    if ((void*) (multiboot_next_module_header+1) - module_image > PAGE_SIZE) {
-        /* Too many modules */
-        errnum = ERR_WONT_FIT;
-        return 0;
-    }
-
-    /* Copy module */
-    memcpy(multiboot_next_module, new_module, new_module_size);
-    multiboot_next_module_header->mod_start = multiboot_next_module - module_image;
-    multiboot_next_module_header->mod_end = multiboot_next_module_header->mod_start + new_module_size - 1;
-    multiboot_next_module += rounded_new_module_size;
-
-    /* Copy cmdline */
-    strcpy(multiboot_next_module, arg);
-    multiboot_next_module_header->cmdline = multiboot_next_module - module_image;
-    multiboot_next_module += PAGE_SIZE;
-
-    /* Pad */
-    multiboot_next_module_header->pad = 0;
-
-    multiboot_next_module_header++;
-
-    return 1;
-}
-
-void
-pv_boot (void)
-{
-    unsigned long flags = 0;
-    if (multiboot_next_module_header) {
-        /* Termination entry */
-        multiboot_next_module_header->mod_start = 0;
-        /* Total size */
-        module_size = multiboot_next_module - module_image;
-        /* It's a multiboot module */
-        flags |= SIF_MULTIBOOT_MOD;
-    }
-    kexec(kernel_image, kernel_size, module_image, module_size, kernel_arg, flags);
-}
-
-/*
- * Network
- */
-
-struct netfront_dev *net_dev;
-
-int
-minios_probe (struct nic *nic)
-{
-    char *ip;
-
-    if (net_dev)
-        return 1;
-
-    /* Clear the ARP table.  */
-    grub_memset ((char *) arptable, 0,
-                 MAX_ARP * sizeof (struct arptable_t));
-
-    net_dev = init_netfront(NULL, (void*) -1, nic->node_addr, &ip);
-    if (!net_dev)
-        return 0;
-
-    return 1;
-}
-
-/* reset adapter */
-static void minios_reset(struct nic *nic)
-{
-    /* TODO? */
-}
-
-static void minios_disable(struct nic *nic)
-{
-}
-
-/* Wait for a frame */
-static int minios_poll(struct nic *nic)
-{
-    return !! (nic->packetlen = netfront_receive(net_dev, (void*) nic->packet, ETH_FRAME_LEN));
-}
-
-/* Transmit a frame */
-struct frame {
-        uint8_t dest[ETH_ALEN];
-        uint8_t src[ETH_ALEN];
-        uint16_t type;
-        unsigned char data[];
-};
-static void minios_transmit (struct nic *nic, const char *d, unsigned int t,
-                             unsigned int s, const char *p)
-{
-    struct frame *frame = alloca(sizeof(*frame) + s);
-
-    memcpy(frame->dest, d, ETH_ALEN);
-    memcpy(frame->src, nic->node_addr, ETH_ALEN);
-    frame->type = htons(t);
-    memcpy(frame->data, p, s);
-
-    netfront_xmit(net_dev, (void*) frame, sizeof(*frame) + s);
-}
-
-static char packet[ETH_FRAME_LEN];
-
-struct nic nic = {
-    .reset = minios_reset,
-    .poll = minios_poll,
-    .transmit = minios_transmit,
-    .disable = minios_disable,
-    .flags = 0,
-    .rom_info = NULL,
-    .node_addr = arptable[ARP_CLIENT].node,
-    .packet = packet,
-    .packetlen = 0,
-    .priv_data = NULL,
-};
-
-int
-eth_probe (void)
-{
-    return minios_probe(&nic);
-}
-
-int
-eth_poll (void)
-{
-    return minios_poll (&nic);
-}
-
-void
-eth_disable (void)
-{
-    minios_disable (&nic);
-}
-
-void
-eth_transmit (const char *d, unsigned int t,
-              unsigned int s, const void *p)
-{
-    minios_transmit (&nic, d, t, s, p);
-    if (t == IP)
-        twiddle();
-}
-
-/*
- * Console
- */
-void
-serial_hw_put (int _c)
-{
-  char c = _c;
-  console_print(NULL, &c, 1);
-}
-
-int
-serial_hw_fetch (void)
-{
-    char key;
-
-    if (!xencons_ring_avail(NULL))
-        return -1;
-
-    read(STDIN_FILENO, &key, 1);
-    switch (key) {
-    case 0x7f: key = '\b'; break;
-    }
-    return key;
-}
-
-/*
- * PVFB
- */
-struct kbdfront_dev *kbd_dev;
-struct fbfront_dev *fb_dev;
-static union xenkbd_in_event ev;
-static int has_ev;
-int console_checkkey (void)
-{
-    if (has_ev)
-        return 1;
-    has_ev = kbdfront_receive(kbd_dev, &ev, 1);
-    return has_ev;
-}
-
-/* static QWERTY layout, that's what most PC BIOSes do anyway */
-static char linux2ascii[] = {
-    [ 1 ] = 27,
-    [ 2 ] = '1',
-    [ 3 ] = '2',
-    [ 4 ] = '3',
-    [ 5 ] = '4',
-    [ 6 ] = '5',
-    [ 7 ] = '6',
-    [ 8 ] = '7',
-    [ 9 ] = '8',
-    [ 10 ] = '9',
-    [ 11 ] = '0',
-    [ 12 ] = '-',
-    [ 13 ] = '=',
-    [ 14 ] = '\b',
-    [ 15 ] = '\t',
-    [ 16 ] = 'q',
-    [ 17 ] = 'w',
-    [ 18 ] = 'e',
-    [ 19 ] = 'r',
-    [ 20 ] = 't',
-    [ 21 ] = 'y',
-    [ 22 ] = 'u',
-    [ 23 ] = 'i',
-    [ 24 ] = 'o',
-    [ 25 ] = 'p',
-    [ 26 ] = '[',
-    [ 27 ] = ']',
-    [ 28 ] = '\n',
-
-    [ 30 ] = 'a',
-    [ 31 ] = 's',
-    [ 32 ] = 'd',
-    [ 33 ] = 'f',
-    [ 34 ] = 'g',
-    [ 35 ] = 'h',
-    [ 36 ] = 'j',
-    [ 37 ] = 'k',
-    [ 38 ] = 'l',
-    [ 39 ] = ';',
-    [ 40 ] = '\'',
-    [ 41 ] = '`',
-
-    [ 43 ] = '\\',
-    [ 44 ] = 'z',
-    [ 45 ] = 'x',
-    [ 46 ] = 'c',
-    [ 47 ] = 'v',
-    [ 48 ] = 'b',
-    [ 49 ] = 'n',
-    [ 50 ] = 'm',
-    [ 51 ] = ',',
-    [ 52 ] = '.',
-    [ 53 ] = '/',
-
-    [ 55 ] = '*',
-    [ 57 ] = ' ',
-
-    [ 71 ] = '7',
-    [ 72 ] = '8',
-    [ 73 ] = '9',
-    [ 74 ] = '-',
-    [ 75 ] = '4',
-    [ 76 ] = '5',
-    [ 77 ] = '6',
-    [ 78 ] = '+',
-    [ 79 ] = '1',
-    [ 80 ] = '2',
-    [ 81 ] = '3',
-    [ 82 ] = '0',
-    [ 83 ] = '.',
-
-    [ 86 ] = '<',
-
-    [ 96 ] = '\n',
-
-    [ 98 ] = '/',
-
-    [ 102 ] = 1,  /* home */
-    [ 103 ] = 16, /* up */
-    [ 104 ] = 7,  /* page up */
-    [ 105 ] = 2,  /* left */
-    [ 106 ] = 6,  /* right */
-    [ 107 ] = 5,  /* end */
-    [ 108 ] = 14, /* down */
-    [ 109 ] = 3,  /* page down */
-
-    [ 111 ] = 4,  /* delete */
-};
-
-static char linux2ascii_shifted[] = {
-    [ 1 ] = 27,
-    [ 2 ] = '!',
-    [ 3 ] = '@',
-    [ 4 ] = '#',
-    [ 5 ] = '$',
-    [ 6 ] = '%',
-    [ 7 ] = '^',
-    [ 8 ] = '&',
-    [ 9 ] = '*',
-    [ 10 ] = '(',
-    [ 11 ] = ')',
-    [ 12 ] = '_',
-    [ 13 ] = '+',
-    [ 14 ] = '\b',
-    [ 15 ] = '\t',
-    [ 16 ] = 'Q',
-    [ 17 ] = 'W',
-    [ 18 ] = 'E',
-    [ 19 ] = 'R',
-    [ 20 ] = 'T',
-    [ 21 ] = 'Y',
-    [ 22 ] = 'U',
-    [ 23 ] = 'I',
-    [ 24 ] = 'O',
-    [ 25 ] = 'P',
-    [ 26 ] = '{',
-    [ 27 ] = '}',
-    [ 28 ] = '\n',
-
-    [ 30 ] = 'A',
-    [ 31 ] = 'S',
-    [ 32 ] = 'D',
-    [ 33 ] = 'F',
-    [ 34 ] = 'G',
-    [ 35 ] = 'H',
-    [ 36 ] = 'J',
-    [ 37 ] = 'K',
-    [ 38 ] = 'L',
-    [ 39 ] = ':',
-    [ 40 ] = '"',
-    [ 41 ] = '~',
-
-    [ 43 ] = '|',
-    [ 44 ] = 'Z',
-    [ 45 ] = 'X',
-    [ 46 ] = 'C',
-    [ 47 ] = 'V',
-    [ 48 ] = 'B',
-    [ 49 ] = 'N',
-    [ 50 ] = 'M',
-    [ 51 ] = '<',
-    [ 52 ] = '>',
-    [ 53 ] = '?',
-
-    [ 55 ] = '*',
-    [ 57 ] = ' ',
-
-    [ 71 ] = '7',
-    [ 72 ] = '8',
-    [ 73 ] = '9',
-    [ 74 ] = '-',
-    [ 75 ] = '4',
-    [ 76 ] = '5',
-    [ 77 ] = '6',
-    [ 78 ] = '+',
-    [ 79 ] = '1',
-    [ 80 ] = '2',
-    [ 81 ] = '3',
-    [ 82 ] = '0',
-    [ 83 ] = '.',
-
-    [ 86 ] = '>',
-
-    [ 96 ] = '\n',
-
-    [ 98 ] = '/',
-
-    [ 102 ] = 1,  /* home */
-    [ 103 ] = 16, /* up */
-    [ 104 ] = 7,  /* page up */
-    [ 105 ] = 2,  /* left */
-    [ 106 ] = 6,  /* right */
-    [ 107 ] = 5,  /* end */
-    [ 108 ] = 14, /* down */
-    [ 109 ] = 3,  /* page down */
-
-    [ 111 ] = 4,  /* delete */
-};
-
-int console_getkey (void)
-{
-    static int shift, control, alt, caps_lock;
-
-    if (!has_ev)
-        has_ev = kbdfront_receive(kbd_dev, &ev, 1);
-    if (!has_ev)
-        return 0;
-
-    has_ev = 0;
-    if (ev.type != XENKBD_TYPE_KEY)
-        return 0;
-
-    if (ev.key.keycode == 42 || ev.key.keycode == 54) {
-        caps_lock = 0;
-        shift = ev.key.pressed;
-        return 0;
-    }
-    if (ev.key.keycode == 58) {
-        caps_lock ^= 1;
-        return 0;
-    }
-    if (ev.key.keycode == 29 || ev.key.keycode == 97) {
-        control = ev.key.pressed;
-        return 0;
-    }
-    if (ev.key.keycode == 56) {
-        alt = ev.key.pressed;
-        return 0;
-    }
-
-    if (!ev.key.pressed)
-        return 0;
-
-    if (ev.key.keycode < sizeof(linux2ascii) / sizeof(*linux2ascii)) {
-        char val;
-        if (shift || caps_lock)
-            val = linux2ascii_shifted[ev.key.keycode];
-        else
-            val = linux2ascii[ev.key.keycode];
-        if (control)
-            val &= ~0x60;
-        return val;
-    }
-
-    return 0;
-}
-
-static DECLARE_MUTEX_LOCKED(kbd_sem);
-static void kbd_thread(void *p)
-{
-    kbd_dev = init_kbdfront(NULL, 1);
-    up(&kbd_sem);
-}
-
-struct fbfront_dev *fb_open(void *fb, int width, int height, int depth)
-{
-    unsigned long *mfns;
-    int linesize = width * (depth / 8);
-    int memsize = linesize * height;
-    int numpages = (memsize + PAGE_SIZE - 1) / PAGE_SIZE;
-    int i;
-
-    create_thread("kbdfront", kbd_thread, &kbd_sem);
-
-    mfns = malloc(numpages * sizeof(*mfns));
-    for (i = 0; i < numpages; i++) {
-        memset(fb + i * PAGE_SIZE, 0, PAGE_SIZE);
-        mfns[i] = virtual_to_mfn(fb + i * PAGE_SIZE);
-    }
-    fb_dev = init_fbfront(NULL, mfns, width, height, depth, linesize, numpages);
-    free(mfns);
-
-    if (!fb_dev)
-        return NULL;
-
-    down(&kbd_sem);
-    if (!kbd_dev)
-        return NULL;
-
-    return fb_dev;
-}
-
-void kbd_close(void *foo)
-{
-    shutdown_kbdfront(kbd_dev);
-    kbd_dev = NULL;
-}
-
-void fb_close(void)
-{
-    create_thread("kbdfront close", kbd_close, NULL);
-    shutdown_fbfront(fb_dev);
-    fb_dev = NULL;
-}
-
-/*
- * Misc
- */
-
-int getrtsecs (void)
-{
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return tv.tv_sec % 10 + ((tv.tv_sec / 10) % 6) * 0x10;
-}
-
-int currticks (void)
-{
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return ((tv.tv_sec * 1000000ULL + tv.tv_usec) * TICKS_PER_SEC) / 1000000;
-}
-
-void __attribute__ ((noreturn)) grub_reboot (void)
-{
-    for ( ;; )
-    {
-        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_reboot };
-        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
-    }
-}
-
-#define SCRATCH_MEMSIZE (4 * 1024 * 1024)
-
-/* Note: not allocating it dynamically permits to make sure it lays below 4G
- * for grub's 32bit pointers to work */
-char grub_scratch_mem[SCRATCH_MEMSIZE] __attribute__((aligned(PAGE_SIZE)));
-
-int main(int argc, char **argv)
-{
-    if (argc > 1 && memcmp(argv[1], "--vtpm-label=", 13) == 0) {
-        vtpm_label = argv[1] + 13;
-        argc--;
-        argv++;
-    }
-
-    if (argc > 1) {
-        strncpy(config_file, argv[1], sizeof(config_file) - 1);
-        config_file[sizeof(config_file) - 1] = 0;
-        if (!strncmp(config_file, "(nd)", 4))
-            preset_menu = "dhcp";
-    } else if (start_info.mod_len)
-        preset_menu = (void*) start_info.mod_start;
-    else
-        preset_menu = "dhcp --with-configfile";
-
-    mbi.drives_addr = BOOTSEC_LOCATION + (60 * 1024);
-    mbi.drives_length = 0;
-
-    mbi.boot_loader_name = (unsigned long) "GNU GRUB " VERSION;
-    mbi.mem_lower = (start_info.nr_pages * PAGE_SIZE) / 1024;
-    mbi.mem_upper = 0;
-    saved_drive = boot_drive;
-    saved_partition = install_partition;
-
-    init_disk();
-
-    /* Try to make sure the client part got launched */
-    sleep(1);
-    cmain();
-    printk("cmain returned!\n");
-}
diff --git a/stubdom/grub/mini-os.h b/stubdom/grub/mini-os.h
deleted file mode 100644 (file)
index 9ec2bda..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-extern int blk_nb;
-extern struct blkfront_dev **blk_dev;
-extern struct netfront_dev *net_dev;
-extern struct kbdfront_dev *kbd_dev;
-extern struct fbfront_dev *fb_dev;
-
-extern char* vtpm_label;
diff --git a/stubdom/grub/minios.cfg b/stubdom/grub/minios.cfg
deleted file mode 100644 (file)
index 8df4909..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_START_NETWORK=n
-CONFIG_SPARSE_BSS=n
-CONFIG_TPMFRONT=y
diff --git a/stubdom/grub/osdep.h b/stubdom/grub/osdep.h
deleted file mode 100644 (file)
index 1d3e50a..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef __OSDEP_H__
-#define __OSDEP_H__
-
-#include <byteswap.h>
-#define swap32(x) bswap_32(x)
-#define swap16(x) bswap_16(x)
-
-#include <machine/endian.h>
-#if BYTE_ORDER == BIG_ENDIAN
-#define htons(x) (x)
-#define ntohs(x) (x)
-#define htonl(x) (x)
-#define ntohl(x) (x)
-#else
-#define htons(x) swap16(x)
-#define ntohs(x) swap16(x)
-#define htonl(x) swap32(x)
-#define ntohl(x) swap32(x)
-#endif
-
-typedef unsigned long Address;
-
-/* ANSI prototyping macro */
-#ifdef  __STDC__
-#define P(x)   x
-#else
-#define P(x)   ()
-#endif
-
-#endif
diff --git a/stubdom/ioemu-minios.cfg b/stubdom/ioemu-minios.cfg
deleted file mode 100644 (file)
index d690553..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-CONFIG_START_NETWORK=n
-CONFIG_QEMU_XS_ARGS=y
-CONFIG_PCIFRONT=y
diff --git a/stubdom/libpci.config.h b/stubdom/libpci.config.h
deleted file mode 100644 (file)
index 28c2f6a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#define PCI_OS_MINIOS
-#define PCI_HAVE_STDINT_H
-#define PCI_PATH_IDS_DIR "."
-#define PCI_COMPRESSED_IDS
-#define PCI_IDS "pci.ids.gz"
diff --git a/stubdom/libpci.config.mak b/stubdom/libpci.config.mak
deleted file mode 100644 (file)
index 5c8632c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-LIBZ=-lz
-LDLIBS+=$(LIBZ)
-PCI_OS_MINIOS=1
-PCI_HAVE_STDINT_H=1
-PCI_PATH_IDS_DIR=.
-PCI_COMPRESSED_IDS=1
-PCI_IDS=pci.ids.gz
diff --git a/stubdom/lwip.dhcp_create_request-hwaddr_len.patch b/stubdom/lwip.dhcp_create_request-hwaddr_len.patch
deleted file mode 100644 (file)
index c43f282..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-Index: src/core/dhcp.c
-===================================================================
---- src/core/dhcp.c
-+++ src/core/dhcp.c
-@@ -1356,7 +1358,7 @@ dhcp_create_request(struct netif *netif)
-   dhcp->msg_out->giaddr.addr = 0;
-   for (i = 0; i < DHCP_CHADDR_LEN; i++) {
-     /* copy netif hardware address, pad with zeroes */
--    dhcp->msg_out->chaddr[i] = (i < netif->hwaddr_len) ? netif->hwaddr[i] : 0/* pad byte*/;
-+    dhcp->msg_out->chaddr[i] = (i < (netif->hwaddr_len > NETIF_MAX_HWADDR_LEN ? NETIF_MAX_HWADDR_LEN : netif->hwaddr_len)) ? netif->hwaddr[i] : 0/* pad byte*/;
-   }
-   for (i = 0; i < DHCP_SNAME_LEN; i++) {
-     dhcp->msg_out->sname[i] = 0;
diff --git a/stubdom/lwip.patch-cvs b/stubdom/lwip.patch-cvs
deleted file mode 100644 (file)
index d03068d..0000000
+++ /dev/null
@@ -1,2398 +0,0 @@
-? .ChangeLog.swp
-? ChangeLog
-Index: CHANGELOG
-===================================================================
-RCS file: /sources/lwip/lwip/CHANGELOG,v
-retrieving revision 1.300
-retrieving revision 1.318
-diff -u -p -r1.300 -r1.318
---- CHANGELOG  23 Mar 2008 13:49:39 -0000      1.300
-+++ CHANGELOG  14 Jul 2008 20:12:36 -0000      1.318
-@@ -19,9 +19,77 @@ HISTORY
-   ++ New features:
-+  2008-06-30 Simon Goldschmidt
-+  * mem.c, opt.h, stats.h: fixed bug #21433: Calling mem_free/pbuf_free from
-+    interrupt context isn't safe: LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT allows
-+    mem_free to run between mem_malloc iterations. Added illegal counter for
-+    mem stats.
-+
-+  2008-06-27 Simon Goldschmidt
-+  * stats.h/.c, some other files: patch #6483: stats module improvement:
-+    Added defines to display each module's statistic individually, added stats
-+    defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter.
-+
-+  2008-06-17 Simon Goldschmidt
-+  * err.h: patch #6459: Made err_t overridable to use a more efficient type
-+    (define LWIP_ERR_T in cc.h)
-+
-+  2008-06-17 Simon Goldschmidt
-+  * slipif.c: patch #6480: Added a configuration option for slipif for symmetry
-+    to loopif
-+
-+  2008-06-17 Simon Goldschmidt (patch by Luca Ceresoli)
-+  * netif.c, loopif.c, ip.c, netif.h, loopif.h, opt.h: Checked in slightly
-+    modified version of patch # 6370: Moved loopif code to netif.c so that
-+    loopback traffic is supported on all netifs (all local IPs).
-+    Added option to limit loopback packets for each netifs.
-+
-   ++ Bugfixes:
-+  2008-08-14 Simon Goldschmidt
-+  * api_msg.c: fixed bug #23847: do_close_internal references freed memory (when
-+    tcp_close returns != ERR_OK)
-+
-+  2008-07-08 Frédéric Bernon
-+  * stats.h: Fix some build bugs introduced with patch #6483 (missing some parameters
-+    in macros, mainly if MEM_STATS=0 and MEMP_STATS=0).
-+
-+  2008-06-24 Jonathan Larmour
-+  * tcp_in.c: Fix for bug #23693 as suggested by Art R. Ensure cseg is unused
-+    if tcp_seg_copy fails.
-+
-+  2008-06-17 Simon Goldschmidt
-+  * inet_chksum.c: Checked in some ideas of patch #6460 (loop optimizations)
-+    and created defines for swapping bytes and folding u32 to u16.
-+
-+  2008-05-30 Kieran Mansley
-+  * tcp_in.c Remove redundant "if" statement, and use real rcv_wnd
-+    rather than rcv_ann_wnd when deciding if packets are in-window.
-+    Contributed by <arasmussen@consultant.datasys.swri.edu>
-+
-+  2008-05-30 Kieran Mansley
-+  * mem.h: Fix BUG#23254.  Change macro definition of mem_* to allow
-+    passing as function pointers when MEM_LIBC_MALLOC is defined.
-+
-+  2008-05-09 Jonathan Larmour
-+  * err.h, err.c, sockets.c: Fix bug #23119: Reorder timeout error code to
-+    stop it being treated as a fatal error.
-+
-+  2008-04-15 Simon Goldschmidt
-+  * dhcp.c: fixed bug #22804: dhcp_stop doesn't clear NETIF_FLAG_DHCP
-+    (flag now cleared)
-+
-+  2008-03-27 Simon Goldschmidt
-+  * mem.c, tcpip.c, tcpip.h, opt.h: fixed bug #21433 (Calling mem_free/pbuf_free
-+    from interrupt context isn't safe): set LWIP_USE_HEAP_FROM_INTERRUPT to 1
-+    in lwipopts.h or use pbuf_free_callback(p)/mem_free_callback(m) to free pbufs
-+    or heap memory from interrupt context
-+
-+  2008-03-26 Simon Goldschmidt
-+  * tcp_in.c, tcp.c: fixed bug #22249: division by zero could occur if a remote
-+    host sent a zero mss as TCP option.
-+
- (STABLE-1.3.0)
-Index: src/api/api_msg.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
-retrieving revision 1.102
-retrieving revision 1.104
-diff -u -p -r1.102 -r1.104
---- src/api/api_msg.c  21 Mar 2008 16:23:14 -0000      1.102
-+++ src/api/api_msg.c  15 Jul 2008 11:18:58 -0000      1.104
-@@ -598,11 +598,16 @@ do_close_internal(struct netconn *conn)
-   LWIP_ASSERT("pcb already closed", (conn->pcb.tcp != NULL));
-   /* Set back some callback pointers */
-+  tcp_arg(conn->pcb.tcp, NULL);
-   if (conn->pcb.tcp->state == LISTEN) {
--    tcp_arg(conn->pcb.tcp, NULL);
-     tcp_accept(conn->pcb.tcp, NULL);
-   } else {
-     tcp_recv(conn->pcb.tcp, NULL);
-+    tcp_accept(conn->pcb.tcp, NULL);
-+    /* some callbacks have to be reset if tcp_close is not successful */
-+    tcp_sent(conn->pcb.tcp, NULL);
-+    tcp_poll(conn->pcb.tcp, NULL, 4);
-+    tcp_err(conn->pcb.tcp, NULL);
-   }
-   /* Try to close the connection */
-   err = tcp_close(conn->pcb.tcp);
-@@ -610,11 +615,6 @@ do_close_internal(struct netconn *conn)
-     /* Closing succeeded */
-     conn->state = NETCONN_NONE;
-     /* Set back some callback pointers as conn is going away */
--    tcp_err(conn->pcb.tcp, NULL);
--    tcp_poll(conn->pcb.tcp, NULL, 4);
--    tcp_sent(conn->pcb.tcp, NULL);
--    tcp_recv(conn->pcb.tcp, NULL);
--    tcp_arg(conn->pcb.tcp, NULL);
-     conn->pcb.tcp = NULL;
-     conn->err = ERR_OK;
-     /* Trigger select() in socket layer. This send should something else so the
-@@ -623,6 +623,14 @@ do_close_internal(struct netconn *conn)
-     API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
-     /* wake up the application task */
-     sys_sem_signal(conn->op_completed);
-+  } else {
-+    /* Closing failed, restore some of the callbacks */
-+    /* Closing of listen pcb will never fail! */
-+    LWIP_ASSERT("Closing a listen pcb may not fail!", (conn->pcb.tcp->state != LISTEN));
-+    tcp_sent(conn->pcb.tcp, sent_tcp);
-+    tcp_poll(conn->pcb.tcp, poll_tcp, 4);
-+    tcp_err(conn->pcb.tcp, err_tcp);
-+    tcp_arg(conn->pcb.tcp, conn);
-   }
-   /* If closing didn't succeed, we get called again either
-      from poll_tcp or from sent_tcp */
-Index: src/api/err.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/api/err.c,v
-retrieving revision 1.11
-retrieving revision 1.12
-diff -u -p -r1.11 -r1.12
---- src/api/err.c      13 Dec 2007 23:06:50 -0000      1.11
-+++ src/api/err.c      9 May 2008 12:14:23 -0000       1.12
-@@ -44,17 +44,17 @@ static const char *err_strerr[] = {
-            "Ok.",                    /* ERR_OK          0  */
-            "Out of memory error.",   /* ERR_MEM        -1  */
-            "Buffer error.",          /* ERR_BUF        -2  */
--           "Routing problem.",       /* ERR_RTE        -3  */
--           "Connection aborted.",    /* ERR_ABRT       -4  */
--           "Connection reset.",      /* ERR_RST        -5  */
--           "Connection closed.",     /* ERR_CLSD       -6  */
--           "Not connected.",         /* ERR_CONN       -7  */
--           "Illegal value.",         /* ERR_VAL        -8  */
--           "Illegal argument.",      /* ERR_ARG        -9  */
--           "Address in use.",        /* ERR_USE        -10 */
--           "Low-level netif error.", /* ERR_IF         -11 */
--           "Already connected.",     /* ERR_ISCONN     -12 */
--           "Timeout.",               /* ERR_TIMEOUT    -13 */
-+           "Timeout.",               /* ERR_TIMEOUT    -3 */
-+           "Routing problem.",       /* ERR_RTE        -4  */
-+           "Connection aborted.",    /* ERR_ABRT       -5  */
-+           "Connection reset.",      /* ERR_RST        -6  */
-+           "Connection closed.",     /* ERR_CLSD       -7  */
-+           "Not connected.",         /* ERR_CONN       -8  */
-+           "Illegal value.",         /* ERR_VAL        -9  */
-+           "Illegal argument.",      /* ERR_ARG        -10 */
-+           "Address in use.",        /* ERR_USE        -11 */
-+           "Low-level netif error.", /* ERR_IF         -12 */
-+           "Already connected.",     /* ERR_ISCONN     -13 */
-            "Operation in progress."  /* ERR_INPROGRESS -14 */
- };
-Index: src/api/netdb.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/api/netdb.c,v
-retrieving revision 1.4
-retrieving revision 1.5
-diff -u -p -r1.4 -r1.5
---- src/api/netdb.c    26 Jan 2008 16:11:39 -0000      1.4
-+++ src/api/netdb.c    16 Jul 2008 20:36:12 -0000      1.5
-@@ -326,7 +326,8 @@ lwip_getaddrinfo(const char *nodename, c
-   if (nodename != NULL) {
-     /* copy nodename to canonname if specified */
-     size_t namelen = strlen(nodename);
--    ai->ai_canonname = mem_malloc(namelen + 1);
-+    LWIP_ASSERT("namelen is too long", (namelen + 1) <= (mem_size_t)-1);
-+    ai->ai_canonname = mem_malloc((mem_size_t)(namelen + 1));
-     if (ai->ai_canonname == NULL) {
-       goto memerr;
-     }
-Index: src/api/sockets.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/api/sockets.c,v
-retrieving revision 1.116
-retrieving revision 1.117
-diff -u -p -r1.116 -r1.117
---- src/api/sockets.c  13 Mar 2008 20:03:57 -0000      1.116
-+++ src/api/sockets.c  9 May 2008 12:14:24 -0000       1.117
-@@ -128,17 +128,17 @@ static const int err_to_errno_table[] = 
-   0,             /* ERR_OK          0      No error, everything OK. */
-   ENOMEM,        /* ERR_MEM        -1      Out of memory error.     */
-   ENOBUFS,       /* ERR_BUF        -2      Buffer error.            */
--  EHOSTUNREACH,  /* ERR_RTE        -3      Routing problem.         */
--  ECONNABORTED,  /* ERR_ABRT       -4      Connection aborted.      */
--  ECONNRESET,    /* ERR_RST        -5      Connection reset.        */
--  ESHUTDOWN,     /* ERR_CLSD       -6      Connection closed.       */
--  ENOTCONN,      /* ERR_CONN       -7      Not connected.           */
--  EINVAL,        /* ERR_VAL        -8      Illegal value.           */
--  EIO,           /* ERR_ARG        -9      Illegal argument.        */
--  EADDRINUSE,    /* ERR_USE        -10     Address in use.          */
--  -1,            /* ERR_IF         -11     Low-level netif error    */
--  -1,            /* ERR_ISCONN     -12     Already connected.       */
--  ETIMEDOUT,     /* ERR_TIMEOUT    -13     Timeout                  */
-+  ETIMEDOUT,     /* ERR_TIMEOUT    -3      Timeout                  */
-+  EHOSTUNREACH,  /* ERR_RTE        -4      Routing problem.         */
-+  ECONNABORTED,  /* ERR_ABRT       -5      Connection aborted.      */
-+  ECONNRESET,    /* ERR_RST        -6      Connection reset.        */
-+  ESHUTDOWN,     /* ERR_CLSD       -7      Connection closed.       */
-+  ENOTCONN,      /* ERR_CONN       -8      Not connected.           */
-+  EINVAL,        /* ERR_VAL        -9      Illegal value.           */
-+  EIO,           /* ERR_ARG        -10     Illegal argument.        */
-+  EADDRINUSE,    /* ERR_USE        -11     Address in use.          */
-+  -1,            /* ERR_IF         -12     Low-level netif error    */
-+  -1,            /* ERR_ISCONN     -13     Already connected.       */
-   EINPROGRESS    /* ERR_INPROGRESS -14     Operation in progress    */
- };
-Index: src/api/tcpip.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/api/tcpip.c,v
-retrieving revision 1.70
-retrieving revision 1.73
-diff -u -p -r1.70 -r1.73
---- src/api/tcpip.c    12 Jan 2008 11:52:22 -0000      1.70
-+++ src/api/tcpip.c    27 Jun 2008 20:34:51 -0000      1.73
-@@ -518,4 +518,42 @@ tcpip_init(void (* initfunc)(void *), vo
-   sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
- }
-+/**
-+ * Simple callback function used with tcpip_callback to free a pbuf
-+ * (pbuf_free has a wrong signature for tcpip_callback)
-+ *
-+ * @param p The pbuf (chain) to be dereferenced.
-+ */
-+static void
-+pbuf_free_int(void *p)
-+{
-+  struct pbuf *q = p;
-+  pbuf_free(q);
-+}
-+
-+/**
-+ * A simple wrapper function that allows you to free a pbuf from interrupt context.
-+ *
-+ * @param p The pbuf (chain) to be dereferenced.
-+ * @return ERR_OK if callback could be enqueued, an err_t if not
-+ */
-+err_t
-+pbuf_free_callback(struct pbuf *p)
-+{
-+  return tcpip_callback_with_block(pbuf_free_int, p, 0);
-+}
-+
-+/**
-+ * A simple wrapper function that allows you to free heap memory from
-+ * interrupt context.
-+ *
-+ * @param m the heap memory to free
-+ * @return ERR_OK if callback could be enqueued, an err_t if not
-+ */
-+err_t
-+mem_free_callback(void *m)
-+{
-+  return tcpip_callback_with_block(mem_free, m, 0);
-+}
-+
- #endif /* !NO_SYS */
-Index: src/core/dhcp.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/dhcp.c,v
-retrieving revision 1.86
-retrieving revision 1.87
-diff -u -p -r1.86 -r1.87
---- src/core/dhcp.c    4 Mar 2008 14:25:58 -0000       1.86
-+++ src/core/dhcp.c    15 Apr 2008 17:24:55 -0000      1.87
-@@ -568,6 +568,8 @@ dhcp_start(struct netif *netif)
-   LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
-   dhcp = netif->dhcp;
-   LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
-+  /* Remove the flag that says this netif is handled by DHCP,
-+     it is set when we succeeded starting. */
-   netif->flags &= ~NETIF_FLAG_DHCP;
-   /* no DHCP client attached yet? */
-@@ -609,6 +611,7 @@ dhcp_start(struct netif *netif)
-     dhcp_stop(netif);
-     return ERR_MEM;
-   }
-+  /* Set the flag that says this netif is handled by DHCP. */
-   netif->flags |= NETIF_FLAG_DHCP;
-   return result;
- }
-@@ -1063,6 +1066,8 @@ dhcp_stop(struct netif *netif)
- {
-   struct dhcp *dhcp = netif->dhcp;
-   LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;);
-+  /* Remove the flag that says this netif is handled by DHCP. */
-+  netif->flags &= ~NETIF_FLAG_DHCP;
-   LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_stop()\n"));
-   /* netif is DHCP configured? */
-Index: src/core/mem.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/mem.c,v
-retrieving revision 1.59
-retrieving revision 1.62
-diff -u -p -r1.59 -r1.62
---- src/core/mem.c     4 Mar 2008 16:31:32 -0000       1.59
-+++ src/core/mem.c     30 Jun 2008 18:16:51 -0000      1.62
-@@ -177,9 +177,36 @@ static u8_t *ram;
- static struct mem *ram_end;
- /** pointer to the lowest free block, this is used for faster search */
- static struct mem *lfree;
-+
- /** concurrent access protection */
- static sys_sem_t mem_sem;
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+
-+static volatile u8_t mem_free_count;
-+
-+/* Allow mem_free from other (e.g. interrupt) context */
-+#define LWIP_MEM_FREE_DECL_PROTECT()  SYS_ARCH_DECL_PROTECT(lev_free)
-+#define LWIP_MEM_FREE_PROTECT()       SYS_ARCH_PROTECT(lev_free)
-+#define LWIP_MEM_FREE_UNPROTECT()     SYS_ARCH_UNPROTECT(lev_free)
-+#define LWIP_MEM_ALLOC_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_alloc)
-+#define LWIP_MEM_ALLOC_PROTECT()      SYS_ARCH_PROTECT(lev_alloc)
-+#define LWIP_MEM_ALLOC_UNPROTECT()    SYS_ARCH_UNPROTECT(lev_alloc)
-+
-+#else /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+
-+/* Protect the heap only by using a semaphore */
-+#define LWIP_MEM_FREE_DECL_PROTECT()
-+#define LWIP_MEM_FREE_PROTECT()    sys_arch_sem_wait(mem_sem, 0)
-+#define LWIP_MEM_FREE_UNPROTECT()  sys_sem_signal(mem_sem)
-+/* mem_malloc is protected using semaphore AND LWIP_MEM_ALLOC_PROTECT */
-+#define LWIP_MEM_ALLOC_DECL_PROTECT()
-+#define LWIP_MEM_ALLOC_PROTECT()
-+#define LWIP_MEM_ALLOC_UNPROTECT()
-+
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+
-+
- /**
-  * "Plug holes" by combining adjacent empty struct mems.
-  * After this function is through, there should not exist
-@@ -255,9 +282,7 @@ mem_init(void)
-   /* initialize the lowest-free pointer to the start of the heap */
-   lfree = (struct mem *)ram;
--#if MEM_STATS
--  lwip_stats.mem.avail = MEM_SIZE_ALIGNED;
--#endif /* MEM_STATS */
-+  MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);
- }
- /**
-@@ -270,6 +295,7 @@ void
- mem_free(void *rmem)
- {
-   struct mem *mem;
-+  LWIP_MEM_FREE_DECL_PROTECT();
-   if (rmem == NULL) {
-     LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_TRACE | 2, ("mem_free(p == NULL) was called.\n"));
-@@ -277,20 +303,20 @@ mem_free(void *rmem)
-   }
-   LWIP_ASSERT("mem_free: sanity check alignment", (((mem_ptr_t)rmem) & (MEM_ALIGNMENT-1)) == 0);
--  /* protect the heap from concurrent access */
--  sys_arch_sem_wait(mem_sem, 0);
--
-   LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
-     (u8_t *)rmem < (u8_t *)ram_end);
-   if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
-+    SYS_ARCH_DECL_PROTECT(lev);
-     LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n"));
--#if MEM_STATS
--    ++lwip_stats.mem.err;
--#endif /* MEM_STATS */
--    sys_sem_signal(mem_sem);
-+    /* protect mem stats from concurrent access */
-+    SYS_ARCH_PROTECT(lev);
-+    MEM_STATS_INC(illegal);
-+    SYS_ARCH_UNPROTECT(lev);
-     return;
-   }
-+  /* protect the heap from concurrent access */
-+  LWIP_MEM_FREE_PROTECT();
-   /* Get the corresponding struct mem ... */
-   mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
-   /* ... which has to be in a used state ... */
-@@ -303,13 +329,14 @@ mem_free(void *rmem)
-     lfree = mem;
-   }
--#if MEM_STATS
--  lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram);
--#endif /* MEM_STATS */
-+  MEM_STATS_DEC_USED(used, mem->next - ((u8_t *)mem - ram));
-   /* finally, see if prev or next are free also */
-   plug_holes(mem);
--  sys_sem_signal(mem_sem);
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+  mem_free_count = 1;
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+  LWIP_MEM_FREE_UNPROTECT();
- }
- /**
-@@ -321,6 +348,8 @@ mem_free(void *rmem)
-  * @param newsize required size after shrinking (needs to be smaller than or
-  *                equal to the previous size)
-  * @return for compatibility reasons: is always == rmem, at the moment
-+ *         or NULL if newsize is > old size, in which case rmem is NOT touched
-+ *         or freed!
-  */
- void *
- mem_realloc(void *rmem, mem_size_t newsize)
-@@ -328,6 +357,8 @@ mem_realloc(void *rmem, mem_size_t newsi
-   mem_size_t size;
-   mem_size_t ptr, ptr2;
-   struct mem *mem, *mem2;
-+  /* use the FREE_PROTECT here: it protects with sem OR SYS_ARCH_PROTECT */
-+  LWIP_MEM_FREE_DECL_PROTECT();
-   /* Expand the size of the allocated memory region so that we can
-      adjust for alignment. */
-@@ -346,7 +377,12 @@ mem_realloc(void *rmem, mem_size_t newsi
-    (u8_t *)rmem < (u8_t *)ram_end);
-   if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
-+    SYS_ARCH_DECL_PROTECT(lev);
-     LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_realloc: illegal memory\n"));
-+    /* protect mem stats from concurrent access */
-+    SYS_ARCH_PROTECT(lev);
-+    MEM_STATS_INC(illegal);
-+    SYS_ARCH_UNPROTECT(lev);
-     return rmem;
-   }
-   /* Get the corresponding struct mem ... */
-@@ -366,11 +402,9 @@ mem_realloc(void *rmem, mem_size_t newsi
-   }
-   /* protect the heap from concurrent access */
--  sys_arch_sem_wait(mem_sem, 0);
-+  LWIP_MEM_FREE_PROTECT();
--#if MEM_STATS
--  lwip_stats.mem.used -= (size - newsize);
--#endif /* MEM_STATS */
-+  MEM_STATS_DEC_USED(used, (size - newsize));
-   mem2 = (struct mem *)&ram[mem->next];
-   if(mem2->used == 0) {
-@@ -426,7 +460,10 @@ mem_realloc(void *rmem, mem_size_t newsi
-     -> don't do anyhting. 
-     -> the remaining space stays unused since it is too small
-   } */
--  sys_sem_signal(mem_sem);
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+  mem_free_count = 1;
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+  LWIP_MEM_FREE_UNPROTECT();
-   return rmem;
- }
-@@ -444,6 +481,10 @@ mem_malloc(mem_size_t size)
- {
-   mem_size_t ptr, ptr2;
-   struct mem *mem, *mem2;
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+  u8_t local_mem_free_count = 0;
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+  LWIP_MEM_ALLOC_DECL_PROTECT();
-   if (size == 0) {
-     return NULL;
-@@ -464,88 +505,101 @@ mem_malloc(mem_size_t size)
-   /* protect the heap from concurrent access */
-   sys_arch_sem_wait(mem_sem, 0);
-+  LWIP_MEM_ALLOC_PROTECT();
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+  /* run as long as a mem_free disturbed mem_malloc */
-+  do {
-+    local_mem_free_count = 0;
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-+
-+    /* Scan through the heap searching for a free block that is big enough,
-+     * beginning with the lowest free block.
-+     */
-+    for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
-+         ptr = ((struct mem *)&ram[ptr])->next) {
-+      mem = (struct mem *)&ram[ptr];
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+      mem_free_count = 0;
-+      LWIP_MEM_ALLOC_UNPROTECT();
-+      /* allow mem_free to run */
-+      LWIP_MEM_ALLOC_PROTECT();
-+      if (mem_free_count != 0) {
-+        local_mem_free_count = mem_free_count;
-+      }
-+      mem_free_count = 0;
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
--  /* Scan through the heap searching for a free block that is big enough,
--   * beginning with the lowest free block.
--   */
--  for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
--       ptr = ((struct mem *)&ram[ptr])->next) {
--    mem = (struct mem *)&ram[ptr];
--
--    if ((!mem->used) &&
--        (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
--      /* mem is not used and at least perfect fit is possible:
--       * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
--
--      if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED)) {
--        /* (in addition to the above, we test if another struct mem (SIZEOF_STRUCT_MEM) containing
--         * at least MIN_SIZE_ALIGNED of data also fits in the 'user data space' of 'mem')
--         * -> split large block, create empty remainder,
--         * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
--         * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
--         * struct mem would fit in but no data between mem2 and mem2->next
--         * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
--         *       region that couldn't hold data, but when mem->next gets freed,
--         *       the 2 regions would be combined, resulting in more free memory
--         */
--        ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
--        /* create mem2 struct */
--        mem2 = (struct mem *)&ram[ptr2];
--        mem2->used = 0;
--        mem2->next = mem->next;
--        mem2->prev = ptr;
--        /* and insert it between mem and mem->next */
--        mem->next = ptr2;
--        mem->used = 1;
--
--        if (mem2->next != MEM_SIZE_ALIGNED) {
--          ((struct mem *)&ram[mem2->next])->prev = ptr2;
--        }
--#if MEM_STATS
--        lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
--        if (lwip_stats.mem.max < lwip_stats.mem.used) {
--          lwip_stats.mem.max = lwip_stats.mem.used;
-+      if ((!mem->used) &&
-+          (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
-+        /* mem is not used and at least perfect fit is possible:
-+         * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
-+
-+        if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED)) {
-+          /* (in addition to the above, we test if another struct mem (SIZEOF_STRUCT_MEM) containing
-+           * at least MIN_SIZE_ALIGNED of data also fits in the 'user data space' of 'mem')
-+           * -> split large block, create empty remainder,
-+           * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
-+           * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
-+           * struct mem would fit in but no data between mem2 and mem2->next
-+           * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
-+           *       region that couldn't hold data, but when mem->next gets freed,
-+           *       the 2 regions would be combined, resulting in more free memory
-+           */
-+          ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
-+          /* create mem2 struct */
-+          mem2 = (struct mem *)&ram[ptr2];
-+          mem2->used = 0;
-+          mem2->next = mem->next;
-+          mem2->prev = ptr;
-+          /* and insert it between mem and mem->next */
-+          mem->next = ptr2;
-+          mem->used = 1;
-+
-+          if (mem2->next != MEM_SIZE_ALIGNED) {
-+            ((struct mem *)&ram[mem2->next])->prev = ptr2;
-+          }
-+          MEM_STATS_INC_USED(used, (size + SIZEOF_STRUCT_MEM));
-+        } else {
-+          /* (a mem2 struct does no fit into the user data space of mem and mem->next will always
-+           * be used at this point: if not we have 2 unused structs in a row, plug_holes should have
-+           * take care of this).
-+           * -> near fit or excact fit: do not split, no mem2 creation
-+           * also can't move mem->next directly behind mem, since mem->next
-+           * will always be used at this point!
-+           */
-+          mem->used = 1;
-+          MEM_STATS_INC_USED(used, mem->next - ((u8_t *)mem - ram));
-         }
--#endif /* MEM_STATS */
--      } else {
--        /* (a mem2 struct does no fit into the user data space of mem and mem->next will always
--         * be used at this point: if not we have 2 unused structs in a row, plug_holes should have
--         * take care of this).
--         * -> near fit or excact fit: do not split, no mem2 creation
--         * also can't move mem->next directly behind mem, since mem->next
--         * will always be used at this point!
--         */
--        mem->used = 1;
--#if MEM_STATS
--        lwip_stats.mem.used += mem->next - ((u8_t *)mem - ram);
--        if (lwip_stats.mem.max < lwip_stats.mem.used) {
--          lwip_stats.mem.max = lwip_stats.mem.used;
--        }
--#endif /* MEM_STATS */
--      }
--      if (mem == lfree) {
--        /* Find next free block after mem and update lowest free pointer */
--        while (lfree->used && lfree != ram_end) {
--          lfree = (struct mem *)&ram[lfree->next];
-+        if (mem == lfree) {
-+          /* Find next free block after mem and update lowest free pointer */
-+          while (lfree->used && lfree != ram_end) {
-+            LWIP_MEM_ALLOC_UNPROTECT();
-+            /* prevent high interrupt latency... */
-+            LWIP_MEM_ALLOC_PROTECT();
-+            lfree = (struct mem *)&ram[lfree->next];
-+          }
-+          LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->used)));
-         }
--        LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->used)));
--      }
--      sys_sem_signal(mem_sem);
--      LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
--       (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
--      LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
--       (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
--      LWIP_ASSERT("mem_malloc: sanity check alignment",
--        (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
-+        LWIP_MEM_ALLOC_UNPROTECT();
-+        sys_sem_signal(mem_sem);
-+        LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
-+         (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
-+        LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
-+         (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
-+        LWIP_ASSERT("mem_malloc: sanity check alignment",
-+          (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
--      return (u8_t *)mem + SIZEOF_STRUCT_MEM;
-+        return (u8_t *)mem + SIZEOF_STRUCT_MEM;
-+      }
-     }
--  }
-+#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+    /* if we got interrupted by a mem_free, try again */
-+  } while(local_mem_free_count != 0);
-+#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
-   LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size));
--#if MEM_STATS
--  ++lwip_stats.mem.err;
--#endif /* MEM_STATS */
-+  MEM_STATS_INC(err);
-+  LWIP_MEM_ALLOC_UNPROTECT();
-   sys_sem_signal(mem_sem);
-   return NULL;
- }
-Index: src/core/memp.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/memp.c,v
-retrieving revision 1.55
-retrieving revision 1.56
-diff -u -p -r1.55 -r1.56
---- src/core/memp.c    25 Nov 2007 10:43:28 -0000      1.55
-+++ src/core/memp.c    27 Jun 2008 18:37:54 -0000      1.56
-@@ -252,13 +252,12 @@ memp_init(void)
-   struct memp *memp;
-   u16_t i, j;
--#if MEMP_STATS
-   for (i = 0; i < MEMP_MAX; ++i) {
--    lwip_stats.memp[i].used = lwip_stats.memp[i].max =
--      lwip_stats.memp[i].err = 0;
--    lwip_stats.memp[i].avail = memp_num[i];
-+    MEMP_STATS_AVAIL(used, i, 0);
-+    MEMP_STATS_AVAIL(max, i, 0);
-+    MEMP_STATS_AVAIL(err, i, 0);
-+    MEMP_STATS_AVAIL(avail, i, memp_num[i]);
-   }
--#endif /* MEMP_STATS */
-   memp = LWIP_MEM_ALIGN(memp_memory);
-   /* for every pool: */
-@@ -315,20 +314,13 @@ memp_malloc_fn(memp_t type, const char* 
-     memp->file = file;
-     memp->line = line;
- #endif /* MEMP_OVERFLOW_CHECK */
--#if MEMP_STATS
--    ++lwip_stats.memp[type].used;
--    if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
--      lwip_stats.memp[type].max = lwip_stats.memp[type].used;
--    }
--#endif /* MEMP_STATS */
-+    MEMP_STATS_INC_USED(used, type);
-     LWIP_ASSERT("memp_malloc: memp properly aligned",
-                 ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
-     memp = (struct memp*)((u8_t*)memp + MEMP_SIZE);
-   } else {
-     LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %s\n", memp_desc[type]));
--#if MEMP_STATS
--    ++lwip_stats.memp[type].err;
--#endif /* MEMP_STATS */
-+    MEMP_STATS_INC(err, type);
-   }
-   SYS_ARCH_UNPROTECT(old_level);
-@@ -365,9 +357,7 @@ memp_free(memp_t type, void *mem)
- #endif /* MEMP_OVERFLOW_CHECK >= 2 */
- #endif /* MEMP_OVERFLOW_CHECK */
--#if MEMP_STATS
--  lwip_stats.memp[type].used--; 
--#endif /* MEMP_STATS */
-+  MEMP_STATS_DEC(used, type); 
-   
-   memp->next = memp_tab[type]; 
-   memp_tab[type] = memp;
-Index: src/core/netif.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/netif.c,v
-retrieving revision 1.65
-retrieving revision 1.68
-diff -u -p -r1.65 -r1.68
---- src/core/netif.c   9 Oct 2007 20:00:55 -0000       1.65
-+++ src/core/netif.c   19 Jun 2008 16:27:18 -0000      1.68
-@@ -45,6 +45,12 @@
- #include "lwip/snmp.h"
- #include "lwip/igmp.h"
- #include "netif/etharp.h"
-+#if ENABLE_LOOPBACK
-+#include "lwip/sys.h"
-+#if LWIP_NETIF_LOOPBACK_MULTITHREADING
-+#include "lwip/tcpip.h"
-+#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
-+#endif /* ENABLE_LOOPBACK */
- #if LWIP_NETIF_STATUS_CALLBACK
- #define NETIF_STATUS_CALLBACK(n) { if (n->status_callback) (n->status_callback)(n); }
-@@ -106,6 +112,10 @@ netif_add(struct netif *netif, struct ip
- #if LWIP_IGMP
-   netif->igmp_mac_filter = NULL;
- #endif /* LWIP_IGMP */
-+#if ENABLE_LOOPBACK
-+  netif->loop_first = NULL;
-+  netif->loop_last = NULL;
-+#endif /* ENABLE_LOOPBACK */
-   /* remember netif specific state information data */
-   netif->state = state;
-@@ -114,6 +124,9 @@ netif_add(struct netif *netif, struct ip
- #if LWIP_NETIF_HWADDRHINT
-   netif->addr_hint = NULL;
- #endif /* LWIP_NETIF_HWADDRHINT*/
-+#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
-+  netif->loop_cnt_current = 0;
-+#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
-   netif_set_addr(netif, ipaddr, netmask, gw);
-@@ -493,7 +506,158 @@ u8_t netif_is_link_up(struct netif *neti
-  */
- void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif ))
- {
--    if ( netif )
--        netif->link_callback = link_callback;
-+  if (netif) {
-+    netif->link_callback = link_callback;
-+  }
- }
- #endif /* LWIP_NETIF_LINK_CALLBACK */
-+
-+#if ENABLE_LOOPBACK
-+/**
-+ * Send an IP packet to be received on the same netif (loopif-like).
-+ * The pbuf is simply copied and handed back to netif->input.
-+ * In multithreaded mode, this is done directly since netif->input must put
-+ * the packet on a queue.
-+ * In callback mode, the packet is put on an internal queue and is fed to
-+ * netif->input by netif_poll().
-+ *
-+ * @param netif the lwip network interface structure
-+ * @param p the (IP) packet to 'send'
-+ * @param ipaddr the ip address to send the packet to (not used)
-+ * @return ERR_OK if the packet has been sent
-+ *         ERR_MEM if the pbuf used to copy the packet couldn't be allocated
-+ */
-+err_t
-+netif_loop_output(struct netif *netif, struct pbuf *p,
-+       struct ip_addr *ipaddr)
-+{
-+  struct pbuf *r;
-+  err_t err;
-+  struct pbuf *last;
-+#if LWIP_LOOPBACK_MAX_PBUFS
-+  u8_t clen = 0;
-+#endif /* LWIP_LOOPBACK_MAX_PBUFS */
-+  SYS_ARCH_DECL_PROTECT(lev);
-+  LWIP_UNUSED_ARG(ipaddr);
-+
-+  /* Allocate a new pbuf */
-+  r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
-+  if (r == NULL) {
-+    return ERR_MEM;
-+  }
-+#if LWIP_LOOPBACK_MAX_PBUFS
-+  clen = pbuf_clen(r);
-+  /* check for overflow or too many pbuf on queue */
-+  if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
-+    ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
-+      pbuf_free(r);
-+      r = NULL;
-+      return ERR_MEM;
-+  }
-+  netif->loop_cnt_current += clen;
-+#endif /* LWIP_LOOPBACK_MAX_PBUFS */
-+
-+  /* Copy the whole pbuf queue p into the single pbuf r */
-+  if ((err = pbuf_copy(r, p)) != ERR_OK) {
-+    pbuf_free(r);
-+    r = NULL;
-+    return err;
-+  }
-+
-+  /* Put the packet on a linked list which gets emptied through calling
-+     netif_poll(). */
-+
-+  /* let last point to the last pbuf in chain r */
-+  for (last = r; last->next != NULL; last = last->next);
-+
-+  SYS_ARCH_PROTECT(lev);
-+  if(netif->loop_first != NULL) {
-+    LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
-+    netif->loop_last->next = r;
-+    netif->loop_last = last;
-+  } else {
-+    netif->loop_first = r;
-+    netif->loop_last = last;
-+  }
-+  SYS_ARCH_UNPROTECT(lev);
-+
-+#if LWIP_NETIF_LOOPBACK_MULTITHREADING
-+  /* For multithreading environment, schedule a call to netif_poll */
-+  tcpip_callback(netif_poll, netif);
-+#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
-+
-+  return ERR_OK;
-+}
-+
-+/**
-+ * Call netif_poll() in the main loop of your application. This is to prevent
-+ * reentering non-reentrant functions like tcp_input(). Packets passed to
-+ * netif_loop_output() are put on a list that is passed to netif->input() by
-+ * netif_poll().
-+ */
-+void
-+netif_poll(struct netif *netif)
-+{
-+  struct pbuf *in;
-+  SYS_ARCH_DECL_PROTECT(lev);
-+
-+  do {
-+    /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
-+    SYS_ARCH_PROTECT(lev);
-+    in = netif->loop_first;
-+    if(in != NULL) {
-+      struct pbuf *in_end = in;
-+#if LWIP_LOOPBACK_MAX_PBUFS
-+      u8_t clen = pbuf_clen(in);
-+      /* adjust the number of pbufs on queue */
-+      LWIP_ASSERT("netif->loop_cnt_current underflow",
-+        ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
-+      netif->loop_cnt_current -= clen;
-+#endif /* LWIP_LOOPBACK_MAX_PBUFS */
-+      while(in_end->len != in_end->tot_len) {
-+        LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
-+        in_end = in_end->next;
-+      }
-+      /* 'in_end' now points to the last pbuf from 'in' */
-+      if(in_end == netif->loop_last) {
-+        /* this was the last pbuf in the list */
-+        netif->loop_first = netif->loop_last = NULL;
-+      } else {
-+        /* pop the pbuf off the list */
-+        netif->loop_first = in_end->next;
-+        LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
-+      }
-+      /* De-queue the pbuf from its successors on the 'loop_' list. */
-+      in_end->next = NULL;
-+    }
-+    SYS_ARCH_UNPROTECT(lev);
-+
-+    if(in != NULL) {
-+      /* loopback packets are always IP packets! */
-+      if(ip_input(in, netif) != ERR_OK) {
-+        pbuf_free(in);
-+      }
-+      /* Don't reference the packet any more! */
-+      in = NULL;
-+    }
-+  /* go on while there is a packet on the list */
-+  } while(netif->loop_first != NULL);
-+}
-+
-+#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
-+/**
-+ * Calls netif_poll() for every netif on the netif_list.
-+ */
-+void
-+netif_poll_all(void)
-+{
-+  struct netif *netif = netif_list;
-+  /* loop through netifs */
-+  while (netif != NULL) {
-+    netif_poll(netif);
-+    /* proceed to next network interface */
-+    netif = netif->next;
-+  }
-+}
-+#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
-+#endif /* ENABLE_LOOPBACK */
-Index: src/core/pbuf.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/pbuf.c,v
-retrieving revision 1.127
-retrieving revision 1.128
-diff -u -p -r1.127 -r1.128
---- src/core/pbuf.c    4 Mar 2008 16:37:46 -0000       1.127
-+++ src/core/pbuf.c    1 Apr 2008 19:05:40 -0000       1.128
-@@ -667,8 +667,8 @@ pbuf_dechain(struct pbuf *p)
-  *
-  * @note Only one packet is copied, no packet queue!
-  *
-- * @param p_to pbuf source of the copy
-- * @param p_from pbuf destination of the copy
-+ * @param p_to pbuf destination of the copy
-+ * @param p_from pbuf source of the copy
-  *
-  * @return ERR_OK if pbuf was copied
-  *         ERR_ARG if one of the pbufs is NULL or p_to is not big
-Index: src/core/stats.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/stats.c,v
-retrieving revision 1.27
-retrieving revision 1.28
-diff -u -p -r1.27 -r1.28
---- src/core/stats.c   4 Mar 2008 16:31:32 -0000       1.27
-+++ src/core/stats.c   27 Jun 2008 18:37:54 -0000      1.28
-@@ -54,7 +54,6 @@ stats_display_proto(struct stats_proto *
- {
-   LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
-   LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit)); 
--  LWIP_PLATFORM_DIAG(("rexmit: %"STAT_COUNTER_F"\n\t", proto->rexmit)); 
-   LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv)); 
-   LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw)); 
-   LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop)); 
-@@ -68,6 +67,7 @@ stats_display_proto(struct stats_proto *
-   LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit)); 
- }
-+#if IGMP_STATS
- void
- stats_display_igmp(struct stats_igmp *igmp)
- {
-@@ -82,7 +82,9 @@ stats_display_igmp(struct stats_igmp *ig
-   LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", igmp->report_rxed)); 
-   LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", igmp->group_query_rxed));
- }
-+#endif /* IGMP_STATS */
-+#if MEM_STATS || MEMP_STATS
- void
- stats_display_mem(struct stats_mem *mem, char *name)
- {
-@@ -93,48 +95,53 @@ stats_display_mem(struct stats_mem *mem,
-   LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
- }
-+#if MEMP_STATS
- void
--stats_display(void)
-+stats_display_memp(struct stats_mem *mem, int index)
- {
--#if MEMP_STATS
--  s16_t i;
-   char * memp_names[] = {
- #define LWIP_MEMPOOL(name,num,size,desc) desc,
- #include "lwip/memp_std.h"
-   };
--#endif
--#if LINK_STATS
--  stats_display_proto(&lwip_stats.link, "LINK");
--#endif
--#if ETHARP_STATS
--  stats_display_proto(&lwip_stats.etharp, "ETHARP");
--#endif
--#if IPFRAG_STATS
--  stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG");
--#endif
--#if IP_STATS
--  stats_display_proto(&lwip_stats.ip, "IP");
--#endif
--#if ICMP_STATS
--  stats_display_proto(&lwip_stats.icmp, "ICMP");
--#endif
--#if IGMP_STATS
--  stats_display_igmp(&lwip_stats.igmp);
--#endif
--#if UDP_STATS
--  stats_display_proto(&lwip_stats.udp, "UDP");
--#endif
--#if TCP_STATS
--  stats_display_proto(&lwip_stats.tcp, "TCP");
--#endif
--#if MEM_STATS
--  stats_display_mem(&lwip_stats.mem, "HEAP");
--#endif
--#if MEMP_STATS
-+  if(index < MEMP_MAX) {
-+    stats_display_mem(mem, memp_names[index]);
-+  }
-+}
-+#endif /* MEMP_STATS */
-+#endif /* MEM_STATS || MEMP_STATS */
-+
-+#if SYS_STATS
-+void
-+stats_display_sys(struct stats_sys *sys)
-+{
-+  LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
-+  LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used)); 
-+  LWIP_PLATFORM_DIAG(("sem.max:  %"U32_F"\n\t", (u32_t)sys->sem.max)); 
-+  LWIP_PLATFORM_DIAG(("sem.err:  %"U32_F"\n\t", (u32_t)sys->sem.err)); 
-+  LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used)); 
-+  LWIP_PLATFORM_DIAG(("mbox.max:  %"U32_F"\n\t", (u32_t)sys->mbox.max)); 
-+  LWIP_PLATFORM_DIAG(("mbox.err:  %"U32_F"\n\t", (u32_t)sys->mbox.err)); 
-+}
-+#endif /* SYS_STATS */
-+
-+void
-+stats_display(void)
-+{
-+  s16_t i;
-+
-+  LINK_STATS_DISPLAY();
-+  ETHARP_STATS_DISPLAY();
-+  IPFRAG_STATS_DISPLAY();
-+  IP_STATS_DISPLAY();
-+  IGMP_STATS_DISPLAY();
-+  ICMP_STATS_DISPLAY();
-+  UDP_STATS_DISPLAY();
-+  TCP_STATS_DISPLAY();
-+  MEM_STATS_DISPLAY();
-   for (i = 0; i < MEMP_MAX; i++) {
--    stats_display_mem(&lwip_stats.memp[i], memp_names[i]);
-+    MEMP_STATS_DISPLAY(i);
-   }
--#endif
-+  SYS_STATS_DISPLAY();
- }
- #endif /* LWIP_STATS_DISPLAY */
-Index: src/core/sys.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/sys.c,v
-retrieving revision 1.32
-retrieving revision 1.33
-diff -u -p -r1.32 -r1.33
---- src/core/sys.c     25 Nov 2007 13:57:05 -0000      1.32
-+++ src/core/sys.c     16 Jul 2008 20:36:12 -0000      1.33
-@@ -65,7 +65,7 @@ struct sswt_cb
- void
- sys_mbox_fetch(sys_mbox_t mbox, void **msg)
- {
--  u32_t time;
-+  u32_t time_needed;
-   struct sys_timeouts *timeouts;
-   struct sys_timeo *tmptimeout;
-   sys_timeout_handler h;
-@@ -76,18 +76,18 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
-   if (!timeouts || !timeouts->next) {
-     UNLOCK_TCPIP_CORE();
--    time = sys_arch_mbox_fetch(mbox, msg, 0);
-+    time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
-     LOCK_TCPIP_CORE();
-   } else {
-     if (timeouts->next->time > 0) {
-       UNLOCK_TCPIP_CORE();
--      time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
-+      time_needed = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
-       LOCK_TCPIP_CORE();
-     } else {
--      time = SYS_ARCH_TIMEOUT;
-+      time_needed = SYS_ARCH_TIMEOUT;
-     }
--    if (time == SYS_ARCH_TIMEOUT) {
-+    if (time_needed == SYS_ARCH_TIMEOUT) {
-       /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
-          could be fetched. We should now call the timeout handler and
-          deallocate the memory allocated for the timeout. */
-@@ -107,8 +107,8 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
-       /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
-          occured. The time variable is set to the number of
-          milliseconds we waited for the message. */
--      if (time < timeouts->next->time) {
--        timeouts->next->time -= time;
-+      if (time_needed < timeouts->next->time) {
-+        timeouts->next->time -= time_needed;
-       } else {
-         timeouts->next->time = 0;
-       }
-@@ -125,7 +125,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
- void
- sys_sem_wait(sys_sem_t sem)
- {
--  u32_t time;
-+  u32_t time_needed;
-   struct sys_timeouts *timeouts;
-   struct sys_timeo *tmptimeout;
-   sys_timeout_handler h;
-@@ -139,12 +139,12 @@ sys_sem_wait(sys_sem_t sem)
-     sys_arch_sem_wait(sem, 0);
-   } else {
-     if (timeouts->next->time > 0) {
--      time = sys_arch_sem_wait(sem, timeouts->next->time);
-+      time_needed = sys_arch_sem_wait(sem, timeouts->next->time);
-     } else {
--      time = SYS_ARCH_TIMEOUT;
-+      time_needed = SYS_ARCH_TIMEOUT;
-     }
--    if (time == SYS_ARCH_TIMEOUT) {
-+    if (time_needed == SYS_ARCH_TIMEOUT) {
-       /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
-         could be fetched. We should now call the timeout handler and
-         deallocate the memory allocated for the timeout. */
-@@ -164,8 +164,8 @@ sys_sem_wait(sys_sem_t sem)
-       /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
-          occured. The time variable is set to the number of
-          milliseconds we waited for the message. */
--      if (time < timeouts->next->time) {
--        timeouts->next->time -= time;
-+      if (time_needed < timeouts->next->time) {
-+        timeouts->next->time -= time_needed;
-       } else {
-         timeouts->next->time = 0;
-       }
-Index: src/core/tcp.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/tcp.c,v
-retrieving revision 1.85
-retrieving revision 1.86
-diff -u -p -r1.85 -r1.86
---- src/core/tcp.c     22 Jan 2008 21:15:15 -0000      1.85
-+++ src/core/tcp.c     26 Mar 2008 11:57:13 -0000      1.86
-@@ -509,7 +509,8 @@ tcp_connect(struct tcp_pcb *pcb, struct 
-   pcb->rcv_wnd = TCP_WND;
-   pcb->rcv_ann_wnd = TCP_WND;
-   pcb->snd_wnd = TCP_WND;
--  /* The send MSS is updated when an MSS option is received. */
-+  /* As initial send MSS, we use TCP_MSS but limit it to 536.
-+     The send MSS is updated when an MSS option is received. */
-   pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
- #if TCP_CALCULATE_EFF_SEND_MSS
-   pcb->mss = tcp_eff_send_mss(pcb->mss, ipaddr);
-@@ -991,7 +992,8 @@ tcp_alloc(u8_t prio)
-     pcb->rcv_ann_wnd = TCP_WND;
-     pcb->tos = 0;
-     pcb->ttl = TCP_TTL;
--    /* The send MSS is updated when an MSS option is received. */
-+    /* As initial send MSS, we use TCP_MSS but limit it to 536.
-+       The send MSS is updated when an MSS option is received. */
-     pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
-     pcb->rto = 3000 / TCP_SLOW_INTERVAL;
-     pcb->sa = 0;
-Index: src/core/tcp_in.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/tcp_in.c,v
-retrieving revision 1.97
-retrieving revision 1.100
-diff -u -p -r1.97 -r1.100
---- src/core/tcp_in.c  22 Jan 2008 21:15:15 -0000      1.97
-+++ src/core/tcp_in.c  24 Jun 2008 15:46:39 -0000      1.100
-@@ -511,7 +511,7 @@ tcp_process(struct tcp_pcb *pcb)
-       }
-     } else {
-       if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
--                          pcb->rcv_nxt+pcb->rcv_ann_wnd)) {
-+                          pcb->rcv_nxt+pcb->rcv_wnd)) {
-         acceptable = 1;
-       }
-     }
-@@ -1038,7 +1038,7 @@ tcp_receive(struct tcp_pcb *pcb)
-        and below rcv_nxt + rcv_wnd) in order to be further
-        processed. */
-     if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
--                        pcb->rcv_nxt + pcb->rcv_ann_wnd - 1)){
-+                        pcb->rcv_nxt + pcb->rcv_wnd - 1)){
-       if (pcb->rcv_nxt == seqno) {
-         accepted_inseq = 1; 
-         /* The incoming segment is the next in sequence. We check if
-@@ -1195,14 +1195,14 @@ tcp_receive(struct tcp_pcb *pcb)
-                   } else {
-                     pcb->ooseq = cseg;
-                   }
--                }
--                tcp_seg_free(next);
--                if (cseg->next != NULL) {
--                  next = cseg->next;
--                  if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
--                    /* We need to trim the incoming segment. */
--                    cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
--                    pbuf_realloc(cseg->p, cseg->len);
-+                  tcp_seg_free(next);
-+                  if (cseg->next != NULL) {
-+                    next = cseg->next;
-+                    if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
-+                      /* We need to trim the incoming segment. */
-+                      cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
-+                      pbuf_realloc(cseg->p, cseg->len);
-+                    }
-                   }
-                 }
-                 break;
-@@ -1282,10 +1282,7 @@ tcp_receive(struct tcp_pcb *pcb)
-       }
-     } else {
--      if(!TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, 
--                          pcb->rcv_nxt + pcb->rcv_ann_wnd-1)){
--        tcp_ack_now(pcb);
--      }
-+      tcp_ack_now(pcb);
-     }
-   } else {
-     /* Segments with length 0 is taken care of here. Segments that
-@@ -1331,7 +1328,8 @@ tcp_parseopt(struct tcp_pcb *pcb)
-         opts[c + 1] == 0x04) {
-         /* An MSS option with the right option length. */
-         mss = (opts[c + 2] << 8) | opts[c + 3];
--        pcb->mss = mss > TCP_MSS? TCP_MSS: mss;
-+        /* Limit the mss to the configured TCP_MSS and prevent division by zero */
-+        pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss;
-         /* And we are done processing options. */
-         break;
-Index: src/core/ipv4/autoip.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/ipv4/autoip.c,v
-retrieving revision 1.16
-retrieving revision 1.17
-diff -u -p -r1.16 -r1.17
---- src/core/ipv4/autoip.c     26 Jan 2008 16:11:40 -0000      1.16
-+++ src/core/ipv4/autoip.c     17 Jun 2008 20:16:23 -0000      1.17
-@@ -395,8 +395,8 @@ autoip_arp_reply(struct netif *netif, st
-     /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
-      * structure packing (not using structure copy which breaks strict-aliasing rules).
-      */
--    MEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
--    MEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
-+    SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
-+    SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
-       
-     if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
-         ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
-Index: src/core/ipv4/inet_chksum.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/ipv4/inet_chksum.c,v
-retrieving revision 1.4
-retrieving revision 1.5
-diff -u -p -r1.4 -r1.5
---- src/core/ipv4/inet_chksum.c        10 Mar 2008 16:12:31 -0000      1.4
-+++ src/core/ipv4/inet_chksum.c        17 Jun 2008 20:06:25 -0000      1.5
-@@ -41,8 +41,6 @@
- #include "lwip/inet_chksum.h"
- #include "lwip/inet.h"
--#include <string.h>
--
- /* These are some reference implementations of the checksum algorithm, with the
-  * aim of being simple, correct and fully portable. Checksumming is the
-  * first thing you would want to optimize for your platform. If you create
-@@ -65,6 +63,11 @@
- # define LWIP_CHKSUM_ALGORITHM 0
- #endif
-+/** Like the name says... */
-+#define SWAP_BYTES_IN_WORD(w) ((w & 0xff) << 8) | ((w & 0xff00) >> 8)
-+/** Split an u32_t in two u16_ts and add them up */
-+#define FOLD_U32T(u)          ((u >> 16) + (u & 0x0000ffffUL))
-+
- #if (LWIP_CHKSUM_ALGORITHM == 1) /* Version #1 */
- /**
-  * lwip checksum
-@@ -86,8 +89,7 @@ lwip_standard_chksum(void *dataptr, u16_
-   acc = 0;
-   /* dataptr may be at odd or even addresses */
-   octetptr = (u8_t*)dataptr;
--  while (len > 1)
--  {
-+  while (len > 1) {
-     /* declare first octet as most significant
-        thus assume network order, ignoring host order */
-     src = (*octetptr) << 8;
-@@ -98,8 +100,7 @@ lwip_standard_chksum(void *dataptr, u16_
-     acc += src;
-     len -= 2;
-   }
--  if (len > 0)
--  {
-+  if (len > 0) {
-     /* accumulate remaining octet */
-     src = (*octetptr) << 8;
-     acc += src;
-@@ -154,19 +155,22 @@ lwip_standard_chksum(void *dataptr, int 
-   }
-   /* Consume left-over byte, if any */
--  if (len > 0)
-+  if (len > 0) {
-     ((u8_t *)&t)[0] = *(u8_t *)ps;;
-+  }
-   /* Add end bytes */
-   sum += t;
--  /*  Fold 32-bit sum to 16 bits */
--  while ((sum >> 16) != 0)
--    sum = (sum & 0xffff) + (sum >> 16);
-+  /* Fold 32-bit sum to 16 bits
-+     calling this twice is propably faster than if statements... */
-+  sum = FOLD_U32T(sum);
-+  sum = FOLD_U32T(sum);
-   /* Swap if alignment was odd */
--  if (odd)
--    sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
-+  if (odd) {
-+    sum = SWAP_BYTES_IN_WORD(sum);
-+  }
-   return sum;
- }
-@@ -211,18 +215,20 @@ lwip_standard_chksum(void *dataptr, int 
-   while (len > 7)  {
-     tmp = sum + *pl++;          /* ping */
--    if (tmp < sum)
-+    if (tmp < sum) {
-       tmp++;                    /* add back carry */
-+    }
-     sum = tmp + *pl++;          /* pong */
--    if (sum < tmp)
-+    if (sum < tmp) {
-       sum++;                    /* add back carry */
-+    }
-     len -= 8;
-   }
-   /* make room in upper bits */
--  sum = (sum >> 16) + (sum & 0xffff);
-+  sum = FOLD_U32T(sum);
-   ps = (u16_t *)pl;
-@@ -233,16 +239,20 @@ lwip_standard_chksum(void *dataptr, int 
-   }
-   /* dangling tail byte remaining? */
--  if (len > 0)                  /* include odd byte */
-+  if (len > 0) {                /* include odd byte */
-     ((u8_t *)&t)[0] = *(u8_t *)ps;
-+  }
-   sum += t;                     /* add end bytes */
--  while ((sum >> 16) != 0)      /* combine halves */
--    sum = (sum >> 16) + (sum & 0xffff);
-+  /* Fold 32-bit sum to 16 bits
-+     calling this twice is propably faster than if statements... */
-+  sum = FOLD_U32T(sum);
-+  sum = FOLD_U32T(sum);
--  if (odd)
--    sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
-+  if (odd) {
-+    sum = SWAP_BYTES_IN_WORD(sum);
-+  }
-   return sum;
- }
-@@ -277,18 +287,18 @@ inet_chksum_pseudo(struct pbuf *p,
-       (void *)q, (void *)q->next));
-     acc += LWIP_CHKSUM(q->payload, q->len);
-     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
--    while ((acc >> 16) != 0) {
--      acc = (acc & 0xffffUL) + (acc >> 16);
--    }
-+    /* just executing this next line is probably faster that the if statement needed
-+       to check whether we really need to execute it, and does no harm */
-+    acc = FOLD_U32T(acc);
-     if (q->len % 2 != 0) {
-       swapped = 1 - swapped;
--      acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
-+      acc = SWAP_BYTES_IN_WORD(acc);
-     }
-     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
-   }
-   if (swapped) {
--    acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
-+    acc = SWAP_BYTES_IN_WORD(acc);
-   }
-   acc += (src->addr & 0xffffUL);
-   acc += ((src->addr >> 16) & 0xffffUL);
-@@ -297,9 +307,10 @@ inet_chksum_pseudo(struct pbuf *p,
-   acc += (u32_t)htons((u16_t)proto);
-   acc += (u32_t)htons(proto_len);
--  while ((acc >> 16) != 0) {
--    acc = (acc & 0xffffUL) + (acc >> 16);
--  }
-+  /* Fold 32-bit sum to 16 bits
-+     calling this twice is propably faster than if statements... */
-+  acc = FOLD_U32T(acc);
-+  acc = FOLD_U32T(acc);
-   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
-   return (u16_t)~(acc & 0xffffUL);
- }
-@@ -340,18 +351,17 @@ inet_chksum_pseudo_partial(struct pbuf *
-     chksum_len -= chklen;
-     LWIP_ASSERT("delete me", chksum_len < 0x7fff);
-     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
--    while ((acc >> 16) != 0) {
--      acc = (acc & 0xffffUL) + (acc >> 16);
--    }
-+    /* fold the upper bit down */
-+    acc = FOLD_U32T(acc);
-     if (q->len % 2 != 0) {
-       swapped = 1 - swapped;
--      acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
-+      acc = SWAP_BYTES_IN_WORD(acc);
-     }
-     /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
-   }
-   if (swapped) {
--    acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
-+    acc = SWAP_BYTES_IN_WORD(acc);
-   }
-   acc += (src->addr & 0xffffUL);
-   acc += ((src->addr >> 16) & 0xffffUL);
-@@ -360,9 +370,10 @@ inet_chksum_pseudo_partial(struct pbuf *
-   acc += (u32_t)htons((u16_t)proto);
-   acc += (u32_t)htons(proto_len);
--  while ((acc >> 16) != 0) {
--    acc = (acc & 0xffffUL) + (acc >> 16);
--  }
-+  /* Fold 32-bit sum to 16 bits
-+     calling this twice is propably faster than if statements... */
-+  acc = FOLD_U32T(acc);
-+  acc = FOLD_U32T(acc);
-   LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
-   return (u16_t)~(acc & 0xffffUL);
- }
-@@ -380,13 +391,7 @@ inet_chksum_pseudo_partial(struct pbuf *
- u16_t
- inet_chksum(void *dataptr, u16_t len)
- {
--  u32_t acc;
--
--  acc = LWIP_CHKSUM(dataptr, len);
--  while ((acc >> 16) != 0) {
--    acc = (acc & 0xffff) + (acc >> 16);
--  }
--  return (u16_t)~(acc & 0xffff);
-+  return ~LWIP_CHKSUM(dataptr, len);
- }
- /**
-@@ -407,17 +412,15 @@ inet_chksum_pbuf(struct pbuf *p)
-   swapped = 0;
-   for(q = p; q != NULL; q = q->next) {
-     acc += LWIP_CHKSUM(q->payload, q->len);
--    while ((acc >> 16) != 0) {
--      acc = (acc & 0xffffUL) + (acc >> 16);
--    }
-+    acc = FOLD_U32T(acc);
-     if (q->len % 2 != 0) {
-       swapped = 1 - swapped;
--      acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
-+      acc = SWAP_BYTES_IN_WORD(acc);
-     }
-   }
-   if (swapped) {
--    acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
-+    acc = SWAP_BYTES_IN_WORD(acc);
-   }
-   return (u16_t)~(acc & 0xffffUL);
- }
-Index: src/core/ipv4/ip.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/core/ipv4/ip.c,v
-retrieving revision 1.66
-retrieving revision 1.68
-diff -u -p -r1.66 -r1.68
---- src/core/ipv4/ip.c 14 Jan 2008 20:53:23 -0000      1.66
-+++ src/core/ipv4/ip.c 17 Jun 2008 19:39:22 -0000      1.68
-@@ -531,9 +531,19 @@ ip_output_if(struct pbuf *p, struct ip_a
-   LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
-   ip_debug_print(p);
--  LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
-+#if (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
-+  if (ip_addr_cmp(dest, &netif->ip_addr)) {
-+    /* Packet to self, enqueue it for loopback */
-+    LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()"));
-+
-+    return netif_loop_output(netif, p, dest);
-+  } else
-+#endif /* (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) */
-+  {
-+    LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
--  return netif->output(netif, p, dest);
-+    return netif->output(netif, p, dest);
-+  }
- }
- /**
-Index: src/include/lwip/debug.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/debug.h,v
-retrieving revision 1.37
-retrieving revision 1.39
-diff -u -p -r1.37 -r1.39
---- src/include/lwip/debug.h   22 Sep 2007 11:16:07 -0000      1.37
-+++ src/include/lwip/debug.h   16 Jul 2008 20:36:22 -0000      1.39
-@@ -61,26 +61,28 @@
- #define LWIP_DBG_HALT          0x08U
- #ifndef LWIP_NOASSERT
--#define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0)
-+#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \
-+  LWIP_PLATFORM_ASSERT(message); } while(0)
- #else  /* LWIP_NOASSERT */
--#define LWIP_ASSERT(x,y) 
-+#define LWIP_ASSERT(message, assertion) 
- #endif /* LWIP_NOASSERT */
--/** print "m" message only if "e" is true, and execute "h" expression */
-+/** if "expression" isn't true, then print "message" and execute "handler" expression */
- #ifndef LWIP_ERROR
--#define LWIP_ERROR(m,e,h) do { if (!(e)) { LWIP_PLATFORM_ASSERT(m); h;}} while(0)
-+#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
-+  LWIP_PLATFORM_ASSERT(message); handler;}} while(0)
- #endif /* LWIP_ERROR */
- #ifdef LWIP_DEBUG
- /** print debug message only if debug message type is enabled...
-  *  AND is of correct type AND is at least LWIP_DBG_LEVEL
-  */
--#define LWIP_DEBUGF(debug,x) do { \
-+#define LWIP_DEBUGF(debug, message) do { \
-                                if ( \
-                                    ((debug) & LWIP_DBG_ON) && \
-                                    ((debug) & LWIP_DBG_TYPES_ON) && \
-                                    ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
--                                 LWIP_PLATFORM_DIAG(x); \
-+                                 LWIP_PLATFORM_DIAG(message); \
-                                  if ((debug) & LWIP_DBG_HALT) { \
-                                    while(1); \
-                                  } \
-@@ -88,7 +90,7 @@
-                              } while(0)
- #else  /* LWIP_DEBUG */
--#define LWIP_DEBUGF(debug,x) 
-+#define LWIP_DEBUGF(debug, message) 
- #endif /* LWIP_DEBUG */
- #endif /* __LWIP_DEBUG_H__ */
-Index: src/include/lwip/err.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/err.h,v
-retrieving revision 1.13
-retrieving revision 1.15
-diff -u -p -r1.13 -r1.15
---- src/include/lwip/err.h     13 Dec 2007 23:06:50 -0000      1.13
-+++ src/include/lwip/err.h     17 Jun 2008 20:27:32 -0000      1.15
-@@ -33,37 +33,43 @@
- #define __LWIP_ERR_H__
- #include "lwip/opt.h"
-+#include "lwip/arch.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
--typedef s8_t err_t;
-+/** Define LWIP_ERR_T in cc.h if you want to use
-+ *  a different type for your platform (must be signed). */
-+#ifdef LWIP_ERR_T
-+typedef LWIP_ERR_T err_t;
-+#else /* LWIP_ERR_T */
-+ typedef s8_t err_t;
-+#endif /* LWIP_ERR_T*/
- /* Definitions for error constants. */
- #define ERR_OK          0    /* No error, everything OK. */
- #define ERR_MEM        -1    /* Out of memory error.     */
- #define ERR_BUF        -2    /* Buffer error.            */
--#define ERR_RTE        -3    /* Routing problem.         */
-+#define ERR_TIMEOUT    -3    /* Timeout.                 */
-+#define ERR_RTE        -4    /* Routing problem.         */
- #define ERR_IS_FATAL(e) ((e) < ERR_RTE)
--#define ERR_ABRT       -4    /* Connection aborted.      */
--#define ERR_RST        -5    /* Connection reset.        */
--#define ERR_CLSD       -6    /* Connection closed.       */
--#define ERR_CONN       -7    /* Not connected.           */
-+#define ERR_ABRT       -5    /* Connection aborted.      */
-+#define ERR_RST        -6    /* Connection reset.        */
-+#define ERR_CLSD       -7    /* Connection closed.       */
-+#define ERR_CONN       -8    /* Not connected.           */
--#define ERR_VAL        -8    /* Illegal value.           */
-+#define ERR_VAL        -9    /* Illegal value.           */
--#define ERR_ARG        -9    /* Illegal argument.        */
-+#define ERR_ARG        -10   /* Illegal argument.        */
--#define ERR_USE        -10   /* Address in use.          */
-+#define ERR_USE        -11   /* Address in use.          */
--#define ERR_IF         -11   /* Low-level netif error    */
--#define ERR_ISCONN     -12   /* Already connected.       */
--
--#define ERR_TIMEOUT    -13   /* Timeout.                 */
-+#define ERR_IF         -12   /* Low-level netif error    */
-+#define ERR_ISCONN     -13   /* Already connected.       */
- #define ERR_INPROGRESS -14   /* Operation in progress    */
-Index: src/include/lwip/mem.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/mem.h,v
-retrieving revision 1.21
-retrieving revision 1.22
-diff -u -p -r1.21 -r1.22
---- src/include/lwip/mem.h     4 Mar 2008 16:31:32 -0000       1.21
-+++ src/include/lwip/mem.h     30 May 2008 11:37:15 -0000      1.22
-@@ -50,16 +50,16 @@ typedef size_t mem_size_t;
-  * allow these defines to be overridden.
-  */
- #ifndef mem_free
--#define mem_free(x) free(x)
-+#define mem_free free
- #endif
- #ifndef mem_malloc
--#define mem_malloc(x) malloc(x)
-+#define mem_malloc malloc
- #endif
- #ifndef mem_calloc
--#define mem_calloc(x, y) calloc(x, y)
-+#define mem_calloc calloc
- #endif
- #ifndef mem_realloc
--#define mem_realloc(x, size) (x)
-+#define mem_realloc realloc
- #endif
- #else /* MEM_LIBC_MALLOC */
-Index: src/include/lwip/netif.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/netif.h,v
-retrieving revision 1.43
-retrieving revision 1.46
-diff -u -p -r1.43 -r1.46
---- src/include/lwip/netif.h   9 Oct 2007 19:59:59 -0000       1.43
-+++ src/include/lwip/netif.h   19 Jun 2008 16:27:23 -0000      1.46
-@@ -34,6 +34,8 @@
- #include "lwip/opt.h"
-+#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
-+
- #include "lwip/err.h"
- #include "lwip/ip_addr.h"
-@@ -165,6 +167,14 @@ struct netif {
- #if LWIP_NETIF_HWADDRHINT
-   u8_t *addr_hint;
- #endif /* LWIP_NETIF_HWADDRHINT */
-+#if ENABLE_LOOPBACK
-+  /* List of packets to be queued for ourselves. */
-+  struct pbuf *loop_first;
-+  struct pbuf *loop_last;
-+#if LWIP_LOOPBACK_MAX_PBUFS
-+  u16_t loop_cnt_current;
-+#endif /* LWIP_LOOPBACK_MAX_PBUFS */
-+#endif /* ENABLE_LOOPBACK */
- };
- #if LWIP_SNMP
-@@ -242,4 +252,12 @@ void netif_set_link_callback(struct neti
- }
- #endif
-+#if ENABLE_LOOPBACK
-+err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
-+void netif_poll(struct netif *netif);
-+#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
-+void netif_poll_all(void);
-+#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
-+#endif /* ENABLE_LOOPBACK */
-+
- #endif /* __LWIP_NETIF_H__ */
-Index: src/include/lwip/opt.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/opt.h,v
-retrieving revision 1.116
-retrieving revision 1.122
-diff -u -p -r1.116 -r1.122
---- src/include/lwip/opt.h     31 Jan 2008 18:19:29 -0000      1.116
-+++ src/include/lwip/opt.h     30 Jun 2008 18:16:52 -0000      1.122
-@@ -155,6 +155,27 @@
- #define MEMP_USE_CUSTOM_POOLS           0
- #endif
-+/**
-+ * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from
-+ * interrupt context (or another context that doesn't allow waiting for a
-+ * semaphore).
-+ * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT,
-+ * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs
-+ * with each loop so that mem_free can run.
-+ *
-+ * ATTENTION: As you can see from the above description, this leads to dis-/
-+ * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc
-+ * can need longer.
-+ *
-+ * If you don't want that, at least for NO_SYS=0, you can still use the following
-+ * functions to enqueue a deallocation call which then runs in the tcpip_thread
-+ * context:
-+ * - pbuf_free_callback(p);
-+ * - mem_free_callback(m);
-+ */
-+#ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
-+#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0
-+#endif
- /*
-    ------------------------------------------------
-@@ -815,6 +836,39 @@
- #define LWIP_NETIF_HWADDRHINT           0
- #endif
-+/**
-+ * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP
-+ * address equal to the netif IP address, looping them back up the stack.
-+ */
-+#ifndef LWIP_NETIF_LOOPBACK
-+#define LWIP_NETIF_LOOPBACK             0
-+#endif
-+
-+/**
-+ * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback
-+ * sending for each netif (0 = disabled)
-+ */
-+#ifndef LWIP_LOOPBACK_MAX_PBUFS
-+#define LWIP_LOOPBACK_MAX_PBUFS         0
-+#endif
-+
-+/**
-+ * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in
-+ * the system, as netifs must change how they behave depending on this setting
-+ * for the LWIP_NETIF_LOOPBACK option to work.
-+ * Setting this is needed to avoid reentering non-reentrant functions like
-+ * tcp_input().
-+ *    LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a
-+ *       multithreaded environment like tcpip.c. In this case, netif->input()
-+ *       is called directly.
-+ *    LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
-+ *       The packets are put on a list and netif_poll() must be called in
-+ *       the main application loop.
-+ */
-+#ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING
-+#define LWIP_NETIF_LOOPBACK_MULTITHREADING    (!NO_SYS)
-+#endif
-+
- /*
-    ------------------------------------
-    ---------- LOOPIF options ----------
-@@ -827,20 +881,16 @@
- #define LWIP_HAVE_LOOPIF                0
- #endif
-+/*
-+   ------------------------------------
-+   ---------- SLIPIF options ----------
-+   ------------------------------------
-+*/
- /**
-- * LWIP_LOOPIF_MULTITHREADING: Indicates whether threading is enabled in
-- * the system, as LOOPIF must change how it behaves depending on this setting.
-- * Setting this is needed to avoid reentering non-reentrant functions like
-- * tcp_input().
-- *    LWIP_LOOPIF_MULTITHREADING==1: Indicates that the user is using a
-- *       multithreaded environment like tcpip.c. In this case, netif->input()
-- *       is called directly.
-- *    LWIP_LOOPIF_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
-- *       The packets are put on a list and loopif_poll() must be called in
-- *       the main application loop.
-+ * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c
-  */
--#ifndef LWIP_LOOPIF_MULTITHREADING
--#define LWIP_LOOPIF_MULTITHREADING      1
-+#ifndef LWIP_HAVE_SLIPIF
-+#define LWIP_HAVE_SLIPIF                0
- #endif
- /*
-Index: src/include/lwip/sio.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/sio.h,v
-retrieving revision 1.7
-retrieving revision 1.8
-diff -u -p -r1.7 -r1.8
---- src/include/lwip/sio.h     6 Sep 2007 16:43:44 -0000       1.7
-+++ src/include/lwip/sio.h     27 Mar 2008 18:06:02 -0000      1.8
-@@ -32,16 +32,24 @@
-  * It needs to be implemented by those platforms which need SLIP or PPP
-  */
-+#ifndef __SIO_H__
-+#define __SIO_H__
-+
- #include "lwip/arch.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
-+/* If you want to define sio_fd_t elsewhere or differently,
-+   define this in your cc.h file. */
- #ifndef __sio_fd_t_defined
- typedef void * sio_fd_t;
- #endif
-+/* The following functions can be defined to something else in your cc.h file
-+   or be implemented in your custom sio.c file. */
-+
- #ifndef sio_open
- sio_fd_t sio_open(u8_t);
- #endif
-@@ -69,3 +77,5 @@ void sio_read_abort(sio_fd_t);
- #ifdef __cplusplus
- }
- #endif
-+
-+#endif /* __SIO_H__ */
-Index: src/include/lwip/sockets.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/sockets.h,v
-retrieving revision 1.38
-retrieving revision 1.39
-diff -u -p -r1.38 -r1.39
---- src/include/lwip/sockets.h 2 Dec 2007 15:24:02 -0000       1.38
-+++ src/include/lwip/sockets.h 26 Apr 2008 10:46:23 -0000      1.39
-@@ -177,7 +177,22 @@ typedef struct ip_mreq {
- } ip_mreq;
- #endif /* LWIP_IGMP */
--/* Unimplemented for now... */
-+/*
-+ * The Type of Service provides an indication of the abstract
-+ * parameters of the quality of service desired.  These parameters are
-+ * to be used to guide the selection of the actual service parameters
-+ * when transmitting a datagram through a particular network.  Several
-+ * networks offer service precedence, which somehow treats high
-+ * precedence traffic as more important than other traffic (generally
-+ * by accepting only traffic above a certain precedence at time of high
-+ * load).  The major choice is a three way tradeoff between low-delay,
-+ * high-reliability, and high-throughput.
-+ * The use of the Delay, Throughput, and Reliability indications may
-+ * increase the cost (in some sense) of the service.  In many networks
-+ * better performance for one of these parameters is coupled with worse
-+ * performance on another.  Except for very unusual cases at most two
-+ * of these three indications should be set.
-+ */
- #define IPTOS_TOS_MASK          0x1E
- #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
- #define IPTOS_LOWDELAY          0x10
-@@ -187,7 +202,13 @@ typedef struct ip_mreq {
- #define IPTOS_MINCOST           IPTOS_LOWCOST
- /*
-- * Definitions for IP precedence (also in ip_tos) (Unimplemented)
-+ * The Network Control precedence designation is intended to be used
-+ * within a network only.  The actual use and control of that
-+ * designation is up to each network. The Internetwork Control
-+ * designation is intended for use by gateway control originators only.
-+ * If the actual use of these precedence designations is of concern to
-+ * a particular network, it is the responsibility of that network to
-+ * control the access to, and use of, those precedence designations.
-  */
- #define IPTOS_PREC_MASK                 0xe0
- #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
-Index: src/include/lwip/stats.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/stats.h,v
-retrieving revision 1.19
-retrieving revision 1.23
-diff -u -p -r1.19 -r1.23
---- src/include/lwip/stats.h   28 Nov 2007 21:25:07 -0000      1.19
-+++ src/include/lwip/stats.h   8 Jul 2008 09:15:57 -0000       1.23
-@@ -57,7 +57,6 @@ extern "C" {
- struct stats_proto {
-   STAT_COUNTER xmit;             /* Transmitted packets. */
--  STAT_COUNTER rexmit;           /* Retransmitted packets. */
-   STAT_COUNTER recv;             /* Received packets. */
-   STAT_COUNTER fw;               /* Forwarded packets. */
-   STAT_COUNTER drop;             /* Dropped packets. */
-@@ -87,7 +86,8 @@ struct stats_mem {
-   mem_size_t avail;
-   mem_size_t used;
-   mem_size_t max;
--  mem_size_t err;
-+  STAT_COUNTER err;
-+  STAT_COUNTER illegal;
- };
- struct stats_syselem {
-@@ -142,64 +142,138 @@ extern struct stats_ lwip_stats;
- #define stats_init() /* Compatibility define, not init needed. */
- #define STATS_INC(x) ++lwip_stats.x
-+#define STATS_DEC(x) --lwip_stats.x
- #else
- #define stats_init()
- #define STATS_INC(x)
-+#define STATS_DEC(x)
- #endif /* LWIP_STATS */
- #if TCP_STATS
- #define TCP_STATS_INC(x) STATS_INC(x)
-+#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
- #else
- #define TCP_STATS_INC(x)
-+#define TCP_STATS_DISPLAY()
- #endif
- #if UDP_STATS
- #define UDP_STATS_INC(x) STATS_INC(x)
-+#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
- #else
- #define UDP_STATS_INC(x)
-+#define UDP_STATS_DISPLAY()
- #endif
- #if ICMP_STATS
- #define ICMP_STATS_INC(x) STATS_INC(x)
-+#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
- #else
- #define ICMP_STATS_INC(x)
-+#define ICMP_STATS_DISPLAY()
- #endif
- #if IGMP_STATS
- #define IGMP_STATS_INC(x) STATS_INC(x)
-+#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
- #else
- #define IGMP_STATS_INC(x)
-+#define IGMP_STATS_DISPLAY()
- #endif
- #if IP_STATS
- #define IP_STATS_INC(x) STATS_INC(x)
-+#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
- #else
- #define IP_STATS_INC(x)
-+#define IP_STATS_DISPLAY()
- #endif
- #if IPFRAG_STATS
- #define IPFRAG_STATS_INC(x) STATS_INC(x)
-+#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
- #else
- #define IPFRAG_STATS_INC(x)
-+#define IPFRAG_STATS_DISPLAY()
- #endif
- #if ETHARP_STATS
- #define ETHARP_STATS_INC(x) STATS_INC(x)
-+#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
- #else
- #define ETHARP_STATS_INC(x)
-+#define ETHARP_STATS_DISPLAY()
- #endif
- #if LINK_STATS
- #define LINK_STATS_INC(x) STATS_INC(x)
-+#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
- #else
- #define LINK_STATS_INC(x)
-+#define LINK_STATS_DISPLAY()
-+#endif
-+
-+#if MEM_STATS
-+#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
-+#define MEM_STATS_INC(x) STATS_INC(mem.x)
-+#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
-+                                    if (lwip_stats.mem.max < lwip_stats.mem.used) { \
-+                                        lwip_stats.mem.max = lwip_stats.mem.used; \
-+                                    } \
-+                                 } while(0)
-+#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
-+#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
-+#else
-+#define MEM_STATS_AVAIL(x, y)
-+#define MEM_STATS_INC(x)
-+#define MEM_STATS_INC_USED(x, y)
-+#define MEM_STATS_DEC_USED(x, y)
-+#define MEM_STATS_DISPLAY()
-+#endif
-+
-+#if MEMP_STATS
-+#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
-+#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
-+#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
-+#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
-+                                    if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
-+                                        lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
-+                                    } \
-+                                 } while(0)
-+#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
-+#else
-+#define MEMP_STATS_AVAIL(x, i, y)
-+#define MEMP_STATS_INC(x, i)
-+#define MEMP_STATS_DEC(x, i)
-+#define MEMP_STATS_INC_USED(x, i)
-+#define MEMP_STATS_DISPLAY(i)
-+#endif
-+
-+#if SYS_STATS
-+#define SYS_STATS_INC(x) STATS_INC(sys.x)
-+#define SYS_STATS_DEC(x) STATS_DEC(sys.x)
-+#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
-+#else
-+#define SYS_STATS_INC(x)
-+#define SYS_STATS_DEC(x)
-+#define SYS_STATS_DISPLAY()
- #endif
- /* Display of statistics */
- #if LWIP_STATS_DISPLAY
- void stats_display(void);
-+void stats_display_proto(struct stats_proto *proto, char *name);
-+void stats_display_igmp(struct stats_igmp *igmp);
-+void stats_display_mem(struct stats_mem *mem, char *name);
-+void stats_display_memp(struct stats_mem *mem, int index);
-+void stats_display_sys(struct stats_sys *sys);
- #else
- #define stats_display()
-+#define stats_display_proto(proto, name)
-+#define stats_display_igmp(igmp)
-+#define stats_display_mem(mem, name)
-+#define stats_display_memp(mem, index)
-+#define stats_display_sys(sys)
- #endif /* LWIP_STATS_DISPLAY */
- #ifdef __cplusplus
-Index: src/include/lwip/tcpip.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/lwip/tcpip.h,v
-retrieving revision 1.24
-retrieving revision 1.27
-diff -u -p -r1.24 -r1.27
---- src/include/lwip/tcpip.h   12 Jan 2008 11:52:22 -0000      1.24
-+++ src/include/lwip/tcpip.h   27 Jun 2008 20:34:55 -0000      1.27
-@@ -83,7 +83,11 @@ err_t tcpip_netifapi_lock(struct netifap
- #endif /* LWIP_NETIF_API */
- err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block);
--#define tcpip_callback(f,ctx) tcpip_callback_with_block(f,ctx,1)
-+#define tcpip_callback(f, ctx)              tcpip_callback_with_block(f, ctx, 1)
-+
-+/* free pbufs or heap memory from another context without blocking */
-+err_t pbuf_free_callback(struct pbuf *p);
-+err_t mem_free_callback(void *m);
- err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
- #define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg)
-Index: src/include/netif/loopif.h
-===================================================================
-RCS file: /sources/lwip/lwip/src/include/netif/loopif.h,v
-retrieving revision 1.7
-retrieving revision 1.9
-diff -u -p -r1.7 -r1.9
---- src/include/netif/loopif.h 10 May 2007 10:59:20 -0000      1.7
-+++ src/include/netif/loopif.h 17 Jun 2008 20:12:22 -0000      1.9
-@@ -32,6 +32,7 @@
- #ifndef __NETIF_LOOPIF_H__
- #define __NETIF_LOOPIF_H__
-+#include "lwip/opt.h"
- #include "lwip/netif.h"
- #include "lwip/err.h"
-@@ -39,9 +40,9 @@
- extern "C" {
- #endif
--#if !LWIP_LOOPIF_MULTITHREADING
--void loopif_poll(struct netif *netif);
--#endif
-+#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
-+#define loopif_poll netif_poll
-+#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
- err_t loopif_init(struct netif *netif);
-Index: src/netif/etharp.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
-retrieving revision 1.145
-retrieving revision 1.148
-diff -u -p -r1.145 -r1.148
---- src/netif/etharp.c 4 Mar 2008 13:41:24 -0000       1.145
-+++ src/netif/etharp.c 19 Jun 2008 16:40:59 -0000      1.148
-@@ -353,7 +353,7 @@ find_entry(struct ip_addr *ipaddr, u8_t 
-    * 1) empty entry
-    * 2) oldest stable entry
-    * 3) oldest pending entry without queued packets
--   * 4) oldest pending entry without queued packets
-+   * 4) oldest pending entry with queued packets
-    * 
-    * { ETHARP_TRY_HARD is set at this point }
-    */ 
-@@ -1130,7 +1130,14 @@ ethernet_input(struct pbuf *p, struct ne
-   /* points to packet payload, which starts with an Ethernet header */
-   ethhdr = p->payload;
--  
-+  LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
-+    ("ethernet_input: dest:%02x:%02x:%02x:%02x:%02x:%02x, src:%02x:%02x:%02x:%02x:%02x:%02x, type:%2hx\n",
-+     (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2],
-+     (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5],
-+     (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2],
-+     (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5],
-+     (unsigned)htons(ethhdr->type)));
-+
-   switch (htons(ethhdr->type)) {
-     /* IP packet? */
-     case ETHTYPE_IP:
-@@ -1165,6 +1172,8 @@ ethernet_input(struct pbuf *p, struct ne
- #endif /* PPPOE_SUPPORT */
-     default:
-+      ETHARP_STATS_INC(etharp.proterr);
-+      ETHARP_STATS_INC(etharp.drop);
-       pbuf_free(p);
-       p = NULL;
-       break;
-Index: src/netif/loopif.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/netif/loopif.c,v
-retrieving revision 1.26
-retrieving revision 1.27
-diff -u -p -r1.26 -r1.27
---- src/netif/loopif.c 31 Aug 2007 10:14:09 -0000      1.26
-+++ src/netif/loopif.c 12 Jun 2008 20:10:10 -0000      1.27
-@@ -40,149 +40,8 @@
- #if LWIP_HAVE_LOOPIF
- #include "netif/loopif.h"
--#include "lwip/pbuf.h"
- #include "lwip/snmp.h"
--#include <string.h>
--
--#if !LWIP_LOOPIF_MULTITHREADING
--
--#include "lwip/sys.h"
--#include "lwip/mem.h"
--
--/* helper struct for the linked list of pbufs */
--struct loopif_private {
--  struct pbuf *first;
--  struct pbuf *last;
--};
--
--/**
-- * Call loopif_poll() in the main loop of your application. This is to prevent
-- * reentering non-reentrant functions like tcp_input(). Packets passed to
-- * loopif_output() are put on a list that is passed to netif->input() by
-- * loopif_poll().
-- *
-- * @param netif the lwip network interface structure for this loopif
-- */
--void
--loopif_poll(struct netif *netif)
--{
--  SYS_ARCH_DECL_PROTECT(lev);
--  struct pbuf *in, *in_end;
--  struct loopif_private *priv = (struct loopif_private*)netif->state;
--
--  LWIP_ERROR("priv != NULL", (priv != NULL), return;);
--
--  do {
--    /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
--    SYS_ARCH_PROTECT(lev);
--    in = priv->first;
--    if(in) {
--      in_end = in;
--      while(in_end->len != in_end->tot_len) {
--        LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
--        in_end = in_end->next;
--      }
--      /* 'in_end' now points to the last pbuf from 'in' */
--      if(in_end == priv->last) {
--        /* this was the last pbuf in the list */
--        priv->first = priv->last = NULL;
--      } else {
--        /* pop the pbuf off the list */
--        priv->first = in_end->next;
--        LWIP_ASSERT("should not be null since first != last!", priv->first != NULL);
--      }
--    }
--    SYS_ARCH_UNPROTECT(lev);
--  
--    if(in != NULL) {
--      if(in_end->next != NULL) {
--        /* De-queue the pbuf from its successors on the 'priv' list. */
--        in_end->next = NULL;
--      }
--      if(netif->input(in, netif) != ERR_OK) {
--        pbuf_free(in);
--      }
--      /* Don't reference the packet any more! */
--      in = NULL;
--      in_end = NULL;
--    }
--  /* go on while there is a packet on the list */
--  } while(priv->first != NULL);
--}
--#endif /* LWIP_LOOPIF_MULTITHREADING */
--
--/**
-- * Send an IP packet over the loopback interface.
-- * The pbuf is simply copied and handed back to netif->input.
-- * In multithreaded mode, this is done directly since netif->input must put
-- * the packet on a queue.
-- * In callback mode, the packet is put on an internal queue and is fed to
-- * netif->input by loopif_poll().
-- *
-- * @param netif the lwip network interface structure for this loopif
-- * @param p the (IP) packet to 'send'
-- * @param ipaddr the ip address to send the packet to (not used for loopif)
-- * @return ERR_OK if the packet has been sent
-- *         ERR_MEM if the pbuf used to copy the packet couldn't be allocated
-- */
--static err_t
--loopif_output(struct netif *netif, struct pbuf *p,
--       struct ip_addr *ipaddr)
--{
--#if !LWIP_LOOPIF_MULTITHREADING
--  SYS_ARCH_DECL_PROTECT(lev);
--  struct loopif_private *priv;
--  struct pbuf *last;
--#endif /* LWIP_LOOPIF_MULTITHREADING */
--  struct pbuf *r;
--  err_t err;
--
--  LWIP_UNUSED_ARG(ipaddr);
--
--  /* Allocate a new pbuf */
--  r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
--  if (r == NULL) {
--    return ERR_MEM;
--  }
--
--  /* Copy the whole pbuf queue p into the single pbuf r */
--  if ((err = pbuf_copy(r, p)) != ERR_OK) {
--    pbuf_free(r);
--    r = NULL;
--    return err;
--  }
--
--#if LWIP_LOOPIF_MULTITHREADING
--  /* Multithreading environment, netif->input() is supposed to put the packet
--     into a mailbox, so we can safely call it here without risking to re-enter
--     functions that are not reentrant (TCP!!!) */
--  if(netif->input(r, netif) != ERR_OK) {
--    pbuf_free(r);
--    r = NULL;
--  }
--#else /* LWIP_LOOPIF_MULTITHREADING */
--  /* Raw API without threads: put the packet on a linked list which gets emptied
--     through calling loopif_poll(). */
--  priv = (struct loopif_private*)netif->state;
--
--  /* let last point to the last pbuf in chain r */
--  for (last = r; last->next != NULL; last = last->next);
--  SYS_ARCH_PROTECT(lev);
--  if(priv->first != NULL) {
--    LWIP_ASSERT("if first != NULL, last must also be != NULL", priv->last != NULL);
--    priv->last->next = r;
--    priv->last = last;
--  } else {
--    priv->first = r;
--    priv->last = last;
--  }
--  SYS_ARCH_UNPROTECT(lev);
--#endif /* LWIP_LOOPIF_MULTITHREADING */
--
--  return ERR_OK;    
--}
--
- /**
-  * Initialize a lwip network interface structure for a loopback interface
-  *
-@@ -193,16 +52,6 @@ loopif_output(struct netif *netif, struc
- err_t
- loopif_init(struct netif *netif)
- {
--#if !LWIP_LOOPIF_MULTITHREADING
--  struct loopif_private *priv;
--
--  priv = (struct loopif_private*)mem_malloc(sizeof(struct loopif_private));
--  if(priv == NULL) 
--    return ERR_MEM;
--  priv->first = priv->last = NULL;
--  netif->state = priv;
--#endif /* LWIP_LOOPIF_MULTITHREADING */
--
-   /* initialize the snmp variables and counters inside the struct netif
-    * ifSpeed: no assumption can be made!
-    */
-@@ -210,7 +59,7 @@ loopif_init(struct netif *netif)
-   netif->name[0] = 'l';
-   netif->name[1] = 'o';
--  netif->output = loopif_output;
-+  netif->output = netif_loop_output;
-   return ERR_OK;
- }
-Index: src/netif/slipif.c
-===================================================================
-RCS file: /sources/lwip/lwip/src/netif/slipif.c,v
-retrieving revision 1.29
-retrieving revision 1.30
-diff -u -p -r1.29 -r1.30
---- src/netif/slipif.c 30 Nov 2007 17:22:21 -0000      1.29
-+++ src/netif/slipif.c 17 Jun 2008 20:14:05 -0000      1.30
-@@ -44,6 +44,9 @@
- #include "netif/slipif.h"
- #include "lwip/opt.h"
-+
-+#if LWIP_HAVE_SLIPIF
-+
- #include "lwip/def.h"
- #include "lwip/pbuf.h"
- #include "lwip/sys.h"
-@@ -273,3 +276,4 @@ slipif_init(struct netif *netif)
-   sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop, netif, SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
-   return ERR_OK;
- }
-+#endif /* LWIP_HAVE_SLIPIF */
diff --git a/stubdom/newlib-chk.patch b/stubdom/newlib-chk.patch
deleted file mode 100644 (file)
index 848dbd5..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
---- newlib/libc/stdio/fprintf_chk.c    1969-12-31 19:00:00.000000000 -0500
-+++ newlib/libc/stdio/fprintf_chk.c    2009-02-26 19:02:53.000000000 -0500
-@@ -0,0 +1,21 @@
-+#include <stdarg.h>
-+#include <stdio.h>
-+
-+/*
-+ * Stub implementation of __fprintf_chk adapted from glibc 2.7.  This 
-+ * doesn't actually implement any buffer overflow protection.  It just makes
-+ * the linker happy :)
-+*/
-+int
-+__fprintf_chk (FILE *fp, int flag, const char *format, ...)
-+{
-+  va_list ap;
-+  int done;
-+
-+  va_start (ap, format);
-+  done = vfprintf (fp, format, ap);
-+  va_end (ap);
-+
-+  return done;
-+}
-+
---- newlib/libc/stdio/Makefile.am      2007-08-02 16:23:06.000000000 -0400
-+++ newlib/libc/stdio/Makefile.am      2009-02-26 18:14:53.000000000 -0500
-@@ -20,6 +20,7 @@
-       flags.c                 \
-       fopen.c                 \
-       fprintf.c                       \
-+      fprintf_chk.c           \
-       fputc.c                 \
-       fputs.c                 \
-       fread.c                 \
-@@ -65,6 +66,7 @@
-       sniprintf.c                     \
-       snprintf.c                      \
-       sprintf.c                       \
-+      sprintf_chk.c                   \
-       sscanf.c                        \
-       stdio.c                 \
-       tmpfile.c                       \
---- newlib/libc/stdio/Makefile.in      2007-12-19 17:36:38.000000000 -0500
-+++ newlib/libc/stdio/Makefile.in      2009-02-26 18:43:52.000000000 -0500
-@@ -63,7 +63,8 @@
-       lib_a-fgets.$(OBJEXT) lib_a-fileno.$(OBJEXT) \
-       lib_a-findfp.$(OBJEXT) lib_a-fiprintf.$(OBJEXT) \
-       lib_a-flags.$(OBJEXT) lib_a-fopen.$(OBJEXT) \
--      lib_a-fprintf.$(OBJEXT) lib_a-fputc.$(OBJEXT) \
-+      lib_a-fprintf.$(OBJEXT) lib_a-fprintf_chk.$(OBJEXT) \
-+      lib_a-fputc.$(OBJEXT) \
-       lib_a-fputs.$(OBJEXT) lib_a-fread.$(OBJEXT) \
-       lib_a-freopen.$(OBJEXT) lib_a-fscanf.$(OBJEXT) \
-       lib_a-fiscanf.$(OBJEXT) lib_a-fseek.$(OBJEXT) \
-@@ -86,6 +87,7 @@
-       lib_a-setvbuf.$(OBJEXT) lib_a-siprintf.$(OBJEXT) \
-       lib_a-siscanf.$(OBJEXT) lib_a-sniprintf.$(OBJEXT) \
-       lib_a-snprintf.$(OBJEXT) lib_a-sprintf.$(OBJEXT) \
-+      lib_a-sprintf_chk.$(OBJEXT) \
-       lib_a-sscanf.$(OBJEXT) lib_a-stdio.$(OBJEXT) \
-       lib_a-tmpfile.$(OBJEXT) lib_a-tmpnam.$(OBJEXT) \
-       lib_a-ungetc.$(OBJEXT) lib_a-vdiprintf.$(OBJEXT) \
-@@ -122,15 +124,15 @@
- LTLIBRARIES = $(noinst_LTLIBRARIES)
- am__objects_4 = clearerr.lo fclose.lo fdopen.lo feof.lo ferror.lo \
-       fflush.lo fgetc.lo fgetpos.lo fgets.lo fileno.lo findfp.lo \
--      fiprintf.lo flags.lo fopen.lo fprintf.lo fputc.lo fputs.lo \
--      fread.lo freopen.lo fscanf.lo fiscanf.lo fseek.lo fsetpos.lo \
-+      fiprintf.lo flags.lo fopen.lo fprintf.lo fprintf_chk.lo fputc.lo \
-+      fputs.lo fread.lo freopen.lo fscanf.lo fiscanf.lo fseek.lo fsetpos.lo \
-       ftell.lo fvwrite.lo fwalk.lo fwrite.lo getc.lo getchar.lo \
-       getc_u.lo getchar_u.lo getdelim.lo getline.lo gets.lo \
-       iprintf.lo iscanf.lo makebuf.lo perror.lo printf.lo putc.lo \
-       putchar.lo putc_u.lo putchar_u.lo puts.lo refill.lo remove.lo \
-       rename.lo rewind.lo rget.lo scanf.lo sccl.lo setbuf.lo \
-       setbuffer.lo setlinebuf.lo setvbuf.lo siprintf.lo siscanf.lo \
--      sniprintf.lo snprintf.lo sprintf.lo sscanf.lo stdio.lo \
-+      sniprintf.lo snprintf.lo sprintf.lo sprintf_chk.lo sscanf.lo stdio.lo \
-       tmpfile.lo tmpnam.lo ungetc.lo vdiprintf.lo vdprintf.lo \
-       viprintf.lo viscanf.lo vprintf.lo vscanf.lo vsiprintf.lo \
-       vsiscanf.lo vsnprintf.lo vsniprintf.lo vsprintf.lo vsscanf.lo \
-@@ -344,6 +346,7 @@
-       flags.c                 \
-       fopen.c                 \
-       fprintf.c                       \
-+      fprintf_chk.c                   \
-       fputc.c                 \
-       fputs.c                 \
-       fread.c                 \
-@@ -389,6 +392,7 @@
-       sniprintf.c                     \
-       snprintf.c                      \
-       sprintf.c                       \
-+      sprintf_chk.c                   \
-       sscanf.c                        \
-       stdio.c                 \
-       tmpfile.c                       \
-@@ -508,6 +512,7 @@
-       siprintf.def            \
-       siscanf.def             \
-       sprintf.def             \
-+      sprintf_chk.def         \
-       sscanf.def              \
-       tmpfile.def             \
-       tmpnam.def              \
-@@ -678,6 +683,12 @@
- lib_a-fprintf.obj: fprintf.c
-       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fprintf.obj `if test -f 'fprintf.c'; then $(CYGPATH_W) 'fprintf.c'; else $(CYGPATH_W) '$(srcdir)/fprintf.c'; fi`
-+lib_a-fprintf_chk.o: fprintf_chk.c
-+      $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fprintf_chk.o `test -f 'fprintf_chk.c' || echo '$(srcdir)/'`fprintf_chk.c
-+
-+lib_a-fprintf_chk.obj: fprintf_chk.c
-+      $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fprintf_chk.obj `if test -f 'fprintf_chk.c'; then $(CYGPATH_W) 'fprintf_chk.c'; else $(CYGPATH_W) '$(srcdir)/fprintf_chk.c'; fi`
-+
- lib_a-fputc.o: fputc.c
-       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputc.o `test -f 'fputc.c' || echo '$(srcdir)/'`fputc.c
-@@ -948,6 +959,12 @@
- lib_a-sprintf.obj: sprintf.c
-       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sprintf.obj `if test -f 'sprintf.c'; then $(CYGPATH_W) 'sprintf.c'; else $(CYGPATH_W) '$(srcdir)/sprintf.c'; fi`
-+lib_a-sprintf_chk.o: sprintf_chk.c
-+      $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sprintf_chk.o `test -f 'sprintf_chk.c' || echo '$(srcdir)/'`sprintf_chk.c
-+
-+lib_a-sprintf_chk.obj: sprintf_chk.c
-+      $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sprintf_chk.obj `if test -f 'sprintf_chk.c'; then $(CYGPATH_W) 'sprintf_chk.c'; else $(CYGPATH_W) '$(srcdir)/sprintf_chk.c'; fi`
-+
- lib_a-sscanf.o: sscanf.c
-       $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sscanf.o `test -f 'sscanf.c' || echo '$(srcdir)/'`sscanf.c
---- newlib/libc/stdio/sprintf_chk.c    1969-12-31 19:00:00.000000000 -0500
-+++ newlib/libc/stdio/sprintf_chk.c    2009-02-26 19:02:26.000000000 -0500
-@@ -0,0 +1,21 @@
-+#include <stdarg.h>
-+#include <stdio.h>
-+
-+/*
-+ * Stub implementation of __sprintf_chk adapted from glibc 2.7.  This 
-+ * doesn't actually implement any buffer overflow protection.  It just makes
-+ * the linker happy :)
-+*/
-+int
-+__sprintf_chk (char *s, int flags, size_t slen, const char *format, ...)
-+{
-+  va_list arg;
-+  int done;
-+
-+  va_start (arg, format);
-+  done = vsprintf (s, format, arg);
-+  va_end (arg);
-+
-+  return done;
-+}
-+
diff --git a/stubdom/newlib-stdint-size_max-fix-from-1.17.0.patch b/stubdom/newlib-stdint-size_max-fix-from-1.17.0.patch
deleted file mode 100644 (file)
index 1054a07..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
---- newlib-1.16.0/newlib/libc/include/stdint.h.orig    2006-08-17 00:39:43.000000000 +0300
-+++ newlib-1.16.0/newlib/libc/include/stdint.h 2009-08-25 17:33:23.000000000 +0300
-@@ -348,8 +348,11 @@
- #endif
- /* This must match size_t in stddef.h, currently long unsigned int */
--#define SIZE_MIN (-__STDINT_EXP(LONG_MAX) - 1L)
--#define SIZE_MAX __STDINT_EXP(LONG_MAX)
-+#ifdef __SIZE_MAX__
-+#define SIZE_MAX __SIZE_MAX__
-+#else
-+#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
-+#endif
- /* This must match sig_atomic_t in <signal.h> (currently int) */
- #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
diff --git a/stubdom/newlib.patch b/stubdom/newlib.patch
deleted file mode 100644 (file)
index ee9b6f2..0000000
+++ /dev/null
@@ -1,727 +0,0 @@
-There is a mix between longs and long longs.
-
-Index: newlib/libc/include/inttypes.h
-===================================================================
-RCS file: /cvs/src/src/newlib/libc/include/inttypes.h,v
-retrieving revision 1.3
-diff -u -p -r1.3 inttypes.h
---- newlib/libc/include/inttypes.h     16 Dec 2005 19:03:12 -0000      1.3
-+++ newlib/libc/include/inttypes.h     8 Nov 2007 16:32:44 -0000
-@@ -163,12 +163,12 @@
- /* 64-bit types */
--#if __have_longlong64
--#define __PRI64(x) __STRINGIFY(ll##x)
--#define __SCN64(x) __STRINGIFY(ll##x)
--#elif __have_long64
-+#if __have_long64
- #define __PRI64(x) __STRINGIFY(l##x)
- #define __SCN64(x) __STRINGIFY(l##x)
-+#elif __have_longlong64
-+#define __PRI64(x) __STRINGIFY(ll##x)
-+#define __SCN64(x) __STRINGIFY(ll##x)
- #else
- #define __PRI64(x) __STRINGIFY(x)
- #define __SCN64(x) __STRINGIFY(x)
-@@ -217,12 +217,12 @@
- #endif
- /* max-bit types */
--#if __have_longlong64
--#define __PRIMAX(x) __STRINGIFY(ll##x)
--#define __SCNMAX(x) __STRINGIFY(ll##x)
--#elif __have_long64
-+#if __have_long64
- #define __PRIMAX(x) __STRINGIFY(l##x)
- #define __SCNMAX(x) __STRINGIFY(l##x)
-+#elif __have_longlong64
-+#define __PRIMAX(x) __STRINGIFY(ll##x)
-+#define __SCNMAX(x) __STRINGIFY(ll##x)
- #else
- #define __PRIMAX(x) __STRINGIFY(x)
- #define __SCNMAX(x) __STRINGIFY(x)
-@@ -242,12 +242,12 @@
- #define SCNxMAX               __SCNMAX(x)
- /* ptr types */
--#if __have_longlong64
--#define __PRIPTR(x) __STRINGIFY(ll##x)
--#define __SCNPTR(x) __STRINGIFY(ll##x)
--#elif __have_long64
-+#if __have_long64
- #define __PRIPTR(x) __STRINGIFY(l##x)
- #define __SCNPTR(x) __STRINGIFY(l##x)
-+#elif __have_longlong64
-+#define __PRIPTR(x) __STRINGIFY(ll##x)
-+#define __SCNPTR(x) __STRINGIFY(ll##x)
- #else
- #define __PRIPTR(x) __STRINGIFY(x)
- #define __SCNPTR(x) __STRINGIFY(x)
-
-We don't want u?int32_t to be long as our code assume in a lot of places to be
-int.
-
-Index: newlib/libc/include/stdint.h
-===================================================================
-RCS file: /cvs/src/src/newlib/libc/include/stdint.h,v
-retrieving revision 1.10
-diff -u -p -r1.10 stdint.h
---- newlib/libc/include/stdint.h       16 Aug 2006 21:39:43 -0000      1.10
-+++ newlib/libc/include/stdint.h       12 Feb 2008 13:07:52 -0000
-@@ -38,7 +38,7 @@ extern "C" {
- #if __STDINT_EXP(LONG_MAX) > 0x7fffffff
- #define __have_long64 1
- #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
--#define __have_long32 1
-+/* #define __have_long32 1 */
- #endif
- #if __STDINT_EXP(SCHAR_MAX) == 0x7f
-
-Define the basic ia64 jump buffer
-
-Index: newlib/libc/include/sys/config.h
-===================================================================
-RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
-retrieving revision 1.47
-diff -u -p -r1.47 config.h
---- newlib/libc/include/sys/config.h   15 Mar 2007 21:32:12 -0000      1.47
-+++ newlib/libc/include/sys/config.h   8 Nov 2007 16:32:44 -0000
-@@ -71,6 +71,10 @@
- #endif
- #endif
-+#ifndef __DYNAMIC_REENT__
-+#define __DYNAMIC_REENT__
-+#endif
-+
- #ifdef __mn10200__
- #define __SMALL_BITFIELDS
- #endif
-
-Dynamic pointer to our reentrancy zone
-
-Index: newlib/libc/reent/getreent.c
-===================================================================
-RCS file: /cvs/src/src/newlib/libc/reent/getreent.c,v
-retrieving revision 1.2
-diff -u -p -r1.2 getreent.c
---- newlib/libc/reent/getreent.c       7 Sep 2007 00:45:55 -0000       1.2
-+++ newlib/libc/reent/getreent.c       8 Nov 2007 16:32:44 -0000
-@@ -3,12 +3,20 @@
- #include <_ansi.h>
- #include <reent.h>
-+#define weak_alias(name, aliasname) \
-+  extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
-+
- #ifdef __getreent
- #undef __getreent
- #endif
-+#ifdef __libc_getreent
-+#undef __libc_getreent
-+#endif
- struct _reent *
--_DEFUN_VOID(__getreent)
-+__libc_getreent (void)
- {
-   return _impure_ptr;
- }
-+weak_alias(__libc_getreent,__getreent)
-+
-
-We can't provide a red zone in mini-os.
-
-Index: newlib/libc/machine/x86_64/memcpy.S
-===================================================================
-RCS file: /cvs/src/src/newlib/libc/machine/x86_64/memcpy.S,v
-retrieving revision 1.1
-diff -u -p -r1.1 memcpy.S
---- newlib/libc/machine/x86_64/memcpy.S        28 Aug 2007 21:56:49 -0000      1.1
-+++ newlib/libc/machine/x86_64/memcpy.S        8 Nov 2007 16:32:44 -0000
-@@ -30,10 +30,18 @@ quadword_aligned:
-   cmpq    $256, rdx
-   jb      quadword_copy
-+#if 1
-+  subq    $32, rsp
-+  movq    rax, 24 (rsp)
-+  movq    r12, 16 (rsp)
-+  movq    r13, 8  (rsp)
-+  movq    r14, 0  (rsp)
-+#else
-   movq    rax, -8  (rsp)
-   movq    r12, -16 (rsp)
-   movq    r13, -24 (rsp)
-   movq    r14, -32 (rsp)
-+#endif
-   movq    rdx, rcx                /* Copy 128 bytes at a time with minimum cache polution */
-   shrq    $7, rcx
-@@ -89,10 +97,18 @@ loop:
-   movq    rdx, rcx
-   andq    $127, rcx
-   rep     movsb
-+#if 1
-+  movq    24 (rsp), rax
-+  movq    16 (rsp), r12
-+  movq    8  (rsp), r13
-+  movq    0  (rsp), r14
-+  addq    $32, rsp
-+#else
-   movq    -8  (rsp), rax
-   movq    -16 (rsp), r12
-   movq    -24 (rsp), r13
-   movq    -32 (rsp), r14
-+#endif
-   ret
---- newlib/libc/machine/x86_64/x86_64mach.h.orig       2008-07-11 14:57:23.062269000 +0100
-+++ newlib/libc/machine/x86_64/x86_64mach.h    2008-07-11 14:58:01.262503000 +0100
-@@ -22,81 +22,81 @@
- #define REG(x) CONCAT1(__REG_PREFIX__, x)
--#define rax REG(rax)
--#define rbx REG(rbx)
--#define rcx REG(rcx)
--#define rdx REG(rdx)
--#define rsi REG(rsi)
--#define rdi REG(rdi)
--#define rbp REG(rbp)
--#define rsp REG(rsp)
--
--#define r8  REG(r8)
--#define r9  REG(r9)
--#define r10 REG(r10)
--#define r11 REG(r11)
--#define r12 REG(r12)
--#define r13 REG(r13)
--#define r14 REG(r14)
--#define r15 REG(r15)
--
--#define eax REG(eax)
--#define ebx REG(ebx)
--#define ecx REG(ecx)
--#define edx REG(edx)
--#define esi REG(esi)
--#define edi REG(edi)
--#define ebp REG(ebp)
--#define esp REG(esp)
--
--#define st0 REG(st)
--#define st1 REG(st(1))
--#define st2 REG(st(2))
--#define st3 REG(st(3))
--#define st4 REG(st(4))
--#define st5 REG(st(5))
--#define st6 REG(st(6))
--#define st7 REG(st(7))
--
--#define ax REG(ax)
--#define bx REG(bx)
--#define cx REG(cx)
--#define dx REG(dx)
--
--#define ah REG(ah)
--#define bh REG(bh)
--#define ch REG(ch)
--#define dh REG(dh)
--
--#define al REG(al)
--#define bl REG(bl)
--#define cl REG(cl)
--#define dl REG(dl)
--
--#define sil REG(sil)
--
--#define mm1 REG(mm1)
--#define mm2 REG(mm2)
--#define mm3 REG(mm3)
--#define mm4 REG(mm4)
--#define mm5 REG(mm5)
--#define mm6 REG(mm6)
--#define mm7 REG(mm7)
--
--#define xmm0 REG(xmm0)
--#define xmm1 REG(xmm1)
--#define xmm2 REG(xmm2)
--#define xmm3 REG(xmm3)
--#define xmm4 REG(xmm4)
--#define xmm5 REG(xmm5)
--#define xmm6 REG(xmm6)
--#define xmm7 REG(xmm7)
--
--#define cr0 REG(cr0)
--#define cr1 REG(cr1)
--#define cr2 REG(cr2)
--#define cr3 REG(cr3)
--#define cr4 REG(cr4)
-+#define rax %rax
-+#define rbx %rbx
-+#define rcx %rcx
-+#define rdx %rdx
-+#define rsi %rsi
-+#define rdi %rdi
-+#define rbp %rbp
-+#define rsp %rsp
-+
-+#define r8  %r8
-+#define r9  %r9
-+#define r10 %r10
-+#define r11 %r11
-+#define r12 %r12
-+#define r13 %r13
-+#define r14 %r14
-+#define r15 %r15
-+
-+#define eax %eax
-+#define ebx %ebx
-+#define ecx %ecx
-+#define edx %edx
-+#define esi %esi
-+#define edi %edi
-+#define ebp %ebp
-+#define esp %esp
-+
-+#define st0 %st
-+#define st1 %st(1)
-+#define st2 %st(2)
-+#define st3 %st(3)
-+#define st4 %st(4)
-+#define st5 %st(5)
-+#define st6 %st(6)
-+#define st7 %st(7)
-+
-+#define ax %ax
-+#define bx %bx
-+#define cx %cx
-+#define dx %dx
-+
-+#define ah %ah
-+#define bh %bh
-+#define ch %ch
-+#define dh %dh
-+
-+#define al %al
-+#define bl %bl
-+#define cl %cl
-+#define dl %dl
-+
-+#define sil %sil
-+
-+#define mm1 %mm1
-+#define mm2 %mm2
-+#define mm3 %mm3
-+#define mm4 %mm4
-+#define mm5 %mm5
-+#define mm6 %mm6
-+#define mm7 %mm7
-+
-+#define xmm0 %xmm0
-+#define xmm1 %xmm1
-+#define xmm2 %xmm2
-+#define xmm3 %xmm3
-+#define xmm4 %xmm4
-+#define xmm5 %xmm5
-+#define xmm6 %xmm6
-+#define xmm7 %xmm7
-+
-+#define cr0 %cr0
-+#define cr1 %cr1
-+#define cr2 %cr2
-+#define cr3 %cr3
-+#define cr4 %cr4
- #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
- #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
---- newlib/libc/machine/x86_64/memcpy.S.orig   2008-07-11 15:12:27.494693000 +0100
-+++ newlib/libc/machine/x86_64/memcpy.S        2008-07-11 15:12:29.448706000 +0100
-@@ -60,14 +60,14 @@
-   movq    48 (rsi), r13
-   movq    56 (rsi), r14
--  movntiq rax,    (rdi)
--  movntiq r8 ,  8 (rdi)
--  movntiq r9 , 16 (rdi)
--  movntiq r10, 24 (rdi)
--  movntiq r11, 32 (rdi)
--  movntiq r12, 40 (rdi)
--  movntiq r13, 48 (rdi)
--  movntiq r14, 56 (rdi)
-+  movnti rax,    (rdi)
-+  movnti r8 ,  8 (rdi)
-+  movnti r9 , 16 (rdi)
-+  movnti r10, 24 (rdi)
-+  movnti r11, 32 (rdi)
-+  movnti r12, 40 (rdi)
-+  movnti r13, 48 (rdi)
-+  movnti r14, 56 (rdi)
-   movq     64 (rsi), rax
-   movq     72 (rsi), r8
-@@ -78,14 +78,14 @@
-   movq    112 (rsi), r13
-   movq    120 (rsi), r14
--  movntiq rax,  64 (rdi)
--  movntiq r8 ,  72 (rdi)
--  movntiq r9 ,  80 (rdi)
--  movntiq r10,  88 (rdi)
--  movntiq r11,  96 (rdi)
--  movntiq r12, 104 (rdi)
--  movntiq r13, 112 (rdi)
--  movntiq r14, 120 (rdi)
-+  movnti rax,  64 (rdi)
-+  movnti r8 ,  72 (rdi)
-+  movnti r9 ,  80 (rdi)
-+  movnti r10,  88 (rdi)
-+  movnti r11,  96 (rdi)
-+  movnti r12, 104 (rdi)
-+  movnti r13, 112 (rdi)
-+  movnti r14, 120 (rdi)
-   leaq    128 (rsi), rsi
-   leaq    128 (rdi), rdi
---- newlib/libc/machine/i386/i386mach.h        2000-08-28 18:50:06.000000000 +0100
-+++ newlib/libc/machine/i386/i386mach.h        2008-07-11 15:17:13.874409000 +0100
-@@ -27,46 +27,46 @@
-  
- #define REG(x) CONCAT1(__REG_PREFIX__, x)
-  
--#define eax REG(eax)
--#define ebx REG(ebx)
--#define ecx REG(ecx)
--#define edx REG(edx)
--#define esi REG(esi)
--#define edi REG(edi)
--#define ebp REG(ebp)
--#define esp REG(esp)
--
--#define st0 REG(st)
--#define st1 REG(st(1))
--#define st2 REG(st(2))
--#define st3 REG(st(3))
--#define st4 REG(st(4))
--#define st5 REG(st(5))
--#define st6 REG(st(6))
--#define st7 REG(st(7))
--
--#define ax REG(ax)
--#define bx REG(bx)
--#define cx REG(cx)
--#define dx REG(dx)
--
--#define ah REG(ah)
--#define bh REG(bh)
--#define ch REG(ch)
--#define dh REG(dh)
--
--#define al REG(al)
--#define bl REG(bl)
--#define cl REG(cl)
--#define dl REG(dl)
--
--#define mm1 REG(mm1)
--#define mm2 REG(mm2)
--#define mm3 REG(mm3)
--#define mm4 REG(mm4)
--#define mm5 REG(mm5)
--#define mm6 REG(mm6)
--#define mm7 REG(mm7)
-+#define eax %eax
-+#define ebx %ebx
-+#define ecx %ecx
-+#define edx %edx
-+#define esi %esi
-+#define edi %edi
-+#define ebp %ebp
-+#define esp %esp
-+
-+#define st0 %st
-+#define st1 %st(1)
-+#define st2 %st(2)
-+#define st3 %st(3)
-+#define st4 %st(4)
-+#define st5 %st(5)
-+#define st6 %st(6)
-+#define st7 %st(7)
-+
-+#define ax %ax
-+#define bx %bx
-+#define cx %cx
-+#define dx %dx
-+
-+#define ah %ah
-+#define bh %bh
-+#define ch %ch
-+#define dh %dh
-+
-+#define al %al
-+#define bl %bl
-+#define cl %cl
-+#define dl %dl
-+
-+#define mm1 %mm1
-+#define mm2 %mm2
-+#define mm3 %mm3
-+#define mm4 %mm4
-+#define mm5 %mm5
-+#define mm6 %mm6
-+#define mm7 %mm7
- #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
- #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
---- newlib/libc/machine/x86_64/memset.S        2007-08-28 22:56:49.000000000 +0100
-+++ newlib/libc/machine/x86_64/memset.S        2008-07-11 15:16:59.098320000 +0100
-@@ -40,22 +40,22 @@
-   .p2align 4
- loop:
--  movntiq rax,     (rdi)
--  movntiq rax,   8 (rdi)
--  movntiq rax,  16 (rdi)
--  movntiq rax,  24 (rdi)
--  movntiq rax,  32 (rdi)
--  movntiq rax,  40 (rdi)
--  movntiq rax,  48 (rdi)
--  movntiq rax,  56 (rdi)
--  movntiq rax,  64 (rdi)
--  movntiq rax,  72 (rdi)
--  movntiq rax,  80 (rdi)
--  movntiq rax,  88 (rdi)
--  movntiq rax,  96 (rdi)
--  movntiq rax, 104 (rdi)
--  movntiq rax, 112 (rdi)
--  movntiq rax, 120 (rdi)
-+  movnti rax,     (rdi)
-+  movnti rax,   8 (rdi)
-+  movnti rax,  16 (rdi)
-+  movnti rax,  24 (rdi)
-+  movnti rax,  32 (rdi)
-+  movnti rax,  40 (rdi)
-+  movnti rax,  48 (rdi)
-+  movnti rax,  56 (rdi)
-+  movnti rax,  64 (rdi)
-+  movnti rax,  72 (rdi)
-+  movnti rax,  80 (rdi)
-+  movnti rax,  88 (rdi)
-+  movnti rax,  96 (rdi)
-+  movnti rax, 104 (rdi)
-+  movnti rax, 112 (rdi)
-+  movnti rax, 120 (rdi)
-   leaq    128 (rdi), rdi
---- newlib/libm/machine/i386/i386mach.h.orig   2008-07-11 15:30:37.367227000 +0100
-+++ newlib/libm/machine/i386/i386mach.h        2008-07-11 15:30:55.232337000 +0100
-@@ -27,46 +27,46 @@
-  
- #define REG(x) CONCAT1(__REG_PREFIX__, x)
-  
--#define eax REG(eax)
--#define ebx REG(ebx)
--#define ecx REG(ecx)
--#define edx REG(edx)
--#define esi REG(esi)
--#define edi REG(edi)
--#define ebp REG(ebp)
--#define esp REG(esp)
--
--#define st0 REG(st)
--#define st1 REG(st(1))
--#define st2 REG(st(2))
--#define st3 REG(st(3))
--#define st4 REG(st(4))
--#define st5 REG(st(5))
--#define st6 REG(st(6))
--#define st7 REG(st(7))
--
--#define ax REG(ax)
--#define bx REG(bx)
--#define cx REG(cx)
--#define dx REG(dx)
--
--#define ah REG(ah)
--#define bh REG(bh)
--#define ch REG(ch)
--#define dh REG(dh)
--
--#define al REG(al)
--#define bl REG(bl)
--#define cl REG(cl)
--#define dl REG(dl)
--
--#define mm1 REG(mm1)
--#define mm2 REG(mm2)
--#define mm3 REG(mm3)
--#define mm4 REG(mm4)
--#define mm5 REG(mm5)
--#define mm6 REG(mm6)
--#define mm7 REG(mm7)
-+#define eax %eax
-+#define ebx %ebx
-+#define ecx %ecx
-+#define edx %edx
-+#define esi %esi
-+#define edi %edi
-+#define ebp %ebp
-+#define esp %esp
-+
-+#define st0 %st
-+#define st1 %st(1)
-+#define st2 %st(2)
-+#define st3 %st(3)
-+#define st4 %st(4)
-+#define st5 %st(5)
-+#define st6 %st(6)
-+#define st7 %st(7)
-+
-+#define ax %ax
-+#define bx %bx
-+#define cx %cx
-+#define dx %dx
-+
-+#define ah %ah
-+#define bh %bh
-+#define ch %ch
-+#define dh %dh
-+
-+#define al %al
-+#define bl %bl
-+#define cl %cl
-+#define dl %dl
-+
-+#define mm1 %mm1
-+#define mm2 %mm2
-+#define mm3 %mm3
-+#define mm4 %mm4
-+#define mm5 %mm5
-+#define mm6 %mm6
-+#define mm7 %mm7
- #ifdef _I386MACH_NEED_SOTYPE_FUNCTION
- #define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
-
-
-We want to have a 64bit offsets libc even on 32bit platforms.
-
---- ./newlib/configure.host.orig       2008-08-07 16:01:17.801946000 +0100
-+++ ./newlib/configure.host    2008-08-07 16:01:34.181064000 +0100
-@@ -317,6 +317,8 @@
-     oext=lo
-     lpfx=
-     aext=la ;;
-+  i[34567]86-xen-elf)
-+    stdio64_dir=stdio64 ;;
-   *) ;; #shared library not supported for ${host}
- esac
---- newlib/libc/include/sys/_types.h.orig      2008-08-07 15:22:44.925008000 +0100
-+++ newlib/libc/include/sys/_types.h   2008-08-07 15:22:50.824044000 +0100
-@@ -13,8 +13,12 @@
- #include <sys/lock.h>
- #ifndef __off_t_defined
-+#ifdef __MINIOS__
-+typedef long long _off_t;
-+#else
- typedef long _off_t;
- #endif
-+#endif
- #if defined(__rtems__)
- /* device numbers are 32-bit major and and 32-bit minor */
---- ./newlib/libc/include/sys/config.h.orig    2008-08-07 14:43:25.915866000 +0100
-+++ ./newlib/libc/include/sys/config.h 2008-08-07 14:44:13.508154000 +0100
-@@ -69,6 +69,10 @@
- /* we use some glibc header files so turn on glibc large file feature */
- #define _LARGEFILE64_SOURCE 1
- #endif
-+#ifdef __MINIOS__
-+#define __LARGE64_FILES 1
-+#define _LARGEFILE64_SOURCE 1
-+#endif
- #endif
- #ifndef __DYNAMIC_REENT__
---- ./newlib/libc/include/sys/_default_fcntl.h.orig    2008-08-07 15:08:22.377836000 +0100
-+++ ./newlib/libc/include/sys/_default_fcntl.h 2008-08-07 15:08:31.651890000 +0100
-@@ -170,7 +170,11 @@
- /* Provide _<systemcall> prototypes for functions provided by some versions
-    of newlib.  */
- #ifdef _COMPILING_NEWLIB
--extern int _open _PARAMS ((const char *, int, ...));
-+extern int _open _PARAMS ((const char *, int, ...))
-+#ifdef __MINIOS__
-+    asm("open64")
-+#endif
-+    ;
- extern int _fcntl _PARAMS ((int, int, ...));
- #ifdef __LARGE64_FILES
- extern int _open64 _PARAMS ((const char *, int, ...));
---- ./newlib/libc/include/sys/unistd.h.orig    2008-08-07 15:09:36.449280000 +0100
-+++ ./newlib/libc/include/sys/unistd.h 2008-08-07 15:09:51.210370000 +0100
-@@ -101,7 +101,11 @@
- int     _EXFUN(link, (const char *__path1, const char *__path2 ));
- int   _EXFUN(nice, (int __nice_value ));
- #if !defined(__INSIDE_CYGWIN__)
--off_t   _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ));
-+off_t   _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ))
-+#ifdef __MINIOS__
-+    asm("lseek64")
-+#endif
-+    ;
- #endif
- #if defined(__SPU__)
- #define F_ULOCK       0
---- ./newlib/libc/include/sys/stat.h.orig      2008-08-07 16:08:50.495116000 +0100
-+++ ./newlib/libc/include/sys/stat.h   2008-08-07 16:10:21.799753000 +0100
-@@ -49,6 +49,9 @@
-   long        st_spare4[2];
- #endif
- };
-+#ifdef __MINIOS__
-+#define stat64 stat
-+#endif
- #endif
- #define       _IFMT           0170000 /* type of file */
-@@ -132,7 +135,11 @@
- /* Provide prototypes for most of the _<systemcall> names that are
-    provided in newlib for some compilers.  */
- #ifdef _COMPILING_NEWLIB
--int   _EXFUN(_fstat,( int __fd, struct stat *__sbuf ));
-+int   _EXFUN(_fstat,( int __fd, struct stat *__sbuf ))
-+#ifdef __MINIOS__
-+    asm("fstat64")
-+#endif
-+    ;
- int   _EXFUN(_stat,( const char *__path, struct stat *__sbuf ));
- #ifdef __LARGE64_FILES
- struct stat64;
---- ./newlib/libc/include/_syslist.h.orig      2008-08-07 16:24:19.122605000 +0100
-+++ ./newlib/libc/include/_syslist.h   2008-08-07 16:24:21.548628000 +0100
-@@ -14,6 +14,7 @@
- #define _kill kill
- #define _link link
- #define _lseek lseek
-+#define _lseek64 lseek64
- #define _open open
- #define _read read
- #define _sbrk sbrk
---- newlib/libc/include/reent.h.orig   2008-08-07 16:28:49.846502000 +0100
-+++ newlib/libc/include/reent.h        2008-08-07 16:29:02.096586000 +0100
-@@ -87,6 +87,9 @@
- #if defined(__CYGWIN__) && defined(_COMPILING_NEWLIB)
- #define stat64 __stat64
- #endif
-+#if defined(__MINIOS__)
-+#define stat64 stat
-+#endif
- struct stat64;
diff --git a/stubdom/ocaml.patch b/stubdom/ocaml.patch
deleted file mode 100644 (file)
index 50db486..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
---- byterun/Makefile.orig      2009-04-07 12:14:02.000000000 +0100
-+++ byterun/Makefile   2009-04-07 12:13:50.000000000 +0100
-@@ -22,14 +22,14 @@
- DOBJS=$(OBJS:.o=.d.o) instrtrace.d.o
- PICOBJS=$(OBJS:.o=.pic.o)
--#ifeq ($(SUPPORTS_SHARED_LIBRARIES),true)
-+ifeq ($(SUPPORTS_SHARED_LIBRARIES),true)
- all:: libcamlrun_shared.so
- install::
-       cp libcamlrun_shared.so $(LIBDIR)/libcamlrun_shared.so
--#endif
-+endif
- ocamlrun$(EXE): libcamlrun.a prims.o
-       $(MKEXE) $(BYTECCLINKOPTS) -o ocamlrun$(EXE) \
diff --git a/stubdom/pciutils.patch b/stubdom/pciutils.patch
deleted file mode 100644 (file)
index 5ab84d6..0000000
+++ /dev/null
@@ -1,298 +0,0 @@
-diff -urN pciutils-2.2.9.orig/lib/access.c pciutils-2.2.9/lib/access.c
---- pciutils-2.2.9.orig/lib/access.c   2007-02-06 11:59:43.000000000 +0000
-+++ pciutils-2.2.9/lib/access.c        2008-06-30 19:07:09.713187000 +0100
-@@ -57,6 +57,11 @@
- #else
-   NULL,
- #endif
-+#ifdef PCI_OS_MINIOS
-+  &pm_minios,
-+#else
-+  NULL,
-+#endif
- };
- struct pci_access *
---- pciutils-2.2.9.orig/lib/pci.h      2006-09-09 13:46:06.000000000 +0100
-+++ pciutils-2.2.9/lib/pci.h   2008-06-30 18:56:15.350111000 +0100
-@@ -33,6 +33,7 @@
-   PCI_ACCESS_NBSD_LIBPCI,             /* NetBSD libpci */
-   PCI_ACCESS_OBSD_DEVICE,             /* OpenBSD /dev/pci */
-   PCI_ACCESS_DUMP,                    /* Dump file (params: filename) */
-+  PCI_ACCESS_MINIOS,                  /* MiniOS */
-   PCI_ACCESS_MAX
- };
---- pciutils-2.2.9.orig/lib/internal.h 2006-09-09 11:52:47.000000000 +0100
-+++ pciutils-2.2.9/lib/internal.h      2008-07-01 10:46:24.968202000 +0100
-@@ -37,4 +37,4 @@
- extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
-       pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
--      pm_dump, pm_linux_sysfs;
-+      pm_dump, pm_linux_sysfs, pm_minios;
---- pciutils-2.2.9.orig/lib/Makefile   2007-10-19 13:41:34.000000000 +0100
-+++ pciutils-2.2.9/lib/Makefile        2008-07-01 12:13:14.400525000 +0100
-@@ -46,6 +46,12 @@
- PCILIB=libpciutils.a
- endif
-+ifdef PCI_OS_MINIOS
-+XEN_ROOT=$(CURDIR)/../../..
-+include $(XEN_ROOT)/Config.mk
-+OBJS += minios.o
-+endif
-+
- all: $(PCILIB) $(PCILIBPC)
- $(PCILIB): $(OBJS)
---- pciutils-2.2.9.orig/lib/types.h    2009-07-14 18:18:59.000000000 +0200
-+++ pciutils-2.2.9/lib/types.h 2009-07-14 18:19:16.000000000 +0200
-@@ -20,10 +20,12 @@ typedef DWORD u32;
- typedef uint8_t u8;
- typedef uint16_t u16;
- typedef uint32_t u32;
-+typedef uint64_t u64;
- #else
- typedef u_int8_t u8;
- typedef u_int16_t u16;
- typedef u_int32_t u32;
-+typedef u_int64_t u64;
- #endif
-
- #ifdef PCI_HAVE_64BIT_ADDRESS
---- pciutils-2.2.9.orig/lib/minios.c   1970-01-01 01:00:00.000000000 +0100
-+++ pciutils-2.2.9/lib/minios.c        2008-07-01 12:31:40.554260000 +0100
-@@ -0,0 +1,106 @@
-+/*
-+ *    The PCI Library -- MiniOS PCI frontend access
-+ *
-+ *    Samuel Thibault <samuel.thibault@eu.citrix.com>, 2008
-+ *
-+ *    Can be freely distributed and used under the terms of the GNU GPL.
-+ */
-+
-+#include <os.h>
-+#include <pcifront.h>
-+#include <xenbus.h>
-+#include "internal.h"
-+
-+static int
-+minios_detect(struct pci_access *a)
-+{
-+  return 1;
-+}
-+
-+static void
-+minios_init(struct pci_access *a)
-+{
-+}
-+
-+static void
-+minios_cleanup(struct pci_access *a)
-+{
-+  shutdown_pcifront(NULL);
-+}
-+
-+static void
-+minios_scan(struct pci_access *a)
-+{
-+  void func(unsigned int domain, unsigned int bus, unsigned int slot, unsigned int fun)
-+  {
-+    struct pci_dev *d = pci_alloc_dev(a);
-+
-+    d->domain = domain;
-+    d->bus = bus;
-+    d->dev = slot;
-+    d->func = fun;
-+
-+    pci_link_dev(a, d);
-+  }
-+
-+  pcifront_scan(NULL, func);
-+}
-+
-+static int
-+minios_read(struct pci_dev *d, int pos, byte *buf, int len)
-+{
-+  unsigned int val;
-+  switch (len) {
-+    case 1:
-+      if (pcifront_conf_read(NULL, d->domain, d->bus, d->dev, d->func, pos, len, &val))
-+        return 0;
-+      * buf = val;
-+      return 1;
-+    case 2:
-+      if (pcifront_conf_read(NULL, d->domain, d->bus, d->dev, d->func, pos, len, &val))
-+        return 0;
-+      *(u16 *) buf = cpu_to_le16((u16) val);
-+      return 1;
-+    case 4:
-+      if (pcifront_conf_read(NULL, d->domain, d->bus, d->dev, d->func, pos, len, &val))
-+        return 0;
-+      *(u32 *) buf = cpu_to_le32((u32) val);
-+      return 1;
-+    default:
-+      return pci_generic_block_read(d, pos, buf, len);
-+  }
-+}
-+
-+static int
-+minios_write(struct pci_dev *d, int pos, byte *buf, int len)
-+{
-+  unsigned int val;
-+  switch (len) {
-+    case 1:
-+      val = * buf;
-+      break;
-+    case 2:
-+      val = le16_to_cpu(*(u16 *) buf);
-+      break;
-+    case 4:
-+      val = le32_to_cpu(*(u32 *) buf);
-+      break;
-+    default:
-+      return pci_generic_block_write(d, pos, buf, len);
-+  }
-+  return !pcifront_conf_write(NULL, d->domain, d->bus, d->dev, d->func, pos, len, val);
-+}
-+
-+struct pci_methods pm_minios = {
-+  "MiniOS-device",
-+  NULL,                                 /* config */
-+  minios_detect,
-+  minios_init,
-+  minios_cleanup,
-+  minios_scan,
-+  pci_generic_fill_info,
-+  minios_read,
-+  minios_write,
-+  NULL,                                 /* dev_init */
-+  NULL                                  /* dev_cleanup */
-+};
---- pciutils-2.2.9/lib/generic.c       2007-02-06 12:00:05.000000000 +0000
-+++ pciutils-2.2.9-mine/lib/generic.c  2008-07-01 19:13:52.289949000 +0100
-@@ -74,6 +74,19 @@
-   pci_generic_scan_bus(a, busmap, 0);
- }
-+static u32 pci_size(u32 base, u32 maxbase, u32 mask)
-+{
-+  u32 size = mask & maxbase;
-+  if (!size)
-+    return 0;
-+  size = (size & ~(size-1)) - 1;
-+
-+  if (base == maxbase && ((base | size) & mask) != mask)
-+    return 0;
-+
-+  return size + 1;
-+}
-+
- int
- pci_generic_fill_info(struct pci_dev *d, int flags)
- {
-@@ -114,23 +127,61 @@
-             if (!x || x == (u32) ~0)
-               continue;
-             if ((x & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
--              d->base_addr[i] = x;
--            else
-+                {
-+                  d->base_addr[i] = x & PCI_BASE_ADDRESS_IO_MASK;
-+                  if (flags & PCI_FILL_SIZES)
-+                    {
-+                      u32 size;
-+                      pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
-+                      d->size[i] = pci_size(x, pci_read_long(d, PCI_BASE_ADDRESS_0 + i*4), PCI_BASE_ADDRESS_IO_MASK);
-+                      pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, x);
-+                    }
-+                }
-+              else
-               {
-                 if ((x & PCI_BASE_ADDRESS_MEM_TYPE_MASK) != PCI_BASE_ADDRESS_MEM_TYPE_64)
--                  d->base_addr[i] = x;
-+                    {
-+                      d->base_addr[i] = x & PCI_BASE_ADDRESS_MEM_MASK;
-+                      if (flags & PCI_FILL_SIZES)
-+                        {
-+                          u32 size;
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
-+                          d->size[i] = pci_read_long(d, PCI_BASE_ADDRESS_0 + i*4);
-+                          d->size[i] = pci_size(x, pci_read_long(d, PCI_BASE_ADDRESS_0 + i*4), PCI_BASE_ADDRESS_MEM_MASK);
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, x);
-+                        }
-+                    }
-                 else if (i >= cnt-1)
-                   a->warning("%04x:%02x:%02x.%d: Invalid 64-bit address seen for BAR %d.", d->domain, d->bus, d->dev, d->func, i);
-                 else
-                   {
-                     u32 y = pci_read_long(d, PCI_BASE_ADDRESS_0 + (++i)*4);
- #ifdef PCI_HAVE_64BIT_ADDRESS
--                    d->base_addr[i-1] = x | (((pciaddr_t) y) << 32);
-+                    d->base_addr[i-1] = (x | (((pciaddr_t) y) << 32)) & PCI_BASE_ADDRESS_MEM_MASK;
-+                      if (flags & PCI_FILL_SIZES)
-+                        {
-+                          u32 size;
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, ~0);
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, ~0);
-+                          d->size[i-1] = pci_size(y, pci_read_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4) | 
-+                                         pci_read_long(d, PCI_BASE_ADDRESS_0 + i*4), 0xffffffff );
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, x);
-+                          pci_write_long(d, PCI_BASE_ADDRESS_0 + i*4, y);
-+                        }
- #else
-                     if (y)
-                       a->warning("%04x:%02x:%02x.%d 64-bit device address ignored.", d->domain, d->bus, d->dev, d->func);
-                     else
--                      d->base_addr[i-1] = x;
-+                        {
-+                          d->base_addr[i-1] = x & PCI_BASE_ADDRESS_MEM_MASK;
-+                          if (flags & PCI_FILL_SIZES)
-+                            {
-+                              u32 size;
-+                              pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, ~0);
-+                              d->size[i-1] = pci_size(x, pci_read_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4), PCI_BASE_ADDRESS_MEM_MASK);
-+                              pci_write_long(d, PCI_BASE_ADDRESS_0 + (i-1)*4, x);
-+                            }
-+                        }
- #endif
-                   }
-               }
-@@ -154,10 +205,19 @@
-       {
-         u32 u = pci_read_long(d, reg);
-         if (u != 0xffffffff)
--          d->rom_base_addr = u;
-+            {
-+              d->rom_base_addr = u;
-+              if (flags & PCI_FILL_SIZES)
-+                {
-+                  u32 size;
-+                  pci_write_long(d, reg, ~0);
-+                  d->rom_size = pci_read_long(d, reg);
-+                  pci_write_long(d, reg, u);
-+                }
-+            }
-       }
-     }
--  return flags & ~PCI_FILL_SIZES;
-+  return flags;
- }
- static int
-diff -uNpbE -uNpbEr pciutils-2.2.9.orig/lib/sysdep.h pciutils-2.2.9/lib/sysdep.h
---- pciutils-2.2.9.orig/lib/sysdep.h   2007-02-06 12:00:18.000000000 +0000
-+++ pciutils-2.2.9/lib/sysdep.h        2009-07-22 16:26:30.000000000 +0100
-@@ -32,6 +32,10 @@ typedef u16 word;
- #else
-+#ifdef PCI_OS_MINIOS
-+#include <machine/endian.h>
-+#endif
-+
- #ifdef PCI_OS_LINUX
- #include <endian.h>
- #define BYTE_ORDER __BYTE_ORDER
diff --git a/stubdom/polarssl.patch b/stubdom/polarssl.patch
deleted file mode 100644 (file)
index d387d4e..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-diff -Naur polarssl-1.1.4/include/polarssl/config.h polarssl-x86_64/include/polarssl/config.h
---- polarssl-1.1.4/include/polarssl/config.h   2011-12-22 05:06:27.000000000 -0500
-+++ polarssl-x86_64/include/polarssl/config.h  2012-10-30 17:18:07.567001000 -0400
-@@ -164,8 +164,8 @@
-  * application.
-  *
-  * Uncomment this macro to prevent loading of default entropy functions.
--#define POLARSSL_NO_DEFAULT_ENTROPY_SOURCES
-  */
-+#define POLARSSL_NO_DEFAULT_ENTROPY_SOURCES
-
- /**
-  * \def POLARSSL_NO_PLATFORM_ENTROPY
-@@ -175,8 +175,8 @@
-  * standards like the /dev/urandom or Windows CryptoAPI.
-  *
-  * Uncomment this macro to disable the built-in platform entropy functions.
--#define POLARSSL_NO_PLATFORM_ENTROPY
-  */
-+#define POLARSSL_NO_PLATFORM_ENTROPY
-
- /**
-  * \def POLARSSL_PKCS1_V21
-@@ -426,8 +426,8 @@
-  * Requires: POLARSSL_TIMING_C
-  *
-  * This module enables the HAVEGE random number generator.
-- */
- #define POLARSSL_HAVEGE_C
-+ */
-
- /**
-  * \def POLARSSL_MD_C
-@@ -490,7 +490,7 @@
-  *
-  * This module provides TCP/IP networking routines.
-  */
--#define POLARSSL_NET_C
-+//#define POLARSSL_NET_C
-
- /**
-  * \def POLARSSL_PADLOCK_C
-@@ -644,8 +644,8 @@
-  * Caller:  library/havege.c
-  *
-  * This module is used by the HAVEGE random number generator.
-- */
- #define POLARSSL_TIMING_C
-+ */
-
- /**
-  * \def POLARSSL_VERSION_C
-diff -Naur polarssl-1.1.4/library/bignum.c polarssl-x86_64/library/bignum.c
---- polarssl-1.1.4/library/bignum.c    2012-04-29 16:15:55.000000000 -0400
-+++ polarssl-x86_64/library/bignum.c   2012-10-30 17:21:52.135000999 -0400
-@@ -1101,7 +1101,7 @@
-             Z.p[i - t - 1] = ~0;
-         else
-         {
--#if defined(POLARSSL_HAVE_LONGLONG)
-+#if 0 //defined(POLARSSL_HAVE_LONGLONG)
-             t_udbl r;
-
-             r  = (t_udbl) X.p[i] << biL;
diff --git a/stubdom/stubdom-dm b/stubdom/stubdom-dm
deleted file mode 100644 (file)
index 05d07ac..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.net>
-#
-# dm script around stubdomains.
-#
-
-DIR=`dirname $0`
-. "${DIR}/stubdompath.sh"
-stubdom_configdir="${XEN_CONFIG_DIR}/stubdoms"
-
-# To fit xterms nicely
-height=339
-
-# Parse arguments
-
-domid=
-domname=
-vncviewer=0
-vncpid=
-extra=
-sdl=0
-opengl=1
-vnc=0
-vncunused=0
-while [ "$#" -gt 0 ];
-do
-    if [ "$#" -ge 2 ];
-    then
-       case "$1" in
-           -d)
-                domid=$2;
-                extra="$extra -d $domid";
-                shift
-                ;;
-           -domain-name)
-                domname=$2;
-                shift
-                ;;
-           -vnc)
-                vnc=1
-                op=${2%,*}
-               ip=${op%:*};
-               vnc_port=${op#*:};
-               shift
-               ;;
-            -vncunused)
-                vncunused=1
-                shift
-                ;;
-            -loadvm)
-                extra="$extra -loadvm $2";
-                shift
-                ;;
-            -k)
-                keymap=$2
-                shift
-                ;;
-           -serial)
-               serial="$2"
-               shift
-               ;;
-            -monitor)
-               monitor="$2"
-               shift
-               ;;
-       esac
-    fi
-    case "$1" in
-       -vncviewer) vncviewer=1 ;;
-        -sdl) sdl=1 ;;
-        -disable-opengl) opengl=0 ;;
-    esac
-    shift
-done
-
-[ -z "$domid"   ] && { echo "couldn't find domain ID" ; exit 1; }
-[ -z "$domname" ] && { echo "couldn't find domain name" ; exit 1; }
-
-# Termination handler
-
-term() {
-    [ -n "$vncpid" ] && kill -9 $vncpid
-    rm -f /tmp/domname-dm
-    rm ${stubdom_configdir}/$domname-dm
-    exit 0
-}
-
-trap term SIGHUP
-
-############
-# stubdomain
-# Wait for any previous stubdom to terminate
-while xm list | grep -w $domname-dm
-do
-       sleep 1
-done
-
-# Generate stubdom config file
-mkdir -p ${stubdom_configdir} &>/dev/null
-echo "#This file is autogenerated, edit $domname instead!" > ${stubdom_configdir}/$domname-dm
-echo "kernel = '${XENFIRMWAREDIR}/ioemu-stubdom.gz'" >> ${stubdom_configdir}/$domname-dm
-
-vfb="sdl=$sdl, opengl=$opengl"
-test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
-test "$XAUTHORITY" && vfb="$vfb, xauthority=$XAUTHORITY"
-test $vnc != 0 && vfb="$vfb, vnc=$vnc, vncdisplay=$vnc_port, vnclisten=$ip, vncunused=$vncunused"
-vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
-test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
-test "$keymap" && vfb="$vfb, keymap=$keymap"
-test "$monitor" && vfb="$vfb, monitor=$monitor"
-test "$serial" && vfb="$vfb, serial=$serial"
-echo "vfb = ['$vfb']" >> ${stubdom_configdir}/$domname-dm
-
-echo -n "disk = [ " >> ${stubdom_configdir}/$domname-dm
-j=0
-for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
-do
-    i=${i%\"}
-    i=${i#\"}
-    vbd_mode=`xenstore-read $i/mode`
-    vbd_disk=`xenstore-read $i/params`
-    vbd_type=`xenstore-read $i/type`
-    vbd_dev=`xenstore-read $i/dev`
-    vbd_front=`xenstore-read $i/frontend`
-    vbd_devtype=`xenstore-read $vbd_front/device-type`
-    if [ $j -ne 0 ]
-    then
-        echo -n "," >> ${stubdom_configdir}/$domname-dm
-    fi
-    echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> ${stubdom_configdir}/$domname-dm
-    j=$(( $j + 1 ))
-done
-echo " ] " >> ${stubdom_configdir}/$domname-dm
-echo -n "vif = [ " >> ${stubdom_configdir}/$domname-dm
-j=0
-for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
-do
-    i=${i%\"}
-    i=${i#\"}
-    vif_mac=`xenstore-read $i/mac`
-    vif_bridge=`xenstore-read $i/bridge`
-    if [ $j -ne 0 ]
-    then
-        echo -n "," >> ${stubdom_configdir}/$domname-dm
-    fi
-    echo -n "'mac=$vif_mac" >> ${stubdom_configdir}/$domname-dm
-    if [ "$vif_bridge" ]
-    then
-        echo -n ",bridge=$vif_bridge'" >> ${stubdom_configdir}/$domname-dm
-    else
-        echo -n "'" >> ${stubdom_configdir}/$domname-dm
-    fi
-    j=$(( $j + 1 ))
-done
-echo " ] " >> ${stubdom_configdir}/$domname-dm
-
-mkfifo /tmp/$domname-dm
-xm create -c ${stubdom_configdir}/$domname-dm target=$domid memory=32 extra="$extra" < /tmp/$domname-dm &
-exec 4>/tmp/$domname-dm
-
-
-###########
-# vncviewer
-if [ "$vncviewer" = 1 ]
-then
-    # Wait for vnc server to appear
-    while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
-    do
-        # Check that the stubdom job is still alive
-        kill -0 $consolepid || term
-       sleep 1
-    done
-
-    vncviewer $ip:$vnc_port &
-    vncpid=$!
-fi
-
-# wait for SIGHUP or stubdom termination
-wait
-
-term
diff --git a/stubdom/tpmemu-0.7.4.patch b/stubdom/tpmemu-0.7.4.patch
deleted file mode 100644 (file)
index b84eff1..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-diff -Naur tpm_emulator-x86_64-back/tpm/tpm_emulator_extern.c tpm_emulator-x86_64/tpm/tpm_emulator_extern.c
---- tpm_emulator-x86_64-back/tpm/tpm_emulator_extern.c 2012-04-27 10:55:46.581963398 -0400
-+++ tpm_emulator-x86_64/tpm/tpm_emulator_extern.c      2012-04-27 10:56:02.193034152 -0400
-@@ -249,7 +249,7 @@
- #else /* TPM_NO_EXTERN */
-
- int (*tpm_extern_init)(void)                                      = NULL;
--int (*tpm_extern_release)(void)                                   = NULL;
-+void (*tpm_extern_release)(void)                                   = NULL;
- void* (*tpm_malloc)(size_t size)                                  = NULL;
- void (*tpm_free)(/*const*/ void *ptr)                             = NULL;
- void (*tpm_log)(int priority, const char *fmt, ...)               = NULL;
diff --git a/stubdom/vtpm-bufsize.patch b/stubdom/vtpm-bufsize.patch
deleted file mode 100644 (file)
index 9c9304c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/config.h.in b/config.h.in
-index d16a997..8088a2a 100644
---- a/config.h.in
-+++ b/config.h.in
-@@ -27,7 +27,7 @@
- #define TPM_STORAGE_NAME "${TPM_STORAGE_NAME}"
- #define TPM_DEVICE_NAME  "${TPM_DEVICE_NAME}"
- #define TPM_LOG_FILE     "${TPM_LOG_FILE}"
--#define TPM_CMD_BUF_SIZE 4096
-+#define TPM_CMD_BUF_SIZE 4088
- #endif /* _CONFIG_H_ */
diff --git a/stubdom/vtpm-cmake-Wextra.patch b/stubdom/vtpm-cmake-Wextra.patch
deleted file mode 100644 (file)
index a603654..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
----
- CMakeLists.txt |    3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
-
-Index: tpm_emulator-x86_64/CMakeLists.txt
-===================================================================
---- tpm_emulator-x86_64.orig/CMakeLists.txt
-+++ tpm_emulator-x86_64/CMakeLists.txt
-@@ -40,10 +40,11 @@ set(TPM_STORAGE_NAME "/var/lib/tpm/tpm_e
- set(TPM_DEVICE_NAME "/dev/tpm")
- endif()
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
--add_definitions(-Wall -Werror -Wno-unused-parameter -Wpointer-arith -Wcast-align -Wwrite-strings)
-+add_definitions(-Wall -Werror)
- if("${CMAKE_SYSTEM}" MATCHES "Linux")
-     add_definitions(-Wextra)
- endif()
-+add_definitions(-Wno-unused-parameter -Wpointer-arith -Wcast-align -Wwrite-strings)
- if(USE_OPENSSL)
-     add_definitions(-DUSE_OPENSSL)
- endif()
diff --git a/stubdom/vtpm-deepquote-anyloc.patch b/stubdom/vtpm-deepquote-anyloc.patch
deleted file mode 100644 (file)
index 7b37d51..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c
-index 69511d1..7545d51 100644
---- a/tpm/tpm_cmd_handler.c
-+++ b/tpm/tpm_cmd_handler.c
-@@ -3347,12 +3347,13 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp)
- {
-       TPM_NONCE nonce;
-       TPM_RESULT res;
--      UINT32 sigSize;
--      BYTE *sig;
-+      UINT32 quote_blob_size;
-+      BYTE *quote_blob;
-       BYTE *ptr;
-       UINT32 len;
-       TPM_PCR_SELECTION myPCR;
-       TPM_PCR_SELECTION ptPCR;
-+      UINT32 extraInfoFlags = 0;
-       tpm_compute_in_param_digest(req);
-@@ -3361,17 +3362,19 @@ static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-       if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce)
-               || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &myPCR)
-               || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &ptPCR)
-+              || tpm_unmarshal_TPM_DEEP_QUOTE_INFO(&ptr, &len, &extraInfoFlags)
-               || len != 0) return TPM_BAD_PARAMETER;
--      res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, &sigSize, &sig);
-+      res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, extraInfoFlags,
-+              &quote_blob_size, &quote_blob);
-       if (res != TPM_SUCCESS) return res;
--      rsp->paramSize = len = sigSize;
-+      rsp->paramSize = len = quote_blob_size;
-       rsp->param = ptr = tpm_malloc(len);
--      if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) {
-+      if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, quote_blob, quote_blob_size)) {
-               tpm_free(rsp->param);
-               res = TPM_FAIL;
-       }
--      tpm_free(sig);
-+      tpm_free(quote_blob);
-       return res;
- }
-diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h
-index 328d1be..a56dd5f 100644
---- a/tpm/tpm_commands.h
-+++ b/tpm/tpm_commands.h
-@@ -3077,6 +3077,7 @@ TPM_RESULT TPM_ParentSignEK(
-  * @myPCR: [in] PCR selection for the virtual TPM
-  * @ptPCR: [in] PCR selection for the hardware TPM
-  * @auth1: [in, out] Authorization protocol parameters
-+ * @extraInfoFlags [in] Flags for including, kernel hash, group info, etc
-  * @sigSize: [out] The length of the returned digital signature
-  * @sig: [out] The resulting digital signature and PCR values
-  * Returns: TPM_SUCCESS on success, a TPM error code otherwise.
-@@ -3086,6 +3087,7 @@ TPM_RESULT TPM_DeepQuote(
-   TPM_PCR_SELECTION *myPCR,
-   TPM_PCR_SELECTION *ptPCR,
-   TPM_AUTH *auth1,
-+  UINT32 extraInfoFlags,
-   UINT32 *sigSize,
-   BYTE **sig
- );
-diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c
-index c0d62e7..6586c22 100644
---- a/tpm/tpm_credentials.c
-+++ b/tpm/tpm_credentials.c
-@@ -183,7 +183,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_KEY_HANDLE keyHandle, TPM_AUTH *auth1,
- int endorsementKeyFresh = 0;
--TPM_RESULT VTPM_GetParentQuote(TPM_DIGEST* data, TPM_PCR_SELECTION *sel, UINT32 *sigSize, BYTE **sig);
-+TPM_RESULT VTPM_GetParentQuote(TPM_NONCE *data, TPM_PCR_SELECTION *sel,
-+                               UINT32 extraInfoFlags, UINT32 *sigSize, BYTE **sig);
- TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel,
-                             TPM_AUTH *auth1, UINT32 *sigSize, BYTE **sig)
-@@ -191,7 +192,7 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel,
-       TPM_PUBKEY pubKey;
-       TPM_RESULT res;
-       TPM_DIGEST hres;
--
-+      UINT32 extraInfoFlags = 0;
-       info("TPM_ParentSignEK()");
-       res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
-@@ -206,7 +207,7 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel,
-               res = TPM_FAIL;
-       if (res == TPM_SUCCESS)
--              res = VTPM_GetParentQuote(&hres, sel, sigSize, sig);
-+              res = VTPM_GetParentQuote((TPM_NONCE*)&hres, sel, extraInfoFlags, sigSize, sig);
-       free_TPM_PUBKEY(pubKey);
-       return res;
-@@ -218,7 +219,7 @@ static const BYTE dquot_hdr[] = {
- TPM_RESULT TPM_DeepQuote(TPM_NONCE *externalData, TPM_PCR_SELECTION *myPCR,
-                          TPM_PCR_SELECTION *ptPCR, TPM_AUTH *auth1,
--                         UINT32 *sigSize, BYTE **sig)
-+                         UINT32 extraInfoFlags, UINT32 *quote_blob_size, BYTE **quote_blob)
- {
-   TPM_RESULT res;
-   TPM_DIGEST hres;
-@@ -253,7 +254,7 @@ TPM_RESULT TPM_DeepQuote(TPM_NONCE *externalData, TPM_PCR_SELECTION *myPCR,
-   tpm_free(buf);
--      res = VTPM_GetParentQuote(&hres, ptPCR, sigSize, sig);
-+  res = VTPM_GetParentQuote((TPM_NONCE*)&hres, ptPCR, extraInfoFlags, quote_blob_size, quote_blob);
-   return res;
- }
-diff --git a/tpm/tpm_marshalling.h b/tpm/tpm_marshalling.h
-index d510ebe..2e0c008 100644
---- a/tpm/tpm_marshalling.h
-+++ b/tpm/tpm_marshalling.h
-@@ -268,6 +268,8 @@ static inline int tpm_unmarshal_BOOL(BYTE **ptr, UINT32 *length, BOOL *v)
- #define tpm_unmarshal_TPM_REDIR_COMMAND        tpm_unmarshal_UINT32
- #define tpm_marshal_DAAHANDLE                  tpm_marshal_UINT32
- #define tpm_unmarshal_DAAHANDLE                tpm_unmarshal_UINT32
-+#define tpm_marshal_TPM_DEEP_QUOTE_INFO        tpm_marshal_UINT32
-+#define tpm_unmarshal_TPM_DEEP_QUOTE_INFO      tpm_unmarshal_UINT32
- int tpm_marshal_UINT32_ARRAY(BYTE **ptr, UINT32 *length, UINT32 *v, UINT32 n);
- int tpm_unmarshal_UINT32_ARRAY(BYTE **ptr, UINT32 *length, UINT32 *v, UINT32 n);
diff --git a/stubdom/vtpm-deepquote.patch b/stubdom/vtpm-deepquote.patch
deleted file mode 100644 (file)
index 6344f38..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c
-index 0fabf98..69511d1 100644
---- a/tpm/tpm_cmd_handler.c
-+++ b/tpm/tpm_cmd_handler.c
-@@ -3343,6 +3343,39 @@ static TPM_RESULT execute_TPM_ParentSignEK(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-       return res;
- }
-+static TPM_RESULT execute_TPM_DeepQuote(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-+{
-+      TPM_NONCE nonce;
-+      TPM_RESULT res;
-+      UINT32 sigSize;
-+      BYTE *sig;
-+      BYTE *ptr;
-+      UINT32 len;
-+      TPM_PCR_SELECTION myPCR;
-+      TPM_PCR_SELECTION ptPCR;
-+
-+      tpm_compute_in_param_digest(req);
-+
-+      ptr = req->param;
-+      len = req->paramSize;
-+      if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce)
-+              || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &myPCR)
-+              || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &ptPCR)
-+              || len != 0) return TPM_BAD_PARAMETER;
-+
-+      res = TPM_DeepQuote(&nonce, &myPCR, &ptPCR, &req->auth1, &sigSize, &sig);
-+      if (res != TPM_SUCCESS) return res;
-+      rsp->paramSize = len = sigSize;
-+      rsp->param = ptr = tpm_malloc(len);
-+      if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) {
-+              tpm_free(rsp->param);
-+              res = TPM_FAIL;
-+      }
-+      tpm_free(sig);
-+
-+      return res;
-+}
-+
- static void tpm_setup_rsp_auth(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp) 
- {
-   tpm_hmac_ctx_t hmac;
-@@ -4098,6 +4131,11 @@ void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-       res = execute_TPM_ParentSignEK(req, rsp);
-     break;
-+    case TPM_ORD_DeepQuote:
-+      debug("[TPM_ORD_DeepQuote]");
-+      res = execute_TPM_DeepQuote(req, rsp);
-+    break;
-+
-     default:
- #ifdef MTM_EMULATOR
-       res = mtm_execute_command(req, rsp);
-diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h
-index 7fef934..328d1be 100644
---- a/tpm/tpm_commands.h
-+++ b/tpm/tpm_commands.h
-@@ -3071,6 +3071,25 @@ TPM_RESULT TPM_ParentSignEK(
-   BYTE **sig
- );
-+/**
-+ * TPM_DeepQuote - gets a hardware TPM quote of a vTPM's PCRs
-+ * @externalData: [in] AntiReplay nonce to prevent replay of messages
-+ * @myPCR: [in] PCR selection for the virtual TPM
-+ * @ptPCR: [in] PCR selection for the hardware TPM
-+ * @auth1: [in, out] Authorization protocol parameters
-+ * @sigSize: [out] The length of the returned digital signature
-+ * @sig: [out] The resulting digital signature and PCR values
-+ * Returns: TPM_SUCCESS on success, a TPM error code otherwise.
-+ */
-+TPM_RESULT TPM_DeepQuote(
-+  TPM_NONCE *externalData,
-+  TPM_PCR_SELECTION *myPCR,
-+  TPM_PCR_SELECTION *ptPCR,
-+  TPM_AUTH *auth1,
-+  UINT32 *sigSize,
-+  BYTE **sig
-+);
-+
- /*
-  * Error handling
-  * [tpm_error.c]
-diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c
-index 01f29e6..c0d62e7 100644
---- a/tpm/tpm_credentials.c
-+++ b/tpm/tpm_credentials.c
-@@ -211,3 +211,49 @@ TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel,
-       free_TPM_PUBKEY(pubKey);
-       return res;
- }
-+
-+static const BYTE dquot_hdr[] = {
-+      0, 0, 0, 0, 'D', 'Q', 'U', 'T'
-+};
-+
-+TPM_RESULT TPM_DeepQuote(TPM_NONCE *externalData, TPM_PCR_SELECTION *myPCR,
-+                         TPM_PCR_SELECTION *ptPCR, TPM_AUTH *auth1,
-+                         UINT32 *sigSize, BYTE **sig)
-+{
-+      TPM_RESULT res;
-+      TPM_DIGEST hres;
-+      TPM_PCR_INFO_SHORT pcrData;
-+      tpm_sha1_ctx_t ctx;
-+      BYTE *buf, *ptr;
-+      UINT32 size, len;
-+
-+      info("TPM_DeepQuote()");
-+
-+      res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
-+      if (res != TPM_SUCCESS) return res;
-+
-+      res = tpm_compute_pcr_digest(myPCR, &pcrData.digestAtRelease, NULL);
-+      if (res != TPM_SUCCESS) return res;
-+
-+      pcrData.pcrSelection.sizeOfSelect = myPCR->sizeOfSelect;
-+      memcpy(pcrData.pcrSelection.pcrSelect, myPCR->pcrSelect, myPCR->sizeOfSelect);
-+      pcrData.localityAtRelease = 1 << tpmData.stany.flags.localityModifier;
-+
-+      size = len = sizeof_TPM_PCR_INFO_SHORT(pcrData);
-+      buf = ptr = tpm_malloc(size);
-+      if (buf == NULL) return TPM_NOSPACE;
-+      if (tpm_marshal_TPM_PCR_INFO_SHORT(&ptr, &len, &pcrData))
-+              return TPM_FAIL;
-+
-+      tpm_sha1_init(&ctx);
-+      tpm_sha1_update(&ctx, dquot_hdr, 8);
-+      tpm_sha1_update(&ctx, externalData->nonce, 20);
-+      tpm_sha1_update(&ctx, buf, size);
-+      tpm_sha1_final(&ctx, hres.digest);
-+
-+      tpm_free(buf);
-+
-+      res = VTPM_GetParentQuote(&hres, ptPCR, sigSize, sig);
-+
-+      return res;
-+}
-diff --git a/tpm/tpm_structures.h b/tpm/tpm_structures.h
-index b0f4625..dfb1894 100644
---- a/tpm/tpm_structures.h
-+++ b/tpm/tpm_structures.h
-@@ -660,6 +660,42 @@ typedef struct tdTPM_CMK_MA_APPROVAL {
- /* VTPM-only commands: */
- /*
-+ * Deep Quote - Create quote of PCRs
-+ * Input:
-+ *   TPM_TAG             tag           TPM_TAG_RQU_AUTH1_COMMAND
-+ *   UINT32              paramSize     Total size of request
-+ *   TPM_COMMAND_CODE    ordinal       TPM_ORD_DeepQuote
-+ *   TPM_NONCE           externData    20 bytes of external data
-+ *   TPM_PCR_SELECTION   vtSel         PCR selection for virtual TPM
-+ *   TPM_PCR_SELECTION   ptSel         PCR selection for physical TPM
-+ *   ---
-+ *   UINT32              authHandle    Owner authorization session (OIAP)
-+ *   TPM_NONCE           nonceOdd      Nonce for authHandle
-+ *   BOOL                continueAuth  Continue flag for authHandle
-+ *   TPM_AUTHDATA        privAuth      Authorization digest for command
-+ *
-+ * Output:
-+ *   TPM_TAG             tag           TPM_TAG_RSP_AUTH1_COMMAND
-+ *   UINT32              paramSize     Total size of response
-+ *   TPM_RESULT          returnCode    Return code of the operation
-+ *   BYTE[]              sig           Signature provided by physical TPM
-+ *   TPM_PCRVALUE[]      pcrValue      Values of hardware PCRs used in the quote
-+ *   ---
-+ *   TPM_NONCE           nonceEven     Nonce for authHandle
-+ *   BOOL                continueAuth  Continue flag for authHandle
-+ *   TPM_AUTHDATA        resAuth       Authorization digest for response
-+ *
-+ * The values of the virutal TPM's PCRs are not included in the response.
-+ * The signature is a standard TPM_Quote response from the physical TPM; its
-+ * externalData is the SHA1 hash of the following structure:
-+ *   TPM_STRUCT_VER      version       MUST be 0.0.0.0
-+ *   BYTE[4]             fixed         MUST be the string "DQUT"
-+ *   TPM_NONCE           externData    From input to the deep quote
-+ *   TPM_PCR_INFO_SHORT  pcrData       Virtual TPM's PCRs
-+ */
-+#define TPM_ORD_DeepQuote                       (TPM_VENDOR_COMMAND | TPM_ORD_Quote)
-+
-+/*
-  * ParentSignEK - Proof of fresh provisioning and EK value
-  *
-  * Input:
diff --git a/stubdom/vtpm-locality.patch b/stubdom/vtpm-locality.patch
deleted file mode 100644 (file)
index 8ab7dea..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-diff --git a/tpm/tpm_capability.c b/tpm/tpm_capability.c
-index 60bbb90..f8f7f0f 100644
---- a/tpm/tpm_capability.c
-+++ b/tpm/tpm_capability.c
-@@ -949,6 +949,8 @@ static TPM_RESULT set_vendor(UINT32 subCap, BYTE *setValue,
-                              UINT32 setValueSize, BOOL ownerAuth,
-                              BOOL deactivated, BOOL disabled)
- {
-+  if (tpmData.stany.flags.localityModifier != 8)
-+    return TPM_BAD_PARAMETER;
-   /* set the capability area with the specified data, on failure
-      deactivate the TPM */
-   switch (subCap) {
-diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c
-index 288d1ce..9e1cfb4 100644
---- a/tpm/tpm_cmd_handler.c
-+++ b/tpm/tpm_cmd_handler.c
-@@ -4132,7 +4132,7 @@ void tpm_emulator_shutdown()
-   tpm_extern_release();
- }
--int tpm_handle_command(const uint8_t *in, uint32_t in_size, uint8_t **out, uint32_t *out_size)
-+int tpm_handle_command(const uint8_t *in, uint32_t in_size, uint8_t **out, uint32_t *out_size, int locality)
- {
-   TPM_REQUEST req;
-   TPM_RESPONSE rsp;
-@@ -4140,7 +4140,9 @@ int tpm_handle_command(const uint8_t *in, uint32_t in_size, uint8_t **out, uint3
-   UINT32 len;
-   BOOL free_out;
--  debug("tpm_handle_command()");
-+  debug("tpm_handle_command(%d)", locality);
-+  if (locality != -1)
-+    tpmData.stany.flags.localityModifier = locality;
-   /* we need the whole packet at once, otherwise unmarshalling will fail */
-   if (tpm_unmarshal_TPM_REQUEST((uint8_t**)&in, &in_size, &req) != 0) {
-diff --git a/tpm/tpm_emulator.h b/tpm/tpm_emulator.h
-index eed749e..4c228bd 100644
---- a/tpm/tpm_emulator.h
-+++ b/tpm/tpm_emulator.h
-@@ -59,7 +59,7 @@ void tpm_emulator_shutdown(void);
-  * its usage. In case of an error, all internally allocated memory
-  * is released and the the state of out and out_size is unspecified.
-  */ 
--int tpm_handle_command(const uint8_t *in, uint32_t in_size, uint8_t **out, uint32_t *out_size);
-+int tpm_handle_command(const uint8_t *in, uint32_t in_size, uint8_t **out, uint32_t *out_size, int locality);
- #endif /* _TPM_EMULATOR_H_ */
diff --git a/stubdom/vtpm-parent-sign-ek.patch b/stubdom/vtpm-parent-sign-ek.patch
deleted file mode 100644 (file)
index 14e66ee..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-diff --git a/tpm/tpm_cmd_handler.c b/tpm/tpm_cmd_handler.c
-index 9e1cfb4..0fabf98 100644
---- a/tpm/tpm_cmd_handler.c
-+++ b/tpm/tpm_cmd_handler.c
-@@ -3312,6 +3312,37 @@ static TPM_RESULT execute_TPM_OwnerReadPubek(TPM_REQUEST *req, TPM_RESPONSE *rsp
-   return res;
- }
-+static TPM_RESULT execute_TPM_ParentSignEK(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-+{
-+      TPM_NONCE nonce;
-+      TPM_RESULT res;
-+      UINT32 sigSize;
-+      BYTE *sig;
-+      BYTE *ptr;
-+      UINT32 len;
-+      TPM_PCR_SELECTION targetPCR;
-+
-+      tpm_compute_in_param_digest(req);
-+
-+      ptr = req->param;
-+      len = req->paramSize;
-+      if (tpm_unmarshal_TPM_NONCE(&ptr, &len, &nonce)
-+              || tpm_unmarshal_TPM_PCR_SELECTION(&ptr, &len, &targetPCR)
-+              || len != 0) return TPM_BAD_PARAMETER;
-+
-+      res = TPM_ParentSignEK(&nonce, &targetPCR, &req->auth1, &sigSize, &sig);
-+      if (res != TPM_SUCCESS) return res;
-+      rsp->paramSize = len = sigSize;
-+      rsp->param = ptr = tpm_malloc(len);
-+      if (ptr == NULL || tpm_marshal_BLOB(&ptr, &len, sig, sigSize)) {
-+              tpm_free(rsp->param);
-+              res = TPM_FAIL;
-+      }
-+      tpm_free(sig);
-+
-+      return res;
-+}
-+
- static void tpm_setup_rsp_auth(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp) 
- {
-   tpm_hmac_ctx_t hmac;
-@@ -4062,6 +4093,11 @@ void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
-       res = execute_TPM_OwnerReadPubek(req, rsp);
-     break;
-+    case TPM_ORD_ParentSignEK:
-+      debug("[TPM_ORD_ParentSignEK]");
-+      res = execute_TPM_ParentSignEK(req, rsp);
-+    break;
-+
-     default:
- #ifdef MTM_EMULATOR
-       res = mtm_execute_command(req, rsp);
-diff --git a/tpm/tpm_commands.h b/tpm/tpm_commands.h
-index a7666f6..7fef934 100644
---- a/tpm/tpm_commands.h
-+++ b/tpm/tpm_commands.h
-@@ -3054,6 +3054,23 @@ TPM_RESULT TPM_OwnerReadPubek(
-   TPM_PUBKEY *pubEndorsementKey 
- );
-+/**
-+ * TPM_ParentSignEK - gets a hardware TPM quote of a vTPM's EK
-+ * @externalData: [in] AntiReplay nonce to prevent replay of messages
-+ * @sel: [in] PCR selection for the hardware TPM's quote
-+ * @auth1: [in, out] Authorization protocol parameters
-+ * @sigSize: [out] The length of the returned digital signature
-+ * @sig: [out] The resulting digital signature and PCR values
-+ * Returns: TPM_SUCCESS on success, a TPM error code otherwise.
-+ */
-+TPM_RESULT TPM_ParentSignEK(
-+  TPM_NONCE *externalData,
-+  TPM_PCR_SELECTION *sel,
-+  TPM_AUTH *auth1,
-+  UINT32 *sigSize,
-+  BYTE **sig
-+);
-+
- /*
-  * Error handling
-  * [tpm_error.c]
-diff --git a/tpm/tpm_credentials.c b/tpm/tpm_credentials.c
-index 9cd64af..01f29e6 100644
---- a/tpm/tpm_credentials.c
-+++ b/tpm/tpm_credentials.c
-@@ -180,3 +180,34 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_KEY_HANDLE keyHandle, TPM_AUTH *auth1,
-     return TPM_BAD_PARAMETER;
-   }
- }
-+
-+int endorsementKeyFresh = 0;
-+
-+TPM_RESULT VTPM_GetParentQuote(TPM_DIGEST* data, TPM_PCR_SELECTION *sel, UINT32 *sigSize, BYTE **sig);
-+
-+TPM_RESULT TPM_ParentSignEK(TPM_NONCE *externalData, TPM_PCR_SELECTION *sel,
-+                            TPM_AUTH *auth1, UINT32 *sigSize, BYTE **sig)
-+{
-+      TPM_PUBKEY pubKey;
-+      TPM_RESULT res;
-+      TPM_DIGEST hres;
-+
-+      info("TPM_ParentSignEK()");
-+
-+      res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
-+      if (res != TPM_SUCCESS) return res;
-+
-+      if (!endorsementKeyFresh) return TPM_DISABLED_CMD;
-+
-+      res = tpm_get_pubek(&pubKey);
-+      if (res != TPM_SUCCESS) return res;
-+
-+      if (tpm_compute_pubkey_checksum(externalData, &pubKey, &hres))
-+              res = TPM_FAIL;
-+
-+      if (res == TPM_SUCCESS)
-+              res = VTPM_GetParentQuote(&hres, sel, sigSize, sig);
-+
-+      free_TPM_PUBKEY(pubKey);
-+      return res;
-+}
-diff --git a/tpm/tpm_data.c b/tpm/tpm_data.c
-index 50c9697..6a0c499 100644
---- a/tpm/tpm_data.c
-+++ b/tpm/tpm_data.c
-@@ -76,6 +76,8 @@ static void init_timeouts(void)
-   tpmData.permanent.data.cmd_durations[2] = 1000;
- }
-+extern int endorsementKeyFresh;
-+
- void tpm_init_data(void)
- {
-   /* endorsement key */
-@@ -157,6 +159,7 @@ void tpm_init_data(void)
-   if (tpmConf & TPM_CONF_GENERATE_EK) {
-     /* generate a new endorsement key */
-     tpm_rsa_generate_key(&tpmData.permanent.data.endorsementKey, 2048);
-+    endorsementKeyFresh = 1;
-   } else {
-     /* setup endorsement key */
-     tpm_rsa_import_key(&tpmData.permanent.data.endorsementKey, 
-diff --git a/tpm/tpm_structures.h b/tpm/tpm_structures.h
-index f746c05..b0f4625 100644
---- a/tpm/tpm_structures.h
-+++ b/tpm/tpm_structures.h
-@@ -658,6 +658,49 @@ typedef struct tdTPM_CMK_MA_APPROVAL {
- #define TPM_ORD_TickStampBlob                   242
- #define TPM_ORD_MAX                             256
-+/* VTPM-only commands: */
-+/*
-+ * ParentSignEK - Proof of fresh provisioning and EK value
-+ *
-+ * Input:
-+ *   TPM_TAG             tag           TPM_TAG_RQU_AUTH1_COMMAND
-+ *   UINT32              paramSize     Total size of request
-+ *   TPM_COMMAND_CODE    ordinal       TPM_ORD_ParentSignEK
-+ *   TPM_NONCE           externData    20 bytes of external data
-+ *   TPM_PCR_SELECTION   ptSel         PCR selection for physical TPM
-+ *   ---
-+ *   UINT32              authHandle    Owner authorization session (OIAP)
-+ *   TPM_NONCE           nonceOdd      Nonce for authHandle
-+ *   BOOL                continueAuth  Continue flag for authHandle
-+ *   TPM_AUTHDATA        privAuth      Authorization digest for command
-+ *
-+ * Output:
-+ *   TPM_TAG             tag           TPM_TAG_RSP_AUTH1_COMMAND
-+ *   UINT32              paramSize     Total size of response
-+ *   TPM_RESULT          returnCode    Return code of the operation
-+ *   BYTE[]              sig           Signature provided by physical TPM
-+ *   TPM_PCRVALUE[]      pcrValue      Values of hardware PCRs used in the quote
-+ *   ---
-+ *   TPM_NONCE           nonceEven     Nonce for authHandle
-+ *   BOOL                continueAuth  Continue flag for authHandle
-+ *   TPM_AUTHDATA        resAuth       Authorization digest for response
-+ *
-+ * This command is only valid on the first boot of a vTPM; on any subsequent
-+ * boot, the command returns TPM_DISABLED_CMD. It is intended to be used to
-+ * provide evidence of proper platform configuration to the verifier/CA which is
-+ * responsible for the creation of the vTPM's endorsement credential, which will
-+ * be used on subsequent boots to certify AIKs via the usual Privacy CA protocol.
-+ *
-+ * The values of the virtual TPM's PCRs are not included in the response.
-+ * The signature is a standard TPM_Quote response from the physical TPM; its
-+ * externalData is the SHA1 hash of the following structure:
-+ *   TPM_PUBKEY          pubEK         The vTPM's public EK
-+ *   TPM_NONCE           externData    From input to the deep quote
-+ *
-+ * This structure was chosen to match the return of TPM_ReadPubek
-+ */
-+#define TPM_ORD_ParentSignEK                    (TPM_VENDOR_COMMAND | TPM_ORD_ReadPubek)
-+
- /*
-  * TCS Ordinals ([TPM_Part2], Section 17.1)
-  *
diff --git a/stubdom/vtpm/Makefile b/stubdom/vtpm/Makefile
deleted file mode 100644 (file)
index 316794c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright (c) 2010-2012 United States Government, as represented by
-# the Secretary of Defense.  All rights reserved.
-#
-# THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
-# ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
-# INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
-# FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
-# DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
-# SOFTWARE.
-#
-
-XEN_ROOT=../..
-
-TARGET=vtpm.a
-OBJS=vtpm.o vtpm_cmd.o vtpmblk.o vtpm_pcrs.o
-
-
-CPPFLAGS+=-I../tpm_emulator-$(XEN_TARGET_ARCH)/build
-CPPFLAGS+=-I../tpm_emulator-$(XEN_TARGET_ARCH)/tpm
-CPPFLAGS+=-I../tpm_emulator-$(XEN_TARGET_ARCH)/crypto
-CPPFLAGS+=-I../tpm_emulator-$(XEN_TARGET_ARCH)
-
-$(TARGET): $(OBJS)
-       ar -cr $@ $(OBJS)
-
-$(OBJS): vtpm_manager.h
-
-vtpm_manager.h:
-       ln -s ../vtpmmgr/vtpm_manager.h vtpm_manager.h
-
-clean:
-       rm -f $(TARGET) $(OBJS) vtpm_manager.h
-
-.PHONY: clean
diff --git a/stubdom/vtpm/minios.cfg b/stubdom/vtpm/minios.cfg
deleted file mode 100644 (file)
index 31652ee..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-CONFIG_TPMFRONT=y
-CONFIG_TPM_TIS=n
-CONFIG_TPMBACK=y
-CONFIG_START_NETWORK=n
-CONFIG_TEST=n
-CONFIG_PCIFRONT=n
-CONFIG_BLKFRONT=y
-CONFIG_NETFRONT=n
-CONFIG_FBFRONT=n
-CONFIG_KBDFRONT=n
-CONFIG_CONSFRONT=n
-CONFIG_XENBUS=y
-CONFIG_LWIP=n
-CONFIG_XC=n
diff --git a/stubdom/vtpm/vtpm.c b/stubdom/vtpm/vtpm.c
deleted file mode 100644 (file)
index 61982c2..0000000
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <syslog.h>
-#include <stdbool.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <xen/xen.h>
-#include <tpmback.h>
-#include <tpmfront.h>
-
-#include <polarssl/entropy.h>
-#include <polarssl/ctr_drbg.h>
-
-#include "tpm/tpm_emulator_extern.h"
-#include "tpm/tpm_marshalling.h"
-#include "vtpm.h"
-#include "vtpm_cmd.h"
-#include "vtpm_pcrs.h"
-#include "vtpmblk.h"
-#include "vtpm_manager.h"
-
-#define TPM_LOG_INFO LOG_INFO
-#define TPM_LOG_ERROR LOG_ERR
-#define TPM_LOG_DEBUG LOG_DEBUG
-
-/* Global commandline options - default values */
-struct Opt_args opt_args = {
-   .startup = ST_CLEAR,
-   .loglevel = TPM_LOG_INFO,
-   .hwinitpcrs = VTPM_PCRNONE,
-   .tpmconf = 0,
-   .enable_maint_cmds = false,
-};
-
-static uint32_t badords[32];
-static unsigned int n_badords = 0;
-
-entropy_context entropy;
-ctr_drbg_context ctr_drbg;
-
-struct tpmfront_dev* tpmfront_dev;
-
-void vtpm_get_extern_random_bytes(void *buf, size_t nbytes)
-{
-   ctr_drbg_random(&ctr_drbg, buf, nbytes);
-}
-
-int vtpm_read_from_file(uint8_t **data, size_t *data_length) {
-   return read_vtpmblk(tpmfront_dev, data, data_length);
-}
-
-int vtpm_write_to_file(uint8_t *data, size_t data_length) {
-   return write_vtpmblk(tpmfront_dev, data, data_length);
-}
-
-int vtpm_extern_init_fake(void) {
-   return 0;
-}
-
-void vtpm_extern_release_fake(void) {
-}
-
-
-void vtpm_log(int priority, const char *fmt, ...)
-{
-   if(opt_args.loglevel >= priority) {
-      va_list v;
-      va_start(v, fmt);
-      vprintf(fmt, v);
-      va_end(v);
-   }
-}
-
-static uint64_t vtpm_get_ticks(void)
-{
-  static uint64_t old_t = 0;
-  uint64_t new_t, res_t;
-  struct timeval tv;
-  gettimeofday(&tv, NULL);
-  new_t = (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
-  res_t = (old_t > 0) ? new_t - old_t : 0;
-  old_t = new_t;
-  return res_t;
-}
-
-
-static int tpm_entropy_source(void* dummy, unsigned char* data, size_t len, size_t* olen) {
-   UINT32 sz = len;
-   TPM_RESULT rc = VTPM_GetRandom(tpmfront_dev, data, &sz);
-   *olen = sz;
-   return rc == TPM_SUCCESS ? 0 : POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
-}
-
-int init_random(void) {
-   /* Initialize the rng */
-   entropy_init(&entropy);
-   entropy_add_source(&entropy, tpm_entropy_source, NULL, 0);
-   entropy_gather(&entropy);
-   ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, NULL, 0);
-   ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_OFF );
-
-   return 0;
-}
-
-int check_passthru(tpmcmd_t* tpmcmd) {
-   TPM_TAG tag;
-   UINT32 len = 10;
-   BYTE* ptr;
-   size_t size;
-
-   if(tpmcmd->req_len < 10) {
-      return false;
-   }
-
-   ptr = tpmcmd->req;
-   tpm_unmarshal_UINT16(&ptr, &len, &tag);
-
-   if (tag == VTPM_TAG_REQ2) {
-      info("VTPM passthru: %d bytes", (int)tpmcmd->req_len);
-      tpmfront_cmd(tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size);
-      tpmcmd->resp_len = size;
-      info("VTPM passthru return: %d bytes", (int)size);
-      return true;
-   }
-
-   if (tag == VTPM_TAG_REQ) {
-      info("VTPM pTPM-cmd: %d bytes", (int)tpmcmd->req_len);
-      ptr = tpmcmd->req;
-      tpm_marshal_UINT16(&ptr, &len, TPM_TAG_RQU_COMMAND);
-      tpmfront_cmd(tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size);
-      tpmcmd->resp_len = size;
-      info("VTPM pTPM-cmd return: %d bytes", (int)size);
-      return true;
-   }
-
-   return false;
-}
-
-int check_ordinal(tpmcmd_t* tpmcmd) {
-   TPM_COMMAND_CODE ord;
-   UINT32 len = 4;
-   BYTE* ptr;
-   unsigned int i;
-
-   if(tpmcmd->req_len < 10) {
-      return true;
-   }
-
-   ptr = tpmcmd->req + 6;
-   tpm_unmarshal_UINT32(&ptr, &len, &ord);
-
-   for(i = 0; i < n_badords; ++i) {
-      if(ord == badords[i]) {
-         error("Disabled command ordinal (%" PRIu32") requested!\n");
-         return false;
-      }
-   }
-   return true;
-}
-
-struct locality_item {
-       char* lbl;
-       uint8_t mask[32];
-};
-#define MAX_CLIENT_LOCALITIES 16
-static struct locality_item client_locality[MAX_CLIENT_LOCALITIES];
-static int nr_client_localities = 0;
-
-static void *generate_locality_mask(domid_t domid, unsigned int handle)
-{
-   char label[512];
-   int i;
-   if (tpmback_get_peercontext(domid, handle, label, sizeof(label)))
-      BUG();
-   for(i=0; i < nr_client_localities; i++) {
-      if (!strcmp(client_locality[i].lbl, label))
-         goto found;
-      if (client_locality[i].lbl[0] == '*') {
-        char * f = strstr(label, 1 + client_locality[i].lbl);
-        if (!strcmp(f, 1 + client_locality[i].lbl))
-           goto found;
-      }
-   }
-   return NULL;
- found:
-   tpmback_set_opaque(domid, handle, client_locality[i].mask);
-   return client_locality[i].mask;
-}
-
-static void main_loop(void) {
-   tpmcmd_t* tpmcmd = NULL;
-   int res = -1;
-
-   info("VTPM Initializing\n");
-
-   /* Set required tpm config args */
-   opt_args.tpmconf |= TPM_CONF_STRONG_PERSISTENCE;
-   opt_args.tpmconf &= ~TPM_CONF_USE_INTERNAL_PRNG;
-   opt_args.tpmconf |= TPM_CONF_GENERATE_EK;
-   opt_args.tpmconf |= TPM_CONF_GENERATE_SEED_DAA;
-
-   /* Initialize the emulator */
-   tpm_emulator_init(opt_args.startup, opt_args.tpmconf);
-
-   /* Initialize any requested PCRs with hardware TPM values */
-   if(vtpm_initialize_hw_pcrs(tpmfront_dev, opt_args.hwinitpcrs) != TPM_SUCCESS) {
-      error("Failed to initialize PCRs with hardware TPM values");
-      goto abort_postpcrs;
-   }
-
-   tpmcmd = tpmback_req_any();
-   while(tpmcmd) {
-      /* Handle the request */
-      if(tpmcmd->req_len) {
-        uint8_t* locality_mask = tpmcmd->opaque;
-        uint8_t locality_bit = (1 << (tpmcmd->locality & 7));
-        int locality_byte = tpmcmd->locality >> 3;
-        tpmcmd->resp = NULL;
-        tpmcmd->resp_len = 0;
-
-        if (nr_client_localities && !locality_mask)
-           locality_mask = generate_locality_mask(tpmcmd->domid, tpmcmd->handle);
-        if (nr_client_localities && !locality_mask) {
-            error("Unknown client label in tpm_handle_command");
-            create_error_response(tpmcmd, TPM_FAIL);
-        }
-        else if (nr_client_localities && !(locality_mask[locality_byte] & locality_bit)) {
-            error("Invalid locality (%d) for client in tpm_handle_command", tpmcmd->locality);
-            create_error_response(tpmcmd, TPM_FAIL);
-        }
-         /* Check for TPM Manager passthrough command */
-         else if(check_passthru(tpmcmd)) {
-        }
-         /* Check for disabled ordinals */
-         else if(!check_ordinal(tpmcmd)) {
-            create_error_response(tpmcmd, TPM_BAD_ORDINAL);
-         }
-         /* If not disabled, do the command */
-         else {
-            if((res = tpm_handle_command(tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &tpmcmd->resp_len, tpmcmd->locality)) != 0) {
-               error("tpm_handle_command() failed");
-               create_error_response(tpmcmd, TPM_FAIL);
-            }
-         }
-      }
-
-      /* Send the response */
-      tpmback_resp(tpmcmd);
-
-      /* Wait for the next request */
-      tpmcmd = tpmback_req_any();
-
-   }
-
-abort_postpcrs:
-   info("VTPM Shutting down");
-
-   tpm_emulator_shutdown();
-}
-
-int parse_cmd_line(int argc, char** argv)
-{
-   char sval[25];
-   char* logstr = NULL;
-   /* Parse the command strings */
-   for(unsigned int i = 1; i < argc; ++i) {
-      if (sscanf(argv[i], "loglevel=%25s", sval) == 1){
-        if (!strcmp(sval, "debug")) {
-           opt_args.loglevel = TPM_LOG_DEBUG;
-           logstr = "debug";
-        }
-        else if (!strcmp(sval, "info")) {
-           logstr = "info";
-           opt_args.loglevel = TPM_LOG_INFO;
-        }
-        else if (!strcmp(sval, "error")) {
-           logstr = "error";
-           opt_args.loglevel = TPM_LOG_ERROR;
-        }
-      }
-      else if (!strcmp(argv[i], "clear")) {
-        opt_args.startup = ST_CLEAR;
-      }
-      else if (!strcmp(argv[i], "save")) {
-        opt_args.startup = ST_SAVE;
-      }
-      else if (!strcmp(argv[i], "deactivated")) {
-        opt_args.startup = ST_DEACTIVATED;
-      }
-      else if (!strncmp(argv[i], "maintcmds=", 10)) {
-         if(!strcmp(argv[i] + 10, "1")) {
-            opt_args.enable_maint_cmds = true;
-         } else if(!strcmp(argv[i] + 10, "0")) {
-            opt_args.enable_maint_cmds = false;
-         }
-      }
-      else if(!strncmp(argv[i], "hwinitpcr=", 10)) {
-         char *pch = argv[i] + 10;
-         unsigned int v1, v2;
-         pch = strtok(pch, ",");
-         while(pch != NULL) {
-            if(!strcmp(pch, "all")) {
-               //Set all
-               opt_args.hwinitpcrs = VTPM_PCRALL;
-            } else if(!strcmp(pch, "none")) {
-               //Set none
-               opt_args.hwinitpcrs = VTPM_PCRNONE;
-            } else if(sscanf(pch, "%u", &v1) == 1) {
-               //Set one
-               if(v1 >= TPM_NUM_PCR) {
-                  error("hwinitpcr error: Invalid PCR index %u", v1);
-                  return -1;
-               }
-               opt_args.hwinitpcrs |= (1 << v1);
-            } else if(sscanf(pch, "%u-%u", &v1, &v2) == 2) {
-               //Set range
-               if(v1 >= TPM_NUM_PCR) {
-                  error("hwinitpcr error: Invalid PCR index %u", v1);
-                  return -1;
-               }
-               if(v2 >= TPM_NUM_PCR) {
-                  error("hwinitpcr error: Invalid PCR index %u", v1);
-                  return -1;
-               }
-               if(v2 < v1) {
-                  unsigned tp = v1;
-                  v1 = v2;
-                  v2 = tp;
-               }
-               for(unsigned int i = v1; i <= v2; ++i) {
-                  opt_args.hwinitpcrs |= (1 << i);
-               }
-            } else {
-               error("hwintipcr error: Invalid PCR specification : %s", pch);
-               return -1;
-            }
-            pch = strtok(NULL, ",");
-         }
-      }
-      else if(!strncmp(argv[i], "locality=", 9)) {
-        char *lbl = argv[i] + 9;
-       char *pch = strchr(lbl, '=');
-       uint8_t* locality_mask = client_locality[nr_client_localities].mask;
-       if (pch == NULL) {
-                error("Invalid locality specification: %s", lbl);
-                return -1;
-       }
-       if (nr_client_localities == MAX_CLIENT_LOCALITIES) {
-               error("Too many locality specifications");
-               return -1;
-       }
-       client_locality[nr_client_localities].lbl = lbl;
-       memset(locality_mask, 0, 32);
-       nr_client_localities++;
-       *pch = 0;
-       pch = strtok(pch + 1, ",");
-       while (pch != NULL) {
-               unsigned int loc;
-               if (sscanf(pch, "%u", &loc) == 1 && loc < 256) {
-                       uint8_t locality_bit = (1 << (loc & 7));
-                       int locality_byte = loc >> 3;
-                       locality_mask[locality_byte] |= locality_bit;
-               } else {
-                       error("Invalid locality item: %s", pch);
-                       return -1;
-               }
-               pch = strtok(NULL, ",");
-       }
-      }
-      else {
-        error("Invalid command line option `%s'", argv[i]);
-      }
-
-   }
-
-   /* Check Errors and print results */
-   switch(opt_args.startup) {
-      case ST_CLEAR:
-        info("Startup mode is `clear'");
-        break;
-      case ST_SAVE:
-        info("Startup mode is `save'");
-        break;
-      case ST_DEACTIVATED:
-        info("Startup mode is `deactivated'");
-        break;
-      default:
-        error("Invalid startup mode %d", opt_args.startup);
-        return -1;
-   }
-
-   if(opt_args.hwinitpcrs & (VTPM_PCRALL))
-   {
-      char pcrstr[1024];
-      char* ptr = pcrstr;
-
-      pcrstr[0] = '\0';
-      info("The following PCRs will be initialized with values from the hardware TPM:");
-      for(unsigned int i = 0; i < TPM_NUM_PCR; ++i) {
-         if(opt_args.hwinitpcrs & (1 << i)) {
-            ptr += sprintf(ptr, "%u, ", i);
-         }
-      }
-      /* get rid of the last comma if any numbers were printed */
-      *(ptr -2) = '\0';
-
-      info("\t%s", pcrstr);
-   } else {
-      info("All PCRs initialized to default values");
-   }
-
-   if(!opt_args.enable_maint_cmds) {
-      info("TPM Maintenance Commands disabled");
-      badords[n_badords++] = TPM_ORD_CreateMaintenanceArchive;
-      badords[n_badords++] = TPM_ORD_LoadMaintenanceArchive;
-      badords[n_badords++] = TPM_ORD_KillMaintenanceFeature;
-      badords[n_badords++] = TPM_ORD_LoadManuMaintPub;
-      badords[n_badords++] = TPM_ORD_ReadManuMaintPub;
-   } else {
-      info("TPM Maintenance Commands enabled");
-   }
-
-   info("Log level set to %s", logstr);
-
-   return 0;
-}
-
-void cleanup_opt_args(void) {
-}
-
-int main(int argc, char **argv)
-{
-   //FIXME: initializing blkfront without this sleep causes the domain to crash on boot
-   sleep(2);
-
-   /* Setup extern function pointers */
-   tpm_extern_init = vtpm_extern_init_fake;
-   tpm_extern_release = vtpm_extern_release_fake;
-   tpm_malloc = malloc;
-   tpm_free = free;
-   tpm_log = vtpm_log;
-   tpm_get_ticks = vtpm_get_ticks;
-   tpm_get_extern_random_bytes = vtpm_get_extern_random_bytes;
-   tpm_write_to_storage = vtpm_write_to_file;
-   tpm_read_from_storage = vtpm_read_from_file;
-
-   info("starting TPM Emulator (1.2.%d.%d-%d)", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
-   if(parse_cmd_line(argc, argv)) {
-      error("Error parsing commandline\n");
-      return -1;
-   }
-
-   /* Initialize devices */
-   init_tpmback(NULL, NULL);
-   if((tpmfront_dev = init_tpmfront(NULL)) == NULL) {
-      error("Unable to initialize tpmfront device");
-      goto abort_posttpmfront;
-   }
-
-   /* Seed the RNG with entropy from hardware TPM */
-   if(init_random()) {
-      error("Unable to initialize RNG");
-      goto abort_postrng;
-   }
-
-   /* Initialize blkfront device */
-   if(init_vtpmblk(tpmfront_dev)) {
-      error("Unable to initialize Blkfront persistent storage");
-      goto abort_postvtpmblk;
-   }
-
-   /* Run main loop */
-   main_loop();
-
-   /* Shutdown blkfront */
-   shutdown_vtpmblk();
-abort_postvtpmblk:
-abort_postrng:
-
-   /* Close devices */
-   shutdown_tpmfront(tpmfront_dev);
-abort_posttpmfront:
-   shutdown_tpmback();
-
-   cleanup_opt_args();
-
-   return 0;
-}
diff --git a/stubdom/vtpm/vtpm.h b/stubdom/vtpm/vtpm.h
deleted file mode 100644 (file)
index 5919e44..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#ifndef VTPM_H
-#define VTPM_H
-
-#include <stdbool.h>
-
-/* For testing */
-#define VERS_CMD "\x00\xC1\x00\x00\x00\x16\x00\x00\x00\x65\x00\x00\x00\x05\x00\x00\x00\x04\x00\x00\x01\x03"
-#define VERS_CMD_LEN 22
-
-/* Global commandline options */
-struct Opt_args {
-   enum StartUp {
-      ST_CLEAR = 1,
-      ST_SAVE = 2,
-      ST_DEACTIVATED = 3
-   } startup;
-   unsigned long hwinitpcrs;
-   int loglevel;
-   uint32_t tpmconf;
-   bool enable_maint_cmds;
-};
-extern struct Opt_args opt_args;
-
-#endif
diff --git a/stubdom/vtpm/vtpm_cmd.c b/stubdom/vtpm/vtpm_cmd.c
deleted file mode 100644 (file)
index eec37df..0000000
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#include <types.h>
-#include <xen/xen.h>
-#include <mm.h>
-#include <gnttab.h>
-#include "tpm/tpm_marshalling.h"
-#include "vtpm_manager.h"
-#include "vtpm_cmd.h"
-#include <tpmback.h>
-
-#define TRYFAILGOTO(C) \
-   if((C)) { \
-      status = TPM_FAIL; \
-      goto abort_egress; \
-   }
-#define TRYFAILGOTOMSG(C, msg) \
-   if((C)) { \
-      status = TPM_FAIL; \
-      error(msg); \
-      goto abort_egress; \
-   }
-#define CHECKSTATUSGOTO(ret, fname) \
-   if((ret) != TPM_SUCCESS) { \
-      error("%s failed with error code (%lu)", fname, (unsigned long) ret); \
-      status = ord; \
-      goto abort_egress; \
-   }
-
-#define ERR_MALFORMED "Malformed response from backend"
-#define ERR_TPMFRONT "Error sending command through frontend device"
-
-struct shpage {
-   void* page;
-   grant_ref_t grantref;
-};
-
-typedef struct shpage shpage_t;
-
-static inline int pack_header(uint8_t** bptr, UINT32* len, TPM_TAG tag, UINT32 size, TPM_COMMAND_CODE ord)
-{
-   return *bptr == NULL ||
-        tpm_marshal_UINT16(bptr, len, tag) ||
-        tpm_marshal_UINT32(bptr, len, size) ||
-        tpm_marshal_UINT32(bptr, len, ord);
-}
-
-static inline int unpack_header(uint8_t** bptr, UINT32* len, TPM_TAG* tag, UINT32* size, TPM_COMMAND_CODE* ord)
-{
-   return *bptr == NULL ||
-        tpm_unmarshal_UINT16(bptr, len, tag) ||
-        tpm_unmarshal_UINT32(bptr, len, size) ||
-        tpm_unmarshal_UINT32(bptr, len, ord);
-}
-
-int create_error_response(tpmcmd_t* tpmcmd, TPM_RESULT errorcode)
-{
-   TPM_TAG tag;
-   UINT32 len = tpmcmd->req_len;
-   uint8_t* respptr;
-   uint8_t* cmdptr = tpmcmd->req;
-
-   if(!tpm_unmarshal_UINT16(&cmdptr, &len, &tag)) {
-      switch (tag) {
-         case TPM_TAG_RQU_COMMAND:
-            tag = TPM_TAG_RSP_COMMAND;
-            break;
-         case TPM_TAG_RQU_AUTH1_COMMAND:
-            tag = TPM_TAG_RQU_AUTH2_COMMAND;
-            break;
-         case TPM_TAG_RQU_AUTH2_COMMAND:
-            tag = TPM_TAG_RQU_AUTH2_COMMAND;
-            break;
-      }
-   } else {
-      tag = TPM_TAG_RSP_COMMAND;
-   }
-
-   tpmcmd->resp_len = len = 10;
-   tpmcmd->resp = respptr = tpm_malloc(tpmcmd->resp_len);
-
-   return pack_header(&respptr, &len, tag, len, errorcode);
-}
-
-TPM_RESULT VTPM_GetRandom(struct tpmfront_dev* tpmfront_dev, BYTE* bytes, UINT32 *numbytes) {
-   TPM_RESULT status = TPM_SUCCESS;
-   uint8_t* cmdbuf, *resp, *bptr;
-   size_t resplen = 0;
-   UINT32 len;
-
-   /*Ask the real tpm for random bytes for the seed */
-   TPM_TAG tag = TPM_TAG_RQU_COMMAND;
-   UINT32 size;
-   TPM_COMMAND_CODE ord = TPM_ORD_GetRandom;
-   len = size = sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE) + sizeof(UINT32);
-
-   /*Create the raw tpm command */
-   bptr = cmdbuf = malloc(size);
-   TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord));
-   TRYFAILGOTO(tpm_marshal_UINT32(&bptr, &len, *numbytes));
-
-   /* Send cmd, wait for response */
-   TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &resplen),
-      ERR_TPMFRONT);
-
-   bptr = resp; len = resplen;
-   TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MALFORMED);
-
-   //Check return status of command
-   CHECKSTATUSGOTO(ord, "TPM_GetRandom()");
-
-   // Get the number of random bytes in the response
-   TRYFAILGOTOMSG(tpm_unmarshal_UINT32(&bptr, &len, &size), ERR_MALFORMED);
-   *numbytes = size;
-
-   //Get the random bytes out, tpm may give us less bytes than what we wanrt
-   TRYFAILGOTOMSG(tpm_unmarshal_BYTE_ARRAY(&bptr, &len, bytes, *numbytes), ERR_MALFORMED);
-
-   goto egress;
-abort_egress:
-egress:
-   free(cmdbuf);
-   return status;
-
-}
-
-TPM_RESULT VTPM_LoadHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t** data, size_t* data_length)
-{
-   TPM_RESULT status = TPM_SUCCESS;
-   uint8_t* bptr, *resp;
-   uint8_t* cmdbuf = NULL;
-   size_t resplen = 0;
-   UINT32 len;
-
-   TPM_TAG tag = VTPM_TAG_REQ;
-   UINT32 size;
-   TPM_COMMAND_CODE ord = VTPM_ORD_LOADHASHKEY;
-
-   /*Create the command*/
-   len = size = VTPM_COMMAND_HEADER_SIZE;
-   bptr = cmdbuf = malloc(size);
-   TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord));
-
-   /* Send the command to vtpm_manager */
-   info("Requesting Encryption key from backend");
-   TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &resplen), ERR_TPMFRONT);
-
-   /* Unpack response header */
-   bptr = resp;
-   len = resplen;
-   TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MALFORMED);
-
-   /* Check return code */
-   CHECKSTATUSGOTO(ord, "VTPM_LoadHashKey()");
-
-   /* Get the size of the key */
-   *data_length = size - VTPM_COMMAND_HEADER_SIZE;
-
-   /* Copy the key bits */
-   *data = malloc(*data_length);
-   memcpy(*data, bptr, *data_length);
-
-   goto egress;
-abort_egress:
-   error("VTPM_LoadHashKey failed");
-egress:
-   free(cmdbuf);
-   return status;
-}
-
-TPM_RESULT VTPM_SaveHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t* data, size_t data_length)
-{
-   TPM_RESULT status = TPM_SUCCESS;
-   uint8_t* bptr, *resp;
-   uint8_t* cmdbuf = NULL;
-   size_t resplen = 0;
-   UINT32 len;
-
-   TPM_TAG tag = VTPM_TAG_REQ;
-   UINT32 size;
-   TPM_COMMAND_CODE ord = VTPM_ORD_SAVEHASHKEY;
-
-   /*Create the command*/
-   len = size = VTPM_COMMAND_HEADER_SIZE + data_length;
-   bptr = cmdbuf = malloc(size);
-   TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord));
-   memcpy(bptr, data, data_length);
-   bptr += data_length;
-
-   /* Send the command to vtpm_manager */
-   info("Sending encryption key to backend");
-   TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &resplen), ERR_TPMFRONT);
-
-   /* Unpack response header */
-   bptr = resp;
-   len = resplen;
-   TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MALFORMED);
-
-   /* Check return code */
-   CHECKSTATUSGOTO(ord, "VTPM_SaveHashKey()");
-
-   goto egress;
-abort_egress:
-   error("VTPM_SaveHashKey failed");
-egress:
-   free(cmdbuf);
-   return status;
-}
-
-extern struct tpmfront_dev* tpmfront_dev;
-TPM_RESULT VTPM_GetParentQuote(TPM_NONCE *data, TPM_PCR_SELECTION *sel,
-                               UINT32 extraInfoFlags, UINT32 *quote_blob_size, BYTE **quote_blob)
-{
-   TPM_RESULT status = TPM_SUCCESS;
-   uint8_t* bptr, *resp;
-   uint8_t* cmdbuf = NULL;
-   size_t resplen = 0;
-   UINT32 len;
-
-   TPM_TAG tag = VTPM_TAG_REQ;
-   UINT32 size;
-   TPM_COMMAND_CODE ord = VTPM_ORD_GET_QUOTE;
-
-   /*Create the command*/
-   len = size = VTPM_COMMAND_HEADER_SIZE + 20 + sizeof_TPM_PCR_SELECTION((*sel)) + 4;
-   bptr = cmdbuf = malloc(size);
-   TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord));
-   TRYFAILGOTO(tpm_marshal_TPM_NONCE(&bptr, &len, data));
-   TRYFAILGOTO(tpm_marshal_TPM_PCR_SELECTION(&bptr, &len, sel));
-   TRYFAILGOTO(tpm_marshal_TPM_DEEP_QUOTE_INFO(&bptr, &len, extraInfoFlags));
-
-   /* Send the command to vtpm_manager */
-   info("Requesting Quote from backend");
-   TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &resplen), ERR_TPMFRONT);
-
-   /* Unpack response header */
-   bptr = resp;
-   len = resplen;
-   TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MALFORMED);
-
-   /* Check return code */
-   CHECKSTATUSGOTO(ord, "VTPM_GetParentQuote()");
-   /* Copy out the value */
-   *quote_blob_size = len;
-   *quote_blob = tpm_malloc(*quote_blob_size);
-   TRYFAILGOTOMSG(tpm_unmarshal_BYTE_ARRAY(&bptr, &len, *quote_blob, *quote_blob_size), ERR_MALFORMED);
-
-   goto egress;
-abort_egress:
-   error("VTPM_GetParentQuote failed");
-egress:
-   free(cmdbuf);
-   return status;
-}
-
-TPM_RESULT VTPM_PCRRead(struct tpmfront_dev* tpmfront_dev, UINT32 pcrIndex, BYTE* outDigest)
-{
-   TPM_RESULT status = TPM_SUCCESS;
-   uint8_t *cmdbuf, *resp, *bptr;
-   size_t resplen = 0;
-   UINT32 len;
-
-   /*Just send a TPM_PCRRead Command to the HW tpm */
-   TPM_TAG tag = TPM_TAG_RQU_COMMAND;
-   UINT32 size;
-   TPM_COMMAND_CODE ord = TPM_ORD_PCRRead;
-   len = size = sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAND_CODE) + sizeof(UINT32);
-
-   /*Create the raw tpm cmd */
-   bptr = cmdbuf = malloc(size);
-   TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord));
-   TRYFAILGOTO(tpm_marshal_UINT32(&bptr, &len, pcrIndex));
-
-   /*Send Cmd wait for response */
-   TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &resplen), ERR_TPMFRONT);
-
-   bptr = resp; len = resplen;
-   TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MALFORMED);
-
-   //Check return status of command
-   CHECKSTATUSGOTO(ord, "TPM_PCRRead");
-
-   //Get the ptr value
-   memcpy(outDigest, bptr, sizeof(TPM_PCRVALUE));
-
-   goto egress;
-abort_egress:
-egress:
-   free(cmdbuf);
-   return status;
-
-}
diff --git a/stubdom/vtpm/vtpm_cmd.h b/stubdom/vtpm/vtpm_cmd.h
deleted file mode 100644 (file)
index b0bfa22..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#ifndef MANAGER_H
-#define MANAGER_H
-
-#include <tpmfront.h>
-#include <tpmback.h>
-#include "tpm/tpm_structures.h"
-
-/* Create a command response error header */
-int create_error_response(tpmcmd_t* tpmcmd, TPM_RESULT errorcode);
-/* Request random bytes from hardware tpm, returns 0 on success */
-TPM_RESULT VTPM_GetRandom(struct tpmfront_dev* tpmfront_dev, BYTE* bytes, UINT32* numbytes);
-/* Retreive 256 bit AES encryption key from manager */
-TPM_RESULT VTPM_LoadHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t** data, size_t* data_length);
-/* Manager securely saves our 256 bit AES encryption key */
-TPM_RESULT VTPM_SaveHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t* data, size_t data_length);
-/* Send a TPM_PCRRead command passthrough the manager to the hw tpm */
-TPM_RESULT VTPM_PCRRead(struct tpmfront_dev* tpmfront_dev, UINT32 pcrIndex, BYTE* outDigest);
-
-#endif
diff --git a/stubdom/vtpm/vtpm_pcrs.c b/stubdom/vtpm/vtpm_pcrs.c
deleted file mode 100644 (file)
index 22a6cef..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#include "vtpm_pcrs.h"
-#include "vtpm_cmd.h"
-#include "tpm/tpm_data.h"
-
-#define PCR_VALUE      tpmData.permanent.data.pcrValue
-
-static int write_pcr_direct(unsigned int pcrIndex, uint8_t* val) {
-   if(pcrIndex > TPM_NUM_PCR) {
-      return TPM_BADINDEX;
-   }
-   memcpy(&PCR_VALUE[pcrIndex], val, sizeof(TPM_PCRVALUE));
-   return TPM_SUCCESS;
-}
-
-TPM_RESULT vtpm_initialize_hw_pcrs(struct tpmfront_dev* tpmfront_dev, unsigned long pcrs)
-{
-   TPM_RESULT rc = TPM_SUCCESS;
-   uint8_t digest[sizeof(TPM_PCRVALUE)];
-
-   for(unsigned int i = 0; i < TPM_NUM_PCR; ++i) {
-      if(pcrs & 1 << i) {
-         if((rc = VTPM_PCRRead(tpmfront_dev, i, digest)) != TPM_SUCCESS) {
-            error("TPM_PCRRead failed with error : %d", rc);
-            return rc;
-         }
-         write_pcr_direct(i, digest);
-      }
-   }
-
-   return rc;
-}
diff --git a/stubdom/vtpm/vtpm_pcrs.h b/stubdom/vtpm/vtpm_pcrs.h
deleted file mode 100644 (file)
index 11835f9..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#ifndef VTPM_PCRS_H
-#define VTPM_PCRS_H
-
-#include "tpm/tpm_structures.h"
-
-#define VTPM_PCR0 1
-#define VTPM_PCR1 1 << 1
-#define VTPM_PCR2 1 << 2
-#define VTPM_PCR3 1 << 3
-#define VTPM_PCR4 1 << 4
-#define VTPM_PCR5 1 << 5
-#define VTPM_PCR6 1 << 6
-#define VTPM_PCR7 1 << 7
-#define VTPM_PCR8 1 << 8
-#define VTPM_PCR9 1 << 9
-#define VTPM_PCR10 1 << 10
-#define VTPM_PCR11 1 << 11
-#define VTPM_PCR12 1 << 12
-#define VTPM_PCR13 1 << 13
-#define VTPM_PCR14 1 << 14
-#define VTPM_PCR15 1 << 15
-#define VTPM_PCR16 1 << 16
-#define VTPM_PCR17 1 << 17
-#define VTPM_PCR18 1 << 18
-#define VTPM_PCR19 1 << 19
-#define VTPM_PCR20 1 << 20
-#define VTPM_PCR21 1 << 21
-#define VTPM_PCR22 1 << 22
-#define VTPM_PCR23 1 << 23
-
-#define VTPM_PCRALL (1 << TPM_NUM_PCR) - 1
-#define VTPM_PCRNONE 0
-
-#define VTPM_NUMPCRS 24
-
-struct tpmfront_dev;
-
-TPM_RESULT vtpm_initialize_hw_pcrs(struct tpmfront_dev* tpmfront_dev, unsigned long pcrs);
-
-
-#endif
diff --git a/stubdom/vtpm/vtpmblk.c b/stubdom/vtpm/vtpmblk.c
deleted file mode 100644 (file)
index fe529ab..0000000
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#include <mini-os/byteorder.h>
-#include "vtpmblk.h"
-#include "tpm/tpm_marshalling.h"
-#include "vtpm_cmd.h"
-#include "polarssl/aes.h"
-#include "polarssl/sha1.h"
-#include <blkfront.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-
-/*Encryption key and block sizes */
-#define BLKSZ 16
-
-static struct blkfront_dev* blkdev = NULL;
-static int blkfront_fd = -1;
-static uint64_t slot_size = 0;
-
-int init_vtpmblk(struct tpmfront_dev* tpmfront_dev)
-{
-   struct blkfront_info blkinfo;
-   info("Initializing persistent NVM storage\n");
-
-   if((blkdev = init_blkfront(NULL, &blkinfo)) == NULL) {
-      error("BLKIO: ERROR Unable to initialize blkfront");
-      return -1;
-   }
-   if (blkinfo.info & VDISK_READONLY || blkinfo.mode != O_RDWR) {
-      error("BLKIO: ERROR block device is read only!");
-      goto error;
-   }
-   if((blkfront_fd = blkfront_open(blkdev)) == -1) {
-      error("Unable to open blkfront file descriptor!");
-      goto error;
-   }
-
-   slot_size = blkinfo.sectors * blkinfo.sector_size / 2;
-
-   return 0;
-error:
-   shutdown_blkfront(blkdev);
-   blkdev = NULL;
-   return -1;
-}
-
-void shutdown_vtpmblk(void)
-{
-   close(blkfront_fd);
-   blkfront_fd = -1;
-   blkdev = NULL;
-}
-
-static int write_vtpmblk_raw(uint8_t *data, size_t data_length, int slot)
-{
-   int rc;
-   uint32_t lenbuf;
-   debug("Begin Write data=%p len=%u slot=%u ssize=%u", data, data_length, slot, slot_size);
-
-   if (data_length > slot_size - 4) {
-      error("vtpm data cannot fit in data slot (%d/%d).", data_length, slot_size - 4);
-      return -1;
-   }
-
-   lenbuf = cpu_to_be32((uint32_t)data_length);
-
-   lseek(blkfront_fd, slot * slot_size, SEEK_SET);
-   if((rc = write(blkfront_fd, (uint8_t*)&lenbuf, 4)) != 4) {
-      error("write(length) failed! error was %s", strerror(errno));
-      return -1;
-   }
-   if((rc = write(blkfront_fd, data, data_length)) != data_length) {
-      error("write(data) failed! error was %s", strerror(errno));
-      return -1;
-   }
-
-   info("Wrote %u bytes to NVM persistent storage", data_length);
-
-   return 0;
-}
-
-static int read_vtpmblk_raw(uint8_t **data, size_t *data_length, int slot)
-{
-   int rc;
-   uint32_t lenbuf;
-
-   lseek(blkfront_fd, slot * slot_size, SEEK_SET);
-   if(( rc = read(blkfront_fd, (uint8_t*)&lenbuf, 4)) != 4) {
-      error("read(length) failed! error was %s", strerror(errno));
-      return -1;
-   }
-   *data_length = (size_t) cpu_to_be32(lenbuf);
-   if(*data_length == 0) {
-      error("read 0 data_length for NVM");
-      return -1;
-   }
-   if(*data_length > slot_size - 4) {
-      error("read invalid data_length for NVM");
-      return -1;
-   }
-
-   *data = tpm_malloc(*data_length);
-   if((rc = read(blkfront_fd, *data, *data_length)) != *data_length) {
-      error("read(data) failed! error was %s", strerror(errno));
-      return -1;
-   }
-
-   info("Read %u bytes from NVM persistent storage (slot %d)", *data_length, slot);
-   return 0;
-}
-
-int encrypt_vtpmblk(uint8_t* clear, size_t clear_len, uint8_t** cipher, size_t* cipher_len, uint8_t* symkey)
-{
-   int rc = 0;
-   uint8_t iv[BLKSZ];
-   aes_context aes_ctx;
-   UINT32 temp;
-   int mod;
-
-   uint8_t* clbuf = NULL;
-
-   uint8_t* ivptr;
-   int ivlen;
-
-   uint8_t* cptr;      //Cipher block pointer
-   int clen;   //Cipher block length
-
-   /*Create a new 256 bit encryption key */
-   if(symkey == NULL) {
-      rc = -1;
-      goto abort_egress;
-   }
-   tpm_get_extern_random_bytes(symkey, NVMKEYSZ);
-
-   /*Setup initialization vector - random bits and then 4 bytes clear text size at the end*/
-   temp = sizeof(UINT32);
-   ivlen = BLKSZ - temp;
-   tpm_get_extern_random_bytes(iv, ivlen);
-   ivptr = iv + ivlen;
-   tpm_marshal_UINT32(&ivptr, &temp, (UINT32) clear_len);
-
-   /*The clear text needs to be padded out to a multiple of BLKSZ */
-   mod = clear_len % BLKSZ;
-   clen = mod ? clear_len + BLKSZ - mod : clear_len;
-   clbuf = malloc(clen);
-   if (clbuf == NULL) {
-      rc = -1;
-      goto abort_egress;
-   }
-   memcpy(clbuf, clear, clear_len);
-   /* zero out the padding bits - FIXME: better / more secure way to handle these? */
-   if(clen - clear_len) {
-      memset(clbuf + clear_len, 0, clen - clear_len);
-   }
-
-   /* Setup the ciphertext buffer */
-   *cipher_len = BLKSZ + clen;         /*iv + ciphertext */
-   cptr = *cipher = malloc(*cipher_len);
-   if (*cipher == NULL) {
-      rc = -1;
-      goto abort_egress;
-   }
-
-   /* Copy the IV to cipher text blob*/
-   memcpy(cptr, iv, BLKSZ);
-   cptr += BLKSZ;
-
-   /* Setup encryption */
-   aes_setkey_enc(&aes_ctx, symkey, 256);
-
-   /* Do encryption now */
-   aes_crypt_cbc(&aes_ctx, AES_ENCRYPT, clen, iv, clbuf, cptr);
-
-   goto egress;
-abort_egress:
-egress:
-   free(clbuf);
-   return rc;
-}
-int decrypt_vtpmblk(uint8_t* cipher, size_t cipher_len, uint8_t** clear, size_t* clear_len, uint8_t* symkey)
-{
-   int rc = 0;
-   uint8_t iv[BLKSZ];
-   uint8_t* ivptr;
-   UINT32 u32, temp;
-   aes_context aes_ctx;
-
-   uint8_t* cptr = cipher;     //cipher block pointer
-   int clen = cipher_len;      //cipher block length
-
-   /* Pull out the initialization vector */
-   memcpy(iv, cipher, BLKSZ);
-   cptr += BLKSZ;
-   clen -= BLKSZ;
-
-   /* Setup the clear text buffer */
-   if((*clear = malloc(clen)) == NULL) {
-      rc = -1;
-      goto abort_egress;
-   }
-
-   /* Get the length of clear text from last 4 bytes of iv */
-   temp = sizeof(UINT32);
-   ivptr = iv + BLKSZ - temp;
-   tpm_unmarshal_UINT32(&ivptr, &temp, &u32);
-   *clear_len = u32;
-
-   /* Setup decryption */
-   aes_setkey_dec(&aes_ctx, symkey, 256);
-
-   /* Do decryption now */
-   if ((clen % BLKSZ) != 0) {
-      error("Decryption Error: Cipher block size was not a multiple of %u", BLKSZ);
-      rc = -1;
-      goto abort_egress;
-   }
-   aes_crypt_cbc(&aes_ctx, AES_DECRYPT, clen, iv, cptr, *clear);
-
-   goto egress;
-abort_egress:
-egress:
-   return rc;
-}
-
-/* Current active state slot, or -1 if no valid saved state exists */
-static int active_slot = -1;
-
-int write_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t* data, size_t data_length) {
-   int rc;
-   uint8_t* cipher = NULL;
-   size_t cipher_len = 0;
-   uint8_t hashkey[HASHKEYSZ];
-   uint8_t* symkey = hashkey + HASHSZ;
-
-   /* Switch to the other slot. Note that in a new vTPM, the read will not
-       * succeed, so active_slot will be -1 and we will write to slot 0.
-       */
-   active_slot = !active_slot;
-
-   /* Encrypt the data */
-   if((rc = encrypt_vtpmblk(data, data_length, &cipher, &cipher_len, symkey))) {
-      goto abort_egress;
-   }
-   /* Write to disk */
-   if((rc = write_vtpmblk_raw(cipher, cipher_len, active_slot))) {
-      goto abort_egress;
-   }
-   /* Get sha1 hash of data */
-   sha1(cipher, cipher_len, hashkey);
-
-   /* Send hash and key to manager */
-   if((rc = VTPM_SaveHashKey(tpmfront_dev, hashkey, HASHKEYSZ)) != TPM_SUCCESS) {
-      goto abort_egress;
-   }
-   goto egress;
-abort_egress:
-egress:
-   free(cipher);
-   return rc;
-}
-
-int read_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t** data, size_t *data_length) {
-   int rc;
-   uint8_t* cipher = NULL;
-   size_t cipher_len = 0;
-   size_t keysize;
-   uint8_t* hashkey = NULL;
-   uint8_t hash0[HASHSZ];
-   uint8_t hash1[HASHSZ];
-   uint8_t* symkey;
-
-   /* Retreive the hash and the key from the manager */
-   if((rc = VTPM_LoadHashKey(tpmfront_dev, &hashkey, &keysize)) != TPM_SUCCESS) {
-      goto abort_egress;
-   }
-   if(keysize != HASHKEYSZ) {
-      error("Manager returned a hashkey of invalid size! expected %d, actual %d", NVMKEYSZ, keysize);
-      rc = -1;
-      goto abort_egress;
-   }
-   symkey = hashkey + HASHSZ;
-
-   active_slot = 0;
-   debug("Reading slot 0 from disk\n");
-   if((rc = read_vtpmblk_raw(&cipher, &cipher_len, 0))) {
-      goto abort_egress;
-   }
-
-   /* Compute the hash of the cipher text and compare */
-   sha1(cipher, cipher_len, hash0);
-   if(!memcmp(hash0, hashkey, HASHSZ))
-      goto valid;
-
-   free(cipher);
-   cipher = NULL;
-
-   active_slot = 1;
-   debug("Reading slot 1 from disk (offset=%u)\n", slot_size);
-   if((rc = read_vtpmblk_raw(&cipher, &cipher_len, 1))) {
-      goto abort_egress;
-   }
-
-   /* Compute the hash of the cipher text and compare */
-   sha1(cipher, cipher_len, hash1);
-   if(!memcmp(hash1, hashkey, HASHSZ))
-      goto valid;
-
-   {
-      int i;
-      error("NVM Storage Checksum failed!");
-      printf("Expected: ");
-      for(i = 0; i < HASHSZ; ++i) {
-        printf("%02hhX ", hashkey[i]);
-      }
-      printf("\n");
-      printf("Slot 0:   ");
-      for(i = 0; i < HASHSZ; ++i) {
-        printf("%02hhX ", hash0[i]);
-      }
-      printf("\n");
-      printf("Slot 1:   ");
-      for(i = 0; i < HASHSZ; ++i) {
-        printf("%02hhX ", hash1[i]);
-      }
-      printf("\n");
-      rc = -1;
-      goto abort_egress;
-   }
-valid:
-
-   /* Decrypt the blob */
-   if((rc = decrypt_vtpmblk(cipher, cipher_len, data, data_length, symkey))) {
-      goto abort_egress;
-   }
-   goto egress;
-abort_egress:
-   active_slot = -1;
-egress:
-   free(cipher);
-   free(hashkey);
-   return rc;
-}
diff --git a/stubdom/vtpm/vtpmblk.h b/stubdom/vtpm/vtpmblk.h
deleted file mode 100644 (file)
index 282ce6a..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
- * ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
- * INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
- * DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
- * SOFTWARE.
- */
-
-#ifndef NVM_H
-#define NVM_H
-#include <mini-os/types.h>
-#include <xen/xen.h>
-#include <tpmfront.h>
-
-#define NVMKEYSZ 32
-#define HASHSZ 20
-#define HASHKEYSZ (NVMKEYSZ + HASHSZ)
-
-int init_vtpmblk(struct tpmfront_dev* tpmfront_dev);
-void shutdown_vtpmblk(void);
-
-/* Encrypts and writes data to blk device */
-int write_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t *data, size_t data_length);
-/* Reads, Decrypts, and returns data from blk device */
-int read_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t **data, size_t *data_length);
-
-#endif
diff --git a/stubdom/vtpmmgr/Makefile b/stubdom/vtpmmgr/Makefile
deleted file mode 100644 (file)
index 6dae034..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (c) 2010-2012 United States Government, as represented by
-# the Secretary of Defense.  All rights reserved.
-#
-# THIS SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT
-# ANY EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES
-# INCLUDING, BUT NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS
-# FOR A PARTICULAR  PURPOSE, AND NONINFRINGEMENT ARE HEREBY
-# DISCLAIMED. USERS ASSUME THE ENTIRE RISK AND LIABILITY OF USING THE
-# SOFTWARE.
-#
-
-XEN_ROOT=../..
-
-TARGET=vtpmmgr.a
-OBJS=vtpmmgr.o vtpm_cmd_handler.o init.o tpmrsa.o tpm.o tpm2.o log.o
-OBJS += vtpm_disk.o disk_tpm.o disk_io.o disk_crypto.o disk_read.o disk_write.o
-OBJS += mgmt_authority.o
-
-CFLAGS+=-Werror -Iutil -Icrypto -Itcs
-CFLAGS+=-Wno-declaration-after-statement -Wno-unused-label
-
-build: $(TARGET)
-$(TARGET): $(OBJS)
-       ar -rcs $@ $^
-
-install:
-       $(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC_BIN)"
-       $(INSTALL_PROG) calc.pl "$(DESTDIR)$(LIBEXEC_BIN)"
-       $(INSTALL_PROG) manage-vtpmmgr.pl "$(DESTDIR)$(LIBEXEC_BIN)"
-
-clean:
-       rm -f $(TARGET) $(OBJS)
-
-distclean: clean
-
-.PHONY: clean distclean
diff --git a/stubdom/vtpmmgr/calc.pl b/stubdom/vtpmmgr/calc.pl
deleted file mode 100755 (executable)
index 4183733..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use Digest::SHA qw(sha1);
-use Math::BigInt only => 'GMP';
-
-my $s2 = Digest::SHA->new("SHA256");
-
-# The key below is an example; its private key is (obviously) not private. This
-# key must be protected at least as well as the vTPM's secrets, since it can
-# approve the release of these secrets to a new TCB.  It may make sense to
-# modify this script to use a TPM or some other hardware key storage device to
-# hold the private key instead of holding the key in plaintext; such integration
-# is beyond the scope of this example script.
-#
-# The public exponent of this key must be 65537 (0x10001); this is the default
-# for TPM-generated RSA keys.
-#
-# The manage-tpmmgr.pl script expects the modulus of this RSA key to be
-# available; this may be done using:
-#
-# open KEY, '>rsa-modulus-file';
-# print KEY pack 'H*', $rsa_n;
-# close KEY;
-
-my $rsa_n = 'c1580b4ea118a6c2f0a56d5af59b080928a9de7267f824457a1e9d7216013b5a322ff67f72153cd4b58693284490aced3a85d81da909ffe544f934c80340020b5bf514e8850926c6ce3314c3283e33cb79cb6aecf041726782013d07f8171fde4ea8165c6a7050af534ffc1b11ae37ace2ed6436c626edb49bf5bd70ee71f74bf2c132a99e5a6427343dbe46829961755558386436ebea90959161295c78df0127d4e468f9a188b3c1e9b68e5b1e78a450ea437ac7930dab294ede8117f6849d53f11e0bbc8ccef44b7fc9ebd6d7c7532875b3225a9106961771001be618ab3f991ba18edc1b73d73b6b80b5df854f9c9113d0b0cd1fec81a85da3638745fd29';
-my $rsa_d = '3229508daed80173f4114744e111beccf982d0d6a7c8c6484c3da3259535ee9b21083690ac1d7c71c742c9ed1994db7894c562e39716a4106c8ba738f936e310e563b96ff60c00c6757ae53918b8c2a158d100c5c63384a5fc21ac1ee42bc3b5de7c5788d4889d364f8c21e137fe162dc1964b78b682250bc5a6c4e686c6849cf8f0020f6ca383d784e5ffb85da56c2b89dc2e879509b1916c8b51f5907a0dbb7e2f9e5fabc500588ef7db6f78ba4605da86d907493648017ac46a1571ffe9b6a68babeeb277e3a96d346cddc996a94163f1e8393d88f710ff64369a62d3edfc62dbdeae57ee12a33adbb9b9d48d575158117f29fc991cbbbaaa4a47ee974f31';
-
-sub rsa_sign {
-       my $m = '1'.('ff'x218).'003021300906052b0e03021a05000414';
-       $m .= unpack 'H*', sha1(shift);
-       $m = Math::BigInt->from_hex($m);
-       my $n = Math::BigInt->from_hex($rsa_n);
-       my $e = Math::BigInt->from_hex($rsa_d);
-       $m->bmodpow($e, $n);
-       $m = $m->as_hex();
-       $m =~ s/^0x//;
-       $m =~ s/^/0/ while length $m < 512;
-       pack 'H*', $m;
-}
-
-sub auth_update_file {
-       my($dst,$seq) = (shift, shift);
-       my(@plt, @pcrs, @kerns, $cfg);
-       open my $update, '>', $dst or die $!;
-       for (@_) {
-               if (/^([0-9a-fA-F]+)=([0-9a-fA-F]+)$/) {
-                       push @pcrs, pack 'V', hex $1;
-                       push @plt, pack 'H*', $2;
-               } elsif (/^[0-9a-fA-F]{40}$/) {
-                       push @kerns, pack 'H*', $_;
-               } elsif (length $_ == 20) {
-                       push @kerns, $_;
-               } else {
-                       print "Bad argument: $_";
-                       exit 1;
-               }
-       }
-       $cfg = pack 'Q>', $seq;
-       $cfg .= pack 'N/(a20)', @plt;
-       $cfg .= pack 'N/(a20)', @kerns;
-
-       printf "cfg_hash for %s: %s\n", $dst, Digest::SHA::sha1_hex($cfg);
-
-       print $update rsa_sign($cfg);
-       print $update $cfg;
-       print $update map { pack 'n/a3', $_ } @pcrs;
-       close $update;
-}
-
-my $out = shift;
-my $seq = $ENV{SEQ} || time;
-
-if (!$out) {
-       print <<EOF;
-Usage: $0 <output> {<pcrs>=<composite>}* {<kernel>}*
-       <output> is the file that will contain the signed configuration
-       <pcrs> is a 24-bit PCR mask in hexadecimal
-       <composite> is a PCR_COMPOSITE_HASH in hexadecimal
-       <kernel> is a 160-bit vTPM kernel hash in hexadecimal
-
-The sequence number may be specified using the SEQ environment variable,
-otherwise the current UNIX timestamp will be used.  The sequence number of a
-vTPM group must increase on each update.
-
-When the vTPM Manager is compiled without support for a domain builder, the
-SHA-1 hash of the vTPM domain's XSM label is used in place of its kernel hash.
-
-Example:
-       A configuration with two valid command lines and one valid vTPM kernel
-       PCRs 0-7 and 17-19 are being validated (static RTM and TBOOT).
-       $0 auth-0 0e00ff=0593ecb564f532df6ef2f4d7272489da52c4c840 0e00ff=0593ecb564f532df6ef2f4d7272489da52c4c840 2bc65001d506ce6cd12cab90a4a2ad9040d641e1
-EOF
-       exit 0;
-}
-print "Sequence: $seq\n";
-
-auth_update_file $out, $seq, @ARGV;
diff --git a/stubdom/vtpmmgr/common_types.h b/stubdom/vtpmmgr/common_types.h
deleted file mode 100644 (file)
index 7321bb6..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef VTPM_COMMON_TYPES
-#define VTPM_COMMON_TYPES 1
-typedef unsigned char BYTE;
-typedef unsigned char BOOL;
-typedef unsigned char UINT8;
-typedef uint16_t UINT16;
-typedef uint32_t UINT32;
-typedef uint64_t UINT64;
-#endif
diff --git a/stubdom/vtpmmgr/disk_crypto.c b/stubdom/vtpmmgr/disk_crypto.c
deleted file mode 100644 (file)
index 18718d0..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-#include <inttypes.h>
-#include <mini-os/byteorder.h>
-#include <polarssl/aes.h>
-#include <polarssl/sha2.h>
-#include <polarssl/ctr_drbg.h>
-
-#include "log.h"
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_io.h"
-#include "disk_crypto.h"
-
-// XXX defining this stubs out all disk encryption for easier debugging
-#undef DISK_IS_PLAINTEXT
-
-void do_random(void *buf, size_t size)
-{
-       int rc = ctr_drbg_random(&vtpm_globals.ctr_drbg, buf, size);
-       if (rc) abort();
-}
-
-void aes_setup(aes_context *ctx, const struct key128 *key)
-{
-       aes_setkey_enc(ctx, (void*)key, 128);
-}
-
-static void aes_encrypt_ecb(void *target, const void *src, const aes_context *key_e)
-{
-       aes_crypt_ecb((void*)key_e, AES_ENCRYPT, src, target);
-}
-
-void aes_encrypt_one(void *target, const void *src, const struct key128 *key)
-{
-       aes_context ctx;
-       aes_setkey_enc(&ctx, (void*)key, 128);
-       aes_crypt_ecb(&ctx, AES_ENCRYPT, src, target);
-}
-
-void aes_decrypt_one(void *target, const void *src, const struct key128 *key)
-{
-       aes_context ctx;
-       aes_setkey_dec(&ctx, (void*)key, 128);
-       aes_crypt_ecb(&ctx, AES_DECRYPT, src, target);
-}
-
-static void aes_ctr_one(uint64_t out[2], uint64_t ctr[2], const aes_context *key_e)
-{
-#ifdef DISK_IS_PLAINTEXT
-       memset(out, 0, 16);
-#else
-       aes_encrypt_ecb(out, ctr, key_e);
-#endif
-       ctr[1]++;
-}
-
-void aes_encrypt_ctr(void *target, size_t target_size, const void *srcv, size_t pt_size, const aes_context *key_e)
-{
-       uint64_t ctr[2];
-       uint64_t tmp[2];
-       uint64_t *dst = target;
-       const uint64_t *src = srcv;
-
-       do_random(ctr, sizeof(ctr));
-       dst[0] = ctr[0];
-       dst[1] = ctr[1];
-       dst += 2;
-       target_size -= 16;
-
-       if (pt_size > target_size)
-               abort(); // invalid argument: target too small for plaintext
-
-       while (pt_size >= 16) {
-               aes_ctr_one(tmp, ctr, key_e);
-
-               dst[0] = tmp[0] ^ src[0];
-               dst[1] = tmp[1] ^ src[1];
-
-               dst += 2;
-               src += 2;
-               pt_size -= 16;
-               target_size -= 16;
-       }
-       if (pt_size) {
-               uint64_t stmp[2];
-               uint64_t dtmp[2];
-               memset(stmp, 0, 16);
-               memcpy(stmp, src, pt_size);
-
-               aes_ctr_one(tmp, ctr, key_e);
-
-               dtmp[0] = tmp[0] ^ stmp[0];
-               dtmp[1] = tmp[1] ^ stmp[1];
-               if (target_size < 16) {
-                       memcpy(dst, dtmp, target_size);
-                       return;
-               } else {
-                       memcpy(dst, dtmp, 16);
-                       target_size -= 16;
-               }
-       }
-       while (target_size >= 16) {
-               aes_ctr_one(dst, ctr, key_e);
-
-               dst += 2;
-               target_size -= 16;
-       }
-       if (target_size)
-               abort(); // invalid argument: overlarge target size is not a full block
-}
-
-void aes_decrypt_ctr(void *target, size_t pt_size, const void *srcv, size_t src_size, const aes_context *key_e)
-{
-       uint64_t ctr[2];
-       uint64_t tmp[2];
-       uint64_t *dst = target;
-       const uint64_t *src = srcv;
-
-       ctr[0] = src[0];
-       ctr[1] = src[1];
-       src += 2;
-       src_size -= 16;
-
-       if (pt_size > src_size)
-               abort(); // invalid argument: source too small for plaintext
-       // we discard src_size now
-
-       while (pt_size >= 16) {
-               aes_ctr_one(tmp, ctr, key_e);
-               dst[0] = tmp[0] ^ src[0];
-               dst[1] = tmp[1] ^ src[1];
-
-               dst += 2;
-               src += 2;
-               pt_size -= 16;
-       }
-       if (pt_size) {
-               uint64_t stmp[2];
-               uint64_t dtmp[2];
-               memset(stmp, 0, 16);
-               memcpy(stmp, src, pt_size);
-
-               aes_ctr_one(tmp, ctr, key_e);
-
-               dtmp[0] = tmp[0] ^ stmp[0];
-               dtmp[1] = tmp[1] ^ stmp[1];
-               memcpy(dst, dtmp, pt_size);
-       }
-}
-
-static void shl_128_mod_hex87(struct mac128 *dst, const struct mac128 *src)
-{
-       int i;
-       int carry = 0x87 * !!(src->bits[0] & 0x80);
-       for(i=0; i < 15; i++)
-               dst->bits[i] = (src->bits[i] << 1) | (src->bits[i+1] >> 7);
-       dst->bits[15] = (src->bits[15] << 1) ^ carry;
-}
-
-static void xor128(struct mac128 *dst, const struct mac128 *s1, const struct mac128 *s2)
-{
-       int i;
-       for(i=0; i < 16; i++)
-               dst->bits[i] = s1->bits[i] ^ s2->bits[i];
-}
-
-void aes_cmac(struct mac128 *target, const void *src, size_t size, const aes_context *key)
-{
-       const struct mac128 *M = src;
-       struct mac128 x, y, L, K1, K2;
-       int i;
-       size_t bsize = (size - 1) / 16;
-
-       memset(&x, 0, sizeof(x));
-       aes_encrypt_ecb(&L, &x, key);
-       shl_128_mod_hex87(&K1, &L);
-       shl_128_mod_hex87(&K2, &K1);
-
-       for(i=0; i < bsize; i++) {
-               xor128(&y, &x, &M[i]);
-               aes_encrypt_ecb(&x, &y, key);
-       }
-       if (size & 0xF) {
-               struct mac128 z;
-               memset(&z, 0, sizeof(z));
-               memcpy(&z, M + bsize, size & 0xF);
-               xor128(&y, &x, &K2);
-               xor128(&x, &y, &z);
-       } else {
-               xor128(&y, &x, &K1);
-               xor128(&x, &y, M + bsize);
-       }
-       aes_encrypt_ecb(target, &x, key);
-}
-
-static int verify_128(const void *a, const void* b)
-{
-       const volatile uint64_t *x = a;
-       const volatile uint64_t *y = b;
-       if ((x[0] ^ y[0]) | (x[1] ^ y[1]))
-               return 1;
-       return 0;
-}
-
-int aes_cmac_verify(const struct mac128 *target, const void *src, size_t size, const aes_context *key)
-{
-       struct mac128 mac;
-       aes_cmac(&mac, src, size, key);
-       return verify_128(&mac, target);
-}
-
-static int verify_256(const void *a, const void* b)
-{
-       const volatile uint64_t *x = a;
-       const volatile uint64_t *y = b;
-       if ((x[0] ^ y[0]) | (x[1] ^ y[1]) | (x[2] ^ y[2]) | (x[3] ^ y[3]))
-               return 1;
-       return 0;
-}
-
-void sha256(struct hash256 *target, const void *src, size_t size)
-{
-       void* dst = target;
-       sha2(src, size, dst, 0);
-}
-
-int sha256_verify(const struct hash256 *targ, const void *data, size_t size)
-{
-       struct hash256 hash;
-       sha256(&hash, data, size);
-       return verify_256(&hash, targ);
-}
diff --git a/stubdom/vtpmmgr/disk_crypto.h b/stubdom/vtpmmgr/disk_crypto.h
deleted file mode 100644 (file)
index faae9ab..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __VTPMMGR_DISK_CRYPTO_H
-#define __VTPMMGR_DISK_CRYPTO_H
-
-void do_random(void *buf, size_t size);
-void aes_encrypt_one(void *target, const void *src, const struct key128 *key);
-void aes_decrypt_one(void *target, const void *src, const struct key128 *key);
-
-void aes_setup(aes_context *ctx, const struct key128 *key);
-void aes_encrypt_ctr(void *target, size_t target_size, const void *srcv, size_t src_size, const aes_context *key_e);
-void aes_decrypt_ctr(void *target, size_t target_size, const void *srcv, size_t src_size, const aes_context *key_e);
-void aes_cmac(struct mac128 *target, const void *src, size_t size, const aes_context *key);
-int aes_cmac_verify(const struct mac128 *target, const void *src, size_t size, const aes_context *key);
-
-void sha256(struct hash256 *target, const void *src, size_t size);
-int sha256_verify(const struct hash256 *targ, const void *data, size_t size);
-
-#endif
diff --git a/stubdom/vtpmmgr/disk_format.h b/stubdom/vtpmmgr/disk_format.h
deleted file mode 100644 (file)
index bc20fbb..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-#ifndef __VTPMMGR_DISK_FORMAT_H
-#define __VTPMMGR_DISK_FORMAT_H
-
-static const uint8_t TPM_MGR_MAGIC[12] = {
-       'T','P','M',0xfe,'M','G','R',0xdd,'D','O','M',0x00
-};
-
-/**
- * Sector 0 on disk: stored in plaintext
- */
-struct disk_header {
-       char magic[12];
-#define TPM_MGR_VERSION 0
-       be32_t version;
-};
-
-/**
- * Raw contents of disk sectors that need both encryption and authentication
- */
-struct disk_crypt_sector_plain {
-       struct mac128 mac;
-       union {
-               struct {
-                       uint8_t iv[16];
-                       char data[4096-32];
-               };
-               uint8_t iv_data[4096-16];
-       };
-};
-
-/**
- * Contents of the sealed blob in the root seal list
- */
-struct disk_root_sealed_data {
-#define DISK_ROOT_BOUND_MAGIC "Root"
-       char magic[4];
-       uuid_t tpm_manager_uuid;
-
-       be32_t nvram_slot;
-       struct tpm_authdata nvram_auth;
-       be32_t counter_index;
-       struct tpm_authdata counter_auth;
-
-       /* encrypted (AES-ECB) with key from NVRAM */
-       struct key128 tm_key;
-};
-
-/**
- * Contents of the sealed blob in a group's seal list
- */
-struct disk_group_sealed_data {
-#define DISK_GROUP_BOUND_MAGIC "TGrp"
-       char magic[4];
-       uuid_t tpm_manager_uuid;
-       struct tpm_authdata aik_authdata;
-
-       struct key128 group_key;
-       struct key128 rollback_mac_key;
-};
-
-/**
- * Contents of the seal_list_N sectors on disk (plaintext, linked list)
- *
- * The hdr field is unused except in sector 0
- */
-struct disk_seal_list {
-       struct disk_header hdr;
-       be32_t length;
-       sector_t next;
-#define SEALS_PER_ROOT_SEAL_LIST 13
-       struct disk_seal_entry entry[SEALS_PER_ROOT_SEAL_LIST];
-};
-
-/**
- * TODO - overflow for struct disk_group_boot_config_list
- */
-struct disk_group_seal_list {
-       sector_t next;
-#define SEALS_PER_GROUP_SEAL_LIST 13
-       struct disk_seal_entry entry[SEALS_PER_GROUP_SEAL_LIST];
-};
-
-/**
- * Rollback detection MAC entry
- */
-struct disk_rb_mac_entry {
-       be32_t id;
-       struct mac128 mac;
-};
-
-#define NR_ENTRIES_PER_ROOT 16
-/**
- * The area of the root sector protected by rollback MACs
- */
-struct disk_root_sector_mac1_area {
-       be64_t sequence;
-       be32_t tpm_counter_value;
-
-       be32_t nr_groups;
-       struct hash256 group_hash[NR_ENTRIES_PER_ROOT];
-};
-
-/**
- * Decrypted contents of the root sector (sector 1 and 2) on disk
- */
-struct disk_root_sector {
-       struct disk_root_sector_mac1_area v;
-
-       sector_t group_loc[NR_ENTRIES_PER_ROOT];
-
-       uint8_t pad[8];
-
-       /* Rollback detection MACs */
-       be32_t nr_rb_macs;
-       sector_t rb_next_loc;
-       /* used if rb_macs overflows */
-       struct hash256 rb_next_hash;
-
-#define NR_RB_MACS_PER_ROOT 128
-       struct disk_rb_mac_entry rb_macs[NR_RB_MACS_PER_ROOT];
-};
-
-/**
- * Hash tree for list expansion. Used for the list of groups in the root and for
- * the list of vTPMs in a group.
- */
-struct disk_itree_sector {
-#define NR_ENTRIES_PER_ITREE 112
-       sector_t location[NR_ENTRIES_PER_ITREE];
-       /* SECTOR-HASH { */
-       struct hash256 hash[NR_ENTRIES_PER_ITREE];
-       /* SECTOR-HASH } */
-};
-
-#define NR_ENTRIES_PER_GROUP_BASE 16
-/**
- * Data that must remain constant if a group is not open
- */
-struct disk_group_sector_mac3_area {
-       struct group_id_data id_data; /* MAC2 */
-       struct group_details details;
-       struct disk_group_boot_config_list boot_configs;
-
-       be32_t nr_vtpms;
-       struct hash256 vtpm_hash[NR_ENTRIES_PER_GROUP_BASE];
-};
-
-/**
- * Group metadata sector
- *
- * Encrypted with TM_KEY - takes 16 bytes for IV; integrity from parent.
- */
-struct disk_group_sector {
-       /* SECTOR-HASH { */
-       struct disk_group_sector_mac3_area v;
-
-       /* MAC(MAC3, group_key) */
-       struct mac128 group_mac;
-       /* SECTOR-HASH } */
-
-       sector_t vtpm_location[NR_ENTRIES_PER_GROUP_BASE];
-       sector_t boot_configs_next;
-};
-
-/**
- * Data on a vTPM which is available when its group is not open
- */
-struct disk_vtpm_plain {
-       uuid_t uuid;
-       be32_t flags;
-};
-
-/**
- * Data on a vTPM which is only available when its group is open
- */
-struct disk_vtpm_secret {
-       uint8_t data[64];
-};
-
-/**
- * Contents of a vTPM data disk sector
- *
- * Encrypted with TM_KEY - takes 16 bytes for IV
- */
-struct disk_vtpm_sector {
-       /* SECTOR-HASH { */
-       struct disk_vtpm_plain header[VTPMS_PER_SECTOR];
-       struct mac128 iv;
-       struct disk_vtpm_secret data[VTPMS_PER_SECTOR];
-       /* SECTOR-HASH } */
-};
-
-#endif
diff --git a/stubdom/vtpmmgr/disk_io.c b/stubdom/vtpmmgr/disk_io.c
deleted file mode 100644 (file)
index 02b4fdd..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#include <blkfront.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-
-#include "vtpm_manager.h"
-#include "log.h"
-#include "uuid.h"
-
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_tpm.h"
-#include "disk_io.h"
-
-static uint8_t disk_staging_buf[4096] __attribute__((aligned(4096)));
-
-static struct blkfront_dev* blkdev;
-static int blkfront_fd = -1;
-
-int vtpm_storage_init(void) {
-       struct blkfront_info info;
-       blkdev = init_blkfront(NULL, &info);
-       if (blkdev == NULL)
-               return -1;
-       blkfront_fd = blkfront_open(blkdev);
-       if (blkfront_fd < 0)
-               return -1;
-       return 0;
-}
-
-void* disk_read_sector(sector_t sector)
-{
-       uint32_t pos = be32_native(sector);
-       int rc;
-       vtpmloginfo(VTPM_LOG_VTPM, "disk_read_sector %x\n", pos);
-       lseek(blkfront_fd, pos * 4096, SEEK_SET);
-       rc = read(blkfront_fd, disk_staging_buf, 4096);
-       if (rc != 4096)
-               abort();
-       return disk_staging_buf;
-}
-
-void* disk_write_buf(void) { return disk_staging_buf; }
-
-void disk_write_sector(sector_t sector, void* buf, size_t siz)
-{
-       int rc;
-       uint32_t pos = be32_native(sector);
-       lseek(blkfront_fd, pos * 4096, SEEK_SET);
-       if (siz < 4096) {
-               if (buf != disk_staging_buf)
-                       memcpy(disk_staging_buf, buf, siz);
-               memset(disk_staging_buf + siz, 0, 4096 - siz);
-               buf = disk_staging_buf;
-       } else if (siz > 4096)
-               abort();
-
-       rc = write(blkfront_fd, buf, 4096);
-       if (rc != 4096)
-               abort();
-}
-
-void disk_write_barrier(void)
-{
-       blkfront_sync(blkdev);
-}
-
-enum inuse_value {
-       UNUSED,
-       SLOT_1,
-       SLOT_2,
-       SHARED
-};
-
-/* TODO make this dynamic to support using more than 2MB of disk */
-#define DISK_MAX_SECTOR 0x200
-
-/* The first 4 sectors are statically allocated:
- *  0 - disk header (copy 1)
- *  1 - disk header (copy 2)
- *  2 - root sector (copy 1)
- *  3 - root sector (copy 2)
- */
-#define FIRST_DYNAMIC_SECTOR 4
-
-static uint8_t sector_inuse_map[DISK_MAX_SECTOR];
-
-static int active_slot(const struct mem_tpm_mgr *mgr)
-{
-       return 1 + mgr->active_root;
-}
-
-void disk_set_used(sector_t loc, const struct mem_tpm_mgr *mgr)
-{
-       uint32_t s = be32_native(loc);
-       if (s > DISK_MAX_SECTOR) {
-               printk("Attempted disk_set_used %x\n", s);
-               return;
-       }
-       sector_inuse_map[s] |= active_slot(mgr);
-}
-
-void disk_flush_slot(const struct mem_tpm_mgr *mgr)
-{
-       int i;
-       for(i = FIRST_DYNAMIC_SECTOR; i < DISK_MAX_SECTOR; i++)
-               sector_inuse_map[i] &= ~active_slot(mgr);
-}
-
-sector_t disk_find_free(const struct mem_tpm_mgr *mgr)
-{
-       int i;
-       for(i = FIRST_DYNAMIC_SECTOR; i < DISK_MAX_SECTOR; i++) {
-               if (sector_inuse_map[i])
-                       continue;
-               sector_inuse_map[i] = active_slot(mgr);
-               return native_be32(i);
-       }
-       // TODO more graceful error handling (in callers)
-       abort();
-}
diff --git a/stubdom/vtpmmgr/disk_io.h b/stubdom/vtpmmgr/disk_io.h
deleted file mode 100644 (file)
index c0d35a5..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __VTPMMGR_DISK_IO_H
-#define __VTPMMGR_DISK_IO_H
-
-void* disk_read_sector(sector_t sector);
-void disk_write_sector(sector_t sector, void* buf, size_t siz);
-void* disk_write_buf(void);
-void disk_write_barrier(void);
-
-sector_t disk_find_free(const struct mem_tpm_mgr *mgr);
-void disk_flush_slot(const struct mem_tpm_mgr *mgr);
-void disk_set_used(sector_t loc, const struct mem_tpm_mgr *mgr);
-
-void disk_write_all(struct mem_tpm_mgr *mgr);
-
-static inline sector_t seal_loc(struct mem_tpm_mgr *mgr)
-{
-       return native_be32(mgr->active_root);
-}
-
-static inline sector_t root_loc(struct mem_tpm_mgr *mgr)
-{
-       return native_be32(2 + mgr->active_root);
-}
-
-#endif
diff --git a/stubdom/vtpmmgr/disk_read.c b/stubdom/vtpmmgr/disk_read.c
deleted file mode 100644 (file)
index 944d3ff..0000000
+++ /dev/null
@@ -1,619 +0,0 @@
-#include <console.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-
-#include "vtpm_manager.h"
-#include "log.h"
-#include "uuid.h"
-
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_tpm.h"
-#include "disk_io.h"
-#include "disk_crypto.h"
-#include "disk_format.h"
-
-static int disk_read_crypt_sector(void *data, size_t size, sector_t block, const struct mem_tpm_mgr *mgr)
-{
-       struct disk_crypt_sector_plain *sector = disk_read_sector(block);
-       if (!sector)
-               return 2;
-
-       if (aes_cmac_verify(&sector->mac, sector->data, sizeof(sector->data), &mgr->tm_key_e))
-               return 2;
-
-       aes_decrypt_ctr(data, size, sector->iv_data, sizeof(sector->iv_data), &mgr->tm_key_e);
-       return 0;
-}
-
-static void group_free(struct mem_group *group)
-{
-       int i, j;
-       if (!group)
-               return;
-       if (group->data) {
-               for (i = 0; i < group->nr_pages; i++) {
-                       for (j = 0; j < group->data[i].size; j++) {
-                               free(group->data[i].vtpms[j]);
-                       }
-               }
-               free(group->data);
-       }
-       free(group->seals);
-       free(group);
-}
-
-static void mgr_free(struct mem_tpm_mgr *mgr)
-{
-       int i;
-       if (!mgr)
-               return;
-       if (mgr->groups) {
-               for(i=0; i < mgr->nr_groups; i++)
-                       group_free(mgr->groups[i].v);
-               free(mgr->groups);
-       }
-       free(mgr);
-}
-
-/* Open the group keys from one of the sealed strutures */
-static int find_group_key(struct mem_group *dst,
-               const struct disk_group_sector *group,
-               const struct mem_tpm_mgr *parent)
-{
-       int i, rc, rv = 1;
-    unsigned int olen;
-       struct hash160 buf;
-       struct disk_group_sealed_data sealed;
-
-       dst->nr_seals = be32_native(group->v.boot_configs.nr_cfgs);
-       if (dst->nr_seals > NR_SEALS_PER_GROUP)
-               return 3; // TODO support spill to extra pages
-
-       dst->seals = calloc(dst->nr_seals, sizeof(dst->seals[0]));
-       if (!dst->seals) {
-               vtpmlogerror(VTPM_LOG_VTPM, "find_group_key alloc %x\n", dst->nr_seals);
-               return 2;
-       }
-
-       for(i=0; i < dst->nr_seals; i++) {
-               const struct disk_seal_entry *cfg = &group->v.boot_configs.entry[i];
-               dst->seals[i].pcr_selection = cfg->pcr_selection;
-               memcpy(&dst->seals[i].digest_release, &cfg->digest_release, 20);
-
-               TPM_pcr_digest(&buf, cfg->pcr_selection);
-               if (memcmp(&buf, &cfg->digest_release, 20))
-                       continue;
-
-        /*TPM 2.0 unbind | TPM 1.x unseal*/
-        if (hw_is_tpm2())
-            rc = TPM2_disk_unbind(&sealed, &olen, cfg);
-        else
-            rc = TPM_disk_unseal(&sealed, sizeof(sealed), cfg);
-
-               if (rc)
-                       continue;
-               if (memcmp(&sealed.magic, DISK_GROUP_BOUND_MAGIC, 4))
-                       continue;
-               if (memcmp(sealed.tpm_manager_uuid, parent->uuid, 16))
-                       continue;
-
-               memcpy(&dst->rollback_mac_key, &sealed.rollback_mac_key, 16);
-               memcpy(&dst->group_key, &sealed.group_key, 16);
-               memcpy(&dst->aik_authdata, &sealed.aik_authdata, 20);
-               rv = 0;
-       }
-
-       // cache the list to allow writes without touching the TPM
-       memcpy(&dst->seal_bits, &group->v.boot_configs, sizeof(dst->seal_bits));
-       dst->flags |= MEM_GROUP_FLAG_SEAL_VALID;
-
-       return rv;
-}
-
-static int parse_root_key(struct mem_tpm_mgr *dst, struct disk_seal_entry *src)
-{
-       int rc;
-    unsigned int olen;
-       struct disk_root_sealed_data sealed;
-
-    /*TPM 2.0 unbind | TPM 1.x unseal*/
-    if (hw_is_tpm2())
-        rc = TPM2_disk_unbind(&sealed, &olen, src);
-    else
-        rc = TPM_disk_unseal(&sealed, sizeof(sealed), src);
-
-       if (rc)
-               return rc;
-
-       if (memcmp(&sealed.magic, DISK_ROOT_BOUND_MAGIC, 4))
-               return 1;
-
-       rc = TPM_disk_nvread(&dst->nv_key, 16, sealed.nvram_slot, sealed.nvram_auth);
-       if (rc)
-               return rc;
-
-       // TODO when an NV slot in the physical TPM is used to populate nv_key,
-       // that value should be used to mask the master key so that the value
-       // can be changed to revoke old disk state
-#if 0
-       aes_decrypt_one(&dst->tm_key, &sealed.tm_key, &dst->nv_key);
-#else
-       memcpy(&dst->tm_key, &sealed.tm_key, 16);
-#endif
-
-       memcpy(dst->uuid, sealed.tpm_manager_uuid, 16);
-       dst->nvram_slot = sealed.nvram_slot;
-       memcpy(&dst->nvram_auth, &sealed.nvram_auth, sizeof(struct tpm_authdata));
-       dst->counter_index = sealed.counter_index;
-       memcpy(&dst->counter_auth, &sealed.counter_auth, sizeof(struct tpm_authdata));
-
-       return 0;
-}
-
-static struct mem_tpm_mgr *find_root_key(int active_root)
-{
-       sector_t seal_list = native_be32(active_root);
-       struct disk_seal_list *seal = disk_read_sector(seal_list);
-       struct hash160 buf;
-       int i, rc, nr;
-       struct mem_tpm_mgr *dst;
-
-       if (memcmp(seal->hdr.magic, TPM_MGR_MAGIC, 12))
-               return NULL;
-
-       if (be32_native(seal->hdr.version) != TPM_MGR_VERSION)
-               return NULL;
-
-       dst = calloc(1, sizeof(*dst));
-       dst->active_root = active_root;
-
-       for (nr = 0; nr < 100; nr++) {
-               disk_set_used(seal_list, dst);
-               uint32_t nr_seals = be32_native(seal->length);
-               if (nr_seals > SEALS_PER_ROOT_SEAL_LIST)
-                       break;
-               for (i = 0; i < nr_seals; i++) {
-                       struct disk_seal_entry *src = &seal->entry[i];
-
-                       TPM_pcr_digest(&buf, src->pcr_selection);
-                       if (memcmp(&buf, &src->digest_release, 20))
-                               continue;
-
-                       rc = parse_root_key(dst, src);
-                       if (rc)
-                               continue;
-                       return dst;
-               }
-               seal_list = seal->next;
-               if (seal_list.value == 0)
-                       break;
-               seal = disk_read_sector(seal_list);
-       }
-       mgr_free(dst);
-       return NULL;
-}
-
-/* Load and verify one sector's worth of vTPMs. This loads all the vTPM entries
- * and decrypts their state data into memory.
- */
-static int load_verify_vtpm_page(struct mem_vtpm_page *dst, int base,
-               const struct mem_tpm_mgr *mgr, const aes_context *group_key)
-{
-       struct disk_vtpm_sector pt;
-       int i, rc;
-
-       disk_set_used(dst->disk_loc, mgr);
-
-       rc = disk_read_crypt_sector(&pt, sizeof(pt), dst->disk_loc, mgr);
-       if (rc) {
-               printk("Malformed sector %d\n", be32_native(dst->disk_loc));
-               return rc;
-       }
-       
-       rc = sha256_verify(&dst->disk_hash, &pt, sizeof(pt));
-       if (rc) {
-               printk("Hash mismatch in sector %d\n", be32_native(dst->disk_loc));
-               return rc;
-       }
-
-       if (!group_key)
-               return 0;
-
-       aes_decrypt_ctr(pt.data, sizeof(pt.data), &pt.iv, sizeof(pt.data) + 16, group_key);
-
-       for (i = 0; i < dst->size; i++) {
-               struct mem_vtpm *vtpm = calloc(1, sizeof(*vtpm));
-               dst->vtpms[i] = vtpm;
-               memcpy(vtpm->uuid, pt.header[i].uuid, 16);
-               memcpy(vtpm->data, pt.data[i].data, 64);
-               vtpm->flags = be32_native(pt.header[i].flags);
-               vtpm->index_in_parent = i + base;
-       }
-       return 0;
-}
-
-static int load_verify_vtpm_pages(struct mem_group *group, int base, int size,
-               const struct hash256 *hash, const sector_t *loc,
-               const struct mem_tpm_mgr *mgr, const aes_context *group_key)
-{
-       int i, rc;
-       struct mem_vtpm_page *page = group->data + base;
-
-       /* base was in terms of sectors; convert to vtpms */
-       base *= VTPMS_PER_SECTOR;
-
-       for (i = 0; i < size; i++) {
-               page->disk_hash = hash[i];
-               page->disk_loc = loc[i];
-               if (group->nr_vtpms - base > VTPMS_PER_SECTOR)
-                       page->size = VTPMS_PER_SECTOR;
-               else
-                       page->size = group->nr_vtpms - base;
-               rc = load_verify_vtpm_page(page, base, mgr, group_key);
-               if (rc)
-                       return rc;
-               base += VTPMS_PER_SECTOR;
-       }
-
-       return 0;
-}
-
-static int load_verify_vtpm_itree(struct mem_group_hdr *hdr, int base, int nr_entries,
-               const struct hash256 *hash, const sector_t *loc, int hsize,
-               const struct mem_tpm_mgr *mgr, const aes_context *group_key);
-
-static int load_verify_vtpm_itree(struct mem_group_hdr *hdr, int base, int nr_entries,
-               const struct hash256 *hash, const sector_t *loc, int hsize,
-               const struct mem_tpm_mgr *mgr, const aes_context *group_key)
-{
-       int i, rc, incr = 1, inuse_base = hdr->disk_nr_inuse, lsize;
-
-       // increase tree depth until all entries fit
-       while (nr_entries > incr * hsize)
-               incr *= NR_ENTRIES_PER_ITREE;
-
-       // save the list of used sectors (itree and vtpm) in the header
-       lsize = 1 + (nr_entries - 1) / incr;
-       hdr->disk_nr_inuse += lsize;
-       hdr->disk_inuse = realloc(hdr->disk_inuse, hdr->disk_nr_inuse * sizeof(sector_t));
-       memcpy(&hdr->disk_inuse[inuse_base], loc, lsize * sizeof(sector_t));
-
-       // if the entries already fit, process vtpm pages
-       if (nr_entries <= hsize)
-               return load_verify_vtpm_pages(hdr->v, base, nr_entries, hash, loc, mgr, group_key);
-
-       for (i = 0; i * incr < nr_entries; i++) {
-               struct disk_itree_sector pt;
-               int child_entries = incr;
-
-               // the last sector is not completely full
-               if (nr_entries - i * incr < incr)
-                       child_entries = nr_entries - i * incr;
-
-               disk_set_used(loc[i], mgr);
-               hdr->disk_inuse[inuse_base++] = loc[i];
-
-               rc = disk_read_crypt_sector(&pt, sizeof(pt), loc[i], mgr);
-               if (rc) {
-                       printk("Malformed sector %d\n", be32_native(loc[i]));
-                       return rc;
-               }
-
-               rc = sha256_verify(&hash[i], pt.hash, sizeof(pt.hash));
-               if (rc) {
-                       printk("Hash mismatch in sector %d\n", be32_native(loc[i]));
-                       return rc;
-               }
-
-               rc = load_verify_vtpm_itree(hdr, base, child_entries, pt.hash, pt.location,
-                               NR_ENTRIES_PER_ITREE, mgr, group_key);
-               if (rc)
-                       return rc;
-
-               base += incr;
-       }
-
-       return 0;
-}
-
-/* Load and verify one group's data structure, including its vTPMs.
- */
-static int load_verify_group(struct mem_group_hdr *dst, const struct mem_tpm_mgr *mgr)
-{
-       struct mem_group *group;
-       struct disk_group_sector disk;
-       int rc;
-       aes_context key_e;
-       aes_context *opened_key = NULL;
-
-       disk_set_used(dst->disk_loc, mgr);
-
-       rc = disk_read_crypt_sector(&disk, sizeof(disk), dst->disk_loc, mgr);
-       if (rc) {
-               printk("Malformed sector %d\n", be32_native(dst->disk_loc));
-               return rc;
-       }
-       
-       rc = sha256_verify(&dst->disk_hash, &disk.v, sizeof(disk.v) + sizeof(disk.group_mac));
-       if (rc) {
-               printk("Hash mismatch in sector %d\n", be32_native(dst->disk_loc));
-               return rc;
-       }
-       
-       dst->v = group = calloc(1, sizeof(*group));
-
-       rc = find_group_key(group, &disk, mgr);
-       if (rc == 0) {
-               opened_key = &key_e;
-               /* Verify the group with the group's own key */
-               aes_setup(opened_key, &group->group_key);
-               if (aes_cmac_verify(&disk.group_mac, &disk.v, sizeof(disk.v), opened_key)) {
-                       printk("Group CMAC failed\n");
-                       return 2;
-               }
-
-               memcpy(&group->id_data, &disk.v.id_data, sizeof(group->id_data));
-               memcpy(&group->details, &disk.v.details, sizeof(group->details));
-       } else if (rc == 1) {
-               // still need to walk the vtpm list
-               rc = 0;
-       } else {
-               printk("Group key unsealing failed\n");
-               return rc;
-       }
-
-       group->nr_vtpms = be32_native(disk.v.nr_vtpms);
-       group->nr_pages = (group->nr_vtpms + VTPMS_PER_SECTOR - 1) / VTPMS_PER_SECTOR;
-
-       group->data = calloc(group->nr_pages, sizeof(group->data[0]));
-
-       rc = load_verify_vtpm_itree(dst, 0, group->nr_pages, disk.v.vtpm_hash,
-                       disk.vtpm_location, NR_ENTRIES_PER_GROUP_BASE, mgr, opened_key);
-
-       if (!opened_key) {
-               /* remove the struct */
-               free(group->data);
-               free(group->seals);
-               free(group);
-               dst->v = NULL;
-       }
-
-       return rc;
-}
-
-static int load_root_pre(struct disk_root_sector *root, struct mem_tpm_mgr *dst)
-{
-       int rc;
-
-       aes_setup(&dst->tm_key_e, &dst->tm_key);
-
-       rc = disk_read_crypt_sector(root, sizeof(*root), root_loc(dst), dst);
-
-       if (rc) {
-               vtpmloginfo(VTPM_LOG_VTPM, "root cmac verify failed in slot %d\n", dst->active_root);
-               return 2;
-       }
-
-       dst->root_seals_valid = 1 + dst->active_root;
-       dst->sequence = be64_native(root->v.sequence);
-
-       return 0;
-}
-
-static int load_verify_group_itree(struct mem_tpm_mgr *dst, int base, int nr_entries,
-               const struct hash256 *hash, const sector_t *loc, int hsize);
-
-static int load_verify_group_itree(struct mem_tpm_mgr *dst, int base, int nr_entries,
-               const struct hash256 *hash, const sector_t *loc, int hsize)
-{
-       int i, rc, incr = 1;
-
-       if (nr_entries <= hsize) {
-               for(i=0; i < nr_entries; i++) {
-                       struct mem_group_hdr *group = dst->groups + base + i;
-                       group->disk_loc = loc[i];
-                       memcpy(&group->disk_hash, &hash[i], sizeof(group->disk_hash));
-                       rc = load_verify_group(group, dst);
-                       if (rc) {
-                               printk("Error loading group %d\n", base + i);
-                               return rc;
-                       }
-               }
-               return 0;
-       }
-
-       // increase tree depth until all entries fit
-       while (nr_entries > incr * hsize)
-               incr *= NR_ENTRIES_PER_ITREE;
-
-       for (i = 0; i * incr < nr_entries; i++) {
-               struct disk_itree_sector pt;
-               int child_entries = incr;
-
-               // the last sector is not completely full
-               if (nr_entries - i * incr < incr)
-                       child_entries = nr_entries - i * incr;
-
-               disk_set_used(loc[i], dst);
-
-               rc = disk_read_crypt_sector(&pt, sizeof(pt), loc[i], dst);
-               if (rc) {
-                       printk("Malformed sector %d\n", be32_native(loc[i]));
-                       return rc;
-               }
-
-               rc = sha256_verify(&hash[i], pt.hash, sizeof(pt.hash));
-               if (rc) {
-                       printk("Hash mismatch in sector %d\n", be32_native(loc[i]));
-                       return rc;
-               }
-
-               rc = load_verify_group_itree(dst, base, child_entries, pt.hash, pt.location, NR_ENTRIES_PER_ITREE);
-               if (rc)
-                       return rc;
-
-               base += incr;
-       }
-
-       return 0;
-}
-
-static int load_root_post(struct mem_tpm_mgr *dst, const struct disk_root_sector *root)
-{
-       int rc, i, j;
-       uint32_t nr_disk_rbs = be32_native(root->nr_rb_macs);
-
-       rc = TPM_disk_check_counter(dst->counter_index, dst->counter_auth,
-                       root->v.tpm_counter_value);
-       if (rc)
-               return 2;
-       dst->counter_value = root->v.tpm_counter_value;
-
-       dst->nr_groups = be32_native(root->v.nr_groups);
-       dst->groups = calloc(sizeof(dst->groups[0]), dst->nr_groups);
-
-       if (!dst->groups) {
-               vtpmlogerror(VTPM_LOG_VTPM, "load_root_post alloc %x\n", dst->nr_groups);
-               return 2;
-       }
-
-       rc = load_verify_group_itree(dst, 0, dst->nr_groups,
-                       root->v.group_hash, root->group_loc, NR_ENTRIES_PER_ROOT);
-       if (rc)
-               return rc;
-
-       /* Sanity check: group0 must be open */
-       if (!dst->groups[0].v) {
-               printk("Error opening group 0\n");
-               return 2;
-       }
-
-       /* TODO support for spilling rollback list */
-       if (nr_disk_rbs > NR_RB_MACS_PER_ROOT)
-               return 3;
-
-       i = 0;
-       j = 0;
-       while (i < dst->nr_groups) {
-               aes_context key_e;
-               struct mem_group_hdr *group = &dst->groups[i];
-               struct mem_group *groupv = group->v;
-               const struct disk_rb_mac_entry *ent = &root->rb_macs[j];
-
-               if (!groupv) {
-                       i++;
-                       // this group is not open - no need to verify now
-                       continue;
-               }
-
-               if (be32_native(ent->id) < i) {
-                       // this entry is for a group that is not open
-                       j++;
-                       continue;
-               }
-
-               if (j >= nr_disk_rbs || be32_native(ent->id) != i) {
-                       // TODO allow delegation
-                       if (!(groupv->details.flags.value & FLAG_ROLLBACK_DETECTED)) {
-                               groupv->details.flags.value |= FLAG_ROLLBACK_DETECTED;
-                               group->disk_loc.value = 0;
-                       }
-                       i++;
-                       continue;
-               }
-
-               aes_setup(&key_e, &groupv->rollback_mac_key);
-               if (aes_cmac_verify(&ent->mac, &root->v, sizeof(root->v), &key_e)) {
-                       if (!(groupv->details.flags.value & FLAG_ROLLBACK_DETECTED)) {
-                               groupv->details.flags.value |= FLAG_ROLLBACK_DETECTED;
-                               group->disk_loc.value = 0;
-                       }
-               }
-               i++; j++;
-       }
-
-       return 0;
-}
-
-int vtpm_load_disk(void)
-{
-       struct disk_root_sector root1, root2;
-       int rc = 0;
-       TPM_read_pcrs();
-
-       printk("TPM Manager - disk format %d\n", TPM_MGR_VERSION);
-       printk(" root seal: %zu; sector of %d: %zu\n",
-               sizeof(struct disk_root_sealed_data), SEALS_PER_ROOT_SEAL_LIST, sizeof(struct disk_seal_list));
-       printk(" root: %zu v=%zu\n", sizeof(root1), sizeof(root1.v));
-       printk(" itree: %u; sector of %d: %zu\n",
-               4 + 32, NR_ENTRIES_PER_ITREE, sizeof(struct disk_itree_sector));
-       printk(" group: %zu v=%zu id=%zu md=%zu\n",
-               sizeof(struct disk_group_sector), sizeof(struct disk_group_sector_mac3_area),
-               sizeof(struct group_id_data), sizeof(struct group_details));
-       printk(" group seal: %zu; %d in parent: %zu; sector of %d: %zu\n",
-               sizeof(struct disk_group_sealed_data), NR_SEALS_PER_GROUP, sizeof(struct disk_group_boot_config_list),
-               SEALS_PER_GROUP_SEAL_LIST, sizeof(struct disk_group_seal_list));
-       printk(" vtpm: %zu+%zu; sector of %d: %zu\n",
-               sizeof(struct disk_vtpm_plain), sizeof(struct disk_vtpm_secret),
-               VTPMS_PER_SECTOR, sizeof(struct disk_vtpm_sector));
-
-       struct mem_tpm_mgr *mgr1 = find_root_key(0);
-       struct mem_tpm_mgr *mgr2 = find_root_key(1);
-
-       rc = mgr1 ? load_root_pre(&root1, mgr1) : 0;
-       if (rc) {
-               mgr_free(mgr1);
-               mgr1 = NULL;
-       }
-
-       rc = mgr2 ? load_root_pre(&root2, mgr2) : 0;
-       if (rc) {
-               mgr_free(mgr2);
-               mgr2 = NULL;
-       }
-
-       printk("load_root_pre: %c/%c\n", mgr1 ? 'y' : 'n', mgr2 ? 'y' : 'n');
-
-       if (!mgr1 && !mgr2)
-               return 2;
-
-       if (mgr1 && mgr2 && mgr2->sequence > mgr1->sequence) {
-               rc = load_root_post(mgr2, &root2);
-               if (rc) {
-                       mgr_free(mgr2);
-                       mgr2 = NULL;
-               } else {
-                       mgr_free(mgr1);
-                       g_mgr = mgr2;
-                       return 0;
-               }
-       }
-       if (mgr1) {
-               rc = load_root_post(mgr1, &root1);
-               if (rc) {
-                       mgr_free(mgr1);
-               } else {
-                       mgr_free(mgr2);
-                       g_mgr = mgr1;
-                       return 0;
-               }
-       }
-       if (mgr2) {
-               rc = load_root_post(mgr2, &root2);
-               if (rc) {
-                       mgr_free(mgr2);
-               } else {
-                       g_mgr = mgr2;
-                       return 0;
-               }
-       }
-       printk("Could not read vTPM disk\n");
-
-       return 2;
-}
diff --git a/stubdom/vtpmmgr/disk_tpm.c b/stubdom/vtpmmgr/disk_tpm.c
deleted file mode 100644 (file)
index 45a326a..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/* TPM disk interface */
-#include <blkfront.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-#include <mini-os/lib.h>
-#include <polarssl/aes.h>
-#include <polarssl/sha1.h>
-
-#include "tpm.h"
-#include "tpm2.h"
-#include "tcg.h"
-
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_tpm.h"
-
-#include "log.h"
-// Print out input/output of seal/unseal operations (includes keys)
-#undef DEBUG_SEAL_OPS
-
-#ifdef DEBUG_SEAL_OPS
-#include "marshal.h"
-#include "tpm2_marshal.h"
-#endif
-
-struct pcr_list {
-       TPM_DIGEST pcrs[24];
-};
-
-static struct pcr_list hwtpm;
-
-/*Ignore PCR on TPM 2.0, read PCR values for TPM 1.x seal | unseal*/
-void TPM_read_pcrs(void)
-{
-       int i;
-       for (i=0; i < 24; i++) {
-        if (hw_is_tpm2())
-            tpm2_pcr_read(i, (uint8_t *)&hwtpm.pcrs[i]);
-        else
-                   TPM_PCR_Read(i, &hwtpm.pcrs[i]);
-    }
-}
-
-struct pcr_composite_3 {
-       be16_t sel_size;
-       uint8_t sel[3];
-       be32_t val_size;
-       uint8_t val[0];
-} __attribute__((packed));
-
-void TPM_pcr_digest(struct hash160 *buf, le32_t selection)
-{
-       int i;
-       int count = 0;
-       uint32_t sel = le32_native(selection);
-       struct pcr_composite_3 *v;
-       for(i=0; i < 24; i++) {
-               if (sel & (1 << i))
-                       count++;
-       }
-       v = alloca(sizeof(*v) + 20 * count);
-       v->sel_size = native_be16(3);
-       memcpy(v->sel, &selection, 3);
-       v->val_size = native_be32(20 * count);
-
-       count = 0;
-       for(i=0; i < 24; i++) {
-               if (sel & (1 << i)) {
-                       memcpy(v->val + 20 * count, &hwtpm.pcrs[i], 20);
-                       count++;
-               }
-       }
-
-       sha1((void*)v, sizeof(*v) + 20 * count, buf->bits);
-}
-
-
-int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)
-{
-       uint32_t rc;
-       uint32_t infoSize;
-       TPM_PCR_INFO_LONG info;
-       TPM_STORED_DATA12 out;
-       TPM_AUTH_SESSION osap = TPM_AUTH_SESSION_INIT;
-       TPM_AUTHDATA sharedsecret;
-       TPM_AUTHDATA auth;
-
-       printk("Calling TPM_disk_seal\n");
-
-       rc = TPM_OSAP(TPM_ET_KEYHANDLE, TPM_SRK_KEYHANDLE, (void*)&vtpm_globals.srk_auth,
-                       &sharedsecret, &osap);
-
-       if (rc) abort();
-
-#ifdef DEBUG_SEAL_OPS
-       int i;
-       printk("to-seal:");
-       for(i=0; i < size; i++)
-               printk(" %02x", ((uint8_t*)src)[i]);
-       printk("\n");
-#endif
-
-       memset(auth, 0, 20);
-       info.tag = TPM_TAG_PCR_INFO_LONG;
-       info.localityAtCreation = 1 << vtpm_globals.hw_locality;
-       info.localityAtRelease = 1 << vtpm_globals.hw_locality;
-       info.creationPCRSelection.sizeOfSelect = 3;
-       info.creationPCRSelection.pcrSelect = (void*)&dst->pcr_selection;
-       info.releasePCRSelection.sizeOfSelect = 3;
-       info.releasePCRSelection.pcrSelect = (void*)&dst->pcr_selection;
-       memcpy(&info.digestAtCreation, &dst->digest_at_seal, 20);
-       memcpy(&info.digestAtRelease, &dst->digest_release, 20);
-
-       infoSize = 2 + 1 + 1 + 2 + 3 + 2 + 3 + 20 + 20;
-       //infoSize = sizeof_TPM_PCR_INFO_LONG(&info);
-
-       rc = TPM_Seal(TPM_SRK_KEYHANDLE, infoSize, &info, size, src, &out,
-                       (void*)&sharedsecret, (void*)&auth, &osap);
-
-       TPM_TerminateHandle(osap.AuthHandle);
-
-#ifdef DEBUG_SEAL_OPS
-       printk("TPM_Seal rc=%d encDataSize=%d sealInfoSize=%d\n", rc, out.encDataSize, out.sealInfoLongSize);
-#endif
-       if (!rc)
-               memcpy(dst->sealed_data, out.encData, 256);
-
-#ifdef DEBUG_SEAL_OPS
-       uint8_t buf[512];
-       uint8_t *start = buf;
-       uint8_t *end = pack_TPM_STORED_DATA12(buf, &out);
-       printk("stored_data:");
-       while (start != end) {
-               printk(" %02x", *start);
-               start++;
-       }
-       printk("\n");
-#endif
-
-       free_TPM_STORED_DATA12(&out);
-       return rc;
-}
-
-TPM_RC TPM2_disk_bind(struct disk_seal_entry *dst, void* src, unsigned int size)
-{
-    TPM_RESULT status = TPM_SUCCESS;
-
-    TPMTRYRETURN(TPM2_Bind(vtpm_globals.sk_handle,
-                           src,
-                           size,
-                           dst->sealed_data));
-
-abort_egress:
-egress:
-   return status;
-}
-
-TPM_RC TPM2_disk_unbind(void *dst, unsigned int *size, const struct disk_seal_entry *src)
-{
-    TPM_RESULT status = TPM_SUCCESS;
-    unsigned char buf[RSA_CIPHER_SIZE];
-
-    memcpy(buf, src->sealed_data, RSA_CIPHER_SIZE);
-    TPMTRYRETURN(TPM2_UnBind(vtpm_globals.sk_handle,
-                             RSA_CIPHER_SIZE,
-                             buf,
-                             size,
-                             dst));
-abort_egress:
-egress:
-   return status;
-}
-
-int TPM_disk_unseal(void *dst, size_t size, const struct disk_seal_entry *src)
-{
-       uint32_t rc;
-       TPM_STORED_DATA12 in;
-       TPM_AUTH_SESSION oiap = TPM_AUTH_SESSION_INIT;
-       TPM_AUTHDATA auth;
-       uint32_t outSize = 0;
-       uint8_t *out = NULL;
-
-       printk("Calling TPM_disk_unseal\n");
-
-       rc = TPM_OIAP(&oiap);
-       if (rc) abort();
-
-       memset(auth, 0, 20);
-
-       in.tag = TPM_TAG_STORED_DATA12;
-       in.et = 0;
-       //in.sealInfoLongSize = sizeof_TPM_PCR_INFO_LONG(&in.sealInfoLong);
-       in.sealInfoLongSize = 2 + 1 + 1 + 2 + 3 + 2 + 3 + 20 + 20;
-       in.sealInfoLong.tag = TPM_TAG_PCR_INFO_LONG;
-       in.sealInfoLong.localityAtCreation = 1 << vtpm_globals.hw_locality;
-       in.sealInfoLong.localityAtRelease = 1 << vtpm_globals.hw_locality;
-       in.sealInfoLong.creationPCRSelection.sizeOfSelect = 3;
-       in.sealInfoLong.creationPCRSelection.pcrSelect = (void*)&src->pcr_selection;
-       in.sealInfoLong.releasePCRSelection.sizeOfSelect = 3;
-       in.sealInfoLong.releasePCRSelection.pcrSelect = (void*)&src->pcr_selection;
-       memcpy(&in.sealInfoLong.digestAtCreation, &src->digest_at_seal, 20);
-       memcpy(&in.sealInfoLong.digestAtRelease, &src->digest_release, 20);
-       in.encDataSize = 256;
-       in.encData = (void*)src->sealed_data;
-
-#ifdef DEBUG_SEAL_OPS
-       uint8_t buf[512];
-       uint8_t *start = buf;
-       uint8_t *end = pack_TPM_STORED_DATA12(buf, &in);
-       printk("stored_data:");
-       while (start != end) {
-               printk(" %02x", *start);
-               start++;
-       }
-       printk("\n");
-#endif
-
-       rc = TPM_Unseal(TPM_SRK_KEYHANDLE, &in, &outSize, &out,
-                       (void*)&vtpm_globals.srk_auth, (void*)&auth, &vtpm_globals.oiap, &oiap);
-
-       TPM_TerminateHandle(oiap.AuthHandle);
-
-#ifdef DEBUG_SEAL_OPS
-       printk("TPM_Unseal rc=%d outSize=%d size=%d\n", rc, outSize, size);
-#endif
-       if (!rc) {
-               memcpy(dst, out, size);
-#ifdef DEBUG_SEAL_OPS
-               printk("unsealed:");
-               int i;
-               for(i=0; i < size; i++)
-                       printk(" %02x", ((uint8_t*)dst)[i]);
-               printk("\n");
-#endif
-       }
-
-       free(out);
-
-       return rc;
-}
-
-int TPM_disk_nvalloc(be32_t *nvram_slot, struct tpm_authdata auth)
-{
-       // TODO-3
-       nvram_slot->value = 0;
-       return 0;
-}
-
-int TPM_disk_nvread(void *buf, size_t bufsiz, be32_t nvram_slot, struct tpm_authdata auth)
-{
-       // TODO-3
-       memset(buf, 0, bufsiz);
-       return 0;
-}
-
-int TPM_disk_nvwrite(void *buf, size_t bufsiz, be32_t nvram_slot, struct tpm_authdata auth)
-{
-       // TODO-3
-       return 0;
-}
-
-int TPM_disk_nvchange(be32_t nvram_slot, struct tpm_authdata old, struct tpm_authdata noo)
-{
-       // TODO-3
-       return 0;
-}
-
-int TPM_disk_alloc_counter(be32_t *slot, struct tpm_authdata auth, be32_t *value)
-{
-       // TODO-3
-       slot->value = 0;
-       value->value = 0;
-       return 0;
-}
-
-int TPM_disk_check_counter(be32_t slot, struct tpm_authdata auth, be32_t value)
-{
-       // TODO-3
-       return 0;
-}
-
-int TPM_disk_incr_counter(be32_t slot, struct tpm_authdata auth)
-{
-       // TODO-3
-       return 0;
-}
-
-int TPM_disk_change_counter(be32_t slot, struct tpm_authdata old, struct tpm_authdata noo)
-{
-       // TODO-3
-       return 0;
-}
diff --git a/stubdom/vtpmmgr/disk_tpm.h b/stubdom/vtpmmgr/disk_tpm.h
deleted file mode 100644 (file)
index 57ae2a6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __VTPMMGR_DISK_VTPM_H
-#define __VTPMMGR_DISK_VTPM_H
-#include "vtpm_disk.h"
-
-/* Read PCR values to determine which unseal to try */
-void TPM_read_pcrs(void);
-void TPM_pcr_digest(struct hash160 *buf, le32_t selection);
-
-/* Sealing for key storage */
-int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size);
-int TPM_disk_unseal(void *dst, size_t size, const struct disk_seal_entry *src);
-
-/*TPM 2.0 Bind and Unbind */
-TPM_RC TPM2_disk_bind(struct disk_seal_entry *dst, void* src, unsigned int size);
-TPM_RC TPM2_disk_unbind(void *dst, unsigned int *size, const struct disk_seal_entry *src);
-
-/* NVRAM to allow revocation of TM-KEY */
-int TPM_disk_nvalloc(be32_t *nvram_slot, struct tpm_authdata auth);
-int TPM_disk_nvread(void *buf, size_t bufsiz, be32_t nvram_slot, struct tpm_authdata auth);
-int TPM_disk_nvwrite(void *buf, size_t bufsiz, be32_t nvram_slot, struct tpm_authdata auth);
-int TPM_disk_nvchange(be32_t nvram_slot, struct tpm_authdata old, struct tpm_authdata noo);
-
-/* Monotonic counters to detect rollback */
-int TPM_disk_alloc_counter(be32_t *slot, struct tpm_authdata auth, be32_t *value);
-int TPM_disk_check_counter(be32_t slot, struct tpm_authdata auth, be32_t value);
-int TPM_disk_incr_counter(be32_t slot, struct tpm_authdata auth);
-int TPM_disk_change_counter(be32_t slot, struct tpm_authdata old, struct tpm_authdata noo);
-
-#endif
diff --git a/stubdom/vtpmmgr/disk_write.c b/stubdom/vtpmmgr/disk_write.c
deleted file mode 100644 (file)
index ab15a9a..0000000
+++ /dev/null
@@ -1,419 +0,0 @@
-#include <console.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-
-#include "vtpm_manager.h"
-#include "log.h"
-#include "uuid.h"
-
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_tpm.h"
-#include "disk_io.h"
-#include "disk_crypto.h"
-#include "disk_format.h"
-#include "mgmt_authority.h"
-
-static void disk_write_crypt_sector(sector_t *dst, const void *data, size_t size, const struct mem_tpm_mgr *mgr)
-{
-       struct disk_crypt_sector_plain *sector = disk_write_buf();
-       *dst = disk_find_free(mgr);
-       aes_encrypt_ctr(sector->iv_data, sizeof(sector->iv_data), data, size, &mgr->tm_key_e);
-       aes_cmac(&sector->mac, sector->data, sizeof(sector->data), &mgr->tm_key_e);
-       disk_write_sector(*dst, sector, sizeof(*sector));
-}
-
-/*
- * Mark unchanged sectors on disk as being used
- */
-static void disk_populate_used_vtpm(const struct mem_vtpm_page *src, const struct mem_tpm_mgr *mgr)
-{
-       if (be32_native(src->disk_loc) != 0)
-               disk_set_used(src->disk_loc, mgr);
-}
-
-/*
- * Write out a vTPM page to disk, doing nothing if the existing copy is valid
- */
-static void disk_write_vtpm_page(struct mem_vtpm_page *dst, const aes_context *auth_key,
-               const struct mem_tpm_mgr *mgr)
-{
-       struct disk_vtpm_sector pt;
-       int i;
-       memset(&pt, 0, sizeof(pt));
-       if (be32_native(dst->disk_loc) != 0)
-               return;
-
-       for(i=0; i < dst->size; i++) {
-               memcpy(pt.header[i].uuid, dst->vtpms[i]->uuid, 16);
-               memcpy(pt.data[i].data, dst->vtpms[i]->data, 64);
-               pt.header[i].flags = native_be32(dst->vtpms[i]->flags & VTPM_FLAG_DISK_MASK);
-       }
-       aes_encrypt_ctr(&pt.iv, sizeof(pt.data) + 16, &pt.data, sizeof(pt.data), auth_key);
-
-       sha256(&dst->disk_hash, &pt, sizeof(pt));
-
-       disk_write_crypt_sector(&dst->disk_loc, &pt, sizeof(pt), mgr);
-}
-
-/*
- * Generate TPM seal blobs for a group's keys; do nothing if existing copy is valid
- */
-static void generate_group_seals(struct mem_group *src, const struct mem_tpm_mgr *parent)
-{
-       int i;
-       struct disk_group_sealed_data sblob;
-
-       // previous seals are still valid, skip talking to the TPM
-       if (src->flags & MEM_GROUP_FLAG_SEAL_VALID)
-               return;
-
-       memcpy(&sblob.magic, DISK_GROUP_BOUND_MAGIC, 4);
-       memcpy(sblob.tpm_manager_uuid, parent->uuid, 16);
-       memcpy(&sblob.aik_authdata, &src->aik_authdata, 20);
-       memcpy(&sblob.group_key, &src->group_key, 16);
-       memcpy(&sblob.rollback_mac_key, &src->rollback_mac_key, 16);
-
-       /* TODO support for more than NR_SEALS_PER_GROUP seals */
-       if (src->nr_seals > NR_SEALS_PER_GROUP)
-               abort();
-
-       for(i=0; i < src->nr_seals; i++) {
-               struct disk_seal_entry *dst = &src->seal_bits.entry[i];
-               dst->pcr_selection = src->seals[i].pcr_selection;
-               memcpy(&dst->digest_release, &src->seals[i].digest_release, 20);
-               TPM_pcr_digest(&dst->digest_at_seal, dst->pcr_selection);
-
-        /*TPM 2.0 bind | TPM 1.x seal*/
-        if (hw_is_tpm2())
-            TPM2_disk_bind(dst, &sblob, sizeof(sblob));
-        else
-            TPM_disk_seal(dst, &sblob, sizeof(sblob));
-       }
-       src->seal_bits.nr_cfgs = native_be32(src->nr_seals);
-
-       src->flags |= MEM_GROUP_FLAG_SEAL_VALID;
-}
-
-/*
- * Mark unchanged sectors on disk as being used
- */
-static void disk_populate_used_group(const struct mem_group_hdr *src, const struct mem_tpm_mgr *mgr)
-{
-       int i;
-       struct mem_group *group = src->v;
-       if (be32_native(src->disk_loc) != 0) {
-               // entire group is unchanged - mark group, itree, and vtpm sectors
-               // TODO mark other children (seal)
-               disk_set_used(src->disk_loc, mgr);
-               for(i = 0; i < src->disk_nr_inuse; i++)
-                       disk_set_used(src->disk_inuse[i], mgr);
-               return;
-       }
-
-       // unopened groups should never have been invalidated
-       if (!group)
-               abort();
-
-       for (i = 0; i < group->nr_pages; i++)
-               disk_populate_used_vtpm(&group->data[i], mgr);
-}
-
-static void disk_write_vtpm_itree(struct mem_group_hdr *hdr, int base, int nr_entries,
-               struct hash256 *hash, sector_t *loc, int hsize,
-               const aes_context *group_key, const struct mem_tpm_mgr *mgr);
-
-static void disk_write_vtpm_itree(struct mem_group_hdr *hdr, int base, int nr_entries,
-               struct hash256 *hash, sector_t *loc, int hsize,
-               const aes_context *group_key, const struct mem_tpm_mgr *mgr)
-{
-       int i, incr = 1, inuse_base, lsize;
-
-       while (nr_entries > incr * hsize)
-               incr *= NR_ENTRIES_PER_ITREE;
-
-       if (nr_entries <= hsize) {
-               struct mem_group *group = hdr->v;
-               for (i = 0; i < nr_entries; i++) {
-                       struct mem_vtpm_page *page = group->data + base + i;
-                       disk_write_vtpm_page(page, group_key, mgr);
-                       loc[i] = page->disk_loc;
-                       hash[i] = page->disk_hash;
-               }
-       } else {
-               for (i = 0; i * incr < nr_entries; i++) {
-                       struct disk_itree_sector pt;
-                       int child_entries = incr;
-
-                       // the last sector is not completely full
-                       if (nr_entries - i * incr < incr)
-                               child_entries = nr_entries - i * incr;
-
-                       disk_write_vtpm_itree(hdr, base, child_entries, pt.hash, pt.location,
-                                       NR_ENTRIES_PER_ITREE, group_key, mgr);
-
-                       sha256(&hash[i], &pt.hash, sizeof(pt.hash));
-                       disk_write_crypt_sector(&loc[i], &pt, sizeof(pt), mgr);
-
-                       base += incr;
-               }
-       }
-
-       // save the list of used sectors (itree and vtpm) in the header
-       inuse_base = hdr->disk_nr_inuse;
-       lsize = 1 + (nr_entries - 1) / incr;
-       hdr->disk_nr_inuse += lsize;
-       hdr->disk_inuse = realloc(hdr->disk_inuse, hdr->disk_nr_inuse * sizeof(sector_t));
-       memcpy(&hdr->disk_inuse[inuse_base], loc, lsize * sizeof(sector_t));
-}
-
-/*
- * Write out a vTPM group sector and its children
- */
-static void disk_write_group_sector(struct mem_group_hdr *src,
-               const struct mem_tpm_mgr *mgr)
-{
-       struct disk_group_sector disk;
-       struct mem_group *group = src->v;
-       aes_context key_e;
-
-       /* Don't write if the data hasn't changed */
-       if (be32_native(src->disk_loc) != 0)
-               return;
-
-       // if the group was not opened, it should not have been changed
-       if (!group)
-               abort();
-
-       memset(&disk, 0, sizeof(disk));
-       memcpy(&disk.v.id_data, &group->id_data, sizeof(disk.v.id_data));
-       memcpy(&disk.v.details, &group->details, sizeof(disk.v.details));
-
-       aes_setup(&key_e, &group->group_key);
-
-       disk.v.nr_vtpms = native_be32(group->nr_vtpms);
-
-       // regenerated
-       src->disk_nr_inuse = 0;
-
-       disk_write_vtpm_itree(src, 0, group->nr_pages, disk.v.vtpm_hash, disk.vtpm_location,
-                       NR_ENTRIES_PER_GROUP_BASE, &key_e, mgr);
-
-       generate_group_seals(group, mgr);
-       memcpy(&disk.v.boot_configs, &group->seal_bits, sizeof(group->seal_bits));
-
-       aes_cmac(&disk.group_mac, &disk.v, sizeof(disk.v), &key_e);
-       sha256(&src->disk_hash, &disk.v, sizeof(disk.v) + sizeof(disk.group_mac));
-       disk_write_crypt_sector(&src->disk_loc, &disk, sizeof(disk), mgr);
-}
-
-/*
- * Write TPM seal blobs for the manager's keys, using the given group's list
- * of valid configurations
- */
-static void disk_write_seal_list(struct mem_tpm_mgr *mgr, struct mem_group *group)
-{
-       int i;
-       struct disk_seal_list *seal = disk_write_buf();
-       struct disk_root_sealed_data sblob;
-
-       if (mgr->root_seals_valid & (1 + mgr->active_root))
-               return;
-
-       memcpy(&sblob.magic, DISK_ROOT_BOUND_MAGIC, 4);
-       memcpy(sblob.tpm_manager_uuid, mgr->uuid, 16);
-       memcpy(&sblob.nvram_slot, &mgr->nvram_slot, 4);
-       memcpy(&sblob.nvram_auth, &mgr->nvram_auth, 20);
-       memcpy(&sblob.counter_index, &mgr->counter_index, 4);
-       memcpy(&sblob.counter_auth, &mgr->counter_auth, 20);
-
-       // TODO when an NV slot in the physical TPM is used to populate nv_key,
-       // that value should be used to mask the master key so that the value
-       // can be changed to revoke old disk state
-#if 0
-       aes_encrypt_one(&sblob.tm_key, &mgr->tm_key, &mgr->nv_key);
-#else
-       memcpy(&sblob.tm_key, &mgr->tm_key, 16);
-#endif
-
-       memset(seal, 0, sizeof(*seal));
-       seal->length = native_be32(group->nr_seals);
-
-       // TODO support for more entries
-       if (group->nr_seals > SEALS_PER_ROOT_SEAL_LIST)
-               abort();
-
-       for(i=0; i < group->nr_seals; i++) {
-               struct mem_seal *src = &group->seals[i];
-               struct disk_seal_entry *dst = &seal->entry[i];
-               dst->pcr_selection = src->pcr_selection;
-               memcpy(&dst->digest_release, &src->digest_release, 20);
-               TPM_pcr_digest(&dst->digest_at_seal, dst->pcr_selection);
-
-        /*TPM 2.0 bind / TPM 1.x seal*/
-        if (hw_is_tpm2())
-            TPM2_disk_bind(dst, &sblob, sizeof(sblob));
-        else
-            TPM_disk_seal(dst, &sblob, sizeof(sblob));
-       }
-
-       memcpy(seal->hdr.magic, TPM_MGR_MAGIC, 12);
-       seal->hdr.version = native_be32(TPM_MGR_VERSION);
-
-       disk_write_sector(seal_loc(mgr), seal, sizeof(*seal));
-       mgr->root_seals_valid |= 1 + mgr->active_root;
-}
-
-/*
- * Mark unchanged sectors on disk as being used
- */
-static void disk_populate_used_mgr(const struct mem_tpm_mgr *mgr)
-{
-       int i;
-
-       // TODO walk the linked lists for seals, rb_macs here (when supported)
-
-       for(i=0; i < mgr->nr_groups; i++)
-               disk_populate_used_group(&mgr->groups[i], mgr);
-}
-
-static void disk_write_group_itree(struct mem_tpm_mgr *mgr, int base, int nr_entries,
-               struct hash256 *hash, sector_t *loc, int hsize);
-
-static void disk_write_group_itree(struct mem_tpm_mgr *mgr, int base, int nr_entries,
-               struct hash256 *hash, sector_t *loc, int hsize)
-{
-       int i, incr = 1;
-
-       if (nr_entries <= hsize) {
-               for(i=0; i < mgr->nr_groups; i++) {
-                       struct mem_group_hdr *group = mgr->groups + base + i;
-                       disk_write_group_sector(group, mgr);
-                       loc[i] = group->disk_loc;
-                       hash[i] = group->disk_hash;
-               }
-               return;
-       }
-
-       while (nr_entries > incr * hsize)
-               incr *= NR_ENTRIES_PER_ITREE;
-
-       for (i = 0; i * incr < nr_entries; i++) {
-               struct disk_itree_sector pt;
-               int child_entries = incr;
-
-               // the last sector is not completely full
-               if (nr_entries - i * incr < incr)
-                       child_entries = nr_entries - i * incr;
-
-               disk_write_group_itree(mgr, base, child_entries, pt.hash, pt.location, NR_ENTRIES_PER_ITREE);
-
-               sha256(&hash[i], &pt.hash, sizeof(pt.hash));
-               disk_write_crypt_sector(&loc[i], &pt, sizeof(pt), mgr);
-
-               base += incr;
-       }
-}
-
-/*
- * Write out the root TPM Manager sector and its children
- */
-static void disk_write_root_sector(struct mem_tpm_mgr *mgr)
-{
-       int i, j;
-       struct disk_root_sector root;
-       memset(&root, 0, sizeof(root));
-       root.v.sequence = native_be64(mgr->sequence);
-       root.v.tpm_counter_value = mgr->counter_value;
-
-       root.v.nr_groups = native_be32(mgr->nr_groups);
-
-       disk_write_group_itree(mgr, 0, mgr->nr_groups, root.v.group_hash, root.group_loc, NR_ENTRIES_PER_ROOT);
-
-       i = 0;
-       j = 0;
-       while (i < mgr->nr_groups) {
-               aes_context key_e;
-               struct mem_group_hdr *group = &mgr->groups[i];
-               struct mem_group *groupv = group->v;
-
-               if (!groupv) {
-                       i++;
-                       continue;
-               }
-               if (groupv->details.flags.value & FLAG_ROLLBACK_DETECTED) {
-                       i++;
-                       continue;
-               }
-               if (j >= NR_RB_MACS_PER_ROOT)
-                       break; // TODO support for nr_rb_macs > 128
-
-               aes_setup(&key_e, &groupv->rollback_mac_key);
-               root.rb_macs[j].id = native_be32(i);
-               aes_cmac(&root.rb_macs[j].mac, &root.v, sizeof(root.v), &key_e);
-               i++; j++;
-       }
-       root.nr_rb_macs = native_be32(j);
-
-       struct disk_crypt_sector_plain *root_sect = disk_write_buf();
-       aes_encrypt_ctr(root_sect->iv_data, sizeof(root_sect->iv_data), &root, sizeof(root), &mgr->tm_key_e);
-       aes_cmac(&root_sect->mac, &root_sect->data, sizeof(root_sect->data), &mgr->tm_key_e);
-       disk_write_sector(root_loc(mgr), root_sect, sizeof(*root_sect));
-}
-
-/*
- * Write out changes to disk
- */
-void disk_write_all(struct mem_tpm_mgr *mgr)
-{
-       disk_flush_slot(mgr);
-       disk_populate_used_mgr(mgr);
-       disk_write_root_sector(mgr);
-
-       disk_write_seal_list(mgr, mgr->groups[0].v);
-
-       disk_write_barrier();
-}
-
-/*
- * Create a new (blank) TPM Manager disk image.
- *
- * Does not actually write anything to disk.
- */
-int vtpm_new_disk(void)
-{
-       int rc;
-       struct mem_tpm_mgr *mgr = calloc(1, sizeof(*mgr));
-
-       do_random(mgr->uuid, 16);
-       do_random(&mgr->tm_key, 16);
-       do_random(&mgr->nvram_auth, 20);
-       do_random(&mgr->counter_auth, 20);
-       do_random(&mgr->nv_key, 16);
-
-       aes_setup(&mgr->tm_key_e, &mgr->tm_key);
-
-       // TODO postpone these allocs until first write?
-       rc = TPM_disk_nvalloc(&mgr->nvram_slot, mgr->nvram_auth);
-       if (rc)
-               return rc;
-
-       rc = TPM_disk_alloc_counter(&mgr->counter_index, mgr->counter_auth, &mgr->counter_value);
-       if (rc)
-               return rc;
-
-       mgr->nr_groups = 1;
-       mgr->groups = calloc(1, sizeof(mgr->groups[0]));
-       mgr->groups[0].v = vtpm_new_group(NULL);
-
-       TPM_disk_nvwrite(&mgr->nv_key, 16, mgr->nvram_slot, mgr->nvram_auth);
-
-       g_mgr = mgr;
-
-       return 0;
-}
diff --git a/stubdom/vtpmmgr/endian_int.h b/stubdom/vtpmmgr/endian_int.h
deleted file mode 100644 (file)
index 030f87b..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef __VTPMMGR_ENDIAN_INT_H
-#define __VTPMMGR_ENDIAN_INT_H
-
-#include <mini-os/byteorder.h>
-
-/* These wrapper structs force the use of endian-to-CPU conversions */
-
-typedef struct be_int16 {
-       uint16_t value;
-} be16_t;
-
-typedef struct be_int32 {
-       uint32_t value;
-} be32_t;
-
-typedef struct le_int32 {
-       uint32_t value;
-} le32_t;
-
-typedef struct be_int64 {
-       uint64_t value;
-} be64_t;
-
-static inline uint16_t be16_native(be16_t v)
-{
-       return be16_to_cpu(v.value);
-}
-
-static inline uint32_t le32_native(le32_t v)
-{
-       return le32_to_cpu(v.value);
-}
-
-static inline uint32_t be32_native(be32_t v)
-{
-       return be32_to_cpu(v.value);
-}
-
-static inline uint64_t be64_native(be64_t v)
-{
-       return be64_to_cpu(v.value);
-}
-
-static inline be16_t native_be16(uint16_t v)
-{
-       be16_t rv;
-       rv.value = cpu_to_be16(v);
-       return rv;
-}
-
-static inline le32_t native_le32(uint32_t v)
-{
-       le32_t rv;
-       rv.value = cpu_to_le32(v);
-       return rv;
-}
-
-static inline be32_t native_be32(uint32_t v)
-{
-       be32_t rv;
-       rv.value = cpu_to_be32(v);
-       return rv;
-}
-
-static inline be64_t native_be64(uint64_t v)
-{
-       be64_t rv;
-       rv.value = cpu_to_be64(v);
-       return rv;
-}
-
-#endif
diff --git a/stubdom/vtpmmgr/init.c b/stubdom/vtpmmgr/init.c
deleted file mode 100644 (file)
index 1506735..0000000
+++ /dev/null
@@ -1,790 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-#include <stdint.h>
-#include <stdlib.h>
-
-#include <xen/xen.h>
-#include <mini-os/tpmback.h>
-#include <mini-os/tpmfront.h>
-#include <mini-os/tpm_tis.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <polarssl/sha1.h>
-
-#include "log.h"
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "tpm.h"
-#include "marshal.h"
-#include "tpm2_marshal.h"
-#include "tpm2.h"
-
-struct Opts {
-   enum {
-      TPMDRV_TPM_TIS,
-      TPMDRV_TPMFRONT,
-   } tpmdriver;
-   unsigned long tpmiomem;
-   unsigned int tpmirq;
-   unsigned int tpmlocality;
-   int gen_owner_auth;
-};
-
-// --------------------------- Well Known Auths --------------------------
-const TPM_AUTHDATA WELLKNOWN_AUTH = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-struct vtpm_globals vtpm_globals = {
-   .tpm_fd = -1,
-   .oiap = { .AuthHandle = 0 },
-   .hw_locality = 0
-};
-
-static int tpm_entropy_source(void* dummy, unsigned char* data, size_t len, size_t* olen) {
-   UINT32 sz = len;
-   TPM_RESULT rc = TPM_GetRandom(&sz, data);
-   *olen = sz;
-   return rc == TPM_SUCCESS ? 0 : POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
-}
-
-static TPM_RESULT check_tpm_version(void) {
-   TPM_RESULT status;
-   UINT32 rsize;
-   BYTE* res = NULL;
-   TPM_CAP_VERSION_INFO vinfo;
-
-   TPMTRYRETURN(TPM_GetCapability(
-            TPM_CAP_VERSION_VAL,
-            0,
-            NULL,
-            &rsize,
-            &res));
-   if(rsize < 4) {
-      vtpmlogerror(VTPM_LOG_VTPM, "Invalid size returned by GetCapability!\n");
-      status = TPM_BAD_PARAMETER;
-      goto abort_egress;
-   }
-
-   unpack_TPM_CAP_VERSION_INFO(res, &vinfo, UNPACK_ALIAS);
-
-   vtpmloginfo(VTPM_LOG_VTPM, "Hardware TPM:\n");
-   vtpmloginfo(VTPM_LOG_VTPM, " version: %hhd %hhd %hhd %hhd\n",
-         vinfo.version.major, vinfo.version.minor, vinfo.version.revMajor, vinfo.version.revMinor);
-   vtpmloginfo(VTPM_LOG_VTPM, " specLevel: %hd\n", vinfo.specLevel);
-   vtpmloginfo(VTPM_LOG_VTPM, " errataRev: %hhd\n", vinfo.errataRev);
-   vtpmloginfo(VTPM_LOG_VTPM, " vendorID: %c%c%c%c\n",
-         vinfo.tpmVendorID[0], vinfo.tpmVendorID[1],
-         vinfo.tpmVendorID[2], vinfo.tpmVendorID[3]);
-   vtpmloginfo(VTPM_LOG_VTPM, " vendorSpecificSize: %hd\n", vinfo.vendorSpecificSize);
-   vtpmloginfo(VTPM_LOG_VTPM, " vendorSpecific: ");
-   for(int i = 0; i < vinfo.vendorSpecificSize; ++i) {
-      vtpmloginfomore(VTPM_LOG_VTPM, "%02hhx", vinfo.vendorSpecific[i]);
-   }
-   vtpmloginfomore(VTPM_LOG_VTPM, "\n");
-
-abort_egress:
-   free(res);
-   return status;
-}
-
-static TPM_RESULT flush_tpm(void) {
-   TPM_RESULT status = TPM_SUCCESS;
-   const TPM_RESOURCE_TYPE reslist[] = { TPM_RT_KEY, TPM_RT_AUTH, TPM_RT_TRANS, TPM_RT_COUNTER, TPM_RT_DAA_TPM, TPM_RT_CONTEXT };
-   BYTE* keylist = NULL;
-   UINT32 keylistSize;
-   BYTE* ptr;
-
-   //Iterate through each resource type and flush all handles
-   for(int i = 0; i < sizeof(reslist) / sizeof(TPM_RESOURCE_TYPE); ++i) {
-      TPM_RESOURCE_TYPE beres = cpu_to_be32(reslist[i]);
-      UINT16 size;
-      TPMTRYRETURN(TPM_GetCapability(
-               TPM_CAP_HANDLE,
-               sizeof(TPM_RESOURCE_TYPE),
-               (BYTE*)(&beres),
-               &keylistSize,
-               &keylist));
-
-      ptr = keylist;
-      ptr = unpack_UINT16(ptr, &size);
-
-      //Flush each handle
-      if(size) {
-         vtpmloginfo(VTPM_LOG_VTPM, "Flushing %u handle(s) of type %lu\n", size, (unsigned long) reslist[i]);
-         for(int j = 0; j < size; ++j) {
-            TPM_HANDLE h;
-            ptr = unpack_TPM_HANDLE(ptr, &h);
-            TPMTRYRETURN(TPM_FlushSpecific(h, reslist[i]));
-         }
-      }
-
-      free(keylist);
-      keylist = NULL;
-   }
-
-   goto egress;
-abort_egress:
-   free(keylist);
-egress:
-   return status;
-}
-
-
-static TPM_RESULT try_take_ownership(void) {
-   TPM_RESULT status = TPM_SUCCESS;
-   TPM_PUBKEY pubEK = TPM_PUBKEY_INIT;
-
-   // If we can read PubEK then there is no owner and we should take it.
-   status = TPM_ReadPubek(&pubEK);
-
-   switch(status) {
-      case TPM_DISABLED_CMD:
-         //Cannot read ek? TPM has owner
-         vtpmloginfo(VTPM_LOG_VTPM, "Failed to readEK meaning TPM has an owner. Creating Keys off existing SRK.\n");
-         status = TPM_SUCCESS;
-         break;
-      case TPM_NO_ENDORSEMENT:
-         {
-            //If theres no ek, we have to create one
-            TPM_KEY_PARMS keyInfo = {
-               .algorithmID = TPM_ALG_RSA,
-               .encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1,
-               .sigScheme = TPM_SS_NONE,
-               .parmSize = 12,
-               .parms.rsa = {
-                  .keyLength = RSA_KEY_SIZE,
-                  .numPrimes = 2,
-                  .exponentSize = 0,
-                  .exponent = NULL,
-               },
-            };
-            TPMTRYRETURN(TPM_CreateEndorsementKeyPair(&keyInfo, &pubEK));
-         }
-         //fall through to take ownership
-      case TPM_SUCCESS:
-         {
-            //Construct the Srk
-            TPM_KEY srk = {
-               .ver = TPM_STRUCT_VER_1_1,
-               .keyUsage = TPM_KEY_STORAGE,
-               .keyFlags = 0x00,
-               .authDataUsage = TPM_AUTH_ALWAYS,
-               .algorithmParms = {
-                  .algorithmID = TPM_ALG_RSA,
-                  .encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1,
-                  .sigScheme =  TPM_SS_NONE,
-                  .parmSize = 12,
-                  .parms.rsa = {
-                     .keyLength = RSA_KEY_SIZE,
-                     .numPrimes = 2,
-                     .exponentSize = 0,
-                     .exponent = NULL,
-                  },
-               },
-               .PCRInfoSize = 0,
-               .pubKey = {
-                  .keyLength = 0,
-                  .key = NULL,
-               },
-               .encDataSize = 0,
-            };
-
-            TPMTRYRETURN(TPM_TakeOwnership(
-                     &pubEK,
-                     (const TPM_AUTHDATA*)&vtpm_globals.owner_auth,
-                     (const TPM_AUTHDATA*)&vtpm_globals.srk_auth,
-                     &srk,
-                     NULL,
-                     &vtpm_globals.oiap));
-
-            TPMTRYRETURN(TPM_DisablePubekRead(
-                     (const TPM_AUTHDATA*)&vtpm_globals.owner_auth,
-                     &vtpm_globals.oiap));
-         }
-         break;
-      default:
-         break;
-   }
-abort_egress:
-   free_TPM_PUBKEY(&pubEK);
-   return status;
-}
-
-static int parse_auth_string(char* authstr, BYTE* target) {
-   int rc;
-   /* well known owner auth */
-   if(!strcmp(authstr, "well-known")) {
-          return 0;
-   }
-   /* owner auth is a raw hash */
-   else if(!strncmp(authstr, "hash:", 5)) {
-      authstr += 5;
-      if((rc = strlen(authstr)) != 40) {
-         vtpmlogerror(VTPM_LOG_VTPM, "Supplied owner auth hex string `%s' must be exactly 40 characters (20 bytes) long, length=%d\n", authstr, rc);
-         return -1;
-      }
-      for(int j = 0; j < 20; ++j) {
-         if(sscanf(authstr, "%hhX", target + j) != 1) {
-            vtpmlogerror(VTPM_LOG_VTPM, "Supplied owner auth string `%s' is not a valid hex string\n", authstr);
-            return -1;
-         }
-         authstr += 2;
-      }
-   }
-   /* owner auth is a string that will be hashed */
-   else if(!strncmp(authstr, "text:", 5)) {
-      authstr += 5;
-      sha1((const unsigned char*)authstr, strlen(authstr), target);
-   }
-   else {
-      vtpmlogerror(VTPM_LOG_VTPM, "Invalid auth string %s\n", authstr);
-      return -1;
-   }
-
-   return 0;
-}
-
-int parse_cmdline_opts(int argc, char** argv, struct Opts* opts)
-{
-   int rc;
-   int i;
-
-   //Set defaults
-   memcpy(vtpm_globals.owner_auth, WELLKNOWN_AUTH, sizeof(TPM_AUTHDATA));
-   memcpy(vtpm_globals.srk_auth, WELLKNOWN_AUTH, sizeof(TPM_AUTHDATA));
-
-   for(i = 1; i < argc; ++i) {
-      if(!strncmp(argv[i], "owner_auth:", 10)) {
-         if((rc = parse_auth_string(argv[i] + 10, vtpm_globals.owner_auth)) < 0) {
-            goto err_invalid;
-         }
-         if(rc == 1) {
-            opts->gen_owner_auth = 1;
-         }
-      }
-      else if(!strncmp(argv[i], "srk_auth:", 8)) {
-         if((rc = parse_auth_string(argv[i] + 8, vtpm_globals.srk_auth)) != 0) {
-            goto err_invalid;
-         }
-      }
-      else if(!strncmp(argv[i], "tpmdriver=", 10)) {
-         if(!strcmp(argv[i] + 10, "tpm_tis")) {
-            opts->tpmdriver = TPMDRV_TPM_TIS;
-         } else if(!strcmp(argv[i] + 10, "tpmfront")) {
-            opts->tpmdriver = TPMDRV_TPMFRONT;
-         } else {
-            goto err_invalid;
-         }
-      }
-      else if(!strncmp(argv[i], "tpmiomem=",9)) {
-         if(sscanf(argv[i] + 9, "0x%lX", &opts->tpmiomem) != 1) {
-            goto err_invalid;
-         }
-      }
-      else if(!strncmp(argv[i], "tpmirq=",7)) {
-         if(!strcmp(argv[i] + 7, "probe")) {
-            opts->tpmirq = TPM_PROBE_IRQ;
-         } else if( sscanf(argv[i] + 7, "%u", &opts->tpmirq) != 1) {
-            goto err_invalid;
-         }
-      }
-      else if(!strncmp(argv[i], "tpmlocality=",12)) {
-         if(sscanf(argv[i] + 12, "%u", &opts->tpmlocality) != 1 || opts->tpmlocality > 4) {
-            goto err_invalid;
-         }
-      }
-   }
-
-   switch(opts->tpmdriver) {
-      case TPMDRV_TPM_TIS:
-         vtpmloginfo(VTPM_LOG_VTPM, "Option: Using tpm_tis driver\n");
-         break;
-      case TPMDRV_TPMFRONT:
-         vtpmloginfo(VTPM_LOG_VTPM, "Option: Using tpmfront driver\n");
-         break;
-   }
-
-   return 0;
-err_invalid:
-   vtpmlogerror(VTPM_LOG_VTPM, "Invalid Option %s\n", argv[i]);
-   return -1;
-}
-
-
-
-static TPM_RESULT vtpmmgr_create(void) {
-   TPM_RESULT status = TPM_SUCCESS;
-   TPM_AUTH_SESSION osap = TPM_AUTH_SESSION_INIT;
-   TPM_AUTHDATA sharedsecret;
-
-   // Take ownership if TPM is unowned
-   TPMTRYRETURN(try_take_ownership());
-
-   // Generate storage key's auth
-   TPMTRYRETURN( TPM_OSAP(
-            TPM_ET_KEYHANDLE,
-            TPM_SRK_KEYHANDLE,
-            (const TPM_AUTHDATA*)&vtpm_globals.srk_auth,
-            &sharedsecret,
-            &osap) );
-
-   //Make sure TPM has commited changes
-   TPMTRYRETURN( TPM_SaveState() );
-
-   //Create new disk image
-   TPMTRYRETURN(vtpm_new_disk());
-
-   goto egress;
-abort_egress:
-egress:
-   vtpmloginfo(VTPM_LOG_VTPM, "Finished initialized new VTPM manager\n");
-
-   //End the OSAP session
-   if(osap.AuthHandle) {
-      TPM_TerminateHandle(osap.AuthHandle);
-   }
-
-   return status;
-}
-
-static void set_opaque(domid_t domid, unsigned int handle)
-{
-       struct tpm_opaque* opq;
-
-       opq = calloc(1, sizeof(*opq));
-       opq->uuid = (uuid_t*)tpmback_get_uuid(domid, handle);
-       opq->domid = domid;
-       opq->handle = handle;
-       tpmback_set_opaque(domid, handle, opq);
-}
-
-static void free_opaque(domid_t domid, unsigned int handle)
-{
-       struct tpm_opaque* opq = tpmback_get_opaque(domid, handle);
-       if (opq && opq->vtpm)
-               opq->vtpm->flags &= ~VTPM_FLAG_OPEN;
-       free(opq);
-}
-
-TPM_RESULT vtpmmgr_init(int argc, char** argv) {
-   TPM_RESULT status = TPM_SUCCESS;
-
-   /* Default commandline options */
-   struct Opts opts = {
-      .tpmdriver = TPMDRV_TPM_TIS,
-      .tpmiomem = TPM_BASEADDR,
-      .tpmirq = 0,
-      .tpmlocality = 0,
-      .gen_owner_auth = 0,
-   };
-
-   if(parse_cmdline_opts(argc, argv, &opts) != 0) {
-      vtpmlogerror(VTPM_LOG_VTPM, "Command line parsing failed! exiting..\n");
-      status = TPM_BAD_PARAMETER;
-      goto abort_egress;
-   }
-
-   //Setup storage system
-   if(vtpm_storage_init() != 0) {
-      vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize storage subsystem!\n");
-      status = TPM_IOERROR;
-      goto abort_egress;
-   }
-
-   //Setup tpmback device
-   init_tpmback(set_opaque, free_opaque);
-
-   //Setup tpm access
-   switch(opts.tpmdriver) {
-      case TPMDRV_TPM_TIS:
-         {
-            struct tpm_chip* tpm;
-            if((tpm = init_tpm_tis(opts.tpmiomem, TPM_TIS_LOCL_INT_TO_FLAG(opts.tpmlocality), opts.tpmirq)) == NULL) {
-               vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize tpmfront device\n");
-               status = TPM_IOERROR;
-               goto abort_egress;
-            }
-            vtpm_globals.tpm_fd = tpm_tis_open(tpm);
-            tpm_tis_request_locality(tpm, opts.tpmlocality);
-            vtpm_globals.hw_locality = opts.tpmlocality;
-         }
-         break;
-      case TPMDRV_TPMFRONT:
-         {
-            struct tpmfront_dev* tpmfront_dev;
-            if((tpmfront_dev = init_tpmfront(NULL)) == NULL) {
-               vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize tpmfront device\n");
-               status = TPM_IOERROR;
-               goto abort_egress;
-            }
-            vtpm_globals.tpm_fd = tpmfront_open(tpmfront_dev);
-         }
-         break;
-   }
-
-   //Get the version of the tpm
-   TPMTRYRETURN(check_tpm_version());
-
-   // Blow away all stale handles left in the tpm
-   if(flush_tpm() != TPM_SUCCESS) {
-      vtpmlogerror(VTPM_LOG_VTPM, "VTPM_FlushResources failed, continuing anyway..\n");
-   }
-
-   /* Initialize the rng */
-   entropy_init(&vtpm_globals.entropy);
-   entropy_add_source(&vtpm_globals.entropy, tpm_entropy_source, NULL, 0);
-   entropy_gather(&vtpm_globals.entropy);
-   ctr_drbg_init(&vtpm_globals.ctr_drbg, entropy_func, &vtpm_globals.entropy, NULL, 0);
-   ctr_drbg_set_prediction_resistance( &vtpm_globals.ctr_drbg, CTR_DRBG_PR_OFF );
-
-   // Generate Auth for Owner
-   if(opts.gen_owner_auth) {
-      vtpmmgr_rand(vtpm_globals.owner_auth, sizeof(TPM_AUTHDATA));
-   }
-
-   // Create OIAP session for service's authorized commands
-   TPMTRYRETURN( TPM_OIAP(&vtpm_globals.oiap) );
-
-   /* Load the Manager data, if it fails create a new manager */
-   // TODO handle upgrade recovery of auth0
-   if (vtpm_load_disk()) {
-      /* If the OIAP session was closed by an error, create a new one */
-      if(vtpm_globals.oiap.AuthHandle == 0) {
-         TPMTRYRETURN( TPM_OIAP(&vtpm_globals.oiap) );
-      }
-      vtpmloginfo(VTPM_LOG_VTPM, "Failed to read manager file. Assuming first time initialization.\n");
-      TPMTRYRETURN( vtpmmgr_create() );
-   }
-
-   goto egress;
-abort_egress:
-   vtpmmgr_shutdown();
-egress:
-   return status;
-}
-
-void vtpmmgr_shutdown(void)
-{
-   /* Cleanup TPM resources */
-   TPM_TerminateHandle(vtpm_globals.oiap.AuthHandle);
-
-   /* Close tpmback */
-   shutdown_tpmback();
-
-   /* Close tpmfront/tpm_tis */
-   close(vtpm_globals.tpm_fd);
-
-   vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager stopped.\n");
-}
-
-/* TPM 2.0 */
-
-static void tpm2_AuthArea_ctor(const char *authValue, UINT32 authLen,
-                               TPM_AuthArea *auth)
-{
-    auth->sessionHandle = TPM_RS_PW;
-    auth->nonce.size = 0;
-    auth->sessionAttributes = 1;
-    auth->auth.size = authLen;
-    memcpy(auth->auth.buffer, authValue, authLen);
-    auth->size = 9 + authLen;
-}
-
-TPM_RC tpm2_take_ownership(void)
-{
-    TPM_RC status = TPM_SUCCESS;
-
-    tpm2_AuthArea_ctor(NULL, 0, &vtpm_globals.pw_auth);
-
-    /* create SRK */
-    TPM2_CreatePrimary_Params_in in = {
-        .inSensitive = {
-            .size = 4,
-            .sensitive = {
-                .userAuth.size = 0,
-                .userAuth.buffer = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
-                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
-                .data.size = 0,
-            },
-        },
-        .inPublic = {
-            .size = 60,
-            .publicArea = {
-                .type = TPM2_ALG_RSA,
-                .nameAlg = TPM2_ALG_SHA256,
-#define SRK_OBJ_ATTR (fixedTPM | fixedParent  | userWithAuth | \
-                      sensitiveDataOrigin | restricted | decrypt)
-                .objectAttributes = SRK_OBJ_ATTR,
-                .authPolicy.size = 0,
-                .parameters.rsaDetail = {
-                    .symmetric = {
-                    .algorithm = TPM2_ALG_AES,
-                    .keyBits.aes = AES_KEY_SIZES_BITS,
-                    .mode.aes = TPM2_ALG_CFB,
-                    },
-                .scheme = { TPM2_ALG_NULL },
-                .keyBits = RSA_KEY_SIZES_BITS,
-                .exponent = 0,
-                },
-                .unique.rsa.size = 0,
-            },
-        },
-            .outsideInfo.size = 0,
-            .creationPCR.count = 0,
-    };
-
-    TPMTRYRETURN(TPM2_CreatePrimary(TPM_RH_OWNER,&in,
-                                    &vtpm_globals.srk_handle, NULL));
-    vtpmloginfo(VTPM_LOG_VTPM, "SRK handle: 0x%X\n", vtpm_globals.srk_handle);
-    {
-        const char data[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
-                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-        tpm2_AuthArea_ctor(data, 20, &vtpm_globals.srk_auth_area);
-    }
-    /*end create SRK*/
-
-abort_egress:
-    return status;
-}
-
-TPM_RESULT vtpmmgr2_create(void)
-{
-    TPM_RESULT status = TPM_SUCCESS;
-
-    TPMTRYRETURN(tpm2_take_ownership());
-
-   /* create SK */
-    TPM2_Create_Params_out out;
-    TPM2_Create_Params_in in = {
-        .inSensitive = {
-            .size = 4 + 20,
-            .sensitive = {
-                .userAuth.size = 20,
-                .userAuth.buffer = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
-                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
-                .data.size = 0,
-            },
-        },
-        .inPublic = {
-            .size = (60),
-            .publicArea = {
-                 .type = TPM2_ALG_RSA,
-                 .nameAlg = TPM2_ALG_SHA256,
-#define SK_OBJ_ATTR (fixedTPM | fixedParent | userWithAuth |\
-                     sensitiveDataOrigin |decrypt)
-                 .objectAttributes = SK_OBJ_ATTR,
-                 .authPolicy.size = 0,
-                 .parameters.rsaDetail = {
-                     .symmetric = {
-                         .algorithm = TPM2_ALG_NULL,
-                     },
-                     .scheme = {
-                         TPM2_ALG_OAEP,
-                         .details.oaep.hashAlg = TPM2_ALG_SHA256,
-                     },
-                     .keyBits = RSA_KEY_SIZES_BITS,
-                     .exponent = 0,
-                  },
-                  .unique.rsa.size = 0,
-            },
-        },
-        .outsideInfo.size = 0,
-        .creationPCR.count = 0,
-    };/*end in */
-
-    TPMTRYRETURN(TPM2_Create(vtpm_globals.srk_handle, &in, &out));
-    TPMTRYRETURN(TPM2_Load(vtpm_globals.srk_handle,
-                           &vtpm_globals.tpm2_storage_key.Private,
-                           &vtpm_globals.tpm2_storage_key.Public,
-                           &vtpm_globals.sk_handle,
-                           &vtpm_globals.sk_name));
-
-    vtpmloginfo(VTPM_LOG_VTPM, "SK HANDLE: 0x%X\n", vtpm_globals.sk_handle);
-
-    /*Create new disk image*/
-    TPMTRYRETURN(vtpm_new_disk());
-
-    goto egress;
-
-abort_egress:
-egress:
-    vtpmloginfo(VTPM_LOG_VTPM, "Finished initialized new VTPM manager\n");
-    return status;
-}
-
-static int tpm2_entropy_source(void* dummy, unsigned char* data,
-                               size_t len, size_t* olen)
-{
-    UINT32 sz = len;
-    TPM_RESULT rc = TPM2_GetRandom(&sz, data);
-    *olen = sz;
-    return rc == TPM_SUCCESS ? 0 : POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
-}
-
-/*TPM 2.0 Objects flush */
-static TPM_RC flush_tpm2(void)
-{
-    int i;
-
-    for (i = TRANSIENT_FIRST; i < TRANSIENT_LAST; i++)
-         TPM2_FlushContext(i);
-
-    return TPM_SUCCESS;
-}
-
-TPM_RESULT vtpmmgr2_init(int argc, char** argv)
-{
-    TPM_RESULT status = TPM_SUCCESS;
-
-    /* Default commandline options */
-    struct Opts opts = {
-        .tpmdriver = TPMDRV_TPM_TIS,
-        .tpmiomem = TPM_BASEADDR,
-        .tpmirq = 0,
-        .tpmlocality = 0,
-        .gen_owner_auth = 0,
-    };
-
-    if (parse_cmdline_opts(argc, argv, &opts) != 0) {
-        vtpmlogerror(VTPM_LOG_VTPM, "Command line parsing failed! exiting..\n");
-        status = TPM_BAD_PARAMETER;
-        goto abort_egress;
-    }
-
-    /*Setup storage system*/
-    if (vtpm_storage_init() != 0) {
-        vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize storage subsystem!\n");
-        status = TPM_IOERROR;
-        goto abort_egress;
-    }
-
-    /*Setup tpmback device*/
-    init_tpmback(set_opaque, free_opaque);
-
-    /*Setup tpm access*/
-    switch(opts.tpmdriver) {
-        case TPMDRV_TPM_TIS:
-        {
-            struct tpm_chip* tpm;
-            if ((tpm = init_tpm2_tis(opts.tpmiomem, TPM_TIS_LOCL_INT_TO_FLAG(opts.tpmlocality),
-                                     opts.tpmirq)) == NULL) {
-                vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize tpmfront device\n");
-                status = TPM_IOERROR;
-                goto abort_egress;
-            }
-            printk("init_tpm2_tis()       ...ok\n");
-            vtpm_globals.tpm_fd = tpm_tis_open(tpm);
-            tpm_tis_request_locality(tpm, opts.tpmlocality);
-        }
-        break;
-        case TPMDRV_TPMFRONT:
-        {
-            struct tpmfront_dev* tpmfront_dev;
-            if ((tpmfront_dev = init_tpmfront(NULL)) == NULL) {
-                vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize tpmfront device\n");
-                status = TPM_IOERROR;
-                goto abort_egress;
-            }
-            vtpm_globals.tpm_fd = tpmfront_open(tpmfront_dev);
-        }
-        break;
-    }
-    printk("TPM 2.0 access ...ok\n");
-    /* Blow away all stale handles left in the tpm*/
-    if (flush_tpm2() != TPM_SUCCESS) {
-        vtpmlogerror(VTPM_LOG_VTPM, "VTPM_FlushResources failed, continuing anyway..\n");
-    }
-
-    /* Initialize the rng */
-    entropy_init(&vtpm_globals.entropy);
-    entropy_add_source(&vtpm_globals.entropy, tpm2_entropy_source, NULL, 0);
-    entropy_gather(&vtpm_globals.entropy);
-    ctr_drbg_init(&vtpm_globals.ctr_drbg, entropy_func, &vtpm_globals.entropy, NULL, 0);
-    ctr_drbg_set_prediction_resistance( &vtpm_globals.ctr_drbg, CTR_DRBG_PR_OFF );
-
-    /* Generate Auth for Owner*/
-    if (opts.gen_owner_auth) {
-        vtpmmgr_rand(vtpm_globals.owner_auth, sizeof(TPM_AUTHDATA));
-    }
-
-    /* Load the Manager data, if it fails create a new manager */
-    if (vtpm_load_disk()) {
-        vtpmloginfo(VTPM_LOG_VTPM, "Assuming first time initialization.\n");
-        TPMTRYRETURN(vtpmmgr2_create());
-    }
-
-    goto egress;
-
-abort_egress:
-    vtpmmgr_shutdown();
-egress:
-    return status;
-}
-
-TPM_RC tpm2_pcr_read(int index, uint8_t *buf)
-{
-    TPM_RESULT status = TPM_SUCCESS;
-    TPML_PCR_SELECTION pcrSelectionIn = {
-        .count = 1,};
-
-    TPMS_PCR_SELECTION tpms_pcr_selection = {
-        .hash = TPM2_ALG_SHA1,
-        .sizeofSelect = PCR_SELECT_MAX,};
-
-    UINT32 pcrUpdateCounter;
-    TPML_PCR_SELECTION pcrSelectionOut;
-    TPML_DIGEST pcrValues;
-    TPM2B_DIGEST tpm2b_digest;
-
-    tpms_pcr_selection.pcrSelect[PCR_SELECT_NUM(index)] = PCR_SELECT_VALUE(index);
-    memcpy(&pcrSelectionIn.pcrSelections[0], &tpms_pcr_selection,
-           sizeof(TPMS_PCR_SELECTION));
-
-    TPMTRYRETURN(TPM2_PCR_Read(pcrSelectionIn, &pcrUpdateCounter,
-                               &pcrSelectionOut, &pcrValues));
-
-    if (pcrValues.count < 1)
-        goto egress;
-
-    unpack_TPM2B_DIGEST((uint8_t *) &pcrValues, &tpm2b_digest);
-    memcpy(buf, tpm2b_digest.buffer, SHA1_DIGEST_SIZE);
-
-abort_egress:
-egress:
-    return status;
-}
diff --git a/stubdom/vtpmmgr/log.c b/stubdom/vtpmmgr/log.c
deleted file mode 100644 (file)
index a82c913..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "tcg.h"
-
-char *module_names[] = { "",
-                                "TPM",
-                                "TPM",
-                                "VTPM",
-                                "VTPM",
-                                "TXDATA",
-                              };
-// Helper code for the consts, eg. to produce messages for error codes.
-
-typedef struct error_code_entry_t {
-  TPM_RESULT code;
-  char * code_name;
-  char * msg;
-} error_code_entry_t;
-
-static const error_code_entry_t error_msgs [] = {
-  { TPM_SUCCESS, "TPM_SUCCESS", "Successful completion of the operation" },
-  { TPM_AUTHFAIL, "TPM_AUTHFAIL", "Authentication failed" },
-  { TPM_BADINDEX, "TPM_BADINDEX", "The index to a PCR, DIR or other register is incorrect" },
-  { TPM_BAD_PARAMETER, "TPM_BAD_PARAMETER", "One or more parameter is bad" },
-  { TPM_AUDITFAILURE, "TPM_AUDITFAILURE", "An operation completed successfully but the auditing of that operation failed." },
-  { TPM_CLEAR_DISABLED, "TPM_CLEAR_DISABLED", "The clear disable flag is set and all clear operations now require physical access" },
-  { TPM_DEACTIVATED, "TPM_DEACTIVATED", "The TPM is deactivated" },
-  { TPM_DISABLED, "TPM_DISABLED", "The TPM is disabled" },
-  { TPM_DISABLED_CMD, "TPM_DISABLED_CMD", "The target command has been disabled" },
-  { TPM_FAIL, "TPM_FAIL", "The operation failed" },
-  { TPM_BAD_ORDINAL, "TPM_BAD_ORDINAL", "The ordinal was unknown or inconsistent" },
-  { TPM_INSTALL_DISABLED, "TPM_INSTALL_DISABLED", "The ability to install an owner is disabled" },
-  { TPM_INVALID_KEYHANDLE, "TPM_INVALID_KEYHANDLE", "The key handle presented was invalid" },
-  { TPM_KEYNOTFOUND, "TPM_KEYNOTFOUND", "The target key was not found" },
-  { TPM_INAPPROPRIATE_ENC, "TPM_INAPPROPRIATE_ENC", "Unacceptable encryption scheme" },
-  { TPM_MIGRATEFAIL, "TPM_MIGRATEFAIL", "Migration authorization failed" },
-  { TPM_INVALID_PCR_INFO, "TPM_INVALID_PCR_INFO", "PCR information could not be interpreted" },
-  { TPM_NOSPACE, "TPM_NOSPACE", "No room to load key." },
-  { TPM_NOSRK, "TPM_NOSRK", "There is no SRK set" },
-  { TPM_NOTSEALED_BLOB, "TPM_NOTSEALED_BLOB", "An encrypted blob is invalid or was not created by this TPM" },
-  { TPM_OWNER_SET, "TPM_OWNER_SET", "There is already an Owner" },
-  { TPM_RESOURCES, "TPM_RESOURCES", "The TPM has insufficient internal resources to perform the requested action." },
-  { TPM_SHORTRANDOM, "TPM_SHORTRANDOM", "A random string was too short" },
-  { TPM_SIZE, "TPM_SIZE", "The TPM does not have the space to perform the operation." },
-  { TPM_WRONGPCRVAL, "TPM_WRONGPCRVAL", "The named PCR value does not match the current PCR value." },
-  { TPM_BAD_PARAM_SIZE, "TPM_BAD_PARAM_SIZE", "The paramSize argument to the command has the incorrect value" },
-  { TPM_SHA_THREAD, "TPM_SHA_THREAD", "There is no existing SHA-1 thread." },
-  { TPM_SHA_ERROR, "TPM_SHA_ERROR", "The calculation is unable to proceed because the existing SHA-1 thread has already encountered an error." },
-  { TPM_FAILEDSELFTEST, "TPM_FAILEDSELFTEST", "Self-test has failed and the TPM has shutdown." },
-  { TPM_AUTH2FAIL, "TPM_AUTH2FAIL", "The authorization for the second key in a 2 key function failed authorization" },
-  { TPM_BADTAG, "TPM_BADTAG", "The tag value sent to for a command is invalid" },
-  { TPM_IOERROR, "TPM_IOERROR", "An IO error occurred transmitting information to the TPM" },
-  { TPM_ENCRYPT_ERROR, "TPM_ENCRYPT_ERROR", "The encryption process had a problem." },
-  { TPM_DECRYPT_ERROR, "TPM_DECRYPT_ERROR", "The decryption process did not complete." },
-  { TPM_INVALID_AUTHHANDLE, "TPM_INVALID_AUTHHANDLE", "An invalid handle was used." },
-  { TPM_NO_ENDORSEMENT, "TPM_NO_ENDORSEMENT", "The TPM does not a EK installed" },
-  { TPM_INVALID_KEYUSAGE, "TPM_INVALID_KEYUSAGE", "The usage of a key is not allowed" },
-  { TPM_WRONG_ENTITYTYPE, "TPM_WRONG_ENTITYTYPE", "The submitted entity type is not allowed" },
-  { TPM_INVALID_POSTINIT, "TPM_INVALID_POSTINIT", "The command was received in the wrong sequence relative to TPM_Init and a subsequent TPM_Startup" },
-  { TPM_INAPPROPRIATE_SIG, "TPM_INAPPROPRIATE_SIG", "Signed data cannot include additional DER information" },
-  { TPM_BAD_KEY_PROPERTY, "TPM_BAD_KEY_PROPERTY", "The key properties in TPM_KEY_PARMs are not supported by this TPM" },
-
-  { TPM_BAD_MIGRATION, "TPM_BAD_MIGRATION", "The migration properties of this key are incorrect." },
-  { TPM_BAD_SCHEME, "TPM_BAD_SCHEME", "The signature or encryption scheme for this key is incorrect or not permitted in this situation." },
-  { TPM_BAD_DATASIZE, "TPM_BAD_DATASIZE", "The size of the data (or blob) parameter is bad or inconsistent with the referenced key" },
-  { TPM_BAD_MODE, "TPM_BAD_MODE", "A mode parameter is bad, such as capArea or subCapArea for TPM_GetCapability, phsicalPresence parameter for TPM_PhysicalPresence, or migrationType for TPM_CreateMigrationBlob." },
-  { TPM_BAD_PRESENCE, "TPM_BAD_PRESENCE", "Either the physicalPresence or physicalPresenceLock bits have the wrong value" },
-  { TPM_BAD_VERSION, "TPM_BAD_VERSION", "The TPM cannot perform this version of the capability" },
-  { TPM_NO_WRAP_TRANSPORT, "TPM_NO_WRAP_TRANSPORT", "The TPM does not allow for wrapped transport sessions" },
-  { TPM_AUDITFAIL_UNSUCCESSFUL, "TPM_AUDITFAIL_UNSUCCESSFUL", "TPM audit construction failed and the underlying command was returning a failure code also" },
-  { TPM_AUDITFAIL_SUCCESSFUL, "TPM_AUDITFAIL_SUCCESSFUL", "TPM audit construction failed and the underlying command was returning success" },
-  { TPM_NOTRESETABLE, "TPM_NOTRESETABLE", "Attempt to reset a PCR register that does not have the resettable attribute" },
-  { TPM_NOTLOCAL, "TPM_NOTLOCAL", "Attempt to reset a PCR register that requires locality and locality modifier not part of command transport" },
-  { TPM_BAD_TYPE, "TPM_BAD_TYPE", "Make identity blob not properly typed" },
-  { TPM_INVALID_RESOURCE, "TPM_INVALID_RESOURCE", "When saving context identified resource type does not match actual resource" },
-  { TPM_NOTFIPS, "TPM_NOTFIPS", "The TPM is attempting to execute a command only available when in FIPS mode" },
-  { TPM_INVALID_FAMILY, "TPM_INVALID_FAMILY", "The command is attempting to use an invalid family ID" },
-  { TPM_NO_NV_PERMISSION, "TPM_NO_NV_PERMISSION", "The permission to manipulate the NV storage is not available" },
-  { TPM_REQUIRES_SIGN, "TPM_REQUIRES_SIGN", "The operation requires a signed command" },
-  { TPM_KEY_NOTSUPPORTED, "TPM_KEY_NOTSUPPORTED", "Wrong operation to load an NV key" },
-  { TPM_AUTH_CONFLICT, "TPM_AUTH_CONFLICT", "NV_LoadKey blob requires both owner and blob authorization" },
-  { TPM_AREA_LOCKED, "TPM_AREA_LOCKED", "The NV area is locked and not writtable" },
-  { TPM_BAD_LOCALITY, "TPM_BAD_LOCALITY", "The locality is incorrect for the attempted operation" },
-  { TPM_READ_ONLY, "TPM_READ_ONLY", "The NV area is read only and can't be written to" },
-  { TPM_PER_NOWRITE, "TPM_PER_NOWRITE", "There is no protection on the write to the NV area" },
-  { TPM_FAMILYCOUNT, "TPM_FAMILYCOUNT", "The family count value does not match" },
-  { TPM_WRITE_LOCKED, "TPM_WRITE_LOCKED", "The NV area has already been written to" },
-  { TPM_BAD_ATTRIBUTES, "TPM_BAD_ATTRIBUTES", "The NV area attributes conflict" },
-  { TPM_INVALID_STRUCTURE, "TPM_INVALID_STRUCTURE", "The structure tag and version are invalid or inconsistent" },
-  { TPM_KEY_OWNER_CONTROL, "TPM_KEY_OWNER_CONTROL", "The key is under control of the TPM Owner and can only be evicted by the TPM Owner." },
-  { TPM_BAD_COUNTER, "TPM_BAD_COUNTER", "The counter handle is incorrect" },
-  { TPM_NOT_FULLWRITE, "TPM_NOT_FULLWRITE", "The write is not a complete write of the area" },
-  { TPM_CONTEXT_GAP, "TPM_CONTEXT_GAP", "The gap between saved context counts is too large" },
-  { TPM_MAXNVWRITES, "TPM_MAXNVWRITES", "The maximum number of NV writes without an owner has been exceeded" },
-  { TPM_NOOPERATOR, "TPM_NOOPERATOR", "No operator authorization value is set" },
-  { TPM_RESOURCEMISSING, "TPM_RESOURCEMISSING", "The resource pointed to by context is not loaded" },
-  { TPM_DELEGATE_LOCK, "TPM_DELEGATE_LOCK", "The delegate administration is locked" },
-  { TPM_DELEGATE_FAMILY, "TPM_DELEGATE_FAMILY", "Attempt to manage a family other then the delegated family" },
-  { TPM_DELEGATE_ADMIN, "TPM_DELEGATE_ADMIN", "Delegation table management not enabled" },
-  { TPM_TRANSPORT_EXCLUSIVE, "TPM_TRANSPORT_EXCLUSIVE", "There was a command executed outside of an exclusive transport session" },
-};
-
-
-// helper function for the error codes:
-const char* tpm_get_error_name (TPM_RESULT code) {
-  // just do a linear scan for now
-  unsigned i;
-  for (i = 0; i < sizeof(error_msgs)/sizeof(error_msgs[0]); i++)
-    if (code == error_msgs[i].code)
-      return error_msgs[i].code_name;
-
-    return("Unknown Error Code");
-}
diff --git a/stubdom/vtpmmgr/log.h b/stubdom/vtpmmgr/log.h
deleted file mode 100644 (file)
index 455219f..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef __VTPM_LOG_H__
-#define __VTPM_LOG_H__
-
-#include <stdint.h>             // for uint32_t
-#include <stddef.h>             // for pointer NULL
-#include <stdio.h>
-#include "tcg.h"
-
-// =========================== LOGGING ==============================
-
-// the logging module numbers
-#define VTPM_LOG_TPM         1
-#define VTPM_LOG_TPM_DEEP    2
-#define VTPM_LOG_VTPM        3
-#define VTPM_LOG_VTPM_DEEP   4
-#define VTPM_LOG_TXDATA      5
-
-extern char *module_names[];
-
-// Default to standard logging
-#ifndef LOGGING_MODULES
-#define LOGGING_MODULES (BITMASK(VTPM_LOG_VTPM)|BITMASK(VTPM_LOG_TPM))
-#endif
-
-// bit-access macros
-#define BITMASK(idx)      ( 1U << (idx) )
-#define GETBIT(num,idx)   ( ((num) & BITMASK(idx)) >> idx )
-#define SETBIT(num,idx)   (num) |= BITMASK(idx)
-#define CLEARBIT(num,idx) (num) &= ( ~ BITMASK(idx) )
-
-void printk(const char *fmt, ...);
-
-#define vtpmloginfo(module, fmt, args...) \
-  if (GETBIT (LOGGING_MODULES, module) == 1) {                         \
-    printk("INFO[%s]: " fmt, module_names[module], ##args); \
-  }
-
-#define vtpmloginfomore(module, fmt, args...) \
-  if (GETBIT (LOGGING_MODULES, module) == 1) {                       \
-    printk(fmt,##args);                                      \
-  }
-
-#define vtpmlogerror(module, fmt, args...) \
-  printk("ERROR[%s]: " fmt, module_names[module], ##args);
-
-//typedef UINT32 tpm_size_t;
-
-// helper function for the error codes:
-const char* tpm_get_error_name (TPM_RESULT code);
-
-#endif // _VTPM_LOG_H_
diff --git a/stubdom/vtpmmgr/manage-vtpmmgr.pl b/stubdom/vtpmmgr/manage-vtpmmgr.pl
deleted file mode 100755 (executable)
index caf4f02..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use Digest::SHA;
-
-# The /dev/tpm0 device can only be opened by one application at a time, so if
-# the trousers daemon is running, this script will fail.
-system "killall tcsd 2>/dev/null";
-open my $tpm, '+>', '/dev/tpm0' or die "Could not open /dev/tpm0: $!";
-
-sub tpm_cmd_raw {
-       my $msg = join '', @_;
-       my $rsp;
-       print '<<', unpack('H*', $msg), "\n" if $ENV{V};
-       syswrite $tpm, $msg;
-       sysread $tpm, $rsp, 4096;
-       print '>>', unpack('H*', $rsp), "\n" if $ENV{V};
-       $rsp;
-}
-
-sub tpm_cmd_nohdr {
-       my($type, $msg) = @_;
-       my $head = pack 'nN', $type, 6 + length $msg;
-       my $rsp = tpm_cmd_raw $head, $msg;
-       my($rtype, $len, $stat, $reply) = unpack 'nNNa*', $rsp;
-       die "incomplete response" if $len != 10 + length $reply;
-       if ($stat) {
-               print "TPM error: $stat\n";
-               exit 1;
-       }
-       $reply;
-}
-
-sub cmd_list_group {
-       my $group = shift;
-       my($uuid, $pubk, $cfg_list) = unpack 'H32 a256 a*', tpm_cmd_nohdr 0x1C2,
-               pack 'NN', 0x02000107, $group;
-       $uuid = join "-", unpack 'a8a4a4a4a12', $uuid;
-       my $pk_hash = Digest::SHA::sha1_hex($pubk);
-       my $cfg_hash = Digest::SHA::sha1_hex($cfg_list);
-       my($seq, @cfgs) = unpack 'Q> N/(H40) a*', $cfg_list;
-       my @kerns = unpack "N/(H40)", pop @cfgs;
-       print "Group $group ($uuid):\n";
-       print " Public key hash: $pk_hash\n";
-       print " Boot config #$seq ($cfg_hash)\n";
-       print " Platforms:\n";
-       print "  $_\n" for @cfgs;
-       print " Kernels:\n";
-       print "  $_\n" for @kerns;
-       print " VTPMs:\n";
-
-       my($nr, @vtpms) = unpack 'N(H32)*', tpm_cmd_nohdr 0x1C2, pack 'NNN', 0x02000201, $group, 0;
-       if ($nr > @vtpms) {
-               print "  TODO this list is cropped; needs multiple requests\n";
-       }
-       @vtpms = () if $nr == 0; # unpack returns an empty string in this case
-       @vtpms = map { join "-", unpack 'a8a4a4a4a12', $_ } @vtpms;
-       print "  $_\n" for @vtpms;
-}
-
-sub cmd_list {
-       if (@_) {
-               cmd_list_group $_[0];
-       } else {
-               my $nr = unpack 'N', tpm_cmd_nohdr 0x1C2, pack 'N', 0x02000101;
-               cmd_list_group $_ for (0..($nr - 1));
-       }
-}
-
-sub cmd_group_add {
-       my $rsa_modfile = shift;
-       my $ca_digest = "\0"x20;
-       open MOD, $rsa_modfile or die $!;
-       my $group_pubkey = join '', <MOD>;
-       close MOD;
-
-       my($uuid, $pubkey, $pksig) = unpack 'H32 a256 a*', tpm_cmd_nohdr 0x1C2, pack 'N(a*)*',
-               0x02000102, $ca_digest, $group_pubkey;
-       $uuid = join "-", unpack 'a8a4a4a4a12', $uuid;
-       print "$uuid\n";
-       mkdir "group-$uuid";
-       open F, ">group-$uuid/aik.pub";
-       print F $pubkey;
-       close F;
-       open F, ">group-$uuid/aik.priv-ca-data";
-       print F $pksig;
-       close F;
-
-       # TODO certify the AIK using the pTPM's EK (privacy CA)
-       # TODO escrow the recovery key for this group
-}
-
-sub cmd_group_del {
-       my $nr = shift;
-       tpm_cmd_nohdr 0x1C2, pack 'NN', 0x02000103, $nr;
-}
-
-sub cmd_group_update {
-       my $nr = shift;
-       open my $fh, '<', shift;
-       my $cmd = join '', <$fh>;
-       close $fh;
-
-       tpm_cmd_nohdr 0x1C2, pack 'NNa*', 0x02000106, $nr, $cmd;
-}
-
-sub cmd_vtpm_add {
-       my($group,$uuid) = @_;
-       if ($uuid) {
-               $uuid =~ s/-//g;
-               $uuid = pack('H32', $uuid)."\0";
-       } else {
-               $uuid = '';
-       }
-       $uuid = unpack 'H32', tpm_cmd_nohdr 0x1C2, pack 'NNa*', 0x02000204, $group, $uuid;
-       printf "%s\n", join "-", unpack 'a8a4a4a4a12', $uuid;
-}
-
-sub cmd_vtpm_del {
-       my($uuid) = @_;
-       $uuid =~ s/-//g;
-       tpm_cmd_nohdr 0x1C2, pack 'NH32', 0x02000205, $uuid;
-}
-
-sub cmd_help {
-       print <<EOH;
-Usage: $0 <command> <args>
-
-list [index]
-       Lists the group identified by index, or all groups if omitted
-
-group-add rsa-modulus-file
-       Adds a new group to the TPM. The public key and Privacy CA data are
-       output to group-UUID/aik.pub and group-UUID/aik.priv-ca-data, and the
-       UUID is output to stdout.
-
-group-update index signed-config-list-file
-       Updates the permitted boot configuration list for an group
-
-group-del index
-       Deletes a group
-
-vtpm-add index
-       Adds a vTPM. Output: UUID
-
-vtpm-del UUID
-       Deletes a vTPM.
-
-EOH
-}
-
-my $cmd = shift || 'help';
-$cmd =~ s/-/_/g;
-my $fn = $main::{"cmd_$cmd"};
-if ($fn) {
-       $fn->(@ARGV);
-} else {
-       print "Unknown command: $cmd\n";
-       exit 1;
-}
diff --git a/stubdom/vtpmmgr/marshal.h b/stubdom/vtpmmgr/marshal.h
deleted file mode 100644 (file)
index d826f19..0000000
+++ /dev/null
@@ -1,851 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef MARSHAL_H
-#define MARSHAL_H
-
-#include <stdlib.h>
-#include <mini-os/byteorder.h>
-#include <mini-os/endian.h>
-#include "tcg.h"
-
-typedef enum UnpackPtr {
-       UNPACK_ALIAS,
-       UNPACK_ALLOC
-} UnpackPtr;
-
-inline BYTE* pack_BYTE(BYTE* ptr, BYTE t) {
-       ptr[0] = t;
-       return ++ptr;
-}
-
-inline BYTE* unpack_BYTE(BYTE* ptr, BYTE* t) {
-       t[0] = ptr[0];
-       return ++ptr;
-}
-
-inline int unpack3_BYTE(BYTE* ptr, UINT32* pos, UINT32 max, BYTE *t)
-{
-       if (*pos + 1 > max)
-               return TPM_SIZE;
-       unpack_BYTE(ptr + *pos, t);
-       *pos += 1;
-       return 0;
-}
-
-
-#define pack_BOOL(p, t) pack_BYTE(p, t)
-#define unpack_BOOL(p, t) unpack_BYTE(p, t)
-#define unpack3_BOOL(p, x, m, t) unpack3_BYTE(p, x, m, t)
-#define sizeof_BOOL(t) 1
-
-inline BYTE* pack_UINT16(void* ptr, UINT16 t) {
-       UINT16* p = ptr;
-       *p = cpu_to_be16(t);
-       return ptr + sizeof(UINT16);
-}
-
-inline BYTE* unpack_UINT16(void* ptr, UINT16* t) {
-       UINT16* p = ptr;
-       *t = be16_to_cpu(*p);
-       return ptr + sizeof(UINT16);
-}
-
-inline int unpack3_UINT16(BYTE* ptr, UINT32* pos, UINT32 max, UINT16 *t)
-{
-       if (*pos + 2 > max)
-               return TPM_SIZE;
-       unpack_UINT16(ptr + *pos, t);
-       *pos += 2;
-       return 0;
-}
-
-inline BYTE* pack_UINT32(void* ptr, UINT32 t) {
-       UINT32* p = ptr;
-       *p = cpu_to_be32(t);
-       return ptr + sizeof(UINT32);
-}
-
-inline BYTE* unpack_UINT32(void* ptr, UINT32* t) {
-       UINT32* p = ptr;
-       *t = be32_to_cpu(*p);
-       return ptr + sizeof(UINT32);
-}
-
-inline int unpack3_UINT32(BYTE* ptr, UINT32* pos, UINT32 max, UINT32 *t)
-{
-       if (*pos + 4 > max)
-               return TPM_SIZE;
-       unpack_UINT32(ptr + *pos, t);
-       *pos += 4;
-       return 0;
-}
-
-#define sizeof_BYTE(x) 1
-#define sizeof_UINT16(x) 2
-#define sizeof_UINT32(x) 4
-
-#define pack_TPM_RESULT(p, t) pack_UINT32(p, t)
-#define pack_TPM_PCRINDEX(p, t) pack_UINT32(p, t)
-#define pack_TPM_DIRINDEX(p, t) pack_UINT32(p, t)
-#define pack_TPM_HANDLE(p, t) pack_UINT32(p, t)
-#define pack_TPM_AUTHHANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TCPA_HASHHANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TCPA_HMACHANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TCPA_ENCHANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TPM_KEY_HANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TCPA_ENTITYHANDLE(p, t) pack_TPM_HANDLE(p, t)
-#define pack_TPM_RESOURCE_TYPE(p, t) pack_UINT32(p, t)
-#define pack_TPM_COMMAND_CODE(p, t) pack_UINT32(p, t)
-#define pack_TPM_PROTOCOL_ID(p, t) pack_UINT16(p, t)
-#define pack_TPM_AUTH_DATA_USAGE(p, t) pack_BYTE(p, t)
-#define pack_TPM_ENTITY_TYPE(p, t) pack_UINT16(p, t)
-#define pack_TPM_ALGORITHM_ID(p, t) pack_UINT32(p, t)
-#define pack_TPM_KEY_USAGE(p, t) pack_UINT16(p, t)
-#define pack_TPM_STARTUP_TYPE(p, t) pack_UINT16(p, t)
-#define pack_TPM_CAPABILITY_AREA(p, t) pack_UINT32(p, t)
-#define pack_TPM_ENC_SCHEME(p, t) pack_UINT16(p, t)
-#define pack_TPM_SIG_SCHEME(p, t) pack_UINT16(p, t)
-#define pack_TPM_MIGRATE_SCHEME(p, t) pack_UINT16(p, t)
-#define pack_TPM_PHYSICAL_PRESENCE(p, t) pack_UINT16(p, t)
-#define pack_TPM_KEY_FLAGS(p, t) pack_UINT32(p, t)
-#define pack_TPM_LOCALITY_SELECTION(p, t) pack_BYTE(p, t)
-
-#define unpack_TPM_RESULT(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_PCRINDEX(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_DIRINDEX(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_HANDLE(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_AUTHHANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TCPA_HASHHANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TCPA_HMACHANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TCPA_ENCHANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TPM_KEY_HANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TCPA_ENTITYHANDLE(p, t) unpack_TPM_HANDLE(p, t)
-#define unpack_TPM_RESOURCE_TYPE(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_COMMAND_CODE(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_PROTOCOL_ID(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_AUTH_DATA_USAGE(p, t) unpack_BYTE(p, t)
-#define unpack_TPM_ENTITY_TYPE(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_ALGORITHM_ID(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_KEY_USAGE(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_STARTUP_TYPE(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_CAPABILITY_AREA(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_ENC_SCHEME(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_SIG_SCHEME(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_MIGRATE_SCHEME(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_PHYSICAL_PRESENCE(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_KEY_FLAGS(p, t) unpack_UINT32(p, t)
-#define unpack_TPM_LOCALITY_SELECTION(p, t) unpack_BYTE(p, t)
-
-#define unpack3_TPM_RESULT(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_PCRINDEX(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_DIRINDEX(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_HANDLE(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_AUTHHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TCPA_HASHHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TCPA_HMACHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TCPA_ENCHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TPM_KEY_HANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TCPA_ENTITYHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t)
-#define unpack3_TPM_RESOURCE_TYPE(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_COMMAND_CODE(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_PROTOCOL_ID(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_AUTH_DATA_USAGE(p, l, m, t) unpack3_BYTE(p, l, m, t)
-#define unpack3_TPM_ENTITY_TYPE(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_ALGORITHM_ID(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_KEY_USAGE(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_STARTUP_TYPE(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_CAPABILITY_AREA(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_ENC_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_SIG_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_MIGRATE_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_PHYSICAL_PRESENCE(p, l, m, t) unpack3_UINT16(p, l, m, t)
-#define unpack3_TPM_KEY_FLAGS(p, l, m, t) unpack3_UINT32(p, l, m, t)
-#define unpack3_TPM_LOCALITY_SELECTION(p, l, m, t) unpack3_BYTE(p, l, m, t)
-#define unpack3_TPM_DEEP_QUOTE_INFO(p, l, m, t) unpack3_UINT32(p, l, m, t)
-
-#define sizeof_TPM_RESULT(t) sizeof_UINT32(t)
-#define sizeof_TPM_PCRINDEX(t) sizeof_UINT32(t)
-#define sizeof_TPM_DIRINDEX(t) sizeof_UINT32(t)
-#define sizeof_TPM_HANDLE(t) sizeof_UINT32(t)
-#define sizeof_TPM_AUTHHANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TCPA_HASHHANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TCPA_HMACHANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TCPA_ENCHANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TPM_KEY_HANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TCPA_ENTITYHANDLE(t) sizeof_TPM_HANDLE(t)
-#define sizeof_TPM_RESOURCE_TYPE(t) sizeof_UINT32(t)
-#define sizeof_TPM_COMMAND_CODE(t) sizeof_UINT32(t)
-#define sizeof_TPM_PROTOCOL_ID(t) sizeof_UINT16(t)
-#define sizeof_TPM_AUTH_DATA_USAGE(t) sizeof_BYTE(t)
-#define sizeof_TPM_ENTITY_TYPE(t) sizeof_UINT16(t)
-#define sizeof_TPM_ALGORITHM_ID(t) sizeof_UINT32(t)
-#define sizeof_TPM_KEY_USAGE(t) sizeof_UINT16(t)
-#define sizeof_TPM_STARTUP_TYPE(t) sizeof_UINT16(t)
-#define sizeof_TPM_CAPABILITY_AREA(t) sizeof_UINT32(t)
-#define sizeof_TPM_ENC_SCHEME(t) sizeof_UINT16(t)
-#define sizeof_TPM_SIG_SCHEME(t) sizeof_UINT16(t)
-#define sizeof_TPM_MIGRATE_SCHEME(t) sizeof_UINT16(t)
-#define sizeof_TPM_PHYSICAL_PRESENCE(t) sizeof_UINT16(t)
-#define sizeof_TPM_KEY_FLAGS(t) sizeof_UINT32(t)
-#define sizeof_TPM_LOCALITY_SELECTION(t) sizeof_BYTE(t)
-
-#define pack_TPM_AUTH_HANDLE(p, t) pack_UINT32(p, t)
-#define pack_TCS_CONTEXT_HANDLE(p, t) pack_UINT32(p, t)
-#define pack_TCS_KEY_HANDLE(p, t) pack_UINT32(p, t)
-
-#define unpack_TPM_AUTH_HANDLE(p, t) unpack_UINT32(p, t)
-#define unpack_TCS_CONTEXT_HANDLE(p, t) unpack_UINT32(p, t)
-#define unpack_TCS_KEY_HANDLE(p, t) unpack_UINT32(p, t)
-
-#define sizeof_TPM_AUTH_HANDLE(t) sizeof_UINT32(t)
-#define sizeof_TCS_CONTEXT_HANDLE(t) sizeof_UINT32(t)
-#define sizeof_TCS_KEY_HANDLE(t) sizeof_UINT32(t)
-
-
-inline BYTE* pack_BUFFER(BYTE* ptr, const BYTE* buf, UINT32 size) {
-       memcpy(ptr, buf, size);
-       return ptr + size;
-}
-
-inline BYTE* unpack_BUFFER(BYTE* ptr, BYTE* buf, UINT32 size) {
-       memcpy(buf, ptr, size);
-       return ptr + size;
-}
-
-inline int unpack3_BUFFER(BYTE* ptr, UINT32* pos, UINT32 max, BYTE* buf, UINT32 size) {
-       if (*pos + size > max)
-               return TPM_SIZE;
-       memcpy(buf, ptr + *pos, size);
-       *pos += size;
-       return 0;
-}
-
-#define sizeof_BUFFER(b, s) s
-
-inline BYTE* unpack_ALIAS(BYTE* ptr, BYTE** buf, UINT32 size) {
-       *buf = ptr;
-       return ptr + size;
-}
-
-inline BYTE* unpack_ALLOC(BYTE* ptr, BYTE** buf, UINT32 size) {
-       if(size) {
-               *buf = malloc(size);
-               memcpy(*buf, ptr, size);
-       } else {
-               *buf = NULL;
-       }
-       return ptr + size;
-}
-
-inline BYTE* unpack_PTR(BYTE* ptr, BYTE** buf, UINT32 size, UnpackPtr alloc) {
-       if(alloc == UNPACK_ALLOC) {
-               return unpack_ALLOC(ptr, buf, size);
-       } else {
-               return unpack_ALIAS(ptr, buf, size);
-       }
-}
-
-inline int unpack3_PTR(BYTE* ptr, UINT32* pos, UINT32 max, BYTE** buf, UINT32 size, UnpackPtr alloc) {
-       if (size > max || *pos + size > max)
-               return TPM_SIZE;
-       if (alloc == UNPACK_ALLOC) {
-               unpack_ALLOC(ptr + *pos, buf, size);
-       } else {
-               unpack_ALIAS(ptr + *pos, buf, size);
-       }
-       *pos += size;
-       return 0;
-}
-#define unpack3_VPTR(ptr, pos, max, buf, size, alloc) unpack3_PTR(ptr, pos, max, (void*)(buf), size, alloc)
-
-inline BYTE* pack_TPM_AUTHDATA(BYTE* ptr, const TPM_AUTHDATA* d) {
-       return pack_BUFFER(ptr, *d, TPM_DIGEST_SIZE);
-}
-
-inline BYTE* unpack_TPM_AUTHDATA(BYTE* ptr, TPM_AUTHDATA* d) {
-       return unpack_BUFFER(ptr, *d, TPM_DIGEST_SIZE);
-}
-
-inline int unpack3_TPM_AUTHDATA(BYTE* ptr, UINT32* pos, UINT32 len, TPM_AUTHDATA* d) {
-       return unpack3_BUFFER(ptr, pos, len, *d, TPM_DIGEST_SIZE);
-}
-
-#define sizeof_TPM_AUTHDATA(d) TPM_DIGEST_SIZE
-
-#define pack_TPM_SECRET(p, t) pack_TPM_AUTHDATA(p, t)
-#define pack_TPM_ENCAUTH(p, t) pack_TPM_AUTHDATA(p, t)
-#define pack_TPM_PAYLOAD_TYPE(p, t) pack_BYTE(p, t)
-#define pack_TPM_TAG(p, t) pack_UINT16(p, t)
-#define pack_TPM_STRUCTURE_TAG(p, t) pack_UINT16(p, t)
-
-#define unpack_TPM_SECRET(p, t) unpack_TPM_AUTHDATA(p, t)
-#define unpack_TPM_ENCAUTH(p, t) unpack_TPM_AUTHDATA(p, t)
-#define unpack_TPM_PAYLOAD_TYPE(p, t) unpack_BYTE(p, t)
-#define unpack_TPM_TAG(p, t) unpack_UINT16(p, t)
-#define unpack_TPM_STRUCTURE_TAG(p, t) unpack_UINT16(p, t)
-#define unpack3_TPM_STRUCTURE_TAG(p, l, m, t) unpack3_UINT16(p, l, m, t)
-
-#define sizeof_TPM_SECRET(t) sizeof_TPM_AUTHDATA(t)
-#define sizeof_TPM_ENCAUTH(t) sizeof_TPM_AUTHDATA(t)
-#define sizeof_TPM_PAYLOAD_TYPE(t) sizeof_BYTE(t)
-#define sizeof_TPM_TAG(t) sizeof_UINT16(t)
-#define sizeof_TPM_STRUCTURE_TAG(t) sizeof_UINT16(t)
-
-inline BYTE* pack_TPM_VERSION(BYTE* ptr, const TPM_VERSION* t) {
-       ptr[0] = t->major;
-       ptr[1] = t->minor;
-       ptr[2] = t->revMajor;
-       ptr[3] = t->revMinor;
-       return ptr + 4;
-}
-
-inline BYTE* unpack_TPM_VERSION(BYTE* ptr, TPM_VERSION* t) {
-       t->major = ptr[0];
-       t->minor = ptr[1];
-       t->revMajor = ptr[2];
-       t->revMinor = ptr[3];
-       return ptr + 4;
-}
-
-inline int unpack3_TPM_VERSION(BYTE* ptr, UINT32 *pos, UINT32 max, TPM_VERSION* t) {
-       if (*pos + 4 > max)
-               return TPM_SIZE;
-       ptr += *pos;
-       t->major = ptr[0];
-       t->minor = ptr[1];
-       t->revMajor = ptr[2];
-       t->revMinor = ptr[3];
-       *pos += 4;
-       return 0;
-}
-
-#define sizeof_TPM_VERSION(x) 4
-
-inline BYTE* pack_TPM_CAP_VERSION_INFO(BYTE* ptr, const TPM_CAP_VERSION_INFO* v) {
-       ptr = pack_TPM_STRUCTURE_TAG(ptr, v->tag);
-       ptr = pack_TPM_VERSION(ptr, &v->version);
-       ptr = pack_UINT16(ptr, v->specLevel);
-       ptr = pack_BYTE(ptr, v->errataRev);
-       ptr = pack_BUFFER(ptr, v->tpmVendorID, sizeof(v->tpmVendorID));
-       ptr = pack_UINT16(ptr, v->vendorSpecificSize);
-       ptr = pack_BUFFER(ptr, v->vendorSpecific, v->vendorSpecificSize);
-       return ptr;
-}
-
-inline BYTE* unpack_TPM_CAP_VERSION_INFO(BYTE* ptr, TPM_CAP_VERSION_INFO* v, UnpackPtr alloc) {
-       ptr = unpack_TPM_STRUCTURE_TAG(ptr, &v->tag);
-       ptr = unpack_TPM_VERSION(ptr, &v->version);
-       ptr = unpack_UINT16(ptr, &v->specLevel);
-       ptr = unpack_BYTE(ptr, &v->errataRev);
-       ptr = unpack_BUFFER(ptr, v->tpmVendorID, sizeof(v->tpmVendorID));
-       ptr = unpack_UINT16(ptr, &v->vendorSpecificSize);
-       ptr = unpack_PTR(ptr, &v->vendorSpecific, v->vendorSpecificSize, alloc);
-       return ptr;
-}
-
-inline BYTE* pack_TPM_DIGEST(BYTE* ptr, const TPM_DIGEST* d) {
-       return pack_BUFFER(ptr, d->digest, TPM_DIGEST_SIZE);
-}
-
-inline BYTE* unpack_TPM_DIGEST(BYTE* ptr, TPM_DIGEST* d) {
-       return unpack_BUFFER(ptr, d->digest, TPM_DIGEST_SIZE);
-}
-
-inline int unpack3_TPM_DIGEST(BYTE* ptr, UINT32* pos, UINT32 max, TPM_DIGEST* d) {
-       return unpack3_BUFFER(ptr, pos, max, d->digest, TPM_DIGEST_SIZE);
-}
-
-#define sizeof_TPM_DIGEST(d) TPM_DIGEST_SIZE
-
-#define pack_TPM_PCRVALUE(ptr, d) pack_TPM_DIGEST(ptr, d)
-#define unpack_TPM_PCRVALUE(ptr, d) unpack_TPM_DIGEST(ptr, d)
-#define unpack3_TPM_PCRVALUE(p...) unpack3_TPM_DIGEST(p)
-
-#define pack_TPM_COMPOSITE_HASH(ptr, d) pack_TPM_DIGEST(ptr, d)
-#define unpack_TPM_COMPOSITE_HASH(ptr, d) unpack_TPM_DIGEST(ptr, d)
-#define unpack3_TPM_COMPOSITE_HASH(ptr, p, m, d) unpack3_TPM_DIGEST(ptr, p, m, d)
-#define sizeof_TPM_COMPOSITE_HASH(d) TPM_DIGEST_SIZE
-
-#define pack_TPM_DIRVALUE(ptr, d) pack_TPM_DIGEST(ptr, d)
-#define unpack_TPM_DIRVALUE(ptr, d) unpack_TPM_DIGEST(ptr, d)
-
-#define pack_TPM_HMAC(ptr, d) pack_TPM_DIGEST(ptr, d)
-#define unpack_TPM_HMAC(ptr, d) unpack_TPM_DIGEST(ptr, d)
-
-#define pack_TPM_CHOSENID_HASH(ptr, d) pack_TPM_DIGEST(ptr, d)
-#define unpack_TPM_CHOSENID_HASH(ptr, d) unpack_TPM_DIGEST(ptr, d)
-
-inline BYTE* pack_TPM_NONCE(BYTE* ptr, const TPM_NONCE* n) {
-       return pack_BUFFER(ptr, n->nonce, TPM_DIGEST_SIZE);
-}
-
-inline BYTE* unpack_TPM_NONCE(BYTE* ptr, TPM_NONCE* n) {
-       return unpack_BUFFER(ptr, n->nonce, TPM_DIGEST_SIZE);
-}
-
-#define sizeof_TPM_NONCE(x) TPM_DIGEST_SIZE
-
-inline int unpack3_TPM_NONCE(BYTE* ptr, UINT32* pos, UINT32 max, TPM_NONCE* n) {
-       return unpack3_BUFFER(ptr, pos, max, n->nonce, TPM_DIGEST_SIZE);
-}
-
-inline BYTE* pack_TPM_SYMMETRIC_KEY_PARMS(BYTE* ptr, const TPM_SYMMETRIC_KEY_PARMS* k) {
-       ptr = pack_UINT32(ptr, k->keyLength);
-       ptr = pack_UINT32(ptr, k->blockSize);
-       ptr = pack_UINT32(ptr, k->ivSize);
-       return pack_BUFFER(ptr, k->IV, k->ivSize);
-}
-
-inline BYTE* pack_TPM_SYMMETRIC_KEY(BYTE* ptr, const TPM_SYMMETRIC_KEY* k) {
-       ptr = pack_UINT32(ptr, k->algId);
-       ptr = pack_UINT16(ptr, k->encScheme);
-       ptr = pack_UINT16(ptr, k->size);
-       return pack_BUFFER(ptr, k->data, k->size);
-}
-
-inline int unpack3_TPM_SYMMETRIC_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 max, TPM_SYMMETRIC_KEY_PARMS* k, UnpackPtr alloc) {
-       return unpack3_UINT32(ptr, pos, max, &k->keyLength) ||
-               unpack3_UINT32(ptr, pos, max, &k->blockSize) ||
-               unpack3_UINT32(ptr, pos, max, &k->ivSize) ||
-               unpack3_PTR(ptr, pos, max, &k->IV, k->ivSize, alloc);
-}
-
-inline int sizeof_TPM_SYMMETRIC_KEY_PARMS(const TPM_SYMMETRIC_KEY_PARMS* k) {
-       return 12 + k->ivSize;
-}
-
-inline int unpack3_TPM_SYMMETRIC_KEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_SYMMETRIC_KEY* k, UnpackPtr alloc) {
-       return unpack3_UINT32(ptr, pos, max, &k->algId) ||
-               unpack3_UINT16(ptr, pos, max, &k->encScheme) ||
-               unpack3_UINT16(ptr, pos, max, &k->size) ||
-               unpack3_PTR(ptr, pos, max, &k->data, k->size, alloc);
-}
-
-inline BYTE* pack_TPM_RSA_KEY_PARMS(BYTE* ptr, const TPM_RSA_KEY_PARMS* k) {
-       ptr = pack_UINT32(ptr, k->keyLength);
-       ptr = pack_UINT32(ptr, k->numPrimes);
-       ptr = pack_UINT32(ptr, k->exponentSize);
-       return pack_BUFFER(ptr, k->exponent, k->exponentSize);
-}
-
-inline int unpack3_TPM_RSA_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 max, TPM_RSA_KEY_PARMS* k, UnpackPtr alloc) {
-       return unpack3_UINT32(ptr, pos, max, &k->keyLength) ||
-               unpack3_UINT32(ptr, pos, max, &k->numPrimes) ||
-               unpack3_UINT32(ptr, pos, max, &k->exponentSize) ||
-               unpack3_PTR(ptr, pos, max, &k->exponent, k->exponentSize, alloc);
-}
-
-inline int sizeof_TPM_RSA_KEY_PARMS(const TPM_RSA_KEY_PARMS* k) {
-       return 12 + k->exponentSize;
-}
-
-
-inline BYTE* pack_TPM_KEY_PARMS(BYTE* ptr, const TPM_KEY_PARMS* k) {
-       ptr = pack_TPM_ALGORITHM_ID(ptr, k->algorithmID);
-       ptr = pack_TPM_ENC_SCHEME(ptr, k->encScheme);
-       ptr = pack_TPM_SIG_SCHEME(ptr, k->sigScheme);
-       ptr = pack_UINT32(ptr, k->parmSize);
-
-       if(k->parmSize) {
-               switch(k->algorithmID) {
-                       case TPM_ALG_RSA:
-                               return pack_TPM_RSA_KEY_PARMS(ptr, &k->parms.rsa);
-                       case TPM_ALG_AES128:
-                       case TPM_ALG_AES192:
-                       case TPM_ALG_AES256:
-                               return pack_TPM_SYMMETRIC_KEY_PARMS(ptr, &k->parms.sym);
-               }
-       }
-       return ptr;
-}
-
-inline int unpack3_TPM_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 len, TPM_KEY_PARMS* k, UnpackPtr alloc) {
-       int rc = unpack3_TPM_ALGORITHM_ID(ptr, pos, len, &k->algorithmID) ||
-               unpack3_TPM_ENC_SCHEME(ptr, pos, len, &k->encScheme) ||
-               unpack3_TPM_SIG_SCHEME(ptr, pos, len, &k->sigScheme) ||
-               unpack3_UINT32(ptr, pos, len, &k->parmSize);
-       if (rc || k->parmSize == 0)
-               return rc;
-       switch(k->algorithmID) {
-       case TPM_ALG_RSA:
-               return unpack3_TPM_RSA_KEY_PARMS(ptr, pos, len, &k->parms.rsa, alloc);
-       case TPM_ALG_AES128:
-       case TPM_ALG_AES192:
-       case TPM_ALG_AES256:
-               return unpack3_TPM_SYMMETRIC_KEY_PARMS(ptr, pos, len, &k->parms.sym, alloc);
-       }
-       return TPM_FAIL;
-}
-
-inline int sizeof_TPM_KEY_PARMS(const TPM_KEY_PARMS* k) {
-       int rc = 0;
-       rc += sizeof_TPM_ALGORITHM_ID(&k->algorithmID);
-       rc += sizeof_TPM_ENC_SCHEME(&k->encScheme);
-       rc += sizeof_TPM_SIG_SCHEME(&k->sigScheme);
-       rc += sizeof_UINT32(&k->parmSize);
-       if (!k->parmSize)
-               return rc;
-       switch(k->algorithmID) {
-       case TPM_ALG_RSA:
-               rc += sizeof_TPM_RSA_KEY_PARMS(&k->parms.rsa);
-               break;
-       case TPM_ALG_AES128:
-       case TPM_ALG_AES192:
-       case TPM_ALG_AES256:
-               rc += sizeof_TPM_SYMMETRIC_KEY_PARMS(&k->parms.sym);
-               break;
-       }
-       return rc;
-}
-
-inline BYTE* pack_TPM_STORE_PUBKEY(BYTE* ptr, const TPM_STORE_PUBKEY* k) {
-       ptr = pack_UINT32(ptr, k->keyLength);
-       ptr = pack_BUFFER(ptr, k->key, k->keyLength);
-       return ptr;
-}
-
-inline int unpack3_TPM_STORE_PUBKEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_STORE_PUBKEY* k, UnpackPtr alloc) {
-       return unpack3_UINT32(ptr, pos, max, &k->keyLength) ||
-               unpack3_PTR(ptr, pos, max, &k->key, k->keyLength, alloc);
-}
-
-inline int sizeof_TPM_STORE_PUBKEY(const TPM_STORE_PUBKEY* k) {
-       return 4 + k->keyLength;
-}
-
-inline BYTE* pack_TPM_PUBKEY(BYTE* ptr, const TPM_PUBKEY* k) {
-       ptr = pack_TPM_KEY_PARMS(ptr, &k->algorithmParms);
-       return pack_TPM_STORE_PUBKEY(ptr, &k->pubKey);
-}
-
-inline int unpack3_TPM_PUBKEY(BYTE* ptr, UINT32* pos, UINT32 len, TPM_PUBKEY* k, UnpackPtr alloc) {
-       return unpack3_TPM_KEY_PARMS(ptr, pos, len, &k->algorithmParms, alloc) ||
-               unpack3_TPM_STORE_PUBKEY(ptr, pos, len, &k->pubKey, alloc);
-}
-
-inline BYTE* pack_TPM_PCR_SELECTION(BYTE* ptr, const TPM_PCR_SELECTION* p) {
-       ptr = pack_UINT16(ptr, p->sizeOfSelect);
-       ptr = pack_BUFFER(ptr, p->pcrSelect, p->sizeOfSelect);
-       return ptr;
-}
-
-inline BYTE* unpack_TPM_PCR_SELECTION(BYTE* ptr, TPM_PCR_SELECTION* p, UnpackPtr alloc) {
-       ptr = unpack_UINT16(ptr, &p->sizeOfSelect);
-       ptr = unpack_PTR(ptr, &p->pcrSelect, p->sizeOfSelect, alloc);
-       return ptr;
-}
-
-inline int unpack3_TPM_PCR_SELECTION(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_SELECTION* p, UnpackPtr alloc) {
-       return unpack3_UINT16(ptr, pos, max, &p->sizeOfSelect) ||
-               unpack3_PTR(ptr, pos, max, &p->pcrSelect, p->sizeOfSelect, alloc);
-}
-
-inline int sizeof_TPM_PCR_SELECTION(const TPM_PCR_SELECTION* p) {
-       return 2 + p->sizeOfSelect;
-}
-
-inline BYTE* pack_TPM_PCR_INFO(BYTE* ptr, const TPM_PCR_INFO* p) {
-       ptr = pack_TPM_PCR_SELECTION(ptr, &p->pcrSelection);
-       ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtRelease);
-       ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtCreation);
-       return ptr;
-}
-
-inline int unpack3_TPM_PCR_INFO(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_INFO* p, UnpackPtr alloc) {
-       return unpack3_TPM_PCR_SELECTION(ptr, pos, max, &p->pcrSelection, alloc) ||
-               unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtRelease) ||
-               unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtCreation);
-}
-
-inline int sizeof_TPM_PCR_INFO(const TPM_PCR_INFO* p) {
-       int rc = 0;
-       rc += sizeof_TPM_PCR_SELECTION(&p->pcrSelection);
-       rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtRelease);
-       rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtCreation);
-       return rc;
-}
-
-inline BYTE* pack_TPM_PCR_INFO_LONG(BYTE* ptr, const TPM_PCR_INFO_LONG* p) {
-       ptr = pack_TPM_STRUCTURE_TAG(ptr, p->tag);
-       ptr = pack_TPM_LOCALITY_SELECTION(ptr, p->localityAtCreation);
-       ptr = pack_TPM_LOCALITY_SELECTION(ptr, p->localityAtRelease);
-       ptr = pack_TPM_PCR_SELECTION(ptr, &p->creationPCRSelection);
-       ptr = pack_TPM_PCR_SELECTION(ptr, &p->releasePCRSelection);
-       ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtCreation);
-       ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtRelease);
-       return ptr;
-}
-
-inline int sizeof_TPM_PCR_INFO_LONG(const TPM_PCR_INFO_LONG* p) {
-       int rc = 0;
-       rc += sizeof_TPM_STRUCTURE_TAG(p->tag);
-       rc += sizeof_TPM_LOCALITY_SELECTION(p->localityAtCreation);
-       rc += sizeof_TPM_LOCALITY_SELECTION(p->localityAtRelease);
-       rc += sizeof_TPM_PCR_SELECTION(&p->creationPCRSelection);
-       rc += sizeof_TPM_PCR_SELECTION(&p->releasePCRSelection);
-       rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtCreation);
-       rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtRelease);
-       return rc;
-}
-
-inline int unpack3_TPM_PCR_INFO_LONG(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_INFO_LONG* p, UnpackPtr alloc) {
-       return unpack3_TPM_STRUCTURE_TAG(ptr, pos, max, &p->tag) ||
-               unpack3_TPM_LOCALITY_SELECTION(ptr, pos, max,
-                                              &p->localityAtCreation) ||
-               unpack3_TPM_LOCALITY_SELECTION(ptr, pos, max,
-                                              &p->localityAtRelease) ||
-               unpack3_TPM_PCR_SELECTION(ptr, pos, max,
-                                         &p->creationPCRSelection, alloc) ||
-               unpack3_TPM_PCR_SELECTION(ptr, pos, max,
-                                         &p->releasePCRSelection, alloc) ||
-               unpack3_TPM_COMPOSITE_HASH(ptr, pos, max,
-                                         &p->digestAtCreation) ||
-               unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtRelease);
-}
-
-inline BYTE* pack_TPM_PCR_COMPOSITE(BYTE* ptr, const TPM_PCR_COMPOSITE* p) {
-       ptr = pack_TPM_PCR_SELECTION(ptr, &p->select);
-       ptr = pack_UINT32(ptr, p->valueSize);
-       ptr = pack_BUFFER(ptr, (const BYTE*)p->pcrValue, p->valueSize);
-       return ptr;
-}
-
-inline int unpack3_TPM_PCR_COMPOSITE(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_COMPOSITE* p, UnpackPtr alloc) {
-       return unpack3_TPM_PCR_SELECTION(ptr, pos, max, &p->select, alloc) ||
-               unpack3_UINT32(ptr, pos, max, &p->valueSize) ||
-               unpack3_PTR(ptr, pos, max, (BYTE**)&p->pcrValue, p->valueSize, alloc);
-}
-
-inline BYTE* pack_TPM_KEY(BYTE* ptr, const TPM_KEY* k) {
-       ptr = pack_TPM_VERSION(ptr, &k->ver);
-       ptr = pack_TPM_KEY_USAGE(ptr, k->keyUsage);
-       ptr = pack_TPM_KEY_FLAGS(ptr, k->keyFlags);
-       ptr = pack_TPM_AUTH_DATA_USAGE(ptr, k->authDataUsage);
-       ptr = pack_TPM_KEY_PARMS(ptr, &k->algorithmParms);
-       ptr = pack_UINT32(ptr, k->PCRInfoSize);
-       if(k->PCRInfoSize) {
-               ptr = pack_TPM_PCR_INFO(ptr, &k->PCRInfo);
-       }
-       ptr = pack_TPM_STORE_PUBKEY(ptr, &k->pubKey);
-       ptr = pack_UINT32(ptr, k->encDataSize);
-       return pack_BUFFER(ptr, k->encData, k->encDataSize);
-}
-
-inline int unpack3_TPM_KEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_KEY* k, UnpackPtr alloc) {
-       int rc = unpack3_TPM_VERSION(ptr, pos, max, &k->ver) ||
-               unpack3_TPM_KEY_USAGE(ptr, pos, max, &k->keyUsage) ||
-               unpack3_TPM_KEY_FLAGS(ptr, pos, max, &k->keyFlags) ||
-               unpack3_TPM_AUTH_DATA_USAGE(ptr, pos, max, &k->authDataUsage) ||
-               unpack3_TPM_KEY_PARMS(ptr, pos, max, &k->algorithmParms, alloc) ||
-               unpack3_UINT32(ptr, pos, max, &k->PCRInfoSize);
-       if (rc) return rc;
-       if(k->PCRInfoSize) {
-               rc = unpack3_TPM_PCR_INFO(ptr, pos, max, &k->PCRInfo, alloc);
-       }
-       if (rc) return rc;
-       return unpack3_TPM_STORE_PUBKEY(ptr, pos, max, &k->pubKey, alloc) ||
-               unpack3_UINT32(ptr, pos, max, &k->encDataSize) ||
-               unpack3_PTR(ptr, pos, max, &k->encData, k->encDataSize, alloc);
-}
-
-inline int sizeof_TPM_KEY(const TPM_KEY* k) {
-       int rc = 0;
-       rc += sizeof_TPM_VERSION(&k->ver);
-       rc += sizeof_TPM_KEY_USAGE(k->keyUsage);
-       rc += sizeof_TPM_KEY_FLAGS(k->keyFlags);
-       rc += sizeof_TPM_AUTH_DATA_USAGE(k->authDataUsage);
-       rc += sizeof_TPM_KEY_PARMS(&k->algorithmParms);
-       rc += sizeof_UINT32(k->PCRInfoSize);
-       if(k->PCRInfoSize) {
-               rc += sizeof_TPM_PCR_INFO(&k->PCRInfo);
-       }
-       rc += sizeof_TPM_STORE_PUBKEY(&k->pubKey);
-       rc += sizeof_UINT32(k->encDataSize);
-       rc += k->encDataSize;
-       return rc;
-}
-
-inline BYTE* pack_TPM_BOUND_DATA(BYTE* ptr, const TPM_BOUND_DATA* b, UINT32 payloadSize) {
-       ptr = pack_TPM_VERSION(ptr, &b->ver);
-       ptr = pack_TPM_PAYLOAD_TYPE(ptr, b->payload);
-       return pack_BUFFER(ptr, b->payloadData, payloadSize);
-}
-
-inline BYTE* unpack_TPM_BOUND_DATA(BYTE* ptr, TPM_BOUND_DATA* b, UINT32 payloadSize, UnpackPtr alloc) {
-       ptr = unpack_TPM_VERSION(ptr, &b->ver);
-       ptr = unpack_TPM_PAYLOAD_TYPE(ptr, &b->payload);
-       return unpack_PTR(ptr, &b->payloadData, payloadSize, alloc);
-}
-
-inline BYTE* pack_TPM_STORED_DATA(BYTE* ptr, const TPM_STORED_DATA* d) {
-       ptr = pack_TPM_VERSION(ptr, &d->ver);
-       ptr = pack_UINT32(ptr, d->sealInfoSize);
-       if(d->sealInfoSize) {
-               ptr = pack_TPM_PCR_INFO(ptr, &d->sealInfo);
-       }
-       ptr = pack_UINT32(ptr, d->encDataSize);
-       ptr = pack_BUFFER(ptr, d->encData, d->encDataSize);
-       return ptr;
-}
-
-inline int sizeof_TPM_STORED_DATA(const TPM_STORED_DATA* d) {
-       int rv = sizeof_TPM_VERSION(&d->ver) + sizeof_UINT32(d->sealInfoSize);
-       if (d->sealInfoSize) {
-               rv += sizeof_TPM_PCR_INFO(&d->sealInfo);
-       }
-       rv += sizeof_UINT32(d->encDataSize);
-       rv += sizeof_BUFFER(d->encData, d->encDataSize);
-       return rv;
-}
-
-inline int unpack3_TPM_STORED_DATA(BYTE* ptr, UINT32* pos, UINT32 len, TPM_STORED_DATA* d, UnpackPtr alloc) {
-       int rc = unpack3_TPM_VERSION(ptr, pos, len, &d->ver) ||
-               unpack3_UINT32(ptr, pos, len, &d->sealInfoSize);
-       if (rc)
-               return rc;
-       if (d->sealInfoSize)
-               rc = unpack3_TPM_PCR_INFO(ptr, pos, len, &d->sealInfo, alloc);
-       if (rc)
-               return rc;
-       rc = unpack3_UINT32(ptr, pos, len, &d->encDataSize) ||
-               unpack3_PTR(ptr, pos, len, &d->encData, d->encDataSize, alloc);
-       return rc;
-}
-
-inline BYTE* pack_TPM_STORED_DATA12(BYTE* ptr, const TPM_STORED_DATA12* d) {
-       ptr = pack_TPM_STRUCTURE_TAG(ptr, d->tag);
-       ptr = pack_TPM_ENTITY_TYPE(ptr, d->et);
-       ptr = pack_UINT32(ptr, d->sealInfoLongSize);
-       if(d->sealInfoLongSize) {
-               ptr = pack_TPM_PCR_INFO_LONG(ptr, &d->sealInfoLong);
-       }
-       ptr = pack_UINT32(ptr, d->encDataSize);
-       ptr = pack_BUFFER(ptr, d->encData, d->encDataSize);
-       return ptr;
-}
-
-inline int sizeof_TPM_STORED_DATA12(const TPM_STORED_DATA12* d) {
-       int rv = sizeof_TPM_STRUCTURE_TAG(&d->ver) +
-                sizeof_TPM_ENTITY_TYPE(&d->et) +
-                sizeof_UINT32(d->sealInfoLongSize);
-       if (d->sealInfoLongSize) {
-               rv += sizeof_TPM_PCR_INFO_LONG(&d->sealInfoLong);
-       }
-       rv += sizeof_UINT32(d->encDataSize);
-       rv += sizeof_BUFFER(d->encData, d->encDataSize);
-       return rv;
-}
-
-inline int unpack3_TPM_STORED_DATA12(BYTE* ptr, UINT32* pos, UINT32 len, TPM_STORED_DATA12* d, UnpackPtr alloc) {
-       int rc = unpack3_TPM_STRUCTURE_TAG(ptr, pos, len, &d->tag) ||
-               unpack3_TPM_ENTITY_TYPE(ptr, pos, len, &d->et) ||
-               unpack3_UINT32(ptr, pos, len, &d->sealInfoLongSize);
-       if (rc)
-               return rc;
-       if (d->sealInfoLongSize)
-               rc = unpack3_TPM_PCR_INFO_LONG(ptr, pos, len, &d->sealInfoLong,
-                                              alloc);
-       if (rc)
-               return rc;
-       rc = unpack3_UINT32(ptr, pos, len, &d->encDataSize) ||
-               unpack3_PTR(ptr, pos, len, &d->encData, d->encDataSize, alloc);
-       return rc;
-}
-
-inline BYTE* pack_TPM_AUTH_SESSION(BYTE* ptr, const TPM_AUTH_SESSION* auth) {
-       ptr = pack_TPM_AUTH_HANDLE(ptr, auth->AuthHandle);
-       ptr = pack_TPM_NONCE(ptr, &auth->NonceOdd);
-       ptr = pack_BOOL(ptr, auth->fContinueAuthSession);
-       ptr = pack_TPM_AUTHDATA(ptr, &auth->HMAC);
-       return ptr;
-}
-
-inline BYTE* unpack_TPM_AUTH_SESSION(BYTE* ptr, TPM_AUTH_SESSION* auth) {
-       ptr = unpack_TPM_NONCE(ptr, &auth->NonceEven);
-       ptr = unpack_BOOL(ptr, &auth->fContinueAuthSession);
-       ptr = unpack_TPM_AUTHDATA(ptr, &auth->HMAC);
-       return ptr;
-}
-
-inline int unpack3_TPM_AUTH_SESSION(BYTE* ptr, UINT32* pos, UINT32 len, TPM_AUTH_SESSION* auth) {
-       return unpack3_TPM_NONCE(ptr, pos, len, &auth->NonceEven) ||
-               unpack3_BOOL(ptr, pos, len, &auth->fContinueAuthSession) ||
-               unpack3_TPM_AUTHDATA(ptr, pos, len, &auth->HMAC);
-}
-
-
-inline int sizeof_TPM_AUTH_SESSION(const TPM_AUTH_SESSION* auth) {
-       int rv = 0;
-       rv += sizeof_TPM_AUTH_HANDLE(auth->AuthHandle);
-       rv += sizeof_TPM_NONCE(&auth->NonceOdd);
-       rv += sizeof_BOOL(auth->fContinueAuthSession);
-       rv += sizeof_TPM_AUTHDATA(&auth->HMAC);
-       return rv;
-}
-
-inline BYTE* pack_TPM_RQU_HEADER(BYTE* ptr,
-               TPM_TAG tag,
-               UINT32 size,
-               TPM_COMMAND_CODE ord) {
-       ptr = pack_UINT16(ptr, tag);
-       ptr = pack_UINT32(ptr, size);
-       return pack_UINT32(ptr, ord);
-}
-
-inline BYTE* unpack_TPM_RQU_HEADER(BYTE* ptr,
-               TPM_TAG* tag,
-               UINT32* size,
-               TPM_COMMAND_CODE* ord) {
-       ptr = unpack_UINT16(ptr, tag);
-       ptr = unpack_UINT32(ptr, size);
-       ptr = unpack_UINT32(ptr, ord);
-       return ptr;
-}
-
-inline int unpack3_TPM_RQU_HEADER(BYTE* ptr, UINT32* pos, UINT32 max,
-               TPM_TAG* tag, UINT32* size, TPM_COMMAND_CODE* ord) {
-       return
-               unpack3_UINT16(ptr, pos, max, tag) ||
-               unpack3_UINT32(ptr, pos, max, size) ||
-               unpack3_UINT32(ptr, pos, max, ord);
-}
-
-#define pack_TPM_RSP_HEADER(p, t, s, r) pack_TPM_RQU_HEADER(p, t, s, r)
-#define unpack_TPM_RSP_HEADER(p, t, s, r) unpack_TPM_RQU_HEADER(p, t, s, r)
-#define unpack3_TPM_RSP_HEADER(p, l, m, t, s, r) unpack3_TPM_RQU_HEADER(p, l, m, t, s, r)
-
-#endif
diff --git a/stubdom/vtpmmgr/mgmt_authority.c b/stubdom/vtpmmgr/mgmt_authority.c
deleted file mode 100644 (file)
index b839a20..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-#include <console.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-#include <polarssl/sha1.h>
-
-#include "vtpm_manager.h"
-#include "log.h"
-#include "uuid.h"
-
-#include "tpm.h"
-#include "tcg.h"
-#include "marshal.h"
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_tpm.h"
-#include "disk_io.h"
-#include "disk_crypto.h"
-#include "disk_format.h"
-#include "mgmt_authority.h"
-
-static int do_provision_aik(struct mem_group *group,
-               const struct tpm_authdata *privCADigest)
-{
-       TPM_KEY kinfo = {
-               .ver = TPM_STRUCT_VER_1_1,
-               .keyUsage = TPM_KEY_IDENTITY,
-               .keyFlags = 0,
-               .authDataUsage = TPM_AUTH_ALWAYS,
-               .algorithmParms = {
-                       .algorithmID = TPM_ALG_RSA,
-                       .encScheme = TPM_ES_NONE,
-                       .sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1,
-                       .parmSize = 12,
-                       .parms.rsa = {
-                               .keyLength = RSA_KEY_SIZE,
-                               .numPrimes = 2,
-                               .exponentSize = 0,
-                               .exponent = NULL,
-                       },
-               },
-               .PCRInfoSize = 0,
-               .pubKey.keyLength = 0,
-               .encDataSize = 0,
-       };
-
-       TPM_AUTH_SESSION srkAuth = TPM_AUTH_SESSION_INIT;
-       TPM_AUTH_SESSION ownAuth = TPM_AUTH_SESSION_INIT;
-       TPM_SECRET osapMask;
-
-       TPM_KEY key = TPM_KEY_INIT;
-       UINT32 identityBindingSize;
-       BYTE* identityBinding = NULL;
-
-       TPM_RESULT rc;
-
-       rc = TPM_OSAP(TPM_ET_OWNER, 0, (void*)&vtpm_globals.owner_auth, &osapMask, &ownAuth);
-       if (rc)
-               return rc;
-
-       rc = TPM_OIAP(&srkAuth);
-       if (rc)
-               return rc;
-
-       rc = TPM_MakeIdentity((void*)&group->aik_authdata, (void*)privCADigest, &kinfo,
-                       (void*)&vtpm_globals.srk_auth, (void*)&osapMask, &srkAuth, &ownAuth,
-                       &key, &identityBindingSize, &identityBinding);
-
-       TPM_TerminateHandle(srkAuth.AuthHandle);
-       TPM_TerminateHandle(ownAuth.AuthHandle);
-
-       if (rc) {
-               printk("TPM_MakeIdentity failed: %d\n", rc);
-               return rc;
-       }
-
-       if (key.pubKey.keyLength != 256)
-               rc = TPM_FAIL;
-       if (key.encDataSize != 256)
-               rc = TPM_FAIL;
-       if (identityBindingSize != 256)
-               rc = TPM_FAIL;
-       if (rc) {
-               printk("TPM_MakeIdentity TPM_KEY mismatch: %d %d %d\n",
-                       key.pubKey.keyLength, key.encDataSize, identityBindingSize);
-       } else {
-               memcpy(group->id_data.tpm_aik_public, key.pubKey.key, 256);
-               memcpy(group->id_data.tpm_aik_edata, key.encData, 256);
-               memcpy(group->details.recovery_data, identityBinding, 256);
-       }
-
-       free_TPM_KEY(&key);
-       free(identityBinding);
-
-       return rc;
-}
-
-static int do_load_aik(struct mem_group *group, TPM_HANDLE *handle)
-{
-       TPM_KEY key = {
-               .ver = TPM_STRUCT_VER_1_1,
-               .keyUsage = TPM_KEY_IDENTITY,
-               .keyFlags = 0,
-               .authDataUsage = TPM_AUTH_ALWAYS,
-               .algorithmParms = {
-                       .algorithmID = TPM_ALG_RSA,
-                       .encScheme = TPM_ES_NONE,
-                       .sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1,
-                       .parmSize = 12,
-                       .parms.rsa = {
-                               .keyLength = RSA_KEY_SIZE,
-                               .numPrimes = 2,
-                               .exponentSize = 0,
-                               .exponent = NULL,
-                       },
-               },
-               .PCRInfoSize = 0,
-               .pubKey.keyLength = 256,
-               .pubKey.key = group->id_data.tpm_aik_public,
-               .encDataSize = 256,
-               .encData = group->id_data.tpm_aik_edata,
-       };
-
-       return TPM_LoadKey(TPM_SRK_KEYHANDLE, &key, handle, (void*)&vtpm_globals.srk_auth, &vtpm_globals.oiap);
-}
-
-static void do_vtpminfo_hash(uint32_t extra_info_flags,struct mem_group *group,
-       const void* uuid, const uint8_t* kern_hash,unsigned char** calc_hashes)
-{
-       int i;
-       sha1_context ctx;
-       if(extra_info_flags & VTPM_QUOTE_FLAGS_HASH_UUID){
-               printk("hashing for FLAGS_HASH_UUID: ");
-               sha1_starts(&ctx);
-               if(uuid){
-                       printk("true");
-                       sha1_update(&ctx, (void*)uuid, 16);
-               }
-               sha1_finish(&ctx, *calc_hashes);
-               *calc_hashes = *calc_hashes + 20;
-               printk("\n");
-       }
-       if(extra_info_flags & VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS){
-               printk("hashing for VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS: ");
-               sha1_starts(&ctx);
-               if(kern_hash){
-                       printk("true");
-                       sha1_update(&ctx, (void*)kern_hash, 20);
-               }
-               sha1_finish(&ctx, *calc_hashes);
-               *calc_hashes = *calc_hashes + 20;
-               printk("\n");
-       }
-       if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_INFO){
-               printk("hashing for VTPM_QUOTE_FLAGS_GROUP_INFO: true\n");
-               sha1_starts(&ctx);
-               sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey));
-               sha1_update(&ctx, (void*)&group->details.cfg_seq, 8);
-               sha1_update(&ctx, (void*)&group->seal_bits.nr_cfgs, 4);
-               for(i=0; i < group->nr_seals; i++)
-                       sha1_update(&ctx, (void*)&group->seals[i].digest_release, 20);
-               sha1_update(&ctx, (void*)&group->seal_bits.nr_kerns, 4);
-               sha1_update(&ctx, (void*)&group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns));
-               sha1_finish(&ctx, *calc_hashes);
-               *calc_hashes = *calc_hashes + 20;
-       }
-       if(extra_info_flags & VTPM_QUOTE_FLAGS_GROUP_PUBKEY){
-               printk("hashing for VTPM_QUOTE_FLAGS_GROUP_PUBKEY: true\n");
-               sha1_starts(&ctx);
-               sha1_update(&ctx, (void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey));
-               sha1_finish(&ctx, *calc_hashes);
-               *calc_hashes = *calc_hashes + 20;
-       }
-}
-
-/* 
- * Sets up resettable PCRs for a vTPM deep quote request
- */
-static int do_pcr_setup(struct mem_group *group, const void* uuid, const uint8_t* kern_hash)
-{
-       uint32_t reset_sel = (1 << 20) | (1 << 21) | (1 << 22) | (1 << 23);
-       sha1_context ctx;
-       TPM_DIGEST extended;
-       TPM_PCR_SELECTION sel = {
-               .sizeOfSelect = 3,
-               .pcrSelect = (void*)&reset_sel,
-       };
-       int rc;
-       int i;
-
-       rc = TPM_Reset(&sel);
-       if (rc)
-               return rc;
-
-       sha1((void*)&group->id_data.saa_pubkey, sizeof(group->id_data.saa_pubkey), extended.digest);
-       rc = TPM_Extend(20, &extended, &extended);
-       if (rc)
-               return rc;
-
-       sha1_starts(&ctx);
-       sha1_update(&ctx, (void*)&group->details.cfg_seq, 8);
-       sha1_update(&ctx, (void*)&group->seal_bits.nr_cfgs, 4);
-       for(i=0; i < group->nr_seals; i++)
-               sha1_update(&ctx, (void*)&group->seals[i].digest_release, 20);
-       sha1_update(&ctx, (void*)&group->seal_bits.nr_kerns, 4);
-       sha1_update(&ctx, (void*)&group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns));
-       sha1_finish(&ctx, extended.digest);
-       rc = TPM_Extend(21, &extended, &extended);
-       if (rc)
-               return rc;
-
-       if (kern_hash) {
-               rc = TPM_Extend(22, (void*)kern_hash, &extended);
-               if (rc)
-                       return rc;
-       }
-
-       memset(&extended, 0, 20);
-       memcpy(&extended, group->id_data.uuid, 16);
-       rc = TPM_Extend(23, &extended, &extended);
-       if (rc)
-               return rc;
-
-       if (uuid) {
-               memset(&extended, 0, 20);
-               memcpy(&extended, uuid, 16);
-               rc = TPM_Extend(23, &extended, &extended);
-               if (rc)
-                       return rc;
-       }
-
-       return rc;
-}
-
-struct mem_group *vtpm_new_group(const struct tpm_authdata *privCADigest)
-{
-       static struct mem_group* group0_delayed = NULL;
-       struct mem_group *group;
-
-       if (group0_delayed) {
-               group = group0_delayed;
-               group0_delayed = NULL;
-       } else {
-               group = calloc(1, sizeof(*group));
-
-               group->flags = MEM_GROUP_FLAG_FIRSTBOOT;
-
-               do_random(&group->id_data.uuid, 16);
-               do_random(&group->group_key, 16);
-               do_random(&group->rollback_mac_key, 16);
-               do_random(&group->aik_authdata, 20);
-
-               group->id_data.uuid[6] = 0x40 | (group->id_data.uuid[6] & 0x0F);
-               group->id_data.uuid[8] = 0x80 | (group->id_data.uuid[8] & 0x3F);
-       }
-
-       if (privCADigest) {
-               int rc;
-               rc = do_provision_aik(group, privCADigest);
-               if (rc) {
-                       free(group);
-                       return NULL;
-               }
-       } else {
-               group0_delayed = group;
-       }
-
-       return group;
-}
-
-int group_do_activate(struct mem_group *group, void* blob, int blobSize,
-       void* resp, unsigned int *rlen)
-{
-       int rc;
-       TPM_HANDLE handle;
-       TPM_AUTH_SESSION aikAuth = TPM_AUTH_SESSION_INIT;
-       TPM_AUTH_SESSION ownAuth = TPM_AUTH_SESSION_INIT;
-       TPM_SYMMETRIC_KEY symKey;
-
-       /* ActivateIdentity with TPM_EK_BLOB_ACTIVATE can check PCRs */
-       rc = do_pcr_setup(group, NULL, NULL);
-       if (rc)
-               return rc;
-
-       rc = do_load_aik(group, &handle);
-       if (rc)
-               return rc;
-
-       rc = TPM_OIAP(&aikAuth);
-       if (rc) {
-               TPM_TerminateHandle(handle);
-               return rc;
-       }
-
-       rc = TPM_OIAP(&ownAuth);
-       if (rc) {
-               TPM_TerminateHandle(aikAuth.AuthHandle);
-               TPM_TerminateHandle(handle);
-               return rc;
-       }
-
-       rc = TPM_ActivateIdentity(handle, blob, blobSize, (void*)&group->aik_authdata,
-                       (void*)&vtpm_globals.owner_auth, &aikAuth, &ownAuth, &symKey);
-
-       TPM_TerminateHandle(ownAuth.AuthHandle);
-       TPM_TerminateHandle(aikAuth.AuthHandle);
-       TPM_TerminateHandle(handle);
-
-       if (rc)
-               return rc;
-
-       pack_TPM_SYMMETRIC_KEY(resp + *rlen, &symKey);
-       *rlen += 8 + symKey.size;
-       free(symKey.data);
-
-       return rc;
-}
-
-int vtpm_do_quote(struct mem_group *group, const uuid_t uuid,
-       const uint8_t* kern_hash, const struct tpm_authdata *data, TPM_PCR_SELECTION *sel,
-       uint32_t extra_info_flags, void* pcr_out, uint32_t *pcr_size, void* sig_out)
-{
-       TPM_HANDLE handle;
-       TPM_AUTH_SESSION oiap = TPM_AUTH_SESSION_INIT;
-       TPM_PCR_COMPOSITE pcrs;
-       BYTE* sig;
-       UINT32 size;
-       sha1_context ctx;
-       TPM_DIGEST externData;
-       const void* data_to_quote = data;
-       unsigned char* ppcr_out = (unsigned char*)pcr_out;
-       unsigned char** pcr_outv = (unsigned char**)&ppcr_out;
-
-       int rc;
-       printk("Extra Info Flags =0x%x\n",extra_info_flags);
-       if((extra_info_flags & ~VTPM_QUOTE_FLAGS_HASH_UUID
-               & ~VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS
-               & ~VTPM_QUOTE_FLAGS_GROUP_INFO
-               & ~VTPM_QUOTE_FLAGS_GROUP_PUBKEY) != 0)
-               return VTPM_INVALID_REQUEST;
-
-       sha1_starts(&ctx);
-       sha1_update(&ctx, (void*)&extra_info_flags, 4);
-       sha1_update(&ctx, (void*)data, 20);
-       if(pcr_out!=NULL && extra_info_flags!=0)
-       {
-               /*creates hashes and sets them to pcr_out*/
-               do_vtpminfo_hash(extra_info_flags,group, uuid, kern_hash, pcr_outv);
-               *pcr_size = *pcr_outv - (unsigned char*)pcr_out;
-               if(*pcr_size > 0)
-                       sha1_update(&ctx, pcr_out, *pcr_size);
-       }
-       sha1_finish(&ctx, externData.digest);
-       data_to_quote = (void*)externData.digest;
-
-       rc = do_load_aik(group, &handle);
-       if (rc)
-               return rc;
-
-       rc = TPM_OIAP(&oiap);
-       if (rc) {
-               TPM_TerminateHandle(handle);
-               return rc;
-       }
-
-       rc = TPM_Quote(handle, data_to_quote, sel, (void*)&group->aik_authdata, &oiap, &pcrs, &sig, &size);
-
-       TPM_TerminateHandle(oiap.AuthHandle);
-       TPM_FlushSpecific(handle, TPM_RT_KEY);
-
-       if (rc)
-               return rc;
-       if (size != 256) {
-               printk("Bad size\n");
-               rc = TPM_FAIL;
-               goto end;
-       }
-
-       if (pcr_out) {
-               /*append TPM_PCRVALUEs after externData hashes*/
-               memcpy(pcr_out+*pcr_size, pcrs.pcrValue, pcrs.valueSize);
-               *pcr_size = *pcr_size + pcrs.valueSize;
-       }
-
-       memcpy(sig_out, sig, size);
-
-end:
-       free_TPM_PCR_COMPOSITE(&pcrs);
-       free(sig);
-
-       return rc;
-}
diff --git a/stubdom/vtpmmgr/mgmt_authority.h b/stubdom/vtpmmgr/mgmt_authority.h
deleted file mode 100644 (file)
index cdd06aa..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __VTPMMGR_MGMT_AUTHORITY_H
-#define __VTPMMGR_MGMT_AUTHORITY_H
-
-struct mem_group *vtpm_new_group(const struct tpm_authdata *privCADigest);
-int group_do_activate(struct mem_group *group, void* blob, int blobSize,
-       void* resp, unsigned int *rlen);
-int vtpm_do_quote(struct mem_group *group, const uuid_t uuid,
-       const uint8_t* kern_hash, const struct tpm_authdata *data, TPM_PCR_SELECTION *sel, uint32_t extraInfoFlags,
-       void* pcr_out, uint32_t *pcr_size, void* sig_out);
-
-#endif
diff --git a/stubdom/vtpmmgr/minios.cfg b/stubdom/vtpmmgr/minios.cfg
deleted file mode 100644 (file)
index 3fb383d..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-CONFIG_TPMFRONT=y
-CONFIG_TPM_TIS=y
-CONFIG_TPMBACK=y
-CONFIG_START_NETWORK=n
-CONFIG_TEST=n
-CONFIG_PCIFRONT=n
-CONFIG_BLKFRONT=y
-CONFIG_NETFRONT=n
-CONFIG_FBFRONT=n
-CONFIG_KBDFRONT=n
-CONFIG_CONSFRONT=n
-CONFIG_XENBUS=y
-CONFIG_LWIP=n
-CONFIG_XC=n
diff --git a/stubdom/vtpmmgr/tcg.h b/stubdom/vtpmmgr/tcg.h
deleted file mode 100644 (file)
index 813ce57..0000000
+++ /dev/null
@@ -1,751 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005 Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef __TCG_H__
-#define __TCG_H__
-
-#include <stdlib.h>
-#include <stdint.h>
-#include "common_types.h"
-
-// **************************** CONSTANTS *********************************
-
-// BOOL values
-#define TRUE 0x01
-#define FALSE 0x00
-
-#define TCPA_MAX_BUFFER_LENGTH 0x2000
-
-//
-// TPM_COMMAND_CODE values
-#define TPM_PROTECTED_ORDINAL 0x00000000UL
-#define TPM_UNPROTECTED_ORDINAL 0x80000000UL
-#define TPM_CONNECTION_ORDINAL 0x40000000UL
-#define TPM_VENDOR_ORDINAL 0x20000000UL
-
-#define TPM_ORD_OIAP                     (10UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_OSAP                     (11UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ChangeAuth               (12UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_TakeOwnership            (13UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ChangeAuthAsymStart      (14UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ChangeAuthAsymFinish     (15UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ChangeAuthOwner          (16UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Extend                   (20UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_PcrRead                  (21UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Quote                    (22UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Seal                     (23UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Unseal                   (24UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_DirWriteAuth             (25UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_DirRead                  (26UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_UnBind                   (30UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CreateWrapKey            (31UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadKey                  (32UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetPubKey                (33UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_EvictKey                 (34UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CreateMigrationBlob      (40UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReWrapKey                (41UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ConvertMigrationBlob     (42UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_AuthorizeMigrationKey    (43UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CreateMaintenanceArchive (44UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadMaintenanceArchive   (45UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_KillMaintenanceFeature   (46UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadManuMaintPub         (47UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReadManuMaintPub         (48UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CertifyKey               (50UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Sign                     (60UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetRandom                (70UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_StirRandom               (71UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SelfTestFull             (80UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SelfTestStartup          (81UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CertifySelfTest          (82UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ContinueSelfTest         (83UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetTestResult            (84UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Reset                    (90UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_OwnerClear               (91UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_DisableOwnerClear        (92UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ForceClear               (93UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_DisableForceClear        (94UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetCapabilitySigned      (100UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetCapability            (101UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetCapabilityOwner       (102UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_OwnerSetDisable          (110UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_PhysicalEnable           (111UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_PhysicalDisable          (112UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SetOwnerInstall          (113UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_PhysicalSetDeactivated   (114UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SetTempDeactivated       (115UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CreateEndorsementKeyPair (120UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_MakeIdentity             (121UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ActivateIdentity         (122UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReadPubek                (124UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_OwnerReadPubek           (125UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_DisablePubekRead         (126UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetAuditEvent            (130UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetAuditEventSigned      (131UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetOrdinalAuditStatus    (140UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SetOrdinalAuditStatus    (141UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Terminate_Handle         (150UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Init                     (151UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SaveState                (152UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Startup                  (153UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SetRedirection           (154UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SHA1Start                (160UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SHA1Update               (161UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SHA1Complete             (162UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SHA1CompleteExtend       (163UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_FieldUpgrade             (170UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SaveKeyContext           (180UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadKeyContext           (181UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SaveAuthContext          (182UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadAuthContext          (183UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_SaveContext                      (184UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_LoadContext                      (185UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_FlushSpecific                    (186UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_PCR_Reset                        (200UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_NV_DefineSpace                   (204UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_NV_WriteValue                    (205UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_NV_WriteValueAuth                (206UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_NV_ReadValue                     (207UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_NV_ReadValueAuth                 (208UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_UpdateVerification      (209UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_Manage                  (210UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_CreateKeyDelegation     (212UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_CreateOwnerDelegation   (213UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_VerifyDelegation        (214UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_LoadOwnerDelegation     (216UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_ReadAuth                (217UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_Delegate_ReadTable               (219UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_CreateCounter                    (220UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_IncrementCounter                 (221UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReadCounter                      (222UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReleaseCounter                   (223UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReleaseCounterOwner              (224UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_EstablishTransport               (230UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ExecuteTransport                 (231UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_ReleaseTransportSigned           (232UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_GetTicks                         (241UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_TickStampBlob                    (242UL + TPM_PROTECTED_ORDINAL)
-#define TPM_ORD_MAX                              (256UL + TPM_PROTECTED_ORDINAL)
-
-#define TSC_ORD_PhysicalPresence         (10UL + TPM_CONNECTION_ORDINAL)
-
-
-
-//
-// TPM_RESULT values
-//
-// just put in the whole table from spec 1.2
-
-#define TPM_BASE   0x0 // The start of TPM return codes
-#define TPM_VENDOR_ERROR 0x00000400 // Mask to indicate that the error code is vendor specific for vendor specific commands
-#define TPM_NON_FATAL  0x00000800 // Mask to indicate that the error code is a non-fatal failure.
-
-#define TPM_SUCCESS   TPM_BASE // Successful completion of the operation
-#define TPM_AUTHFAIL      TPM_BASE + 1 // Authentication failed
-#define TPM_BADINDEX      TPM_BASE + 2 // The index to a PCR, DIR or other register is incorrect
-#define TPM_BAD_PARAMETER     TPM_BASE + 3 // One or more parameter is bad
-#define TPM_AUDITFAILURE     TPM_BASE + 4 // An operation completed successfully but the auditing of that operation failed.
-#define TPM_CLEAR_DISABLED     TPM_BASE + 5 // The clear disable flag is set and all clear operations now require physical access
-#define TPM_DEACTIVATED     TPM_BASE + 6 // The TPM is deactivated
-#define TPM_DISABLED      TPM_BASE + 7 // The TPM is disabled
-#define TPM_DISABLED_CMD     TPM_BASE + 8 // The target command has been disabled
-#define TPM_FAIL       TPM_BASE + 9 // The operation failed
-#define TPM_BAD_ORDINAL     TPM_BASE + 10 // The ordinal was unknown or inconsistent
-#define TPM_INSTALL_DISABLED   TPM_BASE + 11 // The ability to install an owner is disabled
-#define TPM_INVALID_KEYHANDLE  TPM_BASE + 12 // The key handle presented was invalid
-#define TPM_KEYNOTFOUND     TPM_BASE + 13 // The target key was not found
-#define TPM_INAPPROPRIATE_ENC  TPM_BASE + 14 // Unacceptable encryption scheme
-#define TPM_MIGRATEFAIL     TPM_BASE + 15 // Migration authorization failed
-#define TPM_INVALID_PCR_INFO   TPM_BASE + 16 // PCR information could not be interpreted
-#define TPM_NOSPACE      TPM_BASE + 17 // No room to load key.
-#define TPM_NOSRK       TPM_BASE + 18 // There is no SRK set
-#define TPM_NOTSEALED_BLOB     TPM_BASE + 19 // An encrypted blob is invalid or was not created by this TPM
-#define TPM_OWNER_SET      TPM_BASE + 20 // There is already an Owner
-#define TPM_RESOURCES      TPM_BASE + 21 // The TPM has insufficient internal resources to perform the requested action.
-#define TPM_SHORTRANDOM     TPM_BASE + 22 // A random string was too short
-#define TPM_SIZE       TPM_BASE + 23 // The TPM does not have the space to perform the operation.
-#define TPM_WRONGPCRVAL     TPM_BASE + 24 // The named PCR value does not match the current PCR value.
-#define TPM_BAD_PARAM_SIZE     TPM_BASE + 25 // The paramSize argument to the command has the incorrect value
-#define TPM_SHA_THREAD      TPM_BASE + 26 // There is no existing SHA-1 thread.
-#define TPM_SHA_ERROR      TPM_BASE + 27 // The calculation is unable to proceed because the existing SHA-1 thread has already encountered an error.
-#define TPM_FAILEDSELFTEST     TPM_BASE + 28 // Self-test has failed and the TPM has shutdown.
-#define TPM_AUTH2FAIL      TPM_BASE + 29 // The authorization for the second key in a 2 key function failed authorization
-#define TPM_BADTAG       TPM_BASE + 30 // The tag value sent to for a command is invalid
-#define TPM_IOERROR      TPM_BASE + 31 // An IO error occurred transmitting information to the TPM
-#define TPM_ENCRYPT_ERROR     TPM_BASE + 32 // The encryption process had a problem.
-#define TPM_DECRYPT_ERROR     TPM_BASE + 33 // The decryption process did not complete.
-#define TPM_INVALID_AUTHHANDLE TPM_BASE + 34 // An invalid handle was used.
-#define TPM_NO_ENDORSEMENT     TPM_BASE + 35 // The TPM does not a EK installed
-#define TPM_INVALID_KEYUSAGE   TPM_BASE + 36 // The usage of a key is not allowed
-#define TPM_WRONG_ENTITYTYPE   TPM_BASE + 37 // The submitted entity type is not allowed
-#define TPM_INVALID_POSTINIT   TPM_BASE + 38 // The command was received in the wrong sequence relative to TPM_Init and a subsequent TPM_Startup
-#define TPM_INAPPROPRIATE_SIG  TPM_BASE + 39 // Signed data cannot include additional DER information
-#define TPM_BAD_KEY_PROPERTY   TPM_BASE + 40 // The key properties in TPM_KEY_PARMs are not supported by this TPM
-
-#define TPM_BAD_MIGRATION      TPM_BASE + 41 // The migration properties of this key are incorrect.
-#define TPM_BAD_SCHEME       TPM_BASE + 42 // The signature or encryption scheme for this key is incorrect or not permitted in this situation.
-#define TPM_BAD_DATASIZE      TPM_BASE + 43 // The size of the data (or blob) parameter is bad or inconsistent with the referenced key
-#define TPM_BAD_MODE       TPM_BASE + 44 // A mode parameter is bad, such as capArea or subCapArea for TPM_GetCapability, phsicalPresence parameter for TPM_PhysicalPresence, or migrationType for TPM_CreateMigrationBlob.
-#define TPM_BAD_PRESENCE      TPM_BASE + 45 // Either the physicalPresence or physicalPresenceLock bits have the wrong value
-#define TPM_BAD_VERSION      TPM_BASE + 46 // The TPM cannot perform this version of the capability
-#define TPM_NO_WRAP_TRANSPORT     TPM_BASE + 47 // The TPM does not allow for wrapped transport sessions
-#define TPM_AUDITFAIL_UNSUCCESSFUL TPM_BASE + 48 // TPM audit construction failed and the underlying command was returning a failure code also
-#define TPM_AUDITFAIL_SUCCESSFUL   TPM_BASE + 49 // TPM audit construction failed and the underlying command was returning success
-#define TPM_NOTRESETABLE      TPM_BASE + 50 // Attempt to reset a PCR register that does not have the resettable attribute
-#define TPM_NOTLOCAL       TPM_BASE + 51 // Attempt to reset a PCR register that requires locality and locality modifier not part of command transport
-#define TPM_BAD_TYPE       TPM_BASE + 52 // Make identity blob not properly typed
-#define TPM_INVALID_RESOURCE     TPM_BASE + 53 // When saving context identified resource type does not match actual resource
-#define TPM_NOTFIPS       TPM_BASE + 54 // The TPM is attempting to execute a command only available when in FIPS mode
-#define TPM_INVALID_FAMILY      TPM_BASE + 55 // The command is attempting to use an invalid family ID
-#define TPM_NO_NV_PERMISSION     TPM_BASE + 56 // The permission to manipulate the NV storage is not available
-#define TPM_REQUIRES_SIGN      TPM_BASE + 57 // The operation requires a signed command
-#define TPM_KEY_NOTSUPPORTED     TPM_BASE + 58 // Wrong operation to load an NV key
-#define TPM_AUTH_CONFLICT      TPM_BASE + 59 // NV_LoadKey blob requires both owner and blob authorization
-#define TPM_AREA_LOCKED      TPM_BASE + 60 // The NV area is locked and not writtable
-#define TPM_BAD_LOCALITY      TPM_BASE + 61 // The locality is incorrect for the attempted operation
-#define TPM_READ_ONLY       TPM_BASE + 62 // The NV area is read only and can't be written to
-#define TPM_PER_NOWRITE      TPM_BASE + 63 // There is no protection on the write to the NV area
-#define TPM_FAMILYCOUNT      TPM_BASE + 64 // The family count value does not match
-#define TPM_WRITE_LOCKED      TPM_BASE + 65 // The NV area has already been written to
-#define TPM_BAD_ATTRIBUTES      TPM_BASE + 66 // The NV area attributes conflict
-#define TPM_INVALID_STRUCTURE     TPM_BASE + 67 // The structure tag and version are invalid or inconsistent
-#define TPM_KEY_OWNER_CONTROL     TPM_BASE + 68 // The key is under control of the TPM Owner and can only be evicted by the TPM Owner.
-#define TPM_BAD_COUNTER      TPM_BASE + 69 // The counter handle is incorrect
-#define TPM_NOT_FULLWRITE      TPM_BASE + 70 // The write is not a complete write of the area
-#define TPM_CONTEXT_GAP      TPM_BASE + 71 // The gap between saved context counts is too large
-#define TPM_MAXNVWRITES      TPM_BASE + 72 // The maximum number of NV writes without an owner has been exceeded
-#define TPM_NOOPERATOR       TPM_BASE + 73 // No operator authorization value is set
-#define TPM_RESOURCEMISSING     TPM_BASE + 74 // The resource pointed to by context is not loaded
-#define TPM_DELEGATE_LOCK      TPM_BASE + 75 // The delegate administration is locked
-#define TPM_DELEGATE_FAMILY     TPM_BASE + 76 // Attempt to manage a family other then the delegated family
-#define TPM_DELEGATE_ADMIN      TPM_BASE + 77 // Delegation table management not enabled
-#define TPM_TRANSPORT_EXCLUSIVE    TPM_BASE + 78 // There was a command executed outside of an exclusive transport session
-
-// TPM_STARTUP_TYPE values
-#define TPM_ST_CLEAR 0x0001
-#define TPM_ST_STATE 0x0002
-#define TPM_ST_DEACTIVATED 0x003
-
-// TPM_TAG values
-#define TPM_TAG_PCR_INFO_LONG 0x0006
-#define TPM_TAG_STORED_DATA12 0x0016
-#define TPM_TAG_RQU_COMMAND 0x00c1
-#define TPM_TAG_RQU_AUTH1_COMMAND 0x00c2
-#define TPM_TAG_RQU_AUTH2_COMMAND 0x00c3
-#define TPM_TAG_RSP_COMMAND 0x00c4
-#define TPM_TAG_RSP_AUTH1_COMMAND 0x00c5
-#define TPM_TAG_RSP_AUTH2_COMMAND 0x00c6
-
-// TPM_PAYLOAD_TYPE values
-#define TPM_PT_ASYM 0x01
-#define TPM_PT_BIND 0x02
-#define TPM_PT_MIGRATE 0x03
-#define TPM_PT_MAINT 0x04
-#define TPM_PT_SEAL 0x05
-
-// TPM_ENTITY_TYPE values
-#define TPM_ET_KEYHANDLE 0x0001
-#define TPM_ET_OWNER 0x0002
-#define TPM_ET_DATA 0x0003
-#define TPM_ET_SRK 0x0004
-#define TPM_ET_KEY 0x0005
-
-/// TPM_ResourceTypes
-#define TPM_RT_KEY      0x00000001
-#define TPM_RT_AUTH     0x00000002
-#define TPM_RT_HASH     0x00000003
-#define TPM_RT_TRANS    0x00000004
-#define TPM_RT_CONTEXT  0x00000005
-#define TPM_RT_COUNTER  0x00000006
-#define TPM_RT_DELEGATE 0x00000007
-#define TPM_RT_DAA_TPM  0x00000008
-#define TPM_RT_DAA_V0   0x00000009
-#define TPM_RT_DAA_V1   0x0000000A
-
-
-
-// TPM_PROTOCOL_ID values
-#define TPM_PID_OIAP 0x0001
-#define TPM_PID_OSAP 0x0002
-#define TPM_PID_ADIP 0x0003
-#define TPM_PID_ADCP 0x0004
-#define TPM_PID_OWNER 0x0005
-
-// TPM_ALGORITHM_ID values
-#define TPM_ALG_RSA 0x00000001
-#define TPM_ALG_SHA 0x00000004
-#define TPM_ALG_HMAC 0x00000005
-#define TPM_ALG_AES128 0x00000006
-#define TPM_ALG_MFG1 0x00000007
-#define TPM_ALG_AES192 0x00000008
-#define TPM_ALG_AES256 0x00000009
-#define TPM_ALG_XOR 0x0000000A
-
-// TPM_ENC_SCHEME values
-#define TPM_ES_NONE 0x0001
-#define TPM_ES_RSAESPKCSv15 0x0002
-#define TPM_ES_RSAESOAEP_SHA1_MGF1 0x0003
-
-// TPM_SIG_SCHEME values
-#define TPM_SS_NONE 0x0001
-#define TPM_SS_RSASSAPKCS1v15_SHA1 0x0002
-#define TPM_SS_RSASSAPKCS1v15_DER 0x0003
-
-/*
- * TPM_CAPABILITY_AREA Values for TPM_GetCapability ([TPM_Part2], Section 21.1)
- */
-#define TPM_CAP_ORD                     0x00000001
-#define TPM_CAP_ALG                     0x00000002
-#define TPM_CAP_PID                     0x00000003
-#define TPM_CAP_FLAG                    0x00000004
-#define TPM_CAP_PROPERTY                0x00000005
-#define TPM_CAP_VERSION                 0x00000006
-#define TPM_CAP_KEY_HANDLE              0x00000007
-#define TPM_CAP_CHECK_LOADED            0x00000008
-#define TPM_CAP_SYM_MODE                0x00000009
-#define TPM_CAP_KEY_STATUS              0x0000000C
-#define TPM_CAP_NV_LIST                 0x0000000D
-#define TPM_CAP_MFR                     0x00000010
-#define TPM_CAP_NV_INDEX                0x00000011
-#define TPM_CAP_TRANS_ALG               0x00000012
-#define TPM_CAP_HANDLE                  0x00000014
-#define TPM_CAP_TRANS_ES                0x00000015
-#define TPM_CAP_AUTH_ENCRYPT            0x00000017
-#define TPM_CAP_SELECT_SIZE             0x00000018
-#define TPM_CAP_DA_LOGIC                0x00000019
-#define TPM_CAP_VERSION_VAL             0x0000001A
-
-/* subCap definitions ([TPM_Part2], Section 21.2) */
-#define TPM_CAP_PROP_PCR                0x00000101
-#define TPM_CAP_PROP_DIR                0x00000102
-#define TPM_CAP_PROP_MANUFACTURER       0x00000103
-#define TPM_CAP_PROP_KEYS               0x00000104
-#define TPM_CAP_PROP_MIN_COUNTER        0x00000107
-#define TPM_CAP_FLAG_PERMANENT          0x00000108
-#define TPM_CAP_FLAG_VOLATILE           0x00000109
-#define TPM_CAP_PROP_AUTHSESS           0x0000010A
-#define TPM_CAP_PROP_TRANSESS           0x0000010B
-#define TPM_CAP_PROP_COUNTERS           0x0000010C
-#define TPM_CAP_PROP_MAX_AUTHSESS       0x0000010D
-#define TPM_CAP_PROP_MAX_TRANSESS       0x0000010E
-#define TPM_CAP_PROP_MAX_COUNTERS       0x0000010F
-#define TPM_CAP_PROP_MAX_KEYS           0x00000110
-#define TPM_CAP_PROP_OWNER              0x00000111
-#define TPM_CAP_PROP_CONTEXT            0x00000112
-#define TPM_CAP_PROP_MAX_CONTEXT        0x00000113
-#define TPM_CAP_PROP_FAMILYROWS         0x00000114
-#define TPM_CAP_PROP_TIS_TIMEOUT        0x00000115
-#define TPM_CAP_PROP_STARTUP_EFFECT     0x00000116
-#define TPM_CAP_PROP_DELEGATE_ROW       0x00000117
-#define TPM_CAP_PROP_MAX_DAASESS        0x00000119
-#define TPM_CAP_PROP_DAASESS            0x0000011A
-#define TPM_CAP_PROP_CONTEXT_DIST       0x0000011B
-#define TPM_CAP_PROP_DAA_INTERRUPT      0x0000011C
-#define TPM_CAP_PROP_SESSIONS           0x0000011D
-#define TPM_CAP_PROP_MAX_SESSIONS       0x0000011E
-#define TPM_CAP_PROP_CMK_RESTRICTION    0x0000011F
-#define TPM_CAP_PROP_DURATION           0x00000120
-#define TPM_CAP_PROP_ACTIVE_COUNTER     0x00000122
-#define TPM_CAP_PROP_MAX_NV_AVAILABLE   0x00000123
-#define TPM_CAP_PROP_INPUT_BUFFER       0x00000124
-
-// TPM_KEY_USAGE values
-#define TPM_KEY_EK 0x0000
-#define TPM_KEY_SIGNING 0x0010
-#define TPM_KEY_STORAGE 0x0011
-#define TPM_KEY_IDENTITY 0x0012
-#define TPM_KEY_AUTHCHANGE 0X0013
-#define TPM_KEY_BIND 0x0014
-#define TPM_KEY_LEGACY 0x0015
-
-// TPM_AUTH_DATA_USAGE values
-#define TPM_AUTH_NEVER 0x00
-#define TPM_AUTH_ALWAYS 0x01
-
-// Key Handle of owner and srk
-#define TPM_OWNER_KEYHANDLE 0x40000001
-#define TPM_SRK_KEYHANDLE 0x40000000
-
-
-
-// *************************** TYPEDEFS *********************************
-typedef UINT32 TPM_RESULT;
-typedef UINT32 TPM_PCRINDEX;
-typedef UINT32 TPM_DIRINDEX;
-typedef UINT32 TPM_HANDLE;
-typedef TPM_HANDLE TPM_AUTHHANDLE;
-typedef TPM_HANDLE TCPA_HASHHANDLE;
-typedef TPM_HANDLE TCPA_HMACHANDLE;
-typedef TPM_HANDLE TCPA_ENCHANDLE;
-typedef TPM_HANDLE TPM_KEY_HANDLE;
-typedef TPM_HANDLE TCPA_ENTITYHANDLE;
-typedef UINT32 TPM_RESOURCE_TYPE;
-typedef UINT32 TPM_COMMAND_CODE;
-typedef UINT16 TPM_PROTOCOL_ID;
-typedef BYTE TPM_AUTH_DATA_USAGE;
-typedef UINT16 TPM_ENTITY_TYPE;
-typedef UINT32 TPM_ALGORITHM_ID;
-typedef UINT16 TPM_KEY_USAGE;
-typedef UINT16 TPM_STARTUP_TYPE;
-typedef UINT32 TPM_CAPABILITY_AREA;
-typedef UINT16 TPM_ENC_SCHEME;
-typedef UINT16 TPM_SIG_SCHEME;
-typedef UINT16 TPM_MIGRATE_SCHEME;
-typedef UINT16 TPM_PHYSICAL_PRESENCE;
-typedef UINT32 TPM_KEY_FLAGS;
-
-#define TPM_DIGEST_SIZE 20  // Don't change this
-typedef BYTE TPM_AUTHDATA[TPM_DIGEST_SIZE];
-typedef TPM_AUTHDATA TPM_SECRET;
-typedef TPM_AUTHDATA TPM_ENCAUTH;
-typedef BYTE TPM_PAYLOAD_TYPE;
-typedef UINT16 TPM_TAG;
-typedef UINT16 TPM_STRUCTURE_TAG;
-
-// Data Types of the TCS
-typedef UINT32 TCS_AUTHHANDLE;  // Handle addressing a authorization session
-typedef UINT32 TCS_CONTEXT_HANDLE; // Basic context handle
-typedef UINT32 TCS_KEY_HANDLE;  // Basic key handle
-
-// ************************* STRUCTURES **********************************
-
-typedef struct TPM_VERSION {
-  BYTE major;
-  BYTE minor;
-  BYTE revMajor;
-  BYTE revMinor;
-} TPM_VERSION;
-
-static const TPM_VERSION TPM_STRUCT_VER_1_1 = { 1,1,0,0 };
-
-typedef struct TPM_CAP_VERSION_INFO {
-   TPM_STRUCTURE_TAG tag;
-   TPM_VERSION version;
-   UINT16 specLevel;
-   BYTE errataRev;
-   BYTE tpmVendorID[4];
-   UINT16 vendorSpecificSize;
-   BYTE* vendorSpecific;
-} TPM_CAP_VERSION_INFO;
-
-inline void free_TPM_CAP_VERSION_INFO(TPM_CAP_VERSION_INFO* v) {
-   free(v->vendorSpecific);
-   v->vendorSpecific = NULL;
-}
-
-typedef struct TPM_DIGEST {
-  BYTE digest[TPM_DIGEST_SIZE];
-} TPM_DIGEST;
-
-typedef TPM_DIGEST TPM_PCRVALUE;
-typedef TPM_DIGEST TPM_COMPOSITE_HASH;
-typedef TPM_DIGEST TPM_DIRVALUE;
-typedef TPM_DIGEST TPM_HMAC;
-typedef TPM_DIGEST TPM_CHOSENID_HASH;
-
-typedef struct TPM_NONCE {
-  BYTE nonce[TPM_DIGEST_SIZE];
-} TPM_NONCE;
-
-typedef struct TPM_SYMMETRIC_KEY_PARMS {
-   UINT32 keyLength;
-   UINT32 blockSize;
-   UINT32 ivSize;
-   BYTE* IV;
-} TPM_SYMMETRIC_KEY_PARMS;
-
-typedef struct TPM_SYMMETRIC_KEY {
-   UINT32 algId;
-   UINT16 encScheme;
-   UINT16 size;
-   BYTE* data;
-} TPM_SYMMETRIC_KEY;
-
-inline void free_TPM_SYMMETRIC_KEY_PARMS(TPM_SYMMETRIC_KEY_PARMS* p) {
-   free(p->IV);
-   p->IV = NULL;
-}
-
-#define TPM_SYMMETRIC_KEY_PARMS_INIT { 0, 0, 0, NULL }
-
-typedef struct TPM_RSA_KEY_PARMS {
-  UINT32 keyLength;
-  UINT32 numPrimes;
-  UINT32 exponentSize;
-  BYTE* exponent;
-} TPM_RSA_KEY_PARMS;
-
-#define TPM_RSA_KEY_PARMS_INIT { 0, 0, 0, NULL }
-
-inline void free_TPM_RSA_KEY_PARMS(TPM_RSA_KEY_PARMS* p) {
-   free(p->exponent);
-   p->exponent = NULL;
-}
-
-typedef struct TPM_KEY_PARMS {
-  TPM_ALGORITHM_ID algorithmID;
-  TPM_ENC_SCHEME encScheme;
-  TPM_SIG_SCHEME sigScheme;
-  UINT32 parmSize;
-  union {
-     TPM_SYMMETRIC_KEY_PARMS sym;
-     TPM_RSA_KEY_PARMS rsa;
-  } parms;
-} TPM_KEY_PARMS;
-
-#define TPM_KEY_PARMS_INIT { 0, 0, 0, 0 }
-
-inline void free_TPM_KEY_PARMS(TPM_KEY_PARMS* p) {
-   if(p->parmSize) {
-      switch(p->algorithmID) {
-         case TPM_ALG_RSA:
-            free_TPM_RSA_KEY_PARMS(&p->parms.rsa);
-            break;
-         case TPM_ALG_AES128:
-         case TPM_ALG_AES192:
-         case TPM_ALG_AES256:
-            free_TPM_SYMMETRIC_KEY_PARMS(&p->parms.sym);
-            break;
-      }
-   }
-}
-
-typedef struct TPM_STORE_PUBKEY {
-  UINT32 keyLength;
-  BYTE* key;
-} TPM_STORE_PUBKEY;
-
-#define TPM_STORE_PUBKEY_INIT { 0, NULL }
-
-inline void free_TPM_STORE_PUBKEY(TPM_STORE_PUBKEY* p) {
-   free(p->key);
-   p->key = NULL;
-}
-
-typedef struct TPM_PUBKEY {
-  TPM_KEY_PARMS algorithmParms;
-  TPM_STORE_PUBKEY pubKey;
-} TPM_PUBKEY;
-
-#define TPM_PUBKEY_INIT { TPM_KEY_PARMS_INIT, TPM_STORE_PUBKEY_INIT }
-
-inline void free_TPM_PUBKEY(TPM_PUBKEY* k) {
-   free_TPM_KEY_PARMS(&k->algorithmParms);
-   free_TPM_STORE_PUBKEY(&k->pubKey);
-}
-
-typedef struct TPM_PCR_SELECTION {
-   UINT16 sizeOfSelect;
-   BYTE* pcrSelect;
-} TPM_PCR_SELECTION;
-
-#define TPM_PCR_SELECTION_INIT { 0, NULL }
-
-inline void free_TPM_PCR_SELECTION(TPM_PCR_SELECTION* p) {
-   free(p->pcrSelect);
-   p->pcrSelect = NULL;
-}
-
-#define TPM_LOCALITY_SELECTION BYTE
-
-typedef struct TPM_PCR_INFO_LONG {
-   TPM_STRUCTURE_TAG tag;
-   TPM_LOCALITY_SELECTION localityAtCreation;
-   TPM_LOCALITY_SELECTION localityAtRelease;
-   TPM_PCR_SELECTION creationPCRSelection;
-   TPM_PCR_SELECTION releasePCRSelection;
-   TPM_COMPOSITE_HASH digestAtCreation;
-   TPM_COMPOSITE_HASH digestAtRelease;
-} TPM_PCR_INFO_LONG;
-
-#define TPM_PCR_INFO_LONG_INIT { 0, 0, 0, TPM_PCR_SELECTION_INIT, \
-                                 TPM_PCR_SELECTION_INIT }
-
-inline void free_TPM_PCR_INFO_LONG(TPM_PCR_INFO_LONG* p) {
-   free_TPM_PCR_SELECTION(&p->creationPCRSelection);
-   free_TPM_PCR_SELECTION(&p->releasePCRSelection);
-}
-
-typedef struct TPM_PCR_INFO {
-   TPM_PCR_SELECTION pcrSelection;
-   TPM_COMPOSITE_HASH digestAtRelease;
-   TPM_COMPOSITE_HASH digestAtCreation;
-} TPM_PCR_INFO;
-
-#define TPM_PCR_INFO_INIT { TPM_PCR_SELECTION_INIT }
-
-inline void free_TPM_PCR_INFO(TPM_PCR_INFO* p) {
-   free_TPM_PCR_SELECTION(&p->pcrSelection);
-}
-
-typedef struct TPM_PCR_COMPOSITE {
-  TPM_PCR_SELECTION select;
-  UINT32 valueSize;
-  TPM_PCRVALUE* pcrValue;
-} TPM_PCR_COMPOSITE;
-
-#define TPM_PCR_COMPOSITE_INIT { TPM_PCR_SELECTION_INIT, 0, NULL }
-
-inline void free_TPM_PCR_COMPOSITE(TPM_PCR_COMPOSITE* p) {
-   free_TPM_PCR_SELECTION(&p->select);
-   free(p->pcrValue);
-   p->pcrValue = NULL;
-}
-
-typedef struct TPM_KEY {
-  TPM_VERSION         ver;
-  TPM_KEY_USAGE       keyUsage;
-  TPM_KEY_FLAGS       keyFlags;
-  TPM_AUTH_DATA_USAGE authDataUsage;
-  TPM_KEY_PARMS       algorithmParms;
-  UINT32              PCRInfoSize;
-  TPM_PCR_INFO        PCRInfo;
-  TPM_STORE_PUBKEY    pubKey;
-  UINT32              encDataSize;
-  BYTE*               encData;
-} TPM_KEY;
-
-#define TPM_KEY_INIT { .algorithmParms = TPM_KEY_PARMS_INIT,\
-   .PCRInfoSize = 0, .PCRInfo = TPM_PCR_INFO_INIT, \
-   .pubKey = TPM_STORE_PUBKEY_INIT, \
-   .encDataSize = 0, .encData = NULL }
-
-inline void free_TPM_KEY(TPM_KEY* k) {
-   if(k->PCRInfoSize) {
-      free_TPM_PCR_INFO(&k->PCRInfo);
-   }
-   free_TPM_STORE_PUBKEY(&k->pubKey);
-   free(k->encData);
-   k->encData = NULL;
-}
-
-typedef struct TPM_BOUND_DATA {
-  TPM_VERSION ver;
-  TPM_PAYLOAD_TYPE payload;
-  BYTE* payloadData;
-} TPM_BOUND_DATA;
-
-#define TPM_BOUND_DATA_INIT { .payloadData = NULL }
-
-inline void free_TPM_BOUND_DATA(TPM_BOUND_DATA* d) {
-   free(d->payloadData);
-   d->payloadData = NULL;
-}
-
-typedef struct TPM_STORED_DATA {
-  TPM_VERSION ver;
-  UINT32 sealInfoSize;
-  TPM_PCR_INFO sealInfo;
-  UINT32 encDataSize;
-  BYTE* encData;
-} TPM_STORED_DATA;
-
-#define TPM_STORED_DATA_INIT { .sealInfoSize = 0, sealInfo = TPM_PCR_INFO_INIT,\
-   .encDataSize = 0, .encData = NULL }
-
-inline void free_TPM_STORED_DATA(TPM_STORED_DATA* d) {
-   if(d->sealInfoSize) {
-      free_TPM_PCR_INFO(&d->sealInfo);
-   }
-   free(d->encData);
-   d->encData = NULL;
-}
-
-typedef struct TPM_STORED_DATA12 {
-  TPM_STRUCTURE_TAG tag;
-  TPM_ENTITY_TYPE et;
-  UINT32 sealInfoLongSize;
-  TPM_PCR_INFO_LONG sealInfoLong;
-  UINT32 encDataSize;
-  BYTE* encData;
-} TPM_STORED_DATA12;
-
-#define TPM_STORED_DATA12_INIT { .sealInfoLongSize = 0, \
-   sealInfoLong = TPM_PCR_INFO_INIT, .encDataSize = 0, .encData = NULL }
-
-inline void free_TPM_STORED_DATA12(TPM_STORED_DATA12* d) {
-   if(d->sealInfoLongSize) {
-      free_TPM_PCR_INFO_LONG(&d->sealInfoLong);
-   }
-   free(d->encData);
-   d->encData = NULL;
-}
-
-typedef struct TPM_AUTH_SESSION {
-  TPM_AUTHHANDLE  AuthHandle;
-  TPM_NONCE   NonceOdd;   // system
-  TPM_NONCE   NonceEven;   // TPM
-  BOOL   fContinueAuthSession;
-  TPM_AUTHDATA  HMAC;
-} TPM_AUTH_SESSION;
-
-#define TPM_AUTH_SESSION_INIT { .AuthHandle = 0, .fContinueAuthSession = FALSE }
-
-// ---------------------- Functions for checking TPM_RESULTs -----------------
-
-#include <stdio.h>
-
-// FIXME: Review use of these and delete unneeded ones.
-
-// these are really badly dependent on local structure:
-// DEPENDS: local var 'status' of type TPM_RESULT
-// DEPENDS: label 'abort_egress' which cleans up and returns the status
-#define ERRORDIE(s) do { status = s; \
-                         fprintf (stderr, "*** ERRORDIE in %s at %s: %i\n", __func__, __FILE__, __LINE__); \
-                         goto abort_egress; } \
-                    while (0)
-
-// DEPENDS: local var 'status' of type TPM_RESULT
-// DEPENDS: label 'abort_egress' which cleans up and returns the status
-// Try command c. If it fails, set status to s and goto abort.
-#define TPMTRY(s,c) if (c != TPM_SUCCESS) { \
-                       status = s; \
-                       printf("ERROR in %s at %s:%i code: %s.\n", __func__, __FILE__, __LINE__, tpm_get_error_name(status)); \
-                       goto abort_egress; \
-                    } else {\
-                       status = c; \
-                    }
-
-// Try command c. If it fails, print error message, set status to actual return code. Goto abort
-#define TPMTRYRETURN(c) do { status = c; \
-                             if (status != TPM_SUCCESS) { \
-                               fprintf(stderr, "ERROR in %s at %s:%i code: %s.\n", __func__, __FILE__, __LINE__, tpm_get_error_name(status)); \
-                               goto abort_egress; \
-                             } \
-                        } while(0)
-
-
-#endif //__TCPA_H__
diff --git a/stubdom/vtpmmgr/tpm.c b/stubdom/vtpmmgr/tpm.c
deleted file mode 100644 (file)
index 779cddd..0000000
+++ /dev/null
@@ -1,904 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <malloc.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <polarssl/sha1.h>
-
-#include "tcg.h"
-#include "tpm.h"
-#include "log.h"
-#include "marshal.h"
-#include "tpmrsa.h"
-#include "vtpmmgr.h"
-
-#define TCPA_MAX_BUFFER_LENGTH 0x2000
-
-#define TPM_BEGIN_CMD(ord) \
-       const TPM_COMMAND_CODE ordinal = ord; \
-       TPM_RESULT status = TPM_SUCCESS; \
-       BYTE _io_buffer[TCPA_MAX_BUFFER_LENGTH]; \
-       UINT32 _io_bufsize_in; \
-       UINT32 _io_bufsize_out; \
-       vtpmloginfo(VTPM_LOG_TPM, "%s\n", __func__); \
-       do { \
-               BYTE *in_buf = _io_buffer; \
-               UINT32 in_pos = 6; \
-               PACK_IN(UINT32, ordinal);
-
-#define IN_PTR (in_buf + in_pos)
-
-#define PACK_IN(type, item...) do { \
-       UINT32 isize = sizeof_ ## type(item); \
-       if (isize + in_pos > TCPA_MAX_BUFFER_LENGTH) { \
-               status = TPM_SIZE; \
-               goto abort_egress; \
-       } \
-       pack_ ## type (IN_PTR, item); \
-       in_pos += isize; \
-} while (0)
-
-#define TPM_HASH_IN_BEGIN \
-       sha1_context sha1_ctx; \
-       sha1_starts(&sha1_ctx); \
-       sha1_update(&sha1_ctx, in_buf + 6, 4); \
-       TPM_HASH_IN_START
-
-#define TPM_HASH_IN_START \
-       do { \
-               UINT32 _hash_in_start = in_pos;
-
-#define TPM_HASH_IN_STOP \
-               sha1_update(&sha1_ctx, in_buf + _hash_in_start, in_pos - _hash_in_start); \
-       } while (0)
-
-#define TPM_TAG_COMMON(req_tag) \
-               _io_bufsize_in = in_pos; \
-               pack_TPM_TAG(in_buf, req_tag); \
-               pack_UINT32(in_buf + sizeof(TPM_TAG), in_pos); \
-       } while (0); \
-       _io_bufsize_out = TCPA_MAX_BUFFER_LENGTH; \
-       status = TPM_TransmitData(_io_buffer, _io_bufsize_in, _io_buffer, &_io_bufsize_out); \
-       if (status != TPM_SUCCESS) { \
-               goto abort_egress; \
-       } \
-       do { \
-               BYTE *out_buf = _io_buffer; \
-               UINT32 out_pos = 0; \
-               UINT32 out_len = _io_bufsize_out; \
-               do { \
-                       TPM_TAG rsp_tag; \
-                       UINT32 rsp_len; \
-                       UINT32 rsp_status; \
-                       UNPACK_OUT(TPM_RSP_HEADER, &rsp_tag, &rsp_len, &rsp_status); \
-                       if (rsp_status != TPM_SUCCESS) { \
-                               vtpmlogerror(VTPM_LOG_TPM, "Failed with return code %s\n", tpm_get_error_name(rsp_status)); \
-                               status = rsp_status; \
-                               goto abort_egress; \
-                       } \
-                       if (rsp_tag != req_tag + 3 || rsp_len != out_len) { \
-                               status = TPM_FAIL; \
-                               goto abort_egress; \
-                       } \
-               } while(0)
-
-#define OUT_PTR (out_buf + out_pos)
-
-#define UNPACK_OUT(type, item...) do { \
-       if (unpack3_ ## type (out_buf, &out_pos, TCPA_MAX_BUFFER_LENGTH, item)) { \
-               status = TPM_SIZE; \
-               goto abort_egress; \
-       } \
-} while (0)
-
-#define TPM_XMIT_REQ() \
-       TPM_TAG_COMMON(TPM_TAG_RQU_COMMAND)
-
-#define TPM_XMIT_AUTH1(sec1, auth1) \
-       TPM_HASH_IN_STOP; \
-       do { \
-               TPM_DIGEST paramDigest; \
-               sha1_finish(&sha1_ctx, paramDigest.digest); \
-               generateAuth(&paramDigest, sec1, auth1); \
-               PACK_IN(TPM_AUTH_SESSION, auth1); \
-       } while (0); \
-       TPM_TAG_COMMON(TPM_TAG_RQU_AUTH1_COMMAND); \
-       TPM_HASH_OUT_BEGIN
-
-#define TPM_XMIT_AUTH2(sec1, auth1, sec2, auth2) \
-       TPM_HASH_IN_STOP; \
-       do { \
-               TPM_DIGEST paramDigest; \
-               sha1_finish(&sha1_ctx, paramDigest.digest); \
-               generateAuth(&paramDigest, sec1, auth1); \
-               PACK_IN(TPM_AUTH_SESSION, auth1); \
-               generateAuth(&paramDigest, sec2, auth2); \
-               PACK_IN(TPM_AUTH_SESSION, auth2); \
-       } while (0); \
-       TPM_TAG_COMMON(TPM_TAG_RQU_AUTH2_COMMAND); \
-       TPM_HASH_OUT_BEGIN
-
-#define TPM_HASH_OUT_BEGIN \
-       sha1_context sha1_ctx; \
-       sha1_starts(&sha1_ctx); \
-       do { \
-               UINT32 buf[2] = { cpu_to_be32(status), cpu_to_be32(ordinal) }; \
-               sha1_update(&sha1_ctx, (BYTE*)buf, sizeof(buf)); \
-       } while(0); \
-       TPM_HASH_OUT_START
-
-#define TPM_HASH_OUT_START \
-       do { \
-               UINT32 _hash_out_start = out_pos;
-
-#define TPM_HASH_OUT_STOP \
-               sha1_update(&sha1_ctx, out_buf + _hash_out_start, out_pos - _hash_out_start); \
-       } while (0)
-
-#define TPM_END_AUTH1(sec1, auth1) \
-       TPM_HASH_OUT_STOP; \
-       do { \
-               TPM_DIGEST paramDigest; \
-               sha1_finish(&sha1_ctx, paramDigest.digest); \
-               UNPACK_OUT(TPM_AUTH_SESSION, auth1); \
-               status = verifyAuth(&paramDigest, sec1, auth1); \
-               if (status != TPM_SUCCESS) \
-                       goto abort_egress; \
-       } while(0); \
-       TPM_END_COMMON
-
-#define TPM_END_AUTH2(sec1, auth1, sec2, auth2) \
-       TPM_HASH_OUT_STOP; \
-       do { \
-               TPM_DIGEST paramDigest; \
-               sha1_finish(&sha1_ctx, paramDigest.digest); \
-               UNPACK_OUT(TPM_AUTH_SESSION, auth1); \
-               status = verifyAuth(&paramDigest, sec1, auth1); \
-               if (status != TPM_SUCCESS) \
-                       goto abort_egress; \
-               UNPACK_OUT(TPM_AUTH_SESSION, auth2); \
-               status = verifyAuth(&paramDigest, sec2, auth2); \
-               if (status != TPM_SUCCESS) \
-                       goto abort_egress; \
-       } while(0); \
-       TPM_END_COMMON
-
-#define TPM_END() TPM_END_COMMON
-
-#define TPM_END_COMMON \
-               if (out_pos != out_len) { \
-                       vtpmloginfo(VTPM_LOG_TPM, "Response too long (%d != %d)", out_pos, out_len);\
-                       status = TPM_SIZE; \
-                       goto abort_egress; \
-               } \
-       } while (0); \
-
-#define TPM_AUTH_ERR_CHECK(auth) do {\
-       if(status != TPM_SUCCESS || auth->fContinueAuthSession == FALSE) {\
-               vtpmloginfo(VTPM_LOG_TPM, "Auth Session: 0x%x closed by TPM\n", auth->AuthHandle);\
-               auth->AuthHandle = 0;\
-       }\
-} while(0)
-
-static void xorEncrypt(const TPM_SECRET* sharedSecret,
-               TPM_NONCE* nonce,
-               const TPM_AUTHDATA* inAuth0,
-               TPM_ENCAUTH outAuth0,
-               const TPM_AUTHDATA* inAuth1,
-               TPM_ENCAUTH outAuth1) {
-       BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
-       BYTE XORkey[TPM_DIGEST_SIZE];
-       BYTE* ptr = XORbuffer;
-       ptr = pack_TPM_SECRET(ptr, sharedSecret);
-       ptr = pack_TPM_NONCE(ptr, nonce);
-
-       sha1(XORbuffer, ptr - XORbuffer, XORkey);
-
-       if(inAuth0) {
-               for(int i = 0; i < TPM_DIGEST_SIZE; ++i) {
-                       outAuth0[i] = XORkey[i] ^ (*inAuth0)[i];
-               }
-       }
-       if(inAuth1) {
-               for(int i = 0; i < TPM_DIGEST_SIZE; ++i) {
-                       outAuth1[i] = XORkey[i] ^ (*inAuth1)[i];
-               }
-       }
-
-}
-
-static void generateAuth(const TPM_DIGEST* paramDigest,
-               const TPM_SECRET* HMACkey,
-               TPM_AUTH_SESSION *auth)
-{
-       //Generate new OddNonce
-       vtpmmgr_rand((BYTE*)auth->NonceOdd.nonce, sizeof(TPM_NONCE));
-
-       // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
-       BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
-       BYTE* ptr = hmacText;
-
-       ptr = pack_TPM_DIGEST(ptr, paramDigest);
-       ptr = pack_TPM_NONCE(ptr, &auth->NonceEven);
-       ptr = pack_TPM_NONCE(ptr, &auth->NonceOdd);
-       ptr = pack_BOOL(ptr, auth->fContinueAuthSession);
-
-       sha1_hmac((BYTE *) HMACkey, sizeof(TPM_DIGEST),
-                       (BYTE *) hmacText, sizeof(hmacText),
-                       auth->HMAC);
-}
-
-static TPM_RESULT verifyAuth(const TPM_DIGEST* paramDigest,
-               /*[IN]*/ const TPM_SECRET *HMACkey,
-               /*[IN,OUT]*/ TPM_AUTH_SESSION *auth)
-{
-
-       // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
-       TPM_AUTHDATA hm;
-       BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
-       BYTE* ptr = hmacText;
-
-       ptr = pack_TPM_DIGEST(ptr, paramDigest);
-       ptr = pack_TPM_NONCE(ptr, &auth->NonceEven);
-       ptr = pack_TPM_NONCE(ptr, &auth->NonceOdd);
-       ptr = pack_BOOL(ptr, auth->fContinueAuthSession);
-
-       sha1_hmac( (BYTE *) HMACkey, sizeof(TPM_DIGEST),
-                       (BYTE *) hmacText, sizeof(hmacText),
-                       hm);
-
-       // Compare correct HMAC with provided one.
-       if (memcmp(hm, auth->HMAC, sizeof(TPM_DIGEST)) == 0) { // 0 indicates equality
-               return TPM_SUCCESS;
-       } else {
-               vtpmlogerror(VTPM_LOG_TPM, "Auth Session verification failed! %x %x\n",
-                       *(UINT32*)auth->HMAC, *(UINT32*)hm);
-               return TPM_AUTHFAIL;
-       }
-}
-
-
-
-// ------------------------------------------------------------------
-// Authorization Commands
-// ------------------------------------------------------------------
-
-TPM_RESULT TPM_OIAP(TPM_AUTH_SESSION*  auth)  // out
-{
-       TPM_BEGIN_CMD(TPM_ORD_OIAP);
-
-       TPM_XMIT_REQ();
-
-       memset(&auth->HMAC, 0, sizeof(TPM_DIGEST));
-       auth->fContinueAuthSession = TRUE;
-
-       UNPACK_OUT(UINT32, &auth->AuthHandle);
-       UNPACK_OUT(TPM_NONCE, &auth->NonceEven);
-       TPM_END();
-
-       vtpmloginfo(VTPM_LOG_TPM, "Auth Session: 0x%x opened by TPM_OIAP.\n", auth->AuthHandle);
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_OSAP(TPM_ENTITY_TYPE  entityType,  // in
-               UINT32   entityValue, // in
-               const TPM_AUTHDATA* usageAuth, //in
-               TPM_SECRET *sharedSecret, //out
-               TPM_AUTH_SESSION *auth)
-{
-       TPM_DIGEST nonceOddOSAP;
-       vtpmmgr_rand(nonceOddOSAP.digest, TPM_DIGEST_SIZE);
-       TPM_BEGIN_CMD(TPM_ORD_OSAP);
-
-       PACK_IN(TPM_ENTITY_TYPE, entityType);
-       PACK_IN(UINT32, entityValue);
-       PACK_IN(TPM_DIGEST, &nonceOddOSAP);
-
-       TPM_XMIT_REQ();
-
-       UNPACK_OUT(UINT32, &auth->AuthHandle);
-       UNPACK_OUT(TPM_NONCE, &auth->NonceEven);
-
-       //Calculate session secret
-       sha1_context ctx;
-       sha1_hmac_starts(&ctx, *usageAuth, TPM_DIGEST_SIZE);
-       sha1_hmac_update(&ctx, OUT_PTR, TPM_DIGEST_SIZE); // nonceEvenOSAP
-       sha1_hmac_update(&ctx, nonceOddOSAP.digest, TPM_DIGEST_SIZE);
-       sha1_hmac_finish(&ctx, *sharedSecret);
-
-       out_pos += TPM_DIGEST_SIZE;
-       TPM_END();
-
-       memset(&auth->HMAC, 0, sizeof(TPM_DIGEST));
-       auth->fContinueAuthSession = FALSE;
-
-       vtpmloginfo(VTPM_LOG_TPM, "Auth Session: 0x%x opened by TPM_OSAP.\n", auth->AuthHandle);
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_TakeOwnership(
-               const TPM_PUBKEY *pubEK, //in
-               const TPM_AUTHDATA* ownerAuth, //in
-               const TPM_AUTHDATA* srkAuth, //in
-               const TPM_KEY* inSrk, //in
-               TPM_KEY* outSrk, //out, optional
-               TPM_AUTH_SESSION*       auth)   // in, out
-{
-       int keyAlloced = 0;
-       tpmrsa_context ek_rsa = TPMRSA_CTX_INIT;
-
-       TPM_BEGIN_CMD(TPM_ORD_TakeOwnership);
-       TPM_HASH_IN_BEGIN;
-
-       tpmrsa_set_pubkey(&ek_rsa,
-                       pubEK->pubKey.key, pubEK->pubKey.keyLength,
-                       pubEK->algorithmParms.parms.rsa.exponent,
-                       pubEK->algorithmParms.parms.rsa.exponentSize);
-
-       /* Pack the protocol ID */
-       PACK_IN(UINT16, TPM_PID_OWNER);
-
-       /* Pack the encrypted owner auth */
-       PACK_IN(UINT32, pubEK->algorithmParms.parms.rsa.keyLength / 8);
-       tpmrsa_pub_encrypt_oaep(&ek_rsa,
-                       ctr_drbg_random, &vtpm_globals.ctr_drbg,
-                       sizeof(TPM_SECRET),
-                       (BYTE*) ownerAuth,
-                       IN_PTR);
-       in_pos += pubEK->algorithmParms.parms.rsa.keyLength / 8;
-
-       /* Pack the encrypted srk auth */
-       PACK_IN(UINT32, pubEK->algorithmParms.parms.rsa.keyLength / 8);
-       tpmrsa_pub_encrypt_oaep(&ek_rsa,
-                       ctr_drbg_random, &vtpm_globals.ctr_drbg,
-                       sizeof(TPM_SECRET),
-                       (BYTE*) srkAuth,
-                       IN_PTR);
-       in_pos += pubEK->algorithmParms.parms.rsa.keyLength / 8;
-
-       PACK_IN(TPM_KEY, inSrk);
-
-       TPM_XMIT_AUTH1(ownerAuth, auth);
-
-       if (outSrk != NULL) {
-               /* If the user wants a copy of the srk we give it to them */
-               keyAlloced = 1;
-               UNPACK_OUT(TPM_KEY, outSrk, UNPACK_ALLOC);
-       } else {
-               /*otherwise just parse past it */
-               TPM_KEY temp;
-               UNPACK_OUT(TPM_KEY, &temp, UNPACK_ALIAS);
-       }
-
-       TPM_END_AUTH1(ownerAuth, auth);
-
-       goto egress;
-abort_egress:
-       if(keyAlloced) {
-               free_TPM_KEY(outSrk);
-       }
-egress:
-       tpmrsa_free(&ek_rsa);
-       TPM_AUTH_ERR_CHECK(auth);
-       return status;
-}
-
-
-TPM_RESULT TPM_DisablePubekRead (
-               const TPM_AUTHDATA* ownerAuth,
-               TPM_AUTH_SESSION*       auth)
-{
-       TPM_BEGIN_CMD(TPM_ORD_DisablePubekRead);
-       TPM_HASH_IN_BEGIN;
-
-       TPM_XMIT_AUTH1(ownerAuth, auth);
-
-       TPM_END_AUTH1(ownerAuth, auth);
-
-abort_egress:
-       TPM_AUTH_ERR_CHECK(auth);
-       return status;
-}
-
-
-TPM_RESULT TPM_TerminateHandle(TPM_AUTHHANDLE  handle)  // in
-{
-       if(handle == 0) {
-               return TPM_SUCCESS;
-       }
-
-       TPM_BEGIN_CMD(TPM_ORD_Terminate_Handle);
-
-       PACK_IN(TPM_AUTHHANDLE, handle);
-
-       TPM_XMIT_REQ();
-       TPM_END();
-
-       vtpmloginfo(VTPM_LOG_TPM, "Auth Session: 0x%x closed by TPM_TerminateHandle\n", handle);
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_Extend( TPM_PCRINDEX  pcrNum,  // in
-               TPM_DIGEST* inDigest, // in
-               TPM_PCRVALUE*  outDigest) // out
-{
-       TPM_BEGIN_CMD(TPM_ORD_Extend);
-
-       PACK_IN(TPM_PCRINDEX, pcrNum);
-       PACK_IN(TPM_DIGEST, inDigest);
-
-       TPM_XMIT_REQ();
-
-       UNPACK_OUT(TPM_PCRVALUE, outDigest);
-
-       TPM_END();
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_Reset(TPM_PCR_SELECTION *sel)
-{
-       TPM_BEGIN_CMD(TPM_ORD_PCR_Reset);
-       PACK_IN(TPM_PCR_SELECTION, sel);
-       TPM_XMIT_REQ();
-       TPM_END();
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_Seal(
-               TPM_KEY_HANDLE  keyHandle,  // in
-               UINT32   pcrInfoLongSize, // in
-               TPM_PCR_INFO_LONG*       pcrInfoLong,  // in
-               UINT32   inDataSize,  // in
-               const BYTE*      inData,        // in
-               TPM_STORED_DATA12* sealedData, //out
-               const TPM_SECRET* osapSharedSecret, //in
-               const TPM_AUTHDATA* sealedDataAuth, //in
-               TPM_AUTH_SESSION*       pubAuth  // in, out
-               )
-{
-       memset(sealedData, 0, sizeof(*sealedData));
-       TPM_BEGIN_CMD(TPM_ORD_Seal);
-       PACK_IN(TPM_KEY_HANDLE, keyHandle);
-       TPM_HASH_IN_BEGIN;
-
-       xorEncrypt(osapSharedSecret, &pubAuth->NonceEven, sealedDataAuth, IN_PTR, NULL, NULL);
-       in_pos += sizeof(TPM_ENCAUTH);
-
-       PACK_IN(UINT32, pcrInfoLongSize);
-       if (pcrInfoLongSize) {
-               PACK_IN(TPM_PCR_INFO_LONG, pcrInfoLong);
-       }
-       PACK_IN(UINT32, inDataSize);
-       PACK_IN(BUFFER, inData, inDataSize);
-
-       TPM_XMIT_AUTH1(osapSharedSecret, pubAuth);
-
-       UNPACK_OUT(TPM_STORED_DATA12, sealedData, UNPACK_ALLOC);
-
-       TPM_END_AUTH1(osapSharedSecret, pubAuth);
-
- abort_egress:
-       if (status)
-               free_TPM_STORED_DATA12(sealedData);
-       TPM_AUTH_ERR_CHECK(pubAuth);
-       return status;
-}
-
-TPM_RESULT TPM_Unseal(
-               TPM_KEY_HANDLE parentHandle, // in
-               const TPM_STORED_DATA12* sealedData,
-               UINT32* outSize,  // out
-               BYTE**   out, //out
-               const TPM_AUTHDATA* key_usage_auth, //in
-               const TPM_AUTHDATA* data_usage_auth, //in
-               TPM_AUTH_SESSION*       keyAuth,  // in, out
-               TPM_AUTH_SESSION*       dataAuth  // in, out
-               )
-{
-       TPM_BEGIN_CMD(TPM_ORD_Unseal);
-
-       PACK_IN(TPM_KEY_HANDLE, parentHandle);
-
-       TPM_HASH_IN_BEGIN;
-       PACK_IN(TPM_STORED_DATA12, sealedData);
-
-       TPM_XMIT_AUTH2(key_usage_auth, keyAuth, data_usage_auth, dataAuth);
-
-       UNPACK_OUT(UINT32, outSize);
-       UNPACK_OUT(PTR, out, *outSize, UNPACK_ALLOC);
-
-       TPM_END_AUTH2(key_usage_auth, keyAuth, data_usage_auth, dataAuth);
-
-abort_egress:
-       TPM_AUTH_ERR_CHECK(keyAuth);
-       TPM_AUTH_ERR_CHECK(dataAuth);
-       return status;
-}
-
-TPM_RESULT TPM_LoadKey(
-               TPM_KEY_HANDLE  parentHandle, //
-               const TPM_KEY* key, //in
-               TPM_HANDLE*  keyHandle,  // out
-               const TPM_AUTHDATA* usage_auth,
-               TPM_AUTH_SESSION* auth)
-{
-       TPM_BEGIN_CMD(TPM_ORD_LoadKey);
-       PACK_IN(TPM_KEY_HANDLE, parentHandle);
-
-       TPM_HASH_IN_BEGIN;
-
-       PACK_IN(TPM_KEY, key);
-
-       TPM_XMIT_AUTH1(usage_auth, auth);
-
-       UNPACK_OUT(UINT32, keyHandle);
-
-       TPM_END_AUTH1(usage_auth, auth);
-
-       vtpmloginfo(VTPM_LOG_TPM, "Key Handle: 0x%x opened by TPM_LoadKey\n", *keyHandle);
-abort_egress:
-       TPM_AUTH_ERR_CHECK(auth);
-       return status;
-}
-
-TPM_RESULT TPM_FlushSpecific(TPM_HANDLE handle,
-               TPM_RESOURCE_TYPE rt) {
-       if(handle == 0) {
-               return TPM_SUCCESS;
-       }
-       TPM_BEGIN_CMD(TPM_ORD_FlushSpecific);
-
-       PACK_IN(TPM_HANDLE, handle);
-       PACK_IN(TPM_RESOURCE_TYPE, rt);
-
-       TPM_XMIT_REQ();
-       TPM_END();
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_GetRandom( UINT32*       bytesRequested, // in, out
-               BYTE*    randomBytes) // out
-{
-       UINT32 req_len = *bytesRequested;
-       TPM_BEGIN_CMD(TPM_ORD_GetRandom);
-       PACK_IN(UINT32, req_len);
-
-       TPM_XMIT_REQ();
-
-       UNPACK_OUT(UINT32, bytesRequested);
-       if (*bytesRequested > req_len)
-               return TPM_FAIL;
-       UNPACK_OUT(BUFFER, randomBytes, *bytesRequested);
-       TPM_END();
-
-abort_egress:
-       return status;
-}
-
-
-TPM_RESULT TPM_ReadPubek(
-               TPM_PUBKEY* pubEK //out
-               )
-{
-       TPM_DIGEST antiReplay;
-       BYTE* kptr = NULL;
-       BYTE digest[TPM_DIGEST_SIZE];
-       sha1_context ctx;
-
-       vtpmmgr_rand(antiReplay.digest, TPM_DIGEST_SIZE);
-
-       TPM_BEGIN_CMD(TPM_ORD_ReadPubek);
-
-       PACK_IN(TPM_DIGEST, &antiReplay);
-
-       TPM_XMIT_REQ();
-
-       //unpack and allocate the key
-       kptr = OUT_PTR;
-       UNPACK_OUT(TPM_PUBKEY, pubEK, UNPACK_ALLOC);
-
-       //Verify the checksum
-       sha1_starts(&ctx);
-       sha1_update(&ctx, kptr, OUT_PTR - kptr);
-       sha1_update(&ctx, antiReplay.digest, TPM_DIGEST_SIZE);
-       sha1_finish(&ctx, digest);
-
-       UNPACK_OUT(TPM_DIGEST, &antiReplay);
-
-       TPM_END();
-
-       //ptr points to the checksum computed by TPM
-       if(memcmp(digest, antiReplay.digest, TPM_DIGEST_SIZE)) {
-               vtpmlogerror(VTPM_LOG_TPM, "TPM_ReadPubek: Checksum returned by TPM was invalid!\n");
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       goto egress;
-abort_egress:
-       if(kptr != NULL) { //If we unpacked the pubEK, we have to free it
-               free_TPM_PUBKEY(pubEK);
-       }
-egress:
-       return status;
-}
-
-TPM_RESULT TPM_PCR_Read(UINT32 pcr, TPM_DIGEST *value)
-{
-       TPM_BEGIN_CMD(TPM_ORD_PcrRead);
-       PACK_IN(UINT32, pcr);
-       TPM_XMIT_REQ();
-       UNPACK_OUT(TPM_DIGEST, value);
-       TPM_END();
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_SaveState(void)
-{
-       TPM_BEGIN_CMD(TPM_ORD_SaveState);
-       TPM_XMIT_REQ();
-       TPM_END();
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_GetCapability(
-               TPM_CAPABILITY_AREA capArea,
-               UINT32 subCapSize,
-               const BYTE* subCap,
-               UINT32* respSize,
-               BYTE** resp)
-{
-       TPM_BEGIN_CMD(TPM_ORD_GetCapability);
-
-       PACK_IN(TPM_CAPABILITY_AREA, capArea);
-       PACK_IN(UINT32, subCapSize);
-       PACK_IN(BUFFER, subCap, subCapSize);
-
-       TPM_XMIT_REQ();
-
-       UNPACK_OUT(UINT32, respSize);
-       UNPACK_OUT(PTR, resp, *respSize, UNPACK_ALLOC);
-
-       TPM_END();
-
-abort_egress:
-       return status;
-}
-
-TPM_RESULT TPM_CreateEndorsementKeyPair(
-               const TPM_KEY_PARMS* keyInfo,
-               TPM_PUBKEY* pubEK)
-{
-       BYTE* kptr = NULL;
-       sha1_context ctx;
-       TPM_DIGEST checksum;
-       TPM_DIGEST hash;
-       TPM_NONCE antiReplay;
-       TPM_BEGIN_CMD(TPM_ORD_CreateEndorsementKeyPair);
-
-       //Make anti replay nonce
-       vtpmmgr_rand(antiReplay.nonce, sizeof(antiReplay.nonce));
-
-       PACK_IN(TPM_NONCE, &antiReplay);
-       PACK_IN(TPM_KEY_PARMS, keyInfo);
-
-       TPM_XMIT_REQ();
-
-       kptr = OUT_PTR;
-       UNPACK_OUT(TPM_PUBKEY, pubEK, UNPACK_ALLOC);
-
-       /* Hash the pub key blob */
-       sha1_starts(&ctx);
-       sha1_update(&ctx, kptr, OUT_PTR - kptr);
-       sha1_update(&ctx, antiReplay.nonce, sizeof(antiReplay.nonce));
-       sha1_finish(&ctx, hash.digest);
-
-       UNPACK_OUT(TPM_DIGEST, &checksum);
-
-       TPM_END();
-
-       if (memcmp(checksum.digest, hash.digest, TPM_DIGEST_SIZE)) {
-               vtpmloginfo(VTPM_LOG_VTPM, "TPM_CreateEndorsementKey: Checkum verification failed!\n");
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       goto egress;
-abort_egress:
-       if(kptr) {
-               free_TPM_PUBKEY(pubEK);
-       }
-egress:
-       return status;
-}
-
-TPM_RESULT TPM_MakeIdentity(
-       const TPM_AUTHDATA* identityAuth, // in
-       const TPM_AUTHDATA* privCADigest, // in
-       const TPM_KEY* kinfo, // in
-       const TPM_AUTHDATA* srk_auth, // in
-       const TPM_AUTHDATA* own_auth, // in
-       TPM_AUTH_SESSION* srkAuth, // in,out
-       TPM_AUTH_SESSION* ownAuth, // in,out
-       TPM_KEY* key, // out
-       UINT32* identityBindingSize, // out
-       BYTE** identityBinding) // out
-{
-       TPM_BEGIN_CMD(TPM_ORD_MakeIdentity);
-       TPM_HASH_IN_BEGIN;
-
-       xorEncrypt(own_auth, &ownAuth->NonceEven, identityAuth, IN_PTR, NULL, NULL);
-       in_pos += sizeof(TPM_ENCAUTH);
-
-       PACK_IN(TPM_AUTHDATA, privCADigest);
-       PACK_IN(TPM_KEY, kinfo);
-
-       TPM_XMIT_AUTH2(srk_auth, srkAuth, own_auth, ownAuth);
-
-       UNPACK_OUT(TPM_KEY, key, UNPACK_ALLOC);
-       UNPACK_OUT(UINT32, identityBindingSize);
-       UNPACK_OUT(PTR, identityBinding, *identityBindingSize, UNPACK_ALLOC);
-
-       TPM_END_AUTH2(srk_auth, srkAuth, own_auth, ownAuth);
-
-abort_egress:
-       TPM_AUTH_ERR_CHECK(srkAuth);
-       TPM_AUTH_ERR_CHECK(ownAuth);
-       return status;
-}
-
-TPM_RESULT TPM_ActivateIdentity(
-       TPM_KEY_HANDLE aikHandle, // in
-       BYTE* blob, // in
-       UINT32 blobSize, // in
-       const TPM_AUTHDATA* aik_auth, // in
-       const TPM_AUTHDATA* owner_auth, // in
-       TPM_AUTH_SESSION* aikAuth, // in,out
-       TPM_AUTH_SESSION* ownAuth, // in,out
-       TPM_SYMMETRIC_KEY* symKey) // out
-{
-       TPM_BEGIN_CMD(TPM_ORD_ActivateIdentity);
-       PACK_IN(TPM_KEY_HANDLE, aikHandle);
-       TPM_HASH_IN_BEGIN;
-       PACK_IN(UINT32, blobSize);
-       PACK_IN(BUFFER, blob, blobSize);
-       
-       TPM_XMIT_AUTH2(aik_auth, aikAuth, owner_auth, ownAuth);
-
-       UNPACK_OUT(TPM_SYMMETRIC_KEY, symKey, UNPACK_ALLOC);
-
-       TPM_END_AUTH2(aik_auth, aikAuth, owner_auth, ownAuth);
-
-abort_egress:
-       TPM_AUTH_ERR_CHECK(aikAuth);
-       TPM_AUTH_ERR_CHECK(ownAuth);
-       return status;
-}
-
-TPM_RESULT TPM_Quote(
-       TPM_KEY_HANDLE keyh, // in
-       const TPM_NONCE* data, // in
-       const TPM_PCR_SELECTION *pcrSelect, // in
-       const TPM_AUTHDATA* auth, // in
-       TPM_AUTH_SESSION* oiap, // in,out
-       TPM_PCR_COMPOSITE *pcrs, // out
-       BYTE** sig, // out
-       UINT32* sigSize) // out
-{
-       TPM_BEGIN_CMD(TPM_ORD_Quote);
-       PACK_IN(TPM_KEY_HANDLE, keyh);
-       TPM_HASH_IN_BEGIN;
-       PACK_IN(TPM_NONCE, data);
-       PACK_IN(TPM_PCR_SELECTION, pcrSelect);
-
-       TPM_XMIT_AUTH1(auth, oiap);
-
-       UNPACK_OUT(TPM_PCR_COMPOSITE, pcrs, UNPACK_ALLOC);
-       UNPACK_OUT(UINT32, sigSize);
-       UNPACK_OUT(PTR, sig, *sigSize, UNPACK_ALLOC);
-
-       TPM_END_AUTH1(auth, oiap);
-
-abort_egress:
-       TPM_AUTH_ERR_CHECK(oiap);
-       return status;
-}
-
-TPM_RESULT TPM_TransmitData(
-               BYTE* in,
-               UINT32 insize,
-               BYTE* out,
-               UINT32* outsize) {
-       TPM_RESULT status = TPM_SUCCESS;
-
-       UINT32 i;
-       vtpmloginfo(VTPM_LOG_TXDATA, "Sending buffer = 0x");
-       for(i = 0 ; i < insize ; i++)
-               vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", in[i]);
-
-       vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
-
-       ssize_t size = 0;
-
-       // send the request
-       size = write (vtpm_globals.tpm_fd, in, insize);
-       if (size < 0) {
-               vtpmlogerror(VTPM_LOG_TXDATA, "write() failed : %s\n", strerror(errno));
-               ERRORDIE (TPM_IOERROR);
-       }
-       else if ((UINT32) size < insize) {
-               vtpmlogerror(VTPM_LOG_TXDATA, "Wrote %d instead of %d bytes!\n", (int) size, insize);
-               ERRORDIE (TPM_IOERROR);
-       }
-
-       // read the response
-       size = read (vtpm_globals.tpm_fd, out, *outsize);
-       if (size < 0) {
-               vtpmlogerror(VTPM_LOG_TXDATA, "read() failed : %s\n", strerror(errno));
-               ERRORDIE (TPM_IOERROR);
-       }
-
-       vtpmloginfo(VTPM_LOG_TXDATA, "Receiving buffer = 0x");
-       for(i = 0 ; i < size ; i++)
-               vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", out[i]);
-
-       vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
-
-       *outsize = size;
-       goto egress;
-
-abort_egress:
-egress:
-       return status;
-}
diff --git a/stubdom/vtpmmgr/tpm.h b/stubdom/vtpmmgr/tpm.h
deleted file mode 100644 (file)
index d613eb3..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005/2006, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef __TPM_H__
-#define __TPM_H__
-
-#include "tcg.h"
-
-// ------------------------------------------------------------------
-// Exposed API
-// ------------------------------------------------------------------
-
-// TPM v1.1B Command Set
-
-// Authorzation
-TPM_RESULT TPM_OIAP(
-      TPM_AUTH_SESSION*   auth //out
-      );
-
-TPM_RESULT TPM_OSAP (
-      TPM_ENTITY_TYPE entityType,  // in
-      UINT32    entityValue, // in
-      const TPM_AUTHDATA* usageAuth, //in
-      TPM_SECRET *sharedSecret, //out
-      TPM_AUTH_SESSION *auth);
-
-TPM_RESULT TPM_TakeOwnership(
-      const TPM_PUBKEY *pubEK, //in
-      const TPM_AUTHDATA* ownerAuth, //in
-      const TPM_AUTHDATA* srkAuth, //in
-      const TPM_KEY* inSrk, //in
-      TPM_KEY* outSrk, //out, optional
-      TPM_AUTH_SESSION*   auth   // in, out
-      );
-
-TPM_RESULT TPM_DisablePubekRead (
-      const TPM_AUTHDATA* ownerAuth,
-      TPM_AUTH_SESSION*   auth
-      );
-
-TPM_RESULT TPM_TerminateHandle ( TPM_AUTHHANDLE  handle  // in
-      );
-
-TPM_RESULT TPM_FlushSpecific ( TPM_HANDLE  handle,  // in
-      TPM_RESOURCE_TYPE resourceType //in
-      );
-
-// TPM Mandatory
-TPM_RESULT TPM_Extend ( TPM_PCRINDEX  pcrNum,  // in
-      TPM_DIGEST*  inDigest, // in
-      TPM_PCRVALUE*   outDigest // out
-      );
-
-TPM_RESULT TPM_Reset(TPM_PCR_SELECTION *sel);
-
-TPM_RESULT TPM_Seal(
-      TCS_KEY_HANDLE  keyHandle,  // in
-      UINT32    pcrInfoLongSize, // in
-      TPM_PCR_INFO_LONG*    pcrInfoLong,  // in
-      UINT32    inDataSize,  // in
-      const BYTE*    inData,   // in
-      TPM_STORED_DATA12* sealedData, //out
-      const TPM_SECRET* osapSharedSecret, //in
-      const TPM_AUTHDATA* sealDataAuth, //in
-      TPM_AUTH_SESSION*   pubAuth  // in, out
-      );
-
-TPM_RESULT TPM_Unseal (
-      TPM_KEY_HANDLE parentHandle, // in
-      const TPM_STORED_DATA12* sealedData,
-      UINT32*   outSize,  // out
-      BYTE**    out, //out
-      const TPM_AUTHDATA* key_usage_auth, //in
-      const TPM_AUTHDATA* data_usage_auth, //in
-      TPM_AUTH_SESSION*   keyAuth,  // in, out
-      TPM_AUTH_SESSION*   dataAuth  // in, out
-      );
-
-TPM_RESULT TPM_LoadKey (
-      TPM_KEY_HANDLE  parentHandle, //
-      const TPM_KEY* key, //in
-      TPM_HANDLE*  keyHandle,    // out
-      const TPM_AUTHDATA* usage_auth,
-      TPM_AUTH_SESSION* auth
-      );
-
-TPM_RESULT TPM_FlushSpecific(TPM_HANDLE handle, //in
-      TPM_RESOURCE_TYPE rt //in
-      );
-
-TPM_RESULT TPM_GetRandom (  UINT32*    bytesRequested, // in, out
-      BYTE*    randomBytes  // out
-      );
-
-TPM_RESULT TPM_ReadPubek (
-      TPM_PUBKEY* pubEK //out
-      );
-
-TPM_RESULT TPM_GetCapability(
-      TPM_CAPABILITY_AREA capArea,
-      UINT32 subCapSize,
-      const BYTE* subCap,
-      UINT32* respSize,
-      BYTE** resp);
-
-TPM_RESULT TPM_PCR_Read(UINT32 pcr, TPM_DIGEST *value);
-TPM_RESULT TPM_SaveState(void);
-
-TPM_RESULT TPM_CreateEndorsementKeyPair(
-      const TPM_KEY_PARMS* keyInfo,
-      TPM_PUBKEY* pubEK);
-
-TPM_RESULT TPM_MakeIdentity(
-       const TPM_AUTHDATA* identityAuth, // in
-       const TPM_AUTHDATA* privCADigest, // in
-       const TPM_KEY* kinfo, // in
-       const TPM_AUTHDATA* srk_auth, // in
-       const TPM_AUTHDATA* owner_auth, // in
-       TPM_AUTH_SESSION* srkAuth, // in,out
-       TPM_AUTH_SESSION* ownAuth, // in,out
-       TPM_KEY* key, // out
-       UINT32* identityBindingSize, // out
-       BYTE** identityBinding); // out
-
-TPM_RESULT TPM_ActivateIdentity(
-       TPM_KEY_HANDLE aikHandle, // in
-       BYTE* blob, // in
-       UINT32 blobSize, // in
-       const TPM_AUTHDATA* aik_auth, // in
-       const TPM_AUTHDATA* owner_auth, // in
-       TPM_AUTH_SESSION* aikAuth, // in,out
-       TPM_AUTH_SESSION* ownAuth, // in,out
-       TPM_SYMMETRIC_KEY* symKey); // out
-
-TPM_RESULT TPM_Quote(
-       TPM_KEY_HANDLE keyh, // in
-       const TPM_NONCE* data, // in
-       const TPM_PCR_SELECTION *pcrSelect, // in
-       const TPM_AUTHDATA* auth, // in
-       TPM_AUTH_SESSION* oiap, // in,out
-       TPM_PCR_COMPOSITE *pcrs, // out
-       BYTE** sig, // out
-       UINT32* sigSize); // out
-
-TPM_RESULT TPM_TransmitData(
-      BYTE* in,
-      UINT32 insize,
-      BYTE* out,
-      UINT32* outsize);
-
-#endif //TPM_H
diff --git a/stubdom/vtpmmgr/tpm2.c b/stubdom/vtpmmgr/tpm2.c
deleted file mode 100644 (file)
index c9f1016..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * Copyright (c) 2014 Intel Corporation.
- *
- * Authors:
- *   Quan Xu <quan.xu@intel.com>
- *
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005/2006, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <malloc.h>
-#include <unistd.h>
-#include <errno.h>
-#include <polarssl/sha1.h>
-
-#include "tcg.h"
-#include "tpm.h"
-#include "tpm2.h"
-#include "log.h"
-#include "marshal.h"
-#include "tpm2_marshal.h"
-#include "tpmrsa.h"
-#include "vtpmmgr.h"
-
-#define TCPA_MAX_BUFFER_LENGTH 0x2000
-#define TPM_BEGIN(TAG, ORD) \
-    const TPM_TAG intag = TAG;\
-    TPM_TAG tag = intag;\
-    UINT32 paramSize;\
-    const TPM_COMMAND_CODE ordinal = ORD;\
-    TPM_RESULT status = TPM_SUCCESS;\
-    BYTE in_buf[TCPA_MAX_BUFFER_LENGTH];\
-    BYTE out_buf[TCPA_MAX_BUFFER_LENGTH];\
-    UINT32 out_len = sizeof(out_buf);\
-    BYTE* ptr = in_buf;\
-    /*Print a log message */\
-    vtpmloginfo(VTPM_LOG_TPM, "%s\n", __func__);\
-    /* Pack the header*/\
-    ptr = pack_TPM_TAG(ptr, tag);\
-    ptr += sizeof(UINT32);\
-    ptr = pack_TPM_COMMAND_CODE(ptr, ordinal)\
-
-#define TPM_AUTH_BEGIN() \
-    sha1_context sha1_ctx;\
-    BYTE* authbase = ptr - sizeof(TPM_COMMAND_CODE);\
-    TPM_DIGEST paramDigest;\
-    sha1_starts(&sha1_ctx)
-
-#define TPM_AUTH1_GEN(HMACkey, auth) do {\
-    sha1_finish(&sha1_ctx, paramDigest.digest);\
-    generateAuth(&paramDigest, HMACkey, auth);\
-    ptr = pack_TPM_AUTH_SESSION(ptr, auth);\
-} while(0)
-
-#define TPM_AUTH2_GEN(HMACkey, auth) do {\
-    generateAuth(&paramDigest, HMACkey, auth);\
-    ptr = pack_TPM_AUTH_SESSION(ptr, auth);\
-} while(0)
-
-#define TPM_TRANSMIT() do {\
-    /* Pack the command size */\
-    paramSize = ptr - in_buf;\
-    pack_UINT32(in_buf + sizeof(TPM_TAG), paramSize);\
-    if ((status = TPM_TransmitData(in_buf, paramSize, out_buf, &out_len)) != TPM_SUCCESS) {\
-        goto abort_egress;\
-    }\
-} while(0)
-
-#define TPM_AUTH_VERIFY_BEGIN() do {\
-    UINT32 buf[2] = { cpu_to_be32(status), cpu_to_be32(ordinal) };\
-    sha1_starts(&sha1_ctx);\
-    sha1_update(&sha1_ctx, (unsigned char*)buf, sizeof(buf));\
-    authbase = ptr;\
-} while(0)
-
-#define TPM_AUTH1_VERIFY(HMACkey, auth) do {\
-    sha1_finish(&sha1_ctx, paramDigest.digest);\
-    ptr = unpack_TPM_AUTH_SESSION(ptr, auth);\
-    if ((status = verifyAuth(&paramDigest, HMACkey, auth)) != TPM_SUCCESS) {\
-        goto abort_egress;\
-    }\
-} while(0)
-
-#define TPM_AUTH2_VERIFY(HMACkey, auth) do {\
-    ptr = unpack_TPM_AUTH_SESSION(ptr, auth);\
-    if ((status = verifyAuth(&paramDigest, HMACkey, auth)) != TPM_SUCCESS) {\
-        goto abort_egress;\
-    }\
-} while(0)
-
-#define TPM_UNPACK_VERIFY() do { \
-    ptr = out_buf;\
-    ptr = unpack_TPM_RSP_HEADER(ptr, \
-          &(tag), &(paramSize), &(status));\
-    if ((status) != TPM_SUCCESS){ \
-        vtpmlogerror(VTPM_LOG_TPM, "Failed with return code %s\n", tpm_get_error_name(status));\
-        goto abort_egress;\
-    }\
-} while(0)
-
-#define TPM_AUTH_HASH() do {\
-    sha1_update(&sha1_ctx, authbase, ptr - authbase);\
-    authbase = ptr;\
-} while(0)
-
-#define TPM_AUTH_SKIP() do {\
-    authbase = ptr;\
-} while(0)
-
-TPM_RC TPM2_PCR_Read(TPML_PCR_SELECTION pcrSelectionIn,
-                     UINT32 *pcrUpdateCounter,
-                     TPML_PCR_SELECTION *pcrSelectionOut,
-                     TPML_DIGEST *pcrValues)
-{
-    TPM_BEGIN(TPM_ST_NO_SESSIONS,TPM_CC_PCR_Read);
-
-    /*pack in*/
-    ptr =  pack_TPML_PCR_SELECTION(ptr, &pcrSelectionIn);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-    /*unpack out*/
-    ptr = unpack_UINT32(ptr, pcrUpdateCounter);
-    ptr = unpack_TPML_PCR_SELECTION(ptr, pcrSelectionOut);
-    ptr = unpack_TPML_DIGEST(ptr, pcrValues);
-
-    goto egress;
-abort_egress:
-egress:
-    return status;
-}
-
-TPM_RC TPM2_Load(TPMI_DH_OBJECT parentHandle,
-                 TPM2B_PRIVATE *inPrivate, /* in */
-                 TPM2B_PUBLIC *inPublic, /* in */
-                 TPM2_HANDLE *objectHandle, /* out */
-                 TPM2B_NAME *name /* out */)
-{
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_Load);
-
-    /* pack handle of parent for new object */
-    ptr =  pack_UINT32(ptr, parentHandle);
-
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.srk_auth_area);
-    ptr = pack_TPM2B_PRIVATE(ptr, inPrivate);
-    ptr = pack_TPM2B_PUBLIC(ptr, inPublic);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-    if (objectHandle != NULL) {
-        ptr = unpack_TPM_HANDLE(ptr, objectHandle);
-    } else {
-        TPM2_HANDLE tmp;
-        ptr = unpack_TPM_HANDLE(ptr, &tmp);
-    }
-
-    if (name != NULL)
-        ptr = unpack_TPM2B_NAME(ptr, name);
-    goto egress;
-
-abort_egress:
-egress:
-    return status;
-}
-
-TPM_RC TPM2_Create(TPMI_DH_OBJECT parentHandle,
-                   TPM2_Create_Params_in *in,
-                   TPM2_Create_Params_out *out)
-{
-    UINT32 param_size;
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_Create);
-
-    /* pack handle of parent for new object */
-    ptr =  pack_UINT32(ptr, parentHandle);
-
-    /* pack Auth Area */
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.srk_auth_area);
-
-    /* pack inSensitive */
-    ptr = pack_TPM2B_SENSITIVE_CREATE(ptr, &in->inSensitive);
-
-    /* pack inPublic */
-    ptr = pack_TPM2B_PUBLIC(ptr, &in->inPublic);
-
-    /* pack outside Info */
-    ptr = pack_TPM2B_DATA(ptr, &in->outsideInfo);
-
-    /* pack createPCR */
-    ptr = pack_TPML_PCR_SELECTION(ptr, &in->creationPCR);
-
-    /* Send the command to the tpm */
-    TPM_TRANSMIT();
-
-    /* Unpack and validate the header */
-    TPM_UNPACK_VERIFY();
-
-    ptr = unpack_UINT32(ptr, &param_size);
-    if (out != NULL) {
-        ptr = unpack_TPM2B_PRIVATE(ptr, &vtpm_globals.tpm2_storage_key.Private);
-        ptr = unpack_TPM2B_PUBLIC(ptr, &vtpm_globals.tpm2_storage_key.Public);
-        ptr = unpack_TPM2B_CREATION_DATA(ptr, &out->creationData);
-        ptr = unpack_TPM2B_DIGEST(ptr, &out->creationHash);
-        ptr = unpack_TPMT_TK_CREATION(ptr, &out->creationTicket);
-    } else {
-           ptr += param_size;
-    }
-    goto egress;
-
-abort_egress:
-egress:
-    return status;
-}
-
-TPM_RC TPM2_CreatePrimary(TPMI_RH_HIERARCHY primaryHandle,
-                          TPM2_Create_Params_in *in,
-                          TPM2_HANDLE *objHandle,
-                          TPM2_Create_Params_out *out)
-{
-    UINT32 param_size;
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_CreatePrimary);
-
-    /* pack primary handle */
-    ptr = pack_UINT32(ptr, primaryHandle);
-
-    /* pack Auth Area */
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.pw_auth);
-
-    /* pack inSenstive */
-    ptr = pack_TPM2B_SENSITIVE_CREATE(ptr, &in->inSensitive);
-
-    /* pack inPublic */
-    ptr = pack_TPM2B_PUBLIC(ptr, &in->inPublic);
-
-    /* pack outsideInfo */
-    ptr = pack_TPM2B_DATA(ptr, &in->outsideInfo);
-
-    /* pack creationPCR */
-    ptr = pack_TPML_PCR_SELECTION(ptr, &in->creationPCR);
-
-    /* Send the command to the tpm */
-    TPM_TRANSMIT();
-
-    /* Unpack and validate the header */
-    TPM_UNPACK_VERIFY();
-
-    if (objHandle != NULL)
-        ptr = unpack_TPM_HANDLE(ptr, objHandle);
-    else {
-        TPM2_HANDLE handle;
-        ptr = unpack_TPM_HANDLE(ptr, &handle);
-    }
-    ptr = unpack_UINT32(ptr, &param_size);
-
-    if (out != NULL) {
-        ptr = unpack_TPM2B_PUBLIC(ptr, &out->outPublic);
-        ptr = unpack_TPM2B_CREATION_DATA(ptr, &out->creationData);
-        ptr = unpack_TPM2B_DIGEST(ptr, &out->creationHash);
-        ptr = unpack_TPMT_TK_CREATION(ptr, &out->creationTicket);
-    } else {
-        ptr += param_size;
-    }
-
-goto egress;
-
-abort_egress:
-egress:
-   return status;
-}
-
-TPM_RC TPM2_HierachyChangeAuth(TPM2I_RH_HIERARCHY_AUTH authHandle, TPM2B_AUTH *newAuth)
-{
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_HierarchyChangeAuth);
-    ptr = pack_UINT32(ptr, authHandle);
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.pw_auth);
-    ptr = pack_TPM2B_AUTH(ptr, newAuth);
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_RSA_ENCRYPT(TPMI_DH_OBJECT keyHandle,
-                        TPM2B_PUBLIC_KEY_RSA *message,
-                        TPMT_RSA_DECRYPT *inScheme,
-                        TPM2B_DATA *label,
-                        TPM2B_PUBLIC_KEY_RSA *outData)
-{
-    TPM_BEGIN(TPM_ST_NO_SESSIONS, TPM_CC_RSA_Encrypt);
-
-    ptr = pack_UINT32(ptr, keyHandle);
-    ptr = pack_TPM2B_PUBLIC_KEY_RSA(ptr, message);
-    ptr = pack_TPMT_RSA_DECRYPT(ptr, inScheme);
-    ptr = pack_TPM2B_DATA(ptr, label);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-    if (outData != NULL)
-        unpack_TPM2B_PUBLIC_KEY_RSA(ptr, outData);
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_Bind(TPMI_DH_OBJECT keyHandle,
-                 void *buf,
-                 UINT32 len,
-                 void *out)
-{
-    TPM_RC status = TPM_SUCCESS;
-    TPM2B_PUBLIC_KEY_RSA message;
-    TPMT_RSA_DECRYPT inScheme;
-    TPM2B_DATA label;
-    TPM2B_PUBLIC_KEY_RSA outData;
-
-    message.size = len;
-    memcpy(message.buffer, buf, len);
-    inScheme.scheme = TPM2_ALG_NULL;
-    label.size = 0;
-    TPMTRYRETURN(TPM2_RSA_ENCRYPT(keyHandle, &message, &inScheme, &label, &outData));
-    memcpy(out, outData.buffer, outData.size);
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_RSA_Decrypt(TPMI_DH_OBJECT keyHandle,
-                        TPM2B_PUBLIC_KEY_RSA *cipherText,
-                        TPMT_RSA_DECRYPT *inScheme,
-                        TPM2B_DATA *label,
-                        TPM2B_PUBLIC_KEY_RSA *message)
-{
-    UINT32 param_size;
-
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_RSA_Decrypt);
-    ptr = pack_UINT32(ptr, keyHandle);
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.srk_auth_area);
-    ptr = pack_TPM2B_PUBLIC_KEY_RSA(ptr, cipherText);
-    ptr = pack_TPMT_RSA_DECRYPT(ptr, inScheme);
-    ptr = pack_TPM2B_DATA(ptr, label);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-    ptr = unpack_UINT32(ptr, &param_size);
-
-    if (message)
-        ptr = unpack_TPM2B_PUBLIC_KEY_RSA(ptr, message);
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_UnBind(TPMI_DH_OBJECT keyHandle,
-                   UINT32 ilen,
-                   void *in,
-                   UINT32 *olen,
-                   void *out)
-{
-    UINT32 status;
-    TPM2B_PUBLIC_KEY_RSA cipher, message;
-    TPMT_RSA_DECRYPT inScheme;
-    TPM2B_DATA label;
-
-    cipher.size = ilen;
-    memcpy(cipher.buffer, in, ilen);
-    inScheme.scheme = TPM2_ALG_NULL;
-    label.size = 0;
-
-    TPMTRYRETURN(TPM2_RSA_Decrypt(keyHandle, &cipher, &inScheme, &label, &message));
-
-    *olen = message.size;
-    memcpy(out, message.buffer, *olen);
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_CLEAR(void)
-{
-    TPM_BEGIN(TPM_ST_SESSIONS, TPM_CC_Clear);
-
-    ptr = pack_UINT32(ptr, TPM_RH_PLATFORM);
-    ptr = pack_TPM_AuthArea(ptr, &vtpm_globals.pw_auth);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_GetRandom(UINT32 * bytesRequested, BYTE * randomBytes)
-{
-    TPM_BEGIN(TPM_ST_NO_SESSIONS, TPM_CC_GetRandom);
-
-    ptr = pack_UINT16(ptr, (UINT16)*bytesRequested);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-    ptr = unpack_UINT16(ptr, (UINT16 *)bytesRequested);
-    ptr = unpack_TPM_BUFFER(ptr, randomBytes, *bytesRequested);
-
-abort_egress:
-    return status;
-}
-
-TPM_RC TPM2_FlushContext(TPMI_DH_CONTEXT flushHandle)
-{
-    TPM_BEGIN(TPM_ST_NO_SESSIONS, TPM_CC_FlushContext);
-
-    ptr = pack_UINT32(ptr, flushHandle);
-
-    TPM_TRANSMIT();
-    TPM_UNPACK_VERIFY();
-
-abort_egress:
-    return status;
-}
diff --git a/stubdom/vtpmmgr/tpm2.h b/stubdom/vtpmmgr/tpm2.h
deleted file mode 100644 (file)
index 9e01286..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2014 Intel Corporation.
- *
- * Authors:
- *   Quan Xu <quan.xu@intel.com>
- *
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005/2006, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef __TPM2_H__
-#define __TPM2_H__
-
-#include "tcg.h"
-#include "tpm2_types.h"
-
-// ------------------------------------------------------------------
-// TPM 2.0 Exposed API
-// ------------------------------------------------------------------
-
-TPM_RC TPM2_PCR_Read(TPML_PCR_SELECTION pcrSelectionIn,
-                     UINT32 *pcrUpdateCounter,
-                     TPML_PCR_SELECTION *pcrSelectionOut,
-                     TPML_DIGEST *pcrValues);
-
-TPM_RC TPM2_Load(TPMI_DH_OBJECT parentHandle,
-                 TPM2B_PRIVATE *inPrivate,
-                 TPM2B_PUBLIC *inPublic,
-                 TPM2_HANDLE *objectHandle,
-                 TPM2B_NAME *name);
-
-TPM_RC TPM2_Create(TPMI_DH_OBJECT parentHandle,
-                   TPM2_Create_Params_in *in,
-                   TPM2_Create_Params_out *out);
-
-TPM_RC TPM2_CreatePrimary(TPMI_RH_HIERARCHY primaryHandle,
-                          TPM2_Create_Params_in *objHandle,
-                          TPM2_HANDLE *in,
-                          TPM2_Create_Params_out *out);
-
-TPM_RC TPM2_HierachyChangeAuth(TPM2I_RH_HIERARCHY_AUTH authHandle,
-                               TPM2B_AUTH *newAuth);
-
-TPM_RC TPM2_RSA_ENCRYPT(TPMI_DH_OBJECT keyHandle,
-                        TPM2B_PUBLIC_KEY_RSA *message,
-                        TPMT_RSA_DECRYPT *inScheme,
-                        TPM2B_DATA *label,
-                        TPM2B_PUBLIC_KEY_RSA *outData);
-
-TPM_RC TPM2_Bind(TPMI_DH_OBJECT keyHandle,
-                 void *buf,
-                 UINT32 len,
-                 void *out);
-
-TPM_RC TPM2_RSA_Decrypt(TPMI_DH_OBJECT keyHandle,
-                        TPM2B_PUBLIC_KEY_RSA *cipherText,
-                        TPMT_RSA_DECRYPT *inScheme,
-                        TPM2B_DATA *label,
-                        TPM2B_PUBLIC_KEY_RSA *message);
-
-TPM_RC TPM2_UnBind(TPMI_DH_OBJECT keyHandle,
-                   UINT32 ilen,
-                   void *in,
-                   UINT32 *olen,
-                   void *out);
-
-TPM_RESULT TPM2_GetRandom(UINT32* bytesRequested,
-                          BYTE* randomBytes);
-
-TPM_RC TPM2_CLEAR(void);
-
-TPM_RC TPM2_FlushContext(TPMI_DH_CONTEXT);
-#endif //TPM2_H
diff --git a/stubdom/vtpmmgr/tpm2_marshal.h b/stubdom/vtpmmgr/tpm2_marshal.h
deleted file mode 100644 (file)
index aaa4464..0000000
+++ /dev/null
@@ -1,673 +0,0 @@
-/*
- * Copyright (c) 2014 Intel Corporation.
- *
- * Authors:
- *   Quan Xu <quan.xu@intel.com>
- *
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef TPM2_MARSHAL_H
-#define TPM2_MARSHAL_H
-
-#include <stdlib.h>
-#include <mini-os/byteorder.h>
-#include <mini-os/endian.h>
-#include "tcg.h"
-#include "tpm2_types.h"
-#include <assert.h>
-
-#define pack_TPM_BUFFER(ptr, buf, size) pack_BUFFER(ptr, buf, size)
-#define unpack_TPM_BUFFER(ptr, buf, size) unpack_BUFFER(ptr, buf, size)
-
-inline BYTE* pack_BYTE_ARRAY(BYTE* ptr, const BYTE* array, UINT32 size)
-{
-    int i;
-    for (i = 0; i < size; i++)
-         ptr = pack_BYTE(ptr, array[i]);
-    return ptr;
-}
-
-inline BYTE* pack_TPMA_SESSION(BYTE* ptr, const TPMA_SESSION *attr)
-{
-    return pack_BYTE(ptr, (BYTE)(*attr));
-}
-
-inline BYTE* unpack_TPMA_SESSION(BYTE* ptr, TPMA_SESSION *attr)
-{
-    return unpack_BYTE(ptr, (BYTE *)attr);
-}
-
-inline BYTE* pack_TPMI_ALG_HASH(BYTE* ptr, const TPMI_ALG_HASH *hash)
-{
-    return pack_UINT16(ptr, *hash);
-}
-
-inline BYTE* unpack_TPMI_ALG_HASH(BYTE *ptr, TPMI_ALG_HASH *hash)
-{
-    return unpack_UINT16(ptr, hash);
-}
-
-#define pack_TPMA_OBJECT(ptr, t)                pack_UINT32(ptr, (UINT32)(*t))
-#define unpack_TPMA_OBJECT(ptr, t)              unpack_UINT32(ptr, (UINT32 *)(t))
-#define pack_TPM_RH(ptr, t)                     pack_UINT32(ptr, (UINT32)(*t))
-#define unpack_TPM_RH(ptr, t)                   unpack_UINT32(ptr, (UINT32 *)(t))
-#define pack_TPMA_LOCALITY(ptr, locality)       pack_BYTE(ptr, (BYTE)*locality)
-#define unpack_TPMA_LOCALITY(ptr, locality)     unpack_BYTE(ptr, (BYTE *)locality)
-#define pack_TPM_ST(ptr, tag)                   pack_UINT16(ptr, *tag)
-#define unpack_TPM_ST(ptr, tag)                 unpack_UINT16(ptr, tag)
-#define pack_TPM_KEY_BITS(ptr, t)               pack_UINT16(ptr, *t)
-#define unpack_TPM_KEY_BITS(ptr, t)             unpack_UINT16(ptr, t)
-#define pack_TPMI_AES_KEY_BITS(ptr, t)          pack_TPM_KEY_BITS(ptr, t)
-#define unpack_TPMI_AES_KEY_BITS(ptr, t)        unpack_TPM_KEY_BITS(ptr, t)
-#define pack_TPMI_RSA_KEY_BITS(ptr, t)          pack_TPM_KEY_BITS(ptr, t)
-#define unpack_TPMI_RSA_KEY_BITS(ptr, t)        unpack_TPM_KEY_BITS(ptr, t)
-#define pack_TPM_ALG_ID(ptr, id)                pack_UINT16(ptr, *id)
-#define unpack_TPM_ALG_ID(ptr, id)              unpack_UINT16(ptr, id)
-#define pack_TPM_ALG_SYM(ptr, t)                pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPM_ALG_SYM(ptr, t)              unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPMI_ALG_ASYM(ptr, asym)           pack_TPM_ALG_ID(ptr, asym)
-#define unpack_TPMI_ALG_ASYM(ptr, asym)         unpack_TPM_ALG_ID(ptr, asym)
-#define pack_TPMI_ALG_SYM_OBJECT(ptr, t)        pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPMI_ALG_SYM_OBJECT(ptr, t)      unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPMI_ALG_SYM_MODE(ptr, t)          pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPMI_ALG_SYM_MODE(ptr, t)        unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPMI_ALG_KDF(ptr, t)               pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPMI_ALG_KDF(ptr, t)             unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPMI_ALG_PUBLIC(ptr, t)            pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPMI_ALG_PUBLIC(ptr, t)          unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPM2_HANDLE(ptr, h)                pack_UINT32(ptr, *h)
-#define unpack_TPM2_HANDLE(ptr, h)              unpack_UINT32(ptr, h)
-#define pack_TPMI_ALG_RSA_SCHEME(ptr, t)        pack_TPM_ALG_ID(ptr, t)
-#define unpack_TPMI_ALG_RSA_SCHEME(ptr, t)      unpack_TPM_ALG_ID(ptr, t)
-#define pack_TPMI_DH_OBJECT(ptr, o)             pack_TPM2_HANDLE(ptr, o)
-#define unpack_TPMI_DH_OBJECT(PTR, O)           unpack_TPM2_HANDLE(ptr, o)
-#define pack_TPMI_RH_HIERACHY(ptr, h)           pack_TPM2_HANDLE(ptr, h)
-#define unpack_TPMI_RH_HIERACHY(ptr, h)         unpack_TPM2_HANDLE(ptr, h)
-#define pack_TPMI_RH_PLATFORM(ptr, p)           pack_TPM2_HANDLE(ptr, p)
-#define unpack_TPMI_RH_PLATFORM(ptr, p)         unpack_TPM2_HANDLE(ptr, p)
-#define pack_TPMI_RH_OWNER(ptr, o)              pack_TPM2_HANDLE(ptr, o)
-#define unpack_TPMI_RH_OWNER(ptr, o)            unpack_TPM2_HANDLE(ptr, o)
-#define pack_TPMI_RH_ENDORSEMENT(ptr, e)        pack_TPM2_HANDLE(ptr, e)
-#define unpack_TPMI_RH_ENDORSEMENT(ptr, e)      unpack_TPM2_HANDLE(ptr, e)
-#define pack_TPMI_RH_LOCKOUT(ptr, l)            pack_TPM2_HANDLE(ptr, l)
-#define unpack_TPMI_RH_LOCKOUT(ptr, l)          unpack_TPM2_HANDLE(ptr, l)
-
-inline BYTE* pack_TPM2B_DIGEST(BYTE* ptr, const TPM2B_DIGEST *digest)
-{
-    ptr = pack_UINT16(ptr, digest->size);
-    ptr = pack_BUFFER(ptr, digest->buffer, digest->size);
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2B_DIGEST(BYTE* ptr, TPM2B_DIGEST *digest)
-{
-    ptr = unpack_UINT16(ptr, &digest->size);
-    ptr = unpack_BUFFER(ptr, digest->buffer, digest->size);
-    return ptr;
-}
-
-inline BYTE* pack_TPMT_TK_CREATION(BYTE* ptr,const TPMT_TK_CREATION *ticket )
-{
-    ptr = pack_TPM_ST(ptr , &ticket->tag);
-    ptr = pack_TPMI_RH_HIERACHY(ptr , &ticket->hierarchy);
-    ptr = pack_TPM2B_DIGEST(ptr, &ticket->digest);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMT_TK_CREATION(BYTE* ptr, TPMT_TK_CREATION *ticket )
-{
-    ptr = unpack_TPM_ST(ptr, &ticket->tag);
-    ptr = unpack_TPMI_RH_HIERACHY(ptr, &ticket->hierarchy);
-    ptr = unpack_TPM2B_DIGEST(ptr, &ticket->digest);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2B_NAME(BYTE* ptr,const TPM2B_NAME *name )
-{
-    ptr = pack_UINT16(ptr, name->size);
-    ptr = pack_TPM_BUFFER(ptr, name->name, name->size);
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2B_NAME(BYTE* ptr, TPM2B_NAME *name)
-{
-    ptr = unpack_UINT16(ptr, &name->size);
-    ptr = unpack_TPM_BUFFER(ptr, name->name, name->size);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2B_NONCE(BYTE* ptr, const TPM2B_NONCE *nonce)
-{
-    return pack_TPM2B_DIGEST(ptr, (const TPM2B_DIGEST*)nonce);
-}
-
-#define unpack_TPM2B_NONCE(ptr, nonce)  unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)nonce)
-
-inline BYTE* pack_TPM2B_AUTH(BYTE* ptr, const TPM2B_AUTH *auth)
-{
-    return pack_TPM2B_DIGEST(ptr, (const TPM2B_DIGEST*)auth);
-}
-
-#define unpack_TPM2B_AUTH(ptr, auth)    unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)auth)
-
-inline BYTE* pack_TPM2B_DATA(BYTE* ptr, const TPM2B_DATA *data)
-{
-    return pack_TPM2B_DIGEST(ptr, (const TPM2B_DIGEST*)data);
-}
-
-#define unpack_TPM2B_DATA(ptr, data)    unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)data)
-
-inline BYTE* pack_TPM2B_SENSITIVE_DATA(BYTE* ptr, const TPM2B_SENSITIVE_DATA *data)
-{
-    return pack_TPM2B_DIGEST(ptr, (const TPM2B_DIGEST*)data);
-}
-
-#define unpack_TPM2B_SENSITIVE_DATA(ptr, data)  unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)data)
-
-inline BYTE* pack_TPM2B_PUBLIC_KEY_RSA(BYTE* ptr, const TPM2B_PUBLIC_KEY_RSA *rsa)
-{
-    return pack_TPM2B_DIGEST(ptr, (const TPM2B_DIGEST*)rsa);
-}
-
-#define unpack_TPM2B_PUBLIC_KEY_RSA(ptr, rsa)   unpack_TPM2B_DIGEST(ptr, (TPM2B_DIGEST*)rsa)
-
-inline BYTE* pack_TPM2B_PRIVATE(BYTE* ptr, const TPM2B_PRIVATE *Private)
-{
-    ptr = pack_UINT16(ptr, Private->size);
-    ptr = pack_TPM_BUFFER(ptr, Private->buffer, Private->size);
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2B_PRIVATE(BYTE* ptr, TPM2B_PRIVATE *Private)
-{
-    ptr = unpack_UINT16(ptr, &Private->size);
-    ptr = unpack_BUFFER(ptr, Private->buffer, Private->size);
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_PCR_SELECTION_ARRAY(BYTE* ptr, const TPMS_PCR_SELECTION *sel, UINT32 count)
-{
-    int i;
-    for (i = 0; i < count; i++) {
-        ptr = pack_TPMI_ALG_HASH(ptr, &sel[i].hash);
-        ptr = pack_BYTE(ptr, sel[i].sizeofSelect);
-        ptr = pack_BUFFER(ptr, sel[i].pcrSelect, sel[i].sizeofSelect);
-    }
-    return ptr;
-}
-
-inline BYTE* unpack_TPMS_PCR_SELECTION_ARRAY(BYTE* ptr, TPMS_PCR_SELECTION *sel, UINT32 count)
-{
-    int i;
-    for (i = 0; i < count; i++) {
-        ptr = unpack_TPMI_ALG_HASH(ptr, &sel[i].hash);
-        ptr = unpack_BYTE(ptr, &sel[i].sizeofSelect);
-        ptr = unpack_BUFFER(ptr, sel[i].pcrSelect, sel[i].sizeofSelect);
-    }
-    return ptr;
-}
-
-inline BYTE* pack_TPML_PCR_SELECTION(BYTE* ptr, const TPML_PCR_SELECTION *sel)
-{
-    ptr = pack_UINT32(ptr, sel->count);
-    ptr = pack_TPMS_PCR_SELECTION_ARRAY(ptr, sel->pcrSelections, sel->count);
-    return ptr;
-}
-
-inline BYTE* unpack_TPML_PCR_SELECTION(BYTE* ptr, TPML_PCR_SELECTION *sel)
-{
-    ptr = unpack_UINT32(ptr, &sel->count);
-    ptr = unpack_TPMS_PCR_SELECTION_ARRAY(ptr, sel->pcrSelections, sel->count);
-    return ptr;
-}
-
-inline BYTE* unpack_TPML_DIGEST(BYTE* ptr,TPML_DIGEST *digest)
-{
-    int i;
-    ptr = unpack_UINT32(ptr, &digest->count);
-    for (i=0;i<digest->count;i++)
-    {
-        ptr = unpack_TPM2B_DIGEST(ptr, &digest->digests[i]);
-    }
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_CREATION_DATA(BYTE* ptr,const TPMS_CREATION_DATA *data)
-{
-    ptr = pack_TPML_PCR_SELECTION(ptr, &data->pcrSelect);
-    ptr = pack_TPM2B_DIGEST(ptr, &data->pcrDigest);
-    ptr = pack_TPMA_LOCALITY(ptr, &data->locality);
-    ptr = pack_TPM_ALG_ID(ptr, &data->parentNameAlg);
-    ptr = pack_TPM2B_NAME(ptr, &data->parentQualifiedName);
-    ptr = pack_TPM2B_DATA(ptr, &data->outsideInfo);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMS_CREATION_DATA(BYTE* ptr, TPMS_CREATION_DATA *data)
-{
-    ptr = unpack_TPML_PCR_SELECTION(ptr, &data->pcrSelect);
-    ptr = unpack_TPM2B_DIGEST(ptr, &data->pcrDigest);
-    ptr = unpack_TPMA_LOCALITY(ptr, &data->locality);
-    ptr = unpack_TPM_ALG_ID(ptr, &data->parentNameAlg);
-    ptr = unpack_TPM2B_NAME(ptr, &data->parentName);
-    ptr = unpack_TPM2B_NAME(ptr, &data->parentQualifiedName);
-    ptr = unpack_TPM2B_DATA(ptr, &data->outsideInfo);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2B_CREATION_DATA(BYTE* ptr, const TPM2B_CREATION_DATA *data )
-{
-    ptr = pack_UINT16(ptr, data->size);
-    ptr = pack_TPMS_CREATION_DATA(ptr, &data->creationData);
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2B_CREATION_DATA(BYTE* ptr, TPM2B_CREATION_DATA * data)
-{
-    ptr = unpack_UINT16(ptr, &data->size);
-    ptr = unpack_TPMS_CREATION_DATA(ptr, &data->creationData);
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_SENSITIVE_CREATE(BYTE* ptr, const TPMS_SENSITIVE_CREATE *create)
-{
-    ptr = pack_TPM2B_AUTH(ptr, &create->userAuth);
-    ptr = pack_TPM2B_SENSITIVE_DATA(ptr, &create->data);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2B_SENSITIVE_CREATE(BYTE* ptr, const TPM2B_SENSITIVE_CREATE *create)
-{
-    BYTE* sizePtr = ptr;
-    ptr += 2;
-    ptr = pack_TPMS_SENSITIVE_CREATE(ptr, &create->sensitive);
-    pack_UINT16(sizePtr, (UINT16)(ptr - sizePtr - 2));
-    return ptr;
-}
-
-inline BYTE* pack_TPMU_SYM_MODE(BYTE* ptr, const TPMU_SYM_MODE *p,
-                                const TPMI_ALG_SYM_OBJECT *sel)
-{
-    switch(*sel) {
-    case TPM2_ALG_AES:
-        ptr = pack_TPMI_ALG_SYM_MODE(ptr, &p->aes);
-        break;
-    case TPM2_ALG_SM4:
-        assert(false);
-        break;
-    case TPM2_ALG_NULL:
-        case TPM2_ALG_XOR:
-        break;
-    default:
-        ptr = pack_TPMI_ALG_SYM_MODE(ptr, &p->sym);
-    }
-    return ptr;
-}
-inline BYTE* unpack_TPMU_SYM_MODE(BYTE* ptr, TPMU_SYM_MODE *p,
-                                  const TPMI_ALG_SYM_OBJECT *sel)
-{
-    switch(*sel) {
-    case TPM2_ALG_AES:
-        ptr = unpack_TPMI_ALG_SYM_MODE(ptr, &p->aes);
-        break;
-    case TPM2_ALG_SM4:
-        assert(false);
-        break;
-    case TPM2_ALG_NULL:
-    case TPM2_ALG_XOR:
-        break;
-    default:
-        ptr = unpack_TPMI_ALG_SYM_MODE(ptr, &p->sym);
-    }
-    return ptr;
-}
-
-inline BYTE* pack_TPMU_SYM_KEY_BITS(BYTE* ptr, const TPMU_SYM_KEY_BITS *p,
-                                    const TPMI_ALG_SYM_OBJECT *sel)
-{
-    switch(*sel) {
-    case TPM2_ALG_AES:
-        ptr = pack_TPMI_AES_KEY_BITS(ptr, &p->aes);
-        break;
-    case TPM2_ALG_SM4:
-        assert(false);
-        break;
-    case TPM2_ALG_XOR:
-        assert(false);
-        break;
-    case TPM2_ALG_NULL:
-        break;
-    default:
-        ptr = pack_TPM_KEY_BITS(ptr, &p->sym);
-    }
-    return ptr;
-}
-
-inline BYTE* unpack_TPMU_SYM_KEY_BITS(BYTE* ptr, TPMU_SYM_KEY_BITS *p,
-                                      const TPMI_ALG_SYM_OBJECT *sel)
-{
-    switch(*sel) {
-    case TPM2_ALG_AES:
-        ptr = unpack_TPMI_AES_KEY_BITS(ptr, &p->aes);
-        break;
-    case TPM2_ALG_SM4:
-        assert(false);
-        break;
-    case TPM2_ALG_XOR:
-        assert(false);
-        break;
-    case TPM2_ALG_NULL:
-        break;
-    default:
-        ptr = unpack_TPM_KEY_BITS(ptr, &p->sym);
-    }
-    return ptr;
-}
-
-inline BYTE* pack_TPMT_SYM_DEF_OBJECT(BYTE* ptr, const TPMT_SYM_DEF_OBJECT *p)
-{
-    ptr = pack_TPMI_ALG_SYM_OBJECT(ptr, &p->algorithm);
-    ptr = pack_TPMU_SYM_KEY_BITS(ptr, &p->keyBits, &p->algorithm);
-    ptr = pack_TPMU_SYM_MODE(ptr, &p->mode, &p->algorithm);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMT_SYM_DEF_OBJECT(BYTE *ptr, TPMT_SYM_DEF_OBJECT *p)
-{
-    ptr = unpack_TPMI_ALG_SYM_OBJECT(ptr, &p->algorithm);
-    ptr = unpack_TPMU_SYM_KEY_BITS(ptr, &p->keyBits, &p->algorithm);
-    ptr = unpack_TPMU_SYM_MODE(ptr, &p->mode, &p->algorithm);
-    return ptr;
-}
-
-#define pack_TPMS_SCHEME_OAEP(p, t)     pack_TPMI_ALG_HASH(p, &((t)->hashAlg))
-#define unpack_TPMS_SCHEME_OAEP(p, t)   unpack_TPMI_ALG_HASH(p, &((t)->hashAlg))
-
-inline BYTE* pack_TPMU_ASYM_SCHEME(BYTE *ptr, const TPMU_ASYM_SCHEME *p,
-                                   const TPMI_ALG_RSA_SCHEME *s)
-{
-    switch(*s) {
-#ifdef TPM2_ALG_RSASSA
-    case TPM2_ALG_RSASSA:
-        assert(false || "TPM2_ALG_RSASSA");
-        break;
-#endif
-#ifdef TPM2_ALG_OAEP
-    case TPM2_ALG_OAEP:
-        ptr = pack_TPMS_SCHEME_OAEP(ptr, &p->oaep);
-        break;
-#endif
-    case TPM2_ALG_NULL:
-        break;
-    default:
-        assert(false || "DEFAULT");
-    }
-    return ptr;
-}
-
-inline BYTE* unpack_TPMU_ASYM_SCHEME(BYTE *ptr, TPMU_ASYM_SCHEME *p,
-                                     const TPMI_ALG_RSA_SCHEME *s)
-{
-    switch(*s) {
-    #ifdef TPM2_ALG_RSASSA
-    case TPM2_ALG_RSASSA:
-        printf("not support TPM_ALG_RSASSA\n");
-        assert(false);
-        break;
-    #endif
-    #ifdef TPM2_ALG_OAEP
-    case TPM2_ALG_OAEP:
-        ptr = unpack_TPMS_SCHEME_OAEP(ptr, &p->oaep);
-        break;
-    #endif
-    case TPM2_ALG_NULL:
-        break;
-    default:
-        printf("default TPMI_ALG_RSA_SCHEME 0x%X\n", (UINT32)*s);
-        ptr = unpack_TPMI_ALG_HASH(ptr, &p->anySig.hashAlg);
-    }
-    return ptr;
-}
-
-inline BYTE* pack_TPMT_RSA_SCHEME(BYTE* ptr, const TPMT_RSA_SCHEME *p)
-{
-    ptr = pack_TPMI_ALG_RSA_SCHEME(ptr, &p->scheme);
-    ptr = pack_TPMU_ASYM_SCHEME(ptr, &p->details, &p->scheme);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMT_RSA_SCHEME(BYTE* ptr, TPMT_RSA_SCHEME *p)
-{
-    ptr = unpack_TPMI_ALG_RSA_SCHEME(ptr, &p->scheme);
-    ptr = unpack_TPMU_ASYM_SCHEME(ptr, &p->details, &p->scheme);
-    return ptr;
-}
-
-inline BYTE* pack_TPMT_RSA_DECRYPT(BYTE* ptr, const TPMT_RSA_DECRYPT *p)
-{
-    ptr = pack_TPMI_ALG_RSA_SCHEME(ptr, &p->scheme);
-    ptr = pack_TPMU_ASYM_SCHEME(ptr, &p->details, &p->scheme);
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_RSA_PARMS(BYTE* ptr, const TPMS_RSA_PARMS *p)
-{
-    ptr = pack_TPMT_SYM_DEF_OBJECT(ptr, &p->symmetric);
-    ptr = pack_TPMT_RSA_SCHEME(ptr, &p->scheme);
-    ptr = pack_TPMI_RSA_KEY_BITS(ptr, &p->keyBits);
-    ptr = pack_UINT32(ptr, p->exponent);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMS_RSA_PARMS(BYTE *ptr, TPMS_RSA_PARMS *p)
-{
-    ptr = unpack_TPMT_SYM_DEF_OBJECT(ptr, &p->symmetric);
-    ptr = unpack_TPMT_RSA_SCHEME(ptr, &p->scheme);
-    ptr = unpack_TPMI_RSA_KEY_BITS(ptr, &p->keyBits);
-    ptr = unpack_UINT32(ptr, &p->exponent);
-    return ptr;
-}
-
-inline BYTE* pack_TPMU_PUBLIC_PARMS(BYTE* ptr, const TPMU_PUBLIC_PARMS *param,
-                                    const TPMI_ALG_PUBLIC *selector)
-{
-    switch(*selector) {
-    case TPM2_ALG_KEYEDHASH:
-        assert(false);
-    case TPM2_ALG_SYMCIPHER:
-        assert(false);
-    case TPM2_ALG_RSA:
-        return pack_TPMS_RSA_PARMS(ptr, &param->rsaDetail);
-    case TPM2_ALG_ECC:
-        assert(false);
-    }
-    assert(false);
-    return NULL;
-}
-
-inline BYTE* unpack_TPMU_PUBLIC_PARMS(BYTE* ptr, TPMU_PUBLIC_PARMS *param,
-                                      const TPMI_ALG_PUBLIC *selector)
-{
-    switch(*selector) {
-    case TPM2_ALG_KEYEDHASH:
-        assert(false);
-    case TPM2_ALG_SYMCIPHER:
-        assert(false);
-    case TPM2_ALG_RSA:
-        return unpack_TPMS_RSA_PARMS(ptr, &param->rsaDetail);
-    case TPM2_ALG_ECC:
-        assert(false);
-    }
-    assert(false);
-    return NULL;
-}
-
-inline BYTE* pack_TPMS_ECC_POINT(BYTE* ptr, const TPMS_ECC_POINT *point)
-{
-    assert(false);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMS_ECC_POINT(BYTE* ptr, TPMS_ECC_POINT *point)
-{
-    assert(false);
-    return ptr;
-}
-
-inline BYTE* pack_TPMU_PUBLIC_ID(BYTE* ptr, const TPMU_PUBLIC_ID *id,
-                                 const TPMI_ALG_PUBLIC *selector)
-{
-    switch (*selector) {
-    case TPM2_ALG_KEYEDHASH:
-        return pack_TPM2B_DIGEST(ptr, &id->keyedHash);
-    case TPM2_ALG_SYMCIPHER:
-        return pack_TPM2B_DIGEST(ptr, &id->sym);
-    case TPM2_ALG_RSA:
-        return pack_TPM2B_PUBLIC_KEY_RSA(ptr, &id->rsa);
-    case TPM2_ALG_ECC:
-        return pack_TPMS_ECC_POINT(ptr, &id->ecc);
-    }
-    assert(false);
-    return NULL;
-}
-
-inline BYTE* unpack_TPMU_PUBLIC_ID(BYTE* ptr, TPMU_PUBLIC_ID *id, TPMI_ALG_PUBLIC *selector)
-{
-    switch (*selector) {
-    case TPM2_ALG_KEYEDHASH:
-        return unpack_TPM2B_DIGEST(ptr, &id->keyedHash);
-    case TPM2_ALG_SYMCIPHER:
-        return unpack_TPM2B_DIGEST(ptr, &id->sym);
-    case TPM2_ALG_RSA:
-        return unpack_TPM2B_PUBLIC_KEY_RSA(ptr, &id->rsa);
-    case TPM2_ALG_ECC:
-        return unpack_TPMS_ECC_POINT(ptr, &id->ecc);
-    }
-    assert(false);
-    return NULL;
-}
-
-inline BYTE* pack_TPMT_PUBLIC(BYTE* ptr, const TPMT_PUBLIC *public)
-{
-    ptr = pack_TPMI_ALG_PUBLIC(ptr, &public->type);
-    ptr = pack_TPMI_ALG_HASH(ptr, &public->nameAlg);
-    ptr = pack_TPMA_OBJECT(ptr, &public->objectAttributes);
-    ptr = pack_TPM2B_DIGEST(ptr, &public->authPolicy);
-    ptr = pack_TPMU_PUBLIC_PARMS(ptr, &public->parameters, &public->type);
-    ptr = pack_TPMU_PUBLIC_ID(ptr, &public->unique, &public->type);
-    return ptr;
-}
-
-inline BYTE* unpack_TPMT_PUBLIC(BYTE* ptr, TPMT_PUBLIC *public)
-{
-    ptr = unpack_TPMI_ALG_PUBLIC(ptr, &public->type);
-    ptr = unpack_TPMI_ALG_HASH(ptr, &public->nameAlg);
-    ptr = unpack_TPMA_OBJECT(ptr, &public->objectAttributes);
-    ptr = unpack_TPM2B_DIGEST(ptr, &public->authPolicy);
-    ptr = unpack_TPMU_PUBLIC_PARMS(ptr, &public->parameters, &public->type);
-    ptr = unpack_TPMU_PUBLIC_ID(ptr, &public->unique, &public->type);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2B_PUBLIC(BYTE* ptr, const TPM2B_PUBLIC *public)
-{
-    BYTE *sizePtr = ptr;
-    ptr += 2;
-    ptr = pack_TPMT_PUBLIC(ptr, &public->publicArea);
-    pack_UINT16(sizePtr, (UINT16)(ptr - sizePtr - 2));
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2B_PUBLIC(BYTE* ptr, TPM2B_PUBLIC *public)
-{
-    ptr = unpack_UINT16(ptr, &public->size);
-    ptr = unpack_TPMT_PUBLIC(ptr, &public->publicArea);
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_PCR_SELECTION(BYTE* ptr, const TPMS_PCR_SELECTION *selection)
-{
-    ptr = pack_TPMI_ALG_HASH(ptr, &selection->hash);
-    ptr = pack_BYTE(ptr, selection->sizeofSelect);
-    ptr = pack_BYTE_ARRAY(ptr, selection->pcrSelect, selection->sizeofSelect);
-    return ptr;
-}
-
-inline BYTE* pack_TPMS_PCR_SELECTION_Array(BYTE* ptr, const TPMS_PCR_SELECTION *selections,
-                                           const UINT32 cnt)
-{
-    int i;
-    for (i = 0; i < cnt; i++)
-        ptr = pack_TPMS_PCR_SELECTION(ptr, selections + i);
-    return ptr;
-}
-
-inline BYTE* pack_TPM_AuthArea(BYTE* ptr, const TPM_AuthArea *auth)
-{
-    BYTE* sizePtr = ptr;
-    ptr += sizeof(UINT32);
-    ptr = pack_TPM_RH(ptr, &auth->sessionHandle);
-    ptr = pack_TPM2B_NONCE(ptr, &auth->nonce);
-    ptr = pack_TPMA_SESSION(ptr, &auth->sessionAttributes);
-    ptr = pack_TPM2B_AUTH(ptr, &auth->auth);
-    pack_UINT32(sizePtr, ptr - sizePtr - sizeof(UINT32));
-    return ptr;
-}
-
-inline BYTE* unpack_TPM_AuthArea(BYTE* ptr, TPM_AuthArea *auth)
-{
-    ptr = unpack_UINT32(ptr, &auth->size);
-    ptr = unpack_TPM_RH(ptr, &auth->sessionHandle);
-    ptr = unpack_TPM2B_NONCE(ptr, &auth->nonce);
-    ptr = unpack_TPMA_SESSION(ptr, &auth->sessionAttributes);
-    ptr = unpack_TPM2B_AUTH(ptr, &auth->auth);
-    return ptr;
-}
-
-inline BYTE* pack_TPM2_RSA_KEY(BYTE* ptr, const TPM2_RSA_KEY *key)
-{
-    ptr = pack_TPM2B_PRIVATE(ptr, &key->Private);
-    ptr = pack_TPM2B_PUBLIC(ptr, &key->Public);
-    return ptr;
-}
-
-inline BYTE* unpack_TPM2_RSA_KEY(BYTE* ptr, TPM2_RSA_KEY *key)
-{
-    ptr = unpack_TPM2B_PRIVATE(ptr, &key->Private);
-    ptr = unpack_TPM2B_PUBLIC(ptr, &key->Public);
-    return ptr;
-}
-#endif
diff --git a/stubdom/vtpmmgr/tpm2_types.h b/stubdom/vtpmmgr/tpm2_types.h
deleted file mode 100644 (file)
index a07d8f3..0000000
+++ /dev/null
@@ -1,969 +0,0 @@
-#ifndef __TPM2_TYPES_H__
-#define __TPM2_TYPES_H__
-
-#include <stdlib.h>
-#include <stdint.h>
-#include "common_types.h"
-
-// "implementation.h"
-// Table 212 -- Logic Values
-#define    YES      1
-#define    NO       0
-#ifndef    TRUE
-#define    TRUE     1
-#endif
-#ifndef    FALSE
-#define    FALSE    0
-#endif
-#ifndef    true
-#define    true     1
-#endif
-#ifndef    false
-#define    false    0
-#endif
-#define    SET      1
-#define    CLEAR    0
-
-
-// Table 214 -- Implemented Algorithms
-#define    ALG_RSA               YES    // 1
-#define    ALG_DES               NO     // 0
-#define    ALG__3DES             NO     // 0
-#define    ALG_SHA1              YES    // 1
-#define    ALG_HMAC              YES    // 1
-#define    ALG_AES               YES    // 1
-#define    ALG_MGF1              YES    // 1
-#define    ALG_XOR               YES    // 1
-#define    ALG_KEYEDHASH         YES    // 1
-#define    ALG_SHA256            YES    // 1
-#define    ALG_SHA384            YES    // 0
-#define    ALG_SHA512            YES    // 0
-#define    ALG_WHIRLPOOL512      YES    // 0
-#define    ALG_SM3_256           YES    // 1
-#define    ALG_SM4               YES    // 1
-#define    ALG_RSASSA            YES    // 1
-#define    ALG_RSAES             YES    // 1
-#define    ALG_RSAPSS            YES    // 1
-#define    ALG_OAEP              YES    // 1
-#define    ALG_ECC               YES    // 1
-#define    ALG_CFB               YES    // 1
-#define    ALG_ECDH              YES    // 1
-#define    ALG_ECDSA             YES    // 1
-#define    ALG_ECDAA             YES    // 1
-#define    ALG_SM2               YES    // 1
-#define    ALG_ECSCHNORR         YES    // 1
-#define    ALG_SYMCIPHER         YES    // 1
-#define    ALG_KDF1_SP800_56a    YES    // 1
-#define    ALG_KDF2              NO     // 0
-#define    ALG_KDF1_SP800_108    YES    // 1
-#define    ALG_CTR               YES    // 1
-#define    ALG_OFB               YES    // 1
-#define    ALG_CBC               YES    // 1
-
-#define HASH_COUNT (ALG_SHA1+ALG_SHA256+ALG_SHA384+ALG_SHA512+ALG_WHIRLPOOL512+ALG_SM3_256)
-
-// Table 216 -- RSA Algorithm Constants
-#define    RSA_KEY_SIZES_BITS    2048    // {1024,2048}
-#define    MAX_RSA_KEY_BITS      2048
-#define    MAX_RSA_KEY_BYTES     ((MAX_RSA_KEY_BITS + 7) / 8)    // 256
-
-// Table 218 -- AES Algorithm Constants
-#define    AES_KEY_SIZES_BITS          128
-#define    MAX_AES_KEY_BITS            128
-#define    MAX_AES_BLOCK_SIZE_BYTES    16
-#define    MAX_AES_KEY_BYTES           ((MAX_AES_KEY_BITS + 7) / 8)    // 16
-
-
-// Table 220 -- Symmetric Algorithm Constants
-#define    MAX_SYM_KEY_BITS      MAX_AES_KEY_BITS    // 128
-#define    MAX_SYM_KEY_BYTES     MAX_AES_KEY_BYTES    // 16
-#define    MAX_SYM_BLOCK_SIZE    MAX_AES_BLOCK_SIZE_BYTES    // 16
-
-#define    MAX_SYM_DATA         128
-#define    MAX_ECC_KEY_BITS     256
-#define    MAX_ECC_KEY_BYTES    ((MAX_ECC_KEY_BITS + 7) / 8)
-
-// TPM2 command code
-
-typedef UINT32 TPM_CC;
-#define    TPM_CC_FIRST                         (TPM_CC)(0x0000011F)
-#define    TPM_CC_PP_FIRST                      (TPM_CC)(0x0000011F)
-#define    TPM_CC_NV_UndefineSpaceSpecial       (TPM_CC)(0x0000011F)
-#define    TPM_CC_EvictControl                  (TPM_CC)(0x00000120)
-#define    TPM_CC_HierarchyControl              (TPM_CC)(0x00000121)
-#define    TPM_CC_NV_UndefineSpace              (TPM_CC)(0x00000122)
-#define    TPM_CC_ChangeEPS                     (TPM_CC)(0x00000124)
-#define    TPM_CC_ChangePPS                     (TPM_CC)(0x00000125)
-#define    TPM_CC_Clear                         (TPM_CC)(0x00000126)
-#define    TPM_CC_ClearControl                  (TPM_CC)(0x00000127)
-#define    TPM_CC_ClockSet                      (TPM_CC)(0x00000128)
-#define    TPM_CC_HierarchyChangeAuth           (TPM_CC)(0x00000129)
-#define    TPM_CC_NV_DefineSpace                (TPM_CC)(0x0000012A)
-#define    TPM_CC_PCR_Allocate                  (TPM_CC)(0x0000012B)
-#define    TPM_CC_PCR_SetAuthPolicy             (TPM_CC)(0x0000012C)
-#define    TPM_CC_PP_Commands                   (TPM_CC)(0x0000012D)
-#define    TPM_CC_SetPrimaryPolicy              (TPM_CC)(0x0000012E)
-#define    TPM_CC_FieldUpgradeStart             (TPM_CC)(0x0000012F)
-#define    TPM_CC_ClockRateAdjust               (TPM_CC)(0x00000130)
-#define    TPM_CC_CreatePrimary                 (TPM_CC)(0x00000131)
-#define    TPM_CC_NV_GlobalWriteLock            (TPM_CC)(0x00000132)
-#define    TPM_CC_PP_LAST                       (TPM_CC)(0x00000132)
-#define    TPM_CC_GetCommandAuditDigest         (TPM_CC)(0x00000133)
-#define    TPM_CC_NV_Increment                  (TPM_CC)(0x00000134)
-#define    TPM_CC_NV_SetBits                    (TPM_CC)(0x00000135)
-#define    TPM_CC_NV_Extend                     (TPM_CC)(0x00000136)
-#define    TPM_CC_NV_Write                      (TPM_CC)(0x00000137)
-#define    TPM_CC_NV_WriteLock                  (TPM_CC)(0x00000138)
-#define    TPM_CC_DictionaryAttackLockReset     (TPM_CC)(0x00000139)
-#define    TPM_CC_DictionaryAttackParameters    (TPM_CC)(0x0000013A)
-#define    TPM_CC_NV_ChangeAuth                 (TPM_CC)(0x0000013B)
-#define    TPM_CC_PCR_Event                     (TPM_CC)(0x0000013C)
-#define    TPM_CC_PCR_Reset                     (TPM_CC)(0x0000013D)
-#define    TPM_CC_SequenceComplete              (TPM_CC)(0x0000013E)
-#define    TPM_CC_SetAlgorithmSet               (TPM_CC)(0x0000013F)
-#define    TPM_CC_SetCommandCodeAuditStatus     (TPM_CC)(0x00000140)
-#define    TPM_CC_FieldUpgradeData              (TPM_CC)(0x00000141)
-#define    TPM_CC_IncrementalSelfTest           (TPM_CC)(0x00000142)
-#define    TPM_CC_SelfTest                      (TPM_CC)(0x00000143)
-#define    TPM_CC_Startup                       (TPM_CC)(0x00000144)
-#define    TPM_CC_Shutdown                      (TPM_CC)(0x00000145)
-#define    TPM_CC_StirRandom                    (TPM_CC)(0x00000146)
-#define    TPM_CC_ActivateCredential            (TPM_CC)(0x00000147)
-#define    TPM_CC_Certify                       (TPM_CC)(0x00000148)
-#define    TPM_CC_PolicyNV                      (TPM_CC)(0x00000149)
-#define    TPM_CC_CertifyCreation               (TPM_CC)(0x0000014A)
-#define    TPM_CC_Duplicate                     (TPM_CC)(0x0000014B)
-#define    TPM_CC_GetTime                       (TPM_CC)(0x0000014C)
-#define    TPM_CC_GetSessionAuditDigest         (TPM_CC)(0x0000014D)
-#define    TPM_CC_NV_Read                       (TPM_CC)(0x0000014E)
-#define    TPM_CC_NV_ReadLock                   (TPM_CC)(0x0000014F)
-#define    TPM_CC_ObjectChangeAuth              (TPM_CC)(0x00000150)
-#define    TPM_CC_PolicySecret                  (TPM_CC)(0x00000151)
-#define    TPM_CC_Rewrap                        (TPM_CC)(0x00000152)
-#define    TPM_CC_Create                        (TPM_CC)(0x00000153)
-#define    TPM_CC_ECDH_ZGen                     (TPM_CC)(0x00000154)
-#define    TPM_CC_HMAC                          (TPM_CC)(0x00000155)
-#define    TPM_CC_Import                        (TPM_CC)(0x00000156)
-#define    TPM_CC_Load                          (TPM_CC)(0x00000157)
-#define    TPM_CC_Quote                         (TPM_CC)(0x00000158)
-#define    TPM_CC_RSA_Decrypt                   (TPM_CC)(0x00000159)
-#define    TPM_CC_HMAC_Start                    (TPM_CC)(0x0000015B)
-#define    TPM_CC_SequenceUpdate                (TPM_CC)(0x0000015C)
-#define    TPM_CC_Sign                          (TPM_CC)(0x0000015D)
-#define    TPM_CC_Unseal                        (TPM_CC)(0x0000015E)
-#define    TPM_CC_PolicySigned                  (TPM_CC)(0x00000160)
-#define    TPM_CC_ContextLoad                   (TPM_CC)(0x00000161)
-#define    TPM_CC_ContextSave                   (TPM_CC)(0x00000162)
-#define    TPM_CC_ECDH_KeyGen                   (TPM_CC)(0x00000163)
-#define    TPM_CC_EncryptDecrypt                (TPM_CC)(0x00000164)
-#define    TPM_CC_FlushContext                  (TPM_CC)(0x00000165)
-#define    TPM_CC_LoadExternal                  (TPM_CC)(0x00000167)
-#define    TPM_CC_MakeCredential                (TPM_CC)(0x00000168)
-#define    TPM_CC_NV_ReadPublic                 (TPM_CC)(0x00000169)
-#define    TPM_CC_PolicyAuthorize               (TPM_CC)(0x0000016A)
-#define    TPM_CC_PolicyAuthValue               (TPM_CC)(0x0000016B)
-#define    TPM_CC_PolicyCommandCode             (TPM_CC)(0x0000016C)
-#define    TPM_CC_PolicyCounterTimer            (TPM_CC)(0x0000016D)
-#define    TPM_CC_PolicyCpHash                  (TPM_CC)(0x0000016E)
-#define    TPM_CC_PolicyLocality                (TPM_CC)(0x0000016F)
-#define    TPM_CC_PolicyNameHash                (TPM_CC)(0x00000170)
-#define    TPM_CC_PolicyOR                      (TPM_CC)(0x00000171)
-#define    TPM_CC_PolicyTicket                  (TPM_CC)(0x00000172)
-#define    TPM_CC_ReadPublic                    (TPM_CC)(0x00000173)
-#define    TPM_CC_RSA_Encrypt                   (TPM_CC)(0x00000174)
-#define    TPM_CC_StartAuthSession              (TPM_CC)(0x00000176)
-#define    TPM_CC_VerifySignature               (TPM_CC)(0x00000177)
-#define    TPM_CC_ECC_Parameters                (TPM_CC)(0x00000178)
-#define    TPM_CC_FirmwareRead                  (TPM_CC)(0x00000179)
-#define    TPM_CC_GetCapability                 (TPM_CC)(0x0000017A)
-#define    TPM_CC_GetRandom                     (TPM_CC)(0x0000017B)
-#define    TPM_CC_GetTestResult                 (TPM_CC)(0x0000017C)
-#define    TPM_CC_Hash                          (TPM_CC)(0x0000017D)
-#define    TPM_CC_PCR_Read                      (TPM_CC)(0x0000017E)
-#define    TPM_CC_PolicyPCR                     (TPM_CC)(0x0000017F)
-#define    TPM_CC_PolicyRestart                 (TPM_CC)(0x00000180)
-#define    TPM_CC_ReadClock                     (TPM_CC)(0x00000181)
-#define    TPM_CC_PCR_Extend                    (TPM_CC)(0x00000182)
-#define    TPM_CC_PCR_SetAuthValue              (TPM_CC)(0x00000183)
-#define    TPM_CC_NV_Certify                    (TPM_CC)(0x00000184)
-#define    TPM_CC_EventSequenceComplete         (TPM_CC)(0x00000185)
-#define    TPM_CC_HashSequenceStart             (TPM_CC)(0x00000186)
-#define    TPM_CC_PolicyPhysicalPresence        (TPM_CC)(0x00000187)
-#define    TPM_CC_PolicyDuplicationSelect       (TPM_CC)(0x00000188)
-#define    TPM_CC_PolicyGetDigest               (TPM_CC)(0x00000189)
-#define    TPM_CC_TestParms                     (TPM_CC)(0x0000018A)
-#define    TPM_CC_Commit                        (TPM_CC)(0x0000018B)
-#define    TPM_CC_PolicyPassword                (TPM_CC)(0x0000018C)
-#define    TPM_CC_SM2_ZGen                      (TPM_CC)(0x0000018D)
-#define    TPM_CC_LAST                          (TPM_CC)(0x0000018D)
-
-
-//TPM_RC
-typedef UINT32 TPM_RC;
-
-// TPM_ST Constants
-typedef UINT16 TPM_ST;
-#define    TPM_ST_NULL                    (TPM_ST)(0X8000)
-#define    TPM_ST_NO_SESSIONS             (TPM_ST)(0x8001)
-#define    TPM_ST_SESSIONS                (TPM_ST)(0x8002)
-
-
-// TPM Handle types
-typedef UINT32 TPM2_HANDLE;
-typedef UINT8 TPM_HT;
-
-
-// TPM_RH Constants
-typedef UINT32 TPM_RH;
-
-#define    TPM_RH_FIRST          (TPM_RH)(0x40000000)
-#define    TPM_RH_SRK            (TPM_RH)(0x40000000)
-#define    TPM_RH_OWNER          (TPM_RH)(0x40000001)
-#define    TPM_RS_PW             (TPM_RH)(0x40000009)
-#define    TPM_RH_LOCKOUT        (TPM_RH)(0x4000000A)
-#define    TPM_RH_ENDORSEMENT    (TPM_RH)(0x4000000B)
-#define    TPM_RH_PLATFORM       (TPM_RH)(0x4000000C)
-#define    TPM_RH_LAST           (TPM_RH)(0x4000000C)
-
-// Table 4 -- DocumentationClarity Types <I/O>
-typedef UINT32    TPM_MODIFIER_INDICATOR;
-typedef UINT32    TPM_SESSION_OFFSET;
-typedef UINT16    TPM_KEY_SIZE;
-typedef UINT16    TPM_KEY_BITS;
-typedef UINT64    TPM_SYSTEM_ADDRESS;
-typedef UINT32    TPM_SPEC;
-
-// Table 29 -- TPMA_ALGORITHM Bits <I/O>
-typedef struct {
-    unsigned int asymmetric:1;
-    unsigned int symmetric:1;
-    unsigned int hash:1;
-    unsigned int object:1;
-    unsigned int reserved5:4;
-    unsigned int signing:1;
-    unsigned int encrypting:1;
-    unsigned int method:1;
-    unsigned int reserved9:21;
-} TPMA_ALGORITHM;
-
-typedef UINT32 TPMA_OBJECT;
-typedef BYTE TPMA_SESSION;
-typedef BYTE TPMA_LOCALITY;
-
-// Table 37 -- TPMI_YES_NO Type <I/O>
-typedef BYTE TPMI_YES_NO;
-
-// Table 38 -- TPMI_DH_OBJECT Type <I/O>
-typedef TPM2_HANDLE TPMI_DH_OBJECT;
-
-// Table 39 -- TPMI_DH_PERSISTENT Type <I/O>
-typedef TPM2_HANDLE TPMI_DH_PERSISTENT;
-
-// Table 42 -- TPMI_SH_AUTH_SESSION Type <I/O>
-typedef TPM2_HANDLE TPMI_SH_AUTH_SESSION;
-
-// Table 40 -- TPMI_DH_ENTITY Type <I>
-typedef TPM2_HANDLE TPMI_DH_ENTITY;
-
-// Table 45 -- TPMI_DH_CONTEXT Type <I/O>
-typedef TPM2_HANDLE TPMI_DH_CONTEXT;
-
-// Table 46 -- TPMI_RH_HIERARCHY Type <I/O>
-typedef TPM2_HANDLE TPMI_RH_HIERARCHY;
-
-// Table 47 -- TPM2I_RH_HIERARCHY_AUTH Type <I>
-typedef TPM2_HANDLE TPM2I_RH_HIERARCHY_AUTH;
-
-// Table 48 -- TPMI_RH_PLATFORM Type <I>
-typedef TPM2_HANDLE TPMI_RH_PLATFORM;
-
-// Table 49 -- TPMI_RH_OWNER Type <I>
-typedef TPM2_HANDLE TPMI_RH_OWNER;
-
-// Table 50 -- TPMI_RH_ENDORSEMENT Type <I>
-typedef TPM2_HANDLE TPMI_RH_ENDORSEMENT;
-
-// Table 51 -- TPMI_RH_PROVISION Type <I>
-typedef TPM2_HANDLE TPMI_RH_PROVISION;
-
-// Table 52 -- TPMI_RH_CLEAR Type <I>
-typedef TPM2_HANDLE TPMI_RH_CLEAR;
-
-// Table 54 -- TPMI_RH_LOCKOUT Type <I>
-typedef TPM2_HANDLE TPMI_RH_LOCKOUT;
-
-// Table 7 -- TPM_ALG_ID
-typedef UINT16 TPM_ALG_ID;
-
-#define    TPM2_ALG_ERROR             (TPM_ALG_ID)(0x0000) // a: ; D:
-#define    TPM2_ALG_FIRST             (TPM_ALG_ID)(0x0001) // a: ; D:
-#if ALG_RSA == YES || ALG_ALL == YES
-#define    TPM2_ALG_RSA               (TPM_ALG_ID)(0x0001) // a: A O; D:
-#endif
-#if ALG_DES == YES || ALG_ALL == YES
-#define    TPM2_ALG_DES               (TPM_ALG_ID)(0x0002) // a: S; D:
-#endif
-#define    TPM2_ALG_SHA1              (TPM_ALG_ID)(0x0004) // a: H; D:
-#if ALG_HMAC == YES || ALG_ALL == YES
-#define    TPM2_ALG_HMAC              (TPM_ALG_ID)(0x0005) // a: H X; D:
-#endif
-#if ALG_AES == YES || ALG_ALL == YES
-#define    TPM2_ALG_AES               (TPM_ALG_ID)(0x0006) // a: S; D:
-#endif
-#if ALG_XOR == YES || ALG_ALL == YES
-#define    TPM2_ALG_XOR               (TPM_ALG_ID)(0x000A) // a: H S; D:
-#endif
-#if ALG_MGF1 == YES || ALG_ALL == YES
-#define    TPM2_ALG_MGF1              (TPM_ALG_ID)(0x0007) // a: H M; D:
-#endif
-#if ALG_KEYEDHASH == YES || ALG_ALL == YES
-#define    TPM2_ALG_KEYEDHASH         (TPM_ALG_ID)(0x0008) // a: H E X O; D:
-#endif
-#if ALG_SHA256 == YES || ALG_ALL == YES
-#define    TPM2_ALG_SHA256            (TPM_ALG_ID)(0x000B) // a: H; D:
-#endif
-#define    TPM2_ALG_NULL              (TPM_ALG_ID)(0x0010) // a: ; D:
-#if ALG_OAEP == YES || ALG_ALL == YES
-#define    TPM2_ALG_OAEP              (TPM_ALG_ID)(0x0017) // a: A E; D: RSA
-#endif
-#if ALG_ECC == YES || ALG_ALL == YES
-#define    TPM2_ALG_ECC               (TPM_ALG_ID)(0x0023) // a: A O; D:
-#endif
-#if ALG_SM4 == YES || ALG_ALL == YES
-#define    TPM2_ALG_SM4               (TPM_ALG_ID)(0x0013) // a: S; D:
-#endif
-#if ALG_SYMCIPHER == YES || ALG_ALL == YES
-#define    TPM2_ALG_SYMCIPHER         (TPM_ALG_ID)(0x0025) // a: O; D:
-#endif
-#if ALG_CFB == YES || ALG_ALL == YES
-#define    TPM2_ALG_CFB               (TPM_ALG_ID)(0x0043) // a: S E; D:
-#endif
-#define    TPM2_ALG_LAST              (TPM_ALG_ID)(0x0044)
-
-#define    SHA1_DIGEST_SIZE      20
-#define    SHA1_BLOCK_SIZE       64
-#define    SHA256_DIGEST_SIZE    32
-#define    SHA256_BLOCK_SIZE     64
-
-// Table 57 -- TPMI_ALG_ASYM Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_ASYM;
-
-// Table 56 -- TPMI_ALG_HASH Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_HASH;
-
-// Table 58 -- TPMI_ALG_SYM Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_SYM;
-
-// Table 59 -- TPMI_ALG_SYM_OBJECT Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_SYM_OBJECT;
-
-// Table 60 -- TPMI_ALG_SYM_MODE Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_SYM_MODE;
-
-// Table 61 -- TPMI_ALG_KDF Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_KDF;
-
-// Table 62 -- TPMI_ALG_SIG_SCHEME Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_SIG_SCHEME;
-
-// Table 65 -- TPMU_HA Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_SHA1
-    BYTE  sha1[SHA1_DIGEST_SIZE];
-#endif
-#ifdef TPM2_ALG_SHA256
-    BYTE  sha256[SHA256_DIGEST_SIZE];
-#endif
-#ifdef TPM2_ALG_SM3_256
-    BYTE  sm3_256[SM3_256_DIGEST_SIZE];
-#endif
-#ifdef TPM2_ALG_SHA384
-    BYTE  sha384[SHA384_DIGEST_SIZE];
-#endif
-#ifdef TPM2_ALG_SHA512
-    BYTE  sha512[SHA512_DIGEST_SIZE];
-#endif
-#ifdef TPM2_ALG_WHIRLPOOL512
-    BYTE  whirlpool[WHIRLPOOL512_DIGEST_SIZE];
-#endif
-
-} TPMU_HA;
-
-// Table 67 -- TPM2B_DIGEST Structure <I/O>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[sizeof(TPMU_HA)];
-} TPM2B_DIGEST;
-
-// Table 69 -- TPM2B_NONCE Types <I/O>
-typedef TPM2B_DIGEST    TPM2B_NONCE;
-
-typedef TPM2B_DIGEST    TPM2B_DATA;
-
-// Table 70 -- TPM2B_AUTH Types <I/O>
-typedef TPM2B_DIGEST    TPM2B_AUTH;
-
-// Table 71 -- TPM2B_OPERAND Types <I/O>
-typedef TPM2B_DIGEST    TPM2B_OPERAND;
-
-// Table 66 -- TPMT_HA Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-    TPMU_HA          digest;
-} TPMT_HA;
-
-//Table 80 -- TPM2B_NAME Structure
-typedef struct {
-    UINT16 size;
-    BYTE name[sizeof(TPMT_HA)];
-} TPM2B_NAME;
-
-#define    IMPLEMENTATION_PCR   24
-#define    PLATFORM_PCR         24
-#define    PCR_SELECT_MAX       ((IMPLEMENTATION_PCR+7)/8)
-#define    PCR_SELECT_NUM(x)    (uint8_t)(x/8)
-#define    PCR_SELECT_VALUE(x)  (uint8_t)(0x1)<<(x%8)
-
-//Table 79 -- TPMS_PCR_SELECT Structure <I/O>
-typedef struct {
-    UINT8    sizeofSelect;
-    BYTE     pcrSelect[PCR_SELECT_MAX];
-} TPMS_PCR_SELECT;
-
-// Table 80 -- TPMS_PCR_SELECTION Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hash;
-    UINT8            sizeofSelect;
-    BYTE             pcrSelect[PCR_SELECT_MAX];
-} TPMS_PCR_SELECTION;
-
-// Table 83 -- TPMT_TK_CREATION Structure <I/O>
-typedef struct {
-    TPM_ST               tag;
-    TPMI_RH_HIERARCHY    hierarchy;
-    TPM2B_DIGEST         digest;
-} TPMT_TK_CREATION;
-
-// Table 96 -- Definition of TPML_DIGEST Structure <I/O>
-typedef struct {
-    UINT32               count;
-    TPM2B_DIGEST         digests[8];
-}TPML_DIGEST;
-
-// Table 97 -- TPML_PCR_SELECTION Structure <I/O>
-typedef struct {
-    UINT32                count;
-    TPMS_PCR_SELECTION    pcrSelections[HASH_COUNT];
-} TPML_PCR_SELECTION;
-
-// Table 119 -- TPMI_AES_KEY_BITS Type <I/O>
-typedef TPM_KEY_BITS TPMI_AES_KEY_BITS;
-
-// Table 120 -- TPMI_SM4_KEY_BITS Type <I/O>
-typedef TPM_KEY_BITS TPMI_SM4_KEY_BITS;
-
-// Table 121 -- TPMU_SYM_KEY_BITS Union <I/O>
-typedef union {
-#ifdef TPM2_ALG_AES
-    TPMI_AES_KEY_BITS  aes;
-#endif
-#ifdef TPM2_ALG_SM4
-    TPMI_SM4_KEY_BITS  SM4;
-#endif
-    TPM_KEY_BITS  sym;
-#ifdef TPM2_ALG_XOR
-    TPMI_ALG_HASH  xor;
-#endif
-
-} TPMU_SYM_KEY_BITS;
-
-// Table 122 -- TPMU_SYM_MODE Union <I/O>
-typedef union {
-#ifdef TPM2_ALG_AES
-    TPMI_ALG_SYM_MODE  aes;
-#endif
-#ifdef TPM2_ALG_SM4
-    TPMI_ALG_SYM_MODE  SM4;
-#endif
-    TPMI_ALG_SYM_MODE  sym;
-} TPMU_SYM_MODE ;
-
-// Table 124 -- TPMT_SYM_DEF Structure <I/O>
-typedef struct {
-    TPMI_ALG_SYM         algorithm;
-    TPMU_SYM_KEY_BITS    keyBits;
-    TPMU_SYM_MODE        mode;
-} TPMT_SYM_DEF;
-
-// Table 125 -- TPMT_SYM_DEF_OBJECT Structure <I/O>
-typedef struct {
-    TPMI_ALG_SYM_OBJECT    algorithm;
-    TPMU_SYM_KEY_BITS      keyBits;
-    TPMU_SYM_MODE          mode;
-} TPMT_SYM_DEF_OBJECT;
-
-// Table 126 -- TPM2B_SYM_KEY Structure <I/O>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[MAX_SYM_KEY_BYTES];
-} TPM2B_SYM_KEY;
-
-// Table 127 -- TPMS_SYMCIPHER_PARMS Structure <I/O>
-typedef struct {
-    TPMT_SYM_DEF_OBJECT    sym;
-} TPMS_SYMCIPHER_PARMS;
-
-// Table 128 -- TPM2B_SENSITIVE_DATA Structure <I/O>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[MAX_SYM_DATA];
-} TPM2B_SENSITIVE_DATA;
-
-// Table 129 -- TPMS_SENSITIVE_CREATE Structure <I>
-typedef struct {
-    TPM2B_AUTH              userAuth;
-    TPM2B_SENSITIVE_DATA    data;
-} TPMS_SENSITIVE_CREATE;
-
-// Table 130 -- TPM2B_SENSITIVE_CREATE Structure <I,S>
-typedef struct {
-    UINT16                   size;
-    TPMS_SENSITIVE_CREATE    sensitive;
-} TPM2B_SENSITIVE_CREATE;
-
-// Table 131 -- TPMS_SCHEME_SIGHASH Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_SIGHASH;
-
-// Table 132 -- TPMI_ALG_KEYEDHASH_SCHEME Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_KEYEDHASH_SCHEME;
-
-// Table 133 -- HMAC_SIG_SCHEME Types <I/O>
-typedef TPMS_SCHEME_SIGHASH    TPMS_SCHEME_HMAC;
-
-// Table 134 -- TPMS_SCHEME_XOR Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-    TPMI_ALG_KDF     kdf;
-} TPMS_SCHEME_XOR;
-
-// Table 135 -- TPMU_SCHEME_KEYEDHASH Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_HMAC
-    TPMS_SCHEME_HMAC  hmac;
-#endif
-#ifdef TPM2_ALG_XOR
-    TPMS_SCHEME_XOR  xor;
-#endif
-
-} TPMU_SCHEME_KEYEDHASH ;
-
-// Table 136 -- TPMT_KEYEDHASH_SCHEME Structure <I/O>
-typedef struct {
-    TPMI_ALG_KEYEDHASH_SCHEME    scheme;
-    TPMU_SCHEME_KEYEDHASH        details;
-} TPMT_KEYEDHASH_SCHEME;
-
-// Table 137 -- RSA_SIG_SCHEMES Types <I/O>
-typedef TPMS_SCHEME_SIGHASH    TPMS_SCHEME_RSASSA;
-typedef TPMS_SCHEME_SIGHASH    TPMS_SCHEME_RSAPSS;
-
-// Table 138 -- ECC_SIG_SCHEMES Types <I/O>
-typedef TPMS_SCHEME_SIGHASH    TPMS_SCHEME_ECDSA;
-typedef TPMS_SCHEME_SIGHASH    TPMS_SCHEME_SM2;
-
-// Table 139 -- TPMS_SCHEME_ECDAA Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-    UINT16           count;
-} TPMS_SCHEME_ECDAA;
-
-// Table 140 -- TPMS_SCHEME_ECSCHNORR Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-    UINT16           count;
-} TPMS_SCHEME_ECSCHNORR;
-
-// Table 141 -- TPMU_SIG_SCHEME Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_RSASSA
-    TPMS_SCHEME_RSASSA  rsassa;
-#endif
-#ifdef TPM2_ALG_RSAPSS
-    TPMS_SCHEME_RSAPSS  rsapss;
-#endif
-#ifdef TPM2_ALG_ECDSA
-    TPMS_SCHEME_ECDSA  ecdsa;
-#endif
-#ifdef TPM2_ALG_SM2
-    TPMS_SCHEME_SM2  sm2;
-#endif
-#ifdef TPM2_ALG_ECDAA
-    TPMS_SCHEME_ECDAA  ecdaa;
-#endif
-#ifdef TPM2_ALG_ECSCHNORR
-    TPMS_SCHEME_ECSCHNORR  ecSchnorr;
-#endif
-#ifdef TPM2_ALG_HMAC
-    TPMS_SCHEME_HMAC  hmac;
-#endif
-    TPMS_SCHEME_SIGHASH  any;
-} TPMU_SIG_SCHEME;
-
-// Table 142 -- TPMT_SIG_SCHEME Structure <I/O>
-typedef struct {
-    TPMI_ALG_SIG_SCHEME    scheme;
-    TPMU_SIG_SCHEME        details;
-} TPMT_SIG_SCHEME;
-
-// Table 143 -- TPMS_SCHEME_OAEP Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_OAEP;
-
-// Table 144 -- TPMS_SCHEME_ECDH Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_ECDH;
-
-// Table 145 -- TPMS_SCHEME_MGF1 Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_MGF1;
-
-// Table 146 -- TPMS_SCHEME_KDF1_SP800_56a Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_KDF1_SP800_56a;
-
-// Table 147 -- TPMS_SCHEME_KDF2 Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_KDF2;
-
-// Table 148 -- TPMS_SCHEME_KDF1_SP800_108 Structure <I/O>
-typedef struct {
-    TPMI_ALG_HASH    hashAlg;
-} TPMS_SCHEME_KDF1_SP800_108;
-
-// Table 149 -- TPMU_KDF_SCHEME Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_MGF1
-    TPMS_SCHEME_MGF1  mgf1;
-#endif
-#ifdef TPM2_ALG_KDF1_SP800_56a
-    TPMS_SCHEME_KDF1_SP800_56a  kdf1_SP800_56a;
-#endif
-#ifdef TPM2_ALG_KDF2
-    TPMS_SCHEME_KDF2  kdf2;
-#endif
-#ifdef TPM2_ALG_KDF1_SP800_108
-    TPMS_SCHEME_KDF1_SP800_108  kdf1_sp800_108;
-#endif
-
-} TPMU_KDF_SCHEME;
-
-// Table 150 -- TPMT_KDF_SCHEME Structure <I/O>
-typedef struct {
-    TPMI_ALG_KDF       scheme;
-    TPMU_KDF_SCHEME    details;
-} TPMT_KDF_SCHEME;
-typedef TPM_ALG_ID TPMI_ALG_ASYM_SCHEME;
-
-// Table 152 -- TPMU_ASYM_SCHEME Union <I/O>
-typedef union {
-#ifdef TPM2_ALG_RSASSA
-    TPMS_SCHEME_RSASSA  rsassa;
-#endif
-#ifdef TPM2_ALG_RSAPSS
-    TPMS_SCHEME_RSAPSS  rsapss;
-#endif
-#ifdef TPM2_ALG_OAEP
-    TPMS_SCHEME_OAEP  oaep;
-#endif
-#ifdef TPM2_ALG_ECDSA
-    TPMS_SCHEME_ECDSA  ecdsa;
-#endif
-#ifdef TPM2_ALG_SM2
-    TPMS_SCHEME_SM2  sm2;
-#endif
-#ifdef TPM2_ALG_ECDAA
-    TPMS_SCHEME_ECDAA  ecdaa;
-#endif
-#ifdef TPM2_ALG_ECSCHNORR
-    TPMS_SCHEME_ECSCHNORR  ecSchnorr;
-#endif
-    TPMS_SCHEME_SIGHASH  anySig;
-} TPMU_ASYM_SCHEME;
-
-typedef struct {
-    TPMI_ALG_ASYM_SCHEME    scheme;
-    TPMU_ASYM_SCHEME        details;
-} TPMT_ASYM_SCHEME;
-
-// Table 154 -- TPMI_ALG_RSA_SCHEME Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_RSA_SCHEME;
-
-// Table 155 -- TPMT_RSA_SCHEME Structure <I/O>
-typedef struct {
-    TPMI_ALG_RSA_SCHEME    scheme;
-    TPMU_ASYM_SCHEME       details;
-} TPMT_RSA_SCHEME;
-
-// Table 156 -- TPMI_ALG_RSA_DECRYPT Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_RSA_DECRYPT;
-
-// Table 157 -- TPMT_RSA_DECRYPT Structure <I/O>
-typedef struct {
-    TPMI_ALG_RSA_DECRYPT    scheme;
-    TPMU_ASYM_SCHEME        details;
-} TPMT_RSA_DECRYPT;
-
-// Table 158 -- TPM2B_PUBLIC_KEY_RSA Structure <I/O>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[MAX_RSA_KEY_BYTES];
-} TPM2B_PUBLIC_KEY_RSA;
-
-// Table 159 -- TPMI_RSA_KEY_BITS Type <I/O>
-typedef TPM_KEY_BITS TPMI_RSA_KEY_BITS;
-
-// Table 160 -- TPM2B_PRIVATE_KEY_RSA Structure <I/O>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[MAX_RSA_KEY_BYTES/2];
-} TPM2B_PRIVATE_KEY_RSA;
-
-// Table 162 -- TPM2B_ECC_PARAMETER
-typedef struct {
-    UINT16 size;
-    BYTE buffer[MAX_ECC_KEY_BYTES];
-} TPM2B_ECC_PARAMETER;
-
-// Table 163 -- TPMS_ECC_POINT Structure <I/O>
-typedef struct {
-    TPM2B_ECC_PARAMETER    x;
-    TPM2B_ECC_PARAMETER    y;
-} TPMS_ECC_POINT;
-
-// Table 164 -- TPMI_ALG_ECC_SCHEME Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_ECC_SCHEME;
-
-typedef UINT16 TPM_ECC_CURVE;
-
-// Table 165 -- TPMI_ECC_CURVE Type <I/O>
-typedef TPM_ECC_CURVE TPMI_ECC_CURVE;
-
-// Table 166 -- TPMT_ECC_SCHEME Structure <I/O>
-typedef struct {
-    TPMI_ALG_ECC_SCHEME    scheme;
-    TPMU_SIG_SCHEME        details;
-} TPMT_ECC_SCHEME;
-
-// Table 175 -- TPMI_ALG_PUBLIC Type <I/O>
-typedef TPM_ALG_ID TPMI_ALG_PUBLIC;
-
-// Table 176 -- TPMU_PUBLIC_ID Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_KEYEDHASH
-    TPM2B_DIGEST  keyedHash;
-#endif
-#ifdef TPM2_ALG_SYMCIPHER
-    TPM2B_DIGEST  sym;
-#endif
-#ifdef TPM2_ALG_RSA
-    TPM2B_PUBLIC_KEY_RSA  rsa;
-#endif
-#ifdef TPM2_ALG_ECC
-    TPMS_ECC_POINT  ecc;
-#endif
-} TPMU_PUBLIC_ID;
-
-// Table 177 -- TPMS_KEYEDHASH_PARMS Structure <I/O>
-typedef struct {
-    TPMT_KEYEDHASH_SCHEME    scheme;
-} TPMS_KEYEDHASH_PARMS;
-typedef struct {
-    TPMT_SYM_DEF_OBJECT    symmetric;
-    TPMT_ASYM_SCHEME       scheme;
-} TPMS_ASYM_PARMS;
-
-// Table 179 -- TPMS_RSA_PARMS Structure <I/O>
-typedef struct {
-    TPMT_SYM_DEF_OBJECT    symmetric;
-    TPMT_RSA_SCHEME        scheme;
-    TPMI_RSA_KEY_BITS      keyBits;
-    UINT32                 exponent;
-} TPMS_RSA_PARMS;
-
-// Table 180 -- TPMS_ECC_PARMS Structure <I/O>
-typedef struct {
-    TPMT_SYM_DEF_OBJECT    symmetric;
-    TPMT_ECC_SCHEME        scheme;
-    TPMI_ECC_CURVE         curveID;
-    TPMT_KDF_SCHEME        kdf;
-} TPMS_ECC_PARMS;
-
-// Table 181 -- TPMU_PUBLIC_PARMS Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_KEYEDHASH
-    TPMS_KEYEDHASH_PARMS  keyedHashDetail;
-#endif
-#ifdef TPM2_ALG_SYMCIPHER
-    TPMT_SYM_DEF_OBJECT  symDetail;
-#endif
-#ifdef TPM2_ALG_RSA
-    TPMS_RSA_PARMS  rsaDetail;
-#endif
-#ifdef TPM2_ALG_ECC
-    TPMS_ECC_PARMS  eccDetail;
-#endif
-    TPMS_ASYM_PARMS  asymDetail;
-} TPMU_PUBLIC_PARMS;
-
-// Table 182 -- TPMT_PUBLIC_PARMS Structure <I/O>
-typedef struct {
-    TPMI_ALG_PUBLIC      type;
-    TPMU_PUBLIC_PARMS    parameters;
-} TPMT_PUBLIC_PARMS;
-
-// Table 183 -- TPMT_PUBLIC Structure <I/O>
-typedef struct {
-    TPMI_ALG_PUBLIC      type;
-    TPMI_ALG_HASH        nameAlg;
-    TPMA_OBJECT          objectAttributes;
-    TPM2B_DIGEST         authPolicy;
-    TPMU_PUBLIC_PARMS    parameters;
-    TPMU_PUBLIC_ID       unique;
-} TPMT_PUBLIC;
-
-// Table 184 -- TPM2B_PUBLIC
-typedef struct {
-    UINT16         size;
-    TPMT_PUBLIC    publicArea;
-} TPM2B_PUBLIC;
-
-// Table 185 -- TPMU_SENSITIVE_COMPOSITE Union <I/O,S>
-typedef union {
-#ifdef TPM2_ALG_RSA
-    TPM2B_PRIVATE_KEY_RSA  rsa;
-#endif
-#ifdef TPM2_ALG_ECC
-    TPM2B_ECC_PARAMETER  ecc;
-#endif
-#ifdef TPM2_ALG_KEYEDHASH
-    TPM2B_SENSITIVE_DATA  bits;
-#endif
-#ifdef TPM2_ALG_SYMCIPHER
-    TPM2B_SYM_KEY  sym;
-#endif
-    TPM2B_SENSITIVE_DATA  any;
-} TPMU_SENSITIVE_COMPOSITE;
-
-// Table 186 -- TPMT_SENSITIVE Structure <I/O>
-typedef struct {
-    TPMI_ALG_PUBLIC             sensitiveType;
-    TPM2B_AUTH                  authValue;
-    TPM2B_DIGEST                seedValue;
-    TPMU_SENSITIVE_COMPOSITE    sensitive;
-} TPMT_SENSITIVE;
-
-// Table 187 -- TPM2B_SENSITIVE Structure <I/O>
-typedef struct {
-    UINT16            size;
-    TPMT_SENSITIVE    sensitiveArea;
-} TPM2B_SENSITIVE;
-
-typedef struct {
-    TPM2B_DIGEST      integrityOuter;
-    TPM2B_DIGEST      integrityInner;
-    TPMT_SENSITIVE    sensitive;
-} _PRIVATE;
-
-// Table 189 -- TPM2B_PRIVATE Structure <I/O,S>
-typedef struct {
-    UINT16    size;
-    BYTE      buffer[sizeof(_PRIVATE)];
-} TPM2B_PRIVATE;
-
-// Table 204 -- TPMS_CREATION_DATA <OUT>
-typedef struct {
-    TPML_PCR_SELECTION    pcrSelect;
-    TPM2B_DIGEST          pcrDigest;
-    TPMA_LOCALITY         locality;
-    TPM_ALG_ID            parentNameAlg;
-    TPM2B_NAME            parentName;
-    TPM2B_NAME            parentQualifiedName;
-    TPM2B_DATA            outsideInfo;
-} TPMS_CREATION_DATA;
-
-// Table 205 -- TPM2B_CREATION_DATA <OUT>
-typedef struct {
-    UINT16 size;
-    TPMS_CREATION_DATA creationData;
-} TPM2B_CREATION_DATA;
-
-/* the following structs is not part of standard struct defined in TPM2 spec */
-typedef struct {
-    UINT32            size;
-    TPM_RH            sessionHandle;
-    TPM2B_NONCE       nonce;
-    TPMA_SESSION      sessionAttributes;
-    TPM2B_AUTH        auth;
-} TPM_AuthArea;
-
-typedef struct {
-    TPM2B_SENSITIVE_CREATE  inSensitive;
-    TPM2B_PUBLIC            inPublic;
-    TPM2B_DATA              outsideInfo;
-    TPML_PCR_SELECTION      creationPCR;
-} TPM2_Create_Params_in;
-
-typedef TPM2_Create_Params_in    TPM2_CreatePrimary_Params_in;
-
-typedef struct {
-    TPM2B_PUBLIC        outPublic;
-    TPM2B_CREATION_DATA creationData;
-    TPM2B_DIGEST        creationHash;
-    TPMT_TK_CREATION    creationTicket;
-    TPM2B_NAME          name;
-} TPM2_CreatePrimary_Params_out;
-
-typedef struct {
-    TPM2B_PRIVATE       outPrivate;
-    TPM2B_PUBLIC        outPublic;
-    TPM2B_CREATION_DATA creationData;
-    TPM2B_DIGEST        creationHash;
-    TPMT_TK_CREATION    creationTicket;
-} TPM2_Create_Params_out;
-typedef struct {
-    TPM2B_PRIVATE    Private;
-    TPM2B_PUBLIC     Public;
-} TPM2_RSA_KEY;
-
-/*
- * TPM 2.0 Objects
- */
-
-#define TPM_HT_TRANSIENT        0x80
-#define HR_SHIFT                24
-#define HR_PERMANENT            (TPM_HT_TRANSIENT << HR_SHIFT)
-#define TRANSIENT_FIRST         (HR_PERMANENT)
-#define MAX_LOADED_OBJECTS      3
-#define TRANSIENT_LAST          (TRANSIENT_FIRST+MAX_LOADED_OBJECTS-1)
-/*
- * TPMA_OBJECT Bits
- */
-#define fixedTPM                ((1 << 1))
-#define stClear                 ((1 << 2))
-#define fixedParent             ((1 << 4))
-#define sensitiveDataOrigin     ((1 << 5))
-#define userWithAuth            ((1 << 6))
-#define adminWithPolicy         ((1 << 7))
-#define noDA                    ((1 << 10))
-#define encryptedDuplication    ((1 << 11))
-#define restricted              ((1 << 16))
-#define decrypt                 ((1 << 17))
-#define sign                    ((1 << 18))
-#endif
diff --git a/stubdom/vtpmmgr/tpmrsa.c b/stubdom/vtpmmgr/tpmrsa.c
deleted file mode 100644 (file)
index b18a5a3..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- *  The RSA public-key cryptosystem
- *
- *  Copyright (C) 2006-2011, Brainspark B.V.
- *
- *  This file is part of PolarSSL (http://www.polarssl.org)
- *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- *  All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; If not, see <http://www.gnu.org/licenses/>.
- */
-/*
- *  RSA was designed by Ron Rivest, Adi Shamir and Len Adleman.
- *
- *  http://theory.lcs.mit.edu/~rivest/rsapaper.pdf
- *  http://www.cacr.math.uwaterloo.ca/hac/about/chap8.pdf
- */
-
-#include "tcg.h"
-#include "polarssl/sha1.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "tpmrsa.h"
-
-#define HASH_LEN 20
-
-void tpmrsa_set_pubkey(tpmrsa_context* ctx,
-      const unsigned char* key,
-      int keylen,
-      const unsigned char* exponent,
-      int explen) {
-
-   tpmrsa_free(ctx);
-
-   if(explen == 0) { //Default e= 2^16+1
-      mpi_lset(&ctx->E, 65537);
-   } else {
-      mpi_read_binary(&ctx->E, exponent, explen);
-   }
-   mpi_read_binary(&ctx->N, key, keylen);
-
-   ctx->len = ( mpi_msb(&ctx->N) + 7) >> 3;
-}
-
-static TPM_RESULT tpmrsa_public( tpmrsa_context *ctx,
-      const unsigned char *input,
-      unsigned char *output )
-{
-   int ret;
-   size_t olen;
-   mpi T;
-
-   mpi_init( &T );
-
-   MPI_CHK( mpi_read_binary( &T, input, ctx->len ) );
-
-   if( mpi_cmp_mpi( &T, &ctx->N ) >= 0 )
-   {
-      mpi_free( &T );
-      return TPM_ENCRYPT_ERROR;
-   }
-
-   olen = ctx->len;
-   MPI_CHK( mpi_exp_mod( &T, &T, &ctx->E, &ctx->N, &ctx->RN ) );
-   MPI_CHK( mpi_write_binary( &T, output, olen ) );
-
-cleanup:
-
-   mpi_free( &T );
-
-   if( ret != 0 )
-      return TPM_ENCRYPT_ERROR;
-
-   return TPM_SUCCESS;
-}
-
-static const unsigned char rsa_der_header[] = {
-       0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14,
-};
-
-TPM_RESULT tpmrsa_sigcheck(tpmrsa_context *ctx, const unsigned char *input, const unsigned char *sha1)
-{
-       unsigned char *tmp = alloca(ctx->len);
-       TPM_RESULT rv;
-       int i;
-       rv = tpmrsa_public(ctx, input, tmp);
-       if (rv)
-               return rv;
-       if (tmp[0] != 0 || tmp[1] != 1)
-               return TPM_INAPPROPRIATE_SIG;
-       for(i=2; i < 220; i++) {
-               if (tmp[i] != 0xFF)
-                       return TPM_INAPPROPRIATE_SIG;
-       }
-       if (memcmp(tmp + 220, rsa_der_header, sizeof(rsa_der_header)))
-               return TPM_INAPPROPRIATE_SIG;
-       if (memcmp(tmp + 236, sha1, 20))
-               return TPM_DECRYPT_ERROR;
-       return TPM_SUCCESS;
-}
-
-static void mgf_mask( unsigned char *dst, int dlen, unsigned char *src, int slen)
-{
-   unsigned char mask[HASH_LEN];
-   unsigned char counter[4] = {0, 0, 0, 0};
-   int i;
-   sha1_context mctx;
-
-   //We always hash the src with the counter, so save the partial hash
-   sha1_starts(&mctx);
-   sha1_update(&mctx, src, slen);
-
-   // Generate and apply dbMask
-   while(dlen > 0) {
-      //Copy the sha1 context
-      sha1_context ctx = mctx;
-
-      //compute hash for input || counter
-      sha1_update(&ctx, counter, sizeof(counter));
-      sha1_finish(&ctx, mask);
-
-      //Apply the mask
-      for(i = 0; i < (dlen < HASH_LEN ? dlen : HASH_LEN); ++i) {
-         *(dst++) ^= mask[i];
-      }
-
-      //Increment counter
-      ++counter[3];
-
-      dlen -= HASH_LEN;
-   }
-}
-
-/*
- * Add the message padding, then do an RSA operation
- */
-TPM_RESULT tpmrsa_pub_encrypt_oaep( tpmrsa_context *ctx,
-      int (*f_rng)(void *, unsigned char *, size_t),
-      void *p_rng,
-      size_t ilen,
-      const unsigned char *input,
-      unsigned char *output )
-{
-   int ret;
-   int olen;
-   unsigned char* seed = output + 1;
-   unsigned char* db = output + HASH_LEN +1;
-
-   olen = ctx->len-1;
-
-   if( f_rng == NULL )
-      return TPM_ENCRYPT_ERROR;
-
-   if( ilen > olen - 2 * HASH_LEN - 1)
-      return TPM_ENCRYPT_ERROR;
-
-   output[0] = 0;
-
-   //Encoding parameter p
-   sha1((unsigned char*)"TCPA", 4, db);
-
-   //PS
-   memset(db + HASH_LEN, 0,
-         olen - ilen - 2 * HASH_LEN - 1);
-
-   //constant 1 byte
-   db[olen - ilen - HASH_LEN -1] = 0x01;
-
-   //input string
-   memcpy(db + olen - ilen - HASH_LEN,
-         input, ilen);
-
-   //Generate random seed
-   if( ( ret = f_rng( p_rng, seed, HASH_LEN ) ) != 0 )
-      return TPM_ENCRYPT_ERROR;
-
-   // maskedDB: Apply dbMask to DB
-   mgf_mask( db, olen - HASH_LEN, seed, HASH_LEN);
-
-   // maskedSeed: Apply seedMask to seed
-   mgf_mask( seed, HASH_LEN, db, olen - HASH_LEN);
-
-   // Do the crypto op
-   return tpmrsa_public(ctx, output, output);
-}
diff --git a/stubdom/vtpmmgr/tpmrsa.h b/stubdom/vtpmmgr/tpmrsa.h
deleted file mode 100644 (file)
index 08213bb..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * \file rsa.h
- *
- * \brief The RSA public-key cryptosystem
- *
- *  Copyright (C) 2006-2010, Brainspark B.V.
- *
- *  This file is part of PolarSSL (http://www.polarssl.org)
- *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- *  All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef TPMRSA_H
-#define TPMRSA_H
-
-#include "tcg.h"
-#include <polarssl/bignum.h>
-
-/* tpm software key */
-typedef struct
-{
-    size_t len;                 /*!<  size(N) in chars  */
-
-    mpi N;                      /*!<  public modulus    */
-    mpi E;                      /*!<  public exponent   */
-
-    mpi RN;                     /*!<  cached R^2 mod N  */
-}
-tpmrsa_context;
-
-#define TPMRSA_CTX_INIT { 0, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}}
-
-/* Setup the rsa context using tpm public key data */
-void tpmrsa_set_pubkey(tpmrsa_context* ctx,
-      const unsigned char* key,
-      int keylen,
-      const unsigned char* exponent,
-      int explen);
-
-/* Check an RSA signature */
-TPM_RESULT tpmrsa_sigcheck(tpmrsa_context *ctx, const unsigned char *input, const unsigned char *sha1);
-
-/* Do rsa public crypto */
-TPM_RESULT tpmrsa_pub_encrypt_oaep( tpmrsa_context *ctx,
-      int (*f_rng)(void *, unsigned char *, size_t),
-      void *p_rng,
-      size_t ilen,
-      const unsigned char *input,
-      unsigned char *output );
-
-/* free tpmrsa key */
-inline void tpmrsa_free( tpmrsa_context *ctx ) {
-   mpi_free( &ctx->RN ); mpi_free( &ctx->E  ); mpi_free( &ctx->N  );
-}
-
-#endif /* tpmrsa.h */
diff --git a/stubdom/vtpmmgr/uuid.h b/stubdom/vtpmmgr/uuid.h
deleted file mode 100644 (file)
index 4737645..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef VTPMMGR_UUID_H
-#define VTPMMGR_UUID_H
-
-#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define UUID_FMTLEN ((2*16)+4) /* 16 hex bytes plus 4 hypens */
-#define UUID_BYTES(uuid) uuid[0], uuid[1], uuid[2], uuid[3], \
-                                uuid[4], uuid[5], uuid[6], uuid[7], \
-                                uuid[8], uuid[9], uuid[10], uuid[11], \
-                                uuid[12], uuid[13], uuid[14], uuid[15]
-
-
-typedef uint8_t uuid_t[16];
-
-#endif
diff --git a/stubdom/vtpmmgr/vtpm_cmd_handler.c b/stubdom/vtpmmgr/vtpm_cmd_handler.c
deleted file mode 100644 (file)
index 2ac14fa..0000000
+++ /dev/null
@@ -1,882 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <inttypes.h>
-#include <string.h>
-#include <stdlib.h>
-#include <mini-os/console.h>
-#include <mini-os/lib.h>
-#include <polarssl/sha1.h>
-#include <polarssl/sha2.h>
-
-#include "marshal.h"
-#include "log.h"
-#include "vtpm_disk.h"
-#include "vtpmmgr.h"
-#include "tpm.h"
-#include "tpmrsa.h"
-#include "tcg.h"
-#include "mgmt_authority.h"
-#include "disk_crypto.h"
-
-static void gen_random_uuid(uuid_t uuid)
-{
-       do_random(uuid, 16);
-       // make the 128-bit random number a valid UUID (122 bits remain)
-       uuid[6] = 0x40 | (uuid[6] & 0x0F);
-       uuid[8] = 0x80 | (uuid[8] & 0x3F);
-}
-
-/*
- * Instead of using a kernel hash, which requires a trusted domain builder to
- * report, use the XSM label as a substitute.
- */
-static TPM_RESULT find_vtpm_khash(int domid, struct tpm_opaque *opq)
-{
-       char buf[128];
-       int i, rv;
-       buf[127] = 0;
-       rv = tpmback_get_peercontext(opq->domid, opq->handle, buf, sizeof(buf) - 1);
-       if (rv < 0)
-               return TPM_FAIL;
-
-       sha1((void*)buf, strlen(buf), opq->kern_hash);
-
-       /*
-        * As a hack to support the use of the XSM user field as an optional
-        * wildcard, check the hash against the group here. If it fails, replace
-        * the user field with a "*" and return the hash of that value.
-        */
-       for(i=0; i < be32_native(opq->group->seal_bits.nr_kerns); i++) {
-               if (!memcmp(opq->group->seal_bits.kernels[i].bits, opq->kern_hash, 20)) {
-                       return TPM_SUCCESS;
-               }
-       }
-
-       char* upos = strchr(buf, ':');
-       if (upos == NULL || upos == buf)
-               return TPM_SUCCESS;
-
-       upos--;
-       upos[0] = '*';
-
-       sha1((void*)upos, strlen(upos), opq->kern_hash);
-       return TPM_SUCCESS;
-}
-
-static TPM_RESULT find_vtpm_verified(int domid, struct tpm_opaque *opq)
-{
-       TPM_RESULT rc;
-       int i;
-       if (opq->vtpm)
-               return TPM_SUCCESS;
-
-       rc = find_vtpm(&opq->group, &opq->vtpm, *opq->uuid);
-       if (rc)
-               return TPM_BAD_PARAMETER;
-
-       if (opq->vtpm->flags & VTPM_FLAG_OPEN) {
-               printk("Attempted to open vTPM twice!\n");
-               opq->vtpm = NULL;
-               opq->group = NULL;
-               return TPM_DISABLED;
-       }
-
-       rc = find_vtpm_khash(domid, opq);
-       if (rc)
-               return rc;
-
-       for(i=0; i < be32_native(opq->group->seal_bits.nr_kerns); i++) {
-               if (!memcmp(opq->group->seal_bits.kernels[i].bits, opq->kern_hash, 20)) {
-                       opq->vtpm->flags |= VTPM_FLAG_OPEN;
-                       return TPM_SUCCESS;
-               }
-       }
-       printk("Unauthorized vTPM kernel image used!\n");
-       return TPM_DISABLED;
-}
-
-static TPM_RESULT vtpmmgr_SaveHashKey(struct tpm_opaque *opq, tpmcmd_t* tpmcmd)
-{
-       TPM_RESULT status = TPM_SUCCESS;
-       int rc = 0;
-
-       size_t bufsize = tpmcmd->req_len - VTPM_COMMAND_HEADER_SIZE;
-       const void *buf = tpmcmd->req + VTPM_COMMAND_HEADER_SIZE;
-
-       if (bufsize < 52) {
-               vtpmlogerror(VTPM_LOG_VTPM, "VTPM_ORD_SAVEHASHKEY hashkey too short!\n");
-               status = TPM_BAD_PARAMETER;
-               goto abort_egress;
-       }
-       if (bufsize > 64) {
-               vtpmlogerror(VTPM_LOG_VTPM, "VTPM_ORD_SAVEHASHKEY hashkey too long!\n");
-               status = TPM_BAD_PARAMETER;
-               goto abort_egress;
-       }
-
-       vtpmloginfo(VTPM_LOG_VTPM, "vtpmmgr_SaveHashKey\n");
-       status = find_vtpm_verified(tpmcmd->domid, opq);
-
-       // auto-create vTPMs in group0 when saving a new UUID
-       // TODO restrict to certain UUIDs (such as all-zero)
-       // this is not done yet to simplify use of the TPM Manager
-       if (status == TPM_BAD_PARAMETER) {
-               opq->group = g_mgr->groups[0].v;
-               rc = create_vtpm(opq->group, &opq->vtpm, *opq->uuid);
-               if (rc) {
-                       status = TPM_BAD_PARAMETER;
-                       goto abort_egress;
-               }
-               if (opq->group->nr_vtpms == 1)
-                       opq->vtpm->flags = VTPM_FLAG_ADMIN;
-               printk("SaveHashKey with unknown UUID="UUID_FMT" - creating in auth0 (f=%d)\n",
-                               UUID_BYTES((*opq->uuid)), opq->vtpm->flags);
-               status = TPM_SUCCESS;
-       }
-       if (status)
-               goto abort_egress;
-
-       memcpy(opq->vtpm->data, buf, bufsize);
-       memset(opq->vtpm->data + bufsize, 0, 64 - bufsize);
-
-       vtpm_sync(opq->group, opq->vtpm);
-
-abort_egress:
-       pack_TPM_RSP_HEADER(tpmcmd->resp, VTPM_TAG_RSP, VTPM_COMMAND_HEADER_SIZE, status);
-       tpmcmd->resp_len = VTPM_COMMAND_HEADER_SIZE;
-
-       return status;
-}
-
-static TPM_RESULT vtpmmgr_LoadHashKey(struct tpm_opaque *opq, tpmcmd_t* tpmcmd)
-{
-       TPM_RESULT status = TPM_SUCCESS;
-       int i;
-       uint8_t *buf = tpmcmd->resp + VTPM_COMMAND_HEADER_SIZE;
-
-       vtpmloginfo(VTPM_LOG_VTPM, "vtpmmgr_LoadHashKey\n");
-       tpmcmd->resp_len = VTPM_COMMAND_HEADER_SIZE;
-
-       status = find_vtpm_verified(tpmcmd->domid, opq);
-       if (status)
-               goto abort_egress;
-
-       memcpy(buf, opq->vtpm->data, 64);
-
-       for(i=52; i < 64; i++) {
-               if (buf[i]) {
-                       tpmcmd->resp_len += 64;
-                       goto abort_egress;
-               }
-       }
-       tpmcmd->resp_len += 52;
-
-abort_egress:
-       pack_TPM_RSP_HEADER(tpmcmd->resp, VTPM_TAG_RSP, tpmcmd->resp_len, status);
-
-       return status;
-}
-
-#define CMD_BEGIN \
-       TPM_RESULT status = TPM_SUCCESS; \
-       uint32_t in_pos = VTPM_COMMAND_HEADER_SIZE; \
-       tpmcmd->resp_len = VTPM_COMMAND_HEADER_SIZE; \
-       vtpmloginfo(VTPM_LOG_TPM, "%s\n", __func__);
-
-#define CMD_END \
- abort_egress: \
-       if (status) \
-               tpmcmd->resp_len = VTPM_COMMAND_HEADER_SIZE; \
-       pack_TPM_RSP_HEADER(tpmcmd->resp, VTPM_TAG_RSP, tpmcmd->resp_len, status); \
-       return status
-
-#define UNPACK_IN(type, item...) do { \
-       status = unpack3_ ## type (tpmcmd->req, &in_pos, tpmcmd->req_len, item); \
-       if (status) { \
-               status = TPM_BAD_PARAMETER; \
-               goto abort_egress; \
-       } \
-} while (0)
-
-#define UNPACK_GROUP(group) do { \
-       uint32_t group_idx; \
-       UNPACK_IN(UINT32, &group_idx); \
-       if (group_idx >= g_mgr->nr_groups) { \
-               status = TPM_BADINDEX; \
-               goto abort_egress; \
-       } \
-       group = g_mgr->groups[group_idx].v; \
-       if (!group) { \
-               status = TPM_AUTHFAIL; \
-               goto abort_egress; \
-       } \
-} while (0)
-
-#define UNPACK_DONE() do { \
-       if (in_pos != tpmcmd->req_len) { \
-               status = TPM_BAD_PARAMETER; \
-               goto abort_egress; \
-       } \
-} while (0)
-
-#define PACK_OUT(type, item...) do { \
-       UINT32 isize = sizeof_ ## type(item); \
-       if (isize + tpmcmd->resp_len > TCPA_MAX_BUFFER_LENGTH) { \
-               status = TPM_SIZE; \
-               goto abort_egress; \
-       } \
-       pack_ ## type (tpmcmd->resp + tpmcmd->resp_len, item); \
-       tpmcmd->resp_len += isize; \
-} while (0)
-
-#define PACK_BUF ((void*)(tpmcmd->resp + tpmcmd->resp_len))
-
-static TPM_RESULT vtpmmgr_GetBootHash(struct tpm_opaque *opq, tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       UNPACK_DONE();
-
-       PACK_OUT(BUFFER, opq->kern_hash, 20);
-
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GetQuote(struct tpm_opaque *opq, tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       int i;
-       void *ibuf;
-       uint32_t pcr_size;
-       TPM_PCR_SELECTION sel;
-       uint32_t extra_info_flags;
-
-       UNPACK_IN(VPTR, &ibuf, 20, UNPACK_ALIAS);
-       UNPACK_IN(TPM_PCR_SELECTION, &sel, UNPACK_ALIAS);
-       UNPACK_IN(TPM_DEEP_QUOTE_INFO, &extra_info_flags);
-       UNPACK_DONE();
-
-       if (!opq->vtpm) {
-               status = TPM_BAD_PARAMETER;
-               goto abort_egress;
-       }
-
-       printk("ibuf: ");
-       for (i=0; i < 20; i++)
-               printk("%02x", ((uint8_t*)ibuf)[i]);
-       printk("\n");
-
-       status = vtpm_do_quote(opq->group, *opq->uuid, opq->kern_hash, ibuf, &sel, extra_info_flags, PACK_BUF + 256, &pcr_size, PACK_BUF);
-       if (status)
-               goto abort_egress;
-       tpmcmd->resp_len += 256 + pcr_size;
-
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GroupList(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       UNPACK_DONE();
-       PACK_OUT(UINT32, g_mgr->nr_groups);
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GroupNew(tpmcmd_t* tpmcmd)
-{
-       void *privCADigest;
-       BYTE *pubkey;
-       struct mem_group *group;
-       uint32_t group_idx;
-       CMD_BEGIN;
-
-       UNPACK_IN(VPTR, &privCADigest, 20, UNPACK_ALIAS);
-       UNPACK_IN(PTR, &pubkey, 256, UNPACK_ALIAS);
-       UNPACK_DONE();
-
-       group = vtpm_new_group(privCADigest);
-       if (!group) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       memcpy(group->id_data.saa_pubkey, pubkey, 256);
-
-       PACK_OUT(BUFFER, group->id_data.uuid, 16);
-       PACK_OUT(BUFFER, group->id_data.tpm_aik_public, 256);
-       PACK_OUT(BUFFER, group->details.recovery_data, 256);
-
-       memset(group->details.recovery_data, 0, 256);
-
-       group->details.sequence = native_be64(g_mgr->sequence);
-
-       if (group != g_mgr->groups[0].v) {
-               group_idx = g_mgr->nr_groups;
-               g_mgr->nr_groups++;
-               g_mgr->groups = realloc(g_mgr->groups, g_mgr->nr_groups*sizeof(struct mem_group_hdr));
-               memset(&g_mgr->groups[group_idx], 0, sizeof(g_mgr->groups[0]));
-               g_mgr->groups[group_idx].v = group;
-       }
-
-       vtpm_sync_group(group, SEQ_UPDATE);
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GroupDel(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-       uint32_t group_idx, nr_mov;
-
-       UNPACK_IN(UINT32, &group_idx);
-       UNPACK_DONE();
-
-       if (group_idx > g_mgr->nr_groups) {
-               status = TPM_BADINDEX;
-               goto abort_egress;
-       }
-       group = g_mgr->groups[group_idx].v;
-
-       if (group) {
-               int i, j;
-               for (i = 0; i < group->nr_pages; i++) {
-                       for (j = 0; j < group->data[i].size; j++) {
-                               if (group->data[i].vtpms[j]->flags & VTPM_FLAG_OPEN) {
-                                       status = TPM_FAIL;
-                                       goto abort_egress;
-                               }
-                       }
-               }
-
-               for (i = 0; i < group->nr_pages; i++) {
-                       for (j = 0; j < group->data[i].size; j++) {
-                               free(group->data[i].vtpms[j]);
-                       }
-               }
-               free(group->data);
-               free(group->seals);
-               free(group);
-       }
-
-       g_mgr->nr_groups--;
-       nr_mov = g_mgr->nr_groups - group_idx;
-       memmove(&g_mgr->groups[group_idx], &g_mgr->groups[group_idx + 1], nr_mov * sizeof(g_mgr->groups[0]));
-
-       vtpm_sync_disk(g_mgr, CTR_UPDATE);
-
-       CMD_END;
-}
-
-static int pack_cfg_list(void* buf, struct mem_group *group)
-{
-       int i;
-       void *bstart = buf;
-       memcpy(buf, &group->details.cfg_seq, 8); buf += 8;
-       buf = pack_UINT32(buf, group->nr_seals);
-       for(i=0; i < group->nr_seals; i++) {
-               memcpy(buf, &group->seals[i].digest_release, 20);
-               buf += 20;
-       }
-       memcpy(buf, &group->seal_bits.nr_kerns, 4); buf += 4;
-       memcpy(buf, &group->seal_bits.kernels, 20 * be32_native(group->seal_bits.nr_kerns));
-       return buf - bstart + 20 * be32_native(group->seal_bits.nr_kerns);
-}
-
-static TPM_RESULT vtpmmgr_GroupShow(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-
-       UNPACK_GROUP(group);
-       UNPACK_DONE();
-
-       // TODO show is read-only access, need to hit disk if group is NULL
-
-       PACK_OUT(BUFFER, group->id_data.uuid, 16);
-       PACK_OUT(BUFFER, group->id_data.saa_pubkey, 256);
-       tpmcmd->resp_len += pack_cfg_list(PACK_BUF, group);
-
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GroupActivate(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-       uint32_t blobSize;
-       void *blob;
-
-       UNPACK_GROUP(group);
-       UNPACK_IN(UINT32, &blobSize);
-       UNPACK_IN(VPTR, &blob, blobSize, UNPACK_ALIAS);
-       UNPACK_DONE();
-
-       status = group_do_activate(group, blob, blobSize, tpmcmd->resp, &tpmcmd->resp_len);
-
-       CMD_END;
-}
-
-/* 2048-bit MODP Group from RFC3526:
- *   2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 }
- */
-static uint8_t P_bytes[256] = {
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
-       0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
-       0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
-       0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
-       0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
-       0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
-       0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
-       0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
-       0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
-       0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
-       0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36,
-       0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
-       0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56,
-       0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
-       0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
-       0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
-       0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2,
-       0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
-       0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C,
-       0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
-       0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF,
-       0xFF, 0xFF, 0xFF, 0xFF,
-};
-static t_uint Gp[] = { 2 };
-
-static void tm_dhkx_gen(void* dhkx1, void* dhkx2, void* out)
-{
-       mpi GX = { 0 }, GY = { 0 }, K = { 0 }, RP = { 0 };
-       mpi P = { 0 };
-
-       t_uint Xp[sizeof(P_bytes) / sizeof(t_uint)];
-       mpi X = {
-               .s = 1,
-               .n = ARRAY_SIZE(Xp),
-               .p = Xp
-       };
-       mpi G = {
-               .s = 1,
-               .n = 1,
-               .p = Gp,
-       };
-       mpi_read_binary(&P, P_bytes, sizeof(P_bytes));
-
-       do_random(Xp, sizeof(Xp));
-
-       mpi_exp_mod(&GX, &G, &X, &P, &RP);
-       mpi_write_binary(&GX, dhkx2, 256);
-       mpi_free(&GX);
-
-       mpi_read_binary(&GY, dhkx1, 256);
-       mpi_exp_mod(&K, &GY, &X, &P, &RP);
-       mpi_free(&P);
-       mpi_free(&RP);
-       mpi_free(&GY);
-
-       mpi_write_binary(&K, (void*)Xp, 256);
-       mpi_free(&K);
-       sha2((void*)Xp, 256, out, 0);
-}
-
-static void xor2_256b(void *xv, const void* yv)
-{
-       int i;
-       uint64_t *x = xv;
-       const uint64_t *y = yv;
-       for(i=0; i < 4; i++)
-               x[i] ^= y[i];
-}
-
-static TPM_RESULT vtpmmgr_GroupRegister(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group = NULL;
-       tpmrsa_context saa_rsa = TPMRSA_CTX_INIT;
-       struct tpm_authdata digest;
-       sha1_context ctx;
-       TPM_PCR_SELECTION sel;
-       void *dhkx1, *dhkx2, *gk, *sig;
-       uint32_t extra_info_flags = 0;
-
-       UNPACK_GROUP(group);
-       UNPACK_IN(VPTR, &dhkx1, 256, UNPACK_ALIAS);
-       UNPACK_IN(VPTR, &sig, 256, UNPACK_ALIAS);
-       UNPACK_IN(TPM_PCR_SELECTION, &sel, UNPACK_ALIAS);
-       UNPACK_DONE();
-
-       /* Only generating this quote during the same boot that this group was
-        * created in allows the quote to prove that the group key has never
-        * been available outside a configuration approved by its SAA.
-        */
-       if (!(group->flags & MEM_GROUP_FLAG_FIRSTBOOT)) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       sha1(dhkx1, 256, digest.bits);
-       tpmrsa_set_pubkey(&saa_rsa, group->id_data.saa_pubkey, 256, 0, 0);
-       if (tpmrsa_sigcheck(&saa_rsa, sig, digest.bits))
-               status = TPM_FAIL;
-       tpmrsa_free(&saa_rsa);
-       if (status)
-               goto abort_egress;
-
-       dhkx2 = PACK_BUF;
-       tpmcmd->resp_len += 256;
-       gk = PACK_BUF;
-       tpmcmd->resp_len += 32;
-
-       tm_dhkx_gen(dhkx1, dhkx2, gk);
-       xor2_256b(gk, &group->group_key);
-
-       sha1_starts(&ctx);
-       sha1_update(&ctx, (void*)"REGR", 4);
-       sha1_update(&ctx, dhkx1, 256);
-       sha1_update(&ctx, dhkx2, 256 + 32);
-       sha1_finish(&ctx, digest.bits);
-
-       status = vtpm_do_quote(group, NULL, NULL, &digest, &sel, extra_info_flags,NULL, NULL, PACK_BUF);
-       tpmcmd->resp_len += 256;
-
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_GroupUpdate(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-       int i;
-       int hstart;
-       uint32_t nr_kerns, nr_seals;
-       uint64_t old_seq, new_seq;
-       struct mem_seal *seals = NULL;
-       tpmrsa_context saa_rsa = TPMRSA_CTX_INIT;
-       unsigned char digest[20];
-       TPM_RESULT rc;
-       void *sig, *seal_bits, *kern_bits;
-
-       UNPACK_GROUP(group);
-       UNPACK_IN(VPTR, &sig, 256, UNPACK_ALIAS);
-
-       // Hash starts here
-       hstart = in_pos;
-
-       new_seq = be64_native(*(be64_t*)(tpmcmd->req + in_pos));
-       old_seq = be64_native(group->details.cfg_seq);
-       in_pos += 8;
-       if (old_seq > new_seq) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       UNPACK_IN(UINT32, &nr_seals);
-       UNPACK_IN(VPTR, &seal_bits, nr_seals * 20, UNPACK_ALIAS);
-
-       UNPACK_IN(UINT32, &nr_kerns);
-       UNPACK_IN(VPTR, &kern_bits, nr_kerns * 20, UNPACK_ALIAS);
-
-       // TODO handle saving larger lists on disk
-       if (nr_seals > NR_SEALS_PER_GROUP) {
-               status = TPM_SIZE;
-               goto abort_egress;
-       }
-
-       if (nr_kerns > NR_KERNS_PER_GROUP) {
-               status = TPM_SIZE;
-               goto abort_egress;
-       }
-
-       sha1(tpmcmd->req + hstart, in_pos - hstart, digest);
-
-       seals = calloc(nr_seals, sizeof(seals[0]));
-
-       for(i=0; i < nr_seals; i++) {
-               TPM_PCR_SELECTION sel;
-               UNPACK_IN(TPM_PCR_SELECTION, &sel, UNPACK_ALIAS);
-               memcpy(&seals[i].digest_release, seal_bits, 20);
-               seal_bits += 20;
-               if (sel.sizeOfSelect > 4) {
-                       status = TPM_BAD_PARAMETER;
-                       goto abort_egress;
-               }
-               seals[i].pcr_selection = native_le32(0);
-               memcpy(&seals[i].pcr_selection, sel.pcrSelect, sel.sizeOfSelect);
-       }
-
-       UNPACK_DONE();
-
-       tpmrsa_set_pubkey(&saa_rsa, group->id_data.saa_pubkey, 256, 0, 0);
-       rc = tpmrsa_sigcheck(&saa_rsa, sig, digest);
-       tpmrsa_free(&saa_rsa);
-       if (rc) {
-               printk("sigcheck failed: %d\n", rc);
-               status = rc;
-               goto abort_egress;
-       }
-
-       // Commit
-       free(group->seals);
-
-       memcpy(&group->seal_bits.kernels, kern_bits, 20 * nr_kerns);
-       group->details.cfg_seq = native_be64(new_seq);
-       group->nr_seals = nr_seals;
-       group->seals = seals;
-       group->seal_bits.nr_kerns = native_be32(nr_kerns);
-
-       seals = NULL;
-
-       group->flags &= ~MEM_GROUP_FLAG_SEAL_VALID;
-       if (group == g_mgr->groups[0].v)
-               g_mgr->root_seals_valid = 0;
-
-       // TODO use GROUP_KEY_UPDATE or MGR_KEY_UPDATE here?
-       // only required if this update was to address a potential key leak
-       vtpm_sync_group(group, SEQ_UPDATE);
-
- abort_egress:
-       free(seals);
-
-       pack_TPM_RSP_HEADER(tpmcmd->resp, VTPM_TAG_RSP, tpmcmd->resp_len, status);
-       return status;
-}
-
-static TPM_RESULT vtpmmgr_VtpmList(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-       uint32_t vtpm_offset;
-       int i, j;
-
-       UNPACK_GROUP(group);
-       UNPACK_IN(UINT32, &vtpm_offset);
-
-       PACK_OUT(UINT32, group->nr_vtpms);
-       if (vtpm_offset > group->nr_vtpms)
-               goto egress;
-
-       for(i=0; i < group->nr_pages; i++) {
-               struct mem_vtpm_page *pg = &group->data[i];
-               for(j=0; j < pg->size; j++) {
-                       if (vtpm_offset) {
-                               // TODO a proper seek would be far faster
-                               vtpm_offset--;
-                               continue;
-                       }
-                       memcpy(PACK_BUF, pg->vtpms[j]->uuid, 16);
-                       tpmcmd->resp_len += 16;
-                       if (tpmcmd->resp_len + 16 > TCPA_MAX_BUFFER_LENGTH)
-                               goto egress;
-               }
-       }
-
- egress:
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_VtpmNew(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       struct mem_group *group;
-       struct mem_vtpm *vtpm;
-       uuid_t newuuid;
-       int rc;
-
-       UNPACK_GROUP(group);
-
-       // XXX allow non-random UUIDs for testing
-       if (tpmcmd->req_len == 14 + 16)
-               UNPACK_IN(BUFFER, newuuid, 16);
-       else
-               gen_random_uuid(newuuid);
-       UNPACK_DONE();
-
-       rc = create_vtpm(group, &vtpm, newuuid);
-       if (rc) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-       memset(vtpm->data, 0, 64);
-       vtpm_sync(group, vtpm);
-
-       PACK_OUT(BUFFER, newuuid, 16);
-       CMD_END;
-}
-
-static TPM_RESULT vtpmmgr_VtpmDel(tpmcmd_t* tpmcmd)
-{
-       CMD_BEGIN;
-       uuid_t uuid;
-       struct mem_group *group;
-       struct mem_vtpm *vtpm;
-       int rc;
-
-       UNPACK_IN(BUFFER, uuid, 16);
-       UNPACK_DONE();
-       rc = find_vtpm(&group, &vtpm, uuid);
-       if (rc) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       if (vtpm->flags & VTPM_FLAG_OPEN) {
-               status = TPM_FAIL;
-               goto abort_egress;
-       }
-
-       delete_vtpm(group, vtpm);
-
-       CMD_END;
-}
-
-static int vtpmmgr_permcheck(struct tpm_opaque *opq)
-{
-       if (!opq->vtpm)
-               return 1;
-       if (opq->vtpm->flags & VTPM_FLAG_ADMIN)
-               return 0;
-       return 1;
-}
-
-TPM_RESULT vtpmmgr_handle_cmd(
-               struct tpm_opaque *opaque,
-               tpmcmd_t* tpmcmd)
-{
-       TPM_RESULT status = TPM_SUCCESS;
-       TPM_TAG tag;
-       UINT32 size;
-       TPM_COMMAND_CODE ord;
-
-       unpack_TPM_RQU_HEADER(tpmcmd->req,
-                       &tag, &size, &ord);
-
-       /* Handle the command now */
-       switch(tag) {
-       case VTPM_TAG_REQ:
-               // This is a vTPM command
-               switch(ord) {
-               case VTPM_ORD_SAVEHASHKEY:
-                       return vtpmmgr_SaveHashKey(opaque, tpmcmd);
-               case VTPM_ORD_LOADHASHKEY:
-                       return vtpmmgr_LoadHashKey(opaque, tpmcmd);
-               case VTPM_ORD_GET_BOOT_HASH:
-                       return vtpmmgr_GetBootHash(opaque, tpmcmd);
-               case VTPM_ORD_GET_QUOTE:
-                       return vtpmmgr_GetQuote(opaque, tpmcmd);
-               default:
-                       vtpmlogerror(VTPM_LOG_VTPM, "Invalid vTPM Ordinal %" PRIu32 "\n", ord);
-                       status = TPM_BAD_ORDINAL;
-               }
-               break;
-       case VTPM_TAG_REQ2:
-               // This is a management command
-               if (vtpmmgr_permcheck(opaque)) {
-                       status = TPM_AUTHFAIL;
-                       vtpmlogerror(VTPM_LOG_VTPM, "Rejected attempt to use management command from client\n");
-                       break;
-               }
-               switch (ord) {
-               case VTPM_ORD_GROUP_LIST:
-                       return vtpmmgr_GroupList(tpmcmd);
-               case VTPM_ORD_GROUP_NEW:
-                       return vtpmmgr_GroupNew(tpmcmd);
-               case VTPM_ORD_GROUP_DEL:
-                       return vtpmmgr_GroupDel(tpmcmd);
-               case VTPM_ORD_GROUP_ACTIVATE:
-                       return vtpmmgr_GroupActivate(tpmcmd);
-               case VTPM_ORD_GROUP_REGISTER:
-                       return vtpmmgr_GroupRegister(tpmcmd);
-               case VTPM_ORD_GROUP_UPDATE:
-                       return vtpmmgr_GroupUpdate(tpmcmd);
-               case VTPM_ORD_GROUP_SHOW:
-                       return vtpmmgr_GroupShow(tpmcmd);
-               case VTPM_ORD_VTPM_LIST:
-                       return vtpmmgr_VtpmList(tpmcmd);
-               case VTPM_ORD_VTPM_NEW:
-                       return vtpmmgr_VtpmNew(tpmcmd);
-               case VTPM_ORD_VTPM_DEL:
-                       return vtpmmgr_VtpmDel(tpmcmd);
-               default:
-                       vtpmlogerror(VTPM_LOG_VTPM, "Invalid TM Ordinal %" PRIu32 "\n", ord);
-                       status = TPM_BAD_ORDINAL;
-               }
-               break;
-       case TPM_TAG_RQU_COMMAND:
-       case TPM_TAG_RQU_AUTH1_COMMAND:
-       case TPM_TAG_RQU_AUTH2_COMMAND:
-               //This is a TPM passthrough command
-               switch(ord) {
-               case TPM_ORD_GetRandom:
-                       vtpmloginfo(VTPM_LOG_VTPM, "Passthrough: TPM_GetRandom\n");
-                       break;
-               case TPM_ORD_PcrRead:
-                       vtpmloginfo(VTPM_LOG_VTPM, "Passthrough: TPM_PcrRead\n");
-                       // Quotes also need to be restricted to hide PCR values
-                       break;
-               case TPM_ORD_Extend:
-                       // TODO allow to certain clients? A malicious client
-                       // could scramble PCRs and make future quotes invalid.
-                       if (vtpmmgr_permcheck(opaque)) {
-                               vtpmlogerror(VTPM_LOG_VTPM, "Disallowed TPM_Extend\n");
-                               status = TPM_DISABLED_CMD;
-                               goto abort_egress;
-                       } else {
-                               vtpmloginfo(VTPM_LOG_VTPM, "Passthrough: TPM_Extend\n");
-                       }
-                       break;
-               default:
-                       vtpmlogerror(VTPM_LOG_VTPM, "TPM Disallowed Passthrough ord=%" PRIu32 "\n", ord);
-                       status = TPM_DISABLED_CMD;
-                       goto abort_egress;
-               }
-
-               size = TCPA_MAX_BUFFER_LENGTH;
-               TPMTRYRETURN(TPM_TransmitData(tpmcmd->req, tpmcmd->req_len, tpmcmd->resp, &size));
-               tpmcmd->resp_len = size;
-
-               return TPM_SUCCESS;
-       default:
-               vtpmlogerror(VTPM_LOG_VTPM, "Invalid tag=%" PRIu16 "\n", tag);
-               status = TPM_BADTAG;
-       }
-
-abort_egress:
-       tpmcmd->resp_len = VTPM_COMMAND_HEADER_SIZE;
-       pack_TPM_RSP_HEADER(tpmcmd->resp, tag + 3, tpmcmd->resp_len, status);
-
-       return status;
-}
diff --git a/stubdom/vtpmmgr/vtpm_disk.c b/stubdom/vtpmmgr/vtpm_disk.c
deleted file mode 100644 (file)
index a01633a..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-#include <console.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <mini-os/byteorder.h>
-
-#include "vtpm_manager.h"
-#include "log.h"
-#include "uuid.h"
-
-#include "vtpmmgr.h"
-#include "vtpm_disk.h"
-#include "disk_crypto.h"
-#include "disk_format.h"
-#include "disk_io.h"
-#include "disk_tpm.h"
-
-struct mem_tpm_mgr *g_mgr;
-
-int vtpm_sync_disk(struct mem_tpm_mgr *mgr, int depth)
-{
-       int old_active_root = mgr->active_root;
-       int new_active_root = !old_active_root;
-       int rc = 0;
-       struct tpm_authdata prev;
-       struct mem_group *group0 = mgr->groups[0].v;
-
-       // don't bother writing if we will never be able to read
-       if (!group0 || !group0->nr_seals)
-               return 0;
-
-       mgr->sequence++;
-       mgr->active_root = new_active_root;
-
-       switch (depth) {
-       case CTR_UPDATE:
-       {
-               uint32_t ctr = be32_native(mgr->counter_value);
-               mgr->counter_value = native_be32(ctr + 1);
-               break;
-       }
-       case MGR_KEY_UPDATE:
-       {
-               int i;
-               mgr->root_seals_valid = 0;
-               do_random(&mgr->tm_key, 16);
-               aes_setup(&mgr->tm_key_e, &mgr->tm_key);
-               do_random(&mgr->nv_key, 16);
-               for(i=0; i < mgr->nr_groups; i++) {
-                       abort(); // TODO use raw re-encryption to handle unopened groups
-               }
-               break;
-       }
-       case CTR_AUTH_UPDATE:
-               mgr->root_seals_valid = 0;
-               memcpy(&prev, &mgr->counter_auth, 20);
-               do_random(&mgr->counter_auth, 20);
-               break;
-       case NV_AUTH_UPDATE:
-               mgr->root_seals_valid = 0;
-               memcpy(&prev, &mgr->nvram_auth, 20);
-               do_random(&mgr->nvram_auth, 20);
-               break;
-       }
-
-       disk_write_all(mgr);
-
-       switch (depth) {
-       case SEQ_UPDATE:
-               break;
-
-       case CTR_UPDATE:
-               rc = TPM_disk_incr_counter(mgr->counter_index, mgr->counter_auth);
-               if (rc) {
-                       uint32_t ctr = be32_native(mgr->counter_value);
-                       mgr->counter_value = native_be32(ctr - 1);
-                       mgr->active_root = old_active_root;
-                       return rc;
-               }
-               break;
-
-       case MGR_KEY_UPDATE:
-               rc = TPM_disk_nvwrite(&mgr->nv_key, 16, mgr->nvram_slot, mgr->nvram_auth);
-               if (rc)
-                       abort();
-               break;
-
-       case CTR_AUTH_UPDATE:
-               rc = TPM_disk_change_counter(mgr->counter_index, prev, mgr->counter_auth);
-               if (rc)
-                       abort();
-               break;
-
-       case NV_AUTH_UPDATE:
-               rc = TPM_disk_nvchange(mgr->nvram_slot, prev, mgr->nvram_auth);
-               if (rc)
-                       abort();
-               break;
-       }
-
-       return rc;
-}
-
-static struct mem_group_hdr* find_mem_group_hdr(struct mem_tpm_mgr *mgr, struct mem_group *group)
-{
-       int i;
-       for (i = 0; i < mgr->nr_groups; i++) {
-               struct mem_group_hdr *hdr = mgr->groups + i;
-               if (hdr->v == group)
-                       return hdr;
-       }
-       return NULL;
-}
-
-int vtpm_sync_group(struct mem_group *group, int depth)
-{
-       struct mem_group_hdr* hdr = find_mem_group_hdr(g_mgr, group);
-       uint64_t seq = be64_native(group->details.sequence);
-
-       if (!hdr)
-               abort();
-
-       hdr->disk_loc.value = 0;
-       group->details.sequence = native_be64(1 + seq);
-
-       if (depth == GROUP_KEY_UPDATE) {
-               int i;
-               do_random(&group->group_key, 16);
-               do_random(&group->rollback_mac_key, 16);
-               group->flags &= ~MEM_GROUP_FLAG_SEAL_VALID;
-               for (i = 0; i < group->nr_pages; i++)
-                       group->data[i].disk_loc.value = 0;
-               depth = CTR_UPDATE;
-       }
-
-       return vtpm_sync_disk(g_mgr, depth);
-}
-
-static struct mem_vtpm_page* find_mem_vtpm_page(struct mem_group *group, struct mem_vtpm *vtpm)
-{
-       int pgidx = vtpm->index_in_parent / VTPMS_PER_SECTOR;
-       return group->data + pgidx;
-}
-
-int vtpm_sync(struct mem_group *group, struct mem_vtpm *vtpm)
-{
-       struct mem_vtpm_page *pg = find_mem_vtpm_page(group, vtpm);
-       if (!pg)
-               return 1;
-       pg->disk_loc.value = 0;
-       return vtpm_sync_group(group, SEQ_UPDATE);
-}
-
-/************************************************************************/
-
-int create_vtpm(struct mem_group *group, struct mem_vtpm **vtpmp, const uuid_t uuid)
-{
-       int pgidx = group->nr_vtpms / VTPMS_PER_SECTOR;
-       int vtidx = group->nr_vtpms % VTPMS_PER_SECTOR;
-       struct mem_vtpm *vtpm = calloc(1, sizeof(*vtpm));
-
-       struct mem_vtpm_page *page = group->data + pgidx;
-       if (pgidx >= group->nr_pages) {
-               if (pgidx != group->nr_pages)
-                       abort(); // nr_vtpms inconsistent with nr_pages
-               group->nr_pages++;
-               group->data = realloc(group->data, group->nr_pages * sizeof(*page));
-               page = group->data + pgidx;
-               memset(page, 0, sizeof(*page));
-       }
-       if (page->size != vtidx)
-               abort(); // nr_vtpms inconsistent with page->size
-       page->size++;
-
-       page->vtpms[vtidx] = vtpm;
-       vtpm->index_in_parent = group->nr_vtpms;
-       vtpm->flags = 0;
-
-       group->nr_vtpms++;
-
-       memcpy(vtpm->uuid, uuid, 16);
-       *vtpmp = vtpm;
-       return 0;
-}
-
-int delete_vtpm(struct mem_group *group, struct mem_vtpm *vtpm)
-{
-       struct mem_vtpm_page *pg = find_mem_vtpm_page(group, vtpm);
-       struct mem_vtpm_page *last_pg = group->data + (group->nr_pages - 1);
-       struct mem_vtpm *last = last_pg->vtpms[last_pg->size - 1];
-       int vtidx = vtpm->index_in_parent % VTPMS_PER_SECTOR;
-
-       if (vtpm->flags & VTPM_FLAG_OPEN)
-               return 1;
-
-       last->index_in_parent = vtpm->index_in_parent;
-       pg->vtpms[vtidx] = last;
-       pg->disk_loc.value = 0;
-
-       last_pg->vtpms[last_pg->size - 1] = NULL;
-       last_pg->disk_loc.value = 0;
-       last_pg->size--;
-
-       if (last_pg->size == 0)
-               group->nr_pages--;
-       group->nr_vtpms--;
-       free(vtpm);
-       return 0;
-}
-
-int find_vtpm(struct mem_group **groupp, struct mem_vtpm **vtpmp, const uuid_t uuid)
-{
-       struct mem_group *group;
-       int i, j, k;
-
-       for (i = 0; i < g_mgr->nr_groups; i++) {
-               group = g_mgr->groups[i].v;
-               if (!group)
-                       continue;
-               for (j = 0; j < group->nr_pages; j++) {
-                       struct mem_vtpm_page *pg = &group->data[j];
-                       for (k = 0; k < pg->size; k++) {
-                               struct mem_vtpm *vt = pg->vtpms[k];
-                               if (!memcmp(uuid, vt->uuid, 16)) {
-                                       *groupp = group;
-                                       *vtpmp = vt;
-                                       return 0;
-                               }
-                       }
-               }
-       }
-
-       return 1;
-}
diff --git a/stubdom/vtpmmgr/vtpm_disk.h b/stubdom/vtpmmgr/vtpm_disk.h
deleted file mode 100644 (file)
index a567265..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-#ifndef __VTPM_DISK_H
-#define __VTPM_DISK_H
-
-#include "uuid.h"
-#include <polarssl/aes.h>
-#include "endian_int.h"
-
-/* Type for disk sector indexes */
-typedef be32_t sector_t;
-
-/* A TPM authdata entry (160 random bits) */
-struct tpm_authdata {
-       uint8_t bits[20];
-};
-
-/* 160-bit hash (SHA-1) */
-struct hash160 {
-       uint8_t bits[20];
-};
-
-/* 256-bit hash (either SHA256 or SHA512-256) */
-struct hash256 {
-       uint8_t bits[32];
-};
-
-/* 128-bit MAC (AES-128 CMAC) */
-struct mac128 {
-       uint8_t bits[16];
-};
-
-struct key128 {
-       uint8_t bits[16];
-};
-
-/********************************************************************/
-
-/**
- * Unique identifying information for a vTPM group. Once a group has been
- * created, this data will be constant.
- *
- * This structure a component of struct disk_group_sector, stored directly.
- */
-struct group_id_data {
-       uuid_t uuid;
-       uint8_t saa_pubkey[256];
-       uint8_t tpm_aik_public[256];
-       uint8_t tpm_aik_edata[256];
-       struct hash256 rollback_pubkey_hash;
-};
-
-/**
- * Details of a vTPM group that change during normal operation.
- *
- * This structure a component of struct disk_group_sector, stored directly.
- */
-struct group_details {
-       be64_t sequence;
-       be64_t cfg_seq;
-       be64_t flags;
-#define FLAG_ROLLBACK_DETECTED 1
-
-       /* Seal(recovery_seal, PCR16 = H(RECOVERY_KEY)) */
-       uint8_t recovery_data[256];
-};
-
-/**
- * The required input to TPM_Unseal to obtain key data
- *
- * This structure a component of several disk structures, stored directly.
- */
-struct disk_seal_entry {
-       le32_t pcr_selection;
-       struct hash160 digest_at_seal;
-       struct hash160 digest_release;
-       uint8_t sealed_data[256];
-};
-
-/**
- * A vTPM group's configuration list and sealed key data
- *
- * This structure a component of struct disk_group_sector, stored directly.
- */
-struct disk_group_boot_config_list {
-#define NR_SEALS_PER_GROUP 5
-       be32_t nr_cfgs;
-       struct disk_seal_entry entry[NR_SEALS_PER_GROUP];
-#define NR_KERNS_PER_GROUP 16
-       be32_t nr_kerns;
-       struct hash160 kernels[NR_KERNS_PER_GROUP];
-
-       /* TODO support overflow of either nr_cfgs or nr_kerns */
-       struct hash256 next;
-};
-
-/********************************************************************/
-
-#define VTPM_FLAG_ADMIN 1
-#define VTPM_FLAG_DISK_MASK (0xFFFF)
-#define VTPM_FLAG_OPEN (1UL<<31)
-
-/**
- * A single vTPM's in-memory data. Do not free if the open flag is set.
- */
-struct mem_vtpm {
-       uuid_t uuid;
-       uint8_t data[64];
-       uint32_t flags;
-       uint32_t index_in_parent;
-};
-
-/**
- * Shortened form of struct disk_seal_entry
- */
-struct mem_seal {
-       le32_t pcr_selection;
-       struct hash160 digest_release;
-};
-
-/**
- * Maximum number of vTPMs in one sector on the disk.
- *
- * 20 + 64 = 84 bytes per vTPM; 32 bytes overhead from IVs
- * 48*84 + 32 = 4064 bytes
- */
-#define VTPMS_PER_SECTOR 48
-
-/**
- * Decrypted and unpacked version of struct disk_vtpm_sector
- */
-struct mem_vtpm_page {
-       struct hash256 disk_hash;
-       sector_t disk_loc;
-       int size;
-
-       struct mem_vtpm *vtpms[VTPMS_PER_SECTOR];
-};
-
-/**
- * In-memory representation of an open vTPM group
- */
-struct mem_group {
-       struct group_id_data id_data;
-       struct group_details details;
-
-       /* Obtained from sealed data */
-       struct tpm_authdata aik_authdata;
-       struct key128 group_key;
-       struct key128 rollback_mac_key;
-
-       int nr_vtpms;
-       int nr_pages;
-       struct mem_vtpm_page *data;
-
-       int flags;
-#define MEM_GROUP_FLAG_SEAL_VALID 1
-#define MEM_GROUP_FLAG_FIRSTBOOT  2
-       int nr_seals;
-       struct mem_seal *seals;
-
-       sector_t seal_next_loc;
-       struct disk_group_boot_config_list seal_bits;
-};
-
-/**
- * In-memory representation of a vTPM group (open or not)
- */
-struct mem_group_hdr {
-       sector_t disk_loc;
-       struct hash256 disk_hash;
-
-       int disk_nr_inuse;
-       sector_t *disk_inuse;
-
-       struct mem_group *v;
-};
-
-/**
- * In-memory representation of the TPM Manager's permanent data
- */
-struct mem_tpm_mgr {
-       struct key128 tm_key;
-       aes_context tm_key_e;
-       struct key128 nv_key;
-       uuid_t uuid;
-
-       be32_t nvram_slot;
-       struct tpm_authdata nvram_auth;
-       be32_t counter_index;
-       struct tpm_authdata counter_auth;
-       be32_t counter_value;
-
-       uint64_t sequence;
-
-       int active_root;
-
-       int nr_groups;
-       struct mem_group_hdr *groups;
-
-       int root_seals_valid;
-};
-
-int vtpm_storage_init(void);
-int vtpm_load_disk(void);
-int vtpm_new_disk(void);
-
-enum vtpm_sync_depth {
-       SEQ_UPDATE,       /* Just the soft sequence number */
-       CTR_UPDATE,       /* Sequence and TPM counter */
-       GROUP_KEY_UPDATE, /* Group key (and TPM counter) */
-       MGR_KEY_UPDATE,   /* Manager key */
-       CTR_AUTH_UPDATE,  /* TPM counter authdata */
-       NV_AUTH_UPDATE    /* NVRAM authdata */
-};
-
-/*
- * For a full manager key flush, use this ordering of writes:
- *  MGR_KEY_UPDATE
- *  CTR_AUTH_UPDATE
- *  NV_AUTH_UPDATE
- *  CTR_UPDATE or GROUP_KEY_UPDATE
- */
-
-extern struct mem_tpm_mgr *g_mgr;
-
-int vtpm_sync_disk(struct mem_tpm_mgr *mgr, int depth);
-int vtpm_sync_group(struct mem_group *group, int depth);
-int vtpm_sync(struct mem_group *group, struct mem_vtpm *vtpm);
-
-int create_vtpm(struct mem_group *group, struct mem_vtpm **vtpmp, const uuid_t uuid);
-int delete_vtpm(struct mem_group *group, struct mem_vtpm *vtpm);
-int find_vtpm(struct mem_group **groupp, struct mem_vtpm **vtpmp, const uuid_t uuid);
-
-#endif
diff --git a/stubdom/vtpmmgr/vtpm_manager.h b/stubdom/vtpmmgr/vtpm_manager.h
deleted file mode 100644 (file)
index 2d2109d..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef VTPM_MANAGER_H
-#define VTPM_MANAGER_H
-
-#define VTPM_TAG_REQ 0x01c1
-#define VTPM_TAG_REQ2 0x01c2
-#define VTPM_TAG_RSP 0x01c4
-#define VTPM_TAG_RSP2 0x01c5
-#define COMMAND_BUFFER_SIZE 4096
-
-// Header size
-#define VTPM_COMMAND_HEADER_SIZE ( 2 + 4 + 4)
-
-//************************ Command Params ***************************
-#define VTPM_QUOTE_FLAGS_HASH_UUID                  0x00000001
-#define VTPM_QUOTE_FLAGS_VTPM_MEASUREMENTS          0x00000002
-#define VTPM_QUOTE_FLAGS_GROUP_INFO                 0x00000004
-#define VTPM_QUOTE_FLAGS_GROUP_PUBKEY               0x00000008
-
-//************************ Command Codes ****************************
-#define VTPM_ORD_BASE       0x0000
-#define TPM_VENDOR_COMMAND  0x02000000 // TPM Main, part 2, section 17.
-#define VTPM_PRIV_BASE      (VTPM_ORD_BASE | TPM_VENDOR_COMMAND)
-
-/*
- * Non-priviledged VTPM Commands:
- *
- * The PCRs available to read, extend, or quote may be limited to a given vTPM
- * based on a local security policy (this is not yet implemented).
- *
- * vTPMs may request the following commands which will be forwarded directly to
- * the physical TPM:
- *
- *   TPM_ORD_GetRandom
- *   TPM_ORD_PcrRead
- *   TPM_ORD_Extend
- *
- * In addition, the following command are available to all vTPMs:
- */
-
-/**
- * Store a persistent key blob to TPM Manager storage
- * Input:
- *  TPM_TAG         tag          VTPM_TAG_REQ
- *  UINT32          paramSize    total size
- *  UINT32          ordinal      VTPM_ORD_SAVEHASHKEY
- *  BYTE[]          keyblob      52 or 64 bytes of key data
- * Output:
- *  TPM_TAG         tag          VTPM_TAG_RSP
- *  UINT32          paramSize    total size
- *  UINT32          status       return code
- */
-#define VTPM_ORD_SAVEHASHKEY      (VTPM_ORD_BASE + 1)
-/**
- * Load the persistent key blob from TPM Manager storage
- * Input:
- *  TPM_TAG         tag          VTPM_TAG_REQ
- *  UINT32          paramSize    total size
- *  UINT32          ordinal      VTPM_ORD_LOADHASHKEY
- * Output:
- *  TPM_TAG         tag          VTPM_TAG_RSP
- *  UINT32          paramSize    total size
- *  UINT32          status       return code
- *  BYTE[]          keyblob      52 or 64 bytes of key data
- */
-#define VTPM_ORD_LOADHASHKEY      (VTPM_ORD_BASE + 2)
-/**
- * Get a kernel hash of the control domain for this vTPM
- * Input:
- *  TPM_TAG         tag          VTPM_TAG_REQ
- *  UINT32          paramSize    total size
- *  UINT32          ordinal      VTPM_ORD_GET_BOOT_HASH
- * Output:
- *  TPM_TAG         tag          VTPM_TAG_RSP
- *  UINT32          paramSize    total size
- *  UINT32          status       return code
- *  TPM_DIGEST      digest       hash for the initial extend of PCR0
- */
-#define VTPM_ORD_GET_BOOT_HASH    (VTPM_ORD_BASE + 3)
-/**
- * Get a hardware TPM quote for this vTPM.  The quote will use the AIK
- * associated with the group this vTPM was created in. Values specific to the
- * vTPM will be extended to certain resettable PCRs.
- * Additional info can be included when creating the signature by using
- * quoteSelect as PCR selection and by setting flags param. The externData
- * param for TPM_Quote is calculated as:
- * externData = SHA1 (
- *       extraInfoFlags
- *       requestData
- *       [SHA1 (
- *          [SHA1 (UUIDs if requested)]
- *          [SHA1 (vTPM measurements if requested)]
- *          [SHA1 (vTPM group update policy if requested)]
- *          [SHA1 (vTPM group public key if requested)]
- *       ) if flags !=0 ]
- * )
- * The response param pcrValues is an array containing requested hashes used
- * for externData calculation : UUIDs, vTPM measurements, vTPM group update
- * policy, group public key. At the end of these hashes the PCR values are
- * appended.
- *
- * Input:
- *  TPM_TAG         tag          VTPM_TAG_REQ
- *  UINT32          paramSize    total size
- *  UINT32          ordinal      VTPM_ORD_GET_QUOTE
- *  TPM_NONCE       externData   Data to be quoted
- *  PCR_SELECTION   quoteSelect  PCR selection for quote.
- *  UINT32          flags        Bit mask of VTPM_QUOTE_FLAGS_*
- * Output:
- *  TPM_TAG         tag          VTPM_TAG_RSP
- *  UINT32          paramSize    total size
- *  UINT32          status       return code
- *  BYTE[]          signature    256 bytes of signature data
- *  TPM_PCRVALUE[]  pcrValues    Values of additional SHA1 hashes requested,
- *                               concatenated with PCRs selected by the request
- */
-#define VTPM_ORD_GET_QUOTE        (VTPM_ORD_BASE + 4)
-
-/*
- * Resettable PCR values in TPM Manager quotes (VTPM_ORD_GET_QUOTE):
- *
- * PCR#16:
- *     unused - debug PCR
- *
- * PCR#17-19: (cannot be reset by locality 2)
- *     DRTM measurements
- *
- * PCR#20: Remains constant over the life of the vTPM group
- *     SHA1(SAA pubkey)
- *
- * PCR#21: May change during the life; must be approved by SAA
- *     SHA1(TPM_MGR_CFG_LIST)
- *
- * PCR#22: May change during the life; must be in the cfg_list
- *     vTPM kernel build hash (truncated SHA256)
- *     Note: this is currently set to 20 zero bytes
- *
- * PCR#23: Remains constant over the life of the vTPM; system-specific
- *     group UUID || 00 00 00 00
- *     vTPM UUID || 00 00 00 00
- *
- *
- * Group-only PCR values (VTPM_ORD_GROUP_*) are the same except:
- *
- * PCR#22: unused (value is zero)
- * PCR#23:
- *     group UUID || 00 00 00 00
- *
- * The value of externalData for quotes using these PCRs is defined below; it is
- * always a hash whose first 4 bytes identify the rest of the structure.
- *
- *
- * The configuration list signed by a System Approval Agent (SAA) is:
- *
- * TPM_MGR_CFG_LIST:
- *  UINT64               sequence      Monotonic sequence number
- *  UINT32               pltCfgSize    Size of pltCfgs array
- *  TPM_COMPOSITE_HASH[] pltCfgs       Valid platform configurations
- *  UINT32               kernSize      Size of kernList array
- *  TPM_HASH[]           kernList      Valid vTPM kernels
- */
-
-/************************************\
- * TPM Manager Management Interface *
-\************************************/
-
-/**
- * List groups
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_LIST
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  UINT32            count        number of valid groups
- */
-#define VTPM_ORD_GROUP_LIST        (VTPM_PRIV_BASE + 0x101)
-/**
- * Create a group
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_NEW
- *  TPM_CHOSENID_HASH labelDigest  Data for the privacy CA
- *  BYTE[256]         SAASigKey    RSA public signature key for the SAA
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[16]          groupUUID    UUID for the group
- *  BYTE[256]         aikPubKey    Public key of the AIK
- *  BYTE[256]         aikBinding   TPM_IDENTITY_CONTENTS signature
- */
-#define VTPM_ORD_GROUP_NEW         (VTPM_PRIV_BASE + 0x102)
-/**
- * Delete a group
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_DEL
- *  UINT32            groupID      ID of the group to delete
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- */
-#define VTPM_ORD_GROUP_DEL         (VTPM_PRIV_BASE + 0x103)
-/**
- * Activate the group's AIK (message from privacy CA)
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_ACTIVATE
- *  UINT32            groupID      ID of the group to activate
- *  UINT32            blobSize
- *  BYTE[]            blob         Blob from the privay CA
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  TPM_SYMMETRIC_KEY key          Output from TPM_ActivateIdentity
- */
-#define VTPM_ORD_GROUP_ACTIVATE    (VTPM_PRIV_BASE + 0x104)
-/**
- * Register this TPM manager slot with the SAA and provision its recovery data.
- * The initial registration must be done with no reboots between the creation of
- * the group and the execution of this command; it can only be done once.
- *
- * The ExternalData value is SHA1("REGR" || dhkx_1 || dhkx_2 || recoverBlob)
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_REGISTER
- *  UINT32            groupID      ID of the group to register
- *  BYTE[256]         dhkx_1       One half of a diffie-hellman key exchange
- *  BYTE[256]         SAAProof     Signature (using SAASigKey) of derivData
- *  PCR_SELECTION     quoteSelect  PCR selection for quote.
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[256]         dhkx_2       One half of a diffie-hellman key exchange
- *  BYTE[32]          recoverBlob  Encrypted blob (using key derived from DH)
- *  BYTE[256]         regProof     Quote using the group's AIK
- */
-#define VTPM_ORD_GROUP_REGISTER    (VTPM_PRIV_BASE + 0x105)
-/**
- * Update the configuration list
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_UPDATE
- *  UINT32            groupID      ID of the group to update
- *  BYTE[256]         cfgListSig   Signature (using SAASigKey) of cfgList
- *  TPM_MGR_CFG_LIST  cfgList      Configurations the group is valid in
- *  PCR_SELECTION[]   selForCfgs   PCR selections used in the cfgList.pltCfgs
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- */
-#define VTPM_ORD_GROUP_UPDATE      (VTPM_PRIV_BASE + 0x106)
-/**
- * Get the current contents of the group structure.
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_SHOW
- *  UINT32            groupID      ID of the group to view
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[16]          groupUUID    UUID for the group
- *  BYTE[256]         pubkey       public key of the SAA
- *  TPM_MGR_CFG_LIST  cfgList      current list for this group
- */
-#define VTPM_ORD_GROUP_SHOW        (VTPM_PRIV_BASE + 0x107)
-/**
- * Get a quote of the current status of the TMA structure. This can be used to
- * prove that an update has been applied; it is similar to VTPM_ORD_GET_QUOTE,
- * but does not include measurements specific to any vTPM.
- *
- * The ExternalData value for the quote is SHA1("SHOW" || nonce)
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_QUOTE
- *  UINT32            groupID      ID of the group to view
- *  TPM_NONCE         nonce        Anti-replay
- *  PCR_SELECTION     quoteSelect  PCR selection for quote.
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[]            signature    256 bytes of signature data
- *  TPM_PCRVALUE[]    pcrValues    Values of PCRs selected by the request
- */
-#define VTPM_ORD_GROUP_QUOTE       (VTPM_PRIV_BASE + 0x108)
-/**
- * Prepare to use recovery data to open a currently-closed group.
- *
- * The ExternalData value is SHA1("RCVR" || nonce || dhkx_1)
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_RECOVER1
- *  UINT32            groupID      ID of the group to recover
- *  TPM_KEY           proxyAIK     AIK to use for recovery quote
- *  TPM_NONCE         nonce        Anti-replay by challenger
- *  PCR_SELECTION     quoteSelect  PCR selection for quote
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[256]         dhkx_1       One half of a diffie-hellman key exchange
- *  BYTE[256]         signature    quote using proxyAIK
- */
-#define VTPM_ORD_GROUP_RECOVER1    (VTPM_PRIV_BASE + 0x109)
-/**
- * Use recovery data to open a currently-closed group
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_GROUP_RECOVER2
- *  UINT32            groupID      ID of the group to recover
- *  BYTE[256]         dhkx_2       One half of a diffie-hellman key exchange
- *  BYTE[32]          recoverBlob  Encrypted blob (using key derived from DH)
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- */
-#define VTPM_ORD_GROUP_RECOVER2    (VTPM_PRIV_BASE + 0x10A)
-
-/**
- * List the UUIDs of vTPMs in an group. Multiple calls may be required to list
- * all the vTPMs in an group; if the returned list is shorter than totalCount
- * would imply, additional requests using the offest will be required
- * to build the full list.
- *
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_VTPM_LIST
- *  UINT32            groupID      ID of the group to list
- *  UINT32            offset       Offset to start the list at
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  UINT32            totalCount   Count of all vTPMs under this group
- *  BYTE[]            uuids        List of UUIDs (16 bytes each)
- */
-#define VTPM_ORD_VTPM_LIST         (VTPM_PRIV_BASE + 0x201)
-#define VTPM_ORD_VTPM_SHOW         (VTPM_PRIV_BASE + 0x202)
-#define VTPM_ORD_VTPM_EDIT         (VTPM_PRIV_BASE + 0x203)
-/**
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_VTPM_NEW
- *  UINT32            groupID      ID of the group to modify
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- *  BYTE[16]          vtpmUUID     UUID for the vTPM
- */
-#define VTPM_ORD_VTPM_NEW          (VTPM_PRIV_BASE + 0x204)
-/**
- * Input:
- *  TPM_TAG           tag          VTPM_TAG_REQ2
- *  UINT32            paramSize    total size
- *  UINT32            ordinal      VTPM_ORD_VTPM_DEL
- ## UINT32            groupID      ID of the group to modify
- *  BYTE[16]          vtpmUUID     UUID for the vTPM to delete
- * Output:
- *  TPM_TAG           tag          VTPM_TAG_RSP
- *  UINT32            paramSize    total size
- *  UINT32            status       return code
- */
-#define VTPM_ORD_VTPM_DEL          (VTPM_PRIV_BASE + 0x205)
-
-/**
- * Generate an unbound AIK for the pTPM
- *
- * This unbound AIK can be used in the GROUP_RECOVER1 operation.
- */
-#define VTPM_ORD_MakeIdentity      (VTPM_PRIV_BASE + 0x301)
-/**
- * Activate an unbound AIK for the pTPM
- */
-#define VTPM_ORD_ActivateIdentity  (VTPM_PRIV_BASE + 0x302)
-/**
- * Get the EK from the pTPM
- *
- * Used for any AIK activation
- */
-#define VTPM_ORD_ReadPubek         (VTPM_PRIV_BASE + 0x303)
-/**
- * Define an NVRAM slot
- */
-#define VTPM_NV_DefineSpace        (VTPM_PRIV_BASE + 0x304)
-/**
- * Write to NVRAM
- */
-#define VTPM_NV_WriteValue         (VTPM_PRIV_BASE + 0x305)
-/**
- * Read from NVRAM
- */
-#define VTPM_NV_ReadValue          (VTPM_PRIV_BASE + 0x306)
-
-
-//************************ Return Codes ****************************
-#define VTPM_SUCCESS               0
-#define VTPM_FAIL                  1
-#define VTPM_UNSUPPORTED           2
-#define VTPM_FORBIDDEN             3
-#define VTPM_RESTORE_CONTEXT_FAILED    4
-#define VTPM_INVALID_REQUEST       5
-
-#endif
diff --git a/stubdom/vtpmmgr/vtpmmgr.c b/stubdom/vtpmmgr/vtpmmgr.c
deleted file mode 100644 (file)
index 9fddaa2..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stdint.h>
-#include <mini-os/tpmback.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "log.h"
-
-#include "vtpmmgr.h"
-#include "tcg.h"
-
-struct tpm_hardware_version hardware_version = {
-    .hw_version = TPM1_HARDWARE,
-};
-
-int parse_cmdline_hw(int argc, char** argv)
-{
-    int i;
-
-    for (i = 1; i < argc; ++i) {
-        if (!strcmp(argv[i], TPM2_EXTRA_OPT)) {
-            hardware_version.hw_version = TPM2_HARDWARE;
-            break;
-        }
-    }
-    return 0;
-}
-
-int hw_is_tpm2(void)
-{
-    return (hardware_version.hw_version == TPM2_HARDWARE) ? 1 : 0;
-}
-
-void main_loop(void) {
-   tpmcmd_t* tpmcmd;
-   uint8_t respbuf[TCPA_MAX_BUFFER_LENGTH];
-
-   while(1) {
-      /* Wait for requests from a vtpm */
-      vtpmloginfo(VTPM_LOG_VTPM, "Waiting for commands from vTPM's:\n");
-      if((tpmcmd = tpmback_req_any()) == NULL) {
-         vtpmlogerror(VTPM_LOG_VTPM, "NULL tpmcmd\n");
-         continue;
-      }
-
-      tpmcmd->resp = respbuf;
-
-      /* Process the command */
-      vtpmmgr_handle_cmd(tpmcmd->opaque, tpmcmd);
-
-      /* Send response */
-      tpmback_resp(tpmcmd);
-   }
-}
-
-int main(int argc, char** argv)
-{
-   int rc = 0;
-   sleep(2);
-   vtpmloginfo(VTPM_LOG_VTPM, "Starting vTPM manager domain\n");
-
-    /*Parse TPM hardware in extra command line*/
-    parse_cmdline_hw(argc, argv);
-
-    /* Initialize the vtpm manager */
-    if (hw_is_tpm2()) {
-        vtpmloginfo(VTPM_LOG_VTPM, "Hardware : --- TPM 2.0 ---\n");
-        if (vtpmmgr2_init(argc, argv) != TPM_SUCCESS) {
-            vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize vtpmmgr domain!\n");
-            rc = -1;
-            goto exit;
-        }
-    }else{
-        vtpmloginfo(VTPM_LOG_VTPM, "Hardware : --- TPM 1.x ---\n");
-        if (vtpmmgr_init(argc, argv) != TPM_SUCCESS) {
-            vtpmlogerror(VTPM_LOG_VTPM, "Unable to initialize vtpmmgr domain!\n");
-            rc = -1;
-            goto exit;
-        }
-    }
-
-   main_loop();
-
-   vtpmloginfo(VTPM_LOG_VTPM, "vTPM Manager shutting down...\n");
-
-   vtpmmgr_shutdown();
-
-exit:
-   return rc;
-
-}
diff --git a/stubdom/vtpmmgr/vtpmmgr.h b/stubdom/vtpmmgr/vtpmmgr.h
deleted file mode 100644 (file)
index 2e6f8de..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2010-2012 United States Government, as represented by
- * the Secretary of Defense.  All rights reserved.
- *
- * based off of the original tools/vtpm_manager code base which is:
- * Copyright (c) 2005, Intel Corp.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *   * Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above
- *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials provided
- *     with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its
- *     contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef VTPMMGR_H
-#define VTPMMGR_H
-
-#include <mini-os/tpmback.h>
-#include <polarssl/entropy.h>
-#include <polarssl/ctr_drbg.h>
-
-#include "uuid.h"
-#include "tcg.h"
-#include "vtpm_manager.h"
-#include "tpm2_types.h"
-
-#define TPM2_EXTRA_OPT "tpm2=1"
-#define RSA_KEY_SIZE 0x0800
-#define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8)
-
-enum {
-    TPM1_HARDWARE = 1,
-    TPM2_HARDWARE,
-} tpm_version;
-
-struct tpm_hardware_version {
-    int hw_version;
-};
-
-extern struct tpm_hardware_version hardware_version;
-
-struct vtpm_globals {
-   int tpm_fd;
-   TPM_AUTH_SESSION    oiap;                // OIAP session for storageKey
-
-   TPM_AUTHDATA        owner_auth;
-   TPM_AUTHDATA        srk_auth;
-
-   entropy_context     entropy;
-   ctr_drbg_context    ctr_drbg;
-
-   int hw_locality;
-
-    /* TPM 2.0 */
-    TPM_AuthArea       pw_auth;
-    TPM_AuthArea       srk_auth_area;
-    TPM2_HANDLE        srk_handle;
-    TPM2_HANDLE        sk_handle;
-    TPM2B_NAME         sk_name;
-    TPM2_RSA_KEY       tpm2_storage_key;
-};
-
-struct tpm_opaque {
-       uuid_t *uuid;
-       struct mem_group *group;
-       struct mem_vtpm *vtpm;
-
-       domid_t domid;
-       unsigned int handle;
-
-       uint8_t kern_hash[20];
-};
-
-// --------------------------- Global Values --------------------------
-extern struct vtpm_globals vtpm_globals;   // Key info and DMI states
-
-TPM_RESULT vtpmmgr_init(int argc, char** argv);
-void vtpmmgr_shutdown(void);
-
-TPM_RESULT vtpmmgr_handle_cmd(struct tpm_opaque *opq, tpmcmd_t* tpmcmd);
-
-inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {
-   return ctr_drbg_random(&vtpm_globals.ctr_drbg, bytes, num_bytes) == 0 ? 0 : TPM_FAIL;
-}
-
-/* TPM 2.0 */
-TPM_RC tpm2_take_ownership(void);
-TPM_RC tpm2_pcr_read(int index, uint8_t *buf);
-TPM_RESULT vtpmmgr2_create(void);
-TPM_RESULT vtpmmgr2_init(int argc, char** argv);
-int parse_cmdline_hw(int argc, char** argv);
-int hw_is_tpm2(void);
-
-#endif
diff --git a/stubdom/xenstore-minios.cfg b/stubdom/xenstore-minios.cfg
deleted file mode 100644 (file)
index 6a09cce..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-CONFIG_BLKFRONT=n
-CONFIG_NETFRONT=n
-CONFIG_FBFRONT=n
-CONFIG_KBDFRONT=n
-CONFIG_CONSFRONT=n
-CONFIG_XENBUS=n
-CONFIG_LWIP=n