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