#include #include #include #include #include #include "libbch.h" #define SECTOR_DATA_SIZE 512 #define SECTOR_META_SIZE 3 #define SECTOR_ECC_SIZE 13 #define SECTOR_SIZE (SECTOR_DATA_SIZE + SECTOR_META_SIZE + SECTOR_ECC_SIZE) /* scramble mode */ enum { CONTINOUS_ENC, /* scramble whole block at once */ PAGE_ENC /* nand bootloader is scrambled in 0x200 chunks */ }; static uint8_t reverse_bits(uint8_t b) { return (((b & 0x80) >> 7)| ((b & 0x40) >> 5)| ((b & 0x20) >> 3)| ((b & 0x10) >> 1)| ((b & 0x08) << 1)| ((b & 0x04) << 3)| ((b & 0x02) << 5)| ((b & 0x01) << 7)); } static int libbch_decode_sec(struct bch_control *bch, uint8_t *inbuf, uint8_t *outbuf) { unsigned int errloc[8]; static const uint8_t mask[13] = { 0x4e, 0x8c, 0x9d, 0x52, 0x2d, 0x6c, 0x7c, 0xcb, 0xc3, 0x12, 0x14, 0x19, 0x37, }; int i, err_num = 0; /* ecc masking polynomial */ for (i=0; i