Blame view
disk/part_iso.c
6.64 KB
cc1c8a136
|
1 2 3 4 |
/* * (C) Copyright 2001 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch. * |
3765b3e7b
|
5 |
* SPDX-License-Identifier: GPL-2.0+ |
cc1c8a136
|
6 7 8 9 |
*/ #include <common.h> #include <command.h> |
0919228cf
|
10 |
#include <asm/unaligned.h> |
cc1c8a136
|
11 |
#include "part_iso.h" |
1811a928c
|
12 |
#ifdef CONFIG_HAVE_BLOCK_DEVICE |
cc1c8a136
|
13 |
|
1968e615d
|
14 |
/* #define ISO_PART_DEBUG */ |
cc1c8a136
|
15 16 17 18 19 20 21 22 23 24 |
#ifdef ISO_PART_DEBUG #define PRINTF(fmt,args...) printf (fmt ,##args) #else #define PRINTF(fmt,args...) #endif /* enable this if CDs are written with the PowerPC Platform ID */ #undef CHECK_FOR_POWERPC_PLATTFORM #define CD_SECTSIZE 2048 |
5c27535dc
|
25 |
static unsigned char tmpbuf[CD_SECTSIZE] __aligned(ARCH_DMA_MINALIGN); |
cc1c8a136
|
26 |
|
a2adb173e
|
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, void *buffer) { unsigned long ret; if (block_dev->blksz == 512) { /* Convert from 2048 to 512 sector size */ start *= 4; blkcnt *= 4; } ret = blk_dread(block_dev, start, blkcnt, buffer); if (block_dev->blksz == 512) ret /= 4; return ret; } |
cc1c8a136
|
45 |
/* only boot records will be listed as valid partitions */ |
3e8bd4695
|
46 47 |
int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, disk_partition_t *info, int verb) |
cc1c8a136
|
48 49 50 51 52 53 54 55 56 |
{ int i,offset,entry_num; unsigned short *chksumbuf; unsigned short chksum; unsigned long newblkaddr,blkaddr,lastsect,bootaddr; iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf; /* boot record */ iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf; /* primary desc */ iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf; iso_init_def_entry_t *pide; |
a2adb173e
|
57 |
if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512)) |
d7ea4d4d4
|
58 |
return -1; |
cc1c8a136
|
59 60 |
/* the first sector (sector 0x10) must be a primary volume desc */ blkaddr=PVD_OFFSET; |
a2adb173e
|
61 |
if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1) |
7c4213f6a
|
62 |
return -1; |
cc1c8a136
|
63 64 65 66 |
if(ppr->desctype!=0x01) { if(verb) printf ("** First descriptor is NOT a primary desc on %d:%d ** ", |
bcce53d04
|
67 |
dev_desc->devnum, part_num); |
cc1c8a136
|
68 69 |
return (-1); } |
77ddac948
|
70 |
if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) { |
cc1c8a136
|
71 72 73 |
if(verb) printf ("** Wrong ISO Ident: %s on %d:%d ** ", |
bcce53d04
|
74 |
ppr->stand_ident, dev_desc->devnum, part_num); |
cc1c8a136
|
75 76 |
return (-1); } |
ef9e6de54
|
77 78 79 |
lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE); /* assuming same block size for all entries */ info->blksz = be16_to_cpu(ppr->secsize_BE); |
cc1c8a136
|
80 81 82 |
PRINTF(" Lastsect:%08lx ",lastsect); for(i=blkaddr;i<lastsect;i++) { |
c7de829c7
|
83 84 |
PRINTF("Reading block %d ", i); |
a2adb173e
|
85 |
if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1) |
7c4213f6a
|
86 |
return -1; |
cc1c8a136
|
87 88 89 90 91 92 |
if(ppr->desctype==0x00) break; /* boot entry found */ if(ppr->desctype==0xff) { if(verb) printf ("** No valid boot catalog found on %d:%d ** ", |
bcce53d04
|
93 |
dev_desc->devnum, part_num); |
cc1c8a136
|
94 95 96 |
return (-1); } } |
53677ef18
|
97 |
/* boot entry found */ |
cc1c8a136
|
98 99 100 101 |
if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) { if(verb) printf ("** Wrong El Torito ident: %s on %d:%d ** ", |
bcce53d04
|
102 |
pbr->ident_str, dev_desc->devnum, part_num); |
cc1c8a136
|
103 104 |
return (-1); } |
0919228cf
|
105 |
bootaddr = get_unaligned_le32(pbr->pointer); |
cc1c8a136
|
106 107 |
PRINTF(" Boot Entry at: %08lX ",bootaddr); |
a2adb173e
|
108 |
if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) { |
cc1c8a136
|
109 110 111 |
if(verb) printf ("** Can't read Boot Entry at %lX on %d:%d ** ", |
bcce53d04
|
112 |
bootaddr, dev_desc->devnum, part_num); |
cc1c8a136
|
113 114 115 116 117 |
return (-1); } chksum=0; chksumbuf = (unsigned short *)tmpbuf; for(i=0;i<0x10;i++) |
ef9e6de54
|
118 |
chksum += le16_to_cpu(chksumbuf[i]); |
cc1c8a136
|
119 120 |
if(chksum!=0) { if(verb) |
bcce53d04
|
121 122 123 |
printf("** Checksum Error in booting catalog validation entry on %d:%d ** ", dev_desc->devnum, part_num); |
cc1c8a136
|
124 125 126 127 128 129 |
return (-1); } if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) { if(verb) printf ("** Key 0x55 0xAA error on %d:%d ** ", |
bcce53d04
|
130 |
dev_desc->devnum, part_num); |
cc1c8a136
|
131 132 133 134 135 136 137 |
return(-1); } #ifdef CHECK_FOR_POWERPC_PLATTFORM if(pve->platform!=0x01) { if(verb) printf ("** No PowerPC platform CD on %d:%d ** ", |
bcce53d04
|
138 |
dev_desc->devnum, part_num); |
cc1c8a136
|
139 140 141 142 |
return(-1); } #endif /* the validation entry seems to be ok, now search the "partition" */ |
2579c6747
|
143 |
entry_num=1; |
cc1c8a136
|
144 |
offset=0x20; |
192bc6948
|
145 |
strcpy((char *)info->type, "U-Boot"); |
da2ee24d9
|
146 |
part_set_generic_name(dev_desc, part_num, (char *)info->name); |
cc1c8a136
|
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
/* the bootcatalog (including validation Entry) is limited to 2048Bytes * (63 boot entries + validation entry) */ while(offset<2048) { pide=(iso_init_def_entry_t *)&tmpbuf[offset]; if ((pide->boot_ind==0x88) || (pide->boot_ind==0x00)) { /* Header Id for default Sections Entries */ if(entry_num==part_num) { /* part found */ goto found; } entry_num++; /* count partitions Entries (boot and non bootables */ offset+=0x20; continue; } if ((pide->boot_ind==0x90) || /* Section Header Entry */ (pide->boot_ind==0x91) || /* Section Header Entry (last) */ (pide->boot_ind==0x44)) { /* Extension Indicator */ offset+=0x20; /* skip unused entries */ } else { if(verb) printf ("** Partition %d not found on device %d ** ", |
bcce53d04
|
169 |
part_num, dev_desc->devnum); |
cc1c8a136
|
170 171 172 173 174 175 176 177 |
return(-1); } } /* if we reach this point entire sector has been * searched w/o succsess */ if(verb) printf ("** Partition %d not found on device %d ** ", |
bcce53d04
|
178 |
part_num, dev_desc->devnum); |
cc1c8a136
|
179 180 181 182 |
return(-1); found: if(pide->boot_ind!=0x88) { if(verb) |
bcce53d04
|
183 184 185 |
printf("** Partition %d is not bootable on device %d ** ", part_num, dev_desc->devnum); |
cc1c8a136
|
186 187 188 189 |
return (-1); } switch(pide->boot_media) { case 0x00: /* no emulation */ |
0919228cf
|
190 |
info->size = get_unaligned_le16(pide->sec_cnt)>>2; |
cc1c8a136
|
191 192 193 194 195 196 197 |
break; case 0x01: info->size=2400>>2; break; /* 1.2MByte Floppy */ case 0x02: info->size=2880>>2; break; /* 1.44MByte Floppy */ case 0x03: info->size=5760>>2; break; /* 2.88MByte Floppy */ case 0x04: info->size=2880>>2; break; /* dummy (HD Emulation) */ default: info->size=0; break; } |
0919228cf
|
198 |
newblkaddr = get_unaligned_le32(pide->rel_block_addr); |
cc1c8a136
|
199 |
info->start=newblkaddr; |
a2adb173e
|
200 201 202 203 204 205 206 207 208 |
if (dev_desc->blksz == 512) { info->size *= 4; info->start *= 4; info->blksz = 512; } PRINTF(" part %d found @ %lx size %lx ",part_num,info->start,info->size); |
cc1c8a136
|
209 210 |
return 0; } |
3e8bd4695
|
211 |
static int part_get_info_iso(struct blk_desc *dev_desc, int part_num, |
96e5b03c8
|
212 |
disk_partition_t *info) |
cc1c8a136
|
213 |
{ |
b16339e25
|
214 |
return part_get_info_iso_verb(dev_desc, part_num, info, 0); |
cc1c8a136
|
215 |
} |
084bf4c24
|
216 |
static void part_print_iso(struct blk_desc *dev_desc) |
cc1c8a136
|
217 218 219 |
{ disk_partition_t info; int i; |
3e8bd4695
|
220 |
|
28f0014bd
|
221 |
if (part_get_info_iso_verb(dev_desc, 1, &info, 0) == -1) { |
bcce53d04
|
222 223 224 |
printf("** No boot partition found on device %d ** ", dev_desc->devnum); |
cc1c8a136
|
225 226 227 228 |
return; } printf("Part Start Sect x Size Type "); |
28f0014bd
|
229 |
i=1; |
cc1c8a136
|
230 |
do { |
04735e9c5
|
231 232 233 |
printf(" %2d " LBAFU " " LBAFU " %6ld %.32s ", i, info.start, info.size, info.blksz, info.type); |
cc1c8a136
|
234 |
i++; |
3e8bd4695
|
235 |
} while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1); |
cc1c8a136
|
236 |
} |
084bf4c24
|
237 |
static int part_test_iso(struct blk_desc *dev_desc) |
cc1c8a136
|
238 239 |
{ disk_partition_t info; |
b16339e25
|
240 |
return part_get_info_iso_verb(dev_desc, 1, &info, 0); |
cc1c8a136
|
241 |
} |
96e5b03c8
|
242 243 244 |
U_BOOT_PART_TYPE(iso) = { .name = "ISO", .part_type = PART_TYPE_ISO, |
87b8530fe
|
245 |
.max_entries = ISO_ENTRY_NUMBERS, |
3e8bd4695
|
246 |
.get_info = part_get_info_iso, |
084bf4c24
|
247 248 |
.print = part_print_iso, .test = part_test_iso, |
96e5b03c8
|
249 |
}; |
cde5c64d1
|
250 |
#endif |