scripts: support for optional hypervisor kernel.

BUG=b:145357269
TEST=build and update eve-manatee with/without hypervisor.

Change-Id: I0e8aa49f7b13894b598feac444ad2f11622532b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2391302
Tested-by: Tomasz Jeznach <tjeznach@chromium.org>
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh
index d506718..a00576c 100755
--- a/build_library/base_image_util.sh
+++ b/build_library/base_image_util.sh
@@ -499,16 +499,28 @@
   else
     cpmv="mv"
   fi
-  [ -e "${root_fs_dir}"/boot/Image-* ] && \
-    sudo "${cpmv}" "${root_fs_dir}"/boot/Image-* "${BUILD_DIR}/boot_images"
-  [ -L "${root_fs_dir}"/boot/zImage-* ] && \
-    sudo "${cpmv}" "${root_fs_dir}"/boot/zImage-* "${BUILD_DIR}/boot_images"
-  [ -e "${root_fs_dir}"/boot/vmlinuz-* ] && \
-    sudo "${cpmv}" "${root_fs_dir}"/boot/vmlinuz-* "${BUILD_DIR}/boot_images"
-  [ -L "${root_fs_dir}"/boot/vmlinuz ] && \
-    sudo "${cpmv}" "${root_fs_dir}"/boot/vmlinuz "${BUILD_DIR}/boot_images"
-  [ -L "${root_fs_dir}"/boot/vmlinux.uimg ] && \
-    sudo "${cpmv}" "${root_fs_dir}"/boot/vmlinux.uimg \
+
+  # Bootable kernel image for ManaTEE enabled targets is located at
+  # directory /build/manatee/boot and included only in bootable partition.
+  # If no manatee USE flag is specified the standard /boot location
+  # is used, optionally including kernel image in final build image.
+  local boot_dir
+  if has "manatee" "$(portageq-${FLAGS_board} envvar USE)"; then
+    boot_dir="${root_fs_dir}/build/manatee/boot"
+  else
+    boot_dir="${root_fs_dir}/boot"
+  fi
+
+  [ -e "${boot_dir}"/Image-* ] && \
+    sudo "${cpmv}" "${boot_dir}"/Image-* "${BUILD_DIR}/boot_images"
+  [ -L "${boot_dir}"/zImage-* ] && \
+    sudo "${cpmv}" "${boot_dir}"/zImage-* "${BUILD_DIR}/boot_images"
+  [ -e "${boot_dir}"/vmlinuz-* ] && \
+    sudo "${cpmv}" "${boot_dir}"/vmlinuz-* "${BUILD_DIR}/boot_images"
+  [ -L "${boot_dir}"/vmlinuz ] && \
+    sudo "${cpmv}" "${boot_dir}"/vmlinuz "${BUILD_DIR}/boot_images"
+  [ -L "${boot_dir}"/vmlinux.uimg ] && \
+    sudo "${cpmv}" "${boot_dir}"/vmlinux.uimg \
         "${BUILD_DIR}/boot_images"
 
   # Calculate package sizes within the built rootfs for reporting purposes.
diff --git a/update_kernel.sh b/update_kernel.sh
index f872208..113aac5 100755
--- a/update_kernel.sh
+++ b/update_kernel.sh
@@ -154,10 +154,13 @@
 make_kernelimage() {
   local bootloader_path
   local kernel_image
-  local boot_path="/build/${FLAGS_board}/boot"
+  local boot_path="/build/${FLAGS_board}"
   local config_path="$(mktemp /tmp/config.txt.XXXXX)"
-  if [[ ${FLAGS_hv} -eq ${FLAGS_TRUE} && -d "${boot_path}/hv" ]]; then
-    boot_path+="/hv"
+  if [[ ${FLAGS_hv} -eq ${FLAGS_TRUE} && \
+        -d "${boot_path}/build/manatee/boot" ]]; then
+    boot_path+="/build/manatee/boot"
+  else
+    boot_path+="/boot"
   fi
   if [[ "${FLAGS_arch}" == "arm" || "${FLAGS_arch}" == "arm64" ]]; then
     name="bootloader.bin"