OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 2 # |
| 3 # Copyright (C) 2010 Google Inc. |
| 4 # Written by David Hendricks for Google Inc. |
| 5 # |
| 6 # This program is free software; you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License as published by |
| 8 # the Free Software Foundation; either version 2 of the License, or |
| 9 # (at your option) any later version. |
| 10 # |
| 11 # This program is distributed in the hope that it will be useful, |
| 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 # GNU General Public License for more details. |
| 15 # |
| 16 # You should have received a copy of the GNU General Public License |
| 17 # along with this program; if not, write to the Free Software |
| 18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
| 20 # Assume we can set enable/disable bits (that is, SPI chip is not hardware |
| 21 # write-protected). Also, assume output is in the form: |
| 22 # WP: write protect is enabled |
| 23 # WP: write protect is disabled |
| 24 # |
| 25 # FIXME: Carl-Daniel pointed out that this script does little to validate that |
| 26 # the settings on the chip are actually correct. It merely checks that Flashrom |
| 27 # prints what we want it to print. |
| 28 |
| 29 |
| 30 LOGFILE="${0}.log" |
| 31 WP_DISABLED=0 |
| 32 WP_ENABLED=1 |
| 33 MAGIC="write protect is" |
| 34 |
| 35 wp_toggle_fail() |
| 36 { |
| 37 echo "$1" >> ${LOGFILE} |
| 38 echo "$0: failed" >> ${LOGFILE} |
| 39 exit ${EXIT_FAILURE} |
| 40 } |
| 41 |
| 42 wp_status() |
| 43 { |
| 44 if [ "$(printf %s\\n "$1" | sed 's/.*enabled.*/enabled/')" = "enabled" ]
; then |
| 45 return ${WP_ENABLED} |
| 46 elif [ "$(printf %s\\n "$1" | sed 's/.*disabled.*/disabled/')" = "disabl
ed" ]; then |
| 47 return ${WP_DISABLED} |
| 48 else |
| 49 wp_toggle_fail "unknown write protect status: \"$1\"" |
| 50 fi |
| 51 } |
| 52 |
| 53 # Back-up old settings |
| 54 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGIC") |
| 55 wp_status "$tmp" |
| 56 old_status=$? |
| 57 echo "old write protect status: ${old_status}" >> ${LOGFILE} |
| 58 |
| 59 # invert the old setting |
| 60 if [ ${old_status} -eq ${WP_ENABLED} ]; then |
| 61 ./flashrom ${FLASHROM_PARAM} --wp-disable 2>/dev/null |
| 62 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI
C") |
| 63 wp_status "$tmp" |
| 64 if [ $? = ${WP_ENABLED} ]; then |
| 65 wp_toggle_fail "failed to disable write protection" |
| 66 fi |
| 67 elif [ ${old_status} -eq ${WP_DISABLED} ]; then |
| 68 ./flashrom ${FLASHROM_PARAM} --wp-enable 2>/dev/null |
| 69 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI
C") |
| 70 wp_status "$tmp" |
| 71 if [ $? = ${WP_DISABLED} ]; then |
| 72 wp_toggle_fail "failed to enable write protection" |
| 73 fi |
| 74 fi |
| 75 |
| 76 # restore old setting |
| 77 if [ ${old_status} -eq ${WP_ENABLED} ]; then |
| 78 ./flashrom ${FLASHROM_PARAM} --wp-enable 2>/dev/null |
| 79 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI
C") |
| 80 wp_status "$tmp" |
| 81 if [ $? != ${WP_ENABLED} ]; then |
| 82 wp_toggle_fail "failed to enable write protection" |
| 83 fi |
| 84 elif [ ${old_status} -eq ${WP_DISABLED} ]; then |
| 85 ./flashrom ${FLASHROM_PARAM} --wp-disable 2>/dev/null |
| 86 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null | grep "$MAGI
C") |
| 87 wp_status "$tmp" |
| 88 if [ $? != ${WP_DISABLED} ]; then |
| 89 wp_toggle_fail "failed to disable write protection" |
| 90 fi |
| 91 fi |
| 92 |
| 93 echo "$0: passed" >> ${LOGFILE} |
| 94 return ${EXIT_SUCCESS} |
OLD | NEW |