blob: 55c20d02d3126f6b3cd4131133fc185c256d8f4a [file] [log] [blame]
stroese65f36a72003-03-25 14:41:35 +00001/*
stroesea530a9a2004-12-16 18:38:22 +00002 * (C) Copyright 2002-2004
stroese65f36a72003-03-25 14:41:35 +00003 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
stroese65f36a72003-03-25 14:41:35 +00006 */
7
8#include <common.h>
wdenk57b2d802003-06-27 21:31:46 +00009#include <command.h>
stroese65f36a72003-03-25 14:41:35 +000010#include <malloc.h>
11#include <net.h>
12#include <asm/io.h>
13#include <pci.h>
Stefan Roeseca8725f2007-10-03 15:01:02 +020014#include <asm/4xx_pci.h>
stroesea530a9a2004-12-16 18:38:22 +000015#include <asm/processor.h>
stroese65f36a72003-03-25 14:41:35 +000016
17#include "pci405.h"
18
Jon Loeliger4ed9ed62007-07-09 18:24:55 -050019#if defined(CONFIG_CMD_BSP)
stroese65f36a72003-03-25 14:41:35 +000020
stroese65f36a72003-03-25 14:41:35 +000021/*
22 * Command loadpci: wait for signal from host and boot image.
23 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020024int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroese65f36a72003-03-25 14:41:35 +000025{
26 unsigned int *ptr = 0;
27 int count = 0;
28 int count2 = 0;
stroese65f36a72003-03-25 14:41:35 +000029 int i;
30 char addr[16];
31 char str[] = "\\|/-";
32 char *local_args[2];
33
stroese65f36a72003-03-25 14:41:35 +000034 /*
35 * Mark sync address
36 */
37 ptr = 0;
38 *ptr = 0xffffffff;
39 puts("\nWaiting for image from pci host -");
40
41 /*
42 * Wait for host to write the start address
43 */
44 while (*ptr == 0xffffffff) {
45 count++;
46 if (!(count % 100)) {
47 count2++;
48 putc(0x08); /* backspace */
49 putc(str[count2 % 4]);
50 }
51
52 /* Abort if ctrl-c was pressed */
53 if (ctrlc()) {
54 puts("\nAbort\n");
55 return 0;
56 }
57
58 udelay(1000);
59 }
60
61 if (*ptr == PCI_RECONFIG_MAGIC) {
62 /*
63 * Save own pci configuration in PRAM
64 */
65 memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
66 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
67 for (i=0; i<0x40; i+=4) {
68 pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
69 }
70 ptr = (unsigned int *)PCI_REGS_ADDR;
Wolfgang Denk7fb52662005-10-13 16:45:02 +020071 *ptr = crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
stroese65f36a72003-03-25 14:41:35 +000072
73 printf("\nStoring PCI Configuration Regs...\n");
74 } else {
75 sprintf(addr, "%08x", *ptr);
stroese51fbb182003-05-23 11:35:09 +000076
stroesea530a9a2004-12-16 18:38:22 +000077 /*
78 * Boot image via bootm
79 */
80 printf("\nBooting Image at addr 0x%s ...\n", addr);
stroese65f36a72003-03-25 14:41:35 +000081 setenv("loadaddr", addr);
stroese51fbb182003-05-23 11:35:09 +000082
stroese65f36a72003-03-25 14:41:35 +000083 local_args[0] = argv[0];
84 local_args[1] = NULL;
Stefan Roese98adee82011-11-15 08:03:06 +000085 do_bootm (cmdtp, 0, 1, local_args);
stroese65f36a72003-03-25 14:41:35 +000086 }
87
88 return 0;
89}
stroese9cead262003-09-12 08:46:10 +000090U_BOOT_CMD(
91 loadpci, 1, 1, do_loadpci,
Peter Tyserdfb72b82009-01-27 18:03:12 -060092 "Wait for pci-image and boot it",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020093 ""
stroese9cead262003-09-12 08:46:10 +000094);
stroese65f36a72003-03-25 14:41:35 +000095#endif