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