3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/unaligned.h>
13 #ifdef HAVE_BLOCK_DEVICE
15 /* #define ISO_PART_DEBUG */
18 #define PRINTF(fmt,args...) printf (fmt ,##args)
20 #define PRINTF(fmt,args...)
23 /* enable this if CDs are written with the PowerPC Platform ID */
24 #undef CHECK_FOR_POWERPC_PLATTFORM
25 #define CD_SECTSIZE 2048
27 static unsigned char tmpbuf[CD_SECTSIZE];
29 /* only boot records will be listed as valid partitions */
30 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
31 disk_partition_t *info, int verb)
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;
42 if (dev_desc->blksz != CD_SECTSIZE)
45 /* the first sector (sector 0x10) must be a primary volume desc */
47 if (blk_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
49 if(ppr->desctype!=0x01) {
51 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
52 dev_desc->devnum, part_num);
55 if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
57 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
58 ppr->stand_ident, dev_desc->devnum, part_num);
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++) {
68 PRINTF("Reading block %d\n", i);
69 if (blk_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
71 if(ppr->desctype==0x00)
72 break; /* boot entry found */
73 if(ppr->desctype==0xff) {
75 printf ("** No valid boot catalog found on %d:%d **\n",
76 dev_desc->devnum, part_num);
80 /* boot entry found */
81 if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
83 printf ("** Wrong El Torito ident: %s on %d:%d **\n",
84 pbr->ident_str, dev_desc->devnum, part_num);
87 bootaddr = get_unaligned_le32(pbr->pointer);
88 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
89 if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
91 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
92 bootaddr, dev_desc->devnum, part_num);
96 chksumbuf = (unsigned short *)tmpbuf;
98 chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8);
101 printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
102 dev_desc->devnum, part_num);
105 if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
107 printf ("** Key 0x55 0xAA error on %d:%d **\n",
108 dev_desc->devnum, part_num);
111 #ifdef CHECK_FOR_POWERPC_PLATTFORM
112 if(pve->platform!=0x01) {
114 printf ("** No PowerPC platform CD on %d:%d **\n",
115 dev_desc->devnum, part_num);
119 /* the validation entry seems to be ok, now search the "partition" */
122 strcpy((char *)info->type, "U-Boot");
123 switch(dev_desc->if_type) {
127 sprintf ((char *)info->name, "hd%c%d",
128 'a' + dev_desc->devnum, part_num);
131 sprintf ((char *)info->name, "sd%c%d",
132 'a' + dev_desc->devnum, part_num);
135 sprintf ((char *)info->name, "usbd%c%d",
136 'a' + dev_desc->devnum, part_num);
139 sprintf ((char *)info->name, "docd%c%d",
140 'a' + dev_desc->devnum, part_num);
143 sprintf ((char *)info->name, "xx%c%d",
144 'a' + dev_desc->devnum, part_num);
147 /* the bootcatalog (including validation Entry) is limited to 2048Bytes
148 * (63 boot entries + validation entry) */
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 */
156 entry_num++; /* count partitions Entries (boot and non bootables */
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 */
167 printf ("** Partition %d not found on device %d **\n",
168 part_num, dev_desc->devnum);
172 /* if we reach this point entire sector has been
173 * searched w/o succsess */
175 printf ("** Partition %d not found on device %d **\n",
176 part_num, dev_desc->devnum);
179 if(pide->boot_ind!=0x88) {
181 printf("** Partition %d is not bootable on device %d **\n",
182 part_num, dev_desc->devnum);
185 switch(pide->boot_media) {
186 case 0x00: /* no emulation */
187 info->size = get_unaligned_le16(pide->sec_cnt)>>2;
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;
195 newblkaddr = get_unaligned_le32(pide->rel_block_addr);
196 info->start=newblkaddr;
197 PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
201 static int part_get_info_iso(struct blk_desc *dev_desc, int part_num,
202 disk_partition_t *info)
204 return part_get_info_iso_verb(dev_desc, part_num, info, 1);
207 static void part_print_iso(struct blk_desc *dev_desc)
209 disk_partition_t info;
212 if (part_get_info_iso_verb(dev_desc, 0, &info, 0) == -1) {
213 printf("** No boot partition found on device %d **\n",
217 printf("Part Start Sect x Size Type\n");
220 printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n",
221 i, info.start, info.size, info.blksz, info.type);
223 } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1);
226 static int part_test_iso(struct blk_desc *dev_desc)
228 disk_partition_t info;
230 return part_get_info_iso_verb(dev_desc, 0, &info, 0);
233 U_BOOT_PART_TYPE(iso) = {
235 .part_type = PART_TYPE_ISO,
236 .get_info = part_get_info_iso,
237 .print = part_print_iso,
238 .test = part_test_iso,