bootcount.c 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. }
  19. __weak ulong bootcount_load(void)
  20. {
  21. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  22. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  23. u32 tmp = raw_bootcount_load(reg);
  24. if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  25. return 0;
  26. else
  27. return (tmp & 0x0000ffff);
  28. #else
  29. if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
  30. return 0;
  31. else
  32. return raw_bootcount_load(reg);
  33. #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
  34. }