BLKID_LINES=()
+function print_time()
+{
+ echo "$1 $(cat /proc/timer_list | grep now)"
+}
+
function get_blk_dev_path()
{
PART_REGEX="(^|[ ])$1($|[ ])"
function vendor_setup()
{
+ local types=()
+ local types_success=()
local dirs=()
+ local pids=()
+ local vendor_mnt_dirs=()
+ local vendor_mnt_dirs_success=()
local vendor_img_basedir="${DATAFS_MNT}"/vendor
- local vendor_mnt_basedir="${DATAFS_MNT}"/vendor/mnt
local pub_key="${ROOTFS_MNT}"/etc/vendor/pub.pem
if [ ! -d "${vendor_img_basedir}"/hal ] && [ ! -d "${vendor_img_basedir}"/platform ]; then
continue
fi
- local file_info="${vendor_img_dir}".info
- local file_sign="${vendor_img_dir}".sign
+ types+=("${type}")
- if ! openssl dgst -sha256 -verify "${pub_key}" -signature "${file_sign}" "${file_info}" > /dev/null 2>&1; then
- echo "WARNING: Failed to verify ${file_info}. Will not setup ${vendor_img_dir}"
- continue
- fi
-
- local hash_offset=""
- local root_hash=""
-
- while IFS= read -r line; do
- if [[ "${line}" == hash_offset* ]]; then
- hash_offset="${line#*=}"
- elif [[ "${line}" == root_hash* ]]; then
- root_hash="${line#*=}"
- fi
- done < "${file_info}"
-
- if [ -z "${hash_offset}" ] || [ -z "${root_hash}" ]; then
- echo "WARNING: ${hash_offset} and/or ${root_hash} are empty. Will not setup ${vendor_img_dir}"
- continue
- fi
+ local vendor_mnt_dir="${DATAFS_MNT}"/vendor/mnt/"${type}"/"${priority}"
+ vendor_mnt_dirs+=("${vendor_mnt_dir}")
local loop_device="/dev/loop${loop_device_no}"
loop_device_no=$((loop_device_no+1))
+ /usr/sbin/mount_dm_verity.sh "${vendor_img_dir}" "${vendor_mnt_dir}" "${loop_device}" "${pub_key}" &
+ pids+=("$!")
+ done
- if ! /usr/sbin/losetup "${loop_device}" "${vendor_img_dir}"; then
- echo "WARNING: Unable to set up a loop device for ${vendor_img_dir}. Will not setup ${vendor_img_dir}"
- continue
- fi
-
- if ! /usr/sbin/veritysetup open --hash-offset="${hash_offset}" "${loop_device}" "${vendor_img}" "${loop_device}" "${root_hash}"; then
- echo "WARNING: Failed to create dm-verity mapping for ${vendor_img}. Will not setup ${vendor_img_dir}"
- continue
- fi
-
- local vendor_mnt_dir="${vendor_mnt_basedir}"/"${type}"/"${priority}"
-
- if ! mkdir -p "${vendor_mnt_dir}"; then
- echo "WARNING: Unable to create ${vendor_mnt_basedir}/${type}/${priority}. Will not setup ${vendor_img_dir}"
- continue
- fi
-
- if ! mount /dev/mapper/"${vendor_img}" "${vendor_mnt_dir}"; then
- echo "WARNING: Unable to mount /dev/mapper/${vendor_img_dir} in ${vendor_mnt_dir}. Will not setup ${vendor_img_dir}"
- continue
+ local cnt=0
+ for pid in "${pids[@]}"; do
+ if wait "${pid}"; then
+ vendor_mnt_dirs_success+=("${vendor_mnt_dirs["${cnt}"]}")
+ types_success+=("${types["${cnt}"]}")
fi
-
- for entry in "${vendor_mnt_dir}"/*; do
+ cnt=$((cnt+1))
+ done
+
+ cnt=0
+ for vendor_mnt_dir_success in "${vendor_mnt_dirs_success[@]}"; do
+ for entry in "${vendor_mnt_dir_success}"/*; do
if [ ! -d "${entry}" ]; then
continue
fi
continue
fi
- if [ "${type}" = "hal" ] && [ "${dir}" != "hal" ]; then
+ if [ "${types_success["${cnt}"]}" = "hal" ] && [ "${dir}" != "hal" ]; then
continue
fi
- if [ "${type}" = "platform" ] && [ "${dir}" = "hal" ]; then
+ if [ "${types_success["${cnt}"]}" = "platform" ] && [ "${dir}" = "hal" ]; then
continue
fi
dirs+=("${dir}")
fi
- tmp_lowerdir+="${vendor_mnt_dir}"/"${dir}"
+ tmp_lowerdir+="${vendor_mnt_dir_success}"/"${dir}"
declare "lowerdirs_$dir=$tmp_lowerdir"
done
+ cnt=$((cnt+1))
echo "${vendor_img_dir} is ready to be used for overlaying."
done
fi
vendor_setup
+ print_time initrd_stop
if [ $$ = 1 ]
then
source /sbin/init.container
fi
+print_time initrd_start
print_boot_info
wait_find_partitions
--- /dev/null
+#!/bin/bash
+
+vendor_img_dir=$1
+vendor_img=${vendor_img_dir##*/}
+vendor_mnt_dir=$2
+loop_device=$3
+pub_key=$4
+
+file_info="${vendor_img_dir}".info
+file_sign="${vendor_img_dir}".sign
+
+if ! openssl dgst -sha256 -verify "${pub_key}" -signature "${file_sign}" "${file_info}" > /dev/null 2>&1; then
+ echo "WARNING: Failed to verify ${file_info}. Will not setup ${vendor_img_dir}"
+ exit 1
+fi
+
+hash_offset=""
+root_hash=""
+
+while IFS= read -r line; do
+ if [[ "${line}" == hash_offset* ]]; then
+ hash_offset="${line#*=}"
+ elif [[ "${line}" == root_hash* ]]; then
+ root_hash="${line#*=}"
+ fi
+done < "${file_info}"
+
+if [ -z "${hash_offset}" ] || [ -z "${root_hash}" ]; then
+ echo "WARNING: ${hash_offset} and/or ${root_hash} are empty. Will not setup ${vendor_img_dir}"
+ exit 1
+fi
+
+if ! /usr/sbin/losetup "${loop_device}" "${vendor_img_dir}"; then
+ echo "WARNING: Unable to set up a loop device for ${vendor_img_dir}. Will not setup ${vendor_img_dir}"
+ exit 1
+fi
+
+if ! /usr/sbin/veritysetup open --hash-offset="${hash_offset}" "${loop_device}" "${vendor_img}" "${loop_device}" "${root_hash}"; then
+ echo "WARNING: Failed to create dm-verity mapping for ${vendor_img}. Will not setup ${vendor_img_dir}"
+ exit 1
+fi
+
+if ! mkdir -p "${vendor_mnt_dir}"; then
+ echo "WARNING: Unable to create ${vendor_mnt_dir}. Will not setup ${vendor_img_dir}"
+ exit 1
+fi
+
+if ! mount /dev/mapper/"${vendor_img}" "${vendor_mnt_dir}"; then
+ echo "WARNING: Unable to mount /dev/mapper/${vendor_img_dir} in ${vendor_mnt_dir}. Will not setup ${vendor_img_dir}"
+ exit 1
+fi