stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 1 | /* |
stroese | a530a9a | 2004-12-16 18:38:22 +0000 | [diff] [blame] | 2 | * (C) Copyright 2002-2004 |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 9 | #include <command.h> |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 10 | #include <malloc.h> |
| 11 | #include <net.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <pci.h> |
Stefan Roese | ca8725f | 2007-10-03 15:01:02 +0200 | [diff] [blame] | 14 | #include <asm/4xx_pci.h> |
stroese | a530a9a | 2004-12-16 18:38:22 +0000 | [diff] [blame] | 15 | #include <asm/processor.h> |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 16 | |
| 17 | #include "pci405.h" |
| 18 | |
Jon Loeliger | 4ed9ed6 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 19 | #if defined(CONFIG_CMD_BSP) |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 20 | |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 21 | /* |
| 22 | * Command loadpci: wait for signal from host and boot image. |
| 23 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 24 | int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 25 | { |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 26 | unsigned int *ptr; |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 27 | int count = 0; |
| 28 | int count2 = 0; |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 29 | int i; |
| 30 | char addr[16]; |
| 31 | char str[] = "\\|/-"; |
| 32 | char *local_args[2]; |
| 33 | |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 34 | /* |
| 35 | * Mark sync address |
| 36 | */ |
| 37 | ptr = 0; |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 38 | /* cppcheck-suppress nullPointer */ |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 39 | *ptr = 0xffffffff; |
| 40 | puts("\nWaiting for image from pci host -"); |
| 41 | |
| 42 | /* |
| 43 | * Wait for host to write the start address |
| 44 | */ |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 45 | /* cppcheck-suppress nullPointer */ |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 46 | while (*ptr == 0xffffffff) { |
| 47 | count++; |
| 48 | if (!(count % 100)) { |
| 49 | count2++; |
| 50 | putc(0x08); /* backspace */ |
| 51 | putc(str[count2 % 4]); |
| 52 | } |
| 53 | |
| 54 | /* Abort if ctrl-c was pressed */ |
| 55 | if (ctrlc()) { |
| 56 | puts("\nAbort\n"); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | udelay(1000); |
| 61 | } |
| 62 | |
| 63 | if (*ptr == PCI_RECONFIG_MAGIC) { |
| 64 | /* |
| 65 | * Save own pci configuration in PRAM |
| 66 | */ |
| 67 | memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN); |
| 68 | ptr = (unsigned int *)PCI_REGS_ADDR + 1; |
| 69 | for (i=0; i<0x40; i+=4) { |
| 70 | pci_read_config_dword(PCIDEVID_405GP, i, ptr++); |
| 71 | } |
| 72 | ptr = (unsigned int *)PCI_REGS_ADDR; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 73 | *ptr = crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4); |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 74 | |
| 75 | printf("\nStoring PCI Configuration Regs...\n"); |
| 76 | } else { |
| 77 | sprintf(addr, "%08x", *ptr); |
stroese | 51fbb18 | 2003-05-23 11:35:09 +0000 | [diff] [blame] | 78 | |
stroese | a530a9a | 2004-12-16 18:38:22 +0000 | [diff] [blame] | 79 | /* |
| 80 | * Boot image via bootm |
| 81 | */ |
| 82 | printf("\nBooting Image at addr 0x%s ...\n", addr); |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 83 | setenv("loadaddr", addr); |
stroese | 51fbb18 | 2003-05-23 11:35:09 +0000 | [diff] [blame] | 84 | |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 85 | local_args[0] = argv[0]; |
| 86 | local_args[1] = NULL; |
Stefan Roese | 98adee8 | 2011-11-15 08:03:06 +0000 | [diff] [blame] | 87 | do_bootm (cmdtp, 0, 1, local_args); |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |
stroese | 9cead26 | 2003-09-12 08:46:10 +0000 | [diff] [blame] | 92 | U_BOOT_CMD( |
| 93 | loadpci, 1, 1, do_loadpci, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 94 | "Wait for pci-image and boot it", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 95 | "" |
stroese | 9cead26 | 2003-09-12 08:46:10 +0000 | [diff] [blame] | 96 | ); |
stroese | 65f36a7 | 2003-03-25 14:41:35 +0000 | [diff] [blame] | 97 | #endif |