scripts: Build DLC images during the build_image phase.

Previously, the DLC images were created at the build_packages phase.
With this change, the build_packages will only build the DLC packages,
and the DLC images will be created at the build_images phase.
The change in is to exclude the DLC files from the rootfs
during emerge to the image and DUT, but ideally, the DLC files should
not be included in tha tarball during the build_package phase at all.

TEST=build_packages, build test image, cros flash local image.

Cq-Depend: chromium:2067295
Change-Id: Ifb827e101d9a1d65a1d1f5b2c6c58b226d240a7f
Tested-by: Andrew Lassalle <>
Commit-Queue: Andrew Lassalle <>
Reviewed-by: Amin Hassani <>
Reviewed-by: Mike Frysinger <>
diff --git a/build_image b/build_image
index f926a5d..3fd2e3a 100755
--- a/build_image
+++ b/build_image
@@ -213,7 +213,7 @@
 # Move the completed image to the output_root.
 move_image "${BUILD_DIR}" "${OUTPUT_DIR}"
-# Move DLC images to the output_root directory.
+# Copy DLC images to the output_root directory.
 build_dlc --sysroot="${BOARD_ROOT}" --install-root-dir="${OUTPUT_DIR}/dlc"
 # Create a named symlink.
diff --git a/build_library/ b/build_library/
index 1f82b08..5696760 100755
--- a/build_library/
+++ b/build_library/
@@ -450,6 +450,9 @@
     create_dev_install_lists "${root_fs_dir}"
+  # Generate DLCs and copy their metadata to the rootfs.
+  build_dlc --sysroot="${BOARD_ROOT}" --rootfs="${root_fs_dir}"
   restore_fs_contexts "${BOARD_ROOT}" "${root_fs_dir}" "${stateful_fs_dir}"
   # Move the bootable kernel images out of the /boot directory to save
diff --git a/build_library/ b/build_library/
index 2fbcab7..a90768f 100755
--- a/build_library/
+++ b/build_library/
@@ -44,9 +44,9 @@
   # Move DLC images to the /var/cache directory. The dlc-images directory will
   # hold DLC(s) that dlcservice will leverage for testing/provisioning.
-  sudo build_dlc --sysroot="${BOARD_ROOT}" \
+  build_dlc --sysroot="${BOARD_ROOT}" \
     --install-root-dir="${root_fs_dir}/var/cache/dlc-images" \
-    --preload
+    --preload --rootfs="${root_fs_dir}"
   trap - EXIT
diff --git a/ b/
index 5c8bf5e..50394e2 100644
--- a/
+++ b/
@@ -391,6 +391,7 @@
+  /build/rootfs/dlc