factory_install: Also look for model name as cros_payload entry
If <model>.json in cros_payloads/ exists, use it as the cros_payload
metadata. Otherwise fall back to use <board>.json.
This opens a way to create an RMA shim that has different payloads for
different models that belongs to the same board, without changing the
RMA shim structure and image_tool. We can create RMA shims and set the
model model name in `--board` argument, and merge them into a
multi-board shim. A problem for this approach is that all kernels have the
same signing key and bootable on the devices, so only the first kernel
will be used, but it will not be a problem if all models are using
identical factory shims.
BUG=chromium:960249
TEST=manually test on DUT
Change-Id: I1b121a6f2c172cfc7fd07df2e7f889bb983b63f0
Reviewed-on: https://chromium-review.googlesource.com/1806641
Tested-by: Cheng-Han Yang <chenghan@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
Reviewed-by: Kevin Lin <kevinptt@chromium.org>
diff --git a/factory_cros_payload.sh b/factory_cros_payload.sh
index 365948f..fdb8bbe 100644
--- a/factory_cros_payload.sh
+++ b/factory_cros_payload.sh
@@ -8,27 +8,45 @@
. "$(dirname "$0")/factory_common.sh"
+# Get the cros_payload metadata by searching for model and board names.
+cros_payload_metadata() {
+ local src_media="$1"
+ local payloads_dir="$2"
+ local model="$(mosys platform model)"
+ local model_json_path="${payloads_dir}/${model}.json"
+ local board="$(findLSBValue CHROMEOS_RELEASE_BOARD)"
+ local board_json_path="${payloads_dir}/${board}.json"
+ if [ -e "${src_media}/${model_json_path}" ]; then
+ echo "${model_json_path}"
+ elif [ -e "${src_media}/${board_json_path}" ]; then
+ echo "${board_json_path}"
+ fi
+}
+
# Patch dev_image/etc/lsb-factory using lsb_factory payload.
cros_payload_patch_lsb_factory() {
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_lsb_factory="$(mktemp)"
+ local mount_point="$(mktemp -d)"
+ mount -o ro "${stateful_dev}" "${mount_point}"
echo 'Patching lsb-factory...'
- mount -o ro "${stateful_dev}" "${mount_point}"
- # If the RMA shim doesn't have lsb_factory payload, this command will fail,
- # leaving temp_lsb_factory empty.
- cros_payload install "${json_path}" "${temp_lsb_factory}" lsb_factory || true
+ local json_path="$(cros_payload_metadata "${mount_point}" 'cros_payloads')"
+ local json_url="${mount_point}/${json_path}"
+ if [ -n "${json_url}" ]; then
+ # If the RMA shim doesn't have lsb_factory payload, this command will fail,
+ # leaving temp_lsb_factory empty.
+ cros_payload install "${json_url}" "${temp_lsb_factory}" lsb_factory ||
+ true
+ # Append to lsb-factory file.
+ cat "${temp_lsb_factory}" >>"${LSB_FACTORY_FILE}"
+ fi
+
umount "${stateful_dev}"
rmdir "${mount_point}"
-
- # Append to lsb-factory file.
- cat "${temp_lsb_factory}" >>"${LSB_FACTORY_FILE}"
rm "${temp_lsb_factory}"
}
@@ -37,30 +55,32 @@
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_config_path="$(mktemp)"
+ local mount_point="$(mktemp -d)"
+ mount -o ro "${stateful_dev}" "${mount_point}"
echo 'Patching cutoff config...'
- # Get cutoff config in cros_payload.
- mount -o ro "${stateful_dev}" "${mount_point}"
- cros_payload install "${json_path}" "${temp_config_path}" toolkit_config ||
- true
+ local json_path="$(cros_payload_metadata "${mount_point}" 'cros_payloads')"
+ local json_url="${mount_point}/${json_path}"
+ if [ -n "${json_url}" ]; then
+ # Get toolkit config in cros_payload.
+ cros_payload install "${json_url}" "${temp_config_path}" toolkit_config ||
+ true
+ # Get cutoff config from toolkit config.
+ local cutoff_config=""
+ if [ -s "${temp_config_path}" ]; then
+ cutoff_config="$(
+ jq -s '.[].cutoff | select(. != null)' "${temp_config_path}")"
+ fi
+ # Overwrite board-specific cutoff config (see factory/sh/cutoff/options.sh).
+ if [ -n "${cutoff_config}" ]; then
+ local config_path="/usr/share/cutoff/cutoff.json"
+ echo "${cutoff_config}" >"${config_path}"
+ fi
+ fi
+
umount "${stateful_dev}"
rmdir "${mount_point}"
-
- local cutoff_config=""
- if [ -s "${temp_config_path}" ]; then
- cutoff_config="$(
- jq -s '.[].cutoff | select(. != null)' "${temp_config_path}")"
- fi
rm "${temp_config_path}"
-
- # Overwrite board-specific cutoff config (see factory/sh/cutoff/options.sh).
- if [ -n "${cutoff_config}" ]; then
- local config_path="/usr/share/cutoff/cutoff.json"
- echo "${cutoff_config}" >"${config_path}"
- fi
}
diff --git a/factory_install.sh b/factory_install.sh
index 61d986d..75f0a96 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -830,9 +830,19 @@
# Switch to stateful partition.
# shellcheck disable=SC2001
- src_dev="$(echo "${src_dev}" | sed 's/[0-9]\+$/1/')"
+ local stateful_dev="$(echo "${src_dev}" | sed 's/[0-9]\+$/1/')"
- factory_install_cros_payload "${src_dev}" "cros_payloads/${BOARD}.json"
+ local mount_point="$(mktemp -d)"
+ mount -o ro "${stateful_dev}" "${mount_point}"
+ local json_path="$(cros_payload_metadata "${mount_point}" 'cros_payloads')"
+ umount "${stateful_dev}"
+ rmdir "${mount_point}"
+
+ if [ -n "${json_path}" ]; then
+ factory_install_cros_payload "${stateful_dev}" "${json_path}"
+ else
+ die "Cannot find cros_payload metadata."
+ fi
}
factory_install_network() {