]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
cc1c8a13 WD |
2 | /* |
3 | * (C) Copyright 2001 | |
4 | * Denis Peter, MPL AG Switzerland, [email protected]. | |
cc1c8a13 WD |
5 | */ |
6 | ||
7 | #include <common.h> | |
e6f6f9e6 | 8 | #include <blk.h> |
cc1c8a13 | 9 | #include <command.h> |
e6f6f9e6 | 10 | #include <part.h> |
90526e9f | 11 | #include <asm/cache.h> |
0919228c | 12 | #include <asm/unaligned.h> |
cc1c8a13 WD |
13 | #include "part_iso.h" |
14 | ||
1811a928 | 15 | #ifdef CONFIG_HAVE_BLOCK_DEVICE |
cc1c8a13 | 16 | |
1968e615 | 17 | /* #define ISO_PART_DEBUG */ |
cc1c8a13 WD |
18 | |
19 | #ifdef ISO_PART_DEBUG | |
20 | #define PRINTF(fmt,args...) printf (fmt ,##args) | |
21 | #else | |
22 | #define PRINTF(fmt,args...) | |
23 | #endif | |
24 | ||
25 | /* enable this if CDs are written with the PowerPC Platform ID */ | |
26 | #undef CHECK_FOR_POWERPC_PLATTFORM | |
27 | #define CD_SECTSIZE 2048 | |
28 | ||
5c27535d | 29 | static unsigned char tmpbuf[CD_SECTSIZE] __aligned(ARCH_DMA_MINALIGN); |
cc1c8a13 | 30 | |
a2adb173 AG |
31 | unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start, |
32 | lbaint_t blkcnt, void *buffer) | |
33 | { | |
34 | unsigned long ret; | |
35 | ||
36 | if (block_dev->blksz == 512) { | |
37 | /* Convert from 2048 to 512 sector size */ | |
38 | start *= 4; | |
39 | blkcnt *= 4; | |
40 | } | |
41 | ||
42 | ret = blk_dread(block_dev, start, blkcnt, buffer); | |
43 | ||
44 | if (block_dev->blksz == 512) | |
45 | ret /= 4; | |
46 | ||
47 | return ret; | |
48 | } | |
49 | ||
cc1c8a13 | 50 | /* only boot records will be listed as valid partitions */ |
3e8bd469 | 51 | int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, |
0528979f | 52 | struct disk_partition *info, int verb) |
cc1c8a13 WD |
53 | { |
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; | |
62 | ||
a2adb173 | 63 | if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512)) |
d7ea4d4d EE |
64 | return -1; |
65 | ||
cc1c8a13 WD |
66 | /* the first sector (sector 0x10) must be a primary volume desc */ |
67 | blkaddr=PVD_OFFSET; | |
a2adb173 | 68 | if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1) |
7c4213f6 | 69 | return -1; |
cc1c8a13 WD |
70 | if(ppr->desctype!=0x01) { |
71 | if(verb) | |
72 | printf ("** First descriptor is NOT a primary desc on %d:%d **\n", | |
bcce53d0 | 73 | dev_desc->devnum, part_num); |
cc1c8a13 WD |
74 | return (-1); |
75 | } | |
77ddac94 | 76 | if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) { |
cc1c8a13 WD |
77 | if(verb) |
78 | printf ("** Wrong ISO Ident: %s on %d:%d **\n", | |
bcce53d0 | 79 | ppr->stand_ident, dev_desc->devnum, part_num); |
cc1c8a13 WD |
80 | return (-1); |
81 | } | |
ef9e6de5 AG |
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); | |
cc1c8a13 WD |
85 | PRINTF(" Lastsect:%08lx\n",lastsect); |
86 | for(i=blkaddr;i<lastsect;i++) { | |
c7de829c | 87 | PRINTF("Reading block %d\n", i); |
a2adb173 | 88 | if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1) |
7c4213f6 | 89 | return -1; |
cc1c8a13 WD |
90 | if(ppr->desctype==0x00) |
91 | break; /* boot entry found */ | |
92 | if(ppr->desctype==0xff) { | |
93 | if(verb) | |
94 | printf ("** No valid boot catalog found on %d:%d **\n", | |
bcce53d0 | 95 | dev_desc->devnum, part_num); |
cc1c8a13 WD |
96 | return (-1); |
97 | } | |
98 | } | |
53677ef1 | 99 | /* boot entry found */ |
cc1c8a13 WD |
100 | if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) { |
101 | if(verb) | |
102 | printf ("** Wrong El Torito ident: %s on %d:%d **\n", | |
bcce53d0 | 103 | pbr->ident_str, dev_desc->devnum, part_num); |
cc1c8a13 WD |
104 | return (-1); |
105 | } | |
0919228c | 106 | bootaddr = get_unaligned_le32(pbr->pointer); |
cc1c8a13 | 107 | PRINTF(" Boot Entry at: %08lX\n",bootaddr); |
a2adb173 | 108 | if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) { |
cc1c8a13 WD |
109 | if(verb) |
110 | printf ("** Can't read Boot Entry at %lX on %d:%d **\n", | |
bcce53d0 | 111 | bootaddr, dev_desc->devnum, part_num); |
cc1c8a13 WD |
112 | return (-1); |
113 | } | |
114 | chksum=0; | |
115 | chksumbuf = (unsigned short *)tmpbuf; | |
116 | for(i=0;i<0x10;i++) | |
ef9e6de5 | 117 | chksum += le16_to_cpu(chksumbuf[i]); |
cc1c8a13 WD |
118 | if(chksum!=0) { |
119 | if(verb) | |
bcce53d0 SG |
120 | printf("** Checksum Error in booting catalog validation entry on %d:%d **\n", |
121 | dev_desc->devnum, part_num); | |
cc1c8a13 WD |
122 | return (-1); |
123 | } | |
124 | if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) { | |
125 | if(verb) | |
126 | printf ("** Key 0x55 0xAA error on %d:%d **\n", | |
bcce53d0 | 127 | dev_desc->devnum, part_num); |
cc1c8a13 WD |
128 | return(-1); |
129 | } | |
130 | #ifdef CHECK_FOR_POWERPC_PLATTFORM | |
131 | if(pve->platform!=0x01) { | |
132 | if(verb) | |
133 | printf ("** No PowerPC platform CD on %d:%d **\n", | |
bcce53d0 | 134 | dev_desc->devnum, part_num); |
cc1c8a13 WD |
135 | return(-1); |
136 | } | |
137 | #endif | |
138 | /* the validation entry seems to be ok, now search the "partition" */ | |
2579c674 | 139 | entry_num=1; |
cc1c8a13 | 140 | offset=0x20; |
192bc694 | 141 | strcpy((char *)info->type, "U-Boot"); |
da2ee24d | 142 | part_set_generic_name(dev_desc, part_num, (char *)info->name); |
cc1c8a13 WD |
143 | /* the bootcatalog (including validation Entry) is limited to 2048Bytes |
144 | * (63 boot entries + validation entry) */ | |
145 | while(offset<2048) { | |
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 */ | |
150 | goto found; | |
151 | } | |
152 | entry_num++; /* count partitions Entries (boot and non bootables */ | |
153 | offset+=0x20; | |
154 | continue; | |
155 | } | |
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 */ | |
160 | } | |
161 | else { | |
162 | if(verb) | |
163 | printf ("** Partition %d not found on device %d **\n", | |
bcce53d0 | 164 | part_num, dev_desc->devnum); |
cc1c8a13 WD |
165 | return(-1); |
166 | } | |
167 | } | |
168 | /* if we reach this point entire sector has been | |
169 | * searched w/o succsess */ | |
170 | if(verb) | |
171 | printf ("** Partition %d not found on device %d **\n", | |
bcce53d0 | 172 | part_num, dev_desc->devnum); |
cc1c8a13 WD |
173 | return(-1); |
174 | found: | |
175 | if(pide->boot_ind!=0x88) { | |
176 | if(verb) | |
bcce53d0 SG |
177 | printf("** Partition %d is not bootable on device %d **\n", |
178 | part_num, dev_desc->devnum); | |
cc1c8a13 WD |
179 | return (-1); |
180 | } | |
181 | switch(pide->boot_media) { | |
182 | case 0x00: /* no emulation */ | |
0919228c | 183 | info->size = get_unaligned_le16(pide->sec_cnt)>>2; |
cc1c8a13 WD |
184 | break; |
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; | |
190 | } | |
0919228c | 191 | newblkaddr = get_unaligned_le32(pide->rel_block_addr); |
cc1c8a13 | 192 | info->start=newblkaddr; |
a2adb173 AG |
193 | |
194 | if (dev_desc->blksz == 512) { | |
195 | info->size *= 4; | |
196 | info->start *= 4; | |
197 | info->blksz = 512; | |
198 | } | |
199 | ||
200 | PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,info->size); | |
cc1c8a13 WD |
201 | return 0; |
202 | } | |
203 | ||
3e8bd469 | 204 | static int part_get_info_iso(struct blk_desc *dev_desc, int part_num, |
0528979f | 205 | struct disk_partition *info) |
cc1c8a13 | 206 | { |
b16339e2 | 207 | return part_get_info_iso_verb(dev_desc, part_num, info, 0); |
cc1c8a13 WD |
208 | } |
209 | ||
084bf4c2 | 210 | static void part_print_iso(struct blk_desc *dev_desc) |
cc1c8a13 | 211 | { |
0528979f | 212 | struct disk_partition info; |
cc1c8a13 | 213 | int i; |
3e8bd469 | 214 | |
28f0014b | 215 | if (part_get_info_iso_verb(dev_desc, 1, &info, 0) == -1) { |
bcce53d0 SG |
216 | printf("** No boot partition found on device %d **\n", |
217 | dev_desc->devnum); | |
cc1c8a13 WD |
218 | return; |
219 | } | |
220 | printf("Part Start Sect x Size Type\n"); | |
28f0014b | 221 | i=1; |
cc1c8a13 | 222 | do { |
04735e9c FL |
223 | printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n", |
224 | i, info.start, info.size, info.blksz, info.type); | |
cc1c8a13 | 225 | i++; |
3e8bd469 | 226 | } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1); |
cc1c8a13 WD |
227 | } |
228 | ||
084bf4c2 | 229 | static int part_test_iso(struct blk_desc *dev_desc) |
cc1c8a13 | 230 | { |
0528979f | 231 | struct disk_partition info; |
cc1c8a13 | 232 | |
b16339e2 | 233 | return part_get_info_iso_verb(dev_desc, 1, &info, 0); |
cc1c8a13 WD |
234 | } |
235 | ||
96e5b03c SG |
236 | U_BOOT_PART_TYPE(iso) = { |
237 | .name = "ISO", | |
238 | .part_type = PART_TYPE_ISO, | |
87b8530f | 239 | .max_entries = ISO_ENTRY_NUMBERS, |
3e8bd469 | 240 | .get_info = part_get_info_iso, |
084bf4c2 SG |
241 | .print = part_print_iso, |
242 | .test = part_test_iso, | |
96e5b03c | 243 | }; |
cde5c64d | 244 | #endif |