- char *boot_device = NULL;
- char *ep;
- int dev, part = 0;
- ulong addr, cnt, checksum;
- disk_partition_t info;
- image_header_t *hdr;
- int rcode = 0;
-
- switch (argc) {
- case 1:
- addr = CFG_LOAD_ADDR;
- boot_device = getenv ("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv ("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- default:
- printf ("Usage:\n%s\n", cmdtp->usage);
- return 1;
- }
-
- if (!boot_device) {
- puts ("\n** No boot device **\n");
- return 1;
- }
-
- dev = simple_strtoul(boot_device, &ep, 16);
- printf("booting from dev %d\n",dev);
- if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
- printf ("\n** Device %d not available\n", dev);
- return 1;
- }
-
- if (*ep) {
- if (*ep != ':') {
- puts ("\n** Invalid boot device, use `dev[:part]' **\n");
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
- if (get_partition_info (&scsi_dev_desc[dev], part, &info)) {
- printf("error reading partinfo\n");
- return 1;
- }
- if ((strncmp((char *)(info.type), BOOT_PART_TYPE, sizeof(info.type)) != 0) &&
- (strncmp((char *)(info.type), BOOT_PART_COMP, sizeof(info.type)) != 0)) {
- printf ("\n** Invalid partition type \"%.32s\""
- " (expect \"" BOOT_PART_TYPE "\")\n",
- info.type);
- return 1;
- }
-
- printf ("\nLoading from SCSI device %d, partition %d: "
- "Name: %.32s Type: %.32s\n",
- dev, part, info.name, info.type);
-
- debug ("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
- info.start, info.size, info.blksz);
-
- if (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) {
- printf ("** Read error on %d:%d\n", dev, part);
- return 1;
- }
-
- hdr = (image_header_t *)addr;
-
- if (ntohl(hdr->ih_magic) == IH_MAGIC) {
- printf("\n** Bad Magic Number **\n");
- return 1;
- }
-
- checksum = ntohl(hdr->ih_hcrc);
- hdr->ih_hcrc = 0;
-
- if (crc32 (0, (uchar *)hdr, sizeof(image_header_t)) != checksum) {
- puts ("\n** Bad Header Checksum **\n");
- return 1;
- }
- hdr->ih_hcrc = htonl(checksum); /* restore checksum for later use */
-
- print_image_hdr (hdr);
- cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t));
- cnt += info.blksz - 1;
- cnt /= info.blksz;
- cnt -= 1;
-
- if (scsi_read (dev, info.start+1, cnt,
- (ulong *)(addr+info.blksz)) != cnt) {
- printf ("** Read error on %d:%d\n", dev, part);
- return 1;
- }
- /* Loading ok, update default load address */
- load_addr = addr;
-
- flush_cache (addr, (cnt+1)*info.blksz);
-
- /* Check if we should attempt an auto-start */
- if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
- char *local_args[2];
- extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
- local_args[0] = argv[0];
- local_args[1] = NULL;
- printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
- rcode = do_bootm (cmdtp, 0, 1, local_args);
- }
- return rcode;