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