Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | mmc_init() { |
| 4 | base_dir="/media/hostfw" |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 5 | ro_dir="${base_dir}/running-ro" |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 6 | running_dir="${base_dir}/running" |
| 7 | prsv_dir="${base_dir}/prsv" |
Adriana Kobylak | 87372ae | 2020-09-01 11:30:59 -0500 | [diff] [blame] | 8 | staging_dir="${base_dir}/staging" |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 9 | |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 10 | if [ ! -d "${ro_dir}" ]; then |
| 11 | mkdir -p "${ro_dir}" |
| 12 | fi |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 13 | if [ ! -d "${running_dir}" ]; then |
| 14 | mkdir -p ${running_dir} |
| 15 | fi |
| 16 | if [ ! -d "${prsv_dir}" ]; then |
| 17 | mkdir -p "${prsv_dir}" |
| 18 | fi |
Adriana Kobylak | 87372ae | 2020-09-01 11:30:59 -0500 | [diff] [blame] | 19 | if [ ! -d "${staging_dir}" ]; then |
| 20 | mkdir -p "${staging_dir}" |
| 21 | fi |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 22 | |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 23 | # Mount the image that corresponds to the boot label as read-only to be used |
| 24 | # to populate the running directory. |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 25 | boot_label="$(fw_printenv -n bootside)" |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 26 | mount ${base_dir}/hostfw-${boot_label} ${ro_dir} -o ro |
| 27 | |
| 28 | # Determine if the running dir contains the running version |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 29 | running_label="" |
| 30 | running_label_file="${running_dir}/partlabel" |
| 31 | if [ -f "${running_label_file}" ]; then |
| 32 | running_label=$(cat ${running_label_file}) |
| 33 | fi |
| 34 | if [ "${running_label}" != "${boot_label}" ]; then |
| 35 | # Copy off the preserved partitions |
| 36 | # A line in the pnor.toc looks like this: |
| 37 | # partition05=SECBOOT,0x00381000,0x003a5000,00,ECC,PRESERVED |
| 38 | rm -f ${prsv_dir}/* |
| 39 | if [ -f ${running_dir}/pnor.toc ]; then |
| 40 | prsvs=$(grep PRESERVED ${running_dir}/pnor.toc) |
| 41 | for prsv in ${prsvs}; do |
| 42 | prsv=${prsv##partition*=} |
| 43 | prsv=$(echo ${prsv} | cut -d "," -f 1) |
| 44 | cp -p ${running_dir}/${prsv} ${prsv_dir} |
| 45 | done |
| 46 | fi |
| 47 | |
| 48 | # Copy contents of running image to running dir |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 49 | rm -f ${running_dir}/* |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 50 | cp -p ${ro_dir}/* ${running_dir}/ |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 51 | |
Adriana Kobylak | 98f2232 | 2020-07-20 10:39:41 -0500 | [diff] [blame] | 52 | # Restore the preserved partitions. Ignore error, there may be none. |
| 53 | cp -p ${prsv_dir}/* ${running_dir}/ 2>/dev/null || true |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 54 | rm -f ${prsv_dir}/* |
| 55 | |
Adriana Kobylak | 87372ae | 2020-09-01 11:30:59 -0500 | [diff] [blame] | 56 | # Clean up the staging dir in case of a failed update |
| 57 | rm -rf ${staging_dir}/* |
| 58 | |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 59 | # Save the label |
| 60 | echo "${boot_label}" > "${running_label_file}" |
| 61 | |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 62 | fi |
| 63 | |
| 64 | # Mount alternate dir |
| 65 | if [ "${boot_label}" = "a" ]; then |
| 66 | alternate_label="b" |
| 67 | else |
| 68 | alternate_label="a" |
| 69 | fi |
| 70 | alternate_dir="${base_dir}/alternate" |
| 71 | if [ ! -d "${alternate_dir}" ]; then |
| 72 | mkdir -p ${alternate_dir} |
| 73 | fi |
| 74 | mount ${base_dir}/hostfw-${alternate_label} ${alternate_dir} -o ro |
Brad Bishop | 847f54c | 2020-12-01 13:19:05 -0500 | [diff] [blame^] | 75 | |
| 76 | # setup host firmware runtime well known names |
| 77 | openpower-update-manager process-host-firmware |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | mmc_patch() { |
| 81 | # Patching is disabled if field mode is set |
| 82 | if [[ "$(fw_printenv fieldmode 2>/dev/null)" == "fieldmode=true" ]]; then |
| 83 | return 0 |
| 84 | fi |
| 85 | |
Adriana Kobylak | f6608a8 | 2020-08-25 14:16:23 -0500 | [diff] [blame] | 86 | boot_label="$(fw_printenv -n bootside)" |
| 87 | if [ "${boot_label}" = "a" ]; then |
| 88 | alternate_label="b" |
| 89 | else |
| 90 | alternate_label="a" |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 91 | fi |
| 92 | |
Adriana Kobylak | f6608a8 | 2020-08-25 14:16:23 -0500 | [diff] [blame] | 93 | # Create patch directories |
| 94 | patch_dir="/media/hostfw/patch-" |
| 95 | running_patch_dir="${patch_dir}${boot_label}" |
| 96 | if [ ! -d "${running_patch_dir}" ]; then |
| 97 | mkdir -p "${running_patch_dir}" |
| 98 | fi |
| 99 | alternate_patch_dir="${patch_dir}${alternate_label}" |
| 100 | if [ ! -d "${alternate_patch_dir}" ]; then |
| 101 | mkdir -p "${alternate_patch_dir}" |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 102 | fi |
| 103 | |
Adriana Kobylak | f6608a8 | 2020-08-25 14:16:23 -0500 | [diff] [blame] | 104 | # Create patch symlinks |
| 105 | symlink_base="/usr/local/share" |
| 106 | if [ ! -d "${symlink_base}" ]; then |
| 107 | mkdir -p "${symlink_base}" |
| 108 | fi |
| 109 | hostfw_symlink_base="${symlink_base}/hostfw" |
| 110 | if [ ! -d "${hostfw_symlink_base}" ]; then |
| 111 | mkdir -p "${hostfw_symlink_base}" |
| 112 | fi |
| 113 | |
| 114 | ln -s "${running_patch_dir}" "${symlink_base}/pnor" |
| 115 | ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running" |
| 116 | ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate" |
Adriana Kobylak | e8606da | 2020-07-15 09:16:56 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | case "$1" in |
| 120 | mmc-init) |
| 121 | mmc_init |
| 122 | ;; |
| 123 | mmc-patch) |
| 124 | mmc_patch |
| 125 | ;; |
| 126 | *) |
| 127 | echo "Invalid argument" |
| 128 | exit 1 |
| 129 | ;; |
| 130 | esac |