// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2000-2009
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#include <common.h>
#include <command.h>
#include <version.h>
#include <linux/compiler.h>
#ifdef CONFIG_SYS_COREBOOT
#include <asm/arch/sysinfo.h>
#endif
const char __weak version_string[] = U_BOOT_VERSION_STRING;
#define BCH6_PAGE_SIZE 512
#define BCH6_OOB_SIZE 6
#define BCH6_ECC_SIZE 10
#define BCH6_UNIT_SIZE (BCH6_PAGE_SIZE+BCH6_OOB_SIZE+BCH6_ECC_SIZE)
#define TenBit_Mask 0x3ff
static const unsigned char gen_poly_6b[79] = {1,0,1,1,1,1,1,0,1,0,0,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,1,1,1,0,1,1,0,0,0,0,1,1,1,1,0,0,1,0,0,1,1,1,0,0,0,0,1,1,0,0,1,0,0,1,0,0,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1};
static unsigned char R_6b[78] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static inline unsigned char ToBit(unsigned short value, int bth)
{
value = (value >> bth) & 0x1;
return (unsigned char)value;
}
static void bch6_encode_ecc_byte(unsigned char input)
{
unsigned char R7_6b[78], R6_6b[78], R5_6b[78], R4_6b[78], R3_6b[78], R2_6b[78], R1_6b[78], R0_6b[78];
int i,j;
for (i=0;i<78;i++)
{
if (i == 0)
R7_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 7) ^ R_6b[77]));
else
R7_6b[i] = R_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 7) ^ R_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R6_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 6) ^ R7_6b[77]));
else
R6_6b[i] = R7_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 6) ^ R7_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R5_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 5) ^ R6_6b[77]));
else
R5_6b[i] = R6_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 5) ^ R6_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R4_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 4) ^ R5_6b[77]));
else
R4_6b[i] = R5_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 4) ^ R5_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R3_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 3) ^ R4_6b[77]));
else
R3_6b[i] = R4_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 3) ^ R4_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R2_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 2) ^ R3_6b[77]));
else
R2_6b[i] = R3_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 2) ^ R3_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R1_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 1) ^ R2_6b[77]));
else
R1_6b[i] = R2_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 1) ^ R2_6b[77]));
}
for (i=0;i<78;i++)
{
if (i == 0)
R0_6b[0] = 0x0 ^ (gen_poly_6b[0] & (ToBit(input, 0) ^ R1_6b[77]));
else
R0_6b[i] = R1_6b[i-1] ^ (gen_poly_6b[i] & (ToBit(input, 0) ^ R1_6b[77]));
}
//dumpR();
unsigned short synd[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; //memset(synd, 0, sizeof(synd));
for (i=0;i<6;i++)
for (j=12;j>=0;j--)
synd[i] |= (R0_6b[j+(i*13)] << j);
for (i=0;i<6;i++)
for (j=0;j<13;j++)
R_6b[(i*13+j)] = ToBit(synd[i], j);
//dumpSynd();
}
void bch6_ecc_512B_encode(unsigned char *ecc, // ecc: output 10 bytes of ECC code
const unsigned char *input_buf, // input_buf: the 512 bytes input data (BCH6_PAGE_SIZE bytes)
const unsigned char *oob){ // oob: 6 bytes out-of-band for input (BCH6_OOB_SIZE bytes)
// no need to init: synd, R7_6b[78], R6_6b[78], R5_6b[78], R4_6b[78], R3_6b[78], R2_6b[78], R1_6b[78], R0_6b[78];
// should be init here: R_6b, ecc[10]
//unsigned char ecc[10] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,};
//bzero(R_6b, sizeof(R_6b));
//bzero(ecc, BCH6_ECC_SIZE);
memset( R_6b, 0x00, sizeof(R_6b) );
memset( ecc, 0x00, BCH6_ECC_SIZE );
int i,j;
for ( i=0; i< BCH6_PAGE_SIZE; i++)
bch6_encode_ecc_byte(input_buf[i]);
for ( i=0; i< BCH6_OOB_SIZE; i++)
bch6_encode_ecc_byte(oob[i]);
for (i=0;i<9;i++)
for (j=7;j>=0;j--)
ecc[i] |= (R_6b[j+((8-i)*8+6)] << j);
for (j=5;j>=0;j--)
ecc[9] |= (R_6b[j] << (j+2));
#if 1
printf("ecc0=%x, ecc1=%x, ecc2=%x, ecc3=%x, ecc4=%x, ecc5=%x, ecc6=%x, ecc7=%x, ecc8=%x, ecc9=%x\n",
ecc[0], ecc[1], ecc[2], ecc[3], ecc[4], ecc[5], ecc[6], ecc[7], ecc[8], ecc[9]);
#endif
}
#define BCH_SECTS_PER_2K_PAGE (4)
#define BCH_SECTS_PER_4K_PAGE (8)
#define BCH_TAG_SIZE (6)
/* 未命名9 (2023/7/25 16:36:48)
起始位置(h): 00000000, 结束位置(h): 000007FF, 长度(h): 00000800 */
unsigned char rawData[2124] = {
0x27, 0x05, 0x19, 0x56, 0x92, 0x03, 0x34, 0x84, 0x64, 0xBE, 0x4B, 0x71,
0x00, 0x03, 0x16, 0x43, 0x83, 0xC0, 0x00, 0x00, 0x83, 0xC0, 0x00, 0x00,
0xA1, 0xCA, 0x24, 0x46, 0x11, 0x05, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, 0x80, 0x00, 0x79, 0xA9, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2F, 0x00, 0xEC, 0xD1,
0x71, 0x3C, 0x7A, 0xB6, 0x63, 0x39, 0xB6, 0x01, 0x16, 0x1B, 0xC4, 0xA8,
0x5E, 0x29, 0xAB, 0xD2, 0xD1, 0x46, 0x10, 0x28, 0x7D, 0x02, 0xA9, 0x17,
0x3B, 0x84, 0xD5, 0x23, 0x59, 0x8A, 0xB4, 0x68, 0xAE, 0x3B, 0x84, 0x84,
0x3E, 0x8E, 0x16, 0x02, 0x63, 0x2B, 0x90, 0x10, 0x11, 0x3C, 0x94, 0x9A,
0x19, 0x10, 0x96, 0x09, 0x2B, 0x1C, 0x23, 0xBB, 0x5C, 0x07, 0x1B, 0x84,
0xED, 0x0F, 0x0F, 0x88, 0x6B, 0xA8, 0x82, 0x10, 0x59, 0x38, 0x2A, 0xA2,
0xA7, 0x49, 0x5E, 0xB4, 0x2A, 0x19, 0xD9, 0x5E, 0x58, 0x7D, 0x2B, 0x67,
0x1C, 0x67, 0xC6, 0x6D, 0x8E, 0x87, 0xB2, 0x9E, 0x27, 0x2D, 0x27, 0x68,
0x09, 0x2C, 0x4F, 0xA1, 0x9A, 0x23, 0x21, 0x34, 0x23, 0x72, 0xAF, 0x46,
0x15, 0xB3, 0x2C, 0xD9, 0x76, 0x2A, 0x39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 0x01, 0x4B, 0x10, 0x29, 0x19, 0x68, 0xE9,
0x64, 0x5E, 0xA9, 0x42, 0xBD, 0x5A, 0xCB, 0x9B, 0xBC, 0x52, 0x3B, 0x93,
0x01, 0x48, 0x19, 0x30, 0xFC, 0x29, 0x0A, 0x35
};
void plr_ecc_encode_bch(u32_t ecc_ability, void *dma_addr, void *p_eccbuf)
{
u32_t encode_addr = (u32_t)dma_addr;
u32_t page_size = BCH_SECTOR_SIZE*BCH_SECTS_PER_2K_PAGE;
u8_t *tag_addr = (u8_t *)(encode_addr + page_size);
u8_t *syn_addr = (u8_t *)(tag_addr + BCH_TAG_SIZE*BCH_SECTS_PER_2K_PAGE);
u32_t syn_size;
if(12 == ecc_ability) syn_size = BCH12_SYNDROME_SIZE;
else syn_size = BCH6_SYNDROME_SIZE;
// dcache_wr_inv((u32_t)dma_addr, (u32_t)(dma_addr+page_size));
u32_t j;
for(j=0 ; j<BCH_SECTS_PER_2K_PAGE ; j++, encode_addr+=BCH_SECTOR_SIZE, tag_addr+=BCH_TAG_SIZE, syn_addr+=syn_size){
bch6_ecc_512B_encode((unsigned char *)(syn_addr), (unsigned char *)encode_addr, (unsigned char *)tag_addr);
//dcache_wr_inv((u32_t)tag_addr, (u32_t)(tag_addr+BCH_TAG_SIZE));
//dcache_wr_inv((u32_t)syn_addr, (u32_t)(syn_addr+syn_size));
}
}
#if !defined(__LUNA_KERNEL__)
void init_ecc_sw_patch(void)
{
// plr_spi_nand_flash_info._ecc_encode = &plr_ecc_encode_bch;
}
//REG_INIT_FUNC(init_ecc_sw_patch, 5);
#endif
unsigned char p_eccbuf[64] = {0xff};
/* 未命名11 (2023/7/25 17:30:44)
起始位置(h): 00000000, 结束位置(h): 0000003F, 长度(h): 00000040 */
unsigned char rawData_oob[64] = {
0xFF, 0xFF, 0xFF, 0xFF, 0x35, 0x32, 0x31, 0x30, 0x00, 0x01, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x02,
0xD0, 0xA2, 0x92, 0xD8, 0x80, 0xFE, 0x30, 0xB5, 0x8C, 0x64, 0xE5, 0x47,
0x50, 0xFB, 0x30, 0x19, 0x86, 0x8B, 0x28, 0x4C, 0xEC, 0x82, 0x30, 0x8A,
0x25, 0x23, 0x2A, 0xD2, 0xF0, 0xFC, 0x06, 0x13, 0x32, 0xD4, 0x61, 0x30,
0x27, 0x69, 0x01, 0x40
};
extern int macdbg_dmphex(const char* buff, int len);
unsigned char ecc_out[64];
void test_fuck( void )
{
macdbg_dmphex( (const char *)ecc_out, sizeof(ecc_out) );
bch6_ecc_512B_encode(ecc_out, rawData, rawData_oob );
macdbg_dmphex( (const char *)ecc_out, sizeof(ecc_out) );
}
static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
printf(display_options_get_banner(false, buf, sizeof(buf)));
printf("do_version = %p\n", do_version);
macdbg_dmphex( (const char *)rawData, sizeof(rawData) );
memcpy( &rawData[2048], rawData_oob, 24);
plr_ecc_encode_bch(6, rawData, NULL);
macdbg_dmphex( (const char *)rawData, sizeof(rawData) );
//test_fuck();
#ifdef CC_VERSION_STRING
puts(CC_VERSION_STRING "\n");
#endif
#ifdef LD_VERSION_STRING
puts(LD_VERSION_STRING "\n");
#endif
#ifdef CONFIG_SYS_COREBOOT
printf("coreboot-%s (%s)\n", lib_sysinfo.version, lib_sysinfo.build);
#endif
return 0;
}
U_BOOT_CMD(
version, 1, 1, do_version,
"print monitor, compiler and linker version",
""
);