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 a write protect range for 0-64KB |
| 21 # This assumes the output from wp-status is: |
| 22 # "some text ... start=0x00000000, len=0x00010000" |
| 23 # where the start and length are key=value pairs |
| 24 |
| 25 # FIXME: Should we intentionally disable write protection for this? The |
| 26 # status register will not be changeable if hardware WP is in effect. |
| 27 # Then again, if hardware WP is on, then we won't be able to disable WP |
| 28 # either... |
| 29 # |
| 30 # FIXME #2: As per Carl-Daniel's comment, this test does not adequately |
| 31 # check that encoding is correct. It only checks if the output matches |
| 32 # the requested range. |
| 33 # |
| 34 |
| 35 LOGFILE="${0}.log" |
| 36 NEW_WP_RANGE_START=0x000000 |
| 37 NEW_WP_RANGE_LEN=0x010000 |
| 38 |
| 39 # Back-up old settings |
| 40 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null) |
| 41 old_start=${tmp##*start=} |
| 42 old_start=`printf "%s" "${old_start%%,*}"` |
| 43 |
| 44 old_len=${tmp##*len=} |
| 45 old_len=`printf "%s" "${old_len%%,*}"` |
| 46 echo "old start: ${old_start}, old length: ${old_len}" >> ${LOGFILE} |
| 47 |
| 48 # If the old write protection settings are the same as the new ones, we need |
| 49 # to choose new values. If this is the case, we'll extend the range to the |
| 50 # next 64K block. |
| 51 if [ $((${old_start} == ${NEW_WP_RANGE_START})) -ne 1 ] && [ $((${old_len} == ${
NEW_WP_RANGE_LEN})) -ne 1 ] ; then |
| 52 NEW_WP_RANGE_LEN=$((${NEW_WP_RANGE_LEN} + 0x10000})) |
| 53 fi |
| 54 |
| 55 # Try to set new range values |
| 56 echo "attempting to set write protect range: start=${NEW_WP_RANGE_START} ${NEW_W
P_RANGE_LEN}" >> ${LOGFILE} |
| 57 ./flashrom ${FLASHROM_PARAM} --wp-range ${NEW_WP_RANGE_START} ${NEW_WP_RANGE_LEN
} 2>/dev/null |
| 58 if [ ${?} -ne ${EXIT_SUCCESS} ]; then |
| 59 echo -n "failed to set write protect range" >> ${LOGFILE} |
| 60 return ${EXIT_FAILURE} |
| 61 fi |
| 62 |
| 63 tmp=$(./flashrom ${FLASHROM_PARAM} --wp-status 2>/dev/null) |
| 64 new_start=${tmp##*start=} |
| 65 new_start=`printf "%s" "${new_start%%,*}"` |
| 66 |
| 67 new_len=${tmp##*len=} |
| 68 new_len=`printf "%s" "${new_len%%,*}"` |
| 69 |
| 70 if [ $((${new_start} == ${NEW_WP_RANGE_START})) -ne 1 ]; then return ${EXIT_FAIL
URE} ; fi |
| 71 if [ $((${new_len} == ${NEW_WP_RANGE_LEN})) -ne 1 ]; then return ${EXIT_FAILURE}
; fi |
| 72 |
| 73 # restore the old settings |
| 74 ./flashrom ${FLASHROM_PARAM} --wp-range ${old_start} ${old_len} 2>/dev/null |
| 75 if [ ${?} -ne ${EXIT_SUCCESS} ]; then |
| 76 echo "failed to restore old settings" >> ${LOGFILE} |
| 77 return ${EXIT_FAILURE} |
| 78 fi |
| 79 |
| 80 echo "$0: passed" >> ${LOGFILE} |
| 81 return ${EXIT_SUCCESS} |
OLD | NEW |