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