|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2011
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <part.h>
|
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
|
|
|
|
defined(CONFIG_USB_STORAGE)
|
|
|
|
int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
int dev, part;
|
|
|
|
ulong addr = CONFIG_SYS_LOAD_ADDR;
|
|
|
|
ulong cnt;
|
|
|
|
disk_partition_t info;
|
|
|
|
image_header_t *hdr;
|
|
|
|
block_dev_desc_t *dev_desc;
|
|
|
|
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
const void *fit_hdr = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_START);
|
|
|
|
if (argc > 3) {
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
addr = simple_strtoul(argv[1], NULL, 16);
|
|
|
|
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
|
|
|
|
|
|
|
|
part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
|
disk: get_device_and_partition() "auto" partition and cleanup
Rework get_device_and_partition() to:
a) Implement a new partition ID of "auto", which requests that U-Boot
search for the first "bootable" partition, and fall back to the first
valid partition if none is found. This way, users don't need to
specify an explicit partition in their commands.
b) Make use of get_device().
c) Add parameter to indicate whether returning a whole device is
acceptable, or whether a partition is mandatory.
d) Make error-checking of the user's device-/partition-specification
more complete. In particular, if strtoul() doesn't convert all
characters, it's an error rather than just ignored.
The resultant device/partition returned by the function will be as
follows, based on whether the disk has a partition table (ptable) or not,
and whether the calling command allows the whole device to be returned
or not.
(D and P are integers, P >= 1)
D
D:
No ptable:
!allow_whole_dev: error
allow_whole_dev: device D
ptable:
device D partition 1
D:0
!allow_whole_dev: error
allow_whole_dev: device D
D:P
No ptable: error
ptable: device D partition P
D:auto
No ptable:
!allow_whole_dev: error
allow_whole_dev: device D
ptable:
first partition in device D with bootable flag set.
If none, first valid paratition in device D.
Note: In order to review this patch, it's probably easiest to simply
look at the file contents post-application, rather than reading the
patch itself.
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
[swarren: Rob implemented scanning for bootable partitions. I fixed a
couple of issues there, switched the syntax to ":auto", added the
error-checking rework, and ":0" syntax for the whole device]
Signed-off-by: Stephen Warren <swarren@nvidia.com>
12 years ago
|
|
|
&dev_desc, &info, 1);
|
|
|
|
if (part < 0) {
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = dev_desc->dev;
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
|
|
|
|
|
|
|
|
printf("\nLoading from %s device %d, partition %d: "
|
|
|
|
"Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
|
|
|
|
info.type);
|
|
|
|
|
|
|
|
debug("First Block: " LBAFU ", # of blocks: " LBAFU
|
|
|
|
", Block Size: %ld\n",
|
|
|
|
info.start, info.size, info.blksz);
|
|
|
|
|
|
|
|
if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
|
|
|
|
printf("** Read error on %d:%d\n", dev, part);
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
|
|
|
|
|
|
|
|
switch (genimg_get_format((void *) addr)) {
|
|
|
|
case IMAGE_FORMAT_LEGACY:
|
|
|
|
hdr = (image_header_t *) addr;
|
|
|
|
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
|
|
|
|
|
|
|
|
if (!image_check_hcrc(hdr)) {
|
|
|
|
puts("\n** Bad Header Checksum **\n");
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
|
|
|
|
|
|
|
|
image_print_contents(hdr);
|
|
|
|
|
|
|
|
cnt = image_get_image_size(hdr);
|
|
|
|
break;
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
case IMAGE_FORMAT_FIT:
|
|
|
|
fit_hdr = (const void *) addr;
|
|
|
|
puts("Fit image detected...\n");
|
|
|
|
|
|
|
|
cnt = fit_get_size(fit_hdr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
|
|
|
|
puts("** Unknown image type\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt += info.blksz - 1;
|
|
|
|
cnt /= info.blksz;
|
|
|
|
cnt -= 1;
|
|
|
|
|
|
|
|
if (dev_desc->block_read(dev, info.start + 1, cnt,
|
|
|
|
(ulong *)(addr + info.blksz)) != cnt) {
|
|
|
|
printf("** Read error on %d:%d\n", dev, part);
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_READ);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_READ);
|
|
|
|
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
/* This cannot be done earlier,
|
|
|
|
* we need complete FIT image in RAM first */
|
|
|
|
if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
|
|
|
|
if (!fit_check_format(fit_hdr)) {
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
|
|
|
|
puts("** Bad FIT image format\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
|
|
|
|
fit_print_contents(fit_hdr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
flush_cache(addr, (cnt+1)*info.blksz);
|
|
|
|
|
|
|
|
/* Loading ok, update default load address */
|
|
|
|
load_addr = addr;
|
|
|
|
|
|
|
|
return bootm_maybe_autostart(cmdtp, argv[0]);
|
|
|
|
}
|
|
|
|
#endif
|