core/psd/imx6ull/bch.c
static uint32_t *compute_generator_polynomial(struct bch_control *bch)
{
	const unsigned int m = GF_M(bch);
	const unsigned int t = GF_T(bch);
	int n, err = 0;
	unsigned int i, j, nbits, r, word, *roots;
	struct gf_poly *g;
	uint32_t *genpoly;

	g = bch_alloc(GF_POLY_SZ(m*t), &err);
	roots = bch_alloc((bch->n+1)*sizeof(*roots), &err);
	genpoly = bch_alloc(DIV_ROUND_UP(m*t+1, 32)*sizeof(*genpoly), &err);

	if (err) {
		free(genpoly);
		genpoly = NULL;
		goto finish;
	}

	/* enumerate all roots of g(X) */
	memset(roots , 0, (bch->n+1)*sizeof(*roots));
	for (i = 0; i < t; i++) {
		for (j = 0, r = 2*i+1; j < m; j++) {
			roots[r] = 1;
			r = mod_s(bch, 2*r);
		}
	}
	/* build generator polynomial g(X) */
	g->deg = 0;
	g->c[0] = 1;
	for (i = 0; i < GF_N(bch); i++) {
		if (roots[i]) {
			/* multiply g(X) by (X+root) */
			r = bch->a_pow_tab[i];
			g->c[g->deg+1] = 1;
			for (j = g->deg; j > 0; j--)
				g->c[j] = gf_mul(bch, g->c[j], r)^g->c[j-1];

			g->c[0] = gf_mul(bch, g->c[0], r);
			g->deg++;
		}
	}
	/* store left-justified binary representation of g(X) */
	n = g->deg+1;
	i = 0;
	while (n > 0) {
		nbits = (n > 32) ? 32 : n;
		for (j = 0, word = 0; j < nbits; j++) {
			if (g->c[n-1-j])
				word |= 1u << (31-j);
		}
		genpoly[i++] = word;
		n -= nbits;
	}

	bch->ecc_bits = g->deg;

finish:
	free(g);
	free(roots);

	return genpoly;
}
/*
 * compute generator polynomial for given (m,t) parameters.
 */
compute generator polynomial for given (m,t) parameters.
compute generator polynomial for given ( m t ) parameters .
static uint32_t *compute_generator_polynomial(struct bch_control *bch)
{
	const unsigned int m = GF_M(bch);
	const unsigned int t = GF_T(bch);
	int n, err = 0;
	unsigned int i, j, nbits, r, word, *roots;
	struct gf_poly *g;
	uint32_t *genpoly;
	g = bch_alloc(GF_POLY_SZ(m*t), &err);
	roots = bch_alloc((bch->n+1)*sizeof(*roots), &err);
	genpoly = bch_alloc(DIV_ROUND_UP(m*t+1, 32)*sizeof(*genpoly), &err);
	if (err) {
		free(genpoly);
		genpoly = NULL;
		goto finish;
	}
	memset(roots , 0, (bch->n+1)*sizeof(*roots));
	for (i = 0; i < t; i++) {
		for (j = 0, r = 2*i+1; j < m; j++) {
			roots[r] = 1;
			r = mod_s(bch, 2*r);
		}
	}
	g->deg = 0;
	g->c[0] = 1;
	for (i = 0; i < GF_N(bch); i++) {
		if (roots[i]) {
			r = bch->a_pow_tab[i];
			g->c[g->deg+1] = 1;
			for (j = g->deg; j > 0; j--)
				g->c[j] = gf_mul(bch, g->c[j], r)^g->c[j-1];
			g->c[0] = gf_mul(bch, g->c[0], r);
			g->deg++;
		}
	}
	n = g->deg+1;
	i = 0;
	while (n > 0) {
		nbits = (n > 32) ? 32 : n;
		for (j = 0, word = 0; j < nbits; j++) {
			if (g->c[n-1-j])
				word |= 1u << (31-j);
		}
		genpoly[i++] = word;
		n -= nbits;
	}
	bch->ecc_bits = g->deg;
finish:
	free(g);
	free(roots);
	return genpoly;
}
static uint32_t * compute_generator_polynomial ( struct bch_control * bch ) { const unsigned int m = GF_M ( bch ) ; const unsigned int t = GF_T ( bch ) ; int n , err = 0 ; unsigned int i , j , nbits , r , word , * roots ; struct gf_poly * g ; uint32_t * genpoly ; g = bch_alloc ( GF_POLY_SZ ( m * t ) , & err ) ; roots = bch_alloc ( ( bch -> n + 1 ) * sizeof ( * roots ) , & err ) ; genpoly = bch_alloc ( DIV_ROUND_UP ( m * t + 1 , 32 ) * sizeof ( * genpoly ) , & err ) ; if ( err ) { free ( genpoly ) ; genpoly = NULL ; goto finish ; } memset ( roots , 0 , ( bch -> n + 1 ) * sizeof ( * roots ) ) ; for ( i = 0 ; i < t ; i ++ ) { for ( j = 0 , r = 2 * i + 1 ; j < m ; j ++ ) { roots [ r ] = 1 ; r = mod_s ( bch , 2 * r ) ; } } g -> deg = 0 ; g -> c [ 0 ] = 1 ; for ( i = 0 ; i < GF_N ( bch ) ; i ++ ) { if ( roots [ i ] ) { r = bch -> a_pow_tab [ i ] ; g -> c [ g -> deg + 1 ] = 1 ; for ( j = g -> deg ; j > 0 ; j -- ) g -> c [ j ] = gf_mul ( bch , g -> c [ j ] , r ) ^ g -> c [ j - 1 ] ; g -> c [ 0 ] = gf_mul ( bch , g -> c [ 0 ] , r ) ; g -> deg ++ ; } } n = g -> deg + 1 ; i = 0 ; while ( n > 0 ) { nbits = ( n > 32 ) ? 32 : n ; for ( j = 0 , word = 0 ; j < nbits ; j ++ ) { if ( g -> c [ n - 1 - j ] ) word |= 1u << ( 31 - j ) ; } genpoly [ i ++ ] = word ; n -= nbits ; } bch -> ecc_bits = g -> deg ; finish : free ( g ) ; free ( roots ) ; return genpoly ; }
compute generator polynomial for given (m,t) parameters.
compute generator polynomial for given ( m t ) parameters .
/* enumerate all roots of g(X) */ /* build generator polynomial g(X) */ /* multiply g(X) by (X+root) */ /* store left-justified binary representation of g(X) */