cmd_loadpci.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * (C) Copyright 2005
  3. * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com
  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 <command.h>
  25. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  26. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  27. extern int do_autoscript (cmd_tbl_t *, int, int, char *[]);
  28. #define ADDRMASK 0xfffff000
  29. /*
  30. * Command loadpci: wait for signal from host and boot image.
  31. */
  32. int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  33. {
  34. unsigned int *ptr = 0;
  35. int count = 0;
  36. int count2 = 0;
  37. char addr[16];
  38. char str[] = "\\|/-";
  39. char *local_args[2];
  40. while(1) {
  41. /*
  42. * Mark sync address
  43. */
  44. ptr = 0;
  45. memset(ptr, 0, 0x20);
  46. *ptr = 0xffffffff;
  47. puts("\nWaiting for action from pci host -");
  48. /*
  49. * Wait for host to write the start address
  50. */
  51. while (*ptr == 0xffffffff) {
  52. count++;
  53. if (!(count % 100)) {
  54. count2++;
  55. putc(0x08); /* backspace */
  56. putc(str[count2 % 4]);
  57. }
  58. /* Abort if ctrl-c was pressed */
  59. if (ctrlc()) {
  60. puts("\nAbort\n");
  61. return 0;
  62. }
  63. udelay(1000);
  64. }
  65. printf("\nGot bootcode %08x: ", *ptr);
  66. sprintf(addr, "%08x", *ptr & ADDRMASK);
  67. switch (*ptr & ~ADDRMASK) {
  68. case 0:
  69. /*
  70. * Boot image via bootm
  71. */
  72. printf("booting image at addr 0x%s ...\n", addr);
  73. setenv("loadaddr", addr);
  74. do_bootm (cmdtp, 0, 0, NULL);
  75. break;
  76. case 1:
  77. /*
  78. * Boot image via autoscr
  79. */
  80. printf("executing script at addr 0x%s ...\n", addr);
  81. local_args[0] = addr;
  82. local_args[1] = NULL;
  83. do_autoscript(cmdtp, 0, 1, local_args);
  84. break;
  85. case 2:
  86. /*
  87. * Call run_cmd
  88. */
  89. printf("running command at addr 0x%s ...\n", addr);
  90. run_command ((char*)(*ptr & ADDRMASK), 0);
  91. break;
  92. default:
  93. printf("unhandled boot method\n");
  94. break;
  95. }
  96. }
  97. }
  98. U_BOOT_CMD(
  99. loadpci, 1, 1, do_loadpci,
  100. "loadpci - Wait for pci bootcmd and boot it\n",
  101. NULL
  102. );
  103. #endif