cmd_pn62.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Grandegger, DENX Software Engineering, wg@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. #include <common.h>
  24. #include <malloc.h>
  25. #include <net.h>
  26. #include <asm/io.h>
  27. #include <pci.h>
  28. #include <command.h>
  29. #include "pn62.h"
  30. #if defined(CONFIG_CMD_BSP)
  31. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  32. /*
  33. * Command led: controls the various LEDs 0..11 on the PN62 card.
  34. */
  35. int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  36. {
  37. unsigned int number, function;
  38. if (argc != 3) {
  39. cmd_usage(cmdtp);
  40. return 1;
  41. }
  42. number = simple_strtoul(argv[1], NULL, 10);
  43. if (number > PN62_LED_MAX)
  44. return 1;
  45. function = simple_strtoul(argv[2], NULL, 16);
  46. set_led (number, function);
  47. return 0;
  48. }
  49. U_BOOT_CMD(
  50. led , 3, 1, do_led,
  51. "led - set LED 0..11 on the PN62 board\n",
  52. "i fun\n"
  53. " - set 'i'th LED to function 'fun'\n"
  54. );
  55. /*
  56. * Command loadpci: loads a image over PCI.
  57. */
  58. #define CMD_MOVE_WINDOW 0x1
  59. #define CMD_BOOT_IMAGE 0x2
  60. int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  61. {
  62. char *s;
  63. ulong addr = 0, count = 0;
  64. u32 off;
  65. int cmd, rcode = 0;
  66. /* pre-set load_addr */
  67. if ((s = getenv("loadaddr")) != NULL) {
  68. addr = simple_strtoul(s, NULL, 16);
  69. }
  70. switch (argc) {
  71. case 1:
  72. break;
  73. case 2:
  74. addr = simple_strtoul(argv[1], NULL, 16);
  75. break;
  76. default:
  77. cmd_usage(cmdtp);
  78. return 1;
  79. }
  80. printf ("## Ready for image download ...\n");
  81. show_startup_phase(12);
  82. while (1) {
  83. /* Alive indicator */
  84. i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
  85. /* Toggle status LEDs */
  86. cmd = (count / 200) % 4; /* downscale */
  87. set_led(4, cmd == 0 ? LED_1 : LED_0);
  88. set_led(5, cmd == 1 ? LED_1 : LED_0);
  89. set_led(6, cmd == 2 ? LED_1 : LED_0);
  90. set_led(7, cmd == 3 ? LED_1 : LED_0);
  91. udelay(1000);
  92. count++;
  93. cmd = i2155x_read_scrapad(BOOT_CMD);
  94. if (cmd == BOOT_CMD_MOVE) {
  95. off = i2155x_read_scrapad(BOOT_DATA);
  96. off += addr;
  97. i2155x_set_bar_base(3, off);
  98. printf ("## BAR3 Addr moved = 0x%08x\n", off);
  99. i2155x_write_scrapad(BOOT_CMD, ~cmd);
  100. show_startup_phase(13);
  101. }
  102. else if (cmd == BOOT_CMD_BOOT) {
  103. set_led(4, LED_1);
  104. set_led(5, LED_1);
  105. set_led(6, LED_1);
  106. set_led(7, LED_1);
  107. i2155x_write_scrapad(BOOT_CMD, ~cmd);
  108. show_startup_phase(14);
  109. break;
  110. }
  111. /* Abort if ctrl-c was pressed */
  112. if (ctrlc()) {
  113. printf("\nAbort\n");
  114. return 0;
  115. }
  116. }
  117. /* Repoint to the default shared memory */
  118. i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
  119. load_addr = addr;
  120. printf ("## Start Addr = 0x%08lx\n", addr);
  121. show_startup_phase(15);
  122. /* Loading ok, check if we should attempt an auto-start */
  123. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
  124. char *local_args[2];
  125. local_args[0] = argv[0];
  126. local_args[1] = NULL;
  127. printf ("Automatic boot of image at addr 0x%08lX ...\n",
  128. load_addr);
  129. rcode = do_bootm (cmdtp, 0, 1, local_args);
  130. }
  131. #ifdef CONFIG_AUTOSCRIPT
  132. if (load_addr) {
  133. char *s;
  134. if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
  135. printf ("Running autoscript at addr 0x%08lX", load_addr);
  136. s = getenv ("autoscript_uname");
  137. if (s)
  138. printf (":%s ...\n", s);
  139. else
  140. puts (" ...\n");
  141. rcode = autoscript (load_addr, s);
  142. }
  143. }
  144. #endif
  145. return rcode;
  146. }
  147. U_BOOT_CMD(
  148. loadpci, 2, 1, do_loadpci,
  149. "loadpci - load binary file over PCI\n",
  150. "[addr]\n"
  151. " - load binary file over PCI to address 'addr'\n"
  152. );
  153. #endif