Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(935)

Side by Side Diff: util/partial_writes_x86_bios.sh

Issue 5136001: Add new testing framework along with a few micro-tests. (Closed) Base URL: svn://coreboot.org/flashrom/trunk/util
Patch Set: asdf Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « util/partial_writes_ec.sh ('k') | util/wp-range.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 # 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
78 # functionality of erasing and writing specific blocks.
79 offset=0
80 for i in `seq 0 $((${NUM_REGIONS} - 1))` ; do
81 offset_00=$((${i} * 8192))
82 offset_ff=$((${i} * 8192 + 4096))
83 echo "\
84 `printf 0x%x $((${start} + ${offset_00}))`:`printf 0x%x $((${start} + ${offset_0 0} + 0xfff))` 00_${i}
85 `printf 0x%x $((${start} + ${offset_ff}))`:`printf 0x%x $((${start} + ${offset_f f} + 0xfff))` ff_${i}
86 " >> layout_bios_4k_aligned.txt
87 done
88
89 cp "${BACKUP}" "$TESTFILE"
90 i=0
91 while [ $i -lt $NUM_REGIONS ] ; do
92 tmpstr="aligned region ${i} test: "
93 offset=$((${i} * 8192))
94 dd if=${ZERO_4K} of=${TESTFILE} bs=1 conv=notrunc seek=${offset} 2> /dev /null
95 dd if=${FF_4K} of=${TESTFILE} bs=1 conv=notrunc seek=$((${offset} + 4096 )) 2> /dev/null
96
97 ./flashrom ${FLASHROM_PARAM} -l layout_bios_4k_aligned.txt -i 00_${i} -i ff_${i} -w "$TESTFILE" 2> /dev/null
98 if [ "$?" != "0" ] ; then
99 partial_writes_fail "${tmpstr}failed to flash region"
100 fi
101
102 # download the entire ROM image and use diff to compare to ensure
103 # flashrom logic does not violate user-specified regions
104 flashrom ${FLASHROM_PARAM} -r difftest.bin 2> /dev/null
105 diff -q difftest.bin "$TESTFILE"
106 if [ "$?" != "0" ] ; then
107 partial_writes_fail "${tmpstr}failed diff test"
108 fi
109 rm -f difftest.bin
110
111 i=$((${i} + 1))
112 echo "${tmpstr}passed" >> ${LOGFILE}
113 done
114
115 # Make a layout - 4K regions on 4.5K boundaries. This will help find problems
116 # with logic that only operates on part of a block. For example, if a user
117 # wishes to re-write a fraction of a block, then:
118 # 1. The whole block must be erased.
119 # 2. The old content must be restored at unspecified offsets.
120 # 3. The new content must be written at specified offsets.
121 #
122 # Note: The last chunk of 0xff bytes is only 2K as to avoid overrunning a 128KB
123 # test image.
124 #
125 for i in `seq 0 $((${NUM_REGIONS} - 1))` ; do
126 offset_00=$((${i} * 8192 + 2048))
127 offset_ff=$((${i} * 8192 + 4096 + 2048))
128 echo "\
129 `printf 0x%06x $((${start} + ${offset_00}))`:`printf 0x%06x $((${start} + ${offs et_00} + 0xfff))` 00_${i}
130 `printf 0x%06x $((${start} + ${offset_ff}))`:`printf 0x%06x $((${start} + ${offs et_ff} + 0xfff))` ff_${i}
131 " >> layout_bios_unaligned.txt
132 done
133
134 # reset the test file and ROM to the original state
135 flashrom ${FLASHROM_PARAM} -w "${BACKUP}" > /dev/null
136 cp "$BACKUP" "$TESTFILE"
137
138 i=0
139 while [ $i -lt $NUM_REGIONS ] ; do
140 tmpstr="aligned region ${i} test: "
141 offset=$(($((${i} * 8192)) + 2048))
142 # Protect against too long write
143 writelen=4096
144 if [ $((${offset} + 4096 + 4096)) -ge 131072 ]; then
145 writelen=$((131072 - $((${offset} + 4096))))
146 if [ ${writelen} -lt 0 ]; then
147 writelen=0
148 fi
149 fi
150 dd if=${ZERO_4K} of=${TESTFILE} bs=1 conv=notrunc seek=${offset} 2> /dev /null
151 dd if=${FF_4K} of=${TESTFILE} bs=1 conv=notrunc seek=$((${offset} + 4096 )) count=writelen 2> /dev/null
152
153 ./flashrom ${FLASHROM_PARAM} -l layout_bios_unaligned.txt -i 00_${i} -i ff_${i} -w "$TESTFILE" 2> /dev/null
154 if [ "$?" != "0" ] ; then
155 partial_writes_fail "${tmpstr} failed to flash region"
156 fi
157
158 # download the entire ROM image and use diff to compare to ensure
159 # flashrom logic does not violate user-specified regions
160 flashrom ${FLASHROM_PARAM} -r difftest.bin 2> /dev/null
161 diff -q difftest.bin "$TESTFILE"
162 if [ "$?" != "0" ] ; then
163 partial_writes_fail "${tmpstr} failed diff test"
164 fi
165 rm -f difftest.bin
166
167 i=$((${i} + 1))
168 echo "${tmpstr}passed" >> ${LOGFILE}
169 done
170
171 return "$EXIT_SUCCESS"
OLDNEW
« no previous file with comments | « util/partial_writes_ec.sh ('k') | util/wp-range.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698