Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/sh | |
|
hailfinger
2010/11/23 20:05:34
Is this script identical to the partial write test
dhendrix
2010/11/24 02:48:14
Not quite. The one that is already present is stan
| |
| 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 # This script attempts to test Flashrom partial write capability by writing | |
| 21 # patterns of 0xff and 0x00 bytes to the lowest 128KB of flash. 128KB is chosen | |
| 22 # since 64KB is usually the largest possible block size, so we will try to | |
| 23 # cover at least two blocks with this test. | |
| 24 # | |
| 25 # TODO: We need to make sure to force re-writes when desired since flashrom | |
| 26 # may skip regions which do not need to be re-written. | |
| 27 # | |
| 28 | |
| 29 LOGFILE="${0}.log" | |
| 30 ZERO_4K="00_4k.bin" | |
| 31 FF_4K="ff_4k.bin" | |
| 32 FF_4K_TEXT="ff_4k.txt" | |
| 33 | |
| 34 TESTFILE="test.bin" | |
| 35 | |
| 36 partial_writes_fail() | |
| 37 { | |
| 38 echo "$1" >> ${LOGFILE} | |
| 39 echo "$0: failed" >> ${LOGFILE} | |
| 40 exit ${EXIT_FAILURE} | |
| 41 } | |
| 42 | |
| 43 # FIXME: this is a chromium-os -ism. most distros don't strip out "diff"... | |
| 44 which diff > /dev/null | |
| 45 if [ "$?" != "0" ] ; then | |
| 46 partial_writes_fail "diff is required to use this script" | |
| 47 fi | |
| 48 | |
| 49 which uuencode > /dev/null | |
| 50 if [ "$?" != "0" ] ; then | |
| 51 partial_writes_fail "uuencode is required to use this script" | |
| 52 fi | |
| 53 | |
| 54 # Make 4k worth of 0xff bytes | |
| 55 echo "begin 640 $FF_4K" > "$FF_4K_TEXT" | |
| 56 i=0 | |
| 57 while [ $i -le 90 ] ; do | |
| 58 echo "M____________________________________________________________" >> "$FF_4K_TEXT" | |
| 59 i=$((${i} + 1)) | |
| 60 done | |
| 61 echo "!_P``" >> "$FF_4K_TEXT" | |
| 62 echo "\`" >> "$FF_4K_TEXT" | |
| 63 echo "end" >> "$FF_4K_TEXT" | |
| 64 uudecode -o "$FF_4K" "$FF_4K_TEXT" | |
| 65 rm -f "$FF_4K_TEXT" | |
| 66 | |
| 67 # Make 4k worth of 0x00 bytes | |
| 68 dd if=/dev/zero of="$ZERO_4K" bs=1 count=4096 2> /dev/null | |
| 69 echo "ffh pattern written in ${FF_4K}" | |
| 70 echo "00h pattern written in ${ZERO_4K}" | |
| 71 | |
| 72 # | |
| 73 # Actual tests are performed below. | |
| 74 # | |
| 75 NUM_REGIONS=16 | |
| 76 | |
| 77 # Make a layout - 4K regions on 4K boundaries. This will test basic | |
|
Stefan Reinauer
2010/11/23 19:05:30
Maybe a separate function?
dhendrix
2010/11/24 02:48:14
As with the EC stuff, I made this into a loop. Mak
| |
| 78 # functionality of erasing and writing specific blocks. | |
| 79 echo " | |
| 80 0x000000:0x000fff 00_0 | |
| 81 0x001000:0x001fff ff_0 | |
| 82 | |
| 83 0x002000:0x002fff 00_1 | |
| 84 0x003000:0x003fff ff_1 | |
| 85 | |
| 86 0x004000:0x004fff 00_2 | |
| 87 0x005000:0x005fff ff_2 | |
| 88 | |
| 89 0x006000:0x006fff 00_3 | |
| 90 0x007000:0x007fff ff_3 | |
| 91 | |
| 92 0x008000:0x008fff 00_4 | |
| 93 0x009000:0x009fff ff_4 | |
| 94 | |
| 95 0x00a000:0x00afff 00_5 | |
| 96 0x00b000:0x00bfff ff_5 | |
| 97 | |
| 98 0x00c000:0x00cfff 00_6 | |
| 99 0x00d000:0x00dfff ff_6 | |
| 100 | |
| 101 0x00e000:0x00efff 00_7 | |
| 102 0x00f000:0x00ffff ff_7 | |
| 103 | |
| 104 0x010000:0x010fff 00_8 | |
| 105 0x011000:0x011fff ff_8 | |
| 106 | |
| 107 0x012000:0x012fff 00_9 | |
| 108 0x013000:0x013fff ff_9 | |
| 109 | |
| 110 0x014000:0x014fff 00_10 | |
| 111 0x015000:0x015fff ff_10 | |
| 112 | |
| 113 0x016000:0x016fff 00_11 | |
| 114 0x017000:0x017fff ff_11 | |
| 115 | |
| 116 0x018000:0x018fff 00_12 | |
| 117 0x019000:0x019fff ff_12 | |
| 118 | |
| 119 0x01a000:0x01afff 00_13 | |
| 120 0x01b000:0x01bfff ff_13 | |
| 121 | |
| 122 0x01c000:0x01cfff 00_14 | |
| 123 0x01d000:0x01dfff ff_14 | |
| 124 | |
| 125 0x01e000:0x01efff 00_15 | |
| 126 0x01f000:0x01ffff ff_15 | |
| 127 " > layout_4k_aligned.txt | |
| 128 | |
| 129 cp "${BACKUP}" "$TESTFILE" | |
| 130 i=0 | |
| 131 while [ $i -lt $NUM_REGIONS ] ; do | |
| 132 tmpstr="aligned region ${i} test: " | |
| 133 offset=$((${i} * 8192)) | |
| 134 dd if=${ZERO_4K} of=${TESTFILE} bs=1 conv=notrunc seek=${offset} 2> /dev /null | |
| 135 dd if=${FF_4K} of=${TESTFILE} bs=1 conv=notrunc seek=$((${offset} + 4096 )) 2> /dev/null | |
| 136 | |
| 137 ./flashrom ${FLASHROM_PARAM} -l layout_4k_aligned.txt -i 00_${i} -i ff_$ {i} -w "$TESTFILE" 2> /dev/null | |
| 138 if [ "$?" != "0" ] ; then | |
| 139 partial_writes_fail "failed to flash region" | |
| 140 fi | |
| 141 | |
| 142 # download the entire ROM image and use diff to compare to ensure | |
| 143 # flashrom logic does not violate user-specified regions | |
| 144 flashrom ${FLASHROM_PARAM} -r difftest.bin 2> /dev/null | |
| 145 diff -q difftest.bin "$TESTFILE" | |
| 146 if [ "$?" != "0" ] ; then | |
| 147 partial_writes_fail "failed diff test" | |
| 148 fi | |
| 149 rm -f difftest.bin | |
| 150 | |
| 151 i=$((${i} + 1)) | |
| 152 echo "${tmpstr}passed" >> ${LOGFILE} | |
| 153 done | |
| 154 | |
| 155 # Make a layout - 4K regions on 4.5K boundaries. This will help find problems | |
|
Stefan Reinauer
2010/11/23 19:05:30
ditto
| |
| 156 # with logic that only operates on part of a block. For example, if a user | |
| 157 # wishes to re-write a fraction of a block, then: | |
| 158 # 1. The whole block must be erased. | |
| 159 # 2. The old content must be restored at unspecified offsets. | |
| 160 # 3. The new content must be written at specified offsets. | |
| 161 # | |
| 162 # Note: The last chunk of 0xff bytes is only 2K as to avoid overrunning a 128KB | |
| 163 # test image. | |
| 164 # | |
| 165 echo " | |
| 166 0x000800:0x0017ff 00_0 | |
| 167 0x001800:0x0027ff ff_0 | |
| 168 | |
| 169 0x002800:0x0037ff 00_1 | |
| 170 0x003800:0x0047ff ff_1 | |
| 171 | |
| 172 0x004800:0x0057ff 00_2 | |
| 173 0x005800:0x0067ff ff_2 | |
| 174 | |
| 175 0x006800:0x0077ff 00_3 | |
| 176 0x007800:0x0087ff ff_3 | |
| 177 | |
| 178 0x008800:0x0097ff 00_4 | |
| 179 0x009800:0x00a7ff ff_4 | |
| 180 | |
| 181 0x00a800:0x00b7ff 00_5 | |
| 182 0x00b800:0x00c7ff ff_5 | |
| 183 | |
| 184 0x00c800:0x00d7ff 00_6 | |
| 185 0x00d800:0x00e7ff ff_6 | |
| 186 | |
| 187 0x00e800:0x00f7ff 00_7 | |
| 188 0x00f800:0x0107ff ff_7 | |
| 189 | |
| 190 0x010800:0x0117ff 00_8 | |
| 191 0x011800:0x0127ff ff_8 | |
| 192 | |
| 193 0x012800:0x0137ff 00_9 | |
| 194 0x013800:0x0147ff ff_9 | |
| 195 | |
| 196 0x014800:0x0157ff 00_10 | |
| 197 0x015800:0x0167ff ff_10 | |
| 198 | |
| 199 0x016800:0x0177ff 00_11 | |
| 200 0x017800:0x0187ff ff_11 | |
| 201 | |
| 202 0x018800:0x0197ff 00_12 | |
| 203 0x019800:0x01a7ff ff_12 | |
| 204 | |
| 205 0x01a800:0x01b7ff 00_13 | |
| 206 0x01b800:0x01c7ff ff_13 | |
| 207 | |
| 208 0x01c800:0x01d7ff 00_14 | |
| 209 0x01d800:0x01e7ff ff_14 | |
| 210 | |
| 211 0x01e800:0x01f7ff 00_15 | |
| 212 0x01f800:0x01ffff ff_15 | |
| 213 " > layout_unaligned.txt | |
| 214 | |
| 215 # reset the test file and ROM to the original state | |
| 216 flashrom ${FLASHROM_PARAM} -w "${BACKUP}" > /dev/null | |
| 217 cp "$BACKUP" "$TESTFILE" | |
| 218 | |
| 219 i=0 | |
| 220 while [ $i -lt $NUM_REGIONS ] ; do | |
| 221 tmpstr="aligned region ${i} test: " | |
| 222 offset=$(($((${i} * 8192)) + 2048)) | |
| 223 # Protect against too long write | |
| 224 writelen=4096 | |
| 225 if [ $((${offset} + 4096 + 4096)) -ge 131072 ]; then | |
| 226 writelen=$((131072 - $((${offset} + 4096)))) | |
| 227 if [ ${writelen} -lt 0 ]; then | |
| 228 writelen=0 | |
| 229 fi | |
| 230 fi | |
| 231 dd if=${ZERO_4K} of=${TESTFILE} bs=1 conv=notrunc seek=${offset} 2> /dev /null | |
| 232 dd if=${FF_4K} of=${TESTFILE} bs=1 conv=notrunc seek=$((${offset} + 4096 )) count=writelen 2> /dev/null | |
| 233 | |
| 234 ./flashrom ${FLASHROM_PARAM} -l layout_unaligned.txt -i 00_${i} -i ff_${ i} -w "$TESTFILE" 2> /dev/null | |
| 235 if [ "$?" != "0" ] ; then | |
| 236 partial_writes_fail "failed to flash region" | |
| 237 fi | |
| 238 | |
| 239 # download the entire ROM image and use diff to compare to ensure | |
| 240 # flashrom logic does not violate user-specified regions | |
| 241 flashrom ${FLASHROM_PARAM} -r difftest.bin 2> /dev/null | |
| 242 diff -q difftest.bin "$TESTFILE" | |
| 243 if [ "$?" != "0" ] ; then | |
| 244 partial_writes_fail "failed diff test" | |
| 245 fi | |
| 246 rm -f difftest.bin | |
| 247 | |
| 248 i=$((${i} + 1)) | |
| 249 echo "${tmpstr}passed" >> ${LOGFILE} | |
| 250 done | |
| 251 | |
| 252 return "$EXIT_SUCCESS" | |
| OLD | NEW |