blob: 4cc6bb569e31ef0c34d60ac157ec15e19b0b0cd9 [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"
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
# 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}/*
# Save the label
echo "${boot_label}" > "${running_label_file}"
# Remove patches
rm -f ${base_dir}/patch/*
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
}
mmc_patch() {
# Patching is disabled if field mode is set
if [[ "$(fw_printenv fieldmode 2>/dev/null)" == "fieldmode=true" ]]; then
return 0
fi
target="/media/hostfw/patch"
if [ ! -d "${target}" ]; then
mkdir -p "${target}"
fi
patchdir="/usr/local/share"
if [ ! -d "${patchdir}" ]; then
mkdir -p "${patchdir}"
fi
ln -s "${target}" "${patchdir}/hostfw"
ln -s "${target}" "${patchdir}/pnor"
}
case "$1" in
mmc-init)
mmc_init
;;
mmc-patch)
mmc_patch
;;
*)
echo "Invalid argument"
exit 1
;;
esac