flash.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * (C) Copyright 2004-2005
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. /*
  11. * Modified 4/5/2001
  12. * Wait for completion of each sector erase command issued
  13. * 4/5/2001
  14. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  15. */
  16. #include <common.h>
  17. #include <asm/ppc4xx.h>
  18. #include <asm/processor.h>
  19. #include <asm/ppc440.h>
  20. #include "bamboo.h"
  21. #undef DEBUG
  22. #ifdef DEBUG
  23. #define DEBUGF(x...) printf(x)
  24. #else
  25. #define DEBUGF(x...)
  26. #endif /* DEBUG */
  27. flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  28. /*
  29. * Mark big flash bank (16 bit instead of 8 bit access) in address with bit 0
  30. */
  31. static unsigned long flash_addr_table[][CONFIG_SYS_MAX_FLASH_BANKS] = {
  32. {0x87800001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
  33. {0x00000000, 0x00000000, 0x00000000}, /* 1:boot from pci 66 */
  34. {0x87800001, 0x00000000, 0x00000000}, /* 0:boot from nand flash */
  35. {0x87F00000, 0x87F80000, 0xFFC00001}, /* 3:boot from big flash 33*/
  36. {0x87F00000, 0x87F80000, 0xFFC00001}, /* 4:boot from big flash 66*/
  37. {0x00000000, 0x00000000, 0x00000000}, /* 5:boot from */
  38. {0x00000000, 0x00000000, 0x00000000}, /* 6:boot from pci 66 */
  39. {0x00000000, 0x00000000, 0x00000000}, /* 7:boot from */
  40. {0x87C00001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
  41. };
  42. /*
  43. * include common flash code (for amcc boards)
  44. */
  45. #include "../common/flash.c"
  46. /*-----------------------------------------------------------------------
  47. * Functions
  48. */
  49. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  50. static int write_word(flash_info_t * info, ulong dest, ulong data);
  51. /*-----------------------------------------------------------------------
  52. */
  53. unsigned long flash_init(void)
  54. {
  55. unsigned long total_b = 0;
  56. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  57. unsigned short index = 0;
  58. int i;
  59. unsigned long val;
  60. unsigned long ebc_boot_size;
  61. unsigned long boot_selection;
  62. mfsdr(SDR0_PINSTP, val);
  63. index = (val & SDR0_PSTRP0_BOOTSTRAP_MASK) >> 29;
  64. if ((index == 5) || (index == 7)) {
  65. /*
  66. * Boot Settings in IIC EEprom address 0xA8 or 0xA4
  67. * Read Serial Device Strap Register1 in PPC440EP
  68. */
  69. mfsdr(SDR0_SDSTP1, val);
  70. boot_selection = val & SDR0_SDSTP1_BOOT_SEL_MASK;
  71. ebc_boot_size = val & SDR0_SDSTP1_EBC_ROM_BS_MASK;
  72. switch(boot_selection) {
  73. case SDR0_SDSTP1_BOOT_SEL_EBC:
  74. switch(ebc_boot_size) {
  75. case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
  76. index = 3;
  77. break;
  78. case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
  79. index = 0;
  80. break;
  81. }
  82. break;
  83. case SDR0_SDSTP1_BOOT_SEL_PCI:
  84. index = 1;
  85. break;
  86. case SDR0_SDSTP1_BOOT_SEL_NDFC:
  87. index = 2;
  88. break;
  89. }
  90. } else if (index == 0) {
  91. if (in8(FPGA_SETTING_REG) & FPGA_SET_REG_OP_CODE_FLASH_ABOVE) {
  92. index = 8; /* sram below op code flash -> new index 8 */
  93. }
  94. }
  95. DEBUGF("\n");
  96. DEBUGF("FLASH: Index: %d\n", index);
  97. /* Init: no FLASHes known */
  98. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  99. flash_info[i].flash_id = FLASH_UNKNOWN;
  100. flash_info[i].sector_count = -1;
  101. flash_info[i].size = 0;
  102. /* check whether the address is 0 */
  103. if (flash_addr_table[index][i] == 0)
  104. continue;
  105. DEBUGF("Detection bank %d...\n", i);
  106. /* call flash_get_size() to initialize sector address */
  107. size_b[i] = flash_get_size((vu_long *) flash_addr_table[index][i],
  108. &flash_info[i]);
  109. flash_info[i].size = size_b[i];
  110. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  111. printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  112. i, size_b[i], size_b[i] << 20);
  113. flash_info[i].sector_count = -1;
  114. flash_info[i].size = 0;
  115. }
  116. /* Monitor protection ON by default */
  117. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  118. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  119. &flash_info[i]);
  120. #if defined(CONFIG_ENV_IS_IN_FLASH)
  121. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  122. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  123. &flash_info[i]);
  124. #if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR_REDUND)
  125. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  126. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  127. &flash_info[i]);
  128. #endif
  129. #endif
  130. total_b += flash_info[i].size;
  131. }
  132. return total_b;
  133. }