Add the ability to generate test patterns for write testing. This will be useful once we create a --test function for flashrom.
The test patterns make it easy to find skipped and duplicated bytes, are human readable, and have block numbers to detect aliasing or wraparounds. Current size limit is 16 MByte, but since neither LPC nor FWH nor SPI chips exist with bigger sizes, this is reasonably safe. If you ignore the block numbers, test patterns look like this: Pattern 0 is 05 15 25 35 45 55 65 75 85 95 a5 b5 c5 d5 e5 f5 Pattern 1 is a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af 0x5 and 0xa were picked because they are 0101 and 1010 binary.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-testpattern/flashrom.c =================================================================== --- flashrom-testpattern/flashrom.c (Revision 756) +++ flashrom-testpattern/flashrom.c (Arbeitskopie) @@ -407,6 +407,40 @@ return ret; }
+int generate_testpattern(uint8_t *buf, uint32_t size, int variant) +{ + int i; + + if (!buf) { + fprintf(stderr, "Invalid buffer!\n"); + return 1; + } + + /* Pattern 0 is 05 15 25 35 45 55 65 75 85 95 a5 b5 c5 d5 e5 f5 + * Pattern 1 is a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af + * 0x5 and 0xa were picked because they are 0101 and 1010 binary. + */ + switch (variant) { + case 0: + for (i = 0; i < size; i++) + buf[i] = (i % 0x10) << 4 | 5; + break; + case 1: + for (i = 0; i < size; i++) + buf[i] = 0xa0 | (i % 0x10); + break; + } + /* Write block number in the last two bytes of each 256-byte block, + * big endian for easier reading of the hexdump. Note that this wraps + * around for chips larger than 2^24 bytes (16 MB). + */ + for (i = 0; i < size / 256; i++) { + buf[i * 256 + 254] = (i >> 8) & 0xff; + buf[i * 256 + 255] = i & 0xff; + } + return 0; +} + int check_max_decode(enum chipbustype buses, uint32_t size) { int limitexceeded = 0;