| #!/bin/sh |
| |
| mmc_init() { |
| base_dir="/media/hostfw" |
| running_dir="${base_dir}/running" |
| prsv_dir="${base_dir}/prsv" |
| |
| if [ ! -d "${running_dir}" ]; then |
| mkdir -p ${running_dir} |
| fi |
| if [ ! -d "${prsv_dir}" ]; then |
| mkdir -p "${prsv_dir}" |
| fi |
| |
| # Determine if the running dir contains the running version |
| boot_label="$(fw_printenv -n bootside)" |
| 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 |
| tmp_dir="/tmp/hostfw" |
| mkdir -p "${tmp_dir}" |
| mount ${base_dir}/hostfw-${boot_label} ${tmp_dir} -o ro |
| rm -f ${running_dir}/* |
| cp -p ${tmp_dir}/* ${running_dir}/ |
| umount ${tmp_dir} |
| rm -rf ${tmp_dir} |
| |
| # Restore the preserved partitions |
| cp -p ${prsv_dir}/* ${running_dir}/ || 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 |