flash.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * (C) Copyright 2000-2005
  3. * Wolfgang Denk, DENX Software Engineering, wd@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. /*
  24. * Modified 4/5/2001
  25. * Wait for completion of each sector erase command issued
  26. * 4/5/2001
  27. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  28. */
  29. #include <common.h>
  30. #include <ppc4xx.h>
  31. #include <asm/processor.h>
  32. #undef DEBUG
  33. #ifdef DEBUG
  34. #define DEBUGF(x...) printf(x)
  35. #else
  36. #define DEBUGF(x...)
  37. #endif /* DEBUG */
  38. /*
  39. * include common flash code (for amcc boards)
  40. */
  41. #include "../common/flash.c"
  42. /*-----------------------------------------------------------------------
  43. * Functions
  44. */
  45. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  46. static void flash_get_offsets(ulong base, flash_info_t * info);
  47. unsigned long flash_init(void)
  48. {
  49. unsigned long size_b0, size_b1;
  50. int i;
  51. uint pbcr;
  52. unsigned long base_b0, base_b1;
  53. /* Init: no FLASHes known */
  54. for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
  55. flash_info[i].flash_id = FLASH_UNKNOWN;
  56. }
  57. /* Static FLASH Bank configuration here - FIXME XXX */
  58. size_b0 =
  59. flash_get_size((vu_long *) FLASH_BASE0_PRELIM, &flash_info[0]);
  60. if (flash_info[0].flash_id == FLASH_UNKNOWN) {
  61. printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
  62. size_b0, size_b0 << 20);
  63. }
  64. /* Only one bank */
  65. if (CFG_MAX_FLASH_BANKS == 1) {
  66. /* Setup offsets */
  67. flash_get_offsets(FLASH_BASE0_PRELIM, &flash_info[0]);
  68. /* Monitor protection ON by default */
  69. (void)flash_protect(FLAG_PROTECT_SET,
  70. CFG_MONITOR_BASE,
  71. CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
  72. &flash_info[0]);
  73. #ifdef CFG_ENV_IS_IN_FLASH
  74. (void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR,
  75. CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
  76. &flash_info[0]);
  77. (void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR_REDUND,
  78. CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1,
  79. &flash_info[0]);
  80. #endif
  81. size_b1 = 0;
  82. flash_info[0].size = size_b0;
  83. } else {
  84. /* 2 banks */
  85. size_b1 =
  86. flash_get_size((vu_long *) FLASH_BASE1_PRELIM,
  87. &flash_info[1]);
  88. /* Re-do sizing to get full correct info */
  89. if (size_b1) {
  90. mtdcr(ebccfga, pb0cr);
  91. pbcr = mfdcr(ebccfgd);
  92. mtdcr(ebccfga, pb0cr);
  93. base_b1 = -size_b1;
  94. pbcr =
  95. (pbcr & 0x0001ffff) | base_b1 |
  96. (((size_b1 / 1024 / 1024) - 1) << 17);
  97. mtdcr(ebccfgd, pbcr);
  98. /* printf("pb1cr = %x\n", pbcr); */
  99. }
  100. if (size_b0) {
  101. mtdcr(ebccfga, pb1cr);
  102. pbcr = mfdcr(ebccfgd);
  103. mtdcr(ebccfga, pb1cr);
  104. base_b0 = base_b1 - size_b0;
  105. pbcr =
  106. (pbcr & 0x0001ffff) | base_b0 |
  107. (((size_b0 / 1024 / 1024) - 1) << 17);
  108. mtdcr(ebccfgd, pbcr);
  109. /* printf("pb0cr = %x\n", pbcr); */
  110. }
  111. size_b0 = flash_get_size((vu_long *) base_b0, &flash_info[0]);
  112. flash_get_offsets(base_b0, &flash_info[0]);
  113. /* monitor protection ON by default */
  114. (void)flash_protect(FLAG_PROTECT_SET,
  115. base_b0 + size_b0 - monitor_flash_len,
  116. base_b0 + size_b0 - 1, &flash_info[0]);
  117. if (size_b1) {
  118. /* Re-do sizing to get full correct info */
  119. size_b1 =
  120. flash_get_size((vu_long *) base_b1, &flash_info[1]);
  121. flash_get_offsets(base_b1, &flash_info[1]);
  122. /* monitor protection ON by default */
  123. (void)flash_protect(FLAG_PROTECT_SET,
  124. base_b1 + size_b1 -
  125. monitor_flash_len,
  126. base_b1 + size_b1 - 1,
  127. &flash_info[1]);
  128. /* monitor protection OFF by default (one is enough) */
  129. (void)flash_protect(FLAG_PROTECT_CLEAR,
  130. base_b0 + size_b0 -
  131. monitor_flash_len,
  132. base_b0 + size_b0 - 1,
  133. &flash_info[0]);
  134. } else {
  135. flash_info[1].flash_id = FLASH_UNKNOWN;
  136. flash_info[1].sector_count = -1;
  137. }
  138. flash_info[0].size = size_b0;
  139. flash_info[1].size = size_b1;
  140. } /* else 2 banks */
  141. return (size_b0 + size_b1);
  142. }
  143. static void flash_get_offsets(ulong base, flash_info_t * info)
  144. {
  145. int i;
  146. /* set up sector start address table */
  147. if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
  148. (info->flash_id == FLASH_AM040)) {
  149. for (i = 0; i < info->sector_count; i++)
  150. info->start[i] = base + (i * 0x00010000);
  151. } else {
  152. if (info->flash_id & FLASH_BTYPE) {
  153. /* set sector offsets for bottom boot block type */
  154. info->start[0] = base + 0x00000000;
  155. info->start[1] = base + 0x00004000;
  156. info->start[2] = base + 0x00006000;
  157. info->start[3] = base + 0x00008000;
  158. for (i = 4; i < info->sector_count; i++) {
  159. info->start[i] =
  160. base + (i * 0x00010000) - 0x00030000;
  161. }
  162. } else {
  163. /* set sector offsets for top boot block type */
  164. i = info->sector_count - 1;
  165. info->start[i--] = base + info->size - 0x00004000;
  166. info->start[i--] = base + info->size - 0x00006000;
  167. info->start[i--] = base + info->size - 0x00008000;
  168. for (; i >= 0; i--) {
  169. info->start[i] = base + i * 0x00010000;
  170. }
  171. }
  172. }
  173. }