Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Adriana Kobylak | bbb5e3b | 2020-06-19 10:22:13 -0500 | [diff] [blame] | 3 | clear_volatile() { |
| 4 | service=$(mapper get-service /org/open_power/control/volatile) |
| 5 | clearVolatileEnabled=$(busctl get-property $service /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled) |
| 6 | if [[ "$clearVolatileEnabled" != "b true" ]]; then |
| 7 | return 0 |
| 8 | fi |
| 9 | |
| 10 | PNOR_TOC_FILE="pnor.toc" |
| 11 | PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro/" |
| 12 | PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw/" |
| 13 | PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv/" |
| 14 | |
| 15 | # toc partition string format: |
| 16 | # partition27=HB_VOLATILE,0x02ba9000,0x02bae000,00,ECC,VOLATILE,READWRITE |
| 17 | tocFilePath="${PNOR_RO_ACTIVE_PATH}${PNOR_TOC_FILE}" |
| 18 | volatiles=($(grep VOLATILE "${tocFilePath}" | grep -Eo '^partition([0-9]+)=([A-Za-z0-9_]+)')) |
| 19 | for (( index=0; index<${#volatiles[@]}; index++ )); do |
| 20 | volatileName="$(echo ${volatiles[${index}]} | awk -F '=' '{print $2}')" |
| 21 | |
| 22 | rwVolatile="${PNOR_RW_ACTIVE_PATH}${volatileName}" |
| 23 | if [ -f "${rwVolatile}" ]; then |
| 24 | echo "Clear $rwVolatile" |
| 25 | rm "${rwVolatile}" |
| 26 | fi |
| 27 | prsvVolatile="${PNOR_PRSV_ACTIVE_PATH}${volatileName}" |
| 28 | if [ -f "${prsvVolatile}" ]; then |
| 29 | echo "Clear $prsvVolatile" |
| 30 | rm "${prsvVolatile}" |
| 31 | fi |
| 32 | done |
| 33 | # Always reset the sensor after clearing |
| 34 | busctl set-property $service /org/open_power/control/volatile xyz.openbmc_project.Object.Enable Enabled b false |
| 35 | } |
| 36 | |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 37 | update_symlinks() { |
| 38 | PNOR_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/" |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 39 | HOSTFW_ACTIVE_PATH="/var/lib/phosphor-software-manager/hostfw/" |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 40 | PNOR_RO_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/ro" |
| 41 | PNOR_RO_PREFIX="/media/pnor-ro-" |
| 42 | PNOR_RW_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/rw" |
| 43 | PNOR_RW_PREFIX="/media/pnor-rw-" |
| 44 | PNOR_PRSV_ACTIVE_PATH="/var/lib/phosphor-software-manager/pnor/prsv" |
| 45 | PNOR_PRSV="/media/pnor-prsv" |
| 46 | PERSISTENCE_PATH="/var/lib/obmc/openpower-pnor-code-mgmt/" |
| 47 | PNOR_PATCH_LOCATION="/usr/local/share/pnor/" |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 48 | HOSTFW_PATCH_LOCATION="/usr/local/share/hostfw/" |
| 49 | MMC_BASE_PATH="/media/hostfw" |
| 50 | MMC_RUNNING_PATH="${MMC_BASE_PATH}/running" |
| 51 | MMC_ALTERNATE_PATH="${MMC_BASE_PATH}/alternate" |
| 52 | HOSTFW_RUNNING_PATH="${HOSTFW_ACTIVE_PATH}/running" |
| 53 | HOSTFW_ALTERNATE_PATH="${HOSTFW_ACTIVE_PATH}/alternate" |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 54 | |
| 55 | # Get a list of all active PNOR versions |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 56 | data="$(ls -d ${PNOR_RO_PREFIX}* 2>/dev/null)" |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 57 | IFS=$'\n' array=(${data}) |
| 58 | |
| 59 | currentVersion="" |
| 60 | lowestPriority=255 |
| 61 | for element in ${array[@]}; do |
| 62 | #Remove the PNOR_RO_PREFIX from the path to get version ID. |
| 63 | versionId="${element#${PNOR_RO_PREFIX}}" |
| 64 | |
| 65 | # Get the priority of active versions from persistence files. |
| 66 | if [[ -f "${PERSISTENCE_PATH}${versionId}" ]]; then |
| 67 | data="$(grep -r "priority" ${PERSISTENCE_PATH}${versionId})" |
| 68 | priority="${data: -1}" |
| 69 | if [[ priority -le lowestPriority ]]; then |
| 70 | lowestPriority=${priority} |
| 71 | currentVersion=${versionId} |
| 72 | fi |
| 73 | fi |
| 74 | done |
| 75 | |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 76 | if [ ! -z $currentVersion ]; then |
| 77 | # Use active version |
| 78 | roTarget="${PNOR_RO_PREFIX}${currentVersion}" |
| 79 | rwTarget="${PNOR_RW_PREFIX}${currentVersion}" |
| 80 | prsvTarget="${PNOR_PRSV}" |
| 81 | elif [ -d "${MMC_BASE_PATH}" ]; then |
| 82 | # Use eMMC |
| 83 | roTarget="${MMC_RUNNING_PATH}" |
| 84 | rwTarget="${MMC_RUNNING_PATH}" |
| 85 | prsvTarget="${MMC_RUNNING_PATH}" |
| 86 | |
| 87 | if [ ! -d "${HOSTFW_ACTIVE_PATH}" ]; then |
| 88 | mkdir -p "${HOSTFW_ACTIVE_PATH}" |
| 89 | fi |
| 90 | if [[ $(readlink -f "${HOSTFW_RUNNING_PATH}") != ${MMC_RUNNING_PATH} ]]; then |
| 91 | rm -f ${HOSTFW_RUNNING_PATH} |
| 92 | ln -sfv ${MMC_RUNNING_PATH} ${HOSTFW_RUNNING_PATH} |
| 93 | fi |
| 94 | if [[ $(readlink -f "${HOSTFW_ALTERNATE_PATH}") != ${MMC_ALTERNATE_PATH} ]]; then |
| 95 | rm -f ${HOSTFW_ALTERNATE_PATH} |
| 96 | ln -sfv ${MMC_ALTERNATE_PATH} ${HOSTFW_ALTERNATE_PATH} |
| 97 | fi |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 98 | fi |
| 99 | |
| 100 | if [ ! -d "${PNOR_ACTIVE_PATH}" ]; then |
| 101 | mkdir -p "${PNOR_ACTIVE_PATH}" |
| 102 | fi |
| 103 | |
| 104 | # If the RW or RO active links doesn't point to the version with |
| 105 | # lowest priority, then remove the symlink and create new ones. |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 106 | if [[ $(readlink -f "${PNOR_RO_ACTIVE_PATH}") != ${roTarget} ]]; then |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 107 | rm -f ${PNOR_RO_ACTIVE_PATH} |
| 108 | rm -rf ${PNOR_PATCH_LOCATION}* |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 109 | ln -sfv ${roTarget} ${PNOR_RO_ACTIVE_PATH} |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 110 | fi |
| 111 | |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 112 | if [[ $(readlink -f "${PNOR_RW_ACTIVE_PATH}") != ${rwTarget} ]]; then |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 113 | rm -f ${PNOR_RW_ACTIVE_PATH} |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 114 | ln -sfv ${rwTarget} ${PNOR_RW_ACTIVE_PATH} |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 115 | fi |
| 116 | |
Adriana Kobylak | 0e0a3b1 | 2020-07-15 16:47:03 -0500 | [diff] [blame^] | 117 | if [[ $(readlink -f "${PNOR_PRSV_ACTIVE_PATH}") != ${prsvTarget} ]]; then |
| 118 | rm -f ${PNOR_PRSV_ACTIVE_PATH} |
| 119 | ln -sfv ${prsvTarget} ${PNOR_PRSV_ACTIVE_PATH} |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 120 | fi |
| 121 | } |
| 122 | |
| 123 | case "$1" in |
Adriana Kobylak | bbb5e3b | 2020-06-19 10:22:13 -0500 | [diff] [blame] | 124 | clearvolatile) |
| 125 | clear_volatile |
| 126 | ;; |
Adriana Kobylak | f3dfe65 | 2019-10-08 11:35:55 -0500 | [diff] [blame] | 127 | updatesymlinks) |
| 128 | update_symlinks |
| 129 | ;; |
| 130 | *) |
| 131 | echo "Invalid argument" |
| 132 | exit 1 |
| 133 | ;; |
| 134 | esac |
| 135 | rc=$? |
| 136 | if [ ${rc} -ne 0 ]; then |
| 137 | echo "$0: error ${rc}" |
| 138 | exit ${rc} |
| 139 | fi |