blob: a9d4e39686d2919293bf666d2a8a3a11170a3c47 [file] [log] [blame]
#!/bin/sh
mmc_init() {
base_dir="/media/hostfw"
ro_dir="${base_dir}/running-ro"
running_dir="${base_dir}/running"
prsv_dir="${base_dir}/prsv"
staging_dir="${base_dir}/staging"
if [ ! -d "${ro_dir}" ]; then
mkdir -p "${ro_dir}"
fi
if [ ! -d "${running_dir}" ]; then
mkdir -p ${running_dir}
fi
if [ ! -d "${prsv_dir}" ]; then
mkdir -p "${prsv_dir}"
fi
if [ ! -d "${staging_dir}" ]; then
mkdir -p "${staging_dir}"
fi
# Mount the image that corresponds to the boot label as read-only to be used
# to populate the running directory.
boot_label="$(fw_printenv -n bootside)"
mount ${base_dir}/hostfw-"${boot_label}" ${ro_dir} -o ro
# Determine if the running dir contains the running version
running_label=""
running_label_file="${running_dir}/partlabel"
if [ -f "${running_label_file}" ]; then
running_label=$(cat ${running_label_file})
fi
if [ "${running_label}" != "${boot_label}" ]; then
# Copy off the preserved partitions
# A line in the pnor.toc looks like this:
# partition05=SECBOOT,0x00381000,0x003a5000,00,ECC,PRESERVED
rm -f ${prsv_dir}/*
if [ -f ${running_dir}/pnor.toc ]; then
prsvs=$(grep PRESERVED ${running_dir}/pnor.toc)
for prsv in ${prsvs}; do
prsv=${prsv##partition*=}
prsv=$(echo "${prsv}" | cut -d "," -f 1)
cp -p ${running_dir}/"${prsv}" ${prsv_dir}
done
fi
# Copy contents of running image to running dir
rm -f ${running_dir}/*
cp -p ${ro_dir}/* ${running_dir}/
# Restore the preserved partitions. Ignore error, there may be none.
cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true
rm -f "${prsv_dir:?}/"*
# Clean up the staging dir in case of a failed update
rm -rf "${staging_dir:?}/"*
# Save the label
echo "${boot_label}" > "${running_label_file}"
fi
# Mount alternate dir
if [ "${boot_label}" = "a" ]; then
alternate_label="b"
else
alternate_label="a"
fi
alternate_dir="${base_dir}/alternate"
if [ ! -d "${alternate_dir}" ]; then
mkdir -p ${alternate_dir}
fi
mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro
# setup host firmware runtime well known names
openpower-update-manager process-host-firmware
}
mmc_patch() {
# Patching is disabled if field mode is set
if [ "$(fw_printenv fieldmode 2>/dev/null)" = "fieldmode=true" ]; then
return 0
fi
boot_label="$(fw_printenv -n bootside)"
if [ "${boot_label}" = "a" ]; then
alternate_label="b"
else
alternate_label="a"
fi
# Create patch directories
patch_dir="/media/hostfw/patch-"
running_patch_dir="${patch_dir}${boot_label}"
if [ ! -d "${running_patch_dir}" ]; then
mkdir -p "${running_patch_dir}"
fi
alternate_patch_dir="${patch_dir}${alternate_label}"
if [ ! -d "${alternate_patch_dir}" ]; then
mkdir -p "${alternate_patch_dir}"
fi
# Create patch symlinks
symlink_base="/usr/local/share"
if [ ! -d "${symlink_base}" ]; then
mkdir -p "${symlink_base}"
fi
hostfw_symlink_base="${symlink_base}/hostfw"
if [ ! -d "${hostfw_symlink_base}" ]; then
mkdir -p "${hostfw_symlink_base}"
fi
ln -s "${running_patch_dir}" "${symlink_base}/pnor"
ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
}
case "$1" in
mmc-init)
mmc_init
;;
mmc-patch)
mmc_patch
;;
*)
echo "Invalid argument"
exit 1
;;
esac