1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <command.h>
26#include "part_iso.h"
27
28#if defined(CONFIG_CMD_IDE) || \
29 defined(CONFIG_CMD_MG_DISK) || \
30 defined(CONFIG_CMD_SCSI) || \
31 defined(CONFIG_CMD_SATA) || \
32 defined(CONFIG_CMD_USB) || \
33 defined(CONFIG_MMC) || \
34 defined(CONFIG_SYSTEMACE)
35
36
37
38#ifdef ISO_PART_DEBUG
39#define PRINTF(fmt,args...) printf (fmt ,##args)
40#else
41#define PRINTF(fmt,args...)
42#endif
43
44
45#undef CHECK_FOR_POWERPC_PLATTFORM
46#define CD_SECTSIZE 2048
47
48static unsigned char tmpbuf[CD_SECTSIZE];
49
50
51
52static inline unsigned long le32_to_int(unsigned char *le32)
53{
54 return ((le32[3] << 24) +
55 (le32[2] << 16) +
56 (le32[1] << 8) +
57 le32[0]
58 );
59}
60
61
62static inline unsigned short le16_to_int(unsigned char *le16)
63{
64 return ((le16[1] << 8) +
65 le16[0]
66 );
67}
68
69
70
71int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info, int verb)
72{
73 int i,offset,entry_num;
74 unsigned short *chksumbuf;
75 unsigned short chksum;
76 unsigned long newblkaddr,blkaddr,lastsect,bootaddr;
77 iso_boot_rec_t *pbr = (iso_boot_rec_t *)tmpbuf;
78 iso_pri_rec_t *ppr = (iso_pri_rec_t *)tmpbuf;
79 iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
80 iso_init_def_entry_t *pide;
81
82
83 blkaddr=PVD_OFFSET;
84 if (dev_desc->block_read (dev_desc->dev, PVD_OFFSET, 1, (ulong *) tmpbuf) != 1)
85 return (-1);
86 if(ppr->desctype!=0x01) {
87 if(verb)
88 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
89 dev_desc->dev, part_num);
90 return (-1);
91 }
92 if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) {
93 if(verb)
94 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
95 ppr->stand_ident,dev_desc->dev, part_num);
96 return (-1);
97 }
98 lastsect= ((ppr->firstsek_LEpathtab1_LE & 0x000000ff)<<24) +
99 ((ppr->firstsek_LEpathtab1_LE & 0x0000ff00)<< 8) +
100 ((ppr->firstsek_LEpathtab1_LE & 0x00ff0000)>> 8) +
101 ((ppr->firstsek_LEpathtab1_LE & 0xff000000)>>24) ;
102 info->blksz=ppr->secsize_BE;
103 PRINTF(" Lastsect:%08lx\n",lastsect);
104 for(i=blkaddr;i<lastsect;i++) {
105 PRINTF("Reading block %d\n", i);
106 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *) tmpbuf) != 1)
107 return (-1);
108 if(ppr->desctype==0x00)
109 break;
110 if(ppr->desctype==0xff) {
111 if(verb)
112 printf ("** No valid boot catalog found on %d:%d **\n",
113 dev_desc->dev, part_num);
114 return (-1);
115 }
116 }
117
118 if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) {
119 if(verb)
120 printf ("** Wrong El Torito ident: %s on %d:%d **\n",
121 pbr->ident_str,dev_desc->dev, part_num);
122 return (-1);
123 }
124 bootaddr=le32_to_int(pbr->pointer);
125 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
126 if (dev_desc->block_read (dev_desc->dev, bootaddr, 1, (ulong *) tmpbuf) != 1) {
127 if(verb)
128 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
129 bootaddr,dev_desc->dev, part_num);
130 return (-1);
131 }
132 chksum=0;
133 chksumbuf = (unsigned short *)tmpbuf;
134 for(i=0;i<0x10;i++)
135 chksum+=((chksumbuf[i] &0xff)<<8)+((chksumbuf[i] &0xff00)>>8);
136 if(chksum!=0) {
137 if(verb)
138 printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n",
139 dev_desc->dev, part_num);
140 return (-1);
141 }
142 if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) {
143 if(verb)
144 printf ("** Key 0x55 0xAA error on %d:%d **\n",
145 dev_desc->dev, part_num);
146 return(-1);
147 }
148#ifdef CHECK_FOR_POWERPC_PLATTFORM
149 if(pve->platform!=0x01) {
150 if(verb)
151 printf ("** No PowerPC platform CD on %d:%d **\n",
152 dev_desc->dev, part_num);
153 return(-1);
154 }
155#endif
156
157 entry_num=0;
158 offset=0x20;
159 sprintf ((char *)info->type, "U-Boot");
160 switch(dev_desc->if_type) {
161 case IF_TYPE_IDE:
162 case IF_TYPE_SATA:
163 case IF_TYPE_ATAPI:
164 sprintf ((char *)info->name, "hd%c%d",
165 'a' + dev_desc->dev, part_num);
166 break;
167 case IF_TYPE_SCSI:
168 sprintf ((char *)info->name, "sd%c%d",
169 'a' + dev_desc->dev, part_num);
170 break;
171 case IF_TYPE_USB:
172 sprintf ((char *)info->name, "usbd%c%d",
173 'a' + dev_desc->dev, part_num);
174 break;
175 case IF_TYPE_DOC:
176 sprintf ((char *)info->name, "docd%c%d",
177 'a' + dev_desc->dev, part_num);
178 break;
179 default:
180 sprintf ((char *)info->name, "xx%c%d",
181 'a' + dev_desc->dev, part_num);
182 break;
183 }
184
185
186 while(offset<2048) {
187 pide=(iso_init_def_entry_t *)&tmpbuf[offset];
188 if ((pide->boot_ind==0x88) ||
189 (pide->boot_ind==0x00)) {
190 if(entry_num==part_num) {
191 goto found;
192 }
193 entry_num++;
194 offset+=0x20;
195 continue;
196 }
197 if ((pide->boot_ind==0x90) ||
198 (pide->boot_ind==0x91) ||
199 (pide->boot_ind==0x44)) {
200 offset+=0x20;
201 }
202 else {
203 if(verb)
204 printf ("** Partition %d not found on device %d **\n",
205 part_num,dev_desc->dev);
206 return(-1);
207 }
208 }
209
210
211 if(verb)
212 printf ("** Partition %d not found on device %d **\n",
213 part_num,dev_desc->dev);
214 return(-1);
215found:
216 if(pide->boot_ind!=0x88) {
217 if(verb)
218 printf ("** Partition %d is not bootable on device %d **\n",
219 part_num,dev_desc->dev);
220 return (-1);
221 }
222 switch(pide->boot_media) {
223 case 0x00:
224 info->size=le16_to_int(pide->sec_cnt)>>2;
225 break;
226 case 0x01: info->size=2400>>2; break;
227 case 0x02: info->size=2880>>2; break;
228 case 0x03: info->size=5760>>2; break;
229 case 0x04: info->size=2880>>2; break;
230 default: info->size=0; break;
231 }
232 newblkaddr=le32_to_int(pide->rel_block_addr);
233 info->start=newblkaddr;
234 PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
235 return 0;
236}
237
238int get_partition_info_iso(block_dev_desc_t * dev_desc, int part_num, disk_partition_t * info)
239{
240 return(get_partition_info_iso_verb(dev_desc, part_num, info, 1));
241}
242
243
244void print_part_iso(block_dev_desc_t * dev_desc)
245{
246 disk_partition_t info;
247 int i;
248 if(get_partition_info_iso_verb(dev_desc,0,&info,0)==-1) {
249 printf("** No boot partition found on device %d **\n",dev_desc->dev);
250 return;
251 }
252 printf("Part Start Sect x Size Type\n");
253 i=0;
254 do {
255 printf (" %2d %8ld %8ld %6ld %.32s\n",
256 i, info.start, info.size, info.blksz, info.type);
257 i++;
258 } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);
259}
260
261int test_part_iso (block_dev_desc_t *dev_desc)
262{
263 disk_partition_t info;
264
265 return(get_partition_info_iso_verb(dev_desc,0,&info,0));
266}
267
268#endif
269