From nobody Mon Feb 9 18:19:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111075+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111075+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1699660752; cv=none; d=zohomail.com; s=zohoarc; b=YQVJ9Bh7XDkdgVV5s4StuZJnGprdKuR0labWOYuzXgaceZi7Y6FHUQ8BImP2+JXvQ0+x9agK8fwmkqD1eSb06amnUMynXROmdZZ1Wk3OZVW7+QXfTPW/c44jwxYfi45YobDonFthOu55U2SKgqTrLkds77Q6Z0sqAWhLmv4O0VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699660752; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=cBMhCw+uuKSxBVRtf4P+qdIAzIU+MUXzg3YHdMAo2/w=; b=WTkU+t69Q9HXyhQYnG3OYXns7+9ycP4REFQVx5od6xDRvZ0Bsl6FIPd/XX13CwaRD8vdKvqxUBy9c0tkobbyfXEPCpR/e/OVMRrAwspM6q/C92XuAsQvnKL0Ye9UNg4shcakmSoKJ0o8FwTv0ztS1vk264tms5Y8KNAyQfVpQIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111075+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1699660752475467.843320689386; Fri, 10 Nov 2023 15:59:12 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=cBMhCw+uuKSxBVRtf4P+qdIAzIU+MUXzg3YHdMAo2/w=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1699660752; v=1; b=jOZirE66NpWTD4433pDuZJqIXVMIZo5tKsSgDLMdYkOvkJ6kLrR+HhO7uF1r5edxEbXFVtIo CGShZpvICjkRpokFnm2n3W9/ncuYp7kSID2m0541SSC1cIYLZwFpmSeITWOxDyRlNjsXhnsAvFh bMmo0uRbSQmrD98Y7mCfJo78= X-Received: by 127.0.0.2 with SMTP id l7DJYY1788612xyLdpxJNVY7; Fri, 10 Nov 2023 15:59:12 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.42818.1699660751331225384 for ; Fri, 10 Nov 2023 15:59:11 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-Wyh2dqDaOLiln6syNkALcw-1; Fri, 10 Nov 2023 18:59:06 -0500 X-MC-Unique: Wyh2dqDaOLiln6syNkALcw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90364811E7B; Fri, 10 Nov 2023 23:59:06 +0000 (UTC) X-Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7422BC1596F; Fri, 10 Nov 2023 23:59:05 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Jiewen Yao Subject: [edk2-devel] [PATCH 04/37] OvmfPkg: remove LegacyBootManagerLib Date: Sat, 11 Nov 2023 00:57:47 +0100 Message-Id: <20231110235820.644381-5-lersek@redhat.com> In-Reply-To: <20231110235820.644381-1-lersek@redhat.com> References: <20231110235820.644381-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: AXrnrBsHbmcUq6EopRBpz5Bvx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1699660753595100009 Content-Type: text/plain; charset="utf-8"; x-default="true" LegacyBootManagerLib is not used by any platform at this point, remove it. This patch removes mentions of the following CSM resources from the source code: - GUIDs (protocols or otherwise): - gEfiLegacyBiosProtocolGuid - gEfiLegacyDevOrderVariableGuid - headers: - Guid/LegacyDevOrder.h - Protocol/LegacyBios.h which extends the list of resources scheduled for removal to: - GUIDs (protocols or otherwise): - gEfiLegacyBiosProtocolGuid - gEfiLegacyDevOrderVariableGuid - headers: - Guid/LegacyDevOrder.h - Protocol/LegacyBios.h Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jiewen Yao Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4588 Signed-off-by: Laszlo Ersek --- OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.uni | 20 - OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.inf | 57 - OvmfPkg/Csm/LegacyBootManagerLib/InternalLegacyBm.h | 60 - OvmfPkg/Csm/LegacyBootManagerLib/LegacyBm.c | 1573 ---------= ----------- 4 files changed, 1710 deletions(-) diff --git a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.uni b/Ov= mfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.uni deleted file mode 100644 index da2915a9a391..000000000000 --- a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.uni +++ /dev/null @@ -1,20 +0,0 @@ -// /** @file -// Legacy Boot Manager module is library for BDS phase. -// -// Legacy Boot Manager module is library for BDS phase. -// -// Copyright (c) 2015, Intel Corporation. All rights reserved.
-// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// -// **/ - -#string STR_MODULE_ABSTRACT -#language en-US -"Legacy Boot Manager module is library for BDS phase." - -#string STR_MODULE_DESCRIPTION -#language en-US -"Legacy Boot Manager module is library for BDS phase." - - diff --git a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.inf b/Ov= mfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.inf deleted file mode 100644 index e43351cf959f..000000000000 --- a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBootManagerLib.inf +++ /dev/null @@ -1,57 +0,0 @@ -## @file -# Legacy Boot Manager module is library for BDS phase. -# -# Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION =3D 0x00010005 - BASE_NAME =3D LegacyBootManagerLib - MODULE_UNI_FILE =3D LegacyBootManagerLib.uni - FILE_GUID =3D D1BBB810-6A9E-40E0-87CB-65EAD2AA2A09 - MODULE_TYPE =3D DXE_DRIVER - VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D NULL|DXE_DRIVER UEFI_APPLICATION - CONSTRUCTOR =3D LegacyBootManagerLibConstructor - -# -# The following information is for reference only and not required by the = build tools. -# -# VALID_ARCHITECTURES =3D IA32 X64 EBC -# - -[Sources] - LegacyBm.c - InternalLegacyBm.h - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - OvmfPkg/OvmfPkg.dec - -[LibraryClasses] - BaseLib - BaseMemoryLib - UefiBootServicesTableLib - UefiRuntimeServicesTableLib - DevicePathLib - MemoryAllocationLib - UefiLib - DebugLib - PrintLib - PerformanceLib - UefiBootManagerLib - -[Guids] - gEfiGlobalVariableGuid ## SOMETIMES_PRODUCES ## V= ariable:L"Boot####" (Boot option variable) - ## SOMETIMES_CONSUMES ## V= ariable:L"BootOrder" (The boot option array) - gEfiLegacyDevOrderVariableGuid - -[Protocols] - gEfiLegacyBiosProtocolGuid ## SOMETIMES_CONSUMES - -[FeaturePcd] - -[Pcd] diff --git a/OvmfPkg/Csm/LegacyBootManagerLib/InternalLegacyBm.h b/OvmfPkg/= Csm/LegacyBootManagerLib/InternalLegacyBm.h deleted file mode 100644 index 8dd8b884d375..000000000000 --- a/OvmfPkg/Csm/LegacyBootManagerLib/InternalLegacyBm.h +++ /dev/null @@ -1,60 +0,0 @@ -/** @file - -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef _INTERNAL_LEGACY_BM_H_ -#define _INTERNAL_LEGACY_BM_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#pragma pack(1) -typedef struct { - UINT16 BbsIndex; -} LEGACY_BM_BOOT_OPTION_BBS_DATA; -#pragma pack() - -/** - Boot the legacy system with the boot option. - - @param BootOption The legacy boot option which have BBS device path - On return, BootOption->Status contains the boot statu= s. - EFI_UNSUPPORTED There is no legacybios protocol, d= o not support - legacy boot. - EFI_STATUS The status of LegacyBios->LegacyBo= ot (). -**/ -VOID -EFIAPI -LegacyBmBoot ( - IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption - ); - -/** - Refresh all legacy boot options. - -**/ -VOID -EFIAPI -LegacyBmRefreshAllBootOption ( - VOID - ); - -#endif // _INTERNAL_LEGACY_BM_H_ diff --git a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBm.c b/OvmfPkg/Csm/Lega= cyBootManagerLib/LegacyBm.c deleted file mode 100644 index 2e92bce726a9..000000000000 --- a/OvmfPkg/Csm/LegacyBootManagerLib/LegacyBm.c +++ /dev/null @@ -1,1573 +0,0 @@ -/** @file - This function deal with the legacy boot option, it create, delete - and manage the legacy boot option, all legacy boot option is getting from - the legacy BBS table. - -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include "InternalLegacyBm.h" - -#define LEGACY_BM_BOOT_DESCRIPTION_LENGTH 32 - -/** - Initialize legacy boot manager library by call EfiBootManagerRegisterLeg= acyBootSupport - function to export two function pointer. - - @param ImageHandle The image handle. - @param SystemTable The system table. - - @retval EFI_SUCCESS The legacy boot manager library is initialized co= rrectly. - @return Other value if failed to initialize the legacy boot manager libr= ary. -**/ -EFI_STATUS -EFIAPI -LegacyBootManagerLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EfiBootManagerRegisterLegacyBootSupport ( - LegacyBmRefreshAllBootOption, - LegacyBmBoot - ); - return EFI_SUCCESS; -} - -/** - Get the device type from the input legacy device path. - - @param DevicePath The legacy device path. - - @retval The legacy device type. -**/ -UINT16 -LegacyBmDeviceType ( - EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - ASSERT ( - (DevicePathType (DevicePath) =3D=3D BBS_DEVICE_PATH) && - (DevicePathSubType (DevicePath) =3D=3D BBS_BBS_DP) - ); - return ((BBS_BBS_DEVICE_PATH *)DevicePath)->DeviceType; -} - -/** - Validate the BbsEntry base on the Boot Priority info in the BbsEntry. - - @param BbsEntry The input bbs entry info. - - @retval TRUE The BbsEntry is valid. - @retval FALSE The BbsEntry is invalid. -**/ -BOOLEAN -LegacyBmValidBbsEntry ( - IN BBS_TABLE *BbsEntry - ) -{ - switch (BbsEntry->BootPriority) { - case BBS_IGNORE_ENTRY: - case BBS_DO_NOT_BOOT_FROM: - case BBS_LOWEST_PRIORITY: - return FALSE; - default: - return TRUE; - } -} - -/** - Build Legacy Device Name String according. - - @param CurBBSEntry BBS Table. - @param Index Index. - @param BufSize The buffer size. - @param BootString The output string. - -**/ -VOID -LegacyBmBuildLegacyDevNameString ( - IN BBS_TABLE *CurBBSEntry, - IN UINTN Index, - IN UINTN BufSize, - OUT CHAR16 *BootString - ) -{ - CHAR16 *Fmt; - CHAR16 *Type; - CHAR8 *StringDesc; - CHAR8 StringBufferA[LEGACY_BM_BOOT_DESCRIPTION_LENGTH + 1]; - CHAR16 StringBufferU[LEGACY_BM_BOOT_DESCRIPTION_LENGTH + 1]; - - switch (Index) { - // - // Primary Master - // - case 1: - Fmt =3D L"Primary Master %s"; - break; - - // - // Primary Slave - // - case 2: - Fmt =3D L"Primary Slave %s"; - break; - - // - // Secondary Master - // - case 3: - Fmt =3D L"Secondary Master %s"; - break; - - // - // Secondary Slave - // - case 4: - Fmt =3D L"Secondary Slave %s"; - break; - - default: - Fmt =3D L"%s"; - break; - } - - switch (CurBBSEntry->DeviceType) { - case BBS_FLOPPY: - Type =3D L"Floppy"; - break; - - case BBS_HARDDISK: - Type =3D L"Harddisk"; - break; - - case BBS_CDROM: - Type =3D L"CDROM"; - break; - - case BBS_PCMCIA: - Type =3D L"PCMCIAe"; - break; - - case BBS_USB: - Type =3D L"USB"; - break; - - case BBS_EMBED_NETWORK: - Type =3D L"Network"; - break; - - case BBS_BEV_DEVICE: - Type =3D L"BEVe"; - break; - - case BBS_UNKNOWN: - default: - Type =3D L"Unknown"; - break; - } - - // - // If current BBS entry has its description then use it. - // - StringDesc =3D (CHAR8 *)(((UINTN)CurBBSEntry->DescStringSegment << 4) + = CurBBSEntry->DescStringOffset); - if (NULL !=3D StringDesc) { - // - // Only get first 32 characters, this is suggested by BBS spec - // - CopyMem (StringBufferA, StringDesc, LEGACY_BM_BOOT_DESCRIPTION_LENGTH); - StringBufferA[LEGACY_BM_BOOT_DESCRIPTION_LENGTH] =3D 0; - AsciiStrToUnicodeStrS (StringBufferA, StringBufferU, ARRAY_SIZE (Strin= gBufferU)); - Fmt =3D L"%s"; - Type =3D StringBufferU; - } - - // - // BbsTable 16 entries are for onboard IDE. - // Set description string for SATA harddisks, Harddisk 0 ~ Harddisk 11 - // - if ((Index >=3D 5) && (Index <=3D 16) && ((CurBBSEntry->DeviceType =3D= =3D BBS_HARDDISK) || (CurBBSEntry->DeviceType =3D=3D BBS_CDROM))) { - Fmt =3D L"%s %d"; - UnicodeSPrint (BootString, BufSize, Fmt, Type, Index - 5); - } else { - UnicodeSPrint (BootString, BufSize, Fmt, Type); - } -} - -/** - Get the Bbs index for the input boot option. - - @param BootOption The input boot option info. - @param BbsTable The input Bbs table. - @param BbsCount The input total bbs entry number. - @param BbsIndexUsed The array shows how many BBS table indexs have bee= n used. - - @retval The index for the input boot option. -**/ -UINT16 -LegacyBmFuzzyMatch ( - EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, - BBS_TABLE *BbsTable, - UINT16 BbsCount, - BOOLEAN *BbsIndexUsed - ) -{ - UINT16 Index; - LEGACY_BM_BOOT_OPTION_BBS_DATA *BbsData; - CHAR16 Description[LEGACY_BM_BOOT_DESCRIPTION_L= ENGTH + 1]; - - BbsData =3D (LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption->OptionalData; - - // - // Directly check the BBS index stored in BootOption - // - if ((BbsData->BbsIndex < BbsCount) && - (LegacyBmDeviceType (BootOption->FilePath) =3D=3D BbsTable[BbsData->= BbsIndex].DeviceType)) - { - LegacyBmBuildLegacyDevNameString ( - &BbsTable[BbsData->BbsIndex], - BbsData->BbsIndex, - sizeof (Description), - Description - ); - if ((StrCmp (Description, BootOption->Description) =3D=3D 0) && !BbsIn= dexUsed[BbsData->BbsIndex]) { - // - // If devices with the same description string are connected, - // the BbsIndex of the first device is returned for the other device= also. - // So, check if the BbsIndex is already being used, before assigning= the BbsIndex. - // - BbsIndexUsed[BbsData->BbsIndex] =3D TRUE; - return BbsData->BbsIndex; - } - } - - // - // BBS table could be changed (entry removed/moved) - // find the correct BBS index - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&BbsTable[Index]) || - (BbsTable[Index].DeviceType !=3D LegacyBmDeviceType (BootOption->F= ilePath))) - { - continue; - } - - LegacyBmBuildLegacyDevNameString ( - &BbsTable[Index], - Index, - sizeof (Description), - Description - ); - if ((StrCmp (Description, BootOption->Description) =3D=3D 0) && !BbsIn= dexUsed[Index]) { - // - // If devices with the same description string are connected, - // the BbsIndex of the first device is assigned for the other device= also. - // So, check if the BbsIndex is already being used, before assigning= the corrected BbsIndex. - // - break; - } - } - - // - // Add the corrected BbsIndex in the UsedBbsIndex Buffer - // - if (Index !=3D BbsCount) { - BbsIndexUsed[Index] =3D TRUE; - } - - return Index; -} - -/** - - Update legacy device order base on the input info. - - @param LegacyDevOrder Legacy device order data buffer. - @param LegacyDevOrderSize Legacy device order data buffer size. - @param DeviceType Device type which need to check. - @param OldBbsIndex Old Bds Index. - @param NewBbsIndex New Bds Index, if it is -1,means remove this= option. - -**/ -VOID -LegacyBmUpdateBbsIndex ( - LEGACY_DEV_ORDER_ENTRY *LegacyDevOrder, - UINTN *LegacyDevOrderSize, - UINT16 DeviceType, - UINT16 OldBbsIndex, - UINT16 NewBbsIndex // Delete entry if -1 - ) -{ - LEGACY_DEV_ORDER_ENTRY *Entry; - UINTN Index; - - ASSERT ( - ((LegacyDevOrder =3D=3D NULL) && (*LegacyDevOrderSize =3D=3D 0)) || - ((LegacyDevOrder !=3D NULL) && (*LegacyDevOrderSize !=3D 0)) - ); - - for (Entry =3D LegacyDevOrder; - Entry < (LEGACY_DEV_ORDER_ENTRY *)((UINT8 *)LegacyDevOrder + *Legac= yDevOrderSize); - Entry =3D (LEGACY_DEV_ORDER_ENTRY *)((UINTN)Entry + sizeof (BBS_TYP= E) + Entry->Length) - ) - { - if (Entry->BbsType =3D=3D DeviceType) { - for (Index =3D 0; Index < Entry->Length / sizeof (UINT16) - 1; Index= ++) { - if (Entry->Data[Index] =3D=3D OldBbsIndex) { - if (NewBbsIndex =3D=3D (UINT16)-1) { - // - // Delete the old entry - // - CopyMem ( - &Entry->Data[Index], - &Entry->Data[Index + 1], - (UINT8 *)LegacyDevOrder + *LegacyDevOrderSize - (UINT8 *)&En= try->Data[Index + 1] - ); - Entry->Length -=3D sizeof (UINT16); - *LegacyDevOrderSize -=3D sizeof (UINT16); - } else { - Entry->Data[Index] =3D NewBbsIndex; - } - - break; - } - } - - break; - } - } -} - -/** - Delete all the legacy boot options. - - @retval EFI_SUCCESS All legacy boot options are deleted. -**/ -EFI_STATUS -LegacyBmDeleteAllBootOptions ( - VOID - ) -{ - EFI_STATUS Status; - UINTN Index; - EFI_BOOT_MANAGER_LOAD_OPTION *BootOption; - UINTN BootOptionCount; - - BootOption =3D EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptio= nTypeBoot); - for (Index =3D 0; Index < BootOptionCount; Index++) { - if ((DevicePathType (BootOption[Index].FilePath) =3D=3D BBS_DEVICE_PAT= H) && - (DevicePathSubType (BootOption[Index].FilePath) =3D=3D BBS_BBS_DP)) - { - Status =3D EfiBootManagerDeleteLoadOptionVariable (BootOption[Index]= .OptionNumber, BootOption[Index].OptionType); - // - // Deleting variable with current variable implementation shouldn't = fail. - // - ASSERT_EFI_ERROR (Status); - } - } - - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - 0, - 0, - NULL - ); - // - // Deleting variable with current variable implementation shouldn't fail. - // - ASSERT (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_NOT_FOUND); - - return EFI_SUCCESS; -} - -/** - Delete all the invalid legacy boot options. - - @retval EFI_SUCCESS All invalid legacy boot options are dele= ted. - @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory. - @retval EFI_NOT_FOUND Fail to retrieve variable of boot order. -**/ -EFI_STATUS -LegacyBmDeleteAllInvalidBootOptions ( - VOID - ) -{ - EFI_STATUS Status; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *HddInfo; - BBS_TABLE *BbsTable; - UINT16 BbsIndex; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN Index; - EFI_BOOT_MANAGER_LOAD_OPTION *BootOption; - UINTN BootOptionCount; - LEGACY_DEV_ORDER_ENTRY *LegacyDevOrder; - UINTN LegacyDevOrderSize; - BOOLEAN *BbsIndexUsed; - - HddCount =3D 0; - BbsCount =3D 0; - HddInfo =3D NULL; - BbsTable =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &HddInfo, - &BbsCount, - &BbsTable - ); - if (EFI_ERROR (Status)) { - return Status; - } - - GetVariable2 (VAR_LEGACY_DEV_ORDER, &gEfiLegacyDevOrderVariableGuid, (VO= ID **)&LegacyDevOrder, &LegacyDevOrderSize); - - BootOption =3D EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptio= nTypeBoot); - - BbsIndexUsed =3D AllocateZeroPool (BbsCount * sizeof (BOOLEAN)); - ASSERT (BbsIndexUsed !=3D NULL); - - for (Index =3D 0; Index < BootOptionCount; Index++) { - // - // Skip non legacy boot option - // - if ((DevicePathType (BootOption[Index].FilePath) !=3D BBS_DEVICE_PATH)= || - (DevicePathSubType (BootOption[Index].FilePath) !=3D BBS_BBS_DP)) - { - continue; - } - - BbsIndex =3D LegacyBmFuzzyMatch (&BootOption[Index], BbsTable, BbsCoun= t, BbsIndexUsed); - if (BbsIndex =3D=3D BbsCount) { - DEBUG ((DEBUG_INFO, "[LegacyBds] Delete Boot Option Boot%04x: %s\n",= (UINTN)BootOption[Index].OptionNumber, BootOption[Index].Description)); - // - // Delete entry from LegacyDevOrder - // - LegacyBmUpdateBbsIndex ( - LegacyDevOrder, - &LegacyDevOrderSize, - LegacyBmDeviceType (BootOption[Index].FilePath), - ((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption[Index].OptionalData)= ->BbsIndex, - (UINT16)-1 - ); - EfiBootManagerDeleteLoadOptionVariable (BootOption[Index].OptionNumb= er, BootOption[Index].OptionType); - } else { - if (((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption[Index].OptionalDat= a)->BbsIndex !=3D BbsIndex) { - DEBUG (( - DEBUG_INFO, - "[LegacyBds] Update Boot Option Boot%04x: %s Bbs0x%04x->Bbs0x%04= x\n", - (UINTN)BootOption[Index].OptionNumber, - BootOption[Index].Description, - (UINTN)((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption[Index].Opti= onalData)->BbsIndex, - (UINTN)BbsIndex - )); - // - // Update the BBS index in LegacyDevOrder - // - LegacyBmUpdateBbsIndex ( - LegacyDevOrder, - &LegacyDevOrderSize, - LegacyBmDeviceType (BootOption[Index].FilePath), - ((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption[Index].OptionalDat= a)->BbsIndex, - BbsIndex - ); - - // - // Update the OptionalData in the Boot#### variable - // - ((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption[Index].OptionalData)= ->BbsIndex =3D BbsIndex; - EfiBootManagerLoadOptionToVariable (&BootOption[Index]); - } - } - } - - EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount); - - if (LegacyDevOrder !=3D NULL) { - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOL= ATILE, - LegacyDevOrderSize, - LegacyDevOrder - ); - // - // Shrink variable with current variable implementation shouldn't fail. - // - ASSERT_EFI_ERROR (Status); - - FreePool (LegacyDevOrder); - } - - FreePool (BbsIndexUsed); - return Status; -} - -/** - Create legacy boot option. - - @param BootOption Pointer to the boot option which will be crated. - @param BbsEntry The input bbs entry info. - @param BbsIndex The BBS index. - - @retval EFI_SUCCESS Create legacy boot option successfully. - @retval EFI_INVALID_PARAMETER Invalid input parameter. - -**/ -EFI_STATUS -LegacyBmCreateLegacyBootOption ( - IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, - IN BBS_TABLE *BbsEntry, - IN UINT16 BbsIndex - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - CHAR16 Description[LEGACY_BM_BOOT_DESCRIPTION_L= ENGTH + 1]; - CHAR8 HelpString[LEGACY_BM_BOOT_DESCRIPTION_LE= NGTH + 1]; - UINTN StringLen; - LEGACY_BM_BOOT_OPTION_BBS_DATA *OptionalData; - BBS_BBS_DEVICE_PATH *BbsNode; - - if ((BootOption =3D=3D NULL) || (BbsEntry =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - LegacyBmBuildLegacyDevNameString (BbsEntry, BbsIndex, sizeof (Descriptio= n), Description); - - // - // Create the BBS device path with description string - // - UnicodeStrToAsciiStrS (Description, HelpString, sizeof (HelpString)); - StringLen =3D AsciiStrLen (HelpString); - DevicePath =3D AllocatePool (sizeof (BBS_BBS_DEVICE_PATH) + StringLen + = END_DEVICE_PATH_LENGTH); - ASSERT (DevicePath !=3D NULL); - - BbsNode =3D (BBS_BBS_DEVICE_PATH *)DevicePath; - SetDevicePathNodeLength (BbsNode, sizeof (BBS_BBS_DEVICE_PATH) + StringL= en); - BbsNode->Header.Type =3D BBS_DEVICE_PATH; - BbsNode->Header.SubType =3D BBS_BBS_DP; - BbsNode->DeviceType =3D BbsEntry->DeviceType; - CopyMem (&BbsNode->StatusFlag, &BbsEntry->StatusFlags, sizeof (BBS_STATU= S_FLAGS)); - CopyMem (BbsNode->String, HelpString, StringLen + 1); - - SetDevicePathEndNode (NextDevicePathNode (BbsNode)); - - // - // Create the OptionalData - // - OptionalData =3D AllocatePool (sizeof (LEGACY_BM_BOOT_OPTION_BBS_DATA)); - ASSERT (OptionalData !=3D NULL); - OptionalData->BbsIndex =3D BbsIndex; - - // - // Create the BootOption - // - Status =3D EfiBootManagerInitializeLoadOption ( - BootOption, - LoadOptionNumberUnassigned, - LoadOptionTypeBoot, - LOAD_OPTION_ACTIVE, - Description, - DevicePath, - (UINT8 *)OptionalData, - sizeof (LEGACY_BM_BOOT_OPTION_BBS_DATA) - ); - FreePool (DevicePath); - FreePool (OptionalData); - - return Status; -} - -/** - Fill the device order buffer. - - @param BbsTable The BBS table. - @param BbsType The BBS Type. - @param BbsCount The BBS Count. - @param Buf device order buffer. - - @return The device order buffer. - -**/ -UINT16 * -LegacyBmFillDevOrderBuf ( - IN BBS_TABLE *BbsTable, - IN BBS_TYPE BbsType, - IN UINTN BbsCount, - OUT UINT16 *Buf - ) -{ - UINTN Index; - - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&BbsTable[Index])) { - continue; - } - - if (BbsTable[Index].DeviceType !=3D BbsType) { - continue; - } - - *Buf =3D (UINT16)(Index & 0xFF); - Buf++; - } - - return Buf; -} - -/** - Create the device order buffer. - - @param BbsTable The BBS table. - @param BbsCount The BBS Count. - - @retval EFI_SUCCESS The buffer is created and the EFI variabl= e named - VAR_LEGACY_DEV_ORDER and EfiLegacyDevOrde= rGuid is - set correctly. - @retval EFI_OUT_OF_RESOURCES Memory or storage is not enough. - @retval EFI_DEVICE_ERROR Fail to add the device order into EFI var= iable fail - because of hardware error. -**/ -EFI_STATUS -LegacyBmCreateDevOrder ( - IN BBS_TABLE *BbsTable, - IN UINT16 BbsCount - ) -{ - UINTN Index; - UINTN FDCount; - UINTN HDCount; - UINTN CDCount; - UINTN NETCount; - UINTN BEVCount; - UINTN TotalSize; - UINTN HeaderSize; - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *DevOrderPtr; - EFI_STATUS Status; - - FDCount =3D 0; - HDCount =3D 0; - CDCount =3D 0; - NETCount =3D 0; - BEVCount =3D 0; - TotalSize =3D 0; - HeaderSize =3D sizeof (BBS_TYPE) + sizeof (UINT16); - DevOrder =3D NULL; - Status =3D EFI_SUCCESS; - - // - // Count all boot devices - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&BbsTable[Index])) { - continue; - } - - switch (BbsTable[Index].DeviceType) { - case BBS_FLOPPY: - FDCount++; - break; - - case BBS_HARDDISK: - HDCount++; - break; - - case BBS_CDROM: - CDCount++; - break; - - case BBS_EMBED_NETWORK: - NETCount++; - break; - - case BBS_BEV_DEVICE: - BEVCount++; - break; - - default: - break; - } - } - - TotalSize +=3D (HeaderSize + sizeof (UINT16) * FDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * HDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * CDCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * NETCount); - TotalSize +=3D (HeaderSize + sizeof (UINT16) * BEVCount); - - // - // Create buffer to hold all boot device order - // - DevOrder =3D AllocateZeroPool (TotalSize); - if (NULL =3D=3D DevOrder) { - return EFI_OUT_OF_RESOURCES; - } - - DevOrderPtr =3D DevOrder; - - DevOrderPtr->BbsType =3D BBS_FLOPPY; - DevOrderPtr->Length =3D (UINT16)(sizeof (DevOrderPtr->Length) + FDCount= * sizeof (UINT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)LegacyBmFillDevOrderB= uf (BbsTable, BBS_FLOPPY, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_HARDDISK; - DevOrderPtr->Length =3D (UINT16)(sizeof (UINT16) + HDCount * sizeof (UI= NT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)LegacyBmFillDevOrderB= uf (BbsTable, BBS_HARDDISK, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_CDROM; - DevOrderPtr->Length =3D (UINT16)(sizeof (UINT16) + CDCount * sizeof (UI= NT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)LegacyBmFillDevOrderB= uf (BbsTable, BBS_CDROM, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_EMBED_NETWORK; - DevOrderPtr->Length =3D (UINT16)(sizeof (UINT16) + NETCount * sizeof (U= INT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)LegacyBmFillDevOrderB= uf (BbsTable, BBS_EMBED_NETWORK, BbsCount, DevOrderPtr->Data); - - DevOrderPtr->BbsType =3D BBS_BEV_DEVICE; - DevOrderPtr->Length =3D (UINT16)(sizeof (UINT16) + BEVCount * sizeof (U= INT16)); - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)LegacyBmFillDevOrderB= uf (BbsTable, BBS_BEV_DEVICE, BbsCount, DevOrderPtr->Data); - - ASSERT (TotalSize =3D=3D ((UINTN)DevOrderPtr - (UINTN)DevOrder)); - - // - // Save device order for legacy boot device to variable. - // - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLAT= ILE, - TotalSize, - DevOrder - ); - FreePool (DevOrder); - - return Status; -} - -/** - Add the legacy boot devices from BBS table into - the legacy device boot order. - - @retval EFI_SUCCESS The boot devices are added successfully. - @retval EFI_NOT_FOUND The legacy boot devices are not found. - @retval EFI_OUT_OF_RESOURCES Memory or storage is not enough. - @retval EFI_DEVICE_ERROR Fail to add the legacy device boot order i= nto EFI variable - because of hardware error. -**/ -EFI_STATUS -LegacyBmUpdateDevOrder ( - VOID - ) -{ - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *NewDevOrder; - LEGACY_DEV_ORDER_ENTRY *Ptr; - LEGACY_DEV_ORDER_ENTRY *NewPtr; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_STATUS Status; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - UINTN Index; - UINTN Index2; - UINTN *Idx; - UINTN FDCount; - UINTN HDCount; - UINTN CDCount; - UINTN NETCount; - UINTN BEVCount; - UINTN TotalSize; - UINTN HeaderSize; - UINT16 *NewFDPtr; - UINT16 *NewHDPtr; - UINT16 *NewCDPtr; - UINT16 *NewNETPtr; - UINT16 *NewBEVPtr; - UINT16 *NewDevPtr; - UINTN FDIndex; - UINTN HDIndex; - UINTN CDIndex; - UINTN NETIndex; - UINTN BEVIndex; - - Idx =3D NULL; - FDCount =3D 0; - HDCount =3D 0; - CDCount =3D 0; - NETCount =3D 0; - BEVCount =3D 0; - TotalSize =3D 0; - HeaderSize =3D sizeof (BBS_TYPE) + sizeof (UINT16); - FDIndex =3D 0; - HDIndex =3D 0; - CDIndex =3D 0; - NETIndex =3D 0; - BEVIndex =3D 0; - NewDevPtr =3D NULL; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - if (EFI_ERROR (Status)) { - return Status; - } - - GetVariable2 (VAR_LEGACY_DEV_ORDER, &gEfiLegacyDevOrderVariableGuid, (VO= ID **)&DevOrder, NULL); - if (NULL =3D=3D DevOrder) { - return LegacyBmCreateDevOrder (LocalBbsTable, BbsCount); - } - - // - // First we figure out how many boot devices with same device type respe= ctively - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Index])) { - continue; - } - - switch (LocalBbsTable[Index].DeviceType) { - case BBS_FLOPPY: - FDCount++; - break; - - case BBS_HARDDISK: - HDCount++; - break; - - case BBS_CDROM: - CDCount++; - break; - - case BBS_EMBED_NETWORK: - NETCount++; - break; - - case BBS_BEV_DEVICE: - BEVCount++; - break; - - default: - break; - } - } - - TotalSize +=3D (HeaderSize + FDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + HDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + CDCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + NETCount * sizeof (UINT16)); - TotalSize +=3D (HeaderSize + BEVCount * sizeof (UINT16)); - - NewDevOrder =3D AllocateZeroPool (TotalSize); - if (NULL =3D=3D NewDevOrder) { - return EFI_OUT_OF_RESOURCES; - } - - // - // copy FD - // - Ptr =3D DevOrder; - NewPtr =3D NewDevOrder; - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16)(sizeof (UINT16) + FDCount * sizeof (UINT16)= ); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Ptr->Data[Index] & 0xFF]) || - (LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_FLOPPY) - ) - { - continue; - } - - NewPtr->Data[FDIndex] =3D Ptr->Data[Index]; - FDIndex++; - } - - NewFDPtr =3D NewPtr->Data; - - // - // copy HD - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *)(&Ptr->Data[Ptr->Length / = sizeof (UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *)(&NewPtr->Data[NewPtr->Len= gth / sizeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16)(sizeof (UINT16) + HDCount * sizeof (UINT16)= ); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Ptr->Data[Index] & 0xFF]) || - (LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_HARDDI= SK) - ) - { - continue; - } - - NewPtr->Data[HDIndex] =3D Ptr->Data[Index]; - HDIndex++; - } - - NewHDPtr =3D NewPtr->Data; - - // - // copy CD - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *)(&Ptr->Data[Ptr->Length / = sizeof (UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *)(&NewPtr->Data[NewPtr->Len= gth / sizeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16)(sizeof (UINT16) + CDCount * sizeof (UINT16)= ); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Ptr->Data[Index] & 0xFF]) || - (LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_CDROM) - ) - { - continue; - } - - NewPtr->Data[CDIndex] =3D Ptr->Data[Index]; - CDIndex++; - } - - NewCDPtr =3D NewPtr->Data; - - // - // copy NET - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *)(&Ptr->Data[Ptr->Length / = sizeof (UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *)(&NewPtr->Data[NewPtr->Len= gth / sizeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16)(sizeof (UINT16) + NETCount * sizeof (UINT16= )); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Ptr->Data[Index] & 0xFF]) || - (LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_EMBED_= NETWORK) - ) - { - continue; - } - - NewPtr->Data[NETIndex] =3D Ptr->Data[Index]; - NETIndex++; - } - - NewNETPtr =3D NewPtr->Data; - - // - // copy BEV - // - Ptr =3D (LEGACY_DEV_ORDER_ENTRY *)(&Ptr->Data[Ptr->Length / = sizeof (UINT16) - 1]); - NewPtr =3D (LEGACY_DEV_ORDER_ENTRY *)(&NewPtr->Data[NewPtr->Len= gth / sizeof (UINT16) -1]); - NewPtr->BbsType =3D Ptr->BbsType; - NewPtr->Length =3D (UINT16)(sizeof (UINT16) + BEVCount * sizeof (UINT16= )); - for (Index =3D 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Ptr->Data[Index] & 0xFF]) || - (LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType !=3D BBS_BEV_DE= VICE) - ) - { - continue; - } - - NewPtr->Data[BEVIndex] =3D Ptr->Data[Index]; - BEVIndex++; - } - - NewBEVPtr =3D NewPtr->Data; - - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Index])) { - continue; - } - - switch (LocalBbsTable[Index].DeviceType) { - case BBS_FLOPPY: - Idx =3D &FDIndex; - NewDevPtr =3D NewFDPtr; - break; - - case BBS_HARDDISK: - Idx =3D &HDIndex; - NewDevPtr =3D NewHDPtr; - break; - - case BBS_CDROM: - Idx =3D &CDIndex; - NewDevPtr =3D NewCDPtr; - break; - - case BBS_EMBED_NETWORK: - Idx =3D &NETIndex; - NewDevPtr =3D NewNETPtr; - break; - - case BBS_BEV_DEVICE: - Idx =3D &BEVIndex; - NewDevPtr =3D NewBEVPtr; - break; - - default: - Idx =3D NULL; - break; - } - - // - // at this point we have copied those valid indexes to new buffer - // and we should check if there is any new appeared boot device - // - if (Idx !=3D NULL) { - for (Index2 =3D 0; Index2 < *Idx; Index2++) { - if ((NewDevPtr[Index2] & 0xFF) =3D=3D (UINT16)Index) { - break; - } - } - - if (Index2 =3D=3D *Idx) { - // - // Index2 =3D=3D *Idx means we didn't find Index - // so Index is a new appeared device's index in BBS table - // insert it before disabled indexes. - // - for (Index2 =3D 0; Index2 < *Idx; Index2++) { - if ((NewDevPtr[Index2] & 0xFF00) =3D=3D 0xFF00) { - break; - } - } - - CopyMem (&NewDevPtr[Index2 + 1], &NewDevPtr[Index2], (*Idx - Index= 2) * sizeof (UINT16)); - NewDevPtr[Index2] =3D (UINT16)(Index & 0xFF); - (*Idx)++; - } - } - } - - FreePool (DevOrder); - - Status =3D gRT->SetVariable ( - VAR_LEGACY_DEV_ORDER, - &gEfiLegacyDevOrderVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLAT= ILE, - TotalSize, - NewDevOrder - ); - FreePool (NewDevOrder); - - return Status; -} - -/** - Set Boot Priority for specified device type. - - @param DeviceType The device type. - @param BbsIndex The BBS index to set the highest priority. Ignore= when -1. - @param LocalBbsTable The BBS table. - @param Priority The priority table. - - @retval EFI_SUCCESS The function completes successfully. - @retval EFI_NOT_FOUND Failed to find device. - @retval EFI_OUT_OF_RESOURCES Failed to get the efi variable of device o= rder. - -**/ -EFI_STATUS -LegacyBmSetPriorityForSameTypeDev ( - IN UINT16 DeviceType, - IN UINTN BbsIndex, - IN OUT BBS_TABLE *LocalBbsTable, - IN OUT UINT16 *Priority - ) -{ - LEGACY_DEV_ORDER_ENTRY *DevOrder; - LEGACY_DEV_ORDER_ENTRY *DevOrderPtr; - UINTN DevOrderSize; - UINTN Index; - - GetVariable2 (VAR_LEGACY_DEV_ORDER, &gEfiLegacyDevOrderVariableGuid, (VO= ID **)&DevOrder, &DevOrderSize); - if (NULL =3D=3D DevOrder) { - return EFI_OUT_OF_RESOURCES; - } - - DevOrderPtr =3D DevOrder; - while ((UINT8 *)DevOrderPtr < (UINT8 *)DevOrder + DevOrderSize) { - if (DevOrderPtr->BbsType =3D=3D DeviceType) { - break; - } - - DevOrderPtr =3D (LEGACY_DEV_ORDER_ENTRY *)((UINTN)DevOrderPtr + sizeof= (BBS_TYPE) + DevOrderPtr->Length); - } - - if ((UINT8 *)DevOrderPtr >=3D (UINT8 *)DevOrder + DevOrderSize) { - FreePool (DevOrder); - return EFI_NOT_FOUND; - } - - if (BbsIndex !=3D (UINTN)-1) { - // - // In case the BBS entry isn't valid because devices were plugged or r= emoved. - // - if (!LegacyBmValidBbsEntry (&LocalBbsTable[BbsIndex]) || (LocalBbsTabl= e[BbsIndex].DeviceType !=3D DeviceType)) { - FreePool (DevOrder); - return EFI_NOT_FOUND; - } - - LocalBbsTable[BbsIndex].BootPriority =3D *Priority; - (*Priority)++; - } - - // - // If the high byte of the DevIndex is 0xFF, it indicates that this devi= ce has been disabled. - // - for (Index =3D 0; Index < DevOrderPtr->Length / sizeof (UINT16) - 1; Ind= ex++) { - if ((DevOrderPtr->Data[Index] & 0xFF00) =3D=3D 0xFF00) { - // - // LocalBbsTable[DevIndex[Index] & 0xFF].BootPriority =3D BBS_DISABL= ED_ENTRY; - // - } else if (DevOrderPtr->Data[Index] !=3D BbsIndex) { - LocalBbsTable[DevOrderPtr->Data[Index]].BootPriority =3D *Priority; - (*Priority)++; - } - } - - FreePool (DevOrder); - return EFI_SUCCESS; -} - -/** - Print the BBS Table. - - @param LocalBbsTable The BBS table. - @param BbsCount The count of entry in BBS table. -**/ -VOID -LegacyBmPrintBbsTable ( - IN BBS_TABLE *LocalBbsTable, - IN UINT16 BbsCount - ) -{ - UINT16 Index; - - DEBUG ((DEBUG_INFO, "\n")); - DEBUG ((DEBUG_INFO, " NO Prio bb/dd/ff cl/sc Type Stat segm:offs mseg d= seg\n")); - DEBUG ((DEBUG_INFO, "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n")); - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&LocalBbsTable[Index])) { - continue; - } - - DEBUG ( - (DEBUG_INFO, - " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x %04x %04x= \n", - (UINTN)Index, - (UINTN)LocalBbsTable[Index].BootPriority, - (UINTN)LocalBbsTable[Index].Bus, - (UINTN)LocalBbsTable[Index].Device, - (UINTN)LocalBbsTable[Index].Function, - (UINTN)LocalBbsTable[Index].Class, - (UINTN)LocalBbsTable[Index].SubClass, - (UINTN)LocalBbsTable[Index].DeviceType, - (UINTN)*(UINT16 *)&LocalBbsTable[Index].StatusFlags, - (UINTN)LocalBbsTable[Index].BootHandlerSegment, - (UINTN)LocalBbsTable[Index].BootHandlerOffset, - (UINTN)((LocalBbsTable[Index].MfgStringSegment << 4) + LocalBbsTabl= e[Index].MfgStringOffset), - (UINTN)((LocalBbsTable[Index].DescStringSegment << 4) + LocalBbsTab= le[Index].DescStringOffset)) - ); - } - - DEBUG ((DEBUG_INFO, "\n")); -} - -/** - Set the boot priority for BBS entries based on boot option entry and boo= t order. - - @param BootOption The boot option is to be checked for refre= sh BBS table. - - @retval EFI_SUCCESS The boot priority for BBS entries is refre= shed successfully. - @retval EFI_NOT_FOUND BBS entries can't be found. - @retval EFI_OUT_OF_RESOURCES Failed to get the legacy device boot order. -**/ -EFI_STATUS -LegacyBmRefreshBbsTableForBoot ( - IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption - ) -{ - EFI_STATUS Status; - UINT16 BbsIndex; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *LocalHddInfo; - BBS_TABLE *LocalBbsTable; - UINT16 DevType; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN Index; - UINT16 Priority; - UINT16 *DeviceType; - UINTN DeviceTypeCount; - UINTN DeviceTypeIndex; - EFI_BOOT_MANAGER_LOAD_OPTION *Option; - UINTN OptionCount; - - HddCount =3D 0; - BbsCount =3D 0; - LocalHddInfo =3D NULL; - LocalBbsTable =3D NULL; - DevType =3D BBS_UNKNOWN; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &LocalHddInfo, - &BbsCount, - &LocalBbsTable - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // First, set all the present devices' boot priority to BBS_UNPRIORITIZE= D_ENTRY - // We will set them according to the settings setup by user - // - for (Index =3D 0; Index < BbsCount; Index++) { - if (LegacyBmValidBbsEntry (&LocalBbsTable[Index])) { - LocalBbsTable[Index].BootPriority =3D BBS_UNPRIORITIZED_ENTRY; - } - } - - // - // boot priority always starts at 0 - // - Priority =3D 0; - if ((DevicePathType (BootOption->FilePath) =3D=3D BBS_DEVICE_PATH) && - (DevicePathSubType (BootOption->FilePath) =3D=3D BBS_BBS_DP)) - { - // - // If BootOption stands for a legacy boot option, we prioritize the de= vices with the same type first. - // - DevType =3D LegacyBmDeviceType (BootOption->FilePath); - BbsIndex =3D ((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOption->OptionalDa= ta)->BbsIndex; - Status =3D LegacyBmSetPriorityForSameTypeDev ( - DevType, - BbsIndex, - LocalBbsTable, - &Priority - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // - // we have to set the boot priority for other BBS entries with different= device types - // - Option =3D EfiBootManagerGetLoadOptions (&OptionCount, LoadOptionTyp= eBoot); - DeviceType =3D AllocatePool (sizeof (UINT16) * OptionCount); - ASSERT (DeviceType !=3D NULL); - DeviceType[0] =3D DevType; - DeviceTypeCount =3D 1; - for (Index =3D 0; Index < OptionCount; Index++) { - if ((DevicePathType (Option[Index].FilePath) !=3D BBS_DEVICE_PATH) || - (DevicePathSubType (Option[Index].FilePath) !=3D BBS_BBS_DP)) - { - continue; - } - - DevType =3D LegacyBmDeviceType (Option[Index].FilePath); - for (DeviceTypeIndex =3D 0; DeviceTypeIndex < DeviceTypeCount; DeviceT= ypeIndex++) { - if (DeviceType[DeviceTypeIndex] =3D=3D DevType) { - break; - } - } - - if (DeviceTypeIndex < DeviceTypeCount) { - // - // We don't want to process twice for a device type - // - continue; - } - - DeviceType[DeviceTypeCount] =3D DevType; - DeviceTypeCount++; - - Status =3D LegacyBmSetPriorityForSameTypeDev ( - DevType, - (UINTN)-1, - LocalBbsTable, - &Priority - ); - } - - EfiBootManagerFreeLoadOptions (Option, OptionCount); - - DEBUG_CODE_BEGIN (); - LegacyBmPrintBbsTable (LocalBbsTable, BbsCount); - DEBUG_CODE_END (); - - return Status; -} - -/** - Boot the legacy system with the boot option. - - @param BootOption The legacy boot option which have BBS device path - On return, BootOption->Status contains the boot statu= s. - EFI_UNSUPPORTED There is no legacybios protocol, d= o not support - legacy boot. - EFI_STATUS The status of LegacyBios->LegacyBo= ot (). -**/ -VOID -EFIAPI -LegacyBmBoot ( - IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption - ) -{ - EFI_STATUS Status; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - // - // If no LegacyBios protocol we do not support legacy boot - // - BootOption->Status =3D EFI_UNSUPPORTED; - return; - } - - // - // Notes: if we separate the int 19, then we don't need to refresh BBS - // - Status =3D LegacyBmRefreshBbsTableForBoot (BootOption); - if (EFI_ERROR (Status)) { - BootOption->Status =3D Status; - return; - } - - BootOption->Status =3D LegacyBios->LegacyBoot ( - LegacyBios, - (BBS_BBS_DEVICE_PATH *)BootOption->Fi= lePath, - BootOption->OptionalDataSize, - BootOption->OptionalData - ); -} - -/** - This function enumerates all the legacy boot options. - - @param BootOptionCount Return the legacy boot option count. - - @retval Pointer to the legacy boot option buffer. -**/ -EFI_BOOT_MANAGER_LOAD_OPTION * -LegacyBmEnumerateAllBootOptions ( - UINTN *BootOptionCount - ) -{ - EFI_STATUS Status; - UINT16 HddCount; - UINT16 BbsCount; - HDD_INFO *HddInfo; - BBS_TABLE *BbsTable; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINT16 Index; - EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; - - ASSERT (BootOptionCount !=3D NULL); - - BootOptions =3D NULL; - *BootOptionCount =3D 0; - BbsCount =3D 0; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - return NULL; - } - - Status =3D LegacyBios->GetBbsInfo ( - LegacyBios, - &HddCount, - &HddInfo, - &BbsCount, - &BbsTable - ); - if (EFI_ERROR (Status)) { - return NULL; - } - - for (Index =3D 0; Index < BbsCount; Index++) { - if (!LegacyBmValidBbsEntry (&BbsTable[Index])) { - continue; - } - - BootOptions =3D ReallocatePool ( - sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCo= unt), - sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCo= unt + 1), - BootOptions - ); - ASSERT (BootOptions !=3D NULL); - - Status =3D LegacyBmCreateLegacyBootOption (&BootOptions[(*BootOptionCo= unt)++], &BbsTable[Index], Index); - ASSERT_EFI_ERROR (Status); - } - - return BootOptions; -} - -/** - Return the index of the boot option in the boot option array. - - The function compares the Description, FilePath, OptionalData. - - @param Key The input boot option which is compared with. - @param Array The input boot option array. - @param Count The count of the input boot options. - - @retval The index of the input boot option in the array. - -**/ -INTN -LegacyBmFindBootOption ( - IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, - IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, - IN UINTN Count - ) -{ - UINTN Index; - - for (Index =3D 0; Index < Count; Index++) { - if ((StrCmp (Key->Description, Array[Index].Description) =3D=3D 0) && - (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSi= ze (Key->FilePath)) =3D=3D 0) && - (Key->OptionalDataSize =3D=3D Array[Index].OptionalDataSize) && - (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->Op= tionalDataSize) =3D=3D 0)) - { - return (INTN)Index; - } - } - - return -1; -} - -/** - Refresh all legacy boot options. - -**/ -VOID -EFIAPI -LegacyBmRefreshAllBootOption ( - VOID - ) -{ - EFI_STATUS Status; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - UINTN RootBridgeHandleCount; - EFI_HANDLE *RootBridgeHandleBuffer; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN RootBridgeIndex; - UINTN Index; - UINTN Flags; - EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; - UINTN BootOptionCount; - EFI_BOOT_MANAGER_LOAD_OPTION *ExistingBootOptions; - UINTN ExistingBootOptionCount; - - Status =3D gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID= **)&LegacyBios); - if (EFI_ERROR (Status)) { - LegacyBmDeleteAllBootOptions (); - return; - } - - PERF_START (NULL, "LegacyBootOptionEnum", "BDS", 0); - - // - // Before enumerating the legacy boot option, we need to dispatch all th= e legacy option roms - // to ensure the GetBbsInfo() counts all the legacy devices. - // - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciRootBridgeIoProtocolGuid, - NULL, - &RootBridgeHandleCount, - &RootBridgeHandleBuffer - ); - for (RootBridgeIndex =3D 0; RootBridgeIndex < RootBridgeHandleCount; Roo= tBridgeIndex++) { - gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL,= NULL, FALSE); - gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - for (Index =3D 0; Index < HandleCount; Index++) { - // - // Start the thunk driver so that the legacy option rom gets dispatc= hed. - // Note: We don't directly call InstallPciRom because some thunk dri= vers - // (e.g. BlockIo thunk driver) depend on the immediate result after = dispatching - // - Status =3D LegacyBios->CheckPciRom ( - LegacyBios, - HandleBuffer[Index], - NULL, - NULL, - &Flags - ); - if (!EFI_ERROR (Status)) { - gBS->ConnectController (HandleBuffer[Index], NULL, NULL, FALSE); - } - } - } - - // - // Same algorithm pattern as the EfiBootManagerRefreshAllBootOption - // Firstly delete the invalid legacy boot options, - // then enumerate and save the newly appeared legacy boot options - // the last step is legacy boot option special action to refresh the Leg= acyDevOrder variable - // - LegacyBmDeleteAllInvalidBootOptions (); - - ExistingBootOptions =3D EfiBootManagerGetLoadOptions (&ExistingBootOptio= nCount, LoadOptionTypeBoot); - BootOptions =3D LegacyBmEnumerateAllBootOptions (&BootOptionCoun= t); - - for (Index =3D 0; Index < BootOptionCount; Index++) { - if (LegacyBmFindBootOption (&BootOptions[Index], ExistingBootOptions, = ExistingBootOptionCount) =3D=3D -1) { - Status =3D EfiBootManagerAddLoadOptionVariable (&BootOptions[Index],= (UINTN)-1); - DEBUG (( - DEBUG_INFO, - "[LegacyBds] New Boot Option: Boot%04x Bbs0x%04x %s %r\n", - (UINTN)BootOptions[Index].OptionNumber, - (UINTN)((LEGACY_BM_BOOT_OPTION_BBS_DATA *)BootOptions[Index].Optio= nalData)->BbsIndex, - BootOptions[Index].Description, - Status - )); - // - // Continue upon failure to add boot option. - // - } - } - - EfiBootManagerFreeLoadOptions (ExistingBootOptions, ExistingBootOptionCo= unt); - EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); - - // - // Failure to create LegacyDevOrder variable only impacts the boot order. - // - LegacyBmUpdateDevOrder (); - - PERF_END (NULL, "LegacyBootOptionEnum", "BDS", 0); -} -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111075): https://edk2.groups.io/g/devel/message/111075 Mute This Topic: https://groups.io/mt/102518641/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-