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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 10 | #if !defined(CONFIG_440) |
| 11 | #include <asm/4xx_pci.h> |
| 12 | #endif |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 13 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 14 | #if defined(CONFIG_CMD_BSP) |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 15 | |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 16 | extern int do_source (cmd_tbl_t *, int, int, char *[]); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 17 | |
| 18 | #define ADDRMASK 0xfffff000 |
| 19 | |
| 20 | /* |
| 21 | * Command loadpci: wait for signal from host and boot image. |
| 22 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 23 | 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] | 24 | { |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 25 | u32 *ptr = 0; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 26 | int count = 0; |
| 27 | int count2 = 0; |
| 28 | char addr[16]; |
| 29 | char str[] = "\\|/-"; |
| 30 | char *local_args[2]; |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 31 | u32 la, ptm1la; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 32 | |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 33 | #if defined(CONFIG_440) |
Niklaus Giger | ddc922f | 2009-10-04 20:04:20 +0200 | [diff] [blame] | 34 | ptm1la = in32r(PCIL0_PTM1LA); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 35 | #else |
| 36 | ptm1la = in32r(PTM1LA); |
| 37 | #endif |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 38 | while(1) { |
| 39 | /* |
| 40 | * Mark sync address |
| 41 | */ |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 42 | ptr = (u32 *)ptm1la; |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 69 | la = ptm1la + (*ptr & ADDRMASK); |
| 70 | sprintf(addr, "%08x", la); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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); |
Matthias Fuchs | ca0c2d4 | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 79 | do_bootm(cmdtp, 0, 0, NULL); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 80 | break; |
| 81 | |
| 82 | case 1: |
| 83 | /* |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 84 | * Boot image via "source" command |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 85 | */ |
| 86 | printf("executing script at addr 0x%s ...\n", addr); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 87 | local_args[0] = addr; |
| 88 | local_args[1] = NULL; |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 89 | do_source(cmdtp, 0, 1, local_args); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 90 | break; |
| 91 | |
| 92 | case 2: |
| 93 | /* |
| 94 | * Call run_cmd |
| 95 | */ |
| 96 | printf("running command at addr 0x%s ...\n", addr); |
Simon Glass | 5307153 | 2012-02-14 19:59:21 +0000 | [diff] [blame] | 97 | run_command((char *)la, 0); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 109 | "Wait for pci bootcmd and boot it", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 110 | "" |
| 111 | ); |
Stefan Roese | 2076d0a | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 112 | |
| 113 | #endif |