bootcount.c 1009 B

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