Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 1 | /* |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 2 | * (C) Copyright 2005-2008 |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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> |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 26 | #if !defined(CONFIG_440) |
| 27 | #include <asm/4xx_pci.h> |
| 28 | #endif |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 29 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 30 | #if defined(CONFIG_CMD_BSP) |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 31 | |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 32 | extern int do_source (cmd_tbl_t *, int, int, char *[]); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 33 | |
| 34 | #define ADDRMASK 0xfffff000 |
| 35 | |
| 36 | /* |
| 37 | * Command loadpci: wait for signal from host and boot image. |
| 38 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 39 | int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 40 | { |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 41 | u32 *ptr = 0; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 42 | int count = 0; |
| 43 | int count2 = 0; |
| 44 | char addr[16]; |
| 45 | char str[] = "\\|/-"; |
| 46 | char *local_args[2]; |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 47 | u32 la, ptm1la; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 48 | |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 49 | #if defined(CONFIG_440) |
Niklaus Giger | ddc922f | 2009-10-04 20:04:20 +0200 | [diff] [blame] | 50 | ptm1la = in32r(PCIL0_PTM1LA); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 51 | #else |
| 52 | ptm1la = in32r(PTM1LA); |
| 53 | #endif |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 54 | while(1) { |
| 55 | /* |
| 56 | * Mark sync address |
| 57 | */ |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 58 | ptr = (u32 *)ptm1la; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 59 | memset(ptr, 0, 0x20); |
| 60 | |
| 61 | *ptr = 0xffffffff; |
| 62 | puts("\nWaiting for action from pci host -"); |
| 63 | |
| 64 | /* |
| 65 | * Wait for host to write the start address |
| 66 | */ |
| 67 | while (*ptr == 0xffffffff) { |
| 68 | count++; |
| 69 | if (!(count % 100)) { |
| 70 | count2++; |
| 71 | putc(0x08); /* backspace */ |
| 72 | putc(str[count2 % 4]); |
| 73 | } |
| 74 | |
| 75 | /* Abort if ctrl-c was pressed */ |
| 76 | if (ctrlc()) { |
| 77 | puts("\nAbort\n"); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | udelay(1000); |
| 82 | } |
| 83 | |
| 84 | printf("\nGot bootcode %08x: ", *ptr); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 85 | la = ptm1la + (*ptr & ADDRMASK); |
| 86 | sprintf(addr, "%08x", la); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 87 | |
| 88 | switch (*ptr & ~ADDRMASK) { |
| 89 | case 0: |
| 90 | /* |
| 91 | * Boot image via bootm |
| 92 | */ |
| 93 | printf("booting image at addr 0x%s ...\n", addr); |
| 94 | setenv("loadaddr", addr); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 95 | do_bootm(cmdtp, 0, 0, NULL); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 96 | break; |
| 97 | |
| 98 | case 1: |
| 99 | /* |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 100 | * Boot image via "source" command |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 101 | */ |
| 102 | printf("executing script at addr 0x%s ...\n", addr); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 103 | local_args[0] = addr; |
| 104 | local_args[1] = NULL; |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 105 | do_source(cmdtp, 0, 1, local_args); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 106 | break; |
| 107 | |
| 108 | case 2: |
| 109 | /* |
| 110 | * Call run_cmd |
| 111 | */ |
| 112 | printf("running command at addr 0x%s ...\n", addr); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 113 | run_command((char*)la, 0); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | default: |
| 117 | printf("unhandled boot method\n"); |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | U_BOOT_CMD( |
| 124 | loadpci, 1, 1, do_loadpci, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 125 | "Wait for pci bootcmd and boot it", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 126 | "" |
| 127 | ); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 128 | |
| 129 | #endif |