bootcount_blackfin.c 781 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * functions for handling bootcount support
  3. *
  4. * Copyright (c) 2010 Analog Devices Inc.
  5. *
  6. * Licensed under the 2-clause BSD.
  7. */
  8. /* This version uses one 32bit storage and combines the magic/count */
  9. #include <common.h>
  10. /* We abuse the EVT0 MMR for bootcount storage by default */
  11. #ifndef CONFIG_SYS_BOOTCOUNT_ADDR
  12. # define CONFIG_SYS_BOOTCOUNT_ADDR EVT0
  13. #endif
  14. #define MAGIC_MASK 0xffff0000
  15. #define COUNT_MASK 0x0000ffff
  16. void bootcount_store(ulong cnt)
  17. {
  18. ulong magic = (BOOTCOUNT_MAGIC & MAGIC_MASK) | (cnt & COUNT_MASK);
  19. bfin_write32(CONFIG_SYS_BOOTCOUNT_ADDR, magic);
  20. }
  21. ulong bootcount_load(void)
  22. {
  23. ulong magic = bfin_read32(CONFIG_SYS_BOOTCOUNT_ADDR);
  24. if ((magic & MAGIC_MASK) == (BOOTCOUNT_MAGIC & MAGIC_MASK))
  25. return magic & COUNT_MASK;
  26. else
  27. return 0;
  28. }