blob: df91cd4176135dbd1cbccd2fa406073d78aa0c61 [file] [log] [blame]
stroesed69b1002003-03-25 14:41:35 +00001/*
2 * (C) Copyright 2002
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
24#include <common.h>
wdenk8bde7f72003-06-27 21:31:46 +000025#include <command.h>
stroesed69b1002003-03-25 14:41:35 +000026#include <malloc.h>
27#include <net.h>
28#include <asm/io.h>
29#include <pci.h>
30#include <405gp_pci.h>
stroesed69b1002003-03-25 14:41:35 +000031
32#include "pci405.h"
33
34
35#if (CONFIG_COMMANDS & CFG_CMD_BSP)
36
37extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
38
stroesed69b1002003-03-25 14:41:35 +000039
stroesed69b1002003-03-25 14:41:35 +000040/*
41 * Command loadpci: wait for signal from host and boot image.
42 */
43int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
44{
45 unsigned int *ptr = 0;
46 int count = 0;
47 int count2 = 0;
48 int status;
49 int i;
50 char addr[16];
51 char str[] = "\\|/-";
52 char *local_args[2];
53
stroesed69b1002003-03-25 14:41:35 +000054 /*
55 * Mark sync address
56 */
57 ptr = 0;
58 *ptr = 0xffffffff;
59 puts("\nWaiting for image from pci host -");
60
61 /*
62 * Wait for host to write the start address
63 */
64 while (*ptr == 0xffffffff) {
65 count++;
66 if (!(count % 100)) {
67 count2++;
68 putc(0x08); /* backspace */
69 putc(str[count2 % 4]);
70 }
71
72 /* Abort if ctrl-c was pressed */
73 if (ctrlc()) {
74 puts("\nAbort\n");
75 return 0;
76 }
77
78 udelay(1000);
79 }
80
81 if (*ptr == PCI_RECONFIG_MAGIC) {
82 /*
83 * Save own pci configuration in PRAM
84 */
85 memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
86 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
87 for (i=0; i<0x40; i+=4) {
88 pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
89 }
90 ptr = (unsigned int *)PCI_REGS_ADDR;
91 *ptr = crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
92
93 printf("\nStoring PCI Configuration Regs...\n");
94 } else {
95 sprintf(addr, "%08x", *ptr);
stroese38718422003-05-23 11:35:09 +000096
stroesed69b1002003-03-25 14:41:35 +000097 /*
98 * Boot image
99 */
100 printf("\nBooting image at addr 0x%s ...\n", addr);
101 setenv("loadaddr", addr);
stroese38718422003-05-23 11:35:09 +0000102
stroesed69b1002003-03-25 14:41:35 +0000103 local_args[0] = argv[0];
104 local_args[1] = NULL;
105 status = do_bootm (cmdtp, 0, 1, local_args);
106 }
107
108 return 0;
109}
110
111#endif