Esempio n. 1
0
bool run_crc_err_test() {
  prep_buffers();
  uint32_t ecc = ecc_generate(buf1);
  int bit_idx = rand()%24;
  ecc ^= 0x1 << bit_idx;
  return ecc_verify(buf2, ecc);
}
Esempio n. 2
0
static int generateECC(int setting, uint8_t* data, uint8_t* ecc) {
	int eccSize = 0;

	if(setting == 4) {
		eccSize = 15;
	} else if(setting == 8) {
		eccSize = 20;
	} else if(setting == 0) {
		eccSize = 10;
	} else {
		return ERROR_ECC;
	}

	uint8_t* dataPtr = data;
	uint8_t* eccPtr = ecc;
	int sectorsLeft = Data.sectorsPerPage;

	while(sectorsLeft > 0) {
		int toCheck;
		if(sectorsLeft > 4)
			toCheck = 4;
		else
			toCheck = sectorsLeft;

		ecc_generate(setting, toCheck, dataPtr, eccPtr);
		ecc_finish();

		if(LargePages) {
			// If there are more than 4 sectors in a page...
			int i;
			for(i = 0; i < toCheck; i++) {
				// loop through each sector that we have generated this time's ECC
				uint8_t* x = &eccPtr[eccSize * i]; // first byte of ECC
				uint8_t* y = x + eccSize - 1; // last byte of ECC
				while(x < y) {
					// swap the byte order of them
					uint8_t t = *y;
					*y = *x;
					*x = t;
					x++;
					y--;
				}
			}
		}

		dataPtr += toCheck * SECTOR_SIZE;
		eccPtr += toCheck * eccSize;
		sectorsLeft -= toCheck;
	}

	return 0;
}
Esempio n. 3
0
bool run_1_err_test() {
  prep_buffers();
  uint32_t ecc = ecc_generate(buf1);
  int byte_idx = rand()%512;
  int bit_idx = rand()%8;
  buf2[byte_idx] ^= 0x01 << bit_idx;
  bool v = ecc_verify(buf2, ecc);
  if (v) {
    if (!check_buffers()) {
      printf("VERIFIED but not FIXED\n");
      return false;
    }
  }
  return v;
}
Esempio n. 4
0
bool run_2_err_test() {
  prep_buffers();
  uint32_t ecc = ecc_generate(buf1);
  int byte_idx = rand()%512;
  int bit_idx = rand()%8;
  int byte2_idx = rand()%512;
  int bit2_idx = rand()%8;
  while ((byte2_idx == byte_idx) && (bit_idx == bit2_idx)) {
    byte2_idx = rand()%512;
    bit2_idx = rand()%8;
  }
  buf2[byte_idx] ^= 0x01 << bit_idx;
  buf2[byte2_idx] ^= 0x01 << bit2_idx;
  bool v = ecc_verify(buf2, ecc);
  return v == false;
}
Esempio n. 5
0
uint32_t test_value(int where, int what) {
  zero_buffers();
  buf1[where] = what;
  return ecc_generate(buf1);
}
Esempio n. 6
0
bool run_no_err_test() {
  prep_buffers();
  uint32_t ecc = ecc_generate(buf1);
  return ecc_verify(buf2, ecc);
}