Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2005 |
| 3 | * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 27 | #if defined(CONFIG_CMD_BSP) |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 28 | |
| 29 | extern int do_bootm (cmd_tbl_t *, int, int, char *[]); |
| 30 | extern int do_autoscript (cmd_tbl_t *, int, int, char *[]); |
| 31 | |
| 32 | #define ADDRMASK 0xfffff000 |
| 33 | |
| 34 | /* |
| 35 | * Command loadpci: wait for signal from host and boot image. |
| 36 | */ |
| 37 | int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 38 | { |
| 39 | unsigned int *ptr = 0; |
| 40 | int count = 0; |
| 41 | int count2 = 0; |
| 42 | char addr[16]; |
| 43 | char str[] = "\\|/-"; |
| 44 | char *local_args[2]; |
| 45 | |
| 46 | while(1) { |
| 47 | /* |
| 48 | * Mark sync address |
| 49 | */ |
| 50 | ptr = 0; |
| 51 | memset(ptr, 0, 0x20); |
| 52 | |
| 53 | *ptr = 0xffffffff; |
| 54 | puts("\nWaiting for action from pci host -"); |
| 55 | |
| 56 | /* |
| 57 | * Wait for host to write the start address |
| 58 | */ |
| 59 | while (*ptr == 0xffffffff) { |
| 60 | count++; |
| 61 | if (!(count % 100)) { |
| 62 | count2++; |
| 63 | putc(0x08); /* backspace */ |
| 64 | putc(str[count2 % 4]); |
| 65 | } |
| 66 | |
| 67 | /* Abort if ctrl-c was pressed */ |
| 68 | if (ctrlc()) { |
| 69 | puts("\nAbort\n"); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | udelay(1000); |
| 74 | } |
| 75 | |
| 76 | printf("\nGot bootcode %08x: ", *ptr); |
| 77 | sprintf(addr, "%08x", *ptr & ADDRMASK); |
| 78 | |
| 79 | switch (*ptr & ~ADDRMASK) { |
| 80 | case 0: |
| 81 | /* |
| 82 | * Boot image via bootm |
| 83 | */ |
| 84 | printf("booting image at addr 0x%s ...\n", addr); |
| 85 | setenv("loadaddr", addr); |
| 86 | |
| 87 | do_bootm (cmdtp, 0, 0, NULL); |
| 88 | break; |
| 89 | |
| 90 | case 1: |
| 91 | /* |
| 92 | * Boot image via autoscr |
| 93 | */ |
| 94 | printf("executing script at addr 0x%s ...\n", addr); |
| 95 | |
| 96 | local_args[0] = addr; |
| 97 | local_args[1] = NULL; |
| 98 | do_autoscript(cmdtp, 0, 1, local_args); |
| 99 | break; |
| 100 | |
| 101 | case 2: |
| 102 | /* |
| 103 | * Call run_cmd |
| 104 | */ |
| 105 | printf("running command at addr 0x%s ...\n", addr); |
| 106 | run_command ((char*)(*ptr & ADDRMASK), 0); |
| 107 | break; |
| 108 | |
| 109 | default: |
| 110 | printf("unhandled boot method\n"); |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | U_BOOT_CMD( |
| 117 | loadpci, 1, 1, do_loadpci, |
| 118 | "loadpci - Wait for pci bootcmd and boot it\n", |
| 119 | NULL |
| 120 | ); |
| 121 | |
| 122 | #endif |