Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 1 | /* |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 2 | * (C) Copyright 2005-2008 |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 3 | * Matthias Fuchs, esd GmbH Germany, matthias.fuchs@esd-electronics.com |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 10 | #include <console.h> |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 11 | #if !defined(CONFIG_440) |
| 12 | #include <asm/4xx_pci.h> |
| 13 | #endif |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 14 | |
Jon Loeliger | 4ed9ed6 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 15 | #if defined(CONFIG_CMD_BSP) |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 16 | #define ADDRMASK 0xfffff000 |
| 17 | |
| 18 | /* |
| 19 | * Command loadpci: wait for signal from host and boot image. |
| 20 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 21 | int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 22 | { |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 23 | u32 *ptr = 0; |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 24 | int count = 0; |
| 25 | int count2 = 0; |
| 26 | char addr[16]; |
| 27 | char str[] = "\\|/-"; |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 28 | u32 la, ptm1la; |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 29 | |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 30 | #if defined(CONFIG_440) |
Niklaus Giger | 728bd0a | 2009-10-04 20:04:20 +0200 | [diff] [blame] | 31 | ptm1la = in32r(PCIL0_PTM1LA); |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 32 | #else |
| 33 | ptm1la = in32r(PTM1LA); |
| 34 | #endif |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 35 | while(1) { |
| 36 | /* |
| 37 | * Mark sync address |
| 38 | */ |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 39 | ptr = (u32 *)ptm1la; |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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); |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 66 | la = ptm1la + (*ptr & ADDRMASK); |
| 67 | sprintf(addr, "%08x", la); |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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); |
Matthias Fuchs | 2f9756d | 2008-10-28 13:36:57 +0100 | [diff] [blame] | 76 | do_bootm(cmdtp, 0, 0, NULL); |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 77 | break; |
| 78 | |
| 79 | case 1: |
| 80 | /* |
Wolfgang Denk | 85c25df | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 81 | * Boot image via "source" command |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 82 | */ |
| 83 | printf("executing script at addr 0x%s ...\n", addr); |
Tom Rini | 065fd4a | 2014-07-21 11:16:07 -0400 | [diff] [blame] | 84 | source(la, NULL); |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 85 | break; |
| 86 | |
| 87 | case 2: |
| 88 | /* |
| 89 | * Call run_cmd |
| 90 | */ |
| 91 | printf("running command at addr 0x%s ...\n", addr); |
Simon Glass | bf8c5b0 | 2012-02-14 19:59:21 +0000 | [diff] [blame] | 92 | run_command((char *)la, 0); |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 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, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 104 | "Wait for pci bootcmd and boot it", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 105 | "" |
| 106 | ); |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 107 | |
| 108 | #endif |