cmd_loadpci.c 2.8 KB

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