1 // SPDX-License-Identifier: GPL-2.0+
4 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
9 #include <asm/unaligned.h>
12 #ifdef CONFIG_HAVE_BLOCK_DEVICE
14 /* #define ISO_PART_DEBUG */
17 #define PRINTF(fmt,args...) printf (fmt ,##args)
19 #define PRINTF(fmt,args...)
22 /* enable this if CDs are written with the PowerPC Platform ID */
23 #undef CHECK_FOR_POWERPC_PLATTFORM
24 #define CD_SECTSIZE 2048
26 static unsigned char tmpbuf[CD_SECTSIZE] __aligned(ARCH_DMA_MINALIGN);
28 unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start,
29 lbaint_t blkcnt, void *buffer)
33 if (block_dev->blksz == 512) {
34 /* Convert from 2048 to 512 sector size */
39 ret = blk_dread(block_dev, start, blkcnt, buffer);
41 if (block_dev->blksz == 512)
47 /* only boot records will be listed as valid partitions */
48 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
49 disk_partition_t *info, int verb)
51 int i,offset,entry_num;
52 unsigned short *chksumbuf;
53 unsigned short chksum;
54 unsigned long newblkaddr,blkaddr,lastsect,bootaddr;
55 iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */
56 iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */
57 iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
58 iso_init_def_entry_t *pide;
60 if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512))
63 /* the first sector (sector 0x10) must be a primary volume desc */
65 if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
67 if(ppr->desctype!=0x01) {
69 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
70 dev_desc->devnum, part_num);
73 if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
75 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
76 ppr->stand_ident, dev_desc->devnum, part_num);
79 lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE);
80 /* assuming same block size for all entries */
81 info->blksz = be16_to_cpu(ppr->secsize_BE);
82 PRINTF(" Lastsect:%08lx\n",lastsect);
83 for(i=blkaddr;i<lastsect;i++) {
84 PRINTF("Reading block %d\n", i);
85 if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
87 if(ppr->desctype==0x00)
88 break; /* boot entry found */
89 if(ppr->desctype==0xff) {
91 printf ("** No valid boot catalog found on %d:%d **\n",
92 dev_desc->devnum, part_num);
96 /* boot entry found */
97 if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
99 printf ("** Wrong El Torito ident: %s on %d:%d **\n",
100 pbr->ident_str, dev_desc->devnum, part_num);
103 bootaddr = get_unaligned_le32(pbr->pointer);
104 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
105 if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
107 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
108 bootaddr, dev_desc->devnum, part_num);
112 chksumbuf = (unsigned short *)tmpbuf;
114 chksum += le16_to_cpu(chksumbuf[i]);
117 printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
118 dev_desc->devnum, part_num);
121 if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
123 printf ("** Key 0x55 0xAA error on %d:%d **\n",
124 dev_desc->devnum, part_num);
127 #ifdef CHECK_FOR_POWERPC_PLATTFORM
128 if(pve->platform!=0x01) {
130 printf ("** No PowerPC platform CD on %d:%d **\n",
131 dev_desc->devnum, part_num);
135 /* the validation entry seems to be ok, now search the "partition" */
138 strcpy((char *)info->type, "U-Boot");
139 part_set_generic_name(dev_desc, part_num, (char *)info->name);
140 /* the bootcatalog (including validation Entry) is limited to 2048Bytes
141 * (63 boot entries + validation entry) */
143 pide=(iso_init_def_entry_t *)&tmpbuf[offset];
144 if ((pide->boot_ind==0x88) ||
145 (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */
146 if(entry_num==part_num) { /* part found */
149 entry_num++; /* count partitions Entries (boot and non bootables */
153 if ((pide->boot_ind==0x90) || /* Section Header Entry */
154 (pide->boot_ind==0x91) || /* Section Header Entry (last) */
155 (pide->boot_ind==0x44)) { /* Extension Indicator */
156 offset+=0x20; /* skip unused entries */
160 printf ("** Partition %d not found on device %d **\n",
161 part_num, dev_desc->devnum);
165 /* if we reach this point entire sector has been
166 * searched w/o succsess */
168 printf ("** Partition %d not found on device %d **\n",
169 part_num, dev_desc->devnum);
172 if(pide->boot_ind!=0x88) {
174 printf("** Partition %d is not bootable on device %d **\n",
175 part_num, dev_desc->devnum);
178 switch(pide->boot_media) {
179 case 0x00: /* no emulation */
180 info->size = get_unaligned_le16(pide->sec_cnt)>>2;
182 case 0x01: info->size=2400>>2; break; /* 1.2MByte Floppy */
183 case 0x02: info->size=2880>>2; break; /* 1.44MByte Floppy */
184 case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */
185 case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */
186 default: info->size=0; break;
188 newblkaddr = get_unaligned_le32(pide->rel_block_addr);
189 info->start=newblkaddr;
191 if (dev_desc->blksz == 512) {
197 PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,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, 0);
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, 1, &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, 1, &info, 0);
233 U_BOOT_PART_TYPE(iso) = {
235 .part_type = PART_TYPE_ISO,
236 .max_entries = ISO_ENTRY_NUMBERS,
237 .get_info = part_get_info_iso,
238 .print = part_print_iso,
239 .test = part_test_iso,