diff options
| author | kx <kx@radix.pro> | 2024-06-04 06:43:08 +0300 |
|---|---|---|
| committer | kx <kx@radix.pro> | 2024-06-04 06:43:08 +0300 |
| commit | 7e2ccccace24636f29ddc210b94606abd4c7e42b (patch) | |
| tree | 545d43ea12671048956cafeb12303e84d601e571 /UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass | |
| parent | 27b044605cd5f6b33a3d231576003850b3fe305b (diff) | |
| download | edk2-trunk.tar.xz | |
Renormalized end-of-lines from master@27b044605cd5f6b33a3d231576003850b3fe305btrunk
Diffstat (limited to 'UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass')
3 files changed, 176 insertions, 176 deletions
diff --git a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c index b9b2d23eb1..5fed5e7567 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c +++ b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c @@ -1,130 +1,130 @@ -/**
- Implement UnitTestBootLib using USB Class Boot option. This should be
- industry standard and should work on all platforms
-
- Copyright (c) Microsoft Corporation.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-**/
-
-#include <PiDxe.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiBootManagerLib.h>
-#include <Library/DevicePathLib.h>
-#include <Protocol/DevicePath.h>
-#include <Library/MemoryAllocationLib.h>
-
-/**
- Set the boot manager to boot from a specific device on the next boot. This
- should be set only for the next boot and shouldn't require any manual clean up
-
- @retval EFI_SUCCESS Boot device for next boot was set.
- @retval EFI_UNSUPPORTED Setting the boot device for the next boot is not
- supportted.
- @retval Other Boot device for next boot can not be set.
-**/
-EFI_STATUS
-EFIAPI
-SetBootNextDevice (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
- UINT32 Attributes;
- UINT8 *OptionalData;
- UINT32 OptionalDataSize;
- UINT16 BootNextValue;
- USB_CLASS_DEVICE_PATH UsbDp;
- EFI_DEVICE_PATH_PROTOCOL *DpEnd;
- EFI_DEVICE_PATH_PROTOCOL *Dp;
- BOOLEAN NewOptionValid;
-
- OptionalData = NULL;
- OptionalDataSize = 0;
- BootNextValue = 0xABCD; // this should be a safe number...
- DpEnd = NULL;
- Dp = NULL;
- NewOptionValid = FALSE;
-
- UsbDp.Header.Length[0] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) & 0xff);
- UsbDp.Header.Length[1] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) >> 8);
- UsbDp.Header.Type = MESSAGING_DEVICE_PATH;
- UsbDp.Header.SubType = MSG_USB_CLASS_DP;
- UsbDp.VendorId = 0xFFFF;
- UsbDp.ProductId = 0xFFFF;
- UsbDp.DeviceClass = 0xFF;
- UsbDp.DeviceSubClass = 0xFF;
- UsbDp.DeviceProtocol = 0xFF;
-
- Attributes = LOAD_OPTION_ACTIVE;
-
- DpEnd = AppendDevicePathNode (NULL, NULL);
- if (DpEnd == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. DpEnd is NULL.\n", __func__));
- Status = EFI_OUT_OF_RESOURCES;
- goto CLEANUP;
- }
-
- // @MRT --- Is this memory leak because we lose the old Dp memory
- Dp = AppendDevicePathNode (
- DpEnd,
- (EFI_DEVICE_PATH_PROTOCOL *)&UsbDp
- );
- if (Dp == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. Dp is NULL.\n", __func__));
- Status = EFI_OUT_OF_RESOURCES;
- goto CLEANUP;
- }
-
- Status = EfiBootManagerInitializeLoadOption (
- &NewOption,
- (UINTN)BootNextValue,
- LoadOptionTypeBoot,
- Attributes,
- L"Generic USB Class Device",
- Dp,
- OptionalData,
- OptionalDataSize
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: Error creating load option. Status = %r\n", __func__, Status));
- goto CLEANUP;
- }
-
- NewOptionValid = TRUE;
- DEBUG ((DEBUG_VERBOSE, "%a: Generic USB Class Device boot option created.\n", __func__));
- Status = EfiBootManagerLoadOptionToVariable (&NewOption);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: Error Saving boot option NV variable. Status = %r\n", __func__, Status));
- goto CLEANUP;
- }
-
- //
- // Set Boot Next
- //
- Status = gRT->SetVariable (
- L"BootNext",
- &gEfiGlobalVariableGuid,
- (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE),
- sizeof (BootNextValue),
- &(BootNextValue)
- );
-
- DEBUG ((DEBUG_VERBOSE, "%a - Set BootNext Status (%r)\n", __func__, Status));
-
-CLEANUP:
- if (Dp != NULL) {
- FreePool (Dp);
- }
-
- if (DpEnd != NULL) {
- FreePool (DpEnd);
- }
-
- if (NewOptionValid) {
- EfiBootManagerFreeLoadOption (&NewOption);
- }
-
- return Status;
-}
+/** + Implement UnitTestBootLib using USB Class Boot option. This should be + industry standard and should work on all platforms + + Copyright (c) Microsoft Corporation.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <PiDxe.h> +#include <Library/DebugLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiBootManagerLib.h> +#include <Library/DevicePathLib.h> +#include <Protocol/DevicePath.h> +#include <Library/MemoryAllocationLib.h> + +/** + Set the boot manager to boot from a specific device on the next boot. This + should be set only for the next boot and shouldn't require any manual clean up + + @retval EFI_SUCCESS Boot device for next boot was set. + @retval EFI_UNSUPPORTED Setting the boot device for the next boot is not + supportted. + @retval Other Boot device for next boot can not be set. +**/ +EFI_STATUS +EFIAPI +SetBootNextDevice ( + VOID + ) +{ + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; + UINT32 Attributes; + UINT8 *OptionalData; + UINT32 OptionalDataSize; + UINT16 BootNextValue; + USB_CLASS_DEVICE_PATH UsbDp; + EFI_DEVICE_PATH_PROTOCOL *DpEnd; + EFI_DEVICE_PATH_PROTOCOL *Dp; + BOOLEAN NewOptionValid; + + OptionalData = NULL; + OptionalDataSize = 0; + BootNextValue = 0xABCD; // this should be a safe number... + DpEnd = NULL; + Dp = NULL; + NewOptionValid = FALSE; + + UsbDp.Header.Length[0] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) & 0xff); + UsbDp.Header.Length[1] = (UINT8)(sizeof (USB_CLASS_DEVICE_PATH) >> 8); + UsbDp.Header.Type = MESSAGING_DEVICE_PATH; + UsbDp.Header.SubType = MSG_USB_CLASS_DP; + UsbDp.VendorId = 0xFFFF; + UsbDp.ProductId = 0xFFFF; + UsbDp.DeviceClass = 0xFF; + UsbDp.DeviceSubClass = 0xFF; + UsbDp.DeviceProtocol = 0xFF; + + Attributes = LOAD_OPTION_ACTIVE; + + DpEnd = AppendDevicePathNode (NULL, NULL); + if (DpEnd == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. DpEnd is NULL.\n", __func__)); + Status = EFI_OUT_OF_RESOURCES; + goto CLEANUP; + } + + // @MRT --- Is this memory leak because we lose the old Dp memory + Dp = AppendDevicePathNode ( + DpEnd, + (EFI_DEVICE_PATH_PROTOCOL *)&UsbDp + ); + if (Dp == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. Dp is NULL.\n", __func__)); + Status = EFI_OUT_OF_RESOURCES; + goto CLEANUP; + } + + Status = EfiBootManagerInitializeLoadOption ( + &NewOption, + (UINTN)BootNextValue, + LoadOptionTypeBoot, + Attributes, + L"Generic USB Class Device", + Dp, + OptionalData, + OptionalDataSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Error creating load option. Status = %r\n", __func__, Status)); + goto CLEANUP; + } + + NewOptionValid = TRUE; + DEBUG ((DEBUG_VERBOSE, "%a: Generic USB Class Device boot option created.\n", __func__)); + Status = EfiBootManagerLoadOptionToVariable (&NewOption); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Error Saving boot option NV variable. Status = %r\n", __func__, Status)); + goto CLEANUP; + } + + // + // Set Boot Next + // + Status = gRT->SetVariable ( + L"BootNext", + &gEfiGlobalVariableGuid, + (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE), + sizeof (BootNextValue), + &(BootNextValue) + ); + + DEBUG ((DEBUG_VERBOSE, "%a - Set BootNext Status (%r)\n", __func__, Status)); + +CLEANUP: + if (Dp != NULL) { + FreePool (Dp); + } + + if (DpEnd != NULL) { + FreePool (DpEnd); + } + + if (NewOptionValid) { + EfiBootManagerFreeLoadOption (&NewOption); + } + + return Status; +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf index 80c4e4f111..fe00f7ed12 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf +++ b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf @@ -1,34 +1,34 @@ -## @file
-# Library to support booting to USB on the next boot
-# This instance uses the industry standard usb class boot option.
-#
-# Copyright (c) Microsoft Corporation.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-##
-
-[Defines]
- INF_VERSION = 0x00010017
- BASE_NAME = UnitTestBootLibUsbClass
- MODULE_UNI_FILE = UnitTestBootLibUsbClass.uni
- FILE_GUID = DFADE2A2-DB69-47DE-A37A-40FB6D52E844
- VERSION_STRING = 1.0
- MODULE_TYPE = UEFI_APPLICATION
- LIBRARY_CLASS = UnitTestBootLib
-
-[Sources]
- UnitTestBootLibUsbClass.c
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
-
-[LibraryClasses]
- DebugLib
- UefiRuntimeServicesTableLib
- MemoryAllocationLib
- DevicePathLib
- UefiBootManagerLib
-
-[Guids]
- gEfiGlobalVariableGuid ## CONSUMES ## Used to probe boot options and set BootNext.
+## @file +# Library to support booting to USB on the next boot +# This instance uses the industry standard usb class boot option. +# +# Copyright (c) Microsoft Corporation.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = UnitTestBootLibUsbClass + MODULE_UNI_FILE = UnitTestBootLibUsbClass.uni + FILE_GUID = DFADE2A2-DB69-47DE-A37A-40FB6D52E844 + VERSION_STRING = 1.0 + MODULE_TYPE = UEFI_APPLICATION + LIBRARY_CLASS = UnitTestBootLib + +[Sources] + UnitTestBootLibUsbClass.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + DebugLib + UefiRuntimeServicesTableLib + MemoryAllocationLib + DevicePathLib + UefiBootManagerLib + +[Guids] + gEfiGlobalVariableGuid ## CONSUMES ## Used to probe boot options and set BootNext. diff --git a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni index 8468b3537c..056e37e067 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni +++ b/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni @@ -1,12 +1,12 @@ -// /** @file
-// Library to support booting to USB on the next boot
-// This instance uses the industry standard usb class boot option.
-//
-// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_MODULE_ABSTRACT #language en-US "Library to support booting to USB on the next boot"
-
-#string STR_MODULE_DESCRIPTION #language en-US "This instance uses the industry standard usb class boot option.."
+// /** @file +// Library to support booting to USB on the next boot +// This instance uses the industry standard usb class boot option. +// +// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Library to support booting to USB on the next boot" + +#string STR_MODULE_DESCRIPTION #language en-US "This instance uses the industry standard usb class boot option.." |
