Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / u-boot / board / esd / common / cmd_loadpci.c
1 /*
2  * (C) Copyright 2005-2008
3  * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <command.h>
10 #if !defined(CONFIG_440)
11 #include <asm/4xx_pci.h>
12 #endif
13
14 #if defined(CONFIG_CMD_BSP)
15
16 extern int do_source (cmd_tbl_t *, int, int, char *[]);
17
18 #define ADDRMASK 0xfffff000
19
20 /*
21  * Command loadpci: wait for signal from host and boot image.
22  */
23 int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
24 {
25         u32 *ptr = 0;
26         int count = 0;
27         int count2 = 0;
28         char addr[16];
29         char str[] = "\\|/-";
30         char *local_args[2];
31         u32 la, ptm1la;
32
33 #if defined(CONFIG_440)
34         ptm1la = in32r(PCIL0_PTM1LA);
35 #else
36         ptm1la = in32r(PTM1LA);
37 #endif
38         while(1) {
39                 /*
40                  * Mark sync address
41                  */
42                 ptr = (u32 *)ptm1la;
43                 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);
69                 la = ptm1la + (*ptr & ADDRMASK);
70                 sprintf(addr, "%08x", la);
71
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);
79                         do_bootm(cmdtp, 0, 0, NULL);
80                         break;
81
82                 case 1:
83                         /*
84                          * Boot image via "source" command
85                          */
86                         printf("executing script at addr 0x%s ...\n", addr);
87                         local_args[0] = addr;
88                         local_args[1] = NULL;
89                         do_source(cmdtp, 0, 1, local_args);
90                         break;
91
92                 case 2:
93                         /*
94                          * Call run_cmd
95                          */
96                         printf("running command at addr 0x%s ...\n", addr);
97                         run_command((char *)la, 0);
98                         break;
99
100                 default:
101                         printf("unhandled boot method\n");
102                         break;
103                 }
104         }
105 }
106
107 U_BOOT_CMD(
108         loadpci,        1,      1,      do_loadpci,
109         "Wait for pci bootcmd and boot it",
110         ""
111 );
112
113 #endif