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