blob: 9541817d094fa361b9ae44419c065afdc0e2dd1f [file] [log] [blame]
Stefan Roese2076d0a2006-01-18 20:03:15 +01001/*
Matthias Fuchsca0c2d42008-10-28 13:36:57 +01002 * (C) Copyright 2005-2008
Stefan Roese2076d0a2006-01-18 20:03:15 +01003 * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese2076d0a2006-01-18 20:03:15 +01006 */
7
8#include <common.h>
9#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070010#include <console.h>
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010011#if !defined(CONFIG_440)
12#include <asm/4xx_pci.h>
13#endif
Stefan Roese2076d0a2006-01-18 20:03:15 +010014
Jon Loeligerb9307262007-07-09 18:24:55 -050015#if defined(CONFIG_CMD_BSP)
Stefan Roese2076d0a2006-01-18 20:03:15 +010016#define ADDRMASK 0xfffff000
17
18/*
19 * Command loadpci: wait for signal from host and boot image.
20 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020021int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese2076d0a2006-01-18 20:03:15 +010022{
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010023 u32 *ptr = 0;
Stefan Roese2076d0a2006-01-18 20:03:15 +010024 int count = 0;
25 int count2 = 0;
26 char addr[16];
27 char str[] = "\\|/-";
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010028 u32 la, ptm1la;
Stefan Roese2076d0a2006-01-18 20:03:15 +010029
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010030#if defined(CONFIG_440)
Niklaus Gigerddc922f2009-10-04 20:04:20 +020031 ptm1la = in32r(PCIL0_PTM1LA);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010032#else
33 ptm1la = in32r(PTM1LA);
34#endif
Stefan Roese2076d0a2006-01-18 20:03:15 +010035 while(1) {
36 /*
37 * Mark sync address
38 */
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010039 ptr = (u32 *)ptm1la;
Stefan Roese2076d0a2006-01-18 20:03:15 +010040 memset(ptr, 0, 0x20);
41
42 *ptr = 0xffffffff;
43 puts("\nWaiting for action from pci host -");
44
45 /*
46 * Wait for host to write the start address
47 */
48 while (*ptr == 0xffffffff) {
49 count++;
50 if (!(count % 100)) {
51 count2++;
52 putc(0x08); /* backspace */
53 putc(str[count2 % 4]);
54 }
55
56 /* Abort if ctrl-c was pressed */
57 if (ctrlc()) {
58 puts("\nAbort\n");
59 return 0;
60 }
61
62 udelay(1000);
63 }
64
65 printf("\nGot bootcode %08x: ", *ptr);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010066 la = ptm1la + (*ptr & ADDRMASK);
67 sprintf(addr, "%08x", la);
Stefan Roese2076d0a2006-01-18 20:03:15 +010068
69 switch (*ptr & ~ADDRMASK) {
70 case 0:
71 /*
72 * Boot image via bootm
73 */
74 printf("booting image at addr 0x%s ...\n", addr);
75 setenv("loadaddr", addr);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010076 do_bootm(cmdtp, 0, 0, NULL);
Stefan Roese2076d0a2006-01-18 20:03:15 +010077 break;
78
79 case 1:
80 /*
Wolfgang Denk74de7ae2009-04-01 23:34:12 +020081 * Boot image via "source" command
Stefan Roese2076d0a2006-01-18 20:03:15 +010082 */
83 printf("executing script at addr 0x%s ...\n", addr);
Tom Riniec4f5042014-07-21 11:16:07 -040084 source(la, NULL);
Stefan Roese2076d0a2006-01-18 20:03:15 +010085 break;
86
87 case 2:
88 /*
89 * Call run_cmd
90 */
91 printf("running command at addr 0x%s ...\n", addr);
Simon Glass53071532012-02-14 19:59:21 +000092 run_command((char *)la, 0);
Stefan Roese2076d0a2006-01-18 20:03:15 +010093 break;
94
95 default:
96 printf("unhandled boot method\n");
97 break;
98 }
99 }
100}
101
102U_BOOT_CMD(
103 loadpci, 1, 1, do_loadpci,
Peter Tyser2fb26042009-01-27 18:03:12 -0600104 "Wait for pci bootcmd and boot it",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200105 ""
106);
Stefan Roese2076d0a2006-01-18 20:03:15 +0100107
108#endif