summaryrefslogtreecommitdiff
path: root/Core/EM/RestoreSpecialBootOptions/RestoreSpecialBootOptions.c
blob: c34848deb6e0573b712bdd639b8210841295fd67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2013, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/BIN/Modules/BootOptionPolicies/RestoreSpecialBootOptions/RestoreSpecialBootOptions.c 3     9/10/13 8:14a Dukeyeh $
//
// $Revision: 3 $
//
// $Date: 9/10/13 8:14a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/BootOptionPolicies/RestoreSpecialBootOptions/RestoreSpecialBootOptions.c $
// 
// 3     9/10/13 8:14a Dukeyeh
// [TAG]  		EIP135544 
// [Category]  	Bug Fix
// [RootCause]  	RestoreSpecialOrphanBootOptions don't compare multi ELINK
// names
// [Solution]  	Change to be able to compare multi ELINKs for target boot
// options
// [Files]  		RestoreSpecialBootOptions.sdl
// RestoreSpecialBootOptions.chm
// RestoreSpecialBootOptions.c
// 
// 2     7/12/13 12:40a Dukeyeh
// [TAG]  		EIP127111 
// [Category]  	New Feature
// [Description]  	1. Initial Release
//                                 2. This module restores some special
// boot options that have been applied orphan boot options policy on.
// [Files]  		RestoreSpecialBootOptions.c
// 
//**********************************************************************
//**********************************************************************
//<AMI_FHDR_START>
//
// Name:  RestoreSpecialBootOptions.c
//
// Description:	Restore some special boot options.
//
//<AMI_FHDR_END>
//**********************************************************************

#include <AmiDxeLib.h>
#include <RestoreSpecialBootOptions.h>
#include <BootOptions.h>

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   UnMaskFilePathList
//
// Description: Unmask the file path that was masked before.
//
// Input:       BOOT_OPTION *Option - the boot option's file path to be unmasked
//
// Output:      none
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID UnMaskFilePathList(BOOT_OPTION *Option) {
    VENDOR_DEVICE_PATH *MaskedDp;
    UINTN MaskedDpLength;

    MaskedDp = (VENDOR_DEVICE_PATH*)Option->FilePathList;
    MaskedDpLength = DPLength(&MaskedDp->Header);
    if (Option->FilePathListLength <= MaskedDpLength) return;
    Option->FilePathListLength -=MaskedDpLength;
    MemCpy(
        Option->FilePathList, (UINT8*)Option->FilePathList+MaskedDpLength,
        Option->FilePathListLength
    );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   RestoreBootOptionByPolicy
//
// Description: Restore the orphan boot option by policy.
//
// Input:       DLIST *BootOptionList - the master boot option list
//              BOOT_OPTION *Option - The orphaned boot option
//              UINTN Policy - the policy to follow, valid values are
//                  ORPHAN_BOOT_OPTIONS_POLICY_DELETE
//                  ORPHAN_BOOT_OPTIONS_POLICY_DISABLE
//                  ORPHAN_BOOT_OPTIONS_POLICY_KEEP
//
// Output:      none
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID RestoreBootOptionByPolicy(
    DLIST *BootOptionList, BOOT_OPTION *Option, const int Policy
) {
    /*if (Policy==ORPHAN_BOOT_OPTIONS_POLICY_DELETE){
     }else*/
    if (Policy==ORPHAN_BOOT_OPTIONS_POLICY_DISABLE) {
        Option->Attributes |= LOAD_OPTION_ACTIVE;
    } else if (Policy==ORPHAN_BOOT_OPTIONS_POLICY_HIDE) {
        Option->Attributes &= ~LOAD_OPTION_HIDDEN;
        UnMaskFilePathList(Option);
    }
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   RestoreSpecialOrphanBootOptions
//
// Description: This function restores the target orphan boot options that
//              have been applied policy on.
//
// Input:       none
//
// Output:      none
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID RestoreSpecialOrphanBootOptions() {
    DLINK *Link;
    BOOT_OPTION *Option;
    CHAR16 *RestoreBootOptionsByName[] = {RESTORED_BOOT_OPTION_NAMES NULL};
    UINT8 RegisteredBootOptionNames = sizeof(RestoreBootOptionsByName)/sizeof(CHAR16*) - 1; // minus NULL
    UINT8 NameIndex;

    if (0 == RegisteredBootOptionNames)
        return;

    FOR_EACH_BOOT_OPTION(BootOptionList,Link,Option) {

        if (RegisteredBootOptionNames) {

            for (NameIndex = 0; NULL != RestoreBootOptionsByName[NameIndex]; NameIndex++) {

                if (!Wcscmp(Option->Description, RestoreBootOptionsByName[NameIndex])) {

                    if (Option->FwBootOption) {
                        RestoreBootOptionByPolicy(
                            BootOptionList, Option, FW_ORPHAN_BOOT_OPTIONS_POLICY
                        );
                    }
                    else {
                        RestoreBootOptionByPolicy(
                            BootOptionList, Option, NON_FW_ORPHAN_BOOT_OPTIONS_POLICY
                        );
                    }

                    --RegisteredBootOptionNames;
                    if (0 == RegisteredBootOptionNames)
                        return;

                    break;
                }
            }
        }
    }
}

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2013, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************