9541817d094fa361b9ae44419c065afdc0e2dd1f
[platform/kernel/u-boot.git] / 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 #include <console.h>
11 #if !defined(CONFIG_440)
12 #include <asm/4xx_pci.h>
13 #endif
14
15 #if defined(CONFIG_CMD_BSP)
16 #define ADDRMASK 0xfffff000
17
18 /*
19  * Command loadpci: wait for signal from host and boot image.
20  */
21 int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
22 {
23         u32 *ptr = 0;
24         int count = 0;
25         int count2 = 0;
26         char addr[16];
27         char str[] = "\\|/-";
28         u32 la, ptm1la;
29
30 #if defined(CONFIG_440)
31         ptm1la = in32r(PCIL0_PTM1LA);
32 #else
33         ptm1la = in32r(PTM1LA);
34 #endif
35         while(1) {
36                 /*
37                  * Mark sync address
38                  */
39                 ptr = (u32 *)ptm1la;
40                 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);
66                 la = ptm1la + (*ptr & ADDRMASK);
67                 sprintf(addr, "%08x", la);
68
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);
76                         do_bootm(cmdtp, 0, 0, NULL);
77                         break;
78
79                 case 1:
80                         /*
81                          * Boot image via "source" command
82                          */
83                         printf("executing script at addr 0x%s ...\n", addr);
84                         source(la, NULL);
85                         break;
86
87                 case 2:
88                         /*
89                          * Call run_cmd
90                          */
91                         printf("running command at addr 0x%s ...\n", addr);
92                         run_command((char *)la, 0);
93                         break;
94
95                 default:
96                         printf("unhandled boot method\n");
97                         break;
98                 }
99         }
100 }
101
102 U_BOOT_CMD(
103         loadpci,        1,      1,      do_loadpci,
104         "Wait for pci bootcmd and boot it",
105         ""
106 );
107
108 #endif