wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch. |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Simon Glass | 0919228 | 2016-03-16 07:45:34 -0600 | [diff] [blame] | 10 | #include <asm/unaligned.h> |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 11 | #include "part_iso.h" |
| 12 | |
Stephen Warren | 2c1af9d | 2013-02-28 15:03:46 +0000 | [diff] [blame] | 13 | #ifdef HAVE_BLOCK_DEVICE |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 14 | |
wdenk | 1968e61 | 2005-02-24 23:23:29 +0000 | [diff] [blame] | 15 | /* #define ISO_PART_DEBUG */ |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 16 | |
| 17 | #ifdef ISO_PART_DEBUG |
| 18 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 19 | #else |
| 20 | #define PRINTF(fmt,args...) |
| 21 | #endif |
| 22 | |
| 23 | /* enable this if CDs are written with the PowerPC Platform ID */ |
| 24 | #undef CHECK_FOR_POWERPC_PLATTFORM |
| 25 | #define CD_SECTSIZE 2048 |
| 26 | |
| 27 | static unsigned char tmpbuf[CD_SECTSIZE]; |
| 28 | |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 29 | /* only boot records will be listed as valid partitions */ |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 30 | int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, |
| 31 | disk_partition_t *info, int verb) |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 32 | { |
| 33 | int i,offset,entry_num; |
| 34 | unsigned short *chksumbuf; |
| 35 | unsigned short chksum; |
| 36 | unsigned long newblkaddr,blkaddr,lastsect,bootaddr; |
| 37 | iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */ |
| 38 | iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */ |
| 39 | iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf; |
| 40 | iso_init_def_entry_t *pide; |
| 41 | |
Egbert Eich | d7ea4d4 | 2013-04-09 21:11:54 +0000 | [diff] [blame] | 42 | if (dev_desc->blksz != CD_SECTSIZE) |
| 43 | return -1; |
| 44 | |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 45 | /* the first sector (sector 0x10) must be a primary volume desc */ |
| 46 | blkaddr=PVD_OFFSET; |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 47 | if (blk_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1) |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 48 | return -1; |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 49 | if(ppr->desctype!=0x01) { |
| 50 | if(verb) |
| 51 | printf ("** First descriptor is NOT a primary desc on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 52 | dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 53 | return (-1); |
| 54 | } |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 55 | if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) { |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 56 | if(verb) |
| 57 | printf ("** Wrong ISO Ident: %s on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 58 | ppr->stand_ident, dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 59 | return (-1); |
| 60 | } |
| 61 | lastsect= ((ppr->firstsek_LEpathtab1_LE & 0x000000ff)<<24) + |
| 62 | ((ppr->firstsek_LEpathtab1_LE & 0x0000ff00)<< 8) + |
| 63 | ((ppr->firstsek_LEpathtab1_LE & 0x00ff0000)>> 8) + |
| 64 | ((ppr->firstsek_LEpathtab1_LE & 0xff000000)>>24) ; |
| 65 | info->blksz=ppr->secsize_BE; /* assuming same block size for all entries */ |
| 66 | PRINTF(" Lastsect:%08lx\n",lastsect); |
| 67 | for(i=blkaddr;i<lastsect;i++) { |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 68 | PRINTF("Reading block %d\n", i); |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 69 | if (blk_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1) |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 70 | return -1; |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 71 | if(ppr->desctype==0x00) |
| 72 | break; /* boot entry found */ |
| 73 | if(ppr->desctype==0xff) { |
| 74 | if(verb) |
| 75 | printf ("** No valid boot catalog found on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 76 | dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 77 | return (-1); |
| 78 | } |
| 79 | } |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 80 | /* boot entry found */ |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 81 | if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) { |
| 82 | if(verb) |
| 83 | printf ("** Wrong El Torito ident: %s on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 84 | pbr->ident_str, dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 85 | return (-1); |
| 86 | } |
Simon Glass | 0919228 | 2016-03-16 07:45:34 -0600 | [diff] [blame] | 87 | bootaddr = get_unaligned_le32(pbr->pointer); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 88 | PRINTF(" Boot Entry at: %08lX\n",bootaddr); |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 89 | if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) { |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 90 | if(verb) |
| 91 | printf ("** Can't read Boot Entry at %lX on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 92 | bootaddr, dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 93 | return (-1); |
| 94 | } |
| 95 | chksum=0; |
| 96 | chksumbuf = (unsigned short *)tmpbuf; |
| 97 | for(i=0;i<0x10;i++) |
| 98 | chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8); |
| 99 | if(chksum!=0) { |
| 100 | if(verb) |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 101 | printf("** Checksum Error in booting catalog validation entry on %d:%d **\n", |
| 102 | dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 103 | return (-1); |
| 104 | } |
| 105 | if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) { |
| 106 | if(verb) |
| 107 | printf ("** Key 0x55 0xAA error on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 108 | dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 109 | return(-1); |
| 110 | } |
| 111 | #ifdef CHECK_FOR_POWERPC_PLATTFORM |
| 112 | if(pve->platform!=0x01) { |
| 113 | if(verb) |
| 114 | printf ("** No PowerPC platform CD on %d:%d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 115 | dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 116 | return(-1); |
| 117 | } |
| 118 | #endif |
| 119 | /* the validation entry seems to be ok, now search the "partition" */ |
| 120 | entry_num=0; |
| 121 | offset=0x20; |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 122 | strcpy((char *)info->type, "U-Boot"); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 123 | switch(dev_desc->if_type) { |
| 124 | case IF_TYPE_IDE: |
Dave Liu | c7057b5 | 2008-03-26 22:49:44 +0800 | [diff] [blame] | 125 | case IF_TYPE_SATA: |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 126 | case IF_TYPE_ATAPI: |
Wolfgang Denk | 7166552 | 2009-07-28 22:35:39 +0200 | [diff] [blame] | 127 | sprintf ((char *)info->name, "hd%c%d", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 128 | 'a' + dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 129 | break; |
| 130 | case IF_TYPE_SCSI: |
Wolfgang Denk | 7166552 | 2009-07-28 22:35:39 +0200 | [diff] [blame] | 131 | sprintf ((char *)info->name, "sd%c%d", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 132 | 'a' + dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 133 | break; |
| 134 | case IF_TYPE_USB: |
Wolfgang Denk | 7166552 | 2009-07-28 22:35:39 +0200 | [diff] [blame] | 135 | sprintf ((char *)info->name, "usbd%c%d", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 136 | 'a' + dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 137 | break; |
| 138 | case IF_TYPE_DOC: |
Wolfgang Denk | 7166552 | 2009-07-28 22:35:39 +0200 | [diff] [blame] | 139 | sprintf ((char *)info->name, "docd%c%d", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 140 | 'a' + dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 141 | break; |
| 142 | default: |
Wolfgang Denk | 7166552 | 2009-07-28 22:35:39 +0200 | [diff] [blame] | 143 | sprintf ((char *)info->name, "xx%c%d", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 144 | 'a' + dev_desc->devnum, part_num); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 145 | break; |
| 146 | } |
| 147 | /* the bootcatalog (including validation Entry) is limited to 2048Bytes |
| 148 | * (63 boot entries + validation entry) */ |
| 149 | while(offset<2048) { |
| 150 | pide=(iso_init_def_entry_t *)&tmpbuf[offset]; |
| 151 | if ((pide->boot_ind==0x88) || |
| 152 | (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */ |
| 153 | if(entry_num==part_num) { /* part found */ |
| 154 | goto found; |
| 155 | } |
| 156 | entry_num++; /* count partitions Entries (boot and non bootables */ |
| 157 | offset+=0x20; |
| 158 | continue; |
| 159 | } |
| 160 | if ((pide->boot_ind==0x90) || /* Section Header Entry */ |
| 161 | (pide->boot_ind==0x91) || /* Section Header Entry (last) */ |
| 162 | (pide->boot_ind==0x44)) { /* Extension Indicator */ |
| 163 | offset+=0x20; /* skip unused entries */ |
| 164 | } |
| 165 | else { |
| 166 | if(verb) |
| 167 | printf ("** Partition %d not found on device %d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 168 | part_num, dev_desc->devnum); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 169 | return(-1); |
| 170 | } |
| 171 | } |
| 172 | /* if we reach this point entire sector has been |
| 173 | * searched w/o succsess */ |
| 174 | if(verb) |
| 175 | printf ("** Partition %d not found on device %d **\n", |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 176 | part_num, dev_desc->devnum); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 177 | return(-1); |
| 178 | found: |
| 179 | if(pide->boot_ind!=0x88) { |
| 180 | if(verb) |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 181 | printf("** Partition %d is not bootable on device %d **\n", |
| 182 | part_num, dev_desc->devnum); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 183 | return (-1); |
| 184 | } |
| 185 | switch(pide->boot_media) { |
| 186 | case 0x00: /* no emulation */ |
Simon Glass | 0919228 | 2016-03-16 07:45:34 -0600 | [diff] [blame] | 187 | info->size = get_unaligned_le16(pide->sec_cnt)>>2; |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 188 | break; |
| 189 | case 0x01: info->size=2400>>2; break; /* 1.2MByte Floppy */ |
| 190 | case 0x02: info->size=2880>>2; break; /* 1.44MByte Floppy */ |
| 191 | case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */ |
| 192 | case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */ |
| 193 | default: info->size=0; break; |
| 194 | } |
Simon Glass | 0919228 | 2016-03-16 07:45:34 -0600 | [diff] [blame] | 195 | newblkaddr = get_unaligned_le32(pide->rel_block_addr); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 196 | info->start=newblkaddr; |
| 197 | PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size); |
| 198 | return 0; |
| 199 | } |
| 200 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 201 | static int part_get_info_iso(struct blk_desc *dev_desc, int part_num, |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 202 | disk_partition_t *info) |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 203 | { |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 204 | return part_get_info_iso_verb(dev_desc, part_num, info, 1); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 207 | static void part_print_iso(struct blk_desc *dev_desc) |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 208 | { |
| 209 | disk_partition_t info; |
| 210 | int i; |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 211 | |
| 212 | if (part_get_info_iso_verb(dev_desc, 0, &info, 0) == -1) { |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 213 | printf("** No boot partition found on device %d **\n", |
| 214 | dev_desc->devnum); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | printf("Part Start Sect x Size Type\n"); |
| 218 | i=0; |
| 219 | do { |
Frederic Leroy | 04735e9 | 2013-06-26 18:11:25 +0200 | [diff] [blame] | 220 | printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n", |
| 221 | i, info.start, info.size, info.blksz, info.type); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 222 | i++; |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 223 | } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 226 | static int part_test_iso(struct blk_desc *dev_desc) |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 227 | { |
| 228 | disk_partition_t info; |
| 229 | |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 230 | return part_get_info_iso_verb(dev_desc, 0, &info, 0); |
wdenk | cc1c8a1 | 2002-11-02 22:58:18 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 233 | U_BOOT_PART_TYPE(iso) = { |
| 234 | .name = "ISO", |
| 235 | .part_type = PART_TYPE_ISO, |
Simon Glass | 3e8bd46 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 236 | .get_info = part_get_info_iso, |
Simon Glass | 084bf4c | 2016-02-29 15:26:04 -0700 | [diff] [blame] | 237 | .print = part_print_iso, |
| 238 | .test = part_test_iso, |
Simon Glass | 96e5b03 | 2016-02-29 15:25:47 -0700 | [diff] [blame] | 239 | }; |
Jon Loeliger | cde5c64 | 2007-07-09 17:22:37 -0500 | [diff] [blame] | 240 | #endif |