3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #if defined(CONFIG_CMD_IDE) || \
29 defined(CONFIG_CMD_MG_DISK) || \
30 defined(CONFIG_CMD_SCSI) || \
31 defined(CONFIG_CMD_SATA) || \
32 defined(CONFIG_CMD_USB) || \
33 defined(CONFIG_MMC) || \
34 defined(CONFIG_SYSTEMACE)
36 /* #define ISO_PART_DEBUG */
39 #define PRINTF(fmt,args...) printf (fmt ,##args)
41 #define PRINTF(fmt,args...)
44 /* enable this if CDs are written with the PowerPC Platform ID */
45 #undef CHECK_FOR_POWERPC_PLATTFORM
46 #define CD_SECTSIZE 2048
48 static unsigned char tmpbuf[CD_SECTSIZE];
50 /* Convert char[4] in little endian format to the host format integer
52 static inline unsigned long le32_to_int(unsigned char *le32)
54 return ((le32[3] << 24) +
60 /* Convert char[2] in little endian format to the host format integer
62 static inline unsigned short le16_to_int(unsigned char *le16)
64 return ((le16[1] << 8) +
70 /* only boot records will be listed as valid partitions */
71 int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info, int verb)
73 int i,offset,entry_num;
74 unsigned short *chksumbuf;
75 unsigned short chksum;
76 unsigned long newblkaddr,blkaddr,lastsect,bootaddr;
77 iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */
78 iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */
79 iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
80 iso_init_def_entry_t *pide;
82 /* the first sector (sector 0x10) must be a primary volume desc */
84 if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1)
86 if(ppr->desctype!=0x01) {
88 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
89 dev_desc->dev, part_num);
92 if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
94 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
95 ppr->stand_ident,dev_desc->dev, part_num);
98 lastsect= ((ppr->firstsek_LEpathtab1_LE & 0x000000ff)<<24) +
99 ((ppr->firstsek_LEpathtab1_LE & 0x0000ff00)<< 8) +
100 ((ppr->firstsek_LEpathtab1_LE & 0x00ff0000)>> 8) +
101 ((ppr->firstsek_LEpathtab1_LE & 0xff000000)>>24) ;
102 info->blksz=ppr->secsize_BE; /* assuming same block size for all entries */
103 PRINTF(" Lastsect:%08lx\n",lastsect);
104 for(i=blkaddr;i<lastsect;i++) {
105 PRINTF("Reading block %d\n", i);
106 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *) tmpbuf) != 1)
108 if(ppr->desctype==0x00)
109 break; /* boot entry found */
110 if(ppr->desctype==0xff) {
112 printf ("** No valid boot catalog found on %d:%d **\n",
113 dev_desc->dev, part_num);
117 /* boot entry found */
118 if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
120 printf ("** Wrong El Torito ident: %s on %d:%d **\n",
121 pbr->ident_str,dev_desc->dev, part_num);
124 bootaddr=le32_to_int(pbr->pointer);
125 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
126 if (dev_desc->block_read (dev_desc->dev, bootaddr, 1, (ulong *) tmpbuf) != 1) {
128 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
129 bootaddr,dev_desc->dev, part_num);
133 chksumbuf = (unsigned short *)tmpbuf;
135 chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8);
138 printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n",
139 dev_desc->dev, part_num);
142 if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
144 printf ("** Key 0x55 0xAA error on %d:%d **\n",
145 dev_desc->dev, part_num);
148 #ifdef CHECK_FOR_POWERPC_PLATTFORM
149 if(pve->platform!=0x01) {
151 printf ("** No PowerPC platform CD on %d:%d **\n",
152 dev_desc->dev, part_num);
156 /* the validation entry seems to be ok, now search the "partition" */
159 sprintf ((char *)info->type, "U-Boot");
160 switch(dev_desc->if_type) {
164 sprintf ((char *)info->name, "hd%c%d",
165 'a' + dev_desc->dev, part_num);
168 sprintf ((char *)info->name, "sd%c%d",
169 'a' + dev_desc->dev, part_num);
172 sprintf ((char *)info->name, "usbd%c%d",
173 'a' + dev_desc->dev, part_num);
176 sprintf ((char *)info->name, "docd%c%d",
177 'a' + dev_desc->dev, part_num);
180 sprintf ((char *)info->name, "xx%c%d",
181 'a' + dev_desc->dev, part_num);
184 /* the bootcatalog (including validation Entry) is limited to 2048Bytes
185 * (63 boot entries + validation entry) */
187 pide=(iso_init_def_entry_t *)&tmpbuf[offset];
188 if ((pide->boot_ind==0x88) ||
189 (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */
190 if(entry_num==part_num) { /* part found */
193 entry_num++; /* count partitions Entries (boot and non bootables */
197 if ((pide->boot_ind==0x90) || /* Section Header Entry */
198 (pide->boot_ind==0x91) || /* Section Header Entry (last) */
199 (pide->boot_ind==0x44)) { /* Extension Indicator */
200 offset+=0x20; /* skip unused entries */
204 printf ("** Partition %d not found on device %d **\n",
205 part_num,dev_desc->dev);
209 /* if we reach this point entire sector has been
210 * searched w/o succsess */
212 printf ("** Partition %d not found on device %d **\n",
213 part_num,dev_desc->dev);
216 if(pide->boot_ind!=0x88) {
218 printf ("** Partition %d is not bootable on device %d **\n",
219 part_num,dev_desc->dev);
222 switch(pide->boot_media) {
223 case 0x00: /* no emulation */
224 info->size=le16_to_int(pide->sec_cnt)>>2;
226 case 0x01: info->size=2400>>2; break; /* 1.2MByte Floppy */
227 case 0x02: info->size=2880>>2; break; /* 1.44MByte Floppy */
228 case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */
229 case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */
230 default: info->size=0; break;
232 newblkaddr=le32_to_int(pide->rel_block_addr);
233 info->start=newblkaddr;
234 PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
238 int get_partition_info_iso(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info)
240 return(get_partition_info_iso_verb(dev_desc, part_num, info, 1));
244 void print_part_iso(block_dev_desc_t * dev_desc)
246 disk_partition_t info;
248 if(get_partition_info_iso_verb(dev_desc,0,&info,0)==-1) {
249 printf("** No boot partition found on device %d **\n",dev_desc->dev);
252 printf("Part Start Sect x Size Type\n");
255 printf (" %2d %8ld %8ld %6ld %.32s\n",
256 i, info.start, info.size, info.blksz, info.type);
258 } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);
261 int test_part_iso (block_dev_desc_t *dev_desc)
263 disk_partition_t info;
265 return(get_partition_info_iso_verb(dev_desc,0,&info,0));