bootcount.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2010-2012
  4. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  5. */
  6. #include <bootcount.h>
  7. #include <linux/compiler.h>
  8. /* Now implement the generic default functions */
  9. __weak void bootcount_store(ulong a)
  10. {
  11. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  12. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  13. raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
  14. #else
  15. raw_bootcount_store(reg, a);
  16. raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
  17. #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
  18. flush_dcache_range(CONFIG_SYS_BOOTCOUNT_ADDR,
  19. CONFIG_SYS_BOOTCOUNT_ADDR +
  20. CONFIG_SYS_CACHELINE_SIZE);
  21. }
  22. __weak ulong bootcount_load(void)
  23. {
  24. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  25. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  26. u32 tmp = raw_bootcount_load(reg);
  27. if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  28. return 0;
  29. else
  30. return (tmp & 0x0000ffff);
  31. #else
  32. if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
  33. return 0;
  34. else
  35. return raw_bootcount_load(reg);
  36. #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
  37. }