Support 32-bit EFI boot

Build and install bootia32.efi for use from 32-bit EFI BIOSes, alongside
the bootx64.efi used for 64-bit EFI BIOSes.

BUG=chrome-os-partner:18940
TEST=Built and tested a USB image on a system that only supports
     32-bit EFI boot, not 64-bit EFI boot.
CQ-DEPEND=Ib65f7effe0d09ae8690dcdfff76327e43720eed6

Change-Id: If13cd6c0529ea614c73f6b933450925fc3ca7714
Reviewed-on: https://gerrit.chromium.org/gerrit/49197
Tested-by: Josh Triplett <josh@joshtriplett.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Josh Triplett <josh@joshtriplett.org>
diff --git a/build_library/create_legacy_bootloader_templates.sh b/build_library/create_legacy_bootloader_templates.sh
index 73bcb4c..8cecb94 100755
--- a/build_library/create_legacy_bootloader_templates.sh
+++ b/build_library/create_legacy_bootloader_templates.sh
@@ -159,13 +159,23 @@
 
   if [[ -f /bin/grub2-mkimage ]];then
     # Use the newer grub2 1.99+
-    sudo grub2-mkimage -p /efi/boot -O x86_64-efi \
-     -o "${FLAGS_to}/efi/boot/bootx64.efi" \
-     part_gpt fat ext2 hfs hfsplus normal boot chain configfile linux
+    grub_args=(
+      -p /efi/boot
+      part_gpt fat ext2 hfs hfsplus normal boot chain configfile linux
+    )
+    sudo grub2-mkimage -O x86_64-efi \
+      -o "${FLAGS_to}/efi/boot/bootx64.efi" "${grub_args[@]}"
+    sudo i386-grub2-mkimage -O i386-efi \
+      -o "${FLAGS_to}/efi/boot/bootia32.efi" "${grub_args[@]}"
   else
     # Remove this else case after a few weeks (sometime in Dec 2011)
-    sudo grub-mkimage -p /efi/boot -o "${FLAGS_to}/efi/boot/bootx64.efi" \
-     part_gpt fat ext2 normal boot sh chain configfile linux
+    grub_args=(
+      -p /efi/boot
+      part_gpt fat ext2 normal boot sh chain configfile linux
+    )
+    sudo grub-mkimage -o "${FLAGS_to}/efi/boot/bootx64.efi" "${grub_args[@]}"
+    sudo i386-grub-mkimage -o "${FLAGS_to}/efi/boot/bootia32.efi" \
+      "${grub_args[@]}"
   fi
   # Templated variables:
   #  DMTABLEA, DMTABLEB -> '0 xxxx verity ... '
diff --git a/update_bootloaders.sh b/update_bootloaders.sh
index 37053ed..7738725 100755
--- a/update_bootloaders.sh
+++ b/update_bootloaders.sh
@@ -161,10 +161,7 @@
 if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
   # Populate the EFI bootloader configuration
   sudo mkdir -p "${ESP_FS_DIR}/efi/boot"
-  sudo cp "${FLAGS_from}"/efi/boot/bootx64.efi \
-          "${ESP_FS_DIR}/efi/boot/bootx64.efi"
-  sudo cp "${FLAGS_from}/efi/boot/grub.cfg" \
-          "${ESP_FS_DIR}/efi/boot/grub.cfg"
+  sudo cp -r "${FLAGS_from}"/efi/boot/. "${ESP_FS_DIR}"/efi/boot
 
   # Prepopulate the syslinux directories too and update for verified boot values
   # after the rootfs work is done.