factory_install: Patch description with cros_payload and show on screen.

We copy the content of description file in cros_payload to the file in
stateful partition, and show it in the screen.

BUG=b:141155378
TEST=test on DUT

Cq-Depend: chromium:1899029
Change-Id: I50df8b2d9bcd497d6cb6fe390d2b09fc82e335d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory_installer/+/1844892
Commit-Queue: Kevin Lin <kevinptt@chromium.org>
Auto-Submit: Kevin Lin <kevinptt@chromium.org>
Reviewed-by: Cheng-Han Yang <chenghan@chromium.org>
Tested-by: Kevin Lin <kevinptt@chromium.org>
(cherry picked from commit a10dec41490ccf63a4e61c2f92c6eb78a9f21ffd)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/factory_installer/+/1900868
diff --git a/factory_common.sh b/factory_common.sh
index 6e3ec93..8d6482b 100644
--- a/factory_common.sh
+++ b/factory_common.sh
@@ -7,6 +7,7 @@
 
 LSB_RELEASE_FILE=/etc/lsb-release
 LSB_FACTORY_FILE=/mnt/stateful_partition/dev_image/etc/lsb-factory
+DESCRIPTION_FILE=/mnt/stateful_partition/dev_image/etc/description
 
 # Returns the key for "key=value" format string.
 getLSBKey() {
diff --git a/factory_install.sh b/factory_install.sh
index 60827ab..c773eb7 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -29,6 +29,29 @@
   echo "http://${removed_path}"
 }
 
+# Install dev_image/etc/description from description payload.
+install_description() {
+  local real_usb_dev="$(findLSBValue REAL_USB_DEV)"
+  [ -n "${real_usb_dev}" ] || return 0
+  local stateful_dev=${real_usb_dev%[0-9]*}1
+  local mount_point="$(mktemp -d)"
+  local board="$(findLSBValue CHROMEOS_RELEASE_BOARD)"
+  local json_path="${mount_point}/cros_payloads/${board}.json"
+  local temp_path="$(mktemp)"
+
+  echo 'Installing description...'
+
+  mount -o ro "${stateful_dev}" "${mount_point}"
+  cros_payload install_optional "${json_path}" "${temp_path}" description
+  umount "${stateful_dev}"
+  rmdir "${mount_point}"
+
+  cat "${temp_path}" >"${DESCRIPTION_FILE}"
+  rm "${temp_path}"
+}
+
+install_description
+
 # Variables from dev_image/etc/lsb-factory that developers may want to override.
 #
 # - Override this if we want to install with a board different from installer
@@ -937,6 +960,12 @@
     echo -n "Cr50 version: $(get_cr50_rw_version); "
     echo "Board ID flags: 0x$(get_cr50_board_id_flags)"
     echo
+    local description=""
+    if [ -s "${DESCRIPTION_FILE}" ]; then
+      description="$(cat "${DESCRIPTION_FILE}" 2>/dev/null)"
+      echo "${description}"
+      echo
+    fi
 }
 
 # Displays a line in the menu.  Used in the menu function.