blob: 95d18911c3dc366c0e415b1a30ec2b5b76f09752 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese1c671a92006-01-18 20:03:15 +01006 */
7
8#include <common.h>
9#include <command.h>
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010010#if !defined(CONFIG_440)
11#include <asm/4xx_pci.h>
12#endif
Stefan Roese1c671a92006-01-18 20:03:15 +010013
Jon Loeliger4ed9ed62007-07-09 18:24:55 -050014#if defined(CONFIG_CMD_BSP)
Stefan Roese1c671a92006-01-18 20:03:15 +010015#define ADDRMASK 0xfffff000
16
17/*
18 * Command loadpci: wait for signal from host and boot image.
19 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020020int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese1c671a92006-01-18 20:03:15 +010021{
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010022 u32 *ptr = 0;
Stefan Roese1c671a92006-01-18 20:03:15 +010023 int count = 0;
24 int count2 = 0;
25 char addr[16];
26 char str[] = "\\|/-";
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010027 u32 la, ptm1la;
Stefan Roese1c671a92006-01-18 20:03:15 +010028
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010029#if defined(CONFIG_440)
Niklaus Giger728bd0a2009-10-04 20:04:20 +020030 ptm1la = in32r(PCIL0_PTM1LA);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010031#else
32 ptm1la = in32r(PTM1LA);
33#endif
Stefan Roese1c671a92006-01-18 20:03:15 +010034 while(1) {
35 /*
36 * Mark sync address
37 */
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010038 ptr = (u32 *)ptm1la;
Stefan Roese1c671a92006-01-18 20:03:15 +010039 memset(ptr, 0, 0x20);
40
41 *ptr = 0xffffffff;
42 puts("\nWaiting for action from pci host -");
43
44 /*
45 * Wait for host to write the start address
46 */
47 while (*ptr == 0xffffffff) {
48 count++;
49 if (!(count % 100)) {
50 count2++;
51 putc(0x08); /* backspace */
52 putc(str[count2 % 4]);
53 }
54
55 /* Abort if ctrl-c was pressed */
56 if (ctrlc()) {
57 puts("\nAbort\n");
58 return 0;
59 }
60
61 udelay(1000);
62 }
63
64 printf("\nGot bootcode %08x: ", *ptr);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010065 la = ptm1la + (*ptr & ADDRMASK);
66 sprintf(addr, "%08x", la);
Stefan Roese1c671a92006-01-18 20:03:15 +010067
68 switch (*ptr & ~ADDRMASK) {
69 case 0:
70 /*
71 * Boot image via bootm
72 */
73 printf("booting image at addr 0x%s ...\n", addr);
74 setenv("loadaddr", addr);
Matthias Fuchs2f9756d2008-10-28 13:36:57 +010075 do_bootm(cmdtp, 0, 0, NULL);
Stefan Roese1c671a92006-01-18 20:03:15 +010076 break;
77
78 case 1:
79 /*
Wolfgang Denk85c25df2009-04-01 23:34:12 +020080 * Boot image via "source" command
Stefan Roese1c671a92006-01-18 20:03:15 +010081 */
82 printf("executing script at addr 0x%s ...\n", addr);
Tom Rini065fd4a2014-07-21 11:16:07 -040083 source(la, NULL);
Stefan Roese1c671a92006-01-18 20:03:15 +010084 break;
85
86 case 2:
87 /*
88 * Call run_cmd
89 */
90 printf("running command at addr 0x%s ...\n", addr);
Simon Glassbf8c5b02012-02-14 19:59:21 +000091 run_command((char *)la, 0);
Stefan Roese1c671a92006-01-18 20:03:15 +010092 break;
93
94 default:
95 printf("unhandled boot method\n");
96 break;
97 }
98 }
99}
100
101U_BOOT_CMD(
102 loadpci, 1, 1, do_loadpci,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600103 "Wait for pci bootcmd and boot it",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200104 ""
105);
Stefan Roese1c671a92006-01-18 20:03:15 +0100106
107#endif