flash.c 5.8 KB

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