blob: 803179a47238c2f34ef563280f12dbc4221be3f3 [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>
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010010#if !defined(CONFIG_440)
11#include <asm/4xx_pci.h>
12#endif
Stefan Roese2076d0a2006-01-18 20:03:15 +010013
Jon Loeligerb9307262007-07-09 18:24:55 -050014#if defined(CONFIG_CMD_BSP)
Stefan Roese2076d0a2006-01-18 20:03:15 +010015
Wolfgang Denk74de7ae2009-04-01 23:34:12 +020016extern int do_source (cmd_tbl_t *, int, int, char *[]);
Stefan Roese2076d0a2006-01-18 20:03:15 +010017
18#define ADDRMASK 0xfffff000
19
20/*
21 * Command loadpci: wait for signal from host and boot image.
22 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020023int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese2076d0a2006-01-18 20:03:15 +010024{
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010025 u32 *ptr = 0;
Stefan Roese2076d0a2006-01-18 20:03:15 +010026 int count = 0;
27 int count2 = 0;
28 char addr[16];
29 char str[] = "\\|/-";
30 char *local_args[2];
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010031 u32 la, ptm1la;
Stefan Roese2076d0a2006-01-18 20:03:15 +010032
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010033#if defined(CONFIG_440)
Niklaus Gigerddc922f2009-10-04 20:04:20 +020034 ptm1la = in32r(PCIL0_PTM1LA);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010035#else
36 ptm1la = in32r(PTM1LA);
37#endif
Stefan Roese2076d0a2006-01-18 20:03:15 +010038 while(1) {
39 /*
40 * Mark sync address
41 */
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010042 ptr = (u32 *)ptm1la;
Stefan Roese2076d0a2006-01-18 20:03:15 +010043 memset(ptr, 0, 0x20);
44
45 *ptr = 0xffffffff;
46 puts("\nWaiting for action from pci host -");
47
48 /*
49 * Wait for host to write the start address
50 */
51 while (*ptr == 0xffffffff) {
52 count++;
53 if (!(count % 100)) {
54 count2++;
55 putc(0x08); /* backspace */
56 putc(str[count2 % 4]);
57 }
58
59 /* Abort if ctrl-c was pressed */
60 if (ctrlc()) {
61 puts("\nAbort\n");
62 return 0;
63 }
64
65 udelay(1000);
66 }
67
68 printf("\nGot bootcode %08x: ", *ptr);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010069 la = ptm1la + (*ptr & ADDRMASK);
70 sprintf(addr, "%08x", la);
Stefan Roese2076d0a2006-01-18 20:03:15 +010071
72 switch (*ptr & ~ADDRMASK) {
73 case 0:
74 /*
75 * Boot image via bootm
76 */
77 printf("booting image at addr 0x%s ...\n", addr);
78 setenv("loadaddr", addr);
Matthias Fuchsca0c2d42008-10-28 13:36:57 +010079 do_bootm(cmdtp, 0, 0, NULL);
Stefan Roese2076d0a2006-01-18 20:03:15 +010080 break;
81
82 case 1:
83 /*
Wolfgang Denk74de7ae2009-04-01 23:34:12 +020084 * Boot image via "source" command
Stefan Roese2076d0a2006-01-18 20:03:15 +010085 */
86 printf("executing script at addr 0x%s ...\n", addr);
Stefan Roese2076d0a2006-01-18 20:03:15 +010087 local_args[0] = addr;
88 local_args[1] = NULL;
Wolfgang Denk74de7ae2009-04-01 23:34:12 +020089 do_source(cmdtp, 0, 1, local_args);
Stefan Roese2076d0a2006-01-18 20:03:15 +010090 break;
91
92 case 2:
93 /*
94 * Call run_cmd
95 */
96 printf("running command at addr 0x%s ...\n", addr);
Simon Glass53071532012-02-14 19:59:21 +000097 run_command((char *)la, 0);
Stefan Roese2076d0a2006-01-18 20:03:15 +010098 break;
99
100 default:
101 printf("unhandled boot method\n");
102 break;
103 }
104 }
105}
106
107U_BOOT_CMD(
108 loadpci, 1, 1, do_loadpci,
Peter Tyser2fb26042009-01-27 18:03:12 -0600109 "Wait for pci bootcmd and boot it",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200110 ""
111);
Stefan Roese2076d0a2006-01-18 20:03:15 +0100112
113#endif