]> Git Repo - u-boot.git/blame - disk/part_iso.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[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
e6f6f9e6 7#include <blk.h>
cc1c8a13 8#include <command.h>
e6f6f9e6 9#include <part.h>
90526e9f 10#include <asm/cache.h>
0919228c 11#include <asm/unaligned.h>
cc1c8a13
WD
12#include "part_iso.h"
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 */
06e293ed 48int part_get_info_iso_verb(struct blk_desc *desc, int part_num,
0528979f 49 struct disk_partition *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
06e293ed 60 if (desc->blksz != CD_SECTSIZE && 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;
06e293ed 65 if (iso_dread(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",
06e293ed 70 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",
06e293ed 76 ppr->stand_ident, 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);
06e293ed 85 if (iso_dread(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",
06e293ed 92 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",
06e293ed 100 pbr->ident_str, 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);
06e293ed 105 if (iso_dread(desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
cc1c8a13
WD
106 if(verb)
107 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
06e293ed 108 bootaddr, 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 117 printf("** Checksum Error in booting catalog validation entry on %d:%d **\n",
06e293ed 118 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",
06e293ed 124 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",
06e293ed 131 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");
06e293ed 139 part_set_generic_name(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",
06e293ed 161 part_num, 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",
06e293ed 169 part_num, desc->devnum);
cc1c8a13
WD
170 return(-1);
171found:
172 if(pide->boot_ind!=0x88) {
173 if(verb)
bcce53d0 174 printf("** Partition %d is not bootable on device %d **\n",
06e293ed 175 part_num, 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 190
06e293ed 191 if (desc->blksz == 512) {
a2adb173
AG
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
06e293ed 201static int part_get_info_iso(struct blk_desc *desc, int part_num,
0528979f 202 struct disk_partition *info)
cc1c8a13 203{
06e293ed 204 return part_get_info_iso_verb(desc, part_num, info, 0);
cc1c8a13
WD
205}
206
06e293ed 207static void part_print_iso(struct blk_desc *desc)
cc1c8a13 208{
0528979f 209 struct disk_partition info;
cc1c8a13 210 int i;
3e8bd469 211
06e293ed 212 if (part_get_info_iso_verb(desc, 1, &info, 0) == -1) {
bcce53d0 213 printf("** No boot partition found on device %d **\n",
06e293ed 214 desc->devnum);
cc1c8a13
WD
215 return;
216 }
217 printf("Part Start Sect x Size Type\n");
28f0014b 218 i=1;
cc1c8a13 219 do {
d9d88491 220 printf(" %2d %8" LBAFlength "u %8" LBAFlength "u %6ld %.32s\n",
04735e9c 221 i, info.start, info.size, info.blksz, info.type);
cc1c8a13 222 i++;
06e293ed 223 } while (part_get_info_iso_verb(desc, i, &info, 0) != -1);
cc1c8a13
WD
224}
225
06e293ed 226static int part_test_iso(struct blk_desc *desc)
cc1c8a13 227{
0528979f 228 struct disk_partition info;
cc1c8a13 229
06e293ed 230 return part_get_info_iso_verb(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};
This page took 0.417327 seconds and 4 git commands to generate.