cmd_loadpci.c 2.7 KB

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