blob: f570ef340fa91df1e193c37eff808c19f768c5c2 [file] [log] [blame]
stroesed69b1002003-03-25 14:41:35 +00001/*
stroesec2642d12004-12-16 18:38:22 +00002 * (C) Copyright 2002-2004
stroesed69b1002003-03-25 14:41:35 +00003 * 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>
Stefan Roese3048bcb2007-10-03 15:01:02 +020030#include <asm/4xx_pci.h>
stroesec2642d12004-12-16 18:38:22 +000031#include <asm/processor.h>
stroesed69b1002003-03-25 14:41:35 +000032
33#include "pci405.h"
34
Jon Loeligerb9307262007-07-09 18:24:55 -050035#if defined(CONFIG_CMD_BSP)
stroesed69b1002003-03-25 14:41:35 +000036
stroesed69b1002003-03-25 14:41:35 +000037/*
38 * Command loadpci: wait for signal from host and boot image.
39 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020040int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
stroesed69b1002003-03-25 14:41:35 +000041{
42 unsigned int *ptr = 0;
43 int count = 0;
44 int count2 = 0;
stroesed69b1002003-03-25 14:41:35 +000045 int i;
46 char addr[16];
47 char str[] = "\\|/-";
48 char *local_args[2];
49
stroesed69b1002003-03-25 14:41:35 +000050 /*
51 * Mark sync address
52 */
53 ptr = 0;
54 *ptr = 0xffffffff;
55 puts("\nWaiting for image from pci host -");
56
57 /*
58 * Wait for host to write the start address
59 */
60 while (*ptr == 0xffffffff) {
61 count++;
62 if (!(count % 100)) {
63 count2++;
64 putc(0x08); /* backspace */
65 putc(str[count2 % 4]);
66 }
67
68 /* Abort if ctrl-c was pressed */
69 if (ctrlc()) {
70 puts("\nAbort\n");
71 return 0;
72 }
73
74 udelay(1000);
75 }
76
77 if (*ptr == PCI_RECONFIG_MAGIC) {
78 /*
79 * Save own pci configuration in PRAM
80 */
81 memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN);
82 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
83 for (i=0; i<0x40; i+=4) {
84 pci_read_config_dword(PCIDEVID_405GP, i, ptr++);
85 }
86 ptr = (unsigned int *)PCI_REGS_ADDR;
Wolfgang Denk77ddac92005-10-13 16:45:02 +020087 *ptr = crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4);
stroesed69b1002003-03-25 14:41:35 +000088
89 printf("\nStoring PCI Configuration Regs...\n");
90 } else {
91 sprintf(addr, "%08x", *ptr);
stroese38718422003-05-23 11:35:09 +000092
stroesec2642d12004-12-16 18:38:22 +000093 /*
94 * Boot image via bootm
95 */
96 printf("\nBooting Image at addr 0x%s ...\n", addr);
stroesed69b1002003-03-25 14:41:35 +000097 setenv("loadaddr", addr);
stroese38718422003-05-23 11:35:09 +000098
stroesed69b1002003-03-25 14:41:35 +000099 local_args[0] = argv[0];
100 local_args[1] = NULL;
Stefan Roese3cceed22011-11-15 08:03:06 +0000101 do_bootm (cmdtp, 0, 1, local_args);
stroesed69b1002003-03-25 14:41:35 +0000102 }
103
104 return 0;
105}
stroese09433a72003-09-12 08:46:10 +0000106U_BOOT_CMD(
107 loadpci, 1, 1, do_loadpci,
Peter Tyser2fb26042009-01-27 18:03:12 -0600108 "Wait for pci-image and boot it",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200109 ""
stroese09433a72003-09-12 08:46:10 +0000110);
stroesec2642d12004-12-16 18:38:22 +0000111#endif