]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/FatPei/Part.c
FatPkg: Add GPT check in FatPei to support Capsule-on-Disk feature.
[mirror_edk2.git] / FatPkg / FatPei / Part.c
1 /** @file
2 Routines supporting partition discovery and
3 logical device reading
4
5 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
6
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "FatLitePeim.h"
18
19 /**
20 This function finds Eltorito partitions. Main algorithm
21 is ported from DXE partition driver.
22
23 @param[in] PrivateData The global memory map
24 @param[in] ParentBlockDevNo The parent block device
25
26 @retval TRUE New partitions are detected and logical block devices
27 are added to block device array
28 @retval FALSE No new partitions are added
29
30 **/
31 BOOLEAN
32 FatFindEltoritoPartitions (
33 IN PEI_FAT_PRIVATE_DATA *PrivateData,
34 IN UINTN ParentBlockDevNo
35 );
36
37 /**
38 This function finds Mbr partitions. Main algorithm
39 is ported from DXE partition driver.
40
41 @param[in] PrivateData The global memory map
42 @param[in] ParentBlockDevNo The parent block device
43
44 @retval TRUE New partitions are detected and logical block devices
45 are added to block device array
46 @retval FALSE No new partitions are added
47
48 **/
49 BOOLEAN
50 FatFindMbrPartitions (
51 IN PEI_FAT_PRIVATE_DATA *PrivateData,
52 IN UINTN ParentBlockDevNo
53 );
54
55 /**
56 This function is used for finding GPT partition on block device.
57 As follow UEFI spec we should check protective MBR first and then
58 try to check both primary/backup GPT structures.
59
60 @param[in] PrivateData The global memory map
61 @param[in] ParentBlockDevNo The parent block device
62
63 @retval TRUE New partitions are detected and logical block devices
64 are added to block device array
65 @retval FALSE No new partitions are added
66
67 **/
68 BOOLEAN
69 FatFindGptPartitions (
70 IN PEI_FAT_PRIVATE_DATA *PrivateData,
71 IN UINTN ParentBlockDevNo
72 );
73
74 /**
75 This function finds partitions (logical devices) in physical block devices.
76
77 @param PrivateData Global memory map for accessing global variables.
78
79 **/
80 VOID
81 FatFindPartitions (
82 IN PEI_FAT_PRIVATE_DATA *PrivateData
83 )
84 {
85 BOOLEAN Found;
86 UINTN Index;
87
88 do {
89 Found = FALSE;
90
91 for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
92 if (!PrivateData->BlockDevice[Index].PartitionChecked) {
93 if (FatFindGptPartitions (PrivateData, Index)) {
94 Found = TRUE;
95 continue;
96 }
97
98 if (FatFindMbrPartitions (PrivateData, Index)) {
99 Found = TRUE;
100 continue;
101 }
102
103 if (FatFindEltoritoPartitions (PrivateData, Index)) {
104 Found = TRUE;
105 continue;
106 }
107 }
108 }
109 } while (Found && PrivateData->BlockDeviceCount <= PEI_FAT_MAX_BLOCK_DEVICE);
110 }