xref: /openbmc/u-boot/tools/atmel_pmecc_params.c (revision 5c390a5b)
1*5c390a5bSAndreas Bießmann /*
2*5c390a5bSAndreas Bießmann  * (C) Copyright 2014 Andreas Bießmann <andreas.devel@googlemail.com>
3*5c390a5bSAndreas Bießmann  *
4*5c390a5bSAndreas Bießmann  * SPDX-License-Identifier:	GPL-2.0+
5*5c390a5bSAndreas Bießmann  */
6*5c390a5bSAndreas Bießmann 
7*5c390a5bSAndreas Bießmann /*
8*5c390a5bSAndreas Bießmann  * This is a host tool for generating an appropriate string out of board
9*5c390a5bSAndreas Bießmann  * configuration. The string is required for correct generation of PMECC
10*5c390a5bSAndreas Bießmann  * header which in turn is required for NAND flash booting of Atmel AT91 style
11*5c390a5bSAndreas Bießmann  * hardware.
12*5c390a5bSAndreas Bießmann  *
13*5c390a5bSAndreas Bießmann  * See doc/README.atmel_pmecc for more information.
14*5c390a5bSAndreas Bießmann  */
15*5c390a5bSAndreas Bießmann 
16*5c390a5bSAndreas Bießmann #include <config.h>
17*5c390a5bSAndreas Bießmann #include <stdlib.h>
18*5c390a5bSAndreas Bießmann 
19*5c390a5bSAndreas Bießmann static int pmecc_get_ecc_bytes(int cap, int sector_size)
20*5c390a5bSAndreas Bießmann {
21*5c390a5bSAndreas Bießmann 	int m = 12 + sector_size / 512;
22*5c390a5bSAndreas Bießmann 	return (m * cap + 7) / 8;
23*5c390a5bSAndreas Bießmann }
24*5c390a5bSAndreas Bießmann 
25*5c390a5bSAndreas Bießmann int main(int argc, char *argv[])
26*5c390a5bSAndreas Bießmann {
27*5c390a5bSAndreas Bießmann 	unsigned int use_pmecc = 0;
28*5c390a5bSAndreas Bießmann 	unsigned int sector_per_page;
29*5c390a5bSAndreas Bießmann 	unsigned int sector_size = CONFIG_PMECC_SECTOR_SIZE;
30*5c390a5bSAndreas Bießmann 	unsigned int oob_size = CONFIG_SYS_NAND_OOBSIZE;
31*5c390a5bSAndreas Bießmann 	unsigned int ecc_bits = CONFIG_PMECC_CAP;
32*5c390a5bSAndreas Bießmann 	unsigned int ecc_offset;
33*5c390a5bSAndreas Bießmann 
34*5c390a5bSAndreas Bießmann #ifdef CONFIG_ATMEL_NAND_HW_PMECC
35*5c390a5bSAndreas Bießmann 	use_pmecc = 1;
36*5c390a5bSAndreas Bießmann #endif
37*5c390a5bSAndreas Bießmann 
38*5c390a5bSAndreas Bießmann 	sector_per_page = CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_PMECC_SECTOR_SIZE;
39*5c390a5bSAndreas Bießmann 	ecc_offset = oob_size -
40*5c390a5bSAndreas Bießmann 		pmecc_get_ecc_bytes(ecc_bits, sector_size) * sector_per_page;
41*5c390a5bSAndreas Bießmann 
42*5c390a5bSAndreas Bießmann 	printf("usePmecc=%d,", use_pmecc);
43*5c390a5bSAndreas Bießmann 	printf("sectorPerPage=%d,", sector_per_page);
44*5c390a5bSAndreas Bießmann 	printf("sectorSize=%d,", sector_size);
45*5c390a5bSAndreas Bießmann 	printf("spareSize=%d,", oob_size);
46*5c390a5bSAndreas Bießmann 	printf("eccBits=%d,", ecc_bits);
47*5c390a5bSAndreas Bießmann 	printf("eccOffset=%d", ecc_offset);
48*5c390a5bSAndreas Bießmann 	printf("\n");
49*5c390a5bSAndreas Bießmann 
50*5c390a5bSAndreas Bießmann 	exit(EXIT_SUCCESS);
51*5c390a5bSAndreas Bießmann }
52