part.c (e35929e4a1ffe861f2f45e107986568c56c4f077) | part.c (96e5b03c8ab749b6547f6a3ceb4d4b9f274211aa) |
---|---|
1/* 2 * (C) Copyright 2001 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8#include <common.h> 9#include <command.h> | 1/* 2 * (C) Copyright 2001 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8#include <common.h> 9#include <command.h> |
10#include <errno.h> |
|
10#include <ide.h> 11#include <malloc.h> 12#include <part.h> 13#include <ubifs_uboot.h> 14 15#undef PART_DEBUG 16 17#ifdef PART_DEBUG --- 35 unchanged lines hidden (view full) --- 53 { .name = "host", .get_dev = host_get_dev, }, 54#endif 55 { }, 56}; 57 58DECLARE_GLOBAL_DATA_PTR; 59 60#ifdef HAVE_BLOCK_DEVICE | 11#include <ide.h> 12#include <malloc.h> 13#include <part.h> 14#include <ubifs_uboot.h> 15 16#undef PART_DEBUG 17 18#ifdef PART_DEBUG --- 35 unchanged lines hidden (view full) --- 54 { .name = "host", .get_dev = host_get_dev, }, 55#endif 56 { }, 57}; 58 59DECLARE_GLOBAL_DATA_PTR; 60 61#ifdef HAVE_BLOCK_DEVICE |
62static struct part_driver *part_driver_lookup_type(int part_type) 63{ 64 struct part_driver *drv = 65 ll_entry_start(struct part_driver, part_driver); 66 const int n_ents = ll_entry_count(struct part_driver, part_driver); 67 struct part_driver *entry; 68 69 for (entry = drv; entry != drv + n_ents; entry++) { 70 if (part_type == entry->part_type) 71 return entry; 72 } 73 74 /* Not found */ 75 return NULL; 76} 77 |
|
61static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) 62{ 63 const struct block_drvr *drvr = block_drvr; 64 struct blk_desc* (*reloc_get_dev)(int dev); 65 int (*select_hwpart)(int dev_num, int hwpart); 66 char *name; 67 int ret; 68 --- 178 unchanged lines hidden (view full) --- 247 } 248} 249#endif 250 251#ifdef HAVE_BLOCK_DEVICE 252 253void init_part(struct blk_desc *dev_desc) 254{ | 78static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) 79{ 80 const struct block_drvr *drvr = block_drvr; 81 struct blk_desc* (*reloc_get_dev)(int dev); 82 int (*select_hwpart)(int dev_num, int hwpart); 83 char *name; 84 int ret; 85 --- 178 unchanged lines hidden (view full) --- 264 } 265} 266#endif 267 268#ifdef HAVE_BLOCK_DEVICE 269 270void init_part(struct blk_desc *dev_desc) 271{ |
255#ifdef CONFIG_ISO_PARTITION 256 if (test_part_iso(dev_desc) == 0) { 257 dev_desc->part_type = PART_TYPE_ISO; 258 return; 259 } 260#endif | 272 struct part_driver *drv = 273 ll_entry_start(struct part_driver, part_driver); 274 const int n_ents = ll_entry_count(struct part_driver, part_driver); 275 struct part_driver *entry; |
261 | 276 |
262#ifdef CONFIG_MAC_PARTITION 263 if (test_part_mac(dev_desc) == 0) { 264 dev_desc->part_type = PART_TYPE_MAC; 265 return; 266 } 267#endif | 277 dev_desc->part_type = PART_TYPE_UNKNOWN; 278 for (entry = drv; entry != drv + n_ents; entry++) { 279 int ret; |
268 | 280 |
269/* must be placed before DOS partition detection */ 270#ifdef CONFIG_EFI_PARTITION 271 if (test_part_efi(dev_desc) == 0) { 272 dev_desc->part_type = PART_TYPE_EFI; 273 return; | 281 ret = entry->test(dev_desc); 282 debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret); 283 if (!ret) { 284 dev_desc->part_type = entry->part_type; 285 break; 286 } |
274 } | 287 } |
275#endif 276 277#ifdef CONFIG_DOS_PARTITION 278 if (test_part_dos(dev_desc) == 0) { 279 dev_desc->part_type = PART_TYPE_DOS; 280 return; 281 } 282#endif 283 284#ifdef CONFIG_AMIGA_PARTITION 285 if (test_part_amiga(dev_desc) == 0) { 286 dev_desc->part_type = PART_TYPE_AMIGA; 287 return; 288 } 289#endif 290 dev_desc->part_type = PART_TYPE_UNKNOWN; | |
291} 292 | 288} 289 |
293 | 290static void print_part_header(const char *type, struct blk_desc *dev_desc) 291{ |
294#if defined(CONFIG_MAC_PARTITION) || \ 295 defined(CONFIG_DOS_PARTITION) || \ 296 defined(CONFIG_ISO_PARTITION) || \ 297 defined(CONFIG_AMIGA_PARTITION) || \ 298 defined(CONFIG_EFI_PARTITION) | 292#if defined(CONFIG_MAC_PARTITION) || \ 293 defined(CONFIG_DOS_PARTITION) || \ 294 defined(CONFIG_ISO_PARTITION) || \ 295 defined(CONFIG_AMIGA_PARTITION) || \ 296 defined(CONFIG_EFI_PARTITION) |
299 300static void print_part_header(const char *type, struct blk_desc *dev_desc) 301{ | |
302 puts ("\nPartition Map for "); 303 switch (dev_desc->if_type) { 304 case IF_TYPE_IDE: 305 puts ("IDE"); 306 break; 307 case IF_TYPE_SATA: 308 puts ("SATA"); 309 break; --- 16 unchanged lines hidden (view full) --- 326 puts("HOST"); 327 break; 328 default: 329 puts ("UNKNOWN"); 330 break; 331 } 332 printf (" device %d -- Partition Type: %s\n\n", 333 dev_desc->dev, type); | 297 puts ("\nPartition Map for "); 298 switch (dev_desc->if_type) { 299 case IF_TYPE_IDE: 300 puts ("IDE"); 301 break; 302 case IF_TYPE_SATA: 303 puts ("SATA"); 304 break; --- 16 unchanged lines hidden (view full) --- 321 puts("HOST"); 322 break; 323 default: 324 puts ("UNKNOWN"); 325 break; 326 } 327 printf (" device %d -- Partition Type: %s\n\n", 328 dev_desc->dev, type); |
329#endif /* any CONFIG_..._PARTITION */ |
|
334} 335 | 330} 331 |
336#endif /* any CONFIG_..._PARTITION */ 337 | |
338void print_part(struct blk_desc *dev_desc) 339{ | 332void print_part(struct blk_desc *dev_desc) 333{ |
334 struct part_driver *drv; |
|
340 | 335 |
341 switch (dev_desc->part_type) { 342#ifdef CONFIG_MAC_PARTITION 343 case PART_TYPE_MAC: 344 PRINTF ("## Testing for valid MAC partition ##\n"); 345 print_part_header ("MAC", dev_desc); 346 print_part_mac (dev_desc); | 336 drv = part_driver_lookup_type(dev_desc->part_type); 337 if (!drv) { 338 printf("## Unknown partition table type %x\n", 339 dev_desc->part_type); |
347 return; | 340 return; |
348#endif 349#ifdef CONFIG_DOS_PARTITION 350 case PART_TYPE_DOS: 351 PRINTF ("## Testing for valid DOS partition ##\n"); 352 print_part_header ("DOS", dev_desc); 353 print_part_dos (dev_desc); 354 return; 355#endif 356 357#ifdef CONFIG_ISO_PARTITION 358 case PART_TYPE_ISO: 359 PRINTF ("## Testing for valid ISO Boot partition ##\n"); 360 print_part_header ("ISO", dev_desc); 361 print_part_iso (dev_desc); 362 return; 363#endif 364 365#ifdef CONFIG_AMIGA_PARTITION 366 case PART_TYPE_AMIGA: 367 PRINTF ("## Testing for a valid Amiga partition ##\n"); 368 print_part_header ("AMIGA", dev_desc); 369 print_part_amiga (dev_desc); 370 return; 371#endif 372 373#ifdef CONFIG_EFI_PARTITION 374 case PART_TYPE_EFI: 375 PRINTF ("## Testing for valid EFI partition ##\n"); 376 print_part_header ("EFI", dev_desc); 377 print_part_efi (dev_desc); 378 return; 379#endif | |
380 } | 341 } |
381 puts ("## Unknown partition table\n"); | 342 343 PRINTF("## Testing for valid %s partition ##\n", drv->name); 344 print_part_header(drv->name, dev_desc); 345 if (drv->print) 346 drv->print(dev_desc); |
382} 383 384#endif /* HAVE_BLOCK_DEVICE */ 385 386int get_partition_info(struct blk_desc *dev_desc, int part, 387 disk_partition_t *info) 388{ 389#ifdef HAVE_BLOCK_DEVICE | 347} 348 349#endif /* HAVE_BLOCK_DEVICE */ 350 351int get_partition_info(struct blk_desc *dev_desc, int part, 352 disk_partition_t *info) 353{ 354#ifdef HAVE_BLOCK_DEVICE |
355 struct part_driver *drv; |
|
390 391#ifdef CONFIG_PARTITION_UUIDS 392 /* The common case is no UUID support */ 393 info->uuid[0] = 0; 394#endif 395#ifdef CONFIG_PARTITION_TYPE_GUID 396 info->type_guid[0] = 0; 397#endif 398 | 356 357#ifdef CONFIG_PARTITION_UUIDS 358 /* The common case is no UUID support */ 359 info->uuid[0] = 0; 360#endif 361#ifdef CONFIG_PARTITION_TYPE_GUID 362 info->type_guid[0] = 0; 363#endif 364 |
399 switch (dev_desc->part_type) { 400#ifdef CONFIG_MAC_PARTITION 401 case PART_TYPE_MAC: 402 if (get_partition_info_mac(dev_desc, part, info) == 0) { 403 PRINTF("## Valid MAC partition found ##\n"); 404 return 0; 405 } 406 break; 407#endif 408 409#ifdef CONFIG_DOS_PARTITION 410 case PART_TYPE_DOS: 411 if (get_partition_info_dos(dev_desc, part, info) == 0) { 412 PRINTF("## Valid DOS partition found ##\n"); 413 return 0; 414 } 415 break; 416#endif 417 418#ifdef CONFIG_ISO_PARTITION 419 case PART_TYPE_ISO: 420 if (get_partition_info_iso(dev_desc, part, info) == 0) { 421 PRINTF("## Valid ISO boot partition found ##\n"); 422 return 0; 423 } 424 break; 425#endif 426 427#ifdef CONFIG_AMIGA_PARTITION 428 case PART_TYPE_AMIGA: 429 if (get_partition_info_amiga(dev_desc, part, info) == 0) { 430 PRINTF("## Valid Amiga partition found ##\n"); 431 return 0; 432 } 433 break; 434#endif 435 436#ifdef CONFIG_EFI_PARTITION 437 case PART_TYPE_EFI: 438 if (get_partition_info_efi(dev_desc, part, info) == 0) { 439 PRINTF("## Valid EFI partition found ##\n"); 440 return 0; 441 } 442 break; 443#endif 444 default: 445 break; | 365 drv = part_driver_lookup_type(dev_desc->part_type); 366 if (!drv) { 367 debug("## Unknown partition table type %x\n", 368 dev_desc->part_type); 369 return -EPROTONOSUPPORT; |
446 } | 370 } |
371 if (!drv->get_info) { 372 PRINTF("## Driver %s does not have the get_info() method\n"); 373 return -ENOSYS; 374 } 375 if (drv->get_info(dev_desc, part, info) == 0) { 376 PRINTF("## Valid %s partition found ##\n", drv->name); 377 return 0; 378 } |
|
447#endif /* HAVE_BLOCK_DEVICE */ 448 449 return -1; 450} 451 452int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, 453 struct blk_desc **dev_desc) 454{ --- 289 unchanged lines hidden --- | 379#endif /* HAVE_BLOCK_DEVICE */ 380 381 return -1; 382} 383 384int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, 385 struct blk_desc **dev_desc) 386{ --- 289 unchanged lines hidden --- |