bootcount.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_MPC512X)
  35. #define CONFIG_SYS_BOOTCOUNT_ADDR (&((immap_t *)CONFIG_SYS_IMMR)->clk.bcr)
  36. #define CONFIG_SYS_BOOTCOUNT_SINGLEWORD
  37. #endif /* defined(CONFIG_MPC512X) */
  38. #if defined(CONFIG_8xx)
  39. #define CONFIG_SYS_BOOTCOUNT_ADDR (((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + \
  40. CPM_BOOTCOUNT_ADDR)
  41. #endif /* defined(CONFIG_8xx) */
  42. #if defined(CONFIG_MPC8260)
  43. #include <asm/cpm_8260.h>
  44. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + CPM_BOOTCOUNT_ADDR)
  45. #endif /* defined(CONFIG_MPC8260) */
  46. #if defined(CONFIG_MPC8360)
  47. #include <asm/immap_qe.h>
  48. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \
  49. QE_MURAM_SIZE - 2 * sizeof(u32))
  50. #endif /* defined(CONFIG_MPC8360) */
  51. #if defined(CONFIG_4xx)
  52. #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_OCM_DATA_ADDR + \
  53. CONFIG_SYS_BOOTCOUNT_ADDR)
  54. #endif /* defined(CONFIG_4xx) */
  55. #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
  56. void bootcount_store(ulong a)
  57. {
  58. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  59. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  60. out_be32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
  61. #else
  62. out_be32(reg, a);
  63. out_be32(reg + 4, BOOTCOUNT_MAGIC);
  64. #endif
  65. }
  66. ulong bootcount_load(void)
  67. {
  68. void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
  69. #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
  70. u32 tmp = in_be32(reg);
  71. if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  72. return 0;
  73. else
  74. return (tmp & 0x0000ffff);
  75. #else
  76. if (in_be32(reg + 4) != BOOTCOUNT_MAGIC)
  77. return 0;
  78. else
  79. return in_be32(reg);
  80. #endif
  81. }