blob: 2abf8fb22768894cacf415a52f88dddd146a4f7f [file] [log] [blame]
#!/bin/sh
clear_volatile() {
service=$(mapper get-service /org/open_power/control/volatile)
clearVolatileEnabled=$(busctl get-property $service /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled)
if [[ "$clearVolatileEnabled" != "b true" ]]; then
return 0
fi
PNOR_TOC_FILE="pnor.toc"
PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro/"
PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw/"
PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv/"
# toc partition string format:
# partition27=HB_VOLATILE,0x02ba9000,0x02bae000,00,ECC,VOLATILE,READWRITE
tocFilePath="${PNOR_RO_ACTIVE_PATH}${PNOR_TOC_FILE}"
volatiles=($(grep VOLATILE "${tocFilePath}" | grep -Eo '^partition([0-9]+)=([A-Za-z0-9_]+)'))
for (( index=0; index<${#volatiles[@]}; index++ )); do
volatileName="$(echo ${volatiles[${index}]} | awk -F '=' '{print $2}')"
rwVolatile="${PNOR_RW_ACTIVE_PATH}${volatileName}"
if [ -f "${rwVolatile}" ]; then
echo "Clear $rwVolatile"
rm "${rwVolatile}"
fi
prsvVolatile="${PNOR_PRSV_ACTIVE_PATH}${volatileName}"
if [ -f "${prsvVolatile}" ]; then
echo "Clear $prsvVolatile"
rm "${prsvVolatile}"
fi
done
# Always reset the sensor after clearing
busctl set-property $service /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled b false
}
update_symlinks() {
PNOR_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/"
PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro"
PNOR_RO_PREFIX="/media/pnor-ro-"
PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw"
PNOR_RW_PREFIX="/media/pnor-rw-"
PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv"
PNOR_PRSV="/media/pnor-prsv"
PERSISTENCE_PATH="/var/lib/obmc/openpower-pnor-code-mgmt/"
PNOR_PATCH_LOCATION="/usr/local/share/pnor/"
# Get a list of all active PNOR versions
data="$(ls -d ${PNOR_RO_PREFIX}*)"
IFS=$'\n' array=(${data})
currentVersion=""
lowestPriority=255
for element in ${array[@]}; do
#Remove the PNOR_RO_PREFIX from the path to get version ID.
versionId="${element#${PNOR_RO_PREFIX}}"
# Get the priority of active versions from persistence files.
if [[ -f "${PERSISTENCE_PATH}${versionId}" ]]; then
data="$(grep -r "priority" ${PERSISTENCE_PATH}${versionId})"
priority="${data: -1}"
if [[ priority -le lowestPriority ]]; then
lowestPriority=${priority}
currentVersion=${versionId}
fi
fi
done
# Return if no active version found
if [ -z $currentVersion ]; then
return 0;
fi
if [ ! -d "${PNOR_ACTIVE_PATH}" ]; then
mkdir -p "${PNOR_ACTIVE_PATH}"
fi
# If the RW or RO active links doesn't point to the version with
# lowest priority, then remove the symlink and create new ones.
if [[ $(readlink -f "${PNOR_RO_ACTIVE_PATH}") != ${PNOR_RO_PREFIX}${currentVersion} ]]; then
rm -f ${PNOR_RO_ACTIVE_PATH}
rm -rf ${PNOR_PATCH_LOCATION}*
ln -sfv ${PNOR_RO_PREFIX}${currentVersion} ${PNOR_RO_ACTIVE_PATH}
fi
if [[ $(readlink -f "${PNOR_RW_ACTIVE_PATH}") != ${PNOR_RW_PREFIX}${currentVersion} ]]; then
rm -f ${PNOR_RW_ACTIVE_PATH}
ln -sfv ${PNOR_RW_PREFIX}${currentVersion} ${PNOR_RW_ACTIVE_PATH}
fi
if [[ ! -h ${PNOR_PRSV_ACTIVE_PATH} ]]; then
ln -sfv ${PNOR_PRSV} ${PNOR_PRSV_ACTIVE_PATH}
fi
}
case "$1" in
clearvolatile)
clear_volatile
;;
updatesymlinks)
update_symlinks
;;
*)
echo "Invalid argument"
exit 1
;;
esac
rc=$?
if [ ${rc} -ne 0 ]; then
echo "$0: error ${rc}"
exit ${rc}
fi