cmd_loadpci.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * (C) Copyright 2005-2008
  3. * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <console.h>
  10. #if !defined(CONFIG_440)
  11. #include <asm/4xx_pci.h>
  12. #endif
  13. #if defined(CONFIG_CMD_BSP)
  14. #define ADDRMASK 0xfffff000
  15. /*
  16. * Command loadpci: wait for signal from host and boot image.
  17. */
  18. int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  19. {
  20. u32 *ptr = 0;
  21. int count = 0;
  22. int count2 = 0;
  23. char addr[16];
  24. char str[] = "\\|/-";
  25. u32 la, ptm1la;
  26. #if defined(CONFIG_440)
  27. ptm1la = in32r(PCIL0_PTM1LA);
  28. #else
  29. ptm1la = in32r(PTM1LA);
  30. #endif
  31. while(1) {
  32. /*
  33. * Mark sync address
  34. */
  35. ptr = (u32 *)ptm1la;
  36. memset(ptr, 0, 0x20);
  37. *ptr = 0xffffffff;
  38. puts("\nWaiting for action from pci host -");
  39. /*
  40. * Wait for host to write the start address
  41. */
  42. while (*ptr == 0xffffffff) {
  43. count++;
  44. if (!(count % 100)) {
  45. count2++;
  46. putc(0x08); /* backspace */
  47. putc(str[count2 % 4]);
  48. }
  49. /* Abort if ctrl-c was pressed */
  50. if (ctrlc()) {
  51. puts("\nAbort\n");
  52. return 0;
  53. }
  54. udelay(1000);
  55. }
  56. printf("\nGot bootcode %08x: ", *ptr);
  57. la = ptm1la + (*ptr & ADDRMASK);
  58. sprintf(addr, "%08x", la);
  59. switch (*ptr & ~ADDRMASK) {
  60. case 0:
  61. /*
  62. * Boot image via bootm
  63. */
  64. printf("booting image at addr 0x%s ...\n", addr);
  65. setenv("loadaddr", addr);
  66. do_bootm(cmdtp, 0, 0, NULL);
  67. break;
  68. case 1:
  69. /*
  70. * Boot image via "source" command
  71. */
  72. printf("executing script at addr 0x%s ...\n", addr);
  73. source(la, NULL);
  74. break;
  75. case 2:
  76. /*
  77. * Call run_cmd
  78. */
  79. printf("running command at addr 0x%s ...\n", addr);
  80. run_command((char *)la, 0);
  81. break;
  82. default:
  83. printf("unhandled boot method\n");
  84. break;
  85. }
  86. }
  87. }
  88. U_BOOT_CMD(
  89. loadpci, 1, 1, do_loadpci,
  90. "Wait for pci bootcmd and boot it",
  91. ""
  92. );
  93. #endif