TianoCore EDK2 master
Loading...
Searching...
No Matches
UnitTestBootLibUsbClass.c
1
9#include <PiDxe.h>
10#include <Library/DebugLib.h>
14#include <Protocol/DevicePath.h>
16
27EFIAPI
28SetBootNextDevice (
29 VOID
30 )
31{
32 EFI_STATUS Status;
34 UINT32 Attributes;
35 UINT8 *OptionalData;
36 UINT32 OptionalDataSize;
37 UINT16 BootNextValue;
41 BOOLEAN NewOptionValid;
42
43 OptionalData = NULL;
44 OptionalDataSize = 0;
45 BootNextValue = 0xABCD; // this should be a safe number...
46 DpEnd = NULL;
47 Dp = NULL;
48 NewOptionValid = FALSE;
49
50 UsbDp.Header.Length[0] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) & 0xff);
51 UsbDp.Header.Length[1] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) >> 8);
52 UsbDp.Header.Type = MESSAGING_DEVICE_PATH;
53 UsbDp.Header.SubType = MSG_USB_CLASS_DP;
54 UsbDp.VendorId = 0xFFFF;
55 UsbDp.ProductId = 0xFFFF;
56 UsbDp.DeviceClass = 0xFF;
57 UsbDp.DeviceSubClass = 0xFF;
58 UsbDp.DeviceProtocol = 0xFF;
59
60 Attributes = LOAD_OPTION_ACTIVE;
61
63 if (DpEnd == NULL) {
64 DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. DpEnd is NULL.\n", __func__));
65 Status = EFI_OUT_OF_RESOURCES;
66 goto CLEANUP;
67 }
68
69 // @MRT --- Is this memory leak because we lose the old Dp memory
71 DpEnd,
73 );
74 if (Dp == NULL) {
75 DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. Dp is NULL.\n", __func__));
76 Status = EFI_OUT_OF_RESOURCES;
77 goto CLEANUP;
78 }
79
81 &NewOption,
82 (UINTN)BootNextValue,
83 LoadOptionTypeBoot,
84 Attributes,
85 L"Generic USB Class Device",
86 Dp,
87 OptionalData,
88 OptionalDataSize
89 );
90 if (EFI_ERROR (Status)) {
91 DEBUG ((DEBUG_ERROR, "%a: Error creating load option. Status = %r\n", __func__, Status));
92 goto CLEANUP;
93 }
94
95 NewOptionValid = TRUE;
96 DEBUG ((DEBUG_VERBOSE, "%a: Generic USB Class Device boot option created.\n", __func__));
97 Status = EfiBootManagerLoadOptionToVariable (&NewOption);
98 if (EFI_ERROR (Status)) {
99 DEBUG ((DEBUG_ERROR, "%a: Error Saving boot option NV variable. Status = %r\n", __func__, Status));
100 goto CLEANUP;
101 }
102
103 //
104 // Set Boot Next
105 //
106 Status = gRT->SetVariable (
107 L"BootNext",
108 &gEfiGlobalVariableGuid,
109 (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE),
110 sizeof (BootNextValue),
111 &(BootNextValue)
112 );
113
114 DEBUG ((DEBUG_VERBOSE, "%a - Set BootNext Status (%r)\n", __func__, Status));
115
116CLEANUP:
117 if (Dp != NULL) {
118 FreePool (Dp);
119 }
120
121 if (DpEnd != NULL) {
122 FreePool (DpEnd);
123 }
124
125 if (NewOptionValid) {
126 EfiBootManagerFreeLoadOption (&NewOption);
127 }
128
129 return Status;
130}
UINT64 UINTN
#define MSG_USB_CLASS_DP
Definition: DevicePath.h:434
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI EfiBootManagerLoadOptionToVariable(IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
Definition: BmLoadOption.c:170
EFI_STATUS EFIAPI EfiBootManagerFreeLoadOption(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
EFI_STATUS EFIAPI EfiBootManagerInitializeLoadOption(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option, IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType, IN UINT32 Attributes, IN CHAR16 *Description, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN UINT8 *OptionalData, IN UINT32 OptionalDataSize)
#define EFI_VARIABLE_NON_VOLATILE