Add support for a SeaBIOS payload

Allow to optionally add a legacy BIOS (SeaBIOS) in front the usual
payload (U-Boot) to allow booting legacy OS for production purpose.

This is an intermediate solution where SeaBIOS is the primary payload
and can trigger the secondary payload (the usual U-Boot) through its
boot menu. We might want to do the opposite later once we have done the
required development in U-Boot.

BUG=chrome-os-partner:6108
TEST=boot FreeDOS and Ubuntu from a USB key on Lumpy

Change-Id: Ibe031bff4fb4e3eda827ac301f90a6b3d2a126fb
Reviewed-on: http://gerrit.chromium.org/gerrit/9969
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
diff --git a/host/cros_bundle_firmware b/host/cros_bundle_firmware
index 084c385..2d0a418 100755
--- a/host/cros_bundle_firmware
+++ b/host/cros_bundle_firmware
@@ -78,7 +78,7 @@
   bundle.SetDirs(keydir=options.key)
   bundle.SetFiles(board=options.board, uboot=options.uboot, bct=options.bct,
                   bmpblk=options.bmpblk, coreboot=options.coreboot,
-                  postload=options.postload)
+                  postload=options.postload, seabios=options.seabios)
   bundle.SetOptions(small=options.small)
 
   try:
@@ -147,6 +147,8 @@
       '(u-boot-post.bin)')
   parser.add_option('-s', '--small', dest='small', action='store_true',
       help='Create/write only the signed U-Boot binary (not the full image)')
+  parser.add_option('-S', '--seabios', dest='seabios', type='string',
+        action='store', help='Legacy BIOS (SeaBIOS)')
   parser.add_option('-u', '--uboot', dest='uboot', type='string',
       action='store', help='Executable bootloader file (U-Boot)')
   parser.add_option('-U', '--uboot-flasher', dest='uboot_flasher',
diff --git a/host/lib/bundle_firmware.py b/host/lib/bundle_firmware.py
index 09b0648..a024eef 100644
--- a/host/lib/bundle_firmware.py
+++ b/host/lib/bundle_firmware.py
@@ -94,6 +94,7 @@
     self.fdt = None             # Our Fdt object.
     self.bmpblk_fname = None    # Filename of our Bitmap Block
     self.coreboot_fname = None  # Filename of our coreboot binary.
+    self.seabios_fname = None   # Filename of our SeaBIOS payload.
 
   def SetDirs(self, keydir):
     """Set up directories required for Bundle.
@@ -104,7 +105,7 @@
     self._keydir = keydir
 
   def SetFiles(self, board, bct, uboot=None, bmpblk=None, coreboot=None,
-               postload=None):
+               postload=None, seabios=None):
     """Set up files required for Bundle.
 
     Args:
@@ -114,6 +115,7 @@
       bmpblk: The filename of bitmap block file to use.
       coreboot: The filename of the coreboot image to use (on x86)
       postload: The filename of the u-boot-post.bin image to use.
+      seabios: The filename of the SeaBIOS payload to use if any.
     """
     self._board = board
     self.uboot_fname = uboot
@@ -121,6 +123,7 @@
     self.bmpblk_fname = bmpblk
     self.coreboot_fname = coreboot
     self.postload_fname = postload
+    self.seabios_fname = seabios
 
   def SetOptions(self, small):
     """Set up options supported by Bundle.
@@ -342,13 +345,14 @@
 
     return bootstub, signed_postload
 
-  def _CreateCorebootStub(self, uboot, coreboot, fdt):
+  def _CreateCorebootStub(self, uboot, coreboot, fdt, seabios):
     """Create a coreboot boot stub.
 
     Args:
       uboot: Path to u-boot.bin (may be chroot-relative)
       coreboot: Path to coreboot.rom
       fdt: Device Tree
+      seabios: Path to SeaBIOS payload binary or None
 
     Returns:
       Full path to bootstub (coreboot + uboot + fdt).
@@ -360,8 +364,14 @@
     cbfstool = "/usr/bin/cbfstool"
     uboot_elf = uboot.replace(".bin", ".elf")
     shutil.copyfile(coreboot, bootstub)
-    self._tools.Run(cbfstool, [bootstub, 'add-payload', uboot_elf,
-        'fallback/payload', 'lzma'])
+    if seabios:
+        self._tools.Run(cbfstool, [bootstub, 'add-payload', seabios,
+            'fallback/payload', 'lzma'])
+        self._tools.Run(cbfstool, [bootstub, 'add-payload', uboot_elf,
+            'img/U-Boot', 'lzma'])
+    else:
+        self._tools.Run(cbfstool, [bootstub, 'add-payload', uboot_elf,
+            'fallback/payload', 'lzma'])
     self._tools.Run(cbfstool, [bootstub, 'add', fdt.fname, 'u-boot.dtb',
         '0xac'])
     return bootstub
@@ -400,7 +410,7 @@
       # signed gets packed into the bootstub, and bootstub gets
       # packed into the RW sections.
       signed = self._CreateCorebootStub(self.uboot_fname,
-          self.coreboot_fname, fdt)
+          self.coreboot_fname, fdt, self.seabios_fname)
       bootstub = self.uboot_fname
     else:
       # Create the boot stub, which is U-Boot plus an fdt and bct