summaryrefslogtreecommitdiff
path: root/ubi-utils/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'ubi-utils/scripts')
-rw-r--r--ubi-utils/scripts/bin2nand2bin_test.sh184
-rw-r--r--ubi-utils/scripts/inject_biterror.pl94
2 files changed, 278 insertions, 0 deletions
diff --git a/ubi-utils/scripts/bin2nand2bin_test.sh b/ubi-utils/scripts/bin2nand2bin_test.sh
new file mode 100644
index 0000000..a17c91b
--- /dev/null
+++ b/ubi-utils/scripts/bin2nand2bin_test.sh
@@ -0,0 +1,184 @@
+#!/bin/sh
+#
+# Testcase for nand2bin and bin2nand. Generate testdata and inject
+# biterrors. Convert data back and compare with original data.
+#
+# Conversion:
+# bin -> bin2nand -> mif -> nand2bin -> img
+#
+
+inject_biterror=./scripts/inject_biterror.pl
+
+pagesize=2048
+oobsize=64
+
+# Create test data
+dd if=/dev/urandom of=testblock.bin bs=131072 count=1
+
+echo "Test conversion without bitflips ..."
+
+echo -n "Convert bin to mif ... "
+bin2nand --pagesize=${pagesize} -o testblock.mif testblock.bin
+if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+else
+ echo "ok"
+fi
+
+echo -n "Convert mif to bin ... "
+nand2bin --pagesize=${pagesize} -o testblock.img testblock.mif
+if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+else
+ echo "ok"
+fi
+
+echo -n "Comparing data ... "
+diff testblock.bin testblock.img
+if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+else
+ echo "ok"
+fi
+
+echo "Test conversion with uncorrectable ECC erors ..."
+echo -n "Inject biterror at offset $ioffs ... "
+${inject_biterror} --offset=0 --bitmask=0x81 \
+ --input=testblock.mif \
+ --output=testblock_bitflip.mif
+if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+else
+ echo "ok"
+fi
+
+echo "Convert mif to bin ... "
+rm testblock.img
+nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \
+ testblock_bitflip.mif
+if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+else
+ echo "ok"
+fi
+
+echo -n "Comparing data, must fail due to uncorrectable ECC ... "
+diff testblock.bin testblock.img
+if [ $? -ne "0" ]; then
+ echo "ok" # Must fail!
+else
+ echo "failed!"
+ exit 1
+fi
+
+echo "Test bitflips in data ... "
+for offs in `seq 0 255` ; do
+
+ cp testblock.mif testblock_bitflip.mif
+
+ for xoffs in 0 256 512 768 ; do
+ let ioffs=$offs+$xoffs
+
+ cp testblock_bitflip.mif testblock_bitflip_tmp.mif
+ echo -n "Inject biterror at offset $ioffs ... "
+ ${inject_biterror} --offset=${ioffs} --bitmask=0x01 \
+ --input=testblock_bitflip_tmp.mif \
+ --output=testblock_bitflip.mif
+ if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+ done
+
+ echo "Convert mif to bin ... "
+ rm testblock.img
+ nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \
+ testblock_bitflip.mif
+ if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+
+ echo -n "Comparing data ... "
+ diff testblock.bin testblock.img
+ if [ $? -ne "0" ]; then
+ hexdump testblock.bin > testblock.bin.txt
+ hexdump testblock.img > testblock.img.txt
+ echo "Use tkdiff testblock.bin.txt testblock.img.txt to compare"
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+
+ # Without correction
+ echo "Convert mif to bin ... "
+ rm testblock.img
+ nand2bin --pagesize=${pagesize} -o testblock.img \
+ testblock_bitflip.mif
+ if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+
+ echo -n "Comparing data must differ, correction is disabled ... "
+ diff testblock.bin testblock.img
+ if [ $? -ne "0" ]; then
+ echo "ok" # must fail
+ else
+ echo "failed!"
+ exit 1
+ fi
+done
+
+echo "Test bitflips in OOB data ... "
+for offs in `seq 0 $oobsize` ; do
+
+ let ioffs=$pagesize+$offs
+
+ echo -n "Inject biterror at offset $ioffs ... "
+ ${inject_biterror} --offset=${ioffs} --bitmask=0x01 \
+ --input=testblock.mif \
+ --output=testblock_bitflip.mif
+ if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+
+ echo "Convert mif to bin ... "
+ rm testblock.img
+ nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \
+ testblock_bitflip.mif
+ if [ $? -ne "0" ]; then
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+
+ echo -n "Comparing data ... "
+ diff testblock.bin testblock.img
+ if [ $? -ne "0" ]; then
+ hexdump testblock.bin > testblock.bin.txt
+ hexdump testblock.img > testblock.img.txt
+ echo "Use tkdiff testblock.bin.txt testblock.img.txt to compare"
+ echo "failed!"
+ exit 1
+ else
+ echo "ok"
+ fi
+done
+
diff --git a/ubi-utils/scripts/inject_biterror.pl b/ubi-utils/scripts/inject_biterror.pl
new file mode 100644
index 0000000..b4a862a
--- /dev/null
+++ b/ubi-utils/scripts/inject_biterror.pl
@@ -0,0 +1,94 @@
+#!/usr/bin/perl -w
+#
+# 2007 Frank Haverkamp <haver@vnet.ibm.com>
+#
+# Program for bit-error injection. I am sure that perl experts do it
+# in 1 line. Please let me know how it is done right ;-).
+#
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+
+my $i;
+my $help;
+my $result;
+my $offset = 0;
+my $bitmask = 0x01;
+my $in = "input.mif";
+my $out = "output.mif";
+
+$result = GetOptions ("offset=i" => \$offset, # numeric
+ "bitmask=o" => \$bitmask, # numeric
+ "input=s" => \$in, # string
+ "output=s" => \$out, # string
+ "help|?" => \$help) or pod2usage(2);
+
+pod2usage(1) if $help;
+
+my $buf;
+
+open(my $in_fh, "<", $in)
+ or die "Cannot open file $in: $!";
+binmode $in_fh;
+
+open(my $out_fh, ">", $out) or
+ die "Cannot open file $out: $!";
+binmode $out_fh;
+
+$i = 0;
+while (sysread($in_fh, $buf, 1)) {
+
+ $buf = pack('C', unpack('C', $buf) ^ $bitmask) if ($i == $offset);
+ syswrite($out_fh, $buf, 1) or
+ die "Cannot write to offset $offset: $!";
+ $i++;
+}
+
+close $in_fh;
+close $out_fh;
+
+__END__
+
+=head1 NAME
+
+inject_biterrors.pl
+
+=head1 SYNOPSIS
+
+inject_biterror.pl [options]
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--help>
+
+Print a brief help message and exits.
+
+=item B<--offset>=I<offset>
+
+Byte-offset where bit-error should be injected.
+
+=item B<--bitmask>=I<bitmask>
+
+Bit-mask where to inject errors in the byte.
+
+=item B<--input>=I<input-file>
+
+Input file.
+
+=item B<--output>=I<output-file>
+
+Output file.
+
+=back
+
+=head1 DESCRIPTION
+
+B<inject_biterrors.pl> will read the given input file and inject
+biterrors at the I<offset> specified. The location of the biterrors
+are defined by the I<bitmask> parameter.
+
+=cut