]>
git.ipfire.org Git - people/ms/u-boot.git/blob - disk/part_iso.c
3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
5 * SPDX-License-Identifier: GPL-2.0+
12 #ifdef HAVE_BLOCK_DEVICE
14 /* #define ISO_PART_DEBUG */
17 #define PRINTF(fmt,args...) printf (fmt ,##args)
19 #define PRINTF(fmt,args...)
22 /* enable this if CDs are written with the PowerPC Platform ID */
23 #undef CHECK_FOR_POWERPC_PLATTFORM
24 #define CD_SECTSIZE 2048
26 static unsigned char tmpbuf
[CD_SECTSIZE
];
28 /* Convert char[4] in little endian format to the host format integer
30 static inline unsigned long le32_to_int(unsigned char *le32
)
32 return ((le32
[3] << 24) +
38 /* Convert char[2] in little endian format to the host format integer
40 static inline unsigned short le16_to_int(unsigned char *le16
)
42 return ((le16
[1] << 8) +
48 /* only boot records will be listed as valid partitions */
49 int get_partition_info_iso_verb(struct blk_desc
*dev_desc
, int part_num
,
50 disk_partition_t
*info
, int verb
)
52 int i
,offset
,entry_num
;
53 unsigned short *chksumbuf
;
54 unsigned short chksum
;
55 unsigned long newblkaddr
,blkaddr
,lastsect
,bootaddr
;
56 iso_boot_rec_t
*pbr
= (iso_boot_rec_t
*)tmpbuf
; /* boot record */
57 iso_pri_rec_t
*ppr
= (iso_pri_rec_t
*)tmpbuf
; /* primary desc */
58 iso_val_entry_t
*pve
= (iso_val_entry_t
*)tmpbuf
;
59 iso_init_def_entry_t
*pide
;
61 if (dev_desc
->blksz
!= CD_SECTSIZE
)
64 /* the first sector (sector 0x10) must be a primary volume desc */
66 if (dev_desc
->block_read(dev_desc
, PVD_OFFSET
, 1, (ulong
*)tmpbuf
) != 1)
68 if(ppr
->desctype
!=0x01) {
70 printf ("** First descriptor is NOT a primary desc on %d:%d **\n",
71 dev_desc
->dev
, part_num
);
74 if(strncmp((char *)ppr
->stand_ident
,"CD001",5)!=0) {
76 printf ("** Wrong ISO Ident: %s on %d:%d **\n",
77 ppr
->stand_ident
,dev_desc
->dev
, part_num
);
80 lastsect
= ((ppr
->firstsek_LEpathtab1_LE
& 0x000000ff)<<24) +
81 ((ppr
->firstsek_LEpathtab1_LE
& 0x0000ff00)<< 8) +
82 ((ppr
->firstsek_LEpathtab1_LE
& 0x00ff0000)>> 8) +
83 ((ppr
->firstsek_LEpathtab1_LE
& 0xff000000)>>24) ;
84 info
->blksz
=ppr
->secsize_BE
; /* assuming same block size for all entries */
85 PRINTF(" Lastsect:%08lx\n",lastsect
);
86 for(i
=blkaddr
;i
<lastsect
;i
++) {
87 PRINTF("Reading block %d\n", i
);
88 if (dev_desc
->block_read(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
->dev
, 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
->dev
, part_num
);
106 bootaddr
=le32_to_int(pbr
->pointer
);
107 PRINTF(" Boot Entry at: %08lX\n",bootaddr
);
108 if (dev_desc
->block_read(dev_desc
, bootaddr
, 1, (ulong
*)tmpbuf
) != 1) {
110 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
111 bootaddr
,dev_desc
->dev
, part_num
);
115 chksumbuf
= (unsigned short *)tmpbuf
;
117 chksum
+=((chksumbuf
[i
] &0xff)<<8)+((chksumbuf
[i
] &0xff00)>>8);
120 printf ("** Checksum Error in booting catalog validation entry on %d:%d **\n",
121 dev_desc
->dev
, 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
->dev
, 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
->dev
, part_num
);
138 /* the validation entry seems to be ok, now search the "partition" */
141 strcpy((char *)info
->type
, "U-Boot");
142 switch(dev_desc
->if_type
) {
146 sprintf ((char *)info
->name
, "hd%c%d",
147 'a' + dev_desc
->dev
, part_num
);
150 sprintf ((char *)info
->name
, "sd%c%d",
151 'a' + dev_desc
->dev
, part_num
);
154 sprintf ((char *)info
->name
, "usbd%c%d",
155 'a' + dev_desc
->dev
, part_num
);
158 sprintf ((char *)info
->name
, "docd%c%d",
159 'a' + dev_desc
->dev
, part_num
);
162 sprintf ((char *)info
->name
, "xx%c%d",
163 'a' + dev_desc
->dev
, part_num
);
166 /* the bootcatalog (including validation Entry) is limited to 2048Bytes
167 * (63 boot entries + validation entry) */
169 pide
=(iso_init_def_entry_t
*)&tmpbuf
[offset
];
170 if ((pide
->boot_ind
==0x88) ||
171 (pide
->boot_ind
==0x00)) { /* Header Id for default Sections Entries */
172 if(entry_num
==part_num
) { /* part found */
175 entry_num
++; /* count partitions Entries (boot and non bootables */
179 if ((pide
->boot_ind
==0x90) || /* Section Header Entry */
180 (pide
->boot_ind
==0x91) || /* Section Header Entry (last) */
181 (pide
->boot_ind
==0x44)) { /* Extension Indicator */
182 offset
+=0x20; /* skip unused entries */
186 printf ("** Partition %d not found on device %d **\n",
187 part_num
,dev_desc
->dev
);
191 /* if we reach this point entire sector has been
192 * searched w/o succsess */
194 printf ("** Partition %d not found on device %d **\n",
195 part_num
,dev_desc
->dev
);
198 if(pide
->boot_ind
!=0x88) {
200 printf ("** Partition %d is not bootable on device %d **\n",
201 part_num
,dev_desc
->dev
);
204 switch(pide
->boot_media
) {
205 case 0x00: /* no emulation */
206 info
->size
=le16_to_int(pide
->sec_cnt
)>>2;
208 case 0x01: info
->size
=2400>>2; break; /* 1.2MByte Floppy */
209 case 0x02: info
->size
=2880>>2; break; /* 1.44MByte Floppy */
210 case 0x03: info
->size
=5760>>2; break; /* 2.88MByte Floppy */
211 case 0x04: info
->size
=2880>>2; break; /* dummy (HD Emulation) */
212 default: info
->size
=0; break;
214 newblkaddr
=le32_to_int(pide
->rel_block_addr
);
215 info
->start
=newblkaddr
;
216 PRINTF(" part %d found @ %lx size %lx\n",part_num
,newblkaddr
,info
->size
);
220 int get_partition_info_iso(struct blk_desc
*dev_desc
, int part_num
,
221 disk_partition_t
*info
)
223 return(get_partition_info_iso_verb(dev_desc
, part_num
, info
, 1));
227 void print_part_iso(struct blk_desc
*dev_desc
)
229 disk_partition_t info
;
231 if(get_partition_info_iso_verb(dev_desc
,0,&info
,0)==-1) {
232 printf("** No boot partition found on device %d **\n",dev_desc
->dev
);
235 printf("Part Start Sect x Size Type\n");
238 printf(" %2d " LBAFU
" " LBAFU
" %6ld %.32s\n",
239 i
, info
.start
, info
.size
, info
.blksz
, info
.type
);
241 } while (get_partition_info_iso_verb(dev_desc
,i
,&info
,0)!=-1);
244 int test_part_iso(struct blk_desc
*dev_desc
)
246 disk_partition_t info
;
248 return(get_partition_info_iso_verb(dev_desc
,0,&info
,0));