Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2011 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 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> |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 26 | #include <part.h> |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 27 | |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 28 | #if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \ |
| 29 | defined(CONFIG_USB_STORAGE) |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 30 | int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, |
| 31 | char *const argv[]) |
| 32 | { |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 33 | int dev, part; |
| 34 | ulong addr = CONFIG_SYS_LOAD_ADDR; |
| 35 | ulong cnt; |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 36 | disk_partition_t info; |
| 37 | image_header_t *hdr; |
| 38 | block_dev_desc_t *dev_desc; |
| 39 | |
| 40 | #if defined(CONFIG_FIT) |
| 41 | const void *fit_hdr = NULL; |
| 42 | #endif |
| 43 | |
| 44 | bootstage_mark(BOOTSTAGE_ID_IDE_START); |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 45 | if (argc > 3) { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 46 | bootstage_error(BOOTSTAGE_ID_IDE_ADDR); |
| 47 | return CMD_RET_USAGE; |
| 48 | } |
| 49 | bootstage_mark(BOOTSTAGE_ID_IDE_ADDR); |
| 50 | |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 51 | if (argc > 1) |
| 52 | addr = simple_strtoul(argv[1], NULL, 16); |
| 53 | |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 54 | bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE); |
| 55 | |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 56 | part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL, |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 57 | &dev_desc, &info, 1); |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 58 | if (part < 0) { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 59 | bootstage_error(BOOTSTAGE_ID_IDE_TYPE); |
| 60 | return 1; |
| 61 | } |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 62 | |
| 63 | dev = dev_desc->dev; |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 64 | bootstage_mark(BOOTSTAGE_ID_IDE_TYPE); |
| 65 | |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 66 | printf("\nLoading from %s device %d, partition %d: " |
| 67 | "Name: %.32s Type: %.32s\n", intf, dev, part, info.name, |
| 68 | info.type); |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 69 | |
Frederic Leroy | 04735e9 | 2013-06-26 18:11:25 +0200 | [diff] [blame] | 70 | debug("First Block: " LBAFU ", # of blocks: " LBAFU |
| 71 | ", Block Size: %ld\n", |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 72 | info.start, info.size, info.blksz); |
| 73 | |
| 74 | if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) { |
| 75 | printf("** Read error on %d:%d\n", dev, part); |
| 76 | bootstage_error(BOOTSTAGE_ID_IDE_PART_READ); |
| 77 | return 1; |
| 78 | } |
| 79 | bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ); |
| 80 | |
| 81 | switch (genimg_get_format((void *) addr)) { |
| 82 | case IMAGE_FORMAT_LEGACY: |
| 83 | hdr = (image_header_t *) addr; |
| 84 | |
| 85 | bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT); |
| 86 | |
| 87 | if (!image_check_hcrc(hdr)) { |
| 88 | puts("\n** Bad Header Checksum **\n"); |
| 89 | bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM); |
| 90 | return 1; |
| 91 | } |
| 92 | bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM); |
| 93 | |
| 94 | image_print_contents(hdr); |
| 95 | |
| 96 | cnt = image_get_image_size(hdr); |
| 97 | break; |
| 98 | #if defined(CONFIG_FIT) |
| 99 | case IMAGE_FORMAT_FIT: |
| 100 | fit_hdr = (const void *) addr; |
| 101 | puts("Fit image detected...\n"); |
| 102 | |
| 103 | cnt = fit_get_size(fit_hdr); |
| 104 | break; |
| 105 | #endif |
| 106 | default: |
| 107 | bootstage_error(BOOTSTAGE_ID_IDE_FORMAT); |
| 108 | puts("** Unknown image type\n"); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | cnt += info.blksz - 1; |
| 113 | cnt /= info.blksz; |
| 114 | cnt -= 1; |
| 115 | |
| 116 | if (dev_desc->block_read(dev, info.start + 1, cnt, |
| 117 | (ulong *)(addr + info.blksz)) != cnt) { |
| 118 | printf("** Read error on %d:%d\n", dev, part); |
| 119 | bootstage_error(BOOTSTAGE_ID_IDE_READ); |
| 120 | return 1; |
| 121 | } |
| 122 | bootstage_mark(BOOTSTAGE_ID_IDE_READ); |
| 123 | |
| 124 | #if defined(CONFIG_FIT) |
| 125 | /* This cannot be done earlier, |
| 126 | * we need complete FIT image in RAM first */ |
| 127 | if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) { |
| 128 | if (!fit_check_format(fit_hdr)) { |
| 129 | bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ); |
| 130 | puts("** Bad FIT image format\n"); |
| 131 | return 1; |
| 132 | } |
| 133 | bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK); |
| 134 | fit_print_contents(fit_hdr); |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | flush_cache(addr, (cnt+1)*info.blksz); |
| 139 | |
| 140 | /* Loading ok, update default load address */ |
| 141 | load_addr = addr; |
| 142 | |
| 143 | return bootm_maybe_autostart(cmdtp, argv[0]); |
| 144 | } |
Rob Herring | 475c797 | 2012-08-23 11:31:48 +0000 | [diff] [blame] | 145 | #endif |