flash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002 Jun Gu <jung@artesyncp.com>
  6. * Add support for Am29F016D and dynamic switch setting.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * Modified 4/5/2001
  28. * Wait for completion of each sector erase command issued
  29. * 4/5/2001
  30. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  31. */
  32. #include <common.h>
  33. #include <ppc4xx.h>
  34. #include <asm/processor.h>
  35. #undef DEBUG
  36. #ifdef DEBUG
  37. #define DEBUGF(x...) printf(x)
  38. #else
  39. #define DEBUGF(x...)
  40. #endif /* DEBUG */
  41. static unsigned long flash_addr_table[1][CONFIG_SYS_MAX_FLASH_BANKS] = {
  42. {0xff900000, 0xff980000, 0xffc00000}, /* 0:000: configuraton 3 */
  43. };
  44. /*
  45. * include common flash code (for amcc boards)
  46. */
  47. #include "../common/flash.c"
  48. /*-----------------------------------------------------------------------
  49. * Functions
  50. */
  51. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  52. unsigned long flash_init(void)
  53. {
  54. unsigned long total_b = 0;
  55. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  56. unsigned short index = 0;
  57. int i;
  58. /* read FPGA base register FPGA_REG0 */
  59. DEBUGF("\n");
  60. DEBUGF("FLASH: Index: %d\n", index);
  61. /* Init: no FLASHes known */
  62. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  63. flash_info[i].flash_id = FLASH_UNKNOWN;
  64. flash_info[i].sector_count = -1;
  65. flash_info[i].size = 0;
  66. /* check whether the address is 0 */
  67. if (flash_addr_table[index][i] == 0) {
  68. continue;
  69. }
  70. /* call flash_get_size() to initialize sector address */
  71. size_b[i] = flash_get_size((vu_long *)
  72. flash_addr_table[index][i],
  73. &flash_info[i]);
  74. flash_info[i].size = size_b[i];
  75. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  76. printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  77. i, size_b[i], size_b[i] << 20);
  78. flash_info[i].sector_count = -1;
  79. flash_info[i].size = 0;
  80. }
  81. /* Monitor protection ON by default */
  82. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  83. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  84. &flash_info[2]);
  85. #ifdef CONFIG_ENV_IS_IN_FLASH
  86. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  87. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  88. &flash_info[2]);
  89. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  90. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  91. &flash_info[2]);
  92. #endif
  93. total_b += flash_info[i].size;
  94. }
  95. return total_b;
  96. }