Source
x
static void dump_data_ecc(void *error_data, void *error_ecc, void *correct_data,
/*
* Test the implementation for software ECC
*
* No actual MTD device is needed, So we don't need to warry about losing
* important data by human error.
*
* This covers possible patterns of corruption which can be reliably corrected
* or detected.
*/
struct nand_ecc_test {
const char *name;
void (*prepare)(void *, void *, void *, void *, const size_t);
int (*verify)(void *, void *, void *, const size_t);
};
/*
* The reason for this __change_bit_le() instead of __change_bit() is to inject
* bit error properly within the region which is not a multiple of
* sizeof(unsigned long) on big-endian systems
*/
static void single_bit_error_data(void *error_data, void *correct_data,
size_t size)
{
unsigned int offset = prandom_u32() % (size * BITS_PER_BYTE);
memcpy(error_data, correct_data, size);
__change_bit_le(offset, error_data);
}
static void double_bit_error_data(void *error_data, void *correct_data,
size_t size)
{
unsigned int offset[2];
offset[0] = prandom_u32() % (size * BITS_PER_BYTE);
do {
offset[1] = prandom_u32() % (size * BITS_PER_BYTE);
} while (offset[0] == offset[1]);
memcpy(error_data, correct_data, size);
__change_bit_le(offset[0], error_data);
__change_bit_le(offset[1], error_data);
}
static unsigned int random_ecc_bit(size_t size)
{
unsigned int offset = prandom_u32() % (3 * BITS_PER_BYTE);
if (size == 256) {
/*
* Don't inject a bit error into the insignificant bits (16th
* and 17th bit) in ECC code for 256 byte data block
*/
while (offset == 16 || offset == 17)
offset = prandom_u32() % (3 * BITS_PER_BYTE);
}
return offset;
}
static void single_bit_error_ecc(void *error_ecc, void *correct_ecc,
size_t size)
{
unsigned int offset = random_ecc_bit(size);
memcpy(error_ecc, correct_ecc, 3);