1 // SPDX-License-Identifier: GPL-2.0+
4 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
11 #include <asm/cache.h>
12 #include <asm/unaligned.h>
15 #ifdef CONFIG_HAVE_BLOCK_DEVICE
17 /* #define ISO_PART_DEBUG */
20 #define PRINTF(fmt,args...) printf (fmt ,##args)
22 #define PRINTF(fmt,args...)
25 /* enable this if CDs are written with the PowerPC Platform ID */
26 #undef CHECK_FOR_POWERPC_PLATTFORM
27 #define CD_SECTSIZE 2048
29 static unsigned char tmpbuf[CD_SECTSIZE] __aligned(ARCH_DMA_MINALIGN);
31 unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start,
32 lbaint_t blkcnt, void *buffer)
36 if (block_dev->blksz == 512) {
37 /* Convert from 2048 to 512 sector size */
42 ret = blk_dread(block_dev, start, blkcnt, buffer);
44 if (block_dev->blksz == 512)
50 /* only boot records will be listed as valid partitions */
51 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
52 struct disk_partition *info, int verb)
54 int i,offset,entry_num;
55 unsigned short *chksumbuf;
56 unsigned short chksum;
57 unsigned long newblkaddr,blkaddr,lastsect,bootaddr;
58 iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */
59 iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */
60 iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
61 iso_init_def_entry_t *pide;
63 if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512))
66 /* the first sector (sector 0x10) must be a primary volume desc */
68 if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
70 if(ppr->desctype!=0x01) {
72 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
73 dev_desc->devnum, part_num);
76 if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
78 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
79 ppr->stand_ident, dev_desc->devnum, part_num);
82 lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE);
83 /* assuming same block size for all entries */
84 info->blksz = be16_to_cpu(ppr->secsize_BE);
85 PRINTF(" Lastsect:%08lx\n",lastsect);
86 for(i=blkaddr;i<lastsect;i++) {
87 PRINTF("Reading block %d\n", i);
88 if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
90 if(ppr->desctype==0x00)
91 break; /* boot entry found */
92 if(ppr->desctype==0xff) {
94 printf ("** No valid boot catalog found on %d:%d **\n",
95 dev_desc->devnum, part_num);
99 /* boot entry found */
100 if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
102 printf ("** Wrong El Torito ident: %s on %d:%d **\n",
103 pbr->ident_str, dev_desc->devnum, part_num);
106 bootaddr = get_unaligned_le32(pbr->pointer);
107 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
108 if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
110 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
111 bootaddr, dev_desc->devnum, part_num);
115 chksumbuf = (unsigned short *)tmpbuf;
117 chksum += le16_to_cpu(chksumbuf[i]);
120 printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
121 dev_desc->devnum, part_num);
124 if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
126 printf ("** Key 0x55 0xAA error on %d:%d **\n",
127 dev_desc->devnum, part_num);
130 #ifdef CHECK_FOR_POWERPC_PLATTFORM
131 if(pve->platform!=0x01) {
133 printf ("** No PowerPC platform CD on %d:%d **\n",
134 dev_desc->devnum, part_num);
138 /* the validation entry seems to be ok, now search the "partition" */
141 strcpy((char *)info->type, "U-Boot");
142 part_set_generic_name(dev_desc, part_num, (char *)info->name);
143 /* the bootcatalog (including validation Entry) is limited to 2048Bytes
144 * (63 boot entries + validation entry) */
146 pide=(iso_init_def_entry_t *)&tmpbuf[offset];
147 if ((pide->boot_ind==0x88) ||
148 (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */
149 if(entry_num==part_num) { /* part found */
152 entry_num++; /* count partitions Entries (boot and non bootables */
156 if ((pide->boot_ind==0x90) || /* Section Header Entry */
157 (pide->boot_ind==0x91) || /* Section Header Entry (last) */
158 (pide->boot_ind==0x44)) { /* Extension Indicator */
159 offset+=0x20; /* skip unused entries */
163 printf ("** Partition %d not found on device %d **\n",
164 part_num, dev_desc->devnum);
168 /* if we reach this point entire sector has been
169 * searched w/o succsess */
171 printf ("** Partition %d not found on device %d **\n",
172 part_num, dev_desc->devnum);
175 if(pide->boot_ind!=0x88) {
177 printf("** Partition %d is not bootable on device %d **\n",
178 part_num, dev_desc->devnum);
181 switch(pide->boot_media) {
182 case 0x00: /* no emulation */
183 info->size = get_unaligned_le16(pide->sec_cnt)>>2;
185 case 0x01: info->size=2400>>2; break; /* 1.2MByte Floppy */
186 case 0x02: info->size=2880>>2; break; /* 1.44MByte Floppy */
187 case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */
188 case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */
189 default: info->size=0; break;
191 newblkaddr = get_unaligned_le32(pide->rel_block_addr);
192 info->start=newblkaddr;
194 if (dev_desc->blksz == 512) {
200 PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,info->size);
204 static int part_get_info_iso(struct blk_desc *dev_desc, int part_num,
205 struct disk_partition *info)
207 return part_get_info_iso_verb(dev_desc, part_num, info, 0);
210 static void part_print_iso(struct blk_desc *dev_desc)
212 struct disk_partition info;
215 if (part_get_info_iso_verb(dev_desc, 1, &info, 0) == -1) {
216 printf("** No boot partition found on device %d **\n",
220 printf("Part Start Sect x Size Type\n");
223 printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n",
224 i, info.start, info.size, info.blksz, info.type);
226 } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1);
229 static int part_test_iso(struct blk_desc *dev_desc)
231 struct disk_partition info;
233 return part_get_info_iso_verb(dev_desc, 1, &info, 0);
236 U_BOOT_PART_TYPE(iso) = {
238 .part_type = PART_TYPE_ISO,
239 .max_entries = ISO_ENTRY_NUMBERS,
240 .get_info = part_get_info_iso,
241 .print = part_print_iso,
242 .test = part_test_iso,