bootstrap.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * (C) Copyright 2008
  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. */
  24. #include <common.h>
  25. #include <command.h>
  26. #include <i2c.h>
  27. #include <asm/io.h>
  28. /*
  29. * NOR and NAND boot options change bytes 5, 6, 8, 9, 11. The
  30. * values are independent of the rest of the clock settings.
  31. */
  32. #define NAND_COMPATIBLE 0x01
  33. #define NOR_COMPATIBLE 0x02
  34. #define I2C_EEPROM_ADDR 0x52
  35. static char *config_labels[] = {
  36. "CPU: 600 PLB: 200 OPB: 100 EBC: 100",
  37. "CPU: 800 PLB: 200 OPB: 100 EBC: 100",
  38. "CPU:1000 PLB: 200 OPB: 100 EBC: 100",
  39. "CPU:1066 PLB: 266 OPB: 88 EBC: 88",
  40. NULL
  41. };
  42. static u8 boot_configs[][17] = {
  43. {
  44. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  45. 0x86, 0x80, 0xce, 0x1f, 0x79, 0x80, 0x00, 0xa0, 0x40, 0x08,
  46. 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  47. },
  48. {
  49. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  50. 0x86, 0x80, 0xba, 0x14, 0x99, 0x80, 0x00, 0xa0, 0x40, 0x08,
  51. 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  52. },
  53. {
  54. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  55. 0x86, 0x82, 0x96, 0x19, 0xb9, 0x80, 0x00, 0xa0, 0x40, 0x08,
  56. 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  57. },
  58. {
  59. (NAND_COMPATIBLE | NOR_COMPATIBLE),
  60. 0x86, 0x80, 0xb3, 0x01, 0x9d, 0x80, 0x00, 0xa0, 0x40, 0x08,
  61. 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
  62. },
  63. {
  64. 0,
  65. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  66. }
  67. };
  68. /*
  69. * Bytes 5,6,8,9,11 change for NAND boot
  70. */
  71. #if 0
  72. /*
  73. * Values for 512 page size NAND chips, not used anymore, just
  74. * keep them here for reference
  75. */
  76. static u8 nand_boot[] = {
  77. 0x90, 0x01, 0xa0, 0x68, 0x58
  78. };
  79. #else
  80. /*
  81. * Values for 2k page size NAND chips
  82. */
  83. static u8 nand_boot[] = {
  84. 0x90, 0x01, 0xa0, 0xe8, 0x58
  85. };
  86. #endif
  87. static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  88. {
  89. u8 *buf, b_nand;
  90. int x, y, nbytes, selcfg;
  91. extern char console_buffer[];
  92. if (argc < 2) {
  93. cmd_usage(cmdtp);
  94. return 1;
  95. }
  96. if ((strcmp(argv[1], "nor") != 0) &&
  97. (strcmp(argv[1], "nand") != 0)) {
  98. printf("Unsupported boot-device - only nor|nand support\n");
  99. return 1;
  100. }
  101. /* set the nand flag based on provided input */
  102. if ((strcmp(argv[1], "nand") == 0))
  103. b_nand = 1;
  104. else
  105. b_nand = 0;
  106. printf("Available configurations: \n\n");
  107. if (b_nand) {
  108. for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
  109. /* filter on nand compatible */
  110. if (boot_configs[x][0] & NAND_COMPATIBLE) {
  111. printf(" %d - %s\n", (y+1), config_labels[x]);
  112. y++;
  113. }
  114. }
  115. } else {
  116. for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
  117. /* filter on nor compatible */
  118. if (boot_configs[x][0] & NOR_COMPATIBLE) {
  119. printf(" %d - %s\n", (y+1), config_labels[x]);
  120. y++;
  121. }
  122. }
  123. }
  124. do {
  125. nbytes = readline(" Selection [1-x / quit]: ");
  126. if (nbytes) {
  127. if (strcmp(console_buffer, "quit") == 0)
  128. return 0;
  129. selcfg = simple_strtol(console_buffer, NULL, 10);
  130. if ((selcfg < 1) || (selcfg > y))
  131. nbytes = 0;
  132. }
  133. } while (nbytes == 0);
  134. y = (selcfg - 1);
  135. for (x = 0; boot_configs[x][0] != 0; x++) {
  136. if (b_nand) {
  137. if (boot_configs[x][0] & NAND_COMPATIBLE) {
  138. if (y > 0)
  139. y--;
  140. else if (y < 1)
  141. break;
  142. }
  143. } else {
  144. if (boot_configs[x][0] & NOR_COMPATIBLE) {
  145. if (y > 0)
  146. y--;
  147. else if (y < 1)
  148. break;
  149. }
  150. }
  151. }
  152. buf = &boot_configs[x][1];
  153. if (b_nand) {
  154. buf[5] = nand_boot[0];
  155. buf[6] = nand_boot[1];
  156. buf[8] = nand_boot[2];
  157. buf[9] = nand_boot[3];
  158. buf[11] = nand_boot[4];
  159. }
  160. if (i2c_write(I2C_EEPROM_ADDR, 0, 1, buf, 16) != 0)
  161. printf("Error writing to EEPROM at address 0x%x\n", I2C_EEPROM_ADDR);
  162. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  163. printf("Done\n");
  164. printf("Please power-cycle the board for the changes to take effect\n");
  165. return 0;
  166. }
  167. U_BOOT_CMD(
  168. bootstrap, 2, 0, do_bootstrap,
  169. "bootstrap - program the I2C bootstrap EEPROM\n",
  170. "<nand|nor> - strap to boot from NAND or NOR flash\n"
  171. );