bootcount.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. u32 tmp = in_be32(reg);
  67. if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  68. return 0;
  69. else
  70. return (tmp & 0x0000ffff);
  71. #else
  72. if (in_be32(reg + 4) != BOOTCOUNT_MAGIC)
  73. return 0;
  74. else
  75. return in_be32(reg);
  76. #endif
  77. }