cmd_pci405.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * (C) Copyright 2002-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@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. #include <malloc.h>
  26. #include <net.h>
  27. #include <asm/io.h>
  28. #include <pci.h>
  29. #include <asm/4xx_pci.h>
  30. #include <asm/processor.h>
  31. #include "pci405.h"
  32. #if defined(CONFIG_CMD_BSP)
  33. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  34. /*
  35. * Command loadpci: wait for signal from host and boot image.
  36. */
  37. int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  38. {
  39. unsigned int *ptr = 0;
  40. int count = 0;
  41. int count2 = 0;
  42. int status;
  43. int i;
  44. char addr[16];
  45. char str[] = "\\|/-";
  46. char *local_args[2];
  47. /*
  48. * Mark sync address
  49. */
  50. ptr = 0;
  51. *ptr = 0xffffffff;
  52. puts("\nWaiting for image from pci host -");
  53. /*
  54. * Wait for host to write the start address
  55. */
  56. while (*ptr == 0xffffffff) {
  57. count++;
  58. if (!(count % 100)) {
  59. count2++;
  60. putc(0x08); /* backspace */
  61. putc(str[count2 % 4]);
  62. }
  63. /* Abort if ctrl-c was pressed */
  64. if (ctrlc()) {
  65. puts("\nAbort\n");
  66. return 0;
  67. }
  68. udelay(1000);
  69. }
  70. if (*ptr == PCI_RECONFIG_MAGIC) {
  71. /*
  72. * Save own pci configuration in PRAM
  73. */
  74. memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
  75. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  76. for (i=0; i<0x40; i+=4) {
  77. pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
  78. }
  79. ptr = (unsigned int *)PCI_REGS_ADDR;
  80. *ptr = crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
  81. printf("\nStoring PCI Configuration Regs...\n");
  82. } else {
  83. sprintf(addr, "%08x", *ptr);
  84. /*
  85. * Boot image via bootm
  86. */
  87. printf("\nBooting Image at addr 0x%s ...\n", addr);
  88. setenv("loadaddr", addr);
  89. local_args[0] = argv[0];
  90. local_args[1] = NULL;
  91. status = do_bootm (cmdtp, 0, 1, local_args);
  92. }
  93. return 0;
  94. }
  95. U_BOOT_CMD(
  96. loadpci, 1, 1, do_loadpci,
  97. "Wait for pci-image and boot it",
  98. NULL
  99. );
  100. #endif