blob: eecae0a7fd1803864f6a3146bcde3b0d919afa97 [file] [log] [blame]
Stefan Roese1c671a92006-01-18 20:03:15 +01001/*
Matthias Fuchs2f9756d2008-10-28 13:36:57 +01002 * (C) Copyright 2005-2008
Stefan Roese1c671a92006-01-18 20:03:15 +01003 * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@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>
25#include <command.h>
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010026#if !defined(CONFIG_440)
27#include <asm/4xx_pci.h>
28#endif
Stefan Roese1c671a92006-01-18 20:03:15 +010029
Jon Loeliger4ed9ed62007-07-09 18:24:55 -050030#if defined(CONFIG_CMD_BSP)
Stefan Roese1c671a92006-01-18 20:03:15 +010031
32extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
Wolfgang Denk85c25df2009-04-01 23:34:12 +020033extern int do_source (cmd_tbl_t *, int, int, char *[]);
Stefan Roese1c671a92006-01-18 20:03:15 +010034
35#define ADDRMASK 0xfffff000
36
37/*
38 * Command loadpci: wait for signal from host and boot image.
39 */
40int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
41{
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010042 u32 *ptr = 0;
Stefan Roese1c671a92006-01-18 20:03:15 +010043 int count = 0;
44 int count2 = 0;
45 char addr[16];
46 char str[] = "\\|/-";
47 char *local_args[2];
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010048 u32 la, ptm1la;
Stefan Roese1c671a92006-01-18 20:03:15 +010049
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010050#if defined(CONFIG_440)
Niklaus Giger728bd0a2009-10-04 20:04:20 +020051 ptm1la = in32r(PCIL0_PTM1LA);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010052#else
53 ptm1la = in32r(PTM1LA);
54#endif
Stefan Roese1c671a92006-01-18 20:03:15 +010055 while(1) {
56 /*
57 * Mark sync address
58 */
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010059 ptr = (u32 *)ptm1la;
Stefan Roese1c671a92006-01-18 20:03:15 +010060 memset(ptr, 0, 0x20);
61
62 *ptr = 0xffffffff;
63 puts("\nWaiting for action from pci host -");
64
65 /*
66 * Wait for host to write the start address
67 */
68 while (*ptr == 0xffffffff) {
69 count++;
70 if (!(count % 100)) {
71 count2++;
72 putc(0x08); /* backspace */
73 putc(str[count2 % 4]);
74 }
75
76 /* Abort if ctrl-c was pressed */
77 if (ctrlc()) {
78 puts("\nAbort\n");
79 return 0;
80 }
81
82 udelay(1000);
83 }
84
85 printf("\nGot bootcode %08x: ", *ptr);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010086 la = ptm1la + (*ptr & ADDRMASK);
87 sprintf(addr, "%08x", la);
Stefan Roese1c671a92006-01-18 20:03:15 +010088
89 switch (*ptr & ~ADDRMASK) {
90 case 0:
91 /*
92 * Boot image via bootm
93 */
94 printf("booting image at addr 0x%s ...\n", addr);
95 setenv("loadaddr", addr);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010096 do_bootm(cmdtp, 0, 0, NULL);
Stefan Roese1c671a92006-01-18 20:03:15 +010097 break;
98
99 case 1:
100 /*
Wolfgang Denk85c25df2009-04-01 23:34:12 +0200101 * Boot image via "source" command
Stefan Roese1c671a92006-01-18 20:03:15 +0100102 */
103 printf("executing script at addr 0x%s ...\n", addr);
Stefan Roese1c671a92006-01-18 20:03:15 +0100104 local_args[0] = addr;
105 local_args[1] = NULL;
Wolfgang Denk85c25df2009-04-01 23:34:12 +0200106 do_source(cmdtp, 0, 1, local_args);
Stefan Roese1c671a92006-01-18 20:03:15 +0100107 break;
108
109 case 2:
110 /*
111 * Call run_cmd
112 */
113 printf("running command at addr 0x%s ...\n", addr);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +0100114 run_command((char*)la, 0);
Stefan Roese1c671a92006-01-18 20:03:15 +0100115 break;
116
117 default:
118 printf("unhandled boot method\n");
119 break;
120 }
121 }
122}
123
124U_BOOT_CMD(
125 loadpci, 1, 1, do_loadpci,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600126 "Wait for pci bootcmd and boot it",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200127 ""
128);
Stefan Roese1c671a92006-01-18 20:03:15 +0100129
130#endif