xref: /openbmc/u-boot/tools/atmel_pmecc_params.c (revision e8f80a5a)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
25c390a5bSAndreas Bießmann /*
309c2b8f3SAndreas Bießmann  * (C) Copyright 2014 Andreas Bießmann <andreas@biessmann.org>
45c390a5bSAndreas Bießmann  */
55c390a5bSAndreas Bießmann 
65c390a5bSAndreas Bießmann /*
75c390a5bSAndreas Bießmann  * This is a host tool for generating an appropriate string out of board
85c390a5bSAndreas Bießmann  * configuration. The string is required for correct generation of PMECC
95c390a5bSAndreas Bießmann  * header which in turn is required for NAND flash booting of Atmel AT91 style
105c390a5bSAndreas Bießmann  * hardware.
115c390a5bSAndreas Bießmann  *
125c390a5bSAndreas Bießmann  * See doc/README.atmel_pmecc for more information.
135c390a5bSAndreas Bießmann  */
145c390a5bSAndreas Bießmann 
155c390a5bSAndreas Bießmann #include <config.h>
165c390a5bSAndreas Bießmann #include <stdlib.h>
175c390a5bSAndreas Bießmann 
pmecc_get_ecc_bytes(int cap,int sector_size)185c390a5bSAndreas Bießmann static int pmecc_get_ecc_bytes(int cap, int sector_size)
195c390a5bSAndreas Bießmann {
205c390a5bSAndreas Bießmann 	int m = 12 + sector_size / 512;
215c390a5bSAndreas Bießmann 	return (m * cap + 7) / 8;
225c390a5bSAndreas Bießmann }
235c390a5bSAndreas Bießmann 
main(int argc,char * argv[])245c390a5bSAndreas Bießmann int main(int argc, char *argv[])
255c390a5bSAndreas Bießmann {
265c390a5bSAndreas Bießmann 	unsigned int use_pmecc = 0;
275c390a5bSAndreas Bießmann 	unsigned int sector_per_page;
285c390a5bSAndreas Bießmann 	unsigned int sector_size = CONFIG_PMECC_SECTOR_SIZE;
295c390a5bSAndreas Bießmann 	unsigned int oob_size = CONFIG_SYS_NAND_OOBSIZE;
305c390a5bSAndreas Bießmann 	unsigned int ecc_bits = CONFIG_PMECC_CAP;
315c390a5bSAndreas Bießmann 	unsigned int ecc_offset;
325c390a5bSAndreas Bießmann 
335c390a5bSAndreas Bießmann #ifdef CONFIG_ATMEL_NAND_HW_PMECC
345c390a5bSAndreas Bießmann 	use_pmecc = 1;
355c390a5bSAndreas Bießmann #endif
365c390a5bSAndreas Bießmann 
375c390a5bSAndreas Bießmann 	sector_per_page = CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_PMECC_SECTOR_SIZE;
385c390a5bSAndreas Bießmann 	ecc_offset = oob_size -
395c390a5bSAndreas Bießmann 		pmecc_get_ecc_bytes(ecc_bits, sector_size) * sector_per_page;
405c390a5bSAndreas Bießmann 
415c390a5bSAndreas Bießmann 	printf("usePmecc=%d,", use_pmecc);
425c390a5bSAndreas Bießmann 	printf("sectorPerPage=%d,", sector_per_page);
435c390a5bSAndreas Bießmann 	printf("sectorSize=%d,", sector_size);
445c390a5bSAndreas Bießmann 	printf("spareSize=%d,", oob_size);
455c390a5bSAndreas Bießmann 	printf("eccBits=%d,", ecc_bits);
465c390a5bSAndreas Bießmann 	printf("eccOffset=%d", ecc_offset);
475c390a5bSAndreas Bießmann 	printf("\n");
485c390a5bSAndreas Bießmann 
495c390a5bSAndreas Bießmann 	exit(EXIT_SUCCESS);
505c390a5bSAndreas Bießmann }
51