atmel_pmecc_params.c 1.3 KB

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