atmel_pmecc_params.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * (C) Copyright 2014 Andreas Bießmann <andreas@biessmann.org>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  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. #include <config.h>
  15. #include <stdlib.h>
  16. static int pmecc_get_ecc_bytes(int cap, int sector_size)
  17. {
  18. int m = 12 + sector_size / 512;
  19. return (m * cap + 7) / 8;
  20. }
  21. int main(int argc, char *argv[])
  22. {
  23. unsigned int use_pmecc = 0;
  24. unsigned int sector_per_page;
  25. unsigned int sector_size = CONFIG_PMECC_SECTOR_SIZE;
  26. unsigned int oob_size = CONFIG_SYS_NAND_OOBSIZE;
  27. unsigned int ecc_bits = CONFIG_PMECC_CAP;
  28. unsigned int ecc_offset;
  29. #ifdef CONFIG_ATMEL_NAND_HW_PMECC
  30. use_pmecc = 1;
  31. #endif
  32. sector_per_page = CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_PMECC_SECTOR_SIZE;
  33. ecc_offset = oob_size -
  34. pmecc_get_ecc_bytes(ecc_bits, sector_size) * sector_per_page;
  35. printf("usePmecc=%d,", use_pmecc);
  36. printf("sectorPerPage=%d,", sector_per_page);
  37. printf("sectorSize=%d,", sector_size);
  38. printf("spareSize=%d,", oob_size);
  39. printf("eccBits=%d,", ecc_bits);
  40. printf("eccOffset=%d", ecc_offset);
  41. printf("\n");
  42. exit(EXIT_SUCCESS);
  43. }