bootcount.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * (C) Copyright 2010
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. /*
  26. * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This
  27. * way, some boards can define it directly in their config header.
  28. */
  29. #if !defined(CONFIG_SYS_BOOTCOUNT_ADDR)
  30. #if defined(CONFIG_MPC5xxx)
  31. #define CONFIG_SYS_BOOTCOUNT_ADDR (MPC5XXX_CDM_BRDCRMB)
  32. #define CONFIG_SYS_BOOTCOUNT_SINGLEWORD
  33. #endif /* defined(CONFIG_MPC5xxx) */
  34. #if defined(CONFIG_8xx)
  35. #define CONFIG_SYS_BOOTCOUNT_ADDR (((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + \
  36. CPM_BOOTCOUNT_ADDR)
  37. #endif /* defined(CONFIG_8xx) */
  38. #if defined(CONFIG_MPC8260)
  39. #include <asm/cpm_8260.h>
  40. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + CPM_BOOTCOUNT_ADDR)
  41. #endif /* defined(CONFIG_MPC8260) */
  42. #if defined(CONFIG_MPC8360)
  43. #include <asm/immap_qe.h>
  44. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \
  45. QE_MURAM_SIZE - 2 * sizeof(u32))
  46. #endif /* defined(CONFIG_MPC8360) */
  47. #if defined(CONFIG_4xx)
  48. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_OCM_DATA_ADDR + \
  49. CONFIG_SYS_BOOTCOUNT_ADDR)
  50. #endif /* defined(CONFIG_4xx) */
  51. #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
  52. void bootcount_store(ulong a)
  53. {
  54. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  55. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  56. out_be32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
  57. #else
  58. out_be32(reg, a);
  59. out_be32(reg + 4, BOOTCOUNT_MAGIC);
  60. #endif
  61. }
  62. ulong bootcount_load(void)
  63. {
  64. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  65. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  66. if (in_be16(reg + 2) != (BOOTCOUNT_MAGIC & 0xffff))
  67. return 0;
  68. else
  69. return in_be16(reg);
  70. #else
  71. if (in_be32(reg + 4) != BOOTCOUNT_MAGIC)
  72. return 0;
  73. else
  74. return in_be32(reg);
  75. #endif
  76. }