From 31bb486c913795c8b67d1c4dbaae2bdec4943fc9 Mon Sep 17 00:00:00 2001 From: raywu Date: Thu, 13 Sep 2018 16:11:56 +0800 Subject: SLP1.0 / SLP2.0 / Default Password / Logo / Fix Boot Order --- EDK/MiniSetup/TseAdvanced/Bbs.c | 946 +++++++ EDK/MiniSetup/TseAdvanced/Jpeg6.h | 123 + EDK/MiniSetup/TseAdvanced/Logo.c | 282 ++ EDK/MiniSetup/TseAdvanced/MyDefs.h | 103 + EDK/MiniSetup/TseAdvanced/TseAdvanced.c | 3962 +++++++++++++++++++++++++++++ EDK/MiniSetup/TseAdvanced/TseAdvanced.cif | 28 + EDK/MiniSetup/TseAdvanced/TseAdvanced.mak | 160 ++ EDK/MiniSetup/TseAdvanced/TseAdvanced.sdl | 42 + EDK/MiniSetup/TseAdvanced/bootflowLib.c | 199 ++ EDK/MiniSetup/TseAdvanced/dogif.c | 1197 +++++++++ EDK/MiniSetup/TseAdvanced/dogifmgr.c | 486 ++++ EDK/MiniSetup/TseAdvanced/iJpeg.c | 253 ++ EDK/MiniSetup/TseAdvanced/ipcx.c | 188 ++ EDK/MiniSetup/TseAdvanced/jpeg.h | 106 + EDK/MiniSetup/TseAdvanced/jpeg6.c | 1320 ++++++++++ EDK/MiniSetup/TseAdvanced/pcx.h | 138 + EDK/MiniSetup/TseAdvanced/pcxc.c | 321 +++ EDK/MiniSetup/TseAdvanced/png.c | 1353 ++++++++++ EDK/MiniSetup/TseAdvanced/png.h | 136 + EDK/MiniSetup/TseAdvanced/pnguncmp.c | 879 +++++++ EDK/MiniSetup/TseAdvanced/special.c | 1898 ++++++++++++++ EDK/MiniSetup/TseAdvanced/special.h | 196 ++ 22 files changed, 14316 insertions(+) create mode 100644 EDK/MiniSetup/TseAdvanced/Bbs.c create mode 100644 EDK/MiniSetup/TseAdvanced/Jpeg6.h create mode 100644 EDK/MiniSetup/TseAdvanced/Logo.c create mode 100644 EDK/MiniSetup/TseAdvanced/MyDefs.h create mode 100644 EDK/MiniSetup/TseAdvanced/TseAdvanced.c create mode 100644 EDK/MiniSetup/TseAdvanced/TseAdvanced.cif create mode 100644 EDK/MiniSetup/TseAdvanced/TseAdvanced.mak create mode 100644 EDK/MiniSetup/TseAdvanced/TseAdvanced.sdl create mode 100644 EDK/MiniSetup/TseAdvanced/bootflowLib.c create mode 100644 EDK/MiniSetup/TseAdvanced/dogif.c create mode 100644 EDK/MiniSetup/TseAdvanced/dogifmgr.c create mode 100644 EDK/MiniSetup/TseAdvanced/iJpeg.c create mode 100644 EDK/MiniSetup/TseAdvanced/ipcx.c create mode 100644 EDK/MiniSetup/TseAdvanced/jpeg.h create mode 100644 EDK/MiniSetup/TseAdvanced/jpeg6.c create mode 100644 EDK/MiniSetup/TseAdvanced/pcx.h create mode 100644 EDK/MiniSetup/TseAdvanced/pcxc.c create mode 100644 EDK/MiniSetup/TseAdvanced/png.c create mode 100644 EDK/MiniSetup/TseAdvanced/png.h create mode 100644 EDK/MiniSetup/TseAdvanced/pnguncmp.c create mode 100644 EDK/MiniSetup/TseAdvanced/special.c create mode 100644 EDK/MiniSetup/TseAdvanced/special.h (limited to 'EDK/MiniSetup/TseAdvanced') diff --git a/EDK/MiniSetup/TseAdvanced/Bbs.c b/EDK/MiniSetup/TseAdvanced/Bbs.c new file mode 100644 index 0000000..fe46455 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/Bbs.c @@ -0,0 +1,946 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Bbs.c $ +// +// $Author: Arunsb $ +// +// $Revision: 13 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Bbs.c $ +// +// 13 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 13 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 12 5/29/12 3:44a Arunsb +// [TAG] EIP91109 +// [Category] Improvement +// [Description] Sync the Aptio IV source for AptioV +// +// 11 11/13/11 12:33p Arunsb +// [TAG] EIP70421 +// [Category] New Feature +// [Description] Support for driver order in TSE +// [Files] AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini, +// boot.c, +// minisetup.h, bbs.c, special.c, special.h, tseadvanced.c, +// addbootoption.c, +// callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h, +// TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h, +// TseElink.h, variable.h, +// setup.h, Boot.vfr and Setup.uni +// +// 10 2/04/11 4:43p Mallikarjunanv +// added the UpdateBootVariables() fucntion to update BOOT and BBS order +// variables +// +// 9 12/21/10 11:48a Mallikarjunanv +// +// 9 9/21/10 11:26a Madhans +// EIP44542 changes +// +// 7 9/20/10 6:47p Madhans +// [TAG] EIP44542 +// [Category] BUILD ISSUE FIX +// [Symptom] Build issues with TSE label (INT)4.6.2_TSE_2_10_1207_TEST +// when IdeSecurity and FastBoot modules added to the project +// [RootCause] - +// [Solution] Build issues resolved +// [Files] CommonHelper.c, Tsecommon.h, Hiilib.h, Boot.h, minisetup.h, +// bbs.c, special.c, Bds.c TseLitehelp +// +// 6 9/16/10 8:38p Madhans +// Update for TSE 2.10. Refer Changelog.log for more details. +// +// 8 9/16/10 3:14p Madhans +// To Avoid build issues with TSE_USE_EDK_LIBRARY Building. +// +// 7 9/13/10 4:35p Madhans +// To avoid build issue when EDK Build Support is turned off. Aptio 4.6.x +// does not define I2O_DEVICE_PATH structure. +// +// 6 7/28/10 4:46a Mallikarjunanv +// EIP-29951: TSE Device Path Name support updated +// +// 5 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 4 1/09/10 4:47a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: bds.c +// +// Description: This file contains code for legacy boot device handling +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" + + + +// +//---------------------------------------------------------------------------- +// Procedure: GetDevStr +// +// Description: function to get the device strings +// +// Input: UINT16 DevType +// +// Output: device string +// +//---------------------------------------------------------------------------- +// +CHAR16 *GetDevStr(UINT16 DevType) +{ + CHAR16 *DevText=NULL; + + switch ( DevType ) + { + case BBS_TYPE_FLOPPY: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_FDD)); + break; + + case BBS_TYPE_HARDDRIVE: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_HDD)); + break; + + case BBS_TYPE_CDROM: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_CDROM)); + break; + + case BBS_TYPE_USB: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB)); + break; + + case BBS_TYPE_EMBEDDED_NETWORK: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_NETWORK)); + break; + + case BBS_TYPE_DEV: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_BEV)); + break; + } + + return DevText; +} + +// +//---------------------------------------------------------------------------- +// Procedure: IsSATADevice +// +// Description: function to check for SATA Devices +// +// Input: UINT16 *IdentifyDriveData - 512 bytes of device information +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOLEAN IsSATADevice(UINT16 *IdentifyDriveData) +{ + UINT16 data16; + + if(NULL == IdentifyDriveData) + return FALSE; + + // Check Word76 for BIT1 and BIT2; set for SATA drives + data16 = IdentifyDriveData[76]; + if ((data16 != 0xFFFF) && (data16 & 6)) + { + return TRUE; + } + + return FALSE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetBusStr +// +// Description: function to get the bus type string +// +// Input: EFI_HANDLE Handle, UINTN index, HDD_INFO *HDDInfo +// +// Output: Bus string +// +//---------------------------------------------------------------------------- +// +CHAR16 *GetBusStr(EFI_HANDLE Handle, UINTN index, HDD_INFO *HDDInfo) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevPath = NULL; + UINT8 PortNo; + CHAR16 *Format = NULL; + CHAR16 *BusText = NULL; + + //Right now generate names only for internal devices (index 1 to + //16). Devices reported by option ROMs will show string provided + //by Option ROMs. Later this may be extended for all devices. +// if((index<1) || (index>16)) +// return NULL; + + if (!Handle) + return NULL; + + Status = gBS->HandleProtocol(Handle, &gEfiDevicePathProtocolGuid, &DevPath); + + if(EFI_ERROR(Status)) + return NULL; + + while( !(IsDevicePathEnd(DevPath)) ) + { + if(MESSAGING_DEVICE_PATH == DevPath->Type) + { + switch(DevPath->SubType) + { + case MSG_ATAPI_DP: + PortNo = (((ATAPI_DEVICE_PATH*)DevPath)->PrimarySecondary<<1)|((ATAPI_DEVICE_PATH*)DevPath)->SlaveMaster; + if(IsSATADevice(HDDInfo[(index-1)/2].IdentifyDrive[(index-1)%2].Raw)) + { + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SATA_X)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PortNo); + } + else + { + switch(PortNo) + { + case 0: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_PRI_MAS)); + break; + case 1: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_PRI_SLA)); + break; + case 2: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SEC_MAS)); + break; + case 3: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SEC_SLA)); + break; + } + } + break; + //EIP-29951: extended for all devices. + case MSG_SCSI_DP: + { //Showing the SCSI device with Physical and Logical unit numbers + UINT16 PhyUnitNum, LogclUnitNum; + PhyUnitNum = ((SCSI_DEVICE_PATH*)DevPath)->Pun; + LogclUnitNum = ((SCSI_DEVICE_PATH*)DevPath)->Lun; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SCSI_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PhyUnitNum, LogclUnitNum); + } + break; + + case MSG_FIBRECHANNEL_DP: + {// showing Fibre channel with Logical unit number and WWN + UINT64 WWN,Lun; + WWN = ((FIBRECHANNEL_DEVICE_PATH*)DevPath)->WWN; + Lun = ((FIBRECHANNEL_DEVICE_PATH*)DevPath)->Lun; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_FIBRE_CHANNEL_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun, WWN); + } + break; + + case MSG_1394_DP: + //For 1394 device support + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_1394_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format); + break; + + case MSG_USB_DP: + { + // usb device with port number + PortNo = ((USB_DEVICE_PATH*)DevPath)->ParentPortNumber; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PortNo); + } + break; + + case MSG_I2O_DP: + { // I2O device with Tid + UINT32 Tid; + + Tid = ((AMITSE_I2O_DEVICE_PATH*)DevPath)->Tid; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_I20_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Tid); + } + break; + + case MSG_INFINIBAND_DP: //Need to know what type of device is this.. + { // InfiniBand device with Device Id + UINT64 DeviceId; + + DeviceId = ((INFINIBAND_DEVICE_PATH*)DevPath)->DeviceId; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_INFINIBAND_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, DeviceId); + } + break; + + case MSG_VENDOR_DP: + // for vendor specific device + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_VENDOR_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format); + break; + + case MSG_MAC_ADDR_DP: + { // network device with mac address + UINT8 Mac[32]; + + MemCopy( Mac, (UINT8*)&(((AMITSE_MAC_ADDR_DEVICE_PATH*)DevPath)->MacAddress),32*sizeof(UINT8)); + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_MAC_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Mac); + } + + break; + + case MSG_IPv4_DP: + { //IPv4 Device with Logical Port number + UINT16 LocalPort; + + LocalPort = ((IPv4_DEVICE_PATH*)DevPath)->LocalPort; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_NETWORK_IPV4_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, LocalPort); + } + break; + + case MSG_IPv6_DP: + { //IPv6 Device with Logical Port number + UINT16 LocalPort; + + LocalPort = ((IPv6_DEVICE_PATH*)DevPath)->LocalPort; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_NETWORK_IPV6_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, LocalPort); + } + + break; + + case MSG_UART_DP: + { //UART device with Baud Rate + UINT64 BaudRate; + + BaudRate = ((UART_DEVICE_PATH*)DevPath)->BaudRate; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_UART_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, BaudRate); + } + break; + + case MSG_USB_CLASS_DP: + { ////for UBS Class id specific devices. + UINT8 DeviceClass; + + DeviceClass = ((USB_CLASS_DEVICE_PATH*)DevPath)->DeviceClass; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + switch(DeviceClass) + { //To show the type of device based on the class + case USB_PHY_DEV_CLASS: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_PHY_DP)); + break; + + case USB_MASS_DEV_CLASS: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_MASS_DP)); + break; + + default: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_DP)); + + } + SPrint(BusText, MAX_DRIVE_NAME, Format, DeviceClass); + } + break; + + case MSG_USB_WWID_CLASS_DP: + //need the info about USB WWID devices... + break; + + case MSG_USB_LOGICAL_UNIT_CLASS_DP: + { //for USB logical unit class devices with Logical Unit Numnber + UINT8 Lun; + +#if TSE_USE_EDK_LIBRARY + Lun = ((DEVICE_LOGICAL_UNIT_DEVICE_PATH*)DevPath)->Lun; +#else + Lun = ((LOGICAL_UNIT_DEVICE_PATH*)DevPath)->Lun; +#endif + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_LOGICAL_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun); + } + break; + + case MSG_USB_SATA_DP: + { // for USB SATA devices with Port Number + UINT16 PortNumber; + PortNumber = ((AMITSE_SATA_DEVICE_PATH*)DevPath)->HBAPortNumber; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_SATA_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PortNumber); + } + break; + + case MSG_USB_ISCSI_DP: + { // for USB iSCSI devices with Logical Unit Number + UINT64 Lun; + Lun = ((AMITSE_ISCSI_DEVICE_PATH*)DevPath)->Lun; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_ISCSI_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun); + } + break; + } + } + + DevPath = NextDevicePathNode(DevPath); + } + + MemFreePointer((VOID **) &Format); + return BusText; +} + +// +//---------------------------------------------------------------------------- +// Procedure: BBSBuildDevicePathName +// +// Description: function to build the bbs device path +// +// Input: CHAR16 *String, BBS_TABLE *info, UINTN index, HDD_INFO *HDDInfo +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID BBSBuildDevicePathName( CHAR16 *String, BBS_TABLE *info, UINTN index, HDD_INFO *HDDInfo ) +{ + EFI_HANDLE Handle; + CHAR16 *BusText, *DevText; + UINT8 *StringDesc; + UINTN i; + + Handle = *(VOID**)(&info->IBV1); + + BusText = GetBusStr(Handle, index, HDDInfo); + DevText = GetDevStr(info->DeviceType); + + if(BusText && DevText) + { + SPrint(String, MAX_DRIVE_NAME, L"%s %s", BusText, DevText); + } + else + { + StringDesc = (UINT8*)(UINTN)((info->DescStringSegment << 4) + + info->DescStringOffset); + if ( StringDesc != NULL ) + { + for ( i = 0; (i < (MAX_DRIVE_NAME - 1)) && (StringDesc[i] != '\0'); i++ ) + String[i] = (CHAR16)StringDesc[i]; + String[i] = L'\0'; + } + else + { + SPrint(String, MAX_DRIVE_NAME, L"%s %s", BusText ? BusText : L"Unknown", DevText ? DevText : L"Unknown"); + } + } + + MemFreePointer((VOID **)&BusText); + MemFreePointer((VOID **)&DevText); +} + +// +//---------------------------------------------------------------------------- +// Procedure: UpdateLegacyDevVariable +// +// Description: +// +// Input: UINT16 NoOfLegacyGroups +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID UpdateLegacyDevVariable(UINT16 NoOfLegacyGroups) +{ + VarSetNvramName( L"LegacyDev", &gLegacyDevGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, &NoOfLegacyGroups, sizeof(NoOfLegacyGroups) ); +} + +// +//---------------------------------------------------------------------------- +// Procedure: BBSUpdateOrder +// +// Description: function to update Bbs device order +// +// Input: UINT16 *newOption,UINT32 *offset,UINTN *size, VOID **buffer +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID BBSUpdateOrder(UINT16 *newOption,UINT32 *offset,UINTN *size, VOID **buffer) +{ + UINT8 *pDevOrder; + UINT16 count = 0, *optionList = NULL, oldOption; + UINTN i,j,optionNumber; + + *size = 0; + + pDevOrder = VarGetVariable( VARIABLE_ID_BBS_ORDER, size ); + + *offset -= (sizeof(UINT32) + sizeof(UINT16)); + + count = gCurrLegacyBootData->LegacyDevCount; + *offset -= (UINT32)gCurrLegacyBootData->LegacyEntryOffset; + optionList = (UINT16 *)(pDevOrder + gCurrLegacyBootData->LegacyEntryOffset + sizeof(UINT32) + sizeof(UINT16)); + optionNumber = *offset / sizeof(UINT16); + + *offset = 0; + *buffer = (VOID *)pDevOrder; + + oldOption = optionList[optionNumber]; + + if ( *newOption == oldOption ) + return; + + if(DISABLED_BOOT_OPTION == *newOption) + { + for(i = optionNumber; i < count; i++) + { + if((i+1) < count) + optionList[i] = optionList[i + 1]; + else + optionList[i] = *newOption; // or DISABLED_BOOT_OPTION + } + } + else if(DISABLED_BOOT_OPTION == oldOption) + { + //Find newOption's position + for(i=0;i +//---------------------------------------------------------------------------- +// Procedure: GetUefiDevPathString +// +// Description: function to get the device string using device path for UEFI options. +// +// Input: EFI_DEVICE_PATH_PROTOCOL *DevPath +// +// Output: Device string. +// +//---------------------------------------------------------------------------- +// +CHAR16 *GetUefiDevPathString(EFI_DEVICE_PATH_PROTOCOL *DevPath) +{ + UINT8 PortNo; + CHAR16 *Format = NULL; + CHAR16 *BusText = NULL; + CHAR16 *DevText = NULL; + CHAR16 *String = NULL; + + while( !(IsDevicePathEnd(DevPath)) ) + { + if(MESSAGING_DEVICE_PATH == DevPath->Type) + { + switch(DevPath->SubType) + { + case MSG_ATAPI_DP: + PortNo = (((ATAPI_DEVICE_PATH*)DevPath)->PrimarySecondary<<1)|((ATAPI_DEVICE_PATH*)DevPath)->SlaveMaster; + switch(PortNo) + { + case 0: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_PRI_MAS)); + break; + case 1: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_PRI_SLA)); + break; + case 2: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SEC_MAS)); + break; + case 3: + BusText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SEC_SLA)); + break; + } + break; + //Later this may be extended for all devices. + case MSG_SCSI_DP: + { //Showing the SCSI device with Physical and Logical unit numbers + UINT16 PhyUnitNum, LogclUnitNum; + PhyUnitNum = ((SCSI_DEVICE_PATH*)DevPath)->Pun; + LogclUnitNum = ((SCSI_DEVICE_PATH*)DevPath)->Lun; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_SCSI_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PhyUnitNum, LogclUnitNum); + } + break; + + case MSG_FIBRECHANNEL_DP: + {// showing Fibre channel with Logical unit number and WWN + UINT64 WWN,Lun; + WWN = ((FIBRECHANNEL_DEVICE_PATH*)DevPath)->WWN; + Lun = ((FIBRECHANNEL_DEVICE_PATH*)DevPath)->Lun; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_FIBRE_CHANNEL_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun, WWN); + } + break; + + case MSG_1394_DP: + //For 1394 device support + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_1394_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format); + break; + + case MSG_USB_DP: + { + // usb device with port number + PortNo = ((USB_DEVICE_PATH*)DevPath)->ParentPortNumber; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PortNo); + } + break; + + case MSG_I2O_DP: + { // I2O device with Tid + UINT32 Tid; + + Tid = ((AMITSE_I2O_DEVICE_PATH*)DevPath)->Tid; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_I20_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Tid); + } + break; + + case MSG_INFINIBAND_DP: //Need to know what type of device is this.. + { // InfiniBand device with Device Id + UINT64 DeviceId; + + DeviceId = ((INFINIBAND_DEVICE_PATH*)DevPath)->DeviceId; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_INFINIBAND_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, DeviceId); + } + break; + + case MSG_VENDOR_DP: + // for vendor specific device + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_VENDOR_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format); + break; + + case MSG_MAC_ADDR_DP: + { // network device with mac address + UINT8 Mac[32]; + + MemCopy( Mac, (UINT8*)&(((AMITSE_MAC_ADDR_DEVICE_PATH*)DevPath)->MacAddress),32*sizeof(UINT8)); + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_MAC_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Mac); + } + + break; + + case MSG_IPv4_DP: + { //IPv4 Device with Logical Port number + UINT16 LocalPort; + + LocalPort = ((IPv4_DEVICE_PATH*)DevPath)->LocalPort; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_NETWORK_IPV4_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, LocalPort); + } + break; + + case MSG_IPv6_DP: + { //IPv6 Device with Logical Port number + UINT16 LocalPort; + + LocalPort = ((IPv6_DEVICE_PATH*)DevPath)->LocalPort; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_NETWORK_IPV6_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, LocalPort); + } + + break; + + case MSG_UART_DP: + { //UART device with Baud Rate + UINT64 BaudRate; + + BaudRate = ((UART_DEVICE_PATH*)DevPath)->BaudRate; + + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_UART_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, BaudRate); + } + break; + + case MSG_USB_CLASS_DP: + { ////for UBS Class id specific devices. + UINT8 DeviceClass; + + DeviceClass = ((USB_CLASS_DEVICE_PATH*)DevPath)->DeviceClass; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + switch(DeviceClass) + { //To show the type of device based on the class + case USB_PHY_DEV_CLASS: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_PHY_DP)); + break; + + case USB_MASS_DEV_CLASS: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_MASS_DP)); + break; + + default: + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_CLASS_DP)); + + } + SPrint(BusText, MAX_DRIVE_NAME, Format, DeviceClass); + } + break; + + case MSG_USB_LOGICAL_UNIT_CLASS_DP: + { //for USB logical unit class devices with Logical Unit Numnber + UINT8 Lun; + +#if TSE_USE_EDK_LIBRARY + Lun = ((DEVICE_LOGICAL_UNIT_DEVICE_PATH*)DevPath)->Lun; +#else + Lun = ((LOGICAL_UNIT_DEVICE_PATH*)DevPath)->Lun; +#endif + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_LOGICAL_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun); + } + break; + + case MSG_USB_SATA_DP: + { // for USB SATA devices with Port Number + UINT16 PortNumber; + PortNumber = ((AMITSE_SATA_DEVICE_PATH*)DevPath)->HBAPortNumber; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_SATA_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, PortNumber); + } + break; + + case MSG_USB_ISCSI_DP: + { // for USB iSCSI devices with Logical Unit Number + UINT64 Lun; + Lun = ((AMITSE_ISCSI_DEVICE_PATH*)DevPath)->Lun; + BusText = (CHAR16 *)EfiLibAllocatePool(MAX_DRIVE_NAME * sizeof(CHAR16)); + Format = HiiGetString(gHiiHandle, STRING_TOKEN(STR_USB_ISCSI_DP)); + SPrint(BusText, MAX_DRIVE_NAME, Format, Lun); + } + break; + } + } + + if(MEDIA_DEVICE_PATH == DevPath->Type) + { + switch(DevPath->SubType) + { + case MEDIA_HARDDRIVE_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_HDD)); + break; + + case MEDIA_CDROM_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_CDROM)); + break; + + case MEDIA_VENDOR_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_VENDOR)); + break; + + case MEDIA_FILEPATH_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_FILEPATH)); + break; + + case MEDIA_PROTOCOL_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_PROTOCOL)); + break; + + case MEDIA_FV_FILEPATH_DP: + DevText = HiiGetString(gHiiHandle, STRING_TOKEN(STR_FV_FILEPATH)); + break; + + } + } + + DevPath = NextDevicePathNode(DevPath); + } + + if(BusText && DevText) + { + String = (CHAR16 *)EfiLibAllocatePool((MAX_DRIVE_NAME+10) * sizeof(CHAR16)); + SPrint(String, MAX_DRIVE_NAME, L"%s %s", BusText, DevText); + + MemFreePointer((VOID **) &BusText); + MemFreePointer((VOID **) &DevText); + } + + MemFreePointer((VOID **) &Format); + + return String; +} + +// +//---------------------------------------------------------------------------- +// Procedure: UpdateBootVariables +// +// Description: Update the BootOrder,BBSOrder Cache From the NVRAM. +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID UpdateBootVariables () +{ + VarUpdateVariable(VARIABLE_ID_BOOT_ORDER); + VarUpdateVariable(VARIABLE_ID_BBS_ORDER); +} + +//EIP70421 starts +// +//---------------------------------------------------------------------------- +// Procedure: UpdateDriverVariables +// +// Description: Update the DriverOrder Cache From the NVRAM. +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID UpdateDriverVariables() +{ + VarUpdateVariable (VARIABLE_ID_DRIVER_ORDER); +} +//EIP70421 ends + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/Jpeg6.h b/EDK/MiniSetup/TseAdvanced/Jpeg6.h new file mode 100644 index 0000000..6f873ff --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/Jpeg6.h @@ -0,0 +1,123 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Jpeg6.h $ +// +// $Author: Arunsb $ +// +// $Revision: 5 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Jpeg6.h $ +// +// 5 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 7 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 5 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 4 1/09/10 4:43a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 3 6/16/09 2:16p Presannar +// Added File Headers for Header Files +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 9/26/06 4:03p Madhans +// JpegC Implimentation +// +// 1 8/01/06 8:03a Shirinmd +// Files for JPEG decoding (C version) +// +//*****************************************************************// +// +//---------------------------------------------------------------------------- +// +// Name: jpeg6.h +// +// Description: Header file for jpeg6 image format related code +// +//---------------------------------------------------------------------------- +// + +#ifndef _JPEG_6_H_ +#define _JPEG_6_H_ + +#include "Mydefs.h" + + + +#pragma pack(1) + +typedef struct _AMI_TRUECOLOR_PIXEL_JPEG{ + UINT8 Red; + UINT8 Green; + UINT8 Blue; + UINT8 Reserved; +}AMI_TRUECOLOR_PIXEL_JPEG, *PAMI_TRUECOLOR_PIXEL_JPEG; + +#pragma pack() + +#define MKF_JPEG_YUV111_SUPPORT 1 +#define c_g_cb 5638 //; 0.34414 * 16384 +#define c_g_cr 11700 //; 0.71417 * 16384 + + +#define c1_16 8352 //;0.509795 +#define c3_16 9852 //;0.601344 +#define c5_16 14745 //;0.899976 +#define c7_16 41990 //;2.562915 +#define c1_8 8867 //;0.541196 +#define c3_8 21407 //;1.306562 +#define c1_4 11585 //;0.707196 +#define c1_sqrt2 11585 //;0.707106 + + +#endif //#ifndef _JPEG_6_H_ + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/Logo.c b/EDK/MiniSetup/TseAdvanced/Logo.c new file mode 100644 index 0000000..49920a0 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/Logo.c @@ -0,0 +1,282 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Logo.c $ +// +// $Author: Arunsb $ +// +// $Revision: 6 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/Logo.c $ +// +// 6 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 8 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 5 6/13/11 12:32p Rajashakerg +// [TAG] EIP60910 +// [Category] New Feature +// [Description] PNG image support in TSE. +// [Files] LogoLib.h, AMITSE.sdl, CommonHelper.c, logo.c, png.c, png.h, +// pnguncmp.c, TseAdvanced.cif +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 6 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 5 8/17/09 10:46a Presannar +// Use proper tycasting for the parameters of fn ConvertGifToUgaBltWrapper +// to avoid compiler warnings. +// +// 4 8/13/09 12:16p Blaines +// Move Image support to binary module +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: logo.c +// +// Description: This file contains code for advanced logo support +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" + +extern LOGO_TYPE GetGifLogoType(UINT8 *ImageData); +extern LOGO_TYPE GetJPEGLogoType(UINT8 *ImageData); +extern LOGO_TYPE GetPCXLogoType(UINT8 *ImageData); +extern LOGO_TYPE GetPNGLogoType(UINT8 *ImageData); +LOGO_TYPE GetOEMLogoType(UINT8 *ImageData); + +extern EFI_STATUS ConvertBmpToUgaBltWrapper (IN VOID *BmpImage, IN UINTN BmpImageSize, IN OUT VOID **UgaBlt, + IN OUT UINTN *UgaBltSize, OUT UINTN *PixelHeight, OUT UINTN *PixelWidth ); + +extern EFI_STATUS ConvertGifToUgaBltWrapper ( IN VOID *GifImage, IN UINTN GifImageSize, IN OUT VOID **UgaBlt, + IN OUT UINTN *UgaBltSize, OUT UINTN *PixelHeight, OUT UINTN *PixelWidth, OUT BOOLEAN *Animate ); + +extern EFI_STATUS ConvertJPEGToUgaBltWrapper ( IN VOID *JPEGImage, IN UINT32 JPEGImageSize, IN OUT VOID **UgaBlt, + IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth, OUT UINT32 *punBufferWidth); + +extern EFI_STATUS ConvertPCXToUgaBltWrapper ( IN VOID *PCXImage, IN UINT32 PCXImageSize, IN OUT VOID **UgaBlt, + IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth) ; + +extern EFI_STATUS ConvertPNGToUgaBltWrapper ( IN VOID *PCXImage, IN UINT32 PCXImageSize, IN OUT VOID **UgaBlt, + IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth) ; + +extern EFI_STATUS ConvertOEMFormatToUgaBltWrapper ( IN VOID *OEMImage, IN UINT32 OEMImageSize, IN OUT VOID **UgaBlt, + IN OUT UINT32 *UgaBltSize, OUT UINT32 *Height, OUT UINT32 *Width, BOOLEAN * Animate); + +// +//---------------------------------------------------------------------------- +// Procedure: GetExtendedLogoType +// +// Description: function to get the type of extended logo +// +// Input: UINT8 *ImageData +// +// Output: LOGO_TYPE +// +//---------------------------------------------------------------------------- +// +LOGO_TYPE GetExtendedLogoType(UINT8 *ImageData) +{ + if ( GIF_Logo == GetGifLogoType(ImageData)) + return GIF_Logo; + + if ( JPEG_Logo == GetJPEGLogoType(ImageData)) + return JPEG_Logo; + + if ( PCX_Logo == GetPCXLogoType(ImageData)) + return PCX_Logo; + + if ( PNG_Logo == GetPNGLogoType(ImageData)) + return PNG_Logo; + + if( OEM_Format_LOGO == GetOEMLogoType(ImageData)) + return OEM_Format_LOGO; + + return Unsupported_Logo; +} +// +//---------------------------------------------------------------------------- +// Procedure: ConvertAdvancedImageToUgaBlt +// +// Description: Convert a advanced graphics image to a UGA blt buffer. +// +// Input: IN VOID *ImageData, +// IN UINTN ImageSize, +// IN OUT VOID **UgaBlt, +// IN OUT UINTN *UgaBltSize, +// OUT UINTN *Height, +// OUT UINTN *Width, +// OUT BOOLEAN *Animate +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS +ConvertAdvancedImageToUgaBlt ( + IN VOID *ImageData, + IN UINTN ImageSize, + IN OUT VOID **UgaBlt, + IN OUT UINTN *UgaBltSize, + OUT UINTN *Height, + OUT UINTN *Width, + OUT BOOLEAN *Animate +) +{ + UINTN LogoType; + EFI_STATUS Status = EFI_UNSUPPORTED; + + + UINT32 Temp=0; + + + LogoType = GetExtendedLogoType(ImageData); + switch(LogoType) + { + + case GIF_Logo: + + Status = ConvertGifToUgaBltWrapper( + ImageData, + (UINT32)ImageSize, + UgaBlt, + (UINTN*)UgaBltSize, + (UINTN*)Height, + (UINTN*)Width, + Animate + ); + + break; + + case JPEG_Logo: + + Status = ConvertJPEGToUgaBltWrapper( + ImageData, + (UINT32)ImageSize, + UgaBlt, + (UINT32*)UgaBltSize, + (UINT32*)Height, + (UINT32*)&Temp, + (UINT32*)Width + ); + break; + + case PCX_Logo: + + Status = ConvertPCXToUgaBltWrapper( + ImageData, + (UINT32)ImageSize, + UgaBlt, + (UINT32*)UgaBltSize, + (UINT32*)Height, + (UINT32*)Width + ); + break; + case PNG_Logo: + + Status = ConvertPNGToUgaBltWrapper( + ImageData, + (UINT32)ImageSize, + UgaBlt, + (UINT32*)UgaBltSize, + (UINT32*)Height, + (UINT32*)Width + ); + break; + + case OEM_Format_LOGO: + + Status = ConvertOEMFormatToUgaBltWrapper( + ImageData, + (UINT32)ImageSize, + UgaBlt, + (UINT32*)UgaBltSize, + (UINT32*)Height, + (UINT32*)Width, + Animate + ); + break; + + default: + break; + } + return Status; +} + +// +//---------------------------------------------------------------------------- +// Procedure: DoLogoAnimate +// +// Description: function to Handle logo animation +// +// Input: CO_ORD_ATTRIBUTE Attribute, +// INTN CoordinateX,INTN CoordinateY +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID DoLogoAnimate(CO_ORD_ATTRIBUTE Attribute,INTN CoordinateX,INTN CoordinateY) +{ + DoLogoAnimateWrapper(Attribute,CoordinateX,CoordinateY); +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/MyDefs.h b/EDK/MiniSetup/TseAdvanced/MyDefs.h new file mode 100644 index 0000000..57261ef --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/MyDefs.h @@ -0,0 +1,103 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/MyDefs.h $ +// +// $Author: Arunsb $ +// +// $Revision: 5 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/MyDefs.h $ +// +// 5 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 7 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 5 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 4 7/08/09 3:34p Madhans +// Coding Standards. +// +// 3 6/16/09 2:16p Presannar +// Added File Headers for Header Files +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 9/26/06 4:03p Madhans +// JpegC Implimentation +// +// 1 8/01/06 8:03a Shirinmd +// Files for JPEG decoding (C version) +// +//*****************************************************************// +// +//---------------------------------------------------------------------------- +// +// Name: mydefs.h +// +// Description: Header file common definitions +// +//---------------------------------------------------------------------------- +// + +#ifndef _MYDEFS_H_ +#define _MYDEFS_H_ + +#include "minisetup.h" +#define memset MemSet +#define memcpy MemCopy + +#define BOOL INTN +#define BYTE unsigned char +#define WORD UINT16 +#define DWORD UINT32 + + +#endif //#ifndef _MYDEFS_H_ + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/TseAdvanced.c b/EDK/MiniSetup/TseAdvanced/TseAdvanced.c new file mode 100644 index 0000000..f161ee9 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/TseAdvanced.c @@ -0,0 +1,3962 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2014, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/TseAdvanced.c $ +// +// $Author: Premkumara $ +// +// $Revision: 69 $ +// +// $Date: 9/05/14 2:39p $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/TseAdvanced.c $ +// +// 69 9/05/14 2:39p Premkumara +// Moved GetSetDefaultsFromControlPtr() function from Uefi2.1\Hii.c to +// TseAdvanced.c +// +// 68 8/28/14 9:39a Premkumara +// [TAG] EIP172956 +// [Category] Bug Fix +// [Severity:] Critical +// [Symptom:] Build error is displayed when TSE_CLEAR_USERPW_WITH_ADMINPW +// token is ON +// [Root Cause] When we do clear password then with Admin password its +// only clearing user password from cache not from NVRAM. But in ESA it +// working fine +// [Solution] In ClearUserPasswordPolicy in TseAdvanced.c, we just +// clearing password from Cache not from NVRAM if save paswd to nvram +// token ios ON, so added that feature. +// [Files] TseAdvanced.c +// +// 67 8/28/14 9:28a Premkumara +// [TAG] EIP170151 +// [Category] Bug Fix +// [Severity:] Normal +// [Symptom:] DisplayTextBox does not close before it returns. +// [Root Cause] Text box was not clearing before showing message box or +// info box. +// [Solution] modified the code to clear the Text box before showing +// message box or info box +// [Files] TseAdvanced.c +// +// 66 8/28/14 6:48a Premkumara +// [TAG] EIP93340 +// [Category] Improvement +// [Description] - Defaults can be given to string type controls using tag +// "Default = STRING_TOKEN(STR_DEFAULT_STRING)". +// - New token TSE_SUPPORT_DEFAULT_FOR_STRING_CONTROL is introduced for +// this support. +// - Enabling this TSE_SUPPORT_DEFAULT_FOR_STRING_CONTROL token will +// display default string mention in setup. +// - On loading optimal defaults also string will load default mentioned +// in default value tag. +// [Files] AMITSE.sdl, HiiString21.c, TseAdvanced.c, MiniSetupExt.c, Hii.c +// +// 65 5/02/14 8:44a Premkumara +// [TAG] EIP162981 +// [Category] Improvement +// [Description] Configuring default Password through SDL token +// [Files] AMITSE.sdl, CommonHelper.c, Minisetup.c, TseAdvanced.c +// +// 64 5/02/14 2:20a Premkumara +// [TAG] EIP131553 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] SoftKbd clearance issue on selecting UEFI shell from Save +// and Exit tab [when SoftKbd icon is selected] +// [RootCause] TSE was deactivating the softkbd after clearing the +// screen when we are selecting UEFI shell from Save and Exit tab +// [when SoftKbd icon is selected]. +// [Solution] Modified the code to deactivate the softkbd before +// clearing +// the TSE screen when we are selecting UEFI shell from Save and Exit tab +// [when SoftKbd icon is selected]. +// [Files] TseAdvanced.c +// +// 63 5/01/14 11:27p Arunsb +// [TAG] EIP128948 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] TSE security code check failure for using uninitialized +// variable "Action" +// [RootCause] Action variable in TimeHanldeActionKeyMouse and +// _PostPopupEditGetValues is not initialized +// [Solution] Initialized Action variable. +// [Files] Time.c, TseAdvanced.c +// +// 62 2/11/14 7:49p Arunsb +// Changes reverted for 2.16.1243 label +// +// 61 11/26/13 9:48a Premkumara +// [TAG] EIP118342 +// [Category] Improvement +// [Description] Show meaningful error message when HDD is locked after +// reached maximum unlocking attempt. +// [Files] TseAdvanced.c, CommonHelper.c, FakeToken.c, AmiTseStr.uni +// +// 60 11/26/13 1:31a Premkumara +// [TAG] EIP118342 +// [Category] Improvement +// [Description] Show meaningful error message when HDD is locked after +// reached maximum unlocking attempt. +// [Files] TseAdvanced.c, CommonHelper.c +// +// 59 11/06/13 1:26a Premkumara +// [TAG] EIP128948 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] TSE security code check failure for using uninitialized +// variable "Action" +// [RootCause] Action variable in TimeHanldeActionKeyMouse and +// _PostPopupEditGetValues is not initialized +// [Solution] Initialized Action variable. +// [Files] Time.c, TseAdvanced.c +// +// 58 10/07/13 3:06a Premkumara +// Intergrated missed EIP130529 changes (sysAccessGuid variable in +// LoadUserDefaultsSilently) to avoid build error +// +// 57 9/19/13 7:58a Arunsb +// [TAG] EIP127375 +// [Category] Bug Fix +// [Severity:] Critical +// [Symptom:] Legacy boot doesn't work after UEFI Shell is launched from +// LaunchAppHotkey menu. The system hangs +// [Root Cause] If ShowPostMsgBoxEx is invoked through postmgr protcol +// then gMsgBoxAction will be NULL initially, +// so this time action is assigned and used. +// ACTION_DATA *action = gMsgBoxAction; so accessing NULL pointer leads to +// hang. +// [Solution] gMsgBoxAction is created again inside ShowPostMsgBoxEx, +// reassign gMsgBoxAction to action. +// [Files] TseAdvanced.c +// +// 56 8/06/13 4:02a Premkumara +// [TAG] EIP130529 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] When entered into setup with User mode and On pressing +// "Restore User Defaults" SystemAccess variable is loading and the user +// mode is changes to Admin mode so the controls are editable +// [RootCause] LoadUserDefaultsSilently() function is loading defaults +// for all types of variable +// [Solution] Skipping loading SystemAccess variable while loading +// defaults for user default variable. +// [Files] TseAdvanced.c, AMITSE.sdl, CommonHelper.c +// +// 55 5/23/13 3:44a Premkumara +// [TAG] EIP116315 +// [Category] Improvement +// [Description] Display control prompt string for password control. +// (for String on CHAP secret popup) +// [Files] - AMITSE.sdl +// - CommonHelper.c +// - FakeToken.c +// - AmiTSEStr.uni +// - TseLite\PopupPassword.c +// - uefi2.1\UefiWapper21.c +// - uefi2.0\UefiWapper20.c +// - uefi2.0\HiiCallback.c +// - uefi2.0\hii.h +// - uefi2.0\hii.c +// - TseAdvanced.c +// +// 54 5/22/13 10:22a Arunsb +// [TAG] EIP122907 +// [Category] Improvement +// [Description] For getting name value offset preserving page number +// then it will be easy to find handle of the hii which published name +// value +// +// 53 12/05/12 5:20a Arunsb +// [TAG] EIP106749 +// [Category] New Feature +// [Description] Message box can lock the computer if ConIn not present +// [Files] TseAdvanced.c +// +// 52 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 40 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 50 10/10/12 11:22a Arunsb +// +// 49 10/10/12 11:21a Arunsb +// Properly checked in the EIP98918 +// +// 48 9/24/12 1:17a Premkumara +// [TAG] EIP98918 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] Restore User Defaults causes system hang +// [Files] TseAdvanced.c +// +// 47 9/21/12 12:33p Premkumara +// [TAG] EIP99092 +// [Category] Improvement +// [Description] Tokenize the feature of flushing keyboard after every +// key read +// [Files] AMITSE.sdl, CommonHelper.c, TseAdvanced.c, Action.c +// +// 46 9/17/12 6:08a Rajashakerg +// Updated EIP changes for 2.16 release. +// +// 44 9/03/12 3:12a Premkumara +// [TAG] EIP 96246 +// [Category] Improvement +// [Description] Improvement of a boots override when firmware has a +// BootNext variable +// [Files] AMITSE.sdl, CommonHelper.c, FakeToken.c, AmiTSEStr.uni, +// TseAdvanced.c +// +// 43 5/28/12 6:23a Rajashakerg +// [TAG] EIP80873 +// [Category] Improvement +// [Description] TSE Load/Save defaults without Messaaagebox. +// [Files] TseElinks.h, Tseadvanced.c +// +// 42 5/24/12 9:00a Arunsb +// [TAG] EIP90379 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] UefiBootFailHook asserts when it is trying to call +// MsgBoxDestroy +// [RootCause] Tried to free the NULL pointer +// [Solution] Checked NULL before freeing +// [Files] TseAdvanced.c and MessageBox.c +// +// 41 5/09/12 4:56p Premkumara +// [TAG] EIP87117 +// [Category] Improvement +// [Description] AMITSE should handle partial key support +// [Files] TseAdvanced.c +// +// 40 2/02/12 1:15p Premkumara +// [TAG] EIP75351,75352,75384 +// [Category] Improvement +// [Description] Suppress the warnings from static code analyzer +// [Files] String.c, boot.c, TseAdvanced.c,Time.c, PopupEdit.c, +// MessageBox.c, Label.c, Edit.c, Date.c +// +// 39 1/13/12 1:22a Arunsb +// [TAG] EIP80360 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] HDDSecurity module - Issue in login with TSE, Master +// password disabled +// [RootCause] Cache not updated +// [Solution] Cache updated properly +// [Files] Tseadvanced.c, special.c and uefi21wapper.c +// +// 38 12/08/11 12:30p Rajashakerg +// Updated the file to overcome build errors when build for x32 mode. +// +// 37 12/01/11 7:16p Blaines +// Fix build errors in Uefi2.0 +// +// 36 11/30/11 1:28p Premkumara +// [TAG] EIP75352 +// [Category] Improvement +// [Description] Suppress the warnings from static code analyzer +// [Files] Boot.c, bbs.c, TseAdvanced.c, Special.c, Variable.c, +// TseLiteHelper.c, PopupSel.c, AddBootOption.c, Hii.c, FormBrowser2.c +// +// 35 11/30/11 12:00p Premkumara +// [TAG] EIP75521 +// [Category] Improvement +// [Description] Need to support interactive password controls +// [Files] PopupPassword.c, PopupPassword.h, TsetAdvanced.c +// +// 34 11/30/11 12:25a Premkumara +// [TAG] EIP75351 +// [Category] Improvement +// [Description] Static code analysis.Suppress the warnings from static +// code analyzer +// [Files] String.c, HiiString21.c, TseAdvanced.c, Special.c, +// UefiAction., Time.c, PopupEdit.c, MessageBox.c, Label.c, Edit.c, Date.c +// +// 33 11/16/11 11:21a Madhans +// [TAG] EIP75736 +// [Category] Improvement +// [Description] To avoid flicks when booting UEFI OS for seamless boot. +// [Files] Boot.c +// Tseadvanced.c +// +// 32 11/14/11 2:01p Blaines +// Add function headers for the changes made in TSEAdvanced.c for EIP +// 66860 +// +// 31 11/13/11 12:50p Arunsb +// [TAG] EIP70421 +// [Category] New Feature +// [Description] Support for driver order in TSE +// [Files] AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini, +// boot.c, +// minisetup.h, bbs.c, special.c, special.h, tseadvanced.c, +// addbootoption.c, +// callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h, +// TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h, +// TseElink.h, variable.h, +// setup.h, Boot.vfr and Setup.uni +// +// 30 11/10/11 7:25p Blaines +// [TAG] - EIP 66860 +// [Category]- Function Request +// [Synopsis]- AmiPostManager interface for text entry. +// [Files] - LogoLib.h, AMIPostMgr.h, protocol.c, protocol.h, +// TseAdvanced.c, TseLitehelper.c, TseUefiHii.h, Uefi21Wapper.c +// +// Added new parameter to the function prototype DISPLAY_TEXT_KEY_VALIDATE +// +// Initialize textbox witih default value +// +// 29 11/10/11 12:51a Arunsb +// [TAG] EIP67735 +// [Category] Improvement +// [Description] Zeroing password buffers before freeing +// [Files] mem.c, mem.h, popupedit.c, popuppassword.c and tseadvanced.c +// +// 28 10/31/11 9:41a Rajashakerg +// [TAG] EIP71120,71512 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] BIOS gets stuck in infinite loop On enabling +// TSE_LOAD_OPTION_HIDDEN token,In first boot incorrect devices is +// disabled in Setup & BBS table but in second boot the correct device is +// disabled in both places. +// [Solution] Hidden option handled properly. +// [Files] TseLite\variable.c, TseLite\minisetupext.c, TseAdvanced.c, +// special.c, BootOnly\minisetup.h,BootOnly\boot.c, BootOnly\bbs.c +// +// 27 10/19/11 3:52p Blaines +// [TAG] - EIP 66860 +// [Category]- Function Request +// [Synopsis]- AmiPostManager interface for text entry. Add cursor +// support. +// [Files] - LogoLib.h, AMIPostMgr.h, protocol.c, protocol.h, +// TseAdvanced.c, TseLitehelper.c, TseUefiHii.h, Uefi21Wapper.c, +// uefi20Wapper.c, PopupEdit.c +// +// 26 9/29/11 7:02p Blaines +// [TAG] - EIP 66860 +// [Category]- Function Request +// [Synopsis]- AmiPostManager interface for text entry. +// [Files] - LogoLib.h, AMIPostMgr.h, protocol.c, protocol.h, +// TseAdvanced.c, TseLitehelper.c, TseUefiHii.h, Uefi21Wapper.c +// +// 25 7/19/11 12:30p Arunsb +// [TAG] EIP63895 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] Same message "Save & reset" displayed twice +// [RootCause] guidInfo->GuidFlags.GuidLaunchFilename condition also +// executed after executing guidInfo->GuidFlags.GuidLaunchGuid condition. +// [Solution] Made as any one condition will execute +// [Files] Tseadvanced.c +// +// 24 6/30/11 4:12a Arunsb +// [TAG] EIP57661 +// [Category] New Feature +// [Description] Boot manager algorithm for interaction with Driver +// Health protocol. +// Driver health special controls handled. +// [Files] amitse.cif, amitse.sdl, faketokens.c, amitsestr.uni, +// commonhelper.c, uefisetup.ini, tsedrvhealth.h, +// amivfr.h, minisetupbin.mak, +// hiistring21.c, hiistring20.c, tseadvanced.c, special.c, +// special.h, boot.h, minisetup.h, +// uefi20wapper.c, formbrowser2.c, hii.c, parse.c and +// uefi21wapper.c. +// +// 23 12/29/10 6:51a Mallikarjunanv +// [TAG] EIP 49745 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Hangs on CP06 when Core is update to 4.6.4.1 +// [RootCause] It hangs on CP06 when go to SETUP if updated core to +// 4.6.4.1 and added TSE source and X64 = 0. +// [Solution] Fixed the Stack Frame corruption by passing NULL for Var +// or Flags. +// [Files] TseAdvanced.c +// +// 22 12/28/10 6:09p Mallikarjunanv +// [TAG] EIP41615 +// [Category] New Feature +// [Description] Added the file browser support for the Add boot option +// reated controls +// [Files] AmiVfr.h, AmiTse.sdl, AmiTseStr.uni, CommonHelper.c, +// Faketokens.c, TseElinks.h, EdkHelper.h, minisetup.h, TseAdvanced.c, +// AddBootOption.c +// +// 21 12/28/10 12:54p Mallikarjunanv +// [TAG] EIP 47260 +// [Category] Improvement +// [Description] Updated with TSE_NVRAM_DEFAULTS_SUPPORT token name +// [Files] TseAdvanced.sdl, TseAdvanced.c +// +// 20 12/24/10 1:15p Mallikarjunanv +// [TAG] EIP 47932 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] Screen changing to Normal TSE from GTSE if the boot fails +// rom the selected boot option +// [RootCause] Style Initilization is not done before BootLaunchFailed . +// [Solution] Fixed by updating style Initilization BootLaunchFailed. +// +// [Files] TseAdvanced.c +// +// 19 12/22/10 5:28a Mallikarjunanv +// [TAG] EIP47260 +// [Category] Improvement +// [Description] To Build TSE sources without NVRAM module support. +// [Files] TseAdvanced.c, TseAdvanced.mak, TseAdvanced.sdl +// +// 18 11/18/10 7:13p Blaines +// [TAG] - EIP 47962 +// [Category]- Defect +// [Symptom]- Post Manager's DisplayMsgBox displays a corrupted screen +// When the French or Japanese langues are selected and a call is made to +// DisplayMsgBox, the screen that is displayed is corrupted +// +// [Rootcause] +// The bounding box area of the message box is drawn, which may not span +// previous screen redraws. +// Therefore, artifacts from previous screen displays may appear. +// [Solution]- Clear the screen before drawing message box to clear +// artifacts from previous screen redraws. +// [Files] - TseAdvanced.c, AMIPostMgr.h, +// +// 17 9/29/10 1:36p Blaines +// Function ShowPostMsgBoxEx was updated to allow a buttonless messages +// box to be displayed without a legend. +// +// 16 9/16/10 8:38p Madhans +// Update for TSE 2.10. Refer Changelog.log for more details. +// +// 33 8/31/10 11:32a Blaines +// Fix for ShowPostProgress function not calling gAction.Destroy, casuing +// system to appear to hang and to not be responsive to input. +// +// 32 8/10/10 7:13p Madhans +// EIP 40555 : To avoid Compilation issues with Fareast Windows. +// +// 31 6/22/10 5:31a Mallikarjunanv +// EIP:39102 - Handling Scrren corruption if Launching shell from file +// system fails +// +// 30 6/14/10 7:08p Madhans +// To keep the NVRAM defaults only for Aptio 4.x +// +// 29 6/08/10 5:13p Blaines +// Fix for EIP #39416 - PostManagerDisplayProgress does not update +// message. +// +// 28 5/19/10 4:11p Blaines +// Added parameter error checking to the function ShowPostMsgBoxEx +// +// 27 4/22/10 6:21p Blaines +// Fix build error when TSE_USE_AMI_EFI_KEYCODE_PROTOCOL token +// enabled +// +// In function ShowPostMsgBoxEx, set property msgbox->Legend before +// calling gMsgBox.Initialize. +// +// 26 4/20/10 6:15p Blaines +// Add MessageBox Hotkey support +// +// 25 4/15/10 4:49p Blaines +// In function ShowPostMsgBox, +// check if pSelection is null before it attempts to use it. +// +// 24 4/07/10 6:24p Madhans +// To Fix the build issue. +// +// 23 3/30/10 4:46p Blaines +// EIP 36704 : Fix for Making sure to make the Variable to NULL after it +// is Freed up. +// +// 22 3/26/10 6:12p Madhans +// EIP 36704 : Fix for Making sure to make the Variable to NULL after it +// is Freed up. +// +// 21 3/26/10 6:01p Madhans +// Fix in Load Defaults from NVRAM Defaults, To make work for Runtime +// pages. Before this fix it only work for Offline parsing Data and For +// Runtime pages the defaults are broken. +// +// 20 3/23/10 5:11p Blaines +// Add support for new PostManager Extentions +// +// 19 3/19/10 2:39p Madhans +// Support to Load Defaults from NVRAM Defaults. +// +// 18 2/26/10 11:09a Madhans +// to resove build errors;. +// +// 17 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 16 2/15/10 10:13p Madhans +// For EDK Nt32 version +// +// 15 2/04/10 11:19p Madhans +// Fix for Password with AMIKeyCode ON without EfiKey or Scancode support. +// +// 14 1/18/10 2:09a Mallikarjunanv +// EIP-28501: Updated for Keyboard scancode as password. Added a new Token +// SETUP_STORE_KEYCODE_PASSWORD to support the EFI key or Scan code as +// password +// +// 13 1/09/10 4:51a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 12 10/30/09 9:47a Mallikarjunanv +// EIP-28551 : Fixed TSE 2.0 Build error releated to +// SETUP_STORE_EFI_KEY_PASSWORD and TSE_USE_AMI_EFI_KEYCODE_PROTOCOL +// +// 11 9/17/09 9:05a Sudhirv +// EIP:25799 - Remove Load Driver Option from TSE 2.x as it will be +// handled from Core +// +// 10 9/15/09 9:41a Sudhirv +// updated with support for SETUP_OEM_SPECIAL_CONTROL_SUPPORT and the +// support for Add Del boot option support +// +// 9 8/19/09 6:33p Madhans +// IsToggleStateKey Function added +// +// 8 8/19/09 10:42a Mallikarjunanv +// Fixed the issue regarding loading defaults by desabling the chipset +// menu. +// +// 7 8/13/09 7:37a Mallikarjunanv +// eip:24971 - supporting tse features without tse sources +// +// 6 7/30/09 7:48a Mallikarjunanv +// updated the code to move the exit page option elinks to Tse Binary +// +// 5 7/20/09 1:17p Mallikarjunanv +// updated the return values +// +// 4 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 3 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 2 6/05/09 11:55a Blaines +// Fix screen corruption for GTSE +// +// 1 6/04/09 8:05p Madhans +// +// 3 5/07/09 10:36a Madhans +// Changes after Bin module +// +// 2 4/29/09 9:02p Madhans +// Bug Fixes after unit Testing.. +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: TseAdvanced.c +// +// Description: This file contains code to handle the Advanced TSE Operations +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" +#include "Special.h" +#include "TseElinks.h" + +////////////////////////////////////////////////// +/////// INTERNAL VARIABLE DECLARATION +////////////////////////////////////////////////// +///Exit Page options info. from Elink... +extern EXIT_PAGE_OPTIONS gExitPageOptions[END_OF_EXIT_PAGE_OPTION_LIST]; +extern APPLICATION_DATA *gApp; +extern UINTN gSaveUserMsgBox; +extern UINTN gLoadUserMsgBox; +extern UINTN gBootLaunchFailedMsgBox; +extern UINTN gInvalidPasswordFailMsgBox; + + +#define AMITSE_PRINT_SCREEN_PRESS_GUID \ +{ 0x71030b81, 0xf72, 0x4b48, 0xb5, 0xe8, 0xbc, 0xcd, 0x51, 0x78, 0x60, 0x9e } + + +#define CONSTRUCT_DEFAULTS_FIRST_BOOT_GUID \ +{ 0xc5912ed9, 0x83c2, 0x4bff, 0x99, 0x36, 0x23, 0x1f, 0xeb, 0x85, 0xf3, 0xe8 } + +MSGBOX_DATA *gInfoBox = NULL; +UINT32 gtempCurrentPage; +////////////////////////////////////////////////// +/////// INTERNAL FUNCTIONS DECLARATION +////////////////////////////////////////////////// +///Exit page options handling using Elinks... +VOID HandleSaveAndExit(VOID); +VOID HandleExitApplication(VOID); +VOID HandleSaveAndReset(VOID); +VOID HandleResetSys(VOID); +VOID HandleSaveWithoutExit(VOID); +VOID HandleLoadPreviousValues(VOID); +VOID HandleLoadOptimalDefaults(VOID); +VOID HandleSaveUserDefaults(VOID); +VOID HandleRestoreUserDefaults(VOID); +VOID HandleBootAddBootOption(VOID); +VOID HandleDriverAddDriverOption(VOID); + +//EIP-41615: Start +VOID HandleLaunchFileSystem(VOID); +VOID HandleLaunchFileSystemDriver(VOID); +//EIP-41615: End + +VOID SaveUserDefaults( VOID ); +VOID LoadUserDefaults( VOID ); +BOOLEAN CheckIsAllowedPasswordChar(CHAR16 Char); +BOOLEAN CheckIsAllowedChar(CHAR16 Char); + +////////////////////////////////////////////////// +/////// EXTERN FUNCTIONS DECLARATION +////////////////////////////////////////////////// +extern VOID *UefiCreateStringTemplate(UINT16 Token); +extern EFI_STATUS ReadImageResource(EFI_HANDLE ImageHandle, EFI_GUID *pGuid, VOID **ppData, UINTN *pDataSize); +extern BOOLEAN IsLoadSysteAccessOnUserDefault(VOID); +extern BOOLEAN IsSupportDefaultForStringControl (VOID); +EFI_STATUS GetSetDefaultsFromControlPtr(NVRAM_VARIABLE *optimalDefaultlist, NVRAM_VARIABLE *failSafeDefaultlist); +UINTN GetANSIEscapeCode(CHAR16 *String,UINT8 *Bold,UINT8 *Foreground, UINT8 *Background); +VOID OEMSpecialGotoSelect(UINT16 value); +BOOLEAN IsShowPromptStringAsTitle(VOID);//EIP-116315 password window title string +extern BOOLEAN TSEPwdSavetoNvram(VOID); + +typedef UINT16 VAR_SIZE_TYPE; +#pragma pack(push) +#pragma pack(1) +typedef struct{ + UINT32 signature; + VAR_SIZE_TYPE size; + UINT32 next:24; + UINT32 flags:8; +// guid and name are there only if NVRAM_FLAG_DATA_ONLY is not set +// UINT8 guid; +// CHAR8 or CHAR16 name[...]; +// UINT8 data[...]; +// if NVRAM_FLAG_EXT_HEDER is set +// UINT8 extflags; +// UINT8 extdata[...]; +// VAR_SIZE_TYPE extsize; +}NVAR; +#pragma pack(pop) + +typedef struct { + UINT8 *NvramAddress; + UINTN NvramSize; + EFI_GUID* NvramGuidsAddress; + UINT8 *pEndOfVars, *pFirstVar; + INT16 NextGuid; + VAR_SIZE_TYPE LastVarSize; + NVAR *pLastReturned; + UINT8 Flags; +} NVRAM_STORE_INFO; + + +VOID NvInitInfoBuffer(IN NVRAM_STORE_INFO *pInfo, UINTN HeaderSize, UINT8 Flags); +EFI_STATUS NvGetVariable( + IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, OUT VOID *Data, + IN NVRAM_STORE_INFO *pInfo, OUT UINT8 *Flags +); +BOOLEAN IsTseLoadPasswordOnDefaults(); + +#define NVRAM_STORE_FLAG_NON_VALATILE 1 + +#define DEFAULTS_GUID {0x4599d26f, 0x1a11, 0x49b8, 0xb9, 0x1f, 0x85, 0x87, 0x45, 0xcf, 0xf8, 0x24} + +EFI_GUID DefaultsGuid = DEFAULTS_GUID; +VOID SetDrvHealthHandleAndCtrlCount (UINT16); +VOID DoDriverHealthOperation (CONTROL_INFO *, UINT16); +BOOLEAN FlushKeysAfterRead(void); +//EIP-96246 starts +EFI_STATUS ShowBootOverrideSelectOption (VOID); +BOOLEAN IsBootOverrideBootNextSupport (VOID); +#define BOOT_OVERRIDE_OPTION_MENU_COUNT 3 +//EIP-96246 Ends + +#ifndef KEY_STATE_EXPOSED +#define KEY_STATE_EXPOSED 0x40 //EIP-87117 +#endif + +//EIP 162981 Providing defaults through sdl tokens +BOOLEAN DefaultSetupPwdAtFirstBootOnly (void); +BOOLEAN TseDefaultSetupPasswordSupported(VOID); +EFI_STATUS GetDefaultPassword (UINT32 PasswordInstalled, void **DefaultPassword); + + +BOOLEAN TseLiteIsSpecialOptionList(CONTROL_DATA *ControlData) +{ + // For TSE Advanced we papulate and add the control dynamically. + // So it is not TSE lite Special control + // TSE Lite special controls are patched instad of removing and adding. + return FALSE; +} + + +// +//---------------------------------------------------------------------------- +// Procedure: BootUpdateOrder +// +// Description: Function to update the boot/driver order +// +// Input: UINT16 *buffer +// UINT32 *offset +// UINTN *size +// VOID **realBuffer +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID BootUpdateOrder(UINT16 *buffer,UINT32 *offset,UINTN *size, VOID **realBuffer) +{ + UINTN i, j, optionNumber = *offset / sizeof(UINT16); + UINT16 index = *(UINT16 *)buffer; + UINT16 newOption = index; + UINT16 oldOption, *optionList; + +#if TSE_SEPERATE_EFI_LEGACY_OPTIONS + UINT16 *OrgOptionList; + OrgOptionList = EfiLibAllocateZeroPool( *size ); + MemCopy( OrgOptionList, gVariableList[VARIABLE_ID_BOOT_ORDER].Buffer, *size ); +#endif + + *realBuffer = EfiLibAllocateZeroPool( *size ); + if (NULL == *realBuffer) + { + return; + } + *offset = 0; + MemCopy( *realBuffer, gVariableList[VARIABLE_ID_BOOT_ORDER].Buffer, *size ); + + optionList = (UINT16 *)*realBuffer; + oldOption = optionList[ optionNumber ]; + + if ( newOption == oldOption ) + return; + + if(DISABLED_BOOT_OPTION == newOption) + { + for (i = optionNumber, j = 0; i < gBootOptionCount; i++) + { + if ((i+1) < gBootOptionCount) + { + if ( (CheckHiddenforBootDriverOption (optionList [i + 1], BOOT_ORDER_OPTION)) && gLoadOptionHidden ) + { + j ++; + continue; + } + optionList [i] = optionList [i + 1]; + } + else + optionList [i-j] = newOption; // or DISABLED_BOOT_OPTION; boot order will be like active boot option + } //then hidden options, so hidden option will always maintain at same place(last positions). + } + else if (DISABLED_BOOT_OPTION == oldOption) + { + //Find newOption's position + for(i=0;i +//---------------------------------------------------------------------------- +// Procedure: DriverUpdateOrder +// +// Description: Function to update the driver order +// +// Input: UINT16 *buffer +// UINT32 *offset +// UINTN *size +// VOID **realBuffer +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID DriverUpdateOrder (UINT16 *buffer,UINT32 *offset,UINTN *size, VOID **realBuffer) +{ + UINTN i, j, optionNumber = *offset / sizeof(UINT16); + UINT16 index = *(UINT16 *)buffer; + UINT16 newOption = index; + UINT16 oldOption, *optionList; + + *realBuffer = EfiLibAllocateZeroPool (*size); + if (NULL == *realBuffer) + { + return; + } + *offset = 0; + + MemCopy (*realBuffer, gVariableList [VARIABLE_ID_DRIVER_ORDER].Buffer, *size); + optionList = (UINT16 *)*realBuffer; + oldOption = optionList [optionNumber]; + + if (newOption == oldOption) + return; + + if (DISABLED_BOOT_OPTION == newOption) + { + for (i = optionNumber, j = 0; i < gDriverOptionCount; i++) + { + if ((i+1) < gDriverOptionCount) + { + if ( (CheckHiddenforBootDriverOption (optionList [i + 1], DRIVER_ORDER_OPTION)) && gLoadOptionHidden ) + { + j ++; + continue; + } + optionList [i] = optionList [i + 1]; + } + else + optionList [i-j] = newOption; // or DISABLED_BOOT_OPTION; boot order will be like active boot option + } //then hidden options, so hidden option will always maintain at same place(last positions). + } + else if (DISABLED_BOOT_OPTION == oldOption) + { + //Find newOption's position + for (i = 0; i < gDriverOptionCount; i ++) + { + if (newOption == optionList [i]) + break; + } + if (i < gDriverOptionCount)//New option found + { + //Move new option to the last of enabled devices + for (j = i; j < gDriverOptionCount; j ++) + { + if (DISABLED_BOOT_OPTION != optionList [j+1]) + optionList [j] = optionList [j+1]; + else + { + optionList [j] = newOption; + break; + } + } + } + else//New option not enabled + { + //Replace first disabled with new one + for (i = 0; i < gDriverOptionCount; i ++) + { + if (DISABLED_BOOT_OPTION == optionList [i]) + break; + } + optionList [i] = newOption; + } + } + else + { + optionList[optionNumber] = newOption; + for (i = 0; i < gDriverOptionCount; i ++) + { + if(i == optionNumber) + continue; + if(newOption == optionList[i]) + { + optionList[i] = oldOption; + break; + } + } + } +} + +/// functions to handle the exit page options +VOID HandleSaveAndExit() +{ + gApp->Quit = SaveAndExit(); +} + +VOID HandleExitApplication() +{ + gApp->Quit = ExitApplication(); +} + +VOID HandleSaveAndReset() +{ + gApp->Quit = SaveAndReset(); +} + +VOID HandleResetSys() +{ + gApp->Quit = ResetSys(); +} + +VOID HandleSaveWithoutExit() +{ + SaveWithoutExit(); +} + +VOID HandleLoadPreviousValues() +{ + LoadPreviousValues( TRUE ); +} + +VOID HandleLoadOptimalDefaults() +{ + LoadOptimalDefaults(); +} + +VOID HandleSaveUserDefaults() +{ + SaveUserDefaults(); +} + +VOID HandleRestoreUserDefaults(VOID) +{ + LoadUserDefaults(); +} + +VOID HandleBootAddBootOption(VOID) +{ + TseBootAddBootOption(); +} + +//EIP70421 & 70422 +VOID HandleDriverAddDriverOption(VOID) +{ + TseDriverAddDriverOption(); +} + +// EIP-41615: Function to handle selection of the file system +VOID HandleLaunchFileSystem(VOID) +{ + TseLaunchFileSystem(VARIABLE_ID_ADD_BOOT_OPTION); +} + +//EIP70421 & 70422 +VOID HandleLaunchFileSystemDriver(VOID) +{ + TseLaunchFileSystem(VARIABLE_ID_ADD_DRIVER_OPTION); +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SubMenuAmiCallback +// +// Description: Function implemented to handle the Exit page +// options using Elinks. +// +// Input: UINT16 value - index of the exit page option +// +// Output: TRUE +// +//---------------------------------------------------------------------------- +// +BOOLEAN _SubMenuAmiCallback( UINT16 value ) +{ + UINT8 idx=0; + + for(idx=0;idx<(sizeof(gExitPageOptions)/sizeof(EXIT_PAGE_OPTIONS));idx++) + { + if( gExitPageOptions[idx].OptIdx == END_OF_EXIT_PAGE_OPTION_LIST ) { + break; + } + else if(value == gExitPageOptions[idx].OptIdx) { + gExitPageOptions[idx].ExitPageCallBack(); + break; + } + } + + return TRUE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SubMenuHandleSpecialOp +// +// Description: Sub menu handle for Special operations. +// +// Input: Submenu data +// +// Output: Bool - Interpreted by the Caller. +// +//---------------------------------------------------------------------------- +// +BOOLEAN _SubMenuHandleSpecialOp( SUBMENU_DATA *submenu ) +{ + BOOLEAN status = FALSE; + BOOLEAN BootLaunchFailed = FALSE; + BOOLEAN StyleExitDone = FALSE; + UINT16 value; + GUID_INFO *guidInfo; + EFI_STATUS Status; + +// EIP:39412 - START + VOID *ScreenBuf; + + //Save the screen buffer to restore later if required + ScreenBuf = SaveScreen(); +// EIP:39412 - END + + value = SpecialGetValue( (CONTROL_DATA *)submenu, &guidInfo ); + if ( value != (UINT16)-2 ) + { + if ( guidInfo->GuidFlags.GuidLaunchCallback ) + { + switch ( guidInfo->GuidKey ) + { + case GUID_KEY_BOOT_NOW: + //EIP-96246 Starts + if ( !gResetRequired && IsBootOverrideBootNextSupport () ) + { + UINT16 *pBootNext = NULL; + UINTN size = 0; + pBootNext = (UINT16 *)VarGetNvramName(L"BootNext", &gEfiGlobalVariableGuid, NULL, &size); + if ( pBootNext && (size == sizeof(UINT16)))//If BootNext Variable is present + { + Status = ShowBootOverrideSelectOption ();//EIP-96246 To show Override menu option for BootNext variable + if ( Status != EFI_SUCCESS )//Exit menu and retain in override menu + { + status = TRUE; + break; + } + } + if(pBootNext) + MemFreePointer((void **) &pBootNext); + } + //EIP-96246 Ends + if(!gResetRequired) + { + if(!gDoNotBoot) + { + gApp->ClearScreen = TRUE; + //EIP 75736 + StyleExit(); + if (gST->ConOut != NULL) + { + //Disable cursor, set desired attributes and clear screen + gST->ConOut->EnableCursor( gST->ConOut, FALSE ); + gST->ConOut->SetAttribute( gST->ConOut, (EFI_BACKGROUND_BLACK | EFI_WHITE)); + gST->ConOut->ClearScreen( gST->ConOut); + } + + BootLaunchBootNow( value, gShowAllBbsDev/*SETUP_SHOW_ALL_BBS_DEVICES*/ ); + StyleInit(); + } + } + else + { + gApp->Quit = SaveAndReset(); + } + status = TRUE; + break; + + case GUID_KEY_AMI_CALLBACK: + status = _SubMenuAmiCallback( value ); + break; + + case GUID_KEY_ERROR_MANAGER: + { + UefiSpecialGuidCallback(submenu->ControlData.ControlHandle, value, &guidInfo->GuidValue); + } + break; +#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT + case GUID_KEY_OEM_CONTROL: + { + OEMSpecialGotoSelect(value); + break; + } +#endif + case GUID_KEY_IDE_SECURITY: + { + UINTN size; + IDE_SECURITY_CONFIG *ideSecConfig; + + + //Update mem copy of the IDE sec variable + size = 0; + ideSecConfig = VarGetVariable( VARIABLE_ID_IDE_SECURITY, &size ); + //EIP-75352 Suppress the warnings from static code analyzer + if (NULL == ideSecConfig) { + break; + } + + TSEIDEUpdateConfig(ideSecConfig, value); + + VarSetValue( VARIABLE_ID_IDE_SECURITY, 0, size, ideSecConfig ); + MemFreePointer((VOID **)&ideSecConfig); + } + break; + case GUID_KEY_BBS_ORDER: + { + BBSUpdateBootData(value); + VarSetValue(VARIABLE_ID_LEGACY_GROUP_INFO, 0, sizeof(UINT16), &(gCurrLegacyBootData->LegacyDevCount)); + } + break; + //EIP 57661 Start + case GUID_KEY_DRIVER_HEALTH: + { + SetDrvHealthHandleAndCtrlCount (value); + break; + } + case GUID_KEY_DRV_HEALTH_CTRL_COUNT: + { + DoDriverHealthOperation ((VOID *)&((CONTROL_DATA *)submenu)->ControlData, value); + break; + } + //EIP 57661 End + default: + break; + } + } + else + { + EFI_STATUS Status = EFI_UNSUPPORTED; + + if ( guidInfo->GuidFlags.GuidLaunchGuid ) + { + if(!gResetRequired) + { + if(!gDoNotBoot) + { + gApp->ClearScreen = TRUE; + //EIP 75736 + StyleExit(); + if (gST->ConOut != NULL) + { + //Disable cursor, set desired attributes and clear screen + gST->ConOut->EnableCursor( gST->ConOut, FALSE ); + gST->ConOut->SetAttribute( gST->ConOut, (EFI_BACKGROUND_BLACK | EFI_WHITE)); + gST->ConOut->ClearScreen( gST->ConOut); + } + StyleExitDone = TRUE; + Status = BootLaunchGuid( &guidInfo->GuidValue ); + if ( ! EFI_ERROR( Status ) ) + { + gApp->ClearScreen = TRUE; + status = TRUE; + } + else + BootLaunchFailed = TRUE; + } + } + else + { + gApp->Quit = SaveAndReset(); + status = TRUE; + } + } + + if (( guidInfo->GuidFlags.GuidLaunchFilename ) && (FALSE == status)) + { + if(!gResetRequired) + { + if(!gDoNotBoot) + { + CHAR16 FileName[VARIABLE_NAME_LENGTH]; + UINTN i = 0, j; + while(guidInfo->GuidName[i]) + { + j=0; + for(;guidInfo->GuidName[i];i++) + { + if(L'|' == guidInfo->GuidName[i]) + { + i++; + break; + } + FileName[j] = guidInfo->GuidName[i]; + j++; + } + FileName[j] = 0; + if(!StyleExitDone){ + gApp->ClearScreen = TRUE; + //EIP 75736 + StyleExit(); + if (gST->ConOut != NULL) + { + //Disable cursor, set desired attributes and clear screen + gST->ConOut->EnableCursor( gST->ConOut, FALSE ); + gST->ConOut->SetAttribute( gST->ConOut, (EFI_BACKGROUND_BLACK | EFI_WHITE)); + gST->ConOut->ClearScreen( gST->ConOut); + } + + StyleExitDone = TRUE; + } + Status = BootLaunchFilename( FileName ); + if ( ! EFI_ERROR( Status ) ) + { + gApp->ClearScreen = TRUE; + status = TRUE; + BootLaunchFailed = FALSE; + break; + }else + BootLaunchFailed = TRUE; + } + //BootLaunchFailed = TRUE; + } + } + else { + gApp->Quit = SaveAndReset(); + status = TRUE; + } + } + + // EIP:47932 - Start + if(StyleExitDone) + StyleInit(); + // EIP:47932 - End + +// EIP:39412 - START + if ( BootLaunchFailed ){ + + //Restore the Original screen before boot launch + RestoreScreen( ScreenBuf ); + CallbackShowMessageBox( (UINTN)gBootLaunchFailedMsgBox, MSGBOX_TYPE_OK ); + } + else { + //In case Boot Launch not failed, free the saved screen buffer + MemFreePointer((VOID **) &ScreenBuf); + } +// EIP:39412 - END + } + } + + + + + + return status; + +} + +#ifdef TSE_FOR_APTIO_4_50 +// +//---------------------------------------------------------------------------- +// Procedure: InitApplicationData +// +// Description: function to initialize the application data +// +// Input: EFI_HANDLE ImageHandle +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS InitApplicationData(EFI_HANDLE ImageHandle) +{ + EFI_STATUS Status = EFI_SUCCESS; +#if APTIO_4_00 || SETUP_USE_GUIDED_SECTION || TSE_FOR_64BIT + VOID *pSection; + UINTN SectionSize; + EFI_GUID dataGuid = MINI_SETUP_DATA_GUID; + + Status=ReadImageResource(ImageHandle,&dataGuid,&pSection,&SectionSize); + if ( EFI_ERROR( Status ) ) { + return Status; + } + gApplicationData = (UINT8 *)pSection + sizeof(EFI_GUID); +#else +#ifdef USE_DEPRICATED_INTERFACE + + // Read in the data files from the GUIDed section + Status = LoadGuidedDataDriverLib( gImageHandle, dataGuid, &gApplicationData ); + if ( EFI_ERROR( Status ) ) + { + return Status; + } +#else +#ifndef STANDALONE_APPLICATION + gApplicationData = (UINT8 *)&_SetupPackage; +#else + gApplicationData = (UINT8 *)&DummySetupData; +#endif //#ifndef STANDALONE_APPLICATION +#endif //#ifdef USE_DEPRICATED_INTERFACE +#endif //#if APTIO_4_00 || SETUP_USE_GUIDED_SECTION || TSE_FOR_64BIT + + return Status; +} + +#endif + +// +//---------------------------------------------------------------------------- +// Procedure: LoadUserDefaultsSilently +// +// Description: Function to load the user set defaults Silently +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID LoadUserDefaultsSilently(VOID) +{ + NVRAM_VARIABLE *nvramVar, *tmpPtr; + UINTN i = 0; + UINT8 *buffer; + UINT16 size; + UINT32 count; +//EIP-98918 Starts + VARIABLE_INFO *varInfo = NULL; + EFI_GUID sysAccessGuid = SYSTEM_ACCESS_GUID; + + VARIABLE_INFO *InnerLoopvarInfo = NULL; + UINT32 InnerLoop; + BOOLEAN MatchFound = FALSE; +//EIP-98918 Ends + nvramVar = &gVariableList [VARIABLE_ID_USER_DEFAULTS]; + if ( ( nvramVar->Size == 0 ) || ( nvramVar->Buffer == NULL ) ) + return; + + buffer = nvramVar->Buffer; + count = *(UINT32 *)buffer; + buffer += sizeof(UINT32); + + for ( i = 0; i < count; i++ ) + { + varInfo = VarGetVariableInfoIndex (*(UINT32 *)buffer);//EIP-98918 + tmpPtr = &gVariableList[ *(UINT32 *)buffer ]; + + if ( IsLoadSysteAccessOnUserDefault() ) //EIP-130529 Skip loading SYSTEM_ACCESS variable for user defaults + { + if ( !EfiStrCmp(varInfo->VariableName, L"SystemAccess") && EfiCompareGuid(&sysAccessGuid, &(varInfo->VariableGuid)) )//EIP-UserDefault - Skip to load SystemAccess variable on pressing Restore User Defaults + { + buffer += sizeof(UINT32); + size = *(UINT16 *)buffer; + buffer += sizeof(UINT16); + buffer += (sizeof (EFI_GUID) + sizeof (CHAR16) * VARIABLE_NAME_LENGTH); //Move to next variable + buffer += size; + continue; + } + } + + buffer += sizeof(UINT32); + size = *(UINT16 *)buffer; + buffer += sizeof(UINT16); + +//EIP-98918 Starts + if ( + (size == tmpPtr->Size) && + (!MemCmp (&varInfo->VariableGuid, buffer, sizeof (EFI_GUID) )) && + (!EfiStrCmp (varInfo->VariableName, (CHAR16 *)(buffer + sizeof (EFI_GUID)) )) + ) + { + buffer += (sizeof (EFI_GUID) + sizeof (CHAR16) * VARIABLE_NAME_LENGTH); + MemCopy (tmpPtr->Buffer, buffer, size); + } + else //If any variable deleted then order wont be same, so trying in all possible variable and loading the user defaults + { + MatchFound = FALSE; + for (InnerLoop = 0; InnerLoop < gVariables->VariableCount; InnerLoop ++) + { + InnerLoopvarInfo = VarGetVariableInfoIndex (InnerLoop); + if ( NULL != InnerLoopvarInfo) + { + if ( + (size == InnerLoopvarInfo->VariableSize) && + (!MemCmp (&InnerLoopvarInfo->VariableGuid, buffer, sizeof(EFI_GUID))) && + (!EfiStrCmp (InnerLoopvarInfo->VariableName, (CHAR16 *)(buffer + sizeof (EFI_GUID)) )) + ) + { + buffer += (sizeof(EFI_GUID)+ sizeof(CHAR16) * VARIABLE_NAME_LENGTH); + tmpPtr = &gVariableList [InnerLoop]; + MemCopy (tmpPtr->Buffer, buffer, size); + MatchFound = TRUE; + break; + } + } + } + if (FALSE == MatchFound) + { + SETUP_DEBUG_TSE ("\nERROR : Variable %s has been modified so skipping the USER default loading for this variable alone.", varInfo->VariableName ); + buffer += (sizeof(EFI_GUID)+ sizeof(CHAR16) * VARIABLE_NAME_LENGTH); + } + } +//EIP-98918 Ends + buffer += size; + } + LoadedUserDefaultsHook(); + gResetRequired = TRUE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: LoadUserDefaults +// +// Description: Function to load the user set defaults +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID LoadUserDefaults( VOID ) +{ + + if ( CallbackShowMessageBox( (UINTN)gLoadUserMsgBox, MSGBOX_TYPE_YESNO ) != MSGBOX_YES ) + return; + + LoadUserDefaultsSilently(); +} +// +//---------------------------------------------------------------------------- +// Procedure: SaveUserDefaultsSilently +// +// Description: Function to save the user set defaults Silently +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID SaveUserDefaultsSilently(VOID) +{ + NVRAM_VARIABLE *nvramVar, *tmpPtr; + UINT32 i,count; + UINT8 *buffer; + VARIABLE_INFO *varInfo = NULL; + + nvramVar = &gVariableList[ VARIABLE_ID_USER_DEFAULTS ]; + if ( ( nvramVar->Size != 0 ) || ( nvramVar->Buffer != NULL ) ) + MemFreePointer( (VOID **)&(nvramVar->Buffer) ); + + nvramVar->Size = sizeof(UINT32); + count = 0; + for ( i = 0; i < gVariables->VariableCount; i++ ) { + if ( (i == VARIABLE_ID_USER_DEFAULTS) || + (i == VARIABLE_ID_ERROR_MANAGER) || + (i == VARIABLE_ID_BOOT_ORDER) || + (i == VARIABLE_ID_BBS_ORDER) || + (i == VARIABLE_ID_BOOT_MANAGER) || + (i == VARIABLE_ID_BOOT_NOW)) + continue; + nvramVar->Size += sizeof(UINT32) + sizeof(UINT16) + sizeof (EFI_GUID) + (sizeof (CHAR16) * VARIABLE_NAME_LENGTH) + gVariableList[ i ].Size; + count++; + } + + buffer = EfiLibAllocateZeroPool( nvramVar->Size ); + if ( buffer == NULL ) + return; + + nvramVar->Buffer = buffer; + + *(UINT32 *)buffer = count; + buffer += sizeof(UINT32); + + for ( i = 0, tmpPtr = gVariableList; i < gVariables->VariableCount; i++, tmpPtr++ ) + { + if ( (i == VARIABLE_ID_USER_DEFAULTS) || + (i == VARIABLE_ID_ERROR_MANAGER) || + (i == VARIABLE_ID_BOOT_ORDER) || + (i == VARIABLE_ID_BBS_ORDER) || + (i == VARIABLE_ID_BOOT_MANAGER) || + (i == VARIABLE_ID_BOOT_NOW)) + continue; + *(UINT32 *)buffer = i; + buffer += sizeof(UINT32); + *(UINT16 *)buffer = (UINT16)tmpPtr->Size; + buffer += sizeof(UINT16); + + varInfo = VarGetVariableInfoIndex (i); + MemCopy (buffer, &varInfo->VariableGuid, sizeof (EFI_GUID)); + buffer += sizeof (EFI_GUID); + + EfiStrCpy ((CHAR16 *)buffer, varInfo->VariableName); +// MemCopy( buffer, varInfo->VariableName, sizeof(CHAR16) * VARIABLE_NAME_LENGTH ); + buffer += sizeof(CHAR16) * VARIABLE_NAME_LENGTH; + + MemCopy( buffer, tmpPtr->Buffer, tmpPtr->Size ); + buffer += tmpPtr->Size; + } + + VarSetNvram( VARIABLE_ID_USER_DEFAULTS, nvramVar->Buffer, nvramVar->Size ); + +} +// +//---------------------------------------------------------------------------- +// Procedure: SaveUserDefaults +// +// Description: Function to save the user specified defaults +// +// Input: VOID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID SaveUserDefaults( VOID ) +{ + + if ( CallbackShowMessageBox( (UINTN)gSaveUserMsgBox, MSGBOX_TYPE_YESNO ) != MSGBOX_YES ) + return; + + SaveUserDefaultsSilently(); +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetANSIEscapeCode +// +// Description: Return Size of Escape Code and gets the FG,BGColor. +// +// Input: CHAR16 *String, +// UINT8 *Bold, +// UINT8 *Foreground, +// UINT8 *Background +// +// Output: UINTN - Escape code length (in CHAR16), 0 if not an escape code +// Bold, Forground, Background - Filled with -1 if value not found in Escape Code +// +//---------------------------------------------------------------------------- +// +UINTN GetANSIEscapeCode(CHAR16 *String,UINT8 *Bold,UINT8 *Foreground, UINT8 *Background) +{ + CHAR16 *TempStr; + UINTN i; + BOOLEAN Bld=FALSE,Fg=FALSE; + UINT8 Num=0xff; + + //Is ESC Code + if((String[0]==L'\x1b')&&(String[1]==L'[')) + { + TempStr = &String[2]; + + // ESC [ x ; x x ; x x m = Color esc code format + // 0 1 2 3 4 5 6 7 8 9 + // Check till Code m or Upto 10 char + + for(i=2;(*TempStr!=L'm')&&(i<10);i++,TempStr++) + { + if(*TempStr == L';') + { + if(!Bld) + { + *Bold = Num; + Num = 0xFF; + Bld = TRUE; + } + else if(!Fg) + { + *Foreground = Num; + Num = 0xFF; + Fg = TRUE; + } + } + else + { + if(Num==0xFF) + Num =(UINT8)(*TempStr-L'0'); + else + Num = (Num*10)+(UINT8)(*TempStr-L'0'); + } + if(TempStr[1]==L'm') + *Background=Num; + } + if(*TempStr==L'm') + return (TempStr-String); + } + + return 0; +} + +// +//---------------------------------------------------------------------------- +// Procedure: SkipEscCode +// +// Description: function to perform the esc key operation +// +// Input: CHAR16 *string +// +// Output: string +// +//---------------------------------------------------------------------------- +// +CHAR16 *SkipEscCode(CHAR16 *String) +{ + CHAR16 *TempString; + UINTN i=0,j=0; + + //EIP-75351 Suppress the warnings from static code analyzer + if (NULL == String) { + return NULL; + } + // Check For escape Code and remove that from the string + TempString = StrDup(String); + while(String[i]) + { + if((String[i] == 0x001b) && (String[i+1] == L'[')) // ESC Code + { + while(String[i] != L'm')i++; + i++; + } + TempString[j] = String[i]; + i++; j++; + } + TempString[j]=0; + + return TempString; +} +static UINT8 result = (UINT8)-1; +static CALLBACK_MESSAGEBOX gCbMsgBox = { { CALLBACK_TYPE_MESSAGEBOX, sizeof(CALLBACK_MESSAGEBOX) }, 0 }; + +VOID _CallbackMsgboxEx( VOID *container, VOID *object, VOID *cookie ) +{ + if ( (cookie != NULL) && ( ((CALLBACK_MESSAGEBOX*)cookie)->Header.Type == CALLBACK_TYPE_MESSAGEBOX) ) + result = (UINT8)(((CALLBACK_MESSAGEBOX*)cookie)->Result); +} +// +//---------------------------------------------------------------------------- +// Procedure: _CallbackGetValueEx +// +// Description: Callback function to get the message box return value +// +// Input: MSGBOX_DATA *msgbox +// +// Output: Message box return value +// +//---------------------------------------------------------------------------- +// +UINTN _CallbackGetValueEx( MSGBOX_DATA *msgbox ) +{ + ACTION_DATA *action = gMsgBoxAction; + + result = (UINT8)-1; + gMsgBox.SetCallback( msgbox, NULL, _CallbackMsgboxEx, &gCbMsgBox ); + + while ( result == (UINT8)-1 ) + { + if ( action->Input.Type != ACTION_TYPE_NULL ) + gAction.ClearAction( action ); + + gMsgBox.Draw( msgbox ); + + if ( gAction.GetAction( action ) != EFI_SUCCESS ) + continue; + + gMsgBox.HandleAction( msgbox, action ); + DoRealFlushLines(); + } + + return result; +} + + +// +//---------------------------------------------------------------------------- +// Procedure: ShowPostMsgBoxEx +// +// Description: Function to display the message box +// +// Input: CHAR16 *MsgBoxTitle, +// CHAR16 *Message, +// UINT8 MsgBoxType, +// UINT8 *pSelection +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ShowPostMsgBoxEx( + IN CHAR16 *Title, + IN CHAR16 *Message, + IN CHAR16 *Legend, + IN MSGBOX_EX_CATAGORY MsgBoxExCatagory, + IN UINT8 MsgBoxType, + IN UINT16 *OptionPtrTokens, + IN UINT16 OptionCount, + IN AMI_POST_MGR_KEY *HotKeyList, + IN UINT16 HotKeyListCount, + OUT UINT8 *MsgBoxSel, + OUT AMI_POST_MGR_KEY *OutKey +) +{ + static AMI_IFR_MSGBOX MsgBox = { 0, 0, 0, INVALID_HANDLE, 0 }; + EFI_STATUS Status = EFI_SUCCESS; + UINT8 retValue = (UINT8)-1; + MSGBOX_DATA *msgbox = NULL; + CONTROL_INFO dummy; + ACTION_DATA *action = gMsgBoxAction; + UINT16 i = 0; + + if (NULL == gST->ConIn) + return EFI_NOT_READY; + + if(Title == NULL || Message == NULL || + //Note: Messagebox should not require a legend + /*((Legend == NULL ) && (MsgBoxType == MSGBOX_TYPE_NULL)) ||*/ + ((MsgBoxType == MSGBOX_TYPE_CUSTOM) && (OptionPtrTokens == NULL)) || + ((OptionCount > 0) && (OptionPtrTokens == NULL)) || + ((HotKeyListCount > 0) && (HotKeyList == NULL))) + return EFI_INVALID_PARAMETER; + + if((MsgBoxType == MSGBOX_TYPE_CUSTOM) && (OptionCount > MSGBOX_MAX_OPTIONS)) + return EFI_UNSUPPORTED ; + + MsgBox.Title = HiiChangeString(gHiiHandle, MsgBox.Title, Title); + MsgBox.Text = HiiChangeString(gHiiHandle, MsgBox.Text, Message); + + if(!gApp) + { + Status = gAction.Create( &gMsgBoxAction ); + if ( EFI_ERROR( Status ) ) + return Status; + action = gMsgBoxAction; //EIP127375, If NULL while initialization then this assignment will be helpful + } + + + Status = gMsgBox.Create( (void**)&msgbox ); + if ( EFI_ERROR( Status ) ) + return retValue; + + MemSet( &dummy, sizeof(dummy), 0 ); + dummy.ControlHandle = (VOID*)(UINTN)INVALID_HANDLE; + dummy.ControlPtr = (VOID*)&MsgBox ; //data; + dummy.ControlFlags.ControlVisible = TRUE; + + msgbox->MsgBoxCatagory = (MsgBoxExCatagory & (~MSGBOX_EX_ATTRIB_CLEARSCREEN)) ; + + msgbox->Legend = StrDup (Legend); //EIP-88918 + if (OptionCount) //EIP 90379 + { + msgbox->PtrTokens = EfiLibAllocateZeroPool (sizeof (UINT16) * OptionCount); + if (NULL == msgbox->PtrTokens) + { + return EFI_OUT_OF_RESOURCES; + } + MemCopy (msgbox->PtrTokens, OptionPtrTokens, sizeof (UINT16) * OptionCount); + } + else + { + msgbox->PtrTokens = NULL; + } +// msgbox->PtrTokens = OptionPtrTokens; + msgbox->OptionCount = OptionCount ; + + Status = gMsgBox.Initialize( msgbox, &dummy ); + if ( EFI_ERROR( Status ) ) + goto Done; + + gMsgBox.SetType( msgbox, MsgBoxType ); + + //*MsgBoxSel = (UINT8)_CallbackGetValueEx( msgbox ); + + result = (UINT8)-1; + gMsgBox.SetCallback( msgbox, NULL, _CallbackMsgboxEx, &gCbMsgBox ); + +//EIP:47962 Start + if((MsgBoxExCatagory & MSGBOX_EX_ATTRIB_CLEARSCREEN) == MSGBOX_EX_ATTRIB_CLEARSCREEN) + ClearScreen( EFI_BACKGROUND_BLACK | EFI_LIGHTGRAY ); +//EIP:47962 End + + while ( result == (UINT8)-1 ) + { + if ( action->Input.Type != ACTION_TYPE_NULL ) + gAction.ClearAction( action ); + + gMsgBox.Draw( msgbox ); + + if ( gAction.GetAction( action ) != EFI_SUCCESS ) + continue; + + gMsgBox.HandleAction( msgbox, action ); + DoRealFlushLines(); + + if(HotKeyList!=NULL && HotKeyListCount>0) + { + for(i=0 ; iInput.Data.AmiKey.Key.ScanCode ) && + (HotKeyList[i].Key.UnicodeChar == action->Input.Data.AmiKey.Key.UnicodeChar) && + (TseCheckShiftState( action->Input.Data.AmiKey, HotKeyList[i].KeyShiftState) ) ) + { + // Verify passed argument is not NULL before attempting to assign to it + if(OutKey != NULL) + { + OutKey->Key.ScanCode = action->Input.Data.AmiKey.Key.ScanCode ; + OutKey->Key.UnicodeChar = action->Input.Data.AmiKey.Key.UnicodeChar; + +#if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL + OutKey->KeyShiftState = (UINT32)action->Input.Data.AmiKey.KeyState.KeyShiftState ; +#else + OutKey->KeyShiftState = 0 ; +#endif + } + goto Done; + + } + + } + + } + else + { + if((msgbox->MsgBoxType == MSGBOX_TYPE_NULL) && (action ->Input.Type == ACTION_TYPE_KEY)) + goto Done; + + } + + } + + if((result != -1) && (MsgBoxSel != NULL)) + *MsgBoxSel = (UINT8) result; + + +Done: + gMsgBox.Destroy( msgbox, TRUE ); + + + if(!gApp) + { + gAction.Destroy( gMsgBoxAction, TRUE ); + gMsgBoxAction = NULL ; + } + + + return Status; +} +// +//---------------------------------------------------------------------------- +// Procedure: ShowPostProgress +// +// Description: Function to display the progress bar +// +// Input: IN UINT8 ProgressBoxState - Progress bar state +// IN CHAR16 *Title - Progress bar title +// IN CHAR16 *Message, - Progress bar message string +// IN CHAR16 *Legend, - Progress bar legend string +// IN UINTN Percent, - Percent Complete (0 - 100) +// IN OUT VOID **Handle, - HANDLE. Valid Handle for update and close +// OUT AMI_POST_MGR_KEY *OutKey - Out Key +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ShowPostProgress( + IN UINT8 ProgressBoxState, + IN CHAR16 *Title, + IN CHAR16 *Message, + IN CHAR16 *Legend, + IN UINTN Percent, + IN OUT VOID **Handle, + OUT AMI_POST_MGR_KEY *OutKey +) +{ + static AMI_IFR_MSGBOX MsgBox = { 0, 0, 0, INVALID_HANDLE, 0 }; + EFI_STATUS Status = EFI_SUCCESS; + MSGBOX_DATA *msgbox = NULL; + CONTROL_INFO dummy; + ACTION_DATA *action=NULL; + UINT16 MessageToken = 0 ; + MEMO_DATA *memo = NULL; + + switch(ProgressBoxState) + { + case AMI_PROGRESS_BOX_INIT: + + Status = gMsgBox.Create( &msgbox ); + if ( EFI_ERROR( Status ) ) + return EFI_UNSUPPORTED; + + MsgBox.Title = HiiChangeString(gHiiHandle, STRING_TOKEN(STR_MSGBOX_PROGRESS_TITLE), Title); + MsgBox.Text = HiiChangeString(gHiiHandle, STRING_TOKEN(STR_MSGBOX_PROGRESS_TEXT), Message); + + MemSet( &dummy, sizeof(dummy), 0 ); + dummy.ControlHandle = (VOID*)(UINTN)INVALID_HANDLE; + dummy.ControlPtr = (VOID*)&MsgBox ; //data; + dummy.ControlFlags.ControlVisible = TRUE; + + msgbox->MsgBoxCatagory = MSGBOX_EX_CATAGORY_NORMAL ; + + Status = gMsgBox.Initialize( msgbox, &dummy ); + + if ( EFI_ERROR( Status ) ) + { + gMsgBox.Destroy( msgbox, TRUE ); + return Status; + } + + *Handle = msgbox ; + msgbox->Legend = Legend ; + msgbox->Percent = 0 ; + gMsgBox.SetType( msgbox, MSGBOX_TYPE_PROGRESS ); + + gMsgBox.Draw( msgbox ); + DoRealFlushLines(); + + break; + + case AMI_PROGRESS_BOX_UPDATE: + + if(Handle == NULL) + return EFI_UNSUPPORTED; + + msgbox = *Handle ; + msgbox->Percent = Percent ; + +//EIP:39416 START + if(Message != NULL) + { + memo = msgbox->Memo; + MessageToken = HiiChangeString(gHiiHandle, MessageToken, Message); + UefiSetSubTitleField((VOID *)memo->ControlData.ControlPtr, MessageToken); + } +//EIP:39416 END + + gMsgBox.Draw( msgbox ); + DoRealFlushLines(); + + //Output the key + if (! EFI_ERROR( gAction.Create( &action ) ) ) + { + if(!EFI_ERROR(gAction.GetAction( action ))) + { + OutKey->Key.ScanCode = action->Input.Data.AmiKey.Key.ScanCode ; + OutKey->Key.UnicodeChar = action->Input.Data.AmiKey.Key.UnicodeChar; + + #if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL + OutKey->KeyShiftState = action->Input.Data.AmiKey.KeyState.KeyShiftState ; + #else + OutKey->KeyShiftState = 0 ; + #endif + } + Status = gAction.Destroy(action, TRUE); + } + break; + + case AMI_PROGRESS_BOX_CLOSE: + msgbox = *Handle ; + gMsgBox.Destroy( msgbox, TRUE ); + //restore the screen + break; + } + + return Status; +} +// +//---------------------------------------------------------------------------- +// Procedure: ShowPostMsgBox +// +// Description: Function to display the message box +// +// Input: CHAR16 *MsgBoxTitle, +// CHAR16 *Message, +// UINT8 MsgBoxType, +// UINT8 *pSelection +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ShowPostMsgBox(IN CHAR16 *MsgBoxTitle,IN CHAR16 *Message,IN UINT8 MsgBoxType, UINT8 *pSelection) +{ + static AMI_IFR_MSGBOX MsgBox = { 0, 0, 0, INVALID_HANDLE, 0 }; + EFI_STATUS Status = EFI_SUCCESS; + UINT8 Selection; + + MsgBox.Title = HiiChangeString(gHiiHandle, MsgBox.Title, MsgBoxTitle); + MsgBox.Text = HiiChangeString(gHiiHandle, MsgBox.Text, Message); + + if(!gApp) + { + Status = gAction.Create( &gMsgBoxAction ); + if ( EFI_ERROR( Status ) ) + return Status; + } + + Selection = CallbackShowMessageBox((UINTN)&MsgBox, MsgBoxType); + + if(!gApp) + { + gAction.Destroy( gMsgBoxAction, TRUE ); + gMsgBoxAction = NULL; + } + + if(pSelection!=NULL) + *pSelection = Selection; + + return Status; +} + +#define PADDING 8 +#define GUTTER 2 +#define BRACKET 1 +UINT16 gPostLabelMargin = 0 ; +extern EFI_STATUS _CBPopupStringEdit(VOID *container, VOID *object, VOID *cookie); +extern UINT8 res ; +extern CALLBACK_VARIABLE gPopupEditCb ; +// +//---------------------------------------------------------------------------- +// Procedure: _PostEditCallback +// +// Description: Callback function for text entry popup +// +// Input: VOID *container, VOID *object, VOID *cookie +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS _PostEditCallback(VOID *container, VOID *object, VOID *cookie) +{ + EFI_STATUS Status = EFI_SUCCESS; + +/* + if(cookie!=NULL) + { + res=0; + } + else + res=1; +*/ + return Status; +} +// +//---------------------------------------------------------------------------- +// Procedure: _PostEditDraw +// +// Description: Function to draw text entry edit box +// +// Input: POPUPEDIT_DATA *popup +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS _PostEditDraw( POPUPEDIT_DATA *popup ) +{ + UINT16 Length = 0 ; + BOOLEAN bShadow = StyleGetShadowSupport() ; + + //DrawWindow( popup->Left, popup->Top, popup->Width, popup->Height, (UINT8)(popup->BGColor | popup->FGColor) , FALSE, FALSE ); + + if ( popup->Title != NULL ) + { + Length = (UINT16)TestPrintLength( popup->Title ) / (NG_SIZE); + DrawStringWithAttribute( popup->Left - Length - GUTTER, popup->Top, popup->Title, (popup->ControlActive?EFI_WHITE:popup->FGColor) | popup->BGColor ); + } + + Length = (UINT16)UefiGetMaxValue(popup->ControlData.ControlPtr); + DrawStringWithAttribute( popup->Left, popup->Top, L"[", (popup->ControlActive?EFI_WHITE:popup->FGColor) | popup->BGColor ); + DrawStringWithAttribute( popup->Left+Length+1 , popup->Top, L"]", (popup->ControlActive?EFI_WHITE:popup->FGColor) | popup->BGColor ); + if(popup->ControlActive) + DrawWindow( popup->Left+1, popup->Top, Length, popup->Height, (UINT8)(EFI_BLACK | popup->FGColor) , FALSE, FALSE ); + + return gControl.Draw( popup ); +} +// +//---------------------------------------------------------------------------- +// Procedure: _PostPopupEditDraw +// +// Description: Function to draw text entry popup window +// +// Input: POPUPEDIT_DATA *PopupEdit +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS _PostPopupEditDraw( POPUPEDIT_DATA *PopupEdit ) +{ + EFI_STATUS Status; + CHAR16 *text = NULL, *newText = NULL; + CHAR16 *line; + UINT16 pos, height,i,ii=0;; + + + text = StrDup(PopupEdit->Text); + + Status = _PostEditDraw( PopupEdit ); + if(EFI_ERROR(Status)) + return Status; + + // clear out old wrapped string + for ( pos = ii; pos < PopupEdit->Height-2; pos++ ) + DrawStringWithAttribute( PopupEdit->Left+1, PopupEdit->Top + pos, PopupEdit->EmptyString, PopupEdit->FGColor | PopupEdit->BGColor ); + + newText = StringWrapText( text, PopupEdit->Width-1, &height ); + if ( newText != text ) + MemFreePointer( (VOID **)&text ); + + line = newText; + + for ( pos = ii; pos < PopupEdit->Height; pos++ ) + { + CHAR16 save; + + text = line; + if ( *line == L'\0' ) + break; + + while ( ( *line != L'\n' ) &&( *line != L'\r' ) && ( *line != L'\0' ) ) + line++; + + save = *line; + *line = L'\0'; + i=0; + while( (text[i] != L'\0') && (PopupEdit->Chr !=0x0 ) ) + { +// if(text[i] != L' ') //all chars should be treated the same + text[i] = PopupEdit->Chr; + i++; + } + + if(PopupEdit->ControlActive) + DrawStringWithAttribute( PopupEdit->Left+1, PopupEdit->Top + pos, text, EFI_WHITE | EFI_BLACK ); + else + DrawStringWithAttribute( PopupEdit->Left+1, PopupEdit->Top + pos, text, PopupEdit->FGColor | PopupEdit->BGColor ); + + if ( ( *line = save ) != L'\0' ) + { + line++; + if ( ( *line == L'\r' ) || ( *line == L'\n' ) ) + line++; + } + } + MemFreePointer( (VOID **)&newText ); + + if ( pos < height ) + height = pos; + + PopupEdit->DisplayLines = height; + FlushLines( 0, 24 ); + //FlushLines( PopupEdit->Top, PopupEdit->Top + PopupEdit->Height ); + return EFI_SUCCESS; + +} +// +//---------------------------------------------------------------------------- +// Procedure: _PostPopupEditGetValues +// +// Description: Function to draw text entry popup window +// +// Input: POPUP_DATA *popup, +// POPUPEDIT_DATA *editList, +// TEXT_INPUT_TEMPLATE *InputData, +// UINT16 ItemCount, +// DISPLAY_TEXT_KEY_VALIDATE ValidateKeyFunc +// +// Output: UINTN - 0/1 (success/abort) +// +//---------------------------------------------------------------------------- +// +UINTN _PostPopupEditGetValues( + POPUP_DATA *popup, + POPUPEDIT_DATA *editList, + TEXT_INPUT_TEMPLATE *InputData, + UINT16 ItemCount, + DISPLAY_TEXT_KEY_VALIDATE ValidateKeyFunc +) +{ + EFI_STATUS Status; + POPUPEDIT_DATA *ptrEdit=NULL; + CONTROL_ACTION Action = ControlActionUnknown; + ACTION_DATA *action=NULL ; + UINT16 i=0, Length=0, CurPos=0; + UINT16 count = 0; + res = (UINT8)-1; + + + if(!gApp) + { + Status = gAction.Create( &action ); + if ( EFI_ERROR( Status ) ) + { + res=0; + goto Done; + } + } else { + action = gApp->Action; + } + + + gPopup.Draw( popup ); + + //1. Position Child items + for ( i = 0; i < ItemCount; i++) + { + Length = (UINT16)TestPrintLength( editList[i].Title ) / (NG_SIZE); + editList[i].Top = popup->Top+1+i ; + editList[i].Left = popup->Left + gPostLabelMargin ; + editList[i].Height = 1 ; + } + + + + res = (UINT8)-1; + + while ( res == (UINT8)-1 ) + { + //2. Clear the action + if ( action->Input.Type != ACTION_TYPE_NULL ) { + gAction.ClearAction( action ); + } + + //3. Draw the controls + gPopup.Draw( popup ); + + ptrEdit = editList; + + for ( i = 0; i < ItemCount; i++, ptrEdit++) + { + _PostPopupEditDraw( ptrEdit ); + } + + FlushLines( popup->Top-2, popup->Top + popup->Height ); + DoRealFlushLines(); + + //4. Get the action + Status = gAction.GetAction( action ); + if( Status != EFI_SUCCESS ) { + continue; + } + + //5. Set the count to control the active item + if (action->Input.Type == ACTION_TYPE_KEY) + { + Action = MapControlKeysHook(action->Input.Data.AmiKey) ; + + switch(Action) + { + case ControlActionHome: + count = 0; + break; + + case ControlActionEnd: + count = ItemCount-1; + break; + + case ControlActionNextUp: + if (count > 0 ) + count--; + break; + + case ControlActionNextSelection: + case ControlActionNextDown: + if (count < ItemCount-1 ) + count++; + break; + /* + case ControlActionSelect: + count++; + if(count >= ItemCount) + res=0; + break; + */ + case ControlActionAbort: + res=1; + break; + } + } + + ptrEdit = editList; + + //6. Scan Items, Set Active Status and handle the action + for ( i = 0; i < ItemCount; i++, ptrEdit++) + { + if(count == i) + { + //Handle the action ONLY for the active item + ptrEdit->ControlActive = TRUE ; + + //Check filter key, skip the character/Action if required + if( (action->Input.Data.AmiKey.Key.UnicodeChar) && + (Action != ControlActionBackSpace) && + (Action != ControlActionAbort) && + //(Action != ControlActionSelect) && + (Action != ControlActionNextSelection) && + (Action != ControlActionUnknown) + /* (action->Input.Data.AmiKey.Key.UnicodeChar != 0x20 )*/ ) + { + + if(InputData[i].FilterKey == TSE_FILTER_KEY_NUMERIC) + { + if(!CharIsNumeric(action->Input.Data.AmiKey.Key.UnicodeChar)) + continue ; + } + else if(InputData[i].FilterKey == TSE_FILTER_KEY_ALPHA) + { + if(!CharIsAlpha(action->Input.Data.AmiKey.Key.UnicodeChar)) + continue ; + } + else if(InputData[i].FilterKey == TSE_FILTER_KEY_ALPHANUMERIC) + { + if(!CharIsAlphaNumeric(action->Input.Data.AmiKey.Key.UnicodeChar)) + continue ; + } + else if((InputData[i].FilterKey == TSE_FILTER_KEY_CUSTOM) && (ValidateKeyFunc!=NULL)) + { + if(!(ValidateKeyFunc(i, action->Input.Data.AmiKey.Key.UnicodeChar, ptrEdit->Text))) + continue ; + } + } + + gPopupEdit.HandleAction( ptrEdit, action ); + CurPos = (UINT16)EfiStrLen(ptrEdit->Text)+1 ; + gST->ConOut->SetAttribute ( gST->ConOut, ptrEdit->FGColor | ptrEdit->BGColor ); + gST->ConOut->SetCursorPosition( gST->ConOut, + ptrEdit->Left + CurPos, ptrEdit->Top ); + + if(CurPos <= ptrEdit->TextWidth) + { + gST->ConOut->EnableCursor(gST->ConOut, TRUE); + } + else + { + gST->ConOut->EnableCursor(gST->ConOut, FALSE); + } + + + } + else + { + ptrEdit->ControlActive = FALSE ; + } + + } + + if(Action == ControlActionSelect) + { + count++; + + if(count >= ItemCount) + { + res=0; + } + } + + Action = ControlActionUnknown ; + + } + +Done: + if(!gApp) + { + gAction.Destroy( action, TRUE ); + action = NULL ; + } + + + return res; +} +// +//-------------------------------------------------------------------------- +// +// Name: ShowPostTextBox +// +// Description: Function to display text entry interface +// +// +// Input: IN VOID *HiiHandle, +// IN UINT16 TitleToken, +// IN TEXT_INPUT_TEMPLATE *InputData, +// IN UINT16 ItemCount, +// IN DISPLAY_TEXT_KEY_VALIDATE ValidateKeyFunc +// +// Output: EFI_STATUS +// +//-------------------------------------------------------------------------- +// +EFI_STATUS ShowPostTextBox( + IN VOID *HiiHandle, + IN UINT16 TitleToken, + IN TEXT_INPUT_TEMPLATE *InputData, + IN UINT16 ItemCount, + IN DISPLAY_TEXT_KEY_VALIDATE FilterKeyFunc) +{ + + EFI_STATUS Status = EFI_SUCCESS; + UINT16 Token=0, i=0, Length=0, MaxLabelWidth=0, MaxControlWidth=0; + UINT8 retValue = (UINT8)-1; + VOID *OriginalPopupEditDraw = NULL ; + CHAR16 *Text=NULL; + VOID *IFRString ; + CONTROL_INFO dummy; + + POPUP_DATA *popup = NULL ; + POPUPEDIT_DATA *PopupEditList=NULL, *ptrEdit=NULL; + CALLBACK_VARIABLE *PopupEditCb=NULL, *ptrCb=NULL ; + CONTROL_INFO *dummys=NULL, *ptrDummy=NULL; + EFI_TPL OrgTPL; + BOOLEAN PreviousCursorState = gST->ConOut->Mode->CursorVisible; + + if(HiiHandle == NULL) + { + return EFI_UNSUPPORTED ; + } + + Status = gPopup.Create( &popup ); + if ( EFI_ERROR( Status ) ) + { + return Status; + } + + // this *MUST* be run a EFI_TPL_APPLICATION + OrgTPL = gBS->RaiseTPL( EFI_TPL_HIGH_LEVEL ); // guarantees that RestoreTPL won't ASSERT + gBS->RestoreTPL( EFI_TPL_APPLICATION ); + + PopupEditList = EfiLibAllocateZeroPool( sizeof(POPUPEDIT_DATA) * ItemCount); + PopupEditCb = EfiLibAllocateZeroPool( sizeof(CALLBACK_VARIABLE) * ItemCount); + dummys = EfiLibAllocateZeroPool( sizeof(CONTROL_INFO) * ItemCount); + + ptrEdit = PopupEditList; + ptrDummy = dummys ; + ptrCb = PopupEditCb ; + + IFRString = UefiCreateSubTitleTemplate(TitleToken); + //((EFI_IFR_STRING*)IFRString)->MaxSize = 10 ; + + MemSet( &dummy, sizeof(dummy), 0 ); + dummy.ControlPtr = (VOID*)IFRString; + dummy.ControlHandle = HiiHandle; + dummy.ControlType = CONTROL_TYPE_POPUP_STRING; + dummy.ControlFlags.ControlVisible = TRUE; + + + Status = gPopup.Initialize( popup, &dummy ); + if ( EFI_ERROR( Status ) ) + goto Done; + + SetControlColorsHook( NULL, NULL , NULL, NULL , NULL, NULL , + NULL , NULL, NULL,NULL , + NULL,NULL ,NULL,&(popup->FGColor),&(popup->BGColor) ); + + popup->Border = TRUE ; + popup->Title = HiiGetString(HiiHandle, TitleToken); + popup->Style = POPUP_STYLE_BBS ; + + if ( popup->Title == NULL ) + { + Status = EFI_UNSUPPORTED ; + goto Done; + } + + + for ( i = 0; i < ItemCount; i++, ptrEdit++, ptrDummy++, ptrCb++) + { + + if((InputData[i].Value == NULL) || (InputData[i].MaxSize < 1 )) + { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // Create PopupEdit Control + Status = gPopupEdit.Create( &((POPUPEDIT_DATA *)ptrEdit) ); + if ( EFI_ERROR( Status ) ) + goto Done; + + MemSet( ptrDummy, sizeof(CONTROL_INFO), 0 ); + ptrDummy->ControlPtr = (VOID*)UefiCreateStringTemplate(InputData[i].ItemToken); + ptrDummy->ControlHandle = HiiHandle; + ptrDummy->ControlType = CONTROL_TYPE_POPUP_STRING; + ptrDummy->ControlFlags.ControlVisible = TRUE; + ((EFI_IFR_STRING*)ptrDummy->ControlPtr)->MaxSize = InputData[i].MaxSize ; + + //Set the text, caller may want to display default value + gPopupEdit.SetText(ptrEdit, InputData[i].Value); + gPopupEdit.SetType( ptrEdit, InputData[i].Hidden?POPUPEDIT_TYPE_PASSWORD:POPUPEDIT_TYPE_STRING ); + + // Initialize PopupEdit Control + Status = gPopupEdit.Initialize( ptrEdit, ptrDummy ) ; + + if ( EFI_ERROR( Status ) ) + goto Done; + + ptrEdit->Border = FALSE ; + ptrEdit->Style = POPUP_STYLE_NORMAL ; + + gPopupEdit.SetCallback( ptrEdit, NULL, _PostEditCallback, ptrCb ); + + // Item width = PromptStringLength + "[" + ControlWidth +"]" + + //Get maximum label width + Length = (UINT16)TestPrintLength( ptrEdit->Title ) / (NG_SIZE); + if(Length > MaxLabelWidth) + MaxLabelWidth = Length ; + + + //Get maximum control width + Length = (UINT16)UefiGetMaxValue(ptrEdit->ControlData.ControlPtr); + if(Length > MaxControlWidth) + MaxControlWidth = Length ; + } + + //popup->width = MaxLabelWidth + GUTTER + "[" + MaxControlWidth + "]" + popup->Width = MaxLabelWidth + GUTTER + BRACKET + MaxControlWidth + BRACKET ; + popup->Width += PADDING ; + + Length = (UINT16)TestPrintLength( popup->Title ) / (NG_SIZE); + + //Check if the title exceeds the popup window width + if(Length > popup->Width) + { + //Adjust the popup window width + popup->Width = Length + PADDING ; + //Set the label margin + gPostLabelMargin = (popup->Width - (MaxLabelWidth + GUTTER + MaxControlWidth))/2 + MaxLabelWidth ; + } + else + { + //Set the label margin + gPostLabelMargin = MaxLabelWidth + GUTTER + PADDING/2; + } + + //Set the popup window height + popup->Height = ItemCount + 2 ; + + //Check screen overflow + if( (popup->Width > gMaxCols - 2) || + (popup->Height > gMaxRows - 2) ) + { + Status = EFI_UNSUPPORTED; + goto Done; + } + + // Save gPopupEdit.Draw (It may be an override function) + OriginalPopupEditDraw = gPopupEdit.Draw ; + + // Override gPopupEdit.Draw with our functiion (It will be called by the PopupEdit control) + gPopupEdit.Draw = _PostPopupEditDraw ; + + gST->ConOut->EnableCursor(gST->ConOut, TRUE); + gST->ConOut->SetAttribute ( gST->ConOut, popup->FGColor | popup->BGColor ); + + // Launch the textbox and get the values. + retValue = (UINT8)_PostPopupEditGetValues( popup, PopupEditList, InputData, ItemCount, FilterKeyFunc ); + + gST->ConOut->EnableCursor(gST->ConOut, PreviousCursorState); + + // Restore gPopupEdit.Draw to the original + gPopupEdit.Draw = OriginalPopupEditDraw ; + + + if(retValue == 0) + { + for ( i = 0; i < ItemCount; i++) + { + if(InputData[i].Value == NULL) + { + // Allocate space for the user entered value + //EntryData[i].Value = EfiLibAllocateZeroPool( (PopupEditCb[i].Length+1) * sizeof(CHAR16) ); + + //if(EntryData[i].Value == NULL) + Status = EFI_INVALID_PARAMETER; + goto Done; + } + // Get the user entered value + EfiStrCpy( InputData[i].Value, PopupEditList[i].Text ); + //EfiStrCpy( InputData[i].Value, PopupEditCb[i].Data ); + } + } + +Done: + + gPopupEdit.Destroy( PopupEditList, TRUE );//EIP-170151 Destroy text box before message box + + // Free allocated init data + + MemFreePointer((VOID**)&PopupEditCb); + MemFreePointer((VOID**)&dummys); + gPopup.Destroy( popup, TRUE ); + + if (gApp != NULL) { + gApp->CompleteRedraw = TRUE ; //CompleteRedraw; + gApp->OnRedraw = SUBMENU_COMPLETE_REDRAW; + } + + gBS->RaiseTPL( EFI_TPL_HIGH_LEVEL ); // guarantees that RestoreTPL won't ASSERT + gBS->RestoreTPL( OrgTPL ); + + if (res == 1) { + Status = EFI_ABORTED; + } + + return Status; +} +// +//---------------------------------------------------------------------------- +// Procedure: _DisplayInfoCancelTimer +// +// Description: Timer notify fucntion +// +// Input: EFI_EVENT Event +// VOID *Context +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID _DisplayInfoCancelTimer( EFI_EVENT Event, VOID *Context ) +{ + if ( gInfoBox != NULL ) + gMsgBox.Destroy( gInfoBox, TRUE ); + + gInfoBox = NULL; + + TimerStopTimer( &Event ); +} + +// +//---------------------------------------------------------------------------- +// Procedure: ShowInfoBox +// +// Description: fucntiont to display the information box +// +// Input: CHAR16 *InfoBoxTitle, +// CHAR16 *Message, +// UINTN TimeLimit, +// EFI_EVENT *RetEvent) +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ShowInfoBox(IN CHAR16 *InfoBoxTitle, IN CHAR16 *Message, IN UINTN TimeLimit, EFI_EVENT *RetEvent) +{ + EFI_STATUS Status; + static AMI_IFR_MSGBOX msgbox = { 0, 0, 0, INVALID_HANDLE, 0 }; + CONTROL_INFO dummy; + + msgbox.Title = HiiChangeString(gHiiHandle, msgbox.Title, InfoBoxTitle); + msgbox.Text = HiiChangeString(gHiiHandle, msgbox.Text, Message); + + Status = gMsgBox.Create( &gInfoBox ); + if ( EFI_ERROR( Status ) ) + return 1; + + MemSet( &dummy, sizeof(dummy), 0 ); + + dummy.ControlHandle = INVALID_HANDLE; + dummy.ControlPtr = (VOID*)(UINTN) &msgbox; + dummy.ControlFlags.ControlVisible = TRUE; + + gMsgBox.Initialize( gInfoBox, &dummy ); + + gMsgBox.SetType( gInfoBox, MSGBOX_TYPE_NULL ); + gMsgBox.Draw( gInfoBox ); + + if ( TimeLimit != 0 ) + { + UINT32 EventType = EFI_EVENT_TIMER | EFI_EVENT_NOTIFY_SIGNAL; //|EFI_EVENT_NOTIFY_WAIT, EFI_EVENT_NOTIFY_SIGNAL| + + Status = gBS->CreateEvent( + EventType, + EFI_TPL_CALLBACK, + _DisplayInfoCancelTimer, + NULL, + RetEvent + ); + + if ( EFI_ERROR( Status ) ) + return Status; + + Status = gBS->SetTimer( *RetEvent, TimerRelative, MultU64x32((UINT64)TIMER_ONE_SECOND, TimeLimit) ); + + if ( EFI_ERROR( Status ) ) + TimerStopTimer( RetEvent ); + } + + return Status; +} + +#if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL +// +//---------------------------------------------------------------------------- +// Procedure: ActionReadKeyWithAMIKeyCode +// +// Description: fucntion to read the a key using AMI Key Code Protocol +// +// Input: AMI_EFI_KEY_DATA *pAmiKey, +// UINT64 Timeout +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ActionReadKeyWithAMIKeyCode( AMI_EFI_KEY_DATA *pAmiKey, UINT64 Timeout ) +{ + EFI_STATUS Status; + EFI_STATUS StatusFlush; + EFI_EVENT EventList[2] = { NULL, NULL }; + UINTN Count = 1, Index = 1; + AMI_EFI_KEY_DATA KeyFlush; + + AMI_EFIKEYCODE_PROTOCOL *pKeyCodeProtocol; + Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gAmiEfiKeycodeProtocolGuid, (void*)&pKeyCodeProtocol); + if (EFI_ERROR(Status)) return Status; + + if ( Timeout ) + { + EventList[0] = pKeyCodeProtocol->WaitForKeyEx; + + Status = TimerCreateTimer( &EventList[1], NULL, NULL, TimerRelative, Timeout, EFI_TPL_CALLBACK ); + if ( EFI_ERROR( Status ) ) + return Status; + + Count++; + + gBS->WaitForEvent( Count, EventList, &Index ); + + TimerStopTimer( &EventList[1] ); + + if ( Index == 1 ) + return EFI_NOT_READY; + } + + Status = pKeyCodeProtocol->ReadEfikey( pKeyCodeProtocol, pAmiKey ); + ////EIP-87117 If it Partial Key make the Status as Error to ignore + // the Partial Key. + if((pAmiKey->KeyState.KeyToggleState & KEY_STATE_EXPOSED) == KEY_STATE_EXPOSED) { + if( (!EFI_ERROR( Status )) && (pAmiKey->Key.ScanCode==0) && (pAmiKey->Key.UnicodeChar==0)) { + Status = EFI_NOT_READY; + } + } + + if ( ! EFI_ERROR( Status ) && FlushKeysAfterRead())//EIP 99022 :check for the FLUSH_KEYS_AFTER_READ token before flushing the keys + { + do + { + StatusFlush = pKeyCodeProtocol->ReadEfikey( pKeyCodeProtocol, &KeyFlush ); + ////EIP-87117 If it Partial Key make the Status as Error to ignore + // the Partial Key. + if((KeyFlush.KeyState.KeyToggleState & KEY_STATE_EXPOSED) == KEY_STATE_EXPOSED) { + if( (!EFI_ERROR( Status )) && (KeyFlush.Key.ScanCode==0) && (KeyFlush.Key.UnicodeChar==0)) { + StatusFlush = EFI_NOT_READY; + } + } + } while ( ! EFI_ERROR( StatusFlush ) ); + + } + + return Status; +} +#endif + +// +//---------------------------------------------------------------------------- +// Procedure: ActionReadKey +// +// Description: fucntion to handle the read key action +// +// Input: AMI_EFI_KEY_DATA *pAmiKey, +// UINT64 Timeout +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ActionReadKey( AMI_EFI_KEY_DATA *pAmiKey, UINT64 Timeout ) +{ +#if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL + return ActionReadKeyWithAMIKeyCode( pAmiKey, Timeout ); +#else + return _ActionReadKey( pAmiKey, Timeout ); +#endif + +} + +// +//---------------------------------------------------------------------------- +// Procedure: AMIReadKeyStroke +// +// Description: function to read a key stroke +// +// Input: EFI_INPUT_KEY *Key, +// AMI_EFI_KEY_DATA *KeyData +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS AMIReadKeyStroke(EFI_INPUT_KEY *Key,AMI_EFI_KEY_DATA *KeyData) +{ + EFI_STATUS Status; +#if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL + AMI_EFIKEYCODE_PROTOCOL *pKeyCodeProtocol; + + Status = gBS->HandleProtocol(gST->ConsoleInHandle, &gAmiEfiKeycodeProtocolGuid, (void*)&pKeyCodeProtocol); + if (EFI_ERROR(Status)) return Status; + + Status = pKeyCodeProtocol->ReadEfikey( pKeyCodeProtocol, KeyData ); + + ////EIP-87117 If it Partial Key make the Status as Error to ignore + // the Partial Key. + if((KeyData->KeyState.KeyToggleState & KEY_STATE_EXPOSED) == KEY_STATE_EXPOSED) { + if( (!EFI_ERROR( Status )) && (KeyData->Key.ScanCode==0) && (KeyData->Key.UnicodeChar==0)) { + Status = EFI_NOT_READY; + } + } + *Key = KeyData->Key; +#else + Status = gST->ConIn->ReadKeyStroke( gST->ConIn, Key ); +#endif + return Status; +} + + +// +//---------------------------------------------------------------------------- +// Procedure: HelperIsPasswordCharValid +// +// Description: function to check whether the password char is valid +// +// Input: EFI_INPUT_KEY *Key, +// AMI_EFI_KEY_DATA *KeyData, +// UINTN StrIndex, +// UINTN PasswordLength, +// CHAR16 *OutChar +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS HelperIsPasswordCharValid(EFI_INPUT_KEY *Key,AMI_EFI_KEY_DATA *KeyData,UINTN StrIndex,UINTN PasswordLength, CHAR16 *OutChar) +{ +#if (TSE_USE_AMI_EFI_KEYCODE_PROTOCOL ) + switch( SETUP_STORE_KEYCODE_PASSWORD ) + { + case PW_EFI_KEY: + if ( (StrIndex < PasswordLength) && (KeyData->EfiKeyIsValid) ) { + /// EIP:28551 - Get EFI Key with the help of AMI key code protocol + *OutChar = (0x8000)^(CHAR16)(KeyData->EfiKey); + return EFI_SUCCESS; + } + break; + case PW_SCAN_CODE: + if ( (StrIndex < PasswordLength) && (KeyData->PS2ScanCodeIsValid) ) { + *OutChar = (CHAR16)(KeyData->PS2ScanCode); + return EFI_SUCCESS; + } + break; + default: + break; + } + +#endif + // if tokens not enabled then, check whether the character is alphanumeric and return the key + if ( CheckIsAllowedPasswordChar(Key->UnicodeChar) && ( StrIndex < PasswordLength ) ) + { + *OutChar = Key->UnicodeChar; + return EFI_SUCCESS; + } + + // If AMI key code support TOKEN not enabled and the character is not alphanumeric then return as Unsupported. + return EFI_UNSUPPORTED; +} + +// +//---------------------------------------------------------------------------- +// Procedure: PopupEditHandlePassword +// +// Description: function to handle the popup password edit +// +// Input: VOID *pPopupEdit, +// VOID *pData +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS PopupEditHandlePassword( VOID *pPopupEdit, VOID *pData) +{ +#if (TSE_USE_AMI_EFI_KEYCODE_PROTOCOL && SETUP_STORE_KEYCODE_PASSWORD) + POPUPEDIT_DATA *PopupEdit = pPopupEdit; + ACTION_DATA *Data = pData; + + // Check whether the popup edit type is Password, + if(( PopupEdit->PopupEditType == POPUPEDIT_TYPE_PASSWORD )&&( EfiStrLen(PopupEdit->Text) < PopupEdit->TextWidth )) + { + if(PopupEdit->ControlActive ==FALSE) + { + // copy the password text into temp and make the control active. + MemCopy(PopupEdit->TempText,PopupEdit->Text,PopupEdit->TextWidth* sizeof(UINT16)); + PopupEdit->ControlActive = TRUE; + } + switch( SETUP_STORE_KEYCODE_PASSWORD ) + { + case PW_EFI_KEY: + if(Data->Input.Data.AmiKey.EfiKeyIsValid) + PopupEdit->Text[EfiStrLen(PopupEdit->Text)] = 0x8000 ^(CHAR16)(Data->Input.Data.AmiKey.EfiKey); + else + return EFI_UNSUPPORTED; + break; + + case PW_SCAN_CODE: + if(Data->Input.Data.AmiKey.PS2ScanCodeIsValid) + PopupEdit->Text[EfiStrLen(PopupEdit->Text)] = (CHAR16)(Data->Input.Data.AmiKey.PS2ScanCode); + else + return EFI_UNSUPPORTED; + break; + } + // set end of string and return success + PopupEdit->Text[EfiStrLen(PopupEdit->Text)] = 0x0 ; + + return EFI_SUCCESS; + } +#endif + return EFI_UNSUPPORTED; +} + +//TSE_CLEAR_USERPW_WITH_ADMINPW +// +//---------------------------------------------------------------------------- +// Procedure: ClearUserPasswordPolicy +// +// Description: fucntion to clear the user password if admin password is empty, +// Only Valid with Password Local +// +// Input: CALLBACK_PASSWORD *callbackData, +// CHAR16 *saveData +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID ClearUserPasswordPolicy(CALLBACK_PASSWORD *callbackData,CHAR16 *saveData) +{ + if( + (VARIABLE_ID_AMITSESETUP == callbackData->Variable)&& + (STRUCT_OFFSET(AMITSESETUP,AdminPassword) == callbackData->Offset)&& + (0 == ((CHAR16 *)callbackData->Data)[0]) + ) + { + //Admin password is being cleared + //Clear user pw; write the same thing for user + //EIP-172956 To update password values properly + if((TSEPwdSavetoNvram())&&( VARIABLE_ID_AMITSESETUP == callbackData->Variable )) + { + AMITSESETUP *TempSaveData = (AMITSESETUP *)NULL; + UINTN size=0; + TempSaveData = (AMITSESETUP *) EfiLibAllocateZeroPool(sizeof(AMITSESETUP)); + size = sizeof(AMITSESETUP); + + TempSaveData = VarGetNvram(VARIABLE_ID_AMITSESETUP, &size); + MemCopy( ((UINT8*)(TempSaveData))+(STRUCT_OFFSET(AMITSESETUP,UserPassword)), saveData, callbackData->Length ); + VarSetNvram( VARIABLE_ID_AMITSESETUP, TempSaveData, sizeof(AMITSESETUP)); + MemFreePointer( (VOID **)&TempSaveData ); + } + else{ + VarSetValue(VARIABLE_ID_AMITSESETUP, STRUCT_OFFSET(AMITSESETUP,UserPassword), callbackData->Length, saveData); + } + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: TseFramePwdCallbackIdePasswordUpdate +// +// Description: function to update the ide password +// +// Input: CONTROL_DATA *control, +// CHAR16 *saveData +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS TseFramePwdCallbackIdePasswordUpdate ( CONTROL_DATA *control,CHAR16 *saveData) +{ + BOOLEAN bCheckUser = FALSE; + VOID * data =control->ControlData.ControlPtr; + + if (control->ControlData.ControlVariable == VARIABLE_ID_IDE_SECURITY ) // IDE Password + { + if(/*data->QuestionId*/UefiGetQuestionOffset(data) == STRUCT_OFFSET(IDE_SECURITY_CONFIG,IDEUserPassword)) + bCheckUser = TRUE; + TSEIDEPasswordUpdate( (UINT32)gCurrIDESecPage, saveData, bCheckUser ); + return EFI_SUCCESS; + } + else + return EFI_UNSUPPORTED; +} + +// +//---------------------------------------------------------------------------- +// Procedure: TsePopupPwdAuthenticateIDEPwd +// +// Description: Function to authenticate the IDE password +// +// Input: POPUP_PASSWORD_DATA *popuppassword, +// BOOLEAN *AbortUpdate, +// VOID *data +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS TsePopupPwdAuthenticateIDEPwd(POPUP_PASSWORD_DATA *popuppassword, BOOLEAN *AbortUpdate,VOID *data) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + CHAR16 *Text=NULL; + if(popuppassword->ControlData.ControlVariable == VARIABLE_ID_IDE_SECURITY ) + { + //if drive is locked ask for the old password to unlock the drive + VOID* DataPtr = TSEIDEPasswordGetDataPtr(gCurrIDESecPage); + BOOLEAN bCheckUser = FALSE; + BOOLEAN EnabledBit = FALSE; + UINTN size = 0; + IDE_SECURITY_CONFIG *ideSecConfig; + + ideSecConfig = VarGetVariable( VARIABLE_ID_IDE_SECURITY, &size ); + //EIP-75352 Suppress the warnings from static code analyzer + if (NULL == ideSecConfig) { + return EFI_NOT_FOUND; + } + if(ideSecConfig->Enabled) EnabledBit = TRUE; + + if(EnabledBit) + { + if(UefiGetQuestionOffset(data) /*data->QuestionId*/ == STRUCT_OFFSET(IDE_SECURITY_CONFIG,IDEUserPassword)) + bCheckUser = TRUE; + + if(bCheckUser || ideSecConfig->MasterPasswordStatus) + { + Status = _DoPopupEdit( popuppassword, (IsShowPromptStringAsTitle() ? STRING_TOKEN(STR_OLD_PSWD_LABEL): STRING_TOKEN(STR_OLD_PSWD)), &Text);//EIP-116315 password window title string + if(EFI_SUCCESS != Status ) + { + *AbortUpdate = TRUE; + } + else + { + Status = TSEIDEPasswordAuthenticate( Text, DataPtr, bCheckUser ); + if(EFI_ERROR( Status )) + { + CallbackShowMessageBox( (UINTN)gInvalidPasswordFailMsgBox, MSGBOX_TYPE_OK ); + *AbortUpdate = TRUE; + } + StringZeroFreeMemory ((VOID **)&Text); + } + } + } + + MemFreePointer((VOID **) &ideSecConfig); + return EFI_SUCCESS; + } + return EFI_UNSUPPORTED; +} + +// +//---------------------------------------------------------------------------- +// Procedure: TsePopupPwdUpdateIDEPwd +// +// Description: function to update the IDE password +// +// Input: None +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID TsePopupPwdUpdateIDEPwd (VOID) +{ + UINTN size = 0; + IDE_SECURITY_CONFIG *ideSecConfig; + + ideSecConfig = VarGetVariable( VARIABLE_ID_IDE_SECURITY, &size ); + //EIP-75352 Suppress the warnings from static code analyzer + if (NULL == ideSecConfig) { + return; + } + TSEIDEUpdateConfig((VOID*)ideSecConfig, gCurrIDESecPage); + VarSetValue (VARIABLE_ID_IDE_SECURITY, 0, size, ideSecConfig); //Updating the cache + if (gApp != NULL) + gApp->CompleteRedraw = TRUE; //EIP 80360 Complete redraw bcoz if User password set it should grayout the Master password. + MemFreePointer((VOID **)&ideSecConfig); +} + + +#if TSE_SEPERATE_EFI_LEGACY_OPTIONS +// +//---------------------------------------------------------------------------- +// Procedure: IsLegacyOption +// +// Description: function to check for legacy option +// +// Input: UINT16 Option +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOLEAN IsLegacyOption(UINT16 Option) +{ + BOOT_DATA *pBootData; + + pBootData = BootGetBootData(Option); + + if(pBootData) + { + if(BBSValidDevicePath( pBootData->DevicePath )) + return TRUE; + } + + return FALSE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: ReGroupOptions +// +// Description: function to regroup the boot options +// +// Input: UINT16 *optionList, +// UINT16 *OrgOptionList +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID ReGroupOptions(UINT16 *optionList,UINT16 *OrgOptionList) +{ + UINTN src, dest, i; + UINT16 *TempList; + UINTN LegDevStartIndex=0xFFFF,LegDevStopIndex=0xFFFF; + + TempList = EfiLibAllocatePool(gBootOptionCount * sizeof(UINT16)); + MemCopy(TempList, optionList, gBootOptionCount * sizeof(UINT16)); + + dest = 0; + //Copy all first EFI option + for(src=0; (src LegDevStartIndex) && (i < LegDevStopIndex)) + { + // Restore the Orginal Boot Options + MemCopy( optionList, OrgOptionList, gBootOptionCount*sizeof(UINT16)); + break; + } + + optionList[dest] = TempList[i]; + dest++; + } + } + + MemFreePointer((VOID **) &TempList); +} +#endif + + +#ifdef TSE_FOR_APTIO_4_50 +// +//---------------------------------------------------------------------------- +// Procedure: TSEGetNVVariable +// +// Description: reads the NV Varaiable from Nram buffer using NVLib. +// +// Input: UINT32 variable, NVRAM_STORE_INFO *pInfo , UINTN *size +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID *TSEGetNVVariable( UINT32 variable, NVRAM_STORE_INFO *pInfo , UINTN *size ) +{ + VOID *buffer = NULL; +#if TSE_NVRAM_DEFAULTS_SUPPORT //EIP-47260: To build TSE without NVRAM module support. + EFI_STATUS Status = EFI_UNSUPPORTED; + VARIABLE_INFO *varInfo; + //UINT8 Flags; EIP: 49745 To fix the CPU hangs when Core is update to 4.6.4.1 + + varInfo = VarGetVariableInfoIndex( variable ); + if ( varInfo == NULL ) + return buffer; + + *size=0; + Status = NvGetVariable( + varInfo->VariableName, + &varInfo->VariableGuid, + NULL, + size, + buffer, + pInfo, /*&Flags*/ NULL //EIP: 49745 To fix the CPU hangs when Core is update to 4.6.4.1 + + ); + + if ( Status != EFI_BUFFER_TOO_SMALL ) + return buffer; + + buffer = EfiLibAllocatePool( *size ); + if ( buffer == NULL ) + return buffer; + + Status = NvGetVariable( + varInfo->VariableName, + &varInfo->VariableGuid, + NULL, + size, + buffer, + pInfo,/*&Flags*/ NULL //EIP: 49745 To fix the CPU hangs when Core is update to 4.6.4.1 + ); + + if ( EFI_ERROR( Status ) ) + MemFreePointer( (VOID *)&buffer ); + +#endif //TSE_NVRAM_DEFAULTS_SUPPORT + return buffer; +} + +// +//---------------------------------------------------------------------------- +// Procedure: UpdateNVDefautls +// +// Description: Updated the Variable buffer with NVRam Defaults buffer. +// +// Input: UINT32 index, NVRAM_STORE_INFO *NvInfo, NVRAM_VARIABLE * VarPtr +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID UpdateNVDefautls(UINT32 index, NVRAM_STORE_INFO *NvInfo, NVRAM_VARIABLE * VarPtr) +{ + UINTN Nvsize; + UINT8 * NvVarBuffer; + + Nvsize = 0; + NvVarBuffer = TSEGetNVVariable( index, NvInfo , &Nvsize ); + if(NvVarBuffer && Nvsize) + { + if(index == VARIABLE_ID_AMITSESETUP) + { + if(!IsTseLoadPasswordOnDefaults()) + { + // To preserve password + if(Nvsize>=sizeof(AMITSESETUP)) + { + if(VarPtr->Buffer && (VarPtr->Size>=sizeof(AMITSESETUP))) + { + MemCopy(((AMITSESETUP*)NvVarBuffer)->UserPassword, ((AMITSESETUP*)VarPtr->Buffer)->UserPassword,TsePasswordLength*sizeof(CHAR16)); + MemCopy(((AMITSESETUP*)NvVarBuffer)->AdminPassword, ((AMITSESETUP*)VarPtr->Buffer)->AdminPassword,TsePasswordLength*sizeof(CHAR16)); + } + } + } + } + + if(VarPtr->Size >= Nvsize) + { + MemCopy(VarPtr->Buffer,NvVarBuffer,Nvsize); + MemFreePointer( (VOID **)&NvVarBuffer ); + } + else + { + MemFreePointer( (VOID **)&VarPtr->Buffer); + VarPtr->Buffer = NvVarBuffer; + VarPtr->Size = Nvsize; + } + } + +} +#endif + + +// +//---------------------------------------------------------------------------- +// Procedure: TseVarBuildAMIDefaults +// +// Description: function build the AMI defaults +// +// Input: None +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS TseVarBuildAMIDefaults(VOID) +{ + EFI_STATUS Status = EFI_SUCCESS; + UINT32 page, control; + VOID *defaults4FirstBootVar = NULL; +#if TSE_NVRAM_DEFAULTS_SUPPORT //EIP-47260: To build TSE without NVRAM module support. + NVRAM_VARIABLE *OptvarPtr; + NVRAM_VARIABLE *FailsafevarPtr; + UINT32 index; + +#ifdef TSE_FOR_APTIO_4_50 + NVRAM_STORE_INFO NvInfo={0}; + UINTN Nvsize; + UINT8 * NvVarBuffer=NULL; + UINT32 attribute=7; +#endif +#endif + //EIP-93340 Setting "ConstructDefaults4FirstBoot" variable in NVRAM for first boot only + if ( IsSupportDefaultForStringControl() ) + { + EFI_GUID ConstructDefaults4FirstBootGuid = CONSTRUCT_DEFAULTS_FIRST_BOOT_GUID; + UINTN varSize = 0; + + defaults4FirstBootVar = (VOID *)VarGetNvramName (L"ConstructDefaults4FirstBoot", &ConstructDefaults4FirstBootGuid, NULL, &varSize); + if (NULL == defaults4FirstBootVar) + { + VarSetNvramName( L"ConstructDefaults4FirstBoot", &ConstructDefaults4FirstBootGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, &varSize, sizeof (varSize) ); + } + }//EIP-93340 End + + gFailsafeDefaults = EfiLibAllocateZeroPool( sizeof(NVRAM_VARIABLE) * gVariables->VariableCount ); + if ( gFailsafeDefaults == NULL ) + { + Status = EFI_OUT_OF_RESOURCES; + goto DONE; + } + gOptimalDefaults = EfiLibAllocateZeroPool( sizeof(NVRAM_VARIABLE) * gVariables->VariableCount ); + if (gOptimalDefaults == NULL ) + { + Status = EFI_OUT_OF_RESOURCES; + goto DONE; + } +#if TSE_NVRAM_DEFAULTS_SUPPORT //EIP-47260: To build TSE without NVRAM module support. + // Load the Current NVRAM variable then update the defaults. + OptvarPtr = gOptimalDefaults; + FailsafevarPtr = gFailsafeDefaults; + for ( index = 0; index < gVariables->VariableCount; index++, OptvarPtr++, FailsafevarPtr++) + { + if ((VARIABLE_ID_AMITSESETUP == index) && (TseDefaultSetupPasswordSupported ())) + { + OptvarPtr->Buffer = VarGetNvram( index, &OptvarPtr->Size ); + if (OptvarPtr->Buffer) + { + MemSet(OptvarPtr->Buffer, ((TsePasswordLength * 2) * sizeof(CHAR16)), 0 ); //Preserving quietboot details + if ((!DefaultSetupPwdAtFirstBootOnly ())) + { + GetDefaultPassword (AMI_PASSWORD_NONE, &OptvarPtr->Buffer); + } + } + } + else + { + OptvarPtr->Buffer = VarGetNvram( index, &OptvarPtr->Size ); + } + if(OptvarPtr->Size) + { + // init mfg defautls from Std Defaults + FailsafevarPtr->Buffer = EfiLibAllocateZeroPool (OptvarPtr->Size); + if (NULL == FailsafevarPtr->Buffer) + continue; + if (NULL == OptvarPtr->Buffer) //Add the fix for: If name value string is not able to retrieve then system hang + { + OptvarPtr->Buffer = EfiLibAllocateZeroPool (OptvarPtr->Size); + if (NULL == OptvarPtr->Buffer) + continue; + } + MemCopy(FailsafevarPtr->Buffer, OptvarPtr->Buffer,OptvarPtr->Size); + } + else + FailsafevarPtr->Buffer = NULL; + FailsafevarPtr->Size = OptvarPtr->Size; + } +#endif //TSE_NVRAM_DEFAULTS_SUPPORT + + // this is the AMIBCP compatible user defaults + for ( page = 0; page < gPages->PageCount; page++ ) + { + PAGE_INFO *pageInfo = (PAGE_INFO *)((UINTN)gApplicationData + gPages->PageList[page]); + + if(pageInfo->PageHandle ==0) + continue; + if (NULL == gApp) + { + gtempCurrentPage = page; //Will be used in UefiGetQuestionOffset. Since gApp will not be filled but we need handle to find name value variable so + } //saving current page + else + { + gApp->CurrentPage = page; + } + + for ( control= 0; control < pageInfo->PageControls.ControlCount; control++ ) + { + CONTROL_INFO *controlInfo = (CONTROL_INFO *)((UINTN)gControlInfo + pageInfo->PageControls.ControlList[control]); + + if ( ( controlInfo->ControlVariable == VARIABLE_ID_LANGUAGE ) || ( controlInfo->ControlVariable == VARIABLE_ID_BOOT_ORDER ) || (controlInfo->ControlVariable == VARIABLE_ID_BBS_ORDER) ) + continue; + + if ( controlInfo->ControlDataWidth > 0 ) + { + VOID *ifrData = controlInfo->ControlPtr; + UINT8 *failValue = NULL, *optValue = NULL; + UINT32 ControlVarOffset = 0; + + if ( ifrData == NULL ) + continue; + + failValue = (UINT8 *)controlInfo + sizeof(CONTROL_INFO); + optValue = failValue + controlInfo->ControlDataWidth; + + ControlVarOffset = UefiGetQuestionOffset(ifrData); + //EIP-93340 Updating gOptimalDefaults and gFailSafeDefaults for stringType controls based on controlPtr + if (IsSupportDefaultForStringControl () && controlInfo->ControlType == CONTROL_TYPE_POPUP_STRING) + { + CHAR16 *failDefStr = NULL, *optimalDefStr = NULL; + + if (*(UINT16*)(failValue)) + { + failDefStr = (VOID*)HiiGetString( controlInfo->ControlHandle, *(UINT16*)(failValue)); + if (NULL == failDefStr) + continue; + _VarGetSetValue( VAR_COMMAND_SET_VALUE, gFailsafeDefaults, controlInfo->ControlVariable, ControlVarOffset, EfiStrLen(failDefStr)*sizeof(CHAR16), (VOID*)failDefStr ); + } + + if (*(UINT16*)(optValue)) + { + optimalDefStr = (VOID*)HiiGetString( controlInfo->ControlHandle, *(UINT16*)(optValue)); + if (NULL == optimalDefStr) + continue; + _VarGetSetValue( VAR_COMMAND_SET_VALUE, gOptimalDefaults, controlInfo->ControlVariable, ControlVarOffset, EfiStrLen(optimalDefStr)*sizeof(CHAR16), (VOID*)optimalDefStr ); + } + + if (NULL == defaults4FirstBootVar && optimalDefStr) //Modify NVRAM for first time for string type controls based on defaults from controlPtr + { + VOID *optiBuffer = NULL, *failBuffer = NULL; + VARIABLE_INFO *varInfo = (VARIABLE_INFO *)NULL; + UINTN size = 0; + EFI_STATUS status = EFI_SUCCESS; + + varInfo = VarGetVariableInfoIndex (controlInfo->ControlVariable); + + optiBuffer = VarGetNvram( controlInfo->ControlVariable, &size ); + if (NULL == optiBuffer) + { + continue; + } + + MemCopy ( ((UINT8*)optiBuffer)+ControlVarOffset, (UINT8*)optimalDefStr, EfiStrLen(optimalDefStr)*sizeof(CHAR16) ); + + status = VarSetNvramName( varInfo->VariableName, &varInfo->VariableGuid, varInfo->VariableAttributes, optiBuffer, size ); + if (optiBuffer) + MemFreePointer( (VOID **)&optiBuffer ); + } + if (failDefStr) + MemFreePointer( (VOID **)&failDefStr ); + + if (optimalDefStr) + MemFreePointer( (VOID **)&optimalDefStr ); + + } + //EIP-93340 End + else + { + _VarGetSetValue( VAR_COMMAND_SET_VALUE, gFailsafeDefaults, controlInfo->ControlVariable, ControlVarOffset, controlInfo->ControlDataWidth, failValue ); + _VarGetSetValue( VAR_COMMAND_SET_VALUE, gOptimalDefaults, controlInfo->ControlVariable, ControlVarOffset, controlInfo->ControlDataWidth, optValue ); + } + } + } + } + +#ifdef TSE_FOR_APTIO_4_50 +#if TSE_NVRAM_DEFAULTS_SUPPORT //EIP-47260: To build TSE without NVRAM module support. + // StdDefaults + Nvsize = 0; + NvVarBuffer = VarGetNvramName( L"StdDefaults", &DefaultsGuid, &attribute, &Nvsize ); + if(NvVarBuffer && Nvsize) + { + NvInfo.NvramAddress = NvVarBuffer; + NvInfo.NvramSize = Nvsize; + NvInitInfoBuffer(&NvInfo, 0, NVRAM_STORE_FLAG_NON_VALATILE ); + + // Update the defaults. + OptvarPtr = gOptimalDefaults; + for ( index = 0; index < gVariables->VariableCount; index++, OptvarPtr++) + { + UpdateNVDefautls(index, &NvInfo, OptvarPtr); + } + MemFreePointer( (VOID **)&NvVarBuffer ); + } + + // MfgDefaults + Nvsize = 0; + NvVarBuffer = VarGetNvramName( L"MfgDefaults", &DefaultsGuid, &attribute, &Nvsize ); + if(NvVarBuffer && Nvsize) + { + NvInfo.NvramAddress = NvVarBuffer; + NvInfo.NvramSize = Nvsize; + NvInitInfoBuffer(&NvInfo, 0, NVRAM_STORE_FLAG_NON_VALATILE ); + + FailsafevarPtr = gFailsafeDefaults; + for ( index = 0; index < gVariables->VariableCount; index++, FailsafevarPtr++ ) + { + UpdateNVDefautls(index, &NvInfo, FailsafevarPtr); + } + MemFreePointer( (VOID **)&NvVarBuffer ); + } + //EIP-93340 Updating optimalDefaults and gFailsafeDefaults for STRING_TYPE controls + //based on defalut stringID present in controlPtr + GetSetDefaultsFromControlPtr(gOptimalDefaults, gFailsafeDefaults); +#endif //TSE_NVRAM_DEFAULTS_SUPPORT +#endif +DONE: + return Status; +} + +// +//---------------------------------------------------------------------------- +// Procedure: TseBootNowinBootOrderInit +// +// Description: function build the AMI defaults +// +// Input: None +// +// Output: boot order string +// +//---------------------------------------------------------------------------- +// +UINT16 * TseBootNowinBootOrderInit(VOID) +{ + UINT16 *BootOrder=NULL; + UINTN size = 0; + UINTN j,k,i; + + BootOrder = HelperGetVariable(VARIABLE_ID_BOOT_ORDER, L"BootOrder", &gEfiGlobalVariableGuid, NULL, &size ); + //EIP-75352 Suppress the warnings from static code analyzer + if (NULL == BootOrder) { + ASSERT (0); + return NULL; + } + //Find the first disabled option + for ( i = 0; i < gBootOptionCount; i++ ) + { + if ( DISABLED_BOOT_OPTION == BootOrder[i] ) + break; + } + + if(i= gBootOptionCount) + { + //gBootData[j].Option is not present in BootOrder; fill it + BootOrder[i] = gBootData[j].Option; + i++; + } + } + } + return BootOrder; +} + +// +//---------------------------------------------------------------------------- +// Procedure: CheckShiftState +// +// Description: function to check the shift state value +// +// Input: None +// +// Output: 1 - valid shift state +// 0 - invalid shift state +// +//---------------------------------------------------------------------------- +// +BOOLEAN CheckShiftState(UINT32 KeyShiftState, UINT32 HotkeyState) +{ + if( KeyShiftState == HotkeyState) + return 1; + else + return 0; +} + +// +//---------------------------------------------------------------------------- +// Procedure: SupportPrintScreen +// +// Description: function to support the print screen. +// +// Input: None +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID SupportPrintScreen() +{ + EFI_GUID guid = AMITSE_PRINT_SCREEN_PRESS_GUID; + // Install the PrintScreen Notification. + EfiLibNamedEventSignal (&guid); +} + +// +//---------------------------------------------------------------------------- +// Procedure: SupportPrintScreenEvent +// +// Description: function to check the print screen supprot event. +// +// Input: UINT16 ScanCode +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOLEAN SupportPrintScreenEvent(UINT16 ScanCode) +{ + if( ScanCode == TSE_PRN_SCRN_KEY_SCAN ) + return 1; + else + return 0; +} + +// +//---------------------------------------------------------------------------- +// Procedure: IsToggleStateKey +// +// Description: function to check Is any of ToggleStateKey (CapsLock,Numlock ScrollLock) Keys pressed. +// +// Input: ACTION_DATA *Data +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOLEAN IsToggleStateKey(ACTION_DATA *Data) +{ + if(Data->Input.Type == ACTION_TYPE_KEY) + { +#if TSE_USE_AMI_EFI_KEYCODE_PROTOCOL + if(Data->Input.Data.AmiKey.EfiKey == EfiKeyCapsLock || Data->Input.Data.AmiKey.EfiKey == EfiKeySLck || Data->Input.Data.AmiKey.EfiKey == EfiKeyNLck) + return TRUE; + else +#endif + { + // Normal EFI_KEY will return ScanCode and Unicode as 0 for this toggleStateKeys. + if(Data->Input.Data.AmiKey.Key.ScanCode || Data->Input.Data.AmiKey.Key.UnicodeChar) + return FALSE; + else + return TRUE; + } + } + else + return FALSE; +} + +//EIP-96246 Starts +// +//---------------------------------------------------------------------------- +// Procedure: ShowBootOverrideSelectOption +// +// Description: function to Show menu with below option on selecting options under Boot Override +// 1) Override now and clear the BootNext data +// 2) Override now but keep the BootNext data +// 3) Boot to BootNext and clear BootNext data +// Input: VOID +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ShowBootOverrideSelectOption (VOID) +{ + + UINT16 ItemCount = 3,itemSelected = 0; + UINT16 Title, Legend; + UINT8 i; + EFI_STATUS Status; + POSTMENU_TEMPLATE *BootNextOverrideOptionsMenu = NULL; + + UINT16 BootNextOverrideOptionString[3] = {STRING_TOKEN (STR_OVERRIDE_BOOTNEXT_OPTION_1), STRING_TOKEN (STR_OVERRIDE_BOOTNEXT_OPTION_2), STRING_TOKEN (STR_OVERRIDE_BOOTNEXT_OPTION_3)}; + + BootNextOverrideOptionsMenu = EfiLibAllocateZeroPool ( sizeof( POSTMENU_TEMPLATE ) * BOOT_OVERRIDE_OPTION_MENU_COUNT); + + for ( i = 0; i < BOOT_OVERRIDE_OPTION_MENU_COUNT; i++ ) + { + BootNextOverrideOptionsMenu[i].ItemToken = BootNextOverrideOptionString[i]; + BootNextOverrideOptionsMenu[i].Callback = (VOID*)NULL ; + BootNextOverrideOptionsMenu[i].CallbackContext = (VOID*)NULL ; + BootNextOverrideOptionsMenu[i].Attribute = AMI_POSTMENU_ATTRIB_FOCUS; + BootNextOverrideOptionsMenu[i].Key.Key.ScanCode = 0 ; + BootNextOverrideOptionsMenu[i].Key.Key.UnicodeChar = 0 ; + BootNextOverrideOptionsMenu[i].Key.KeyShiftState = 0 ; + } + + + Title = STRING_TOKEN (STR_OVERRIDE_OPTION_MENU_TITLE) ; + Legend = STRING_TOKEN (STR_OVERRIDE_OPTION_MENU_LEGEND) ; + + //To show menu with options + Status = PostManagerDisplayMenu (gHiiHandle, Title, Legend, BootNextOverrideOptionsMenu, BOOT_OVERRIDE_OPTION_MENU_COUNT, &itemSelected); + + if( Status == EFI_SUCCESS ) + { + UINTN size = 0; + UINT16 *pBootNext = NULL; + pBootNext = (UINT16 *)VarGetNvramName (L"BootNext", &gEfiGlobalVariableGuid, NULL, &size); + + //Override now and clear the BootNext data + if ( BootNextOverrideOptionsMenu[itemSelected].ItemToken == BootNextOverrideOptionString[0] ) + { + if( pBootNext && (size == sizeof(UINT16))) + { + //Clear Boot next variable + VarSetNvramName (L"BootNext", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + NULL, + 0); + } + if(pBootNext) + MemFreePointer((void **) &pBootNext); + Status = EFI_SUCCESS; + } + //Override now but keep the BootNext data + else if(BootNextOverrideOptionsMenu[itemSelected].ItemToken == BootNextOverrideOptionString[1]) + { + Status = EFI_SUCCESS; + return Status; + } + //Boot to BootNext and clear BootNext data + else if(BootNextOverrideOptionsMenu[itemSelected].ItemToken == BootNextOverrideOptionString[2]) + { + if( pBootNext && (size == sizeof(UINT16))) + { + //Clear Boot next variable + VarSetNvramName (L"BootNext", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + NULL, + 0); + if(!gResetRequired) + { + if(!gDoNotBoot) + { + gApp->ClearScreen = TRUE; + StyleExit(); + if (gST->ConOut != NULL) + { + gST->ConOut->EnableCursor( gST->ConOut, FALSE ); + gST->ConOut->SetAttribute( gST->ConOut, (EFI_BACKGROUND_BLACK | EFI_WHITE)); + gST->ConOut->ClearScreen( gST->ConOut); + } + BootLaunchBootOption(*pBootNext, NULL, 0); //Boot to BootNext option + StyleInit(); + } + } + } + if(pBootNext) + MemFreePointer((void **) &pBootNext); + + Status = EFI_UNSUPPORTED; + } + } + return Status; +} +//EIP-96246 Ends + +//EIP-93340 Start +// +//---------------------------------------------------------------------------- +// Procedure: GetSetDefaultsFromControlPtr +// +// Description: Function to get default stringID for String Type control from controlPtr and +// fetch respective string from Hii database and set as default to NVRAM, gOptimalDefaults, gFailSafeDefaults buffer +// Input: NVRAM_VARIABLE *OptimalDefs, NVRAM_VARIABLE *FailSafeDefs +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS GetSetDefaultsFromControlPtr(NVRAM_VARIABLE *optimalDefaultlist, NVRAM_VARIABLE *failSafeDefaultlist) +{ + EFI_STATUS status = EFI_UNSUPPORTED; + + if ( IsSupportDefaultForStringControl () ) + { + UINT32 page = 0, control = 0; + + for ( page = 0; page < gPages->PageCount; page++ ) + { + PAGE_INFO *pageInfo = (PAGE_INFO *)((UINTN)gApplicationData + gPages->PageList[page]); + + if(pageInfo->PageHandle ==0) + continue; + + for ( control= 0; control < pageInfo->PageControls.ControlCount; control++ ) + { + CONTROL_INFO *controlInfo = (CONTROL_INFO *)((UINTN)gControlInfo + pageInfo->PageControls.ControlList[control]); + + if ( ( controlInfo->ControlVariable == VARIABLE_ID_LANGUAGE ) || ( controlInfo->ControlVariable == VARIABLE_ID_BOOT_ORDER ) || (controlInfo->ControlVariable == VARIABLE_ID_BBS_ORDER) ) + continue; + + //To update Optimal and FailSafe defaults with STRING default based on StringID from controlPtr + if ( (controlInfo->ControlType == CONTROL_TYPE_POPUP_STRING) && (controlInfo->ControlDataWidth > 0) ) + { + if ( (optimalDefaultlist) || (failSafeDefaultlist)) + { + CHAR16 *failDefStr = NULL, *optimalDefStr = NULL; + UINT8 *failValue, *optValue; + UINT32 ControlVarOffset, size = 0; + + //Getting stringID if any present in controlPtr for failsafe default + failValue = (UINT8 *)controlInfo + sizeof(CONTROL_INFO); + + //Getting stringID if any present in controlPtr for optimal default + optValue = failValue + controlInfo->ControlDataWidth; + //size = controlInfo->ControlDataWidth; + + size = UefiGetWidth (controlInfo->ControlPtr) * sizeof(CHAR16); + ControlVarOffset = UefiGetQuestionOffset(controlInfo->ControlPtr); + + //Getting string based on StrigID from controlPtr and updating failsafeDefaults + if (NULL != failSafeDefaultlist) + { + if (*(UINT16*)(failValue)) + { + failDefStr = (VOID*)HiiGetString( controlInfo->ControlHandle, *(UINT16*)(failValue)); + if (NULL == failDefStr) + continue; + _VarGetSetValue( VAR_COMMAND_SET_VALUE, gFailsafeDefaults, controlInfo->ControlVariable, ControlVarOffset, EfiStrLen(failDefStr)*sizeof(CHAR16), failDefStr ); + } + } + + //Getting string based on StrigID from controlPtr and updating optimalDefaults + if (NULL != optimalDefaultlist) + { + if (*(UINT16*)(optValue)) + { + optimalDefStr = (VOID*)HiiGetString( controlInfo->ControlHandle, *(UINT16*)(optValue)); + if (NULL == optimalDefStr) + continue; + status = _VarGetSetValue( VAR_COMMAND_SET_VALUE, gOptimalDefaults, controlInfo->ControlVariable, ControlVarOffset, EfiStrLen(optimalDefStr)*sizeof(CHAR16), optimalDefStr ); + } + } + + if (failDefStr) + MemFreePointer( (VOID **)&failDefStr ); + + if (optimalDefStr) + MemFreePointer( (VOID **)&optimalDefStr ); + }//End of optimal/Failsafe condition check + }//End of ControlType condition check + }//End of control iteration + }//End of Page iteration + }//End of Default support condition check + return status; +} +//EIP-93340 End +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2014, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/TseAdvanced.cif b/EDK/MiniSetup/TseAdvanced/TseAdvanced.cif new file mode 100644 index 0000000..6ca25c9 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/TseAdvanced.cif @@ -0,0 +1,28 @@ + + name = "TSE Sources - Advanced TSE" + category = ModulePart + LocalRoot = "EDK\MiniSetup\TseAdvanced" + RefName = "TseAdvanced" +[files] +"TseAdvanced.sdl" +"TseAdvanced.mak" +"MyDefs.h" +"iJpeg.c" +"jpeg6.c" +"Jpeg6.h" +"jpeg.h" +"Logo.c" +"ipcx.c" +"pcx.h" +"pcxc.c" +"dogifmgr.c" +"dogif.c" +"Bbs.c" +"TseAdvanced.c" +"special.c" +"special.h" +"bootflowLib.c" +"png.c" +"png.h" +"pnguncmp.c" + diff --git a/EDK/MiniSetup/TseAdvanced/TseAdvanced.mak b/EDK/MiniSetup/TseAdvanced/TseAdvanced.mak new file mode 100644 index 0000000..3112ab3 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/TseAdvanced.mak @@ -0,0 +1,160 @@ +##*****************************************************************## +##*****************************************************************## +##*****************************************************************## +##** **## +##** (C)Copyright 2010, American Megatrends, Inc. **## +##** **## +##** All Rights Reserved. **## +##** **## +##** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **## +##** **## +##** Phone (770)-246-8600 **## +##** **## +##*****************************************************************## +##*****************************************************************## +##*****************************************************************## +## $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/TseAdvanced.mak $ +## +## $Author: Arunsb $ +## +## $Revision: 14 $ +## +## $Date: 10/18/12 5:53a $ +## +##*****************************************************************## +##*****************************************************************## +## Revision History +## ---------------- +## $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/TseAdvanced.mak $ +# +# 14 10/18/12 5:53a Arunsb +# Updated for 2.16.1235 QA submission +## +## 11 10/10/12 12:35p Arunsb +## Synched the source for v2.16.1232, backup with Aptio +# +# 13 1/07/11 1:20a Mallikarjunanv +# [TAG] EIP47260 +# [Description] Updated the changes made in EIP:47260 proprely +# +# 12 12/29/10 6:12a Mallikarjunanv +# [TAG] EIP 47260 +# [Category] Improvement +# [Description] Updated TSE_NVRAM_SUPPORT with +# TSE_NVRAM_DEFAULTS_SUPPORT sdl token name +# [Files] TseAdvanced.mak, TseAdvanced.sdl, TseAdvanced.c +# +# 10 9/21/10 6:28p Madhans +# [TAG] - +# [Category] BUILD ISSUE FIX +# [Symptom] Build issues When TSEsource listed before TSE binary module +# [RootCause] ExitPageElinkList Is added TSEadvanced.mak +# [Solution] remove the ExitPageElinkList from TSEadvanced.mak +# [Files] TSEadvanced.mak +# # +# +# 9 6/04/10 12:51p Blaines +# Add ExitPageElinkList +# +# 8 4/23/10 6:04p Madhans +# to cleanup. +# +# 7 4/16/10 5:13p Madhans +# Changes for Tse 2.02. Please see Changelog.log for more details. +# +# 6 2/19/10 1:04p Madhans +# Updated for TSE 2.01. Refer Changelog.log for File change history. +## +## 5 2/19/10 8:11a Mallikarjunanv +## updated year in copyright message +## +## 4 8/17/09 12:23p Presannar +## Removed include path to core dir +## +## 3 6/24/09 6:10p Madhans +## Made TSE_USE_EDK_LIBRARY=OFF to not to refer EDK module. +## +## 2 6/12/09 7:43p Presannar +## Initial implementation of coding standards for AMITSE2.0 +## +## 1 6/04/09 8:05p Madhans +# +# 2 5/07/09 10:36a Madhans +# Changes after Bin module +# +# 1 4/28/09 11:16p Madhans +# Tse 2.0 Code complete Checkin. +## +## 1 4/28/09 10:27p Madhans +## Tse 2.0 Code complete Checkin. +## +## 1 12/18/08 7:59p Madhans +## Intial version of TSE Lite sources +## +## +##*****************************************************************## +##*****************************************************************## + +# MAK file for the eModule:TseLite + +TSE_ADVANCED_INCLUDES = \ + -I $(TSE_ADVANCED_DIR) \ + -I $(TSE_STYLE_DIR) \ +!if "$(UEFI_SOURCES_SUPPORT)" == "1" + -I $(UEFISRC_DIR) \ +!endif + -I $(TSESRC_DIR) \ + -I $(TSESRC_DIR)\AMILOGO \ + -I $(TSELITESRC_DIR) \ +!if "$(TSE_BOARD_SOURCE_SUPPORT)" == "1" + -I $(TSE_BOARD_DIR)\ +!endif + -I $(TSEBIN_DIR) \ + -I $(TSEBIN_DIR)\Inc \ + -I $(PROJECT_DIR)\Include\Protocol \ + -I $(PROJECT_DIR) \ + -I $(PROJECT_DIR)\Include \ + -I $(BUILD_DIR) \ + +$(BUILD_DIR)\TseAdvanced.lib : TseAdvancedLib + +TseAdvancedLib : $(BUILD_DIR)\TseAdvanced.mak TseAdvancedLibBin + +$(BUILD_DIR)\TseAdvanced.mak : $(TSE_ADVANCED_DIR)\$(@B).cif $(TSE_ADVANCED_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(TSE_ADVANCED_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +!if "$(TSE_USE_EDK_LIBRARY)" == "1" +TSE_DEFAULTS = $(EDK_DEFAULTS) +!else +TSE_DEFAULTS = $(BUILD_DEFAULTS) +!endif + +!if "$(TSE_NVRAM_DEFAULTS_SUPPORT)" == "1" ##EIP-47260: to build TSE without NVRAM module support +TseAdvancedLibBin : $(BUILD_DIR)\NVRAMDXE.lib +!else +#if nvram_support is disabled, then OEM should provide their own variable library name here +TseAdvancedLibBin : +!endif + $(MAKE) /$(MAKEFLAGS) $(TSE_DEFAULTS)\ + /f $(BUILD_DIR)\TseAdvanced.mak all\ + "MY_INCLUDES=$(TSE_ADVANCED_INCLUDES)"\ + "UNI_INCLUDE_PATH=$(TSEBIN_DIR)"\ + TYPE=LIBRARY \ + "EXT_HEADERS=$(BUILD_DIR)\token.h"\ + LIBRARY_NAME=$(BUILD_DIR)\TseAdvanced.lib\ + "CFLAGS=$(CFLAGS) /DTSE_FOR_APTIO_4_50" + + +##*****************************************************************## +##*****************************************************************## +##** **## +##** (C)Copyright 2010, American Megatrends, Inc. **## +##** **## +##** All Rights Reserved. **## +##** **## +##** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **## +##** **## +##** Phone (770)-246-8600 **## +##** **## +##*****************************************************************## +##*****************************************************************## diff --git a/EDK/MiniSetup/TseAdvanced/TseAdvanced.sdl b/EDK/MiniSetup/TseAdvanced/TseAdvanced.sdl new file mode 100644 index 0000000..acf7657 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/TseAdvanced.sdl @@ -0,0 +1,42 @@ +TOKEN + Name = "TSE_ADVANCED_SUPPORT" + Value = "1" + Help = "Main switch to enable Ezport Style in TSE" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "TSE_SEPERATE_EFI_LEGACY_OPTIONS" + Value = "0" + Help = "Turn on to have EFI options and Legacy options seperate. This will have effect only if BDS also seperates EFI and Legacy options." + TokenType = Boolean + TargetH = Yes +End + +TOKEN + Name = "TSE_NVRAM_DEFAULTS_SUPPORT" + Value = "1" + Help = "To enable NVRAM support in TSE modules. This token requires TSE Sources support" + TokenType = Boolean + TargetH = Yes + TargetMAK = Yes + Token = "NVRAM_SUPPORT" "!=" "0" +End + +PATH + Name = "TSE_ADVANCED_DIR" +End + +MODULE + Help = "Includes TseAdvanced.mak to Project" + File = "TseAdvanced.mak" +End + +ELINK + Name = "$(BUILD_DIR)\TseAdvanced.lib" + Parent = "$(TSE_ADVANCED_DIR)\TseAdvanced$(ARCH).lib" + InvokeOrder = ReplaceParent +End diff --git a/EDK/MiniSetup/TseAdvanced/bootflowLib.c b/EDK/MiniSetup/TseAdvanced/bootflowLib.c new file mode 100644 index 0000000..32fdc36 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/bootflowLib.c @@ -0,0 +1,199 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/bootflowLib.c $ +// +// $Author: Premkumara $ +// +// $Revision: 8 $ +// +// $Date: 8/28/14 8:42a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/bootflowLib.c $ +// +// 8 8/28/14 8:42a Premkumara +// [TAG] EIP142551 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] Mouse Movement is not initialized to Full Screen Resolution +// in case of quiet boot mode with high resolution OEM Logo. +// [Root Cause] Mouse Initialization was not across the full screen incase +// of High Resolution Quiet Boot Logo. +// [Solution] Initialised the Mouse with the Resolution Set in case of +// Quiet Boot logo so that Mouse will move acroos the Whole screen +// [Files] Mouse.c, BootFlowLib.c, PostMgmt.c, PostMgmtExt.c, +// Notify.c, MinisetupExt.c +// +// 7 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 9 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 6 3/26/10 5:06p Madhans +// EIP 36704 : Fix for Making sure to make the Variable to NULL after it +// is Freed up. +// +// 5 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 6 2/19/10 8:12a Mallikarjunanv +// updated year in copyright message +// +// 5 1/29/10 4:37p Madhans +// To not to depend on ConsoleControl and ConOut. +// +// 4 10/12/09 4:11p Madhans +// //EIP 28577 : Fix to avoid "Checker: SIGN_EXTENSION" +// +// 3 7/08/09 3:35p Madhans +// In Aptio use the Text mode as is it in post screen +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 2 1/07/08 10:34a Arunkumars +// Stand alone application support for x64 and nt32 +// +// 1 7/09/07 1:29p Arunkumars +// - Added elink hooks for Logo, Password management and Control Keys +// customizations +// +//*****************************************************************// +//*****************************************************************// + +#include "minisetup.h" +BOOLEAN IsMouseSupported(VOID); +BOOLEAN IsSoftKbdSupported(VOID); +static MSGBOX_DATA *_gBootFlowMsg = NULL; + +VOID _BootFlowCancelTimer( EFI_EVENT Event, VOID *Context ) +{ + if ( _gBootFlowMsg != NULL ) + gMsgBox.Destroy( _gBootFlowMsg, TRUE ); + + _gBootFlowMsg = NULL; + + TimerStopTimer( &Event ); +} + +VOID _BootFlowShowMessageBox( BOOT_FLOW *bootFlowPtr ) +{ + AMI_IFR_MSGBOX msgBox; + CONTROL_INFO dummy; + +#ifndef STANDALONE_APPLICATION + if ( gConsoleControl != NULL ) + gConsoleControl->SetMode( gConsoleControl, EfiConsoleControlScreenText ); +#endif + + if (gST->ConOut == NULL) // Headless system/NoVideo in BIOS + return; + + gST->ConOut->Reset( gST->ConOut, FALSE ); +#if !APTIO_4_00 + SetDesiredTextMode(); +#else + // In Aptio use the Text mode as is it in post screen + if(EFI_ERROR(gST->ConOut->QueryMode( gST->ConOut, gST->ConOut->Mode->Mode, &gMaxCols, &gMaxRows ))) + { + gMaxRows = StyleGetStdMaxRows(); + gMaxCols = StyleGetStdMaxCols(); + } +#endif + + if(IsMouseSupported()&& IsSoftKbdSupported())//Initializing the mouse at post when mouse and softkbd present + MouseInit(); + + ClearScreen( EFI_BACKGROUND_BLACK | EFI_LIGHTGRAY ); + + MemSet( &msgBox, sizeof(msgBox), 0 ); + msgBox.Text = bootFlowPtr->MessageBoxToken; + + MemSet( &dummy, sizeof(dummy), 0 ); + dummy.ControlHandle = INVALID_HANDLE; + dummy.ControlPtr = (VOID*)(UINTN)&msgBox; + dummy.ControlFlags.ControlVisible = TRUE; + + gMsgBox.Create( &_gBootFlowMsg ); + if ( _gBootFlowMsg == NULL ) + return; + + gMsgBox.Initialize( _gBootFlowMsg, &dummy ); + gMsgBox.SetType( _gBootFlowMsg, MSGBOX_TYPE_NULL ); + gMsgBox.Draw( _gBootFlowMsg ); + + if ( bootFlowPtr->MessageBoxTimeout != 0 ) + { + EFI_EVENT Event; + + //EIP 28577 : Fix to avoid "Checker: SIGN_EXTENSION" + TimerCreateTimer( &Event, _BootFlowCancelTimer, NULL, + TimerRelative, MultU64x32( (UINT64)TIMER_ONE_SECOND, (UINT32) bootFlowPtr->MessageBoxTimeout ), EFI_TPL_CALLBACK ); + } +} + +VOID _BootFlowSetActivePage( BOOT_FLOW *bootFlowPtr ) +{ + PAGE_INFO *pageInfo; + UINT32 i; + + for ( i = 0; i < gPages->PageCount; i++ ) + { + pageInfo = (PAGE_INFO *)((UINTN)gSetupPkg + gPages->PageList[i]); + if ( + ( bootFlowPtr->PageClass == gPageIdInfo[pageInfo->PageIdIndex].PageClass ) && + ( bootFlowPtr->PageSubClass == gPageIdInfo[pageInfo->PageIdIndex].PageSubClass ) && + ( bootFlowPtr->PageFormID == pageInfo->PageFormID ) + ) + { + gEnterSetup = TRUE; + gStartPage = i; + break; + } + } + +} + +VOID _BootFlowSetActiveControl( BOOT_FLOW *bootFlowPtr ) +{ + // select the control from the currently active page +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/dogif.c b/EDK/MiniSetup/TseAdvanced/dogif.c new file mode 100644 index 0000000..0c641eb --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/dogif.c @@ -0,0 +1,1197 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/dogif.c $ +// +// $Author: Arunsb $ +// +// $Revision: 8 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/dogif.c $ +// +// 8 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 10 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 7 3/28/11 9:35p Arunsb +// [TAG] EIP55548 +// [Category] Improvement +// [Description] Support to display Multiple GIF and to display other +// image format when Active animated Gif is displaying +// [Files] dogif.c and dogifmgr.c +// +// 6 3/21/11 1:16a Rajashakerg +// [TAG] EIP53740 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Animation does not continue after the last frame of the +// logo. +// [RootCause] The animation is done upto last frame of the animated +// image. +// [Solution] Fixed the issue by handling Gif image data to redraw image +// if all the frames are completed and if boottimeout is present. +// [Files] minisetup.h, dogif.c, dogifmgr.c +// +// 5 6/17/10 2:59p Madhans +// Dynamic parsing support in TSE. +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 7 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 6 2/15/10 10:12p Madhans +// To avoid warnings +// +// 5 1/09/10 4:46a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 4 12/04/09 7:12a Mallikarjunanv +// Fix for EIP:30263 - Gif Logo Issue +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 2 7/06/06 6:38p Arunkumars +// warn fix +// +// 1 1/24/06 3:01a Stefanor +// quiet boot support +// implementation of buffering for POST messages +// gif support +// support for OEM badging protocol +// fixed fallback from 100x31 to 80x25 +// cleanup of set graphic/text mode +// ver 1.17.1051 +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: dogif.c +// +// Description: This file contains code for gif image handling +// +//---------------------------------------------------------------------------- +// +#include + +// definitions +#undef DEBUG +#undef TRUE +#undef FALSE + +#define DEBUG 0 +#define TIANO 1 +#if TIANO +#define TRUE 1 +#else +#define TRUE (-1) +#endif +#define FALSE 0 + +#define MaxColors 256 /* rev 87a */ + +struct ColorEntry + { + unsigned char blue, green, red, dummy; + }; + +#if TIANO +#define short int +//#define unsigned +#define huge +#define far +unsigned char * blitbuf = 0; +static struct ColorEntry * pColorMap = 0; +#else +#define _FP_SEG(fp) (*((unsigned __far *)&(fp)+1)) +#define _FP_OFF(fp) (*((unsigned __far *)&(fp))) +#define _MK_FP(seg, offset) (void __far *)(((unsigned long)seg << 16) \ + + (unsigned long)(unsigned)offset) +#endif + +// variables +#if TIANO +int screen_width = 800; +int screen_height = 600; +#else +int screen_width = 640; +int screen_height = 480; +#endif + +unsigned char huge * pbuf = 0; +unsigned long lenbuf = 0; +unsigned long firstframeadd = 0; //EIP: 53740 global decleration such that we access the first frame address of the gif image + +static char GIF87signature[] = "GIF87a"; +static char GIF89signature[] = "GIF89a"; +static char GIFversion = 0; +#define GIF87 1 +#define GIF89 2 +static struct ColorEntry GlobalColorMap[MaxColors] = {{0}}; +static struct ColorEntry LocalColorMap[MaxColors] = {{0}}; +static unsigned int BackdropWidth = 0; +static unsigned int BackdropHeight = 0; +static unsigned int LeftMargin = 0; +static unsigned int TopMargin = 0; +static unsigned int ColorRez = 0; +static unsigned int FillColor = 0; +#if TIANO +static short DefaultNumColors = 0; +#else +static unsigned int DefaultNumColors = 0; +#endif +static unsigned int LeftEdge = 0; +static unsigned int TopEdge = 0; +static unsigned int Width = 0; +static unsigned int Height = 0; +static unsigned int Interlaced = 0; +#if TIANO +static short LocalNumColors = 0; +#else +static unsigned int LocalNumColors = 0; +#endif +static unsigned int RightEdge = 0; +static unsigned int BottomEdge = 0; +static unsigned int InterlacePass = 0; +static unsigned int X = 0; +static unsigned int Y = 0; +static short BaseLine[5] = {0, 4, 2, 1, 0}; +static short LineOffset[5] = {8, 8, 4, 2, 0}; + +unsigned char huge * pcurbuf = 0; +static unsigned long unreadbuf = 0; + +static unsigned int CurrentBank = 0; +static unsigned long PixelAdd = 0; + +static int TransparentColor = -1; +static int GlobalColorMapActive = FALSE; + +static int UnexpectedError = FALSE; + +// functions +#if TIANO +unsigned long dofirst( unsigned char *, unsigned long ); +unsigned long donext( unsigned char * ); +#else +unsigned long far _loadds dofirst(void); +unsigned long far _loadds donext(void); +#endif +static int _inline readbuf(void); +static void _inline writepixel(unsigned char); +static void setbank(unsigned int); +static short ReadScreenDesc(void); +static short ReadImageDesc(void); +static unsigned long ReadGraphicControlExt(void); +#if DEBUG +static short ReadCommentExt(void); +static short ReadPlainTextExt(void); +static short ReadApplicationExt(void); +#endif +static short SkipObject(void); +static void SetPalette( struct ColorEntry [], unsigned int ); +static short Expand_Data(void); + +extern UINT16 gGifSrcX; +extern UINT16 gGifSrcY; +extern UINT16 gGifDestX; +extern UINT16 gGifDestY; +extern BOOLEAN GifImageFlag; + +// Expander +struct code_entry + { + short prefix; /* prefix code */ + char suffix; /* suffix character */ + char stack; + }; +static short code_size = 0; +static short clear_code = 0; +static short eof_code = 0; +static short first_free = 0; +static short bit_offset = 0; +static short byte_offset = 0; +static short bits_left = 0; +static short max_code = 0; +static short free_code = 0; +static short old_code = 0; +static short input_code = 0; +static short code = 0; +static short suffix_char = 0; +static short final_char = 0; +static short bytes_unread = 0; +static unsigned char code_buffer[64] = {0}; +static struct code_entry code_table[4096] = {0}; +static short mask[12] = + {0x001, 0x003, 0x007, 0x00F, + 0x01F, 0x03F, 0x07F, 0x0FF, + 0x1FF, 0x3FF, 0x7FF, 0xFFF}; +static unsigned int endofdata = 0; + +#if TIANO +unsigned long dofirst( unsigned char * filemem, unsigned long filememlen ) +#else +unsigned long far _loadds dofirst( ) +#endif +{ + +#if TIANO + pbuf = filemem; + lenbuf = filememlen; +#endif + pcurbuf = pbuf; + unreadbuf = lenbuf; + if (!ReadScreenDesc()) + { + /* Invalid GIF dataset */ +#if DEBUG + printf("\nnot a GIF file - 1\n"); +#endif + return 0xffffffffL; + } +#if DEBUG + printf("\nscreen width = %d, screen height = %d\n", BackdropWidth, BackdropHeight); + printf("# of colors = %d out of %ld\n", DefaultNumColors, (long)(1L << (3*ColorRez))); + printf("fill color index = %d\n", FillColor); +#endif + + SetPalette( GlobalColorMap, DefaultNumColors ); + GlobalColorMapActive = TRUE; + +#if TIANO + LeftMargin = 0; + TopMargin = 0; + screen_width = BackdropWidth; + screen_height = BackdropHeight; + firstframeadd = (unsigned long)pcurbuf;//EIP:53740 Storing the first frame address and unread buffer length of the first frame to a static global variable + return (BackdropWidth << 16) | BackdropHeight; +#else + LeftMargin = ( screen_width - BackdropWidth ) / 2; + TopMargin = ( screen_height - BackdropHeight ) / 2; +#if DEBUG + printf("LeftMargin = %d, TopMargin = %d\n", LeftMargin, TopMargin); +#endif + if (FillColor > 0) + { + /* Set the default color palette. Flood the backdrop region with + the FillColor. */ + setbank( 0 ); + Width = BackdropWidth; + Height = BackdropHeight; + LeftEdge = 0; + TopEdge = 0; + RightEdge = LeftEdge + Width - 1; + BottomEdge = TopEdge + Height - 1; + Interlaced = 0; +#if DEBUG + printf("LeftEdge = %d, RightEdge = %d, Width = %d\n", LeftEdge, RightEdge, Width); + printf("TopEdge = %d, BottomEdge = %d, Height = %d\n", TopEdge, BottomEdge, Height); +#endif + X = LeftEdge; + Y = TopEdge; + InterlacePass = 0; + { + PixelAdd = ( Y + TopMargin ) * (unsigned long)screen_width + ( X + LeftMargin ); + if( CurrentBank != (PixelAdd >> 16) ) + setbank((unsigned int)(PixelAdd >> 16)); + } + for( ; Y <= BottomEdge ; Y++ ) + for( ; X <= BottomEdge ; X++ ) + writepixel( (unsigned char)FillColor ); + } + return donext(); +#endif +} + +#if TIANO +unsigned long donext( unsigned char * BlitBuf ) +#else +unsigned long far _loadds donext( ) +#endif +{ + unsigned int Done; + short Id; /* object identifier */ + short Status; /* return status code */ + unsigned long ret = 0; + +#if TIANO + blitbuf = BlitBuf; +#endif + Done = FALSE; + /* Now display one or more GIF objects */ + while(!Done) + { + switch (readbuf()) + { + case ';': + /* End of the GIF dataset */ + Done = TRUE; + break; + + case ',': + /* Start of an image object. + Read the image description. */ + if (!ReadImageDesc()) + { + /* Invalid GIF dataset */ +#if DEBUG + printf("\nnot a GIF file - 2\n"); +#endif + ret = 0xffffffffL; + Done = TRUE; + break; + } + /* Setup the color palette for the image */ + if (LocalNumColors > 0) + { + /* Change the palette table */ + SetPalette( LocalColorMap, LocalNumColors ); + GlobalColorMapActive = FALSE; + } + else if (DefaultNumColors > 0) + { + /* Reset the palette table back to the default setting */ + if( !GlobalColorMapActive ) + { + SetPalette( GlobalColorMap, DefaultNumColors ); + GlobalColorMapActive = TRUE; + } + } + + X = LeftEdge; + Y = TopEdge; + RightEdge = LeftEdge + Width - 1; + BottomEdge = TopEdge + Height - 1; + + ///Need to update the image based on the current frame coordinates. + gGifSrcX = (UINT16)LeftEdge; + gGifSrcY = (UINT16)TopEdge; + if(Width) gGifDestX = (UINT16)Width-1; + if(Height) gGifDestY = (UINT16)Height-1; + GifImageFlag=1; + +#if DEBUG + printf("LeftEdge = %d, RightEdge = %d, Width = %d\n", LeftEdge, RightEdge, Width); + printf("TopEdge = %d, BottomEdge = %d, Height = %d\n", TopEdge, BottomEdge, Height); +#endif + InterlacePass = 0; + { + PixelAdd = ( Y + TopMargin ) * (unsigned long)screen_width + ( X + LeftMargin ); + if( CurrentBank != (PixelAdd >> 16) ) + setbank((unsigned int)(PixelAdd >> 16)); + + } + + Status = Expand_Data(); + + if (Status != 0) + { + /* Error expanding the raster image */ +#if DEBUG + printf("\nnot a GIF file - 3\n"); +#endif + ret = 0xffffffffL; + Done = TRUE; + break; + } + break; + + case '!': + /* Start of an extended object (not in rev 87a) */ + Id = readbuf(); /* Get the object identifier */ + if (Id < 0) + { + /* Error reading object identifier */ +#if DEBUG + printf("\nnot a GIF file - 4\n"); +#endif + ret = 0xffffffffL; + Done = TRUE; + break; + } + switch ( Id ) + { + case 0xF9: + ret = ReadGraphicControlExt(); + if( ret != 0 ) + { +#if DEBUG + if (ret == 0xffffffffL) + printf("\nnot a GIF file - 9\n"); +#endif + Done = TRUE; + } + break; +#if DEBUG + case 0xFE: + if (!ReadCommentExt()) + { + printf("\nnot a GIF file - 6\n"); + ret = 0xffffffffL; + Done = TRUE; + } + break; + case 0x01: + if (!ReadPlainTextExt()) + { + printf("\nnot a GIF file - 7\n"); + ret = 0xffffffffL; + Done = TRUE; + } + break; + case 0xFF: + if (!ReadApplicationExt()) + { + printf("\nnot a GIF file - 8\n"); + ret = 0xffffffffL; + Done = TRUE; + } + break; +#endif + default: + /* Since there no extented objects defined in rev 87a, we + will just skip over them. In the future, we will handle + the extended object here. */ + if (!SkipObject()) + { +#if DEBUG + printf("\nnot a GIF file - 5\n"); +#endif + ret = 0xffffffffL; + Done = TRUE; + } + break; + } + break; + + default: + /* Error */ +#if DEBUG + printf("\nnot a GIF file - 10\n"); +#endif + ret = 0xffffffffL; + Done = TRUE; + break; + } + } +#if DEBUG + printf("offset = %lx\n", lenbuf-unreadbuf); + printf("wait = %ld\n", ret); +#endif + if( (ret > 0) && (ret < 100) ) + ret = 100; + return ret; +} + +// +//---------------------------------------------------------------------------- +// Procedure: readbuf +// +// Description: Read the next byte from buffer +// +// Input: None +// +// Output: 0 .. 255 the byte +// -1 end of file +// +//---------------------------------------------------------------------------- +// +static int _inline readbuf( ) +{ + + if( unreadbuf == 0 ) + return -1; + + unreadbuf--; +#if TIANO + return (((int)*pcurbuf++)&0xff); +#else + return (int) *pcurbuf++; +#endif +} + +// +//---------------------------------------------------------------------------- +// Procedure: writepixel +// +// Description: Write a pixel at (X,Y) on the screen. +// +// Input: unsigned char Pixel +// +// Output: None +// +//---------------------------------------------------------------------------- +// +static void _inline writepixel(unsigned char Pixel) +{ + unsigned char far * fp; + // Display the pixel on the screen + if( Pixel != TransparentColor ) + { +#if TIANO + fp = blitbuf + PixelAdd * 4; + *fp++ = pColorMap[Pixel].blue; + *fp++ = pColorMap[Pixel].green; + *fp++ = pColorMap[Pixel].red; + *fp++ = 0; +#else + fp = _MK_FP( 0xa000, PixelAdd ); + *fp = Pixel; +#endif + } + // Advance the point + X++; + PixelAdd++; + if (X > RightEdge) + { + X = LeftEdge; + + if (Interlaced) + { + Y += LineOffset[InterlacePass]; + if (Y > BottomEdge) + { + InterlacePass++; + Y = TopEdge + BaseLine[InterlacePass]; + } + } + else + Y++; + PixelAdd = ( Y + TopMargin ) * (unsigned long)screen_width + ( X + LeftMargin ); + } + if( CurrentBank != (PixelAdd >> 16) ) + setbank((unsigned int)(PixelAdd >> 16)); +} + +static void setbank(unsigned int bank) +{ + CurrentBank = bank; +#if TIANO == 0 + _asm + { + mov ax,4f05h + mov bx,0 + mov dx,CurrentBank + int 10h + /*mov retvesa,ax*/ + } + + _asm + { + mov ax,4f05h + mov bx,1 + mov dx,CurrentBank + int 10h + /*mov retvesa,ax*/ + } + +#endif +} + +// +//---------------------------------------------------------------------------- +// Procedure: ReadScreenDesc +// +// Description: Read the signature, the screen description, and the optional +// default color map. +// +// Input: None +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +static short ReadScreenDesc( ) +{ + unsigned char Buffer[16]; + + short + I, J, + Status, + HaveColorMap, + NumPlanes; + + for (I = 0; I < 13; I++) + { + Status = readbuf(); + if (Status < 0) return FALSE; + Buffer[I] = (unsigned char) Status; + } + + for (I = 0; I < 6; I++) + if (Buffer[I] != GIF87signature[I]) + break; + if (I >= 6) + GIFversion = GIF87; + else + { + for (I = 0; I < 6; I++) + if (Buffer[I] != GIF89signature[I]) + break; + if (I >= 6) + GIFversion = GIF89; + else + return FALSE; + } + + BackdropWidth = Buffer[6] | Buffer[7] << 8; + BackdropHeight = Buffer[8] | Buffer[9] << 8; + NumPlanes = (Buffer[10] & 0x07) + 1; + ColorRez = ((Buffer[10] & 0x70) >> 4) + 1; + HaveColorMap = (Buffer[10] & 0x80) != 0; + DefaultNumColors = 1 << NumPlanes; + FillColor = Buffer[11]; + + if (HaveColorMap) + { + for (I = 0; I < DefaultNumColors; I++) + { + for (J = 0; J < 3; J++) + { + Status = readbuf(); + if (Status < 0) return FALSE; + Buffer[J] = (unsigned char) Status; + } + + if (I < MaxColors) + { + GlobalColorMap[I].red = Buffer[0]; + GlobalColorMap[I].green = Buffer[1]; + GlobalColorMap[I].blue = Buffer[2]; + } + } + } + else + DefaultNumColors = 0; + + return TRUE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: ReadImageDesc +// +// Description: Read the image description and the optional color map. +// +// Input: None +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +static short ReadImageDesc( ) +{ + unsigned char Buffer[16]; + + short + I, J, + NumPlanes, + HaveColorMap, + Status; + + for (I = 0; I < 9; I++) + { + if ((Status = readbuf()) < 0) return FALSE; + Buffer[I] = (unsigned char) Status; + } + + LeftEdge = Buffer[0] | Buffer[1] << 8; + TopEdge = Buffer[2] | Buffer[3] << 8; + Width = Buffer[4] | Buffer[5] << 8; + Height = Buffer[6] | Buffer[7] << 8; + NumPlanes = (Buffer[8] & 0x07) + 1; + LocalNumColors = 1 << NumPlanes; + Interlaced = (Buffer[8] & 0x40) != 0; + HaveColorMap = (Buffer[8] & 0x80) != 0; + + if (HaveColorMap) + { + for (I = 0; I < LocalNumColors; I++) + { + for (J = 0; J < 3; J++) + { + if ((Status = readbuf()) < 0) return FALSE; + Buffer[J] = (unsigned char) Status; + } + + if (I < MaxColors) + { + LocalColorMap[I].red = Buffer[0]; + LocalColorMap[I].green = Buffer[1]; + LocalColorMap[I].blue = Buffer[2]; + } + } + } + else + LocalNumColors = 0; + + return TRUE; +} + +static unsigned long ReadGraphicControlExt() +{ + unsigned char Buffer[6]; + short I; + short Status; + short HaveTransparentColor; + unsigned long timewait; + +#if DEBUG + printf("Graphic Control Extension : "); +#endif + for (I = 0; I < 6; I++) + { + if ((Status = readbuf()) < 0) return 0xffffffffL; + Buffer[I] = (unsigned char) Status; + } + timewait = (Buffer[2] | Buffer[3] << 8)*10; + HaveTransparentColor = (Buffer[1] & 0x01) != 0; + if (HaveTransparentColor) + TransparentColor = Buffer[4]; +#if DEBUG + printf("%ld\n", timewait); +#endif + return timewait; +} + +#if DEBUG +static short ReadCommentExt() +{ + short Count; + short c; + + printf("Comment Extension : "); + while ((Count = readbuf()) > 0) + { + printf("\n#"); + do + { + if ((c = readbuf()) < 0) + return FALSE; + printf("%c", c); + }while (--Count > 0); + printf("#"); + } + if (Count < 0) + return FALSE; + printf("\n"); + return TRUE; +} + +static short ReadPlainTextExt() +{ + unsigned char Buffer[13]; + short I; + short Status; + short Count; + short c; + + printf("Plain Text Extension : "); + for (I = 0; I < 13; I++) + { + if ((Status = readbuf()) < 0) return FALSE; + Buffer[I] = (unsigned char) Status; + } + while ((Count = readbuf()) > 0) + { + printf("\n#"); + do + { + if ((c = readbuf()) < 0) + return FALSE; + printf("%c", c); + }while (--Count > 0); + printf("#"); + } + if (Count < 0) + return FALSE; + printf("\n"); + return TRUE; +} + +static short ReadApplicationExt() +{ + unsigned char Buffer[13]; + short I; + short Status; + short Count; + short c; + + printf("Application Extension : "); + for (I = 0; I < 12; I++) + { + if ((Status = readbuf()) < 0) return FALSE; + Buffer[I] = (unsigned char) Status; + } + for (I = 1; I < 9; I++) + printf("%c", Buffer[I]); + printf(" "); + for (I = 9; I < 12; I++) + printf("%c", Buffer[I]); + while ((Count = readbuf()) > 0) + { + printf("\n%2.2X", Count); + do + { + if ((c = readbuf()) < 0) + return FALSE; + printf("%2.2X", c); + }while (--Count > 0); + } + if (Count < 0) + return FALSE; + printf("\n"); + return TRUE; +} +#endif + +// +//---------------------------------------------------------------------------- +// Procedure: SkipObject +// +// Description: Skip over an extended GIF object. +// +// Input: None +// +// Output: TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +static short SkipObject() +{ + short Count; + + while ((Count = readbuf()) > 0) + do + { + if (readbuf() < 0) + return FALSE; + }while (--Count > 0); + if (Count < 0) + return FALSE; + return TRUE; +} + +void SetPalette( struct ColorEntry ColorMap[], unsigned int num_colors ) +{ +#if TIANO + pColorMap = ColorMap; + num_colors; + return; +#else + int i; + int bitofcolor; + int retvesa; + unsigned int segval, offval; + unsigned char far * fp; + + _asm + { + mov ax,4f08h + mov bx,0001h + int 10h + mov retvesa,ax + mov bitofcolor,bx + } + if(retvesa != 0x004f) + bitofcolor = 8; + else + bitofcolor >>= 8; + if( 8 != bitofcolor ) + { + if( 8 > bitofcolor ) + for (i = 0; i < num_colors; i++) + { + ColorMap[i].red >>= (8 - bitofcolor); + ColorMap[i].green >>= (8 - bitofcolor); + ColorMap[i].blue >>= (8 - bitofcolor); + } + else + for (i = 0; i < num_colors; i++) + { + ColorMap[i].red <<= (bitofcolor - 8); + ColorMap[i].green <<= (bitofcolor - 8); + ColorMap[i].blue <<= (bitofcolor - 8); + } + } + fp = (unsigned char far *)ColorMap; + segval = _FP_SEG( fp ); + offval = _FP_OFF( fp ); + _asm + { + push di + mov ax,4f09h + mov bl,0 + mov cx,num_colors + mov dx,0 + mov di,segval + mov es,di + mov di,offval + int 10h + mov retvesa,ax + pop di + } + +#endif +} + +// Expander +#if TIANO +static int _inline init_table(short min_code_size) +#else +static int _inline init_table(min_code_size) + short min_code_size; +#endif + { + code_size = min_code_size + 1; + clear_code = 1 << min_code_size; + eof_code = clear_code + 1; + first_free = clear_code + 2; + free_code = first_free; + max_code = 1 << code_size; + return 0; //WARN FIX + } + +static int _inline read_code() + { + short bytes_to_move, i, ch; + long temp; + + byte_offset = bit_offset >> 3; + bits_left = bit_offset & 7; + + if (byte_offset >= 61) + { + bytes_to_move = 64 - byte_offset; + + for (i = 0; i < bytes_to_move; i++) + code_buffer[i] = code_buffer[byte_offset + i]; + + while (i < 64) + { + if (bytes_unread == 0) + { + /* Get the length of the next record. A zero-length record + * denotes "end of data". + */ + if( endofdata ) + break; + + if( unreadbuf > 0 ) + { + bytes_unread = *pcurbuf++; + unreadbuf--; + } + else + { + UnexpectedError = TRUE; + return -1; + } + + if (bytes_unread == 0) /* end of data */ + { + endofdata = TRUE; + break; + } + } + + if( unreadbuf > 0 ) + { + ch = *pcurbuf++; + unreadbuf--; + } + else + { + UnexpectedError = TRUE; + return -1; + } + +#if TIANO + code_buffer[i++] = (char)ch; +#else + code_buffer[i++] = ch; +#endif + bytes_unread--; + } + + bit_offset = bits_left; + byte_offset = 0; + } + + bit_offset += code_size; + temp = (long) code_buffer[byte_offset] + | (long) code_buffer[byte_offset + 1] << 8 + | (long) code_buffer[byte_offset + 2] << 16; + + if (bits_left > 0) + temp >>= bits_left; + + return temp & mask[code_size - 1]; + } + +// +//---------------------------------------------------------------------------- +// Procedure: Expand_Data +// +// Description: Decompress a LZW compressed data stream. +// +// Input: None +// +// Output: 0 OK +// -1 expected end-of-file +// -2 cannot allocate memory +// -3 bad "min_code_size" +// < -3 error status from the get_byte or put_byte routine +// +//---------------------------------------------------------------------------- +// +static short Expand_Data( ) +{ +#if TIANO == 0 + short i; +#endif + short sp; /* stack ptr */ +#if TIANO == 0 + short status; +#endif + short min_code_size; + + /* Get the minimum code size (2 to 9) */ + + if( unreadbuf > 0 ) + { + min_code_size = *pcurbuf++; + unreadbuf--; + } + else + return -4; + + if (min_code_size < 2 || min_code_size > 9) + return -3; + + init_table(min_code_size); + sp = 0; + bit_offset = 64*8; /* force "read_code" to start a new */ + bytes_unread = 0; /* record */ + endofdata = FALSE; + + while ((code = read_code()) != eof_code) + { + if( UnexpectedError ) + return -4; + if (code == clear_code) + { + init_table(min_code_size); + code = read_code(); + if( UnexpectedError ) + return -4; + old_code = code; + suffix_char = code; + final_char = code; + //(*put_byte)(suffix_char); + writepixel((unsigned char)suffix_char); + } + else + { + input_code = code; + + if (code >= free_code) + { + code = old_code; +#if TIANO + code_table[sp++].stack = (char)final_char; +#else + code_table[sp++].stack = final_char; +#endif + } + + while (code >= first_free) + { + code_table[sp++].stack = code_table[code].suffix; + code = code_table[code].prefix; + } + + final_char = code; + suffix_char = code; +#if TIANO + code_table[sp++].stack = (char)final_char; +#else + code_table[sp++].stack = final_char; +#endif + + while (sp > 0) + //(*put_byte)(code_table[--sp].stack); + writepixel((unsigned char)code_table[--sp].stack); + +#if TIANO + code_table[free_code].suffix = (char)suffix_char; +#else + code_table[free_code].suffix = suffix_char; +#endif + code_table[free_code].prefix = old_code; + free_code++; + old_code = input_code; + + if (free_code >= max_code) + if (code_size < 12) + { + code_size++; + max_code <<= 1; + } + } + } + + return 0; + } + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/dogifmgr.c b/EDK/MiniSetup/TseAdvanced/dogifmgr.c new file mode 100644 index 0000000..03eb6e0 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/dogifmgr.c @@ -0,0 +1,486 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/dogifmgr.c $ +// +// $Author: Arunsb $ +// +// $Revision: 10 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/dogifmgr.c $ +// +// 10 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 14 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 9 3/29/11 6:59p Madhans +// To fix the function header +// +// 8 3/28/11 9:38p Arunsb +// [TAG] EIP55548 +// [Category] Improvement +// [Description] Support to display Multiple GIF and display other image +// format when Active animated Gif is displaying. +// [Files] dogif.c and dogifmgr.c +// +// 7 3/21/11 1:19a Rajashakerg +// [TAG] EIP53740 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Animation does not continue after the last frame of the +// logo. +// [RootCause] Animation is continued upto the last frame of the +// animated image +// [Solution] Fixed the issue by handling Gif image data to redraw image +// if all the frames are completed and if boottimeout is present. +// [Files] minisetup.h, dogif.c, dogifmgr.c +// +// 6 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 12 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 11 1/09/10 4:46a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 10 12/04/09 7:13a Mallikarjunanv +// Fix for EIP:30263 - Gif Logo Issue +// +// 9 10/28/09 5:37p Madhans +// To do the clean up. +// +// 8 9/02/09 7:39p Madhans +// To Realy fix the Logo Security issue +// +// 7 8/13/09 12:15p Blaines +// Move Image support to binary module +// +// 6 7/09/09 10:56a Madhans +// To fix the compilation error +// +// 4 6/24/09 6:10p Madhans +// Made TSE_USE_EDK_LIBRARY=OFF to not to refer EDK module. +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 3 6/30/06 4:21p Madhans +// To Integrate the PCX and Jpeg Support. SDL tokens created to support +// different image formats. +// +// 2 6/16/06 3:40p Madhans +// 64 Bit Support. Set SDL token TSE_FOR_64BIT for 64 bit support. +// +// 1 1/24/06 3:01a Stefanor +// quiet boot support +// implementation of buffering for POST messages +// gif support +// support for OEM badging protocol +// fixed fallback from 100x31 to 80x25 +// cleanup of set graphic/text mode +// ver 1.17.1051 +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: dogifmgr.c +// +// Description: This file contains code for gif image handling +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" + +//#if SETUP_GIF_LOGO_SUPPORT +//static EFI_EVENT NextFrameEvent; +//static EFI_UGA_PIXEL *UgaBltForGif = NULL; +//static UINT8 *ImageDataForGif = NULL; +//static CO_ORD_ATTRIBUTE GifAttribute; +//static UINTN GifWidth, GifHeight, GifX, GifY, GifBufferWidth; +static UINTN gGifDelay, animateDelay; +//#endif + +extern unsigned long dofirst( unsigned char *, unsigned long ); +extern unsigned long donext( unsigned char * ); + +UINT64 RShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ); + +//EIP: 55548: To display multiple gif +typedef struct //Structure to preserve the various gif images data +{ + UINTN GifWidth; + UINTN GifHeight; + UINTN GifX; + UINTN GifY; + UINTN GifBufferWidth; + EFI_EVENT GifEvent; + EFI_UGA_PIXEL *UgaBltForGif; + CO_ORD_ATTRIBUTE GifAttribute; + unsigned char *GifCurBufLocation; + unsigned char *ImageBuffer; + UINTN ImageSize; + unsigned long FistFrameAddress; +} GIF_ANIMATE_DATA; + +struct GIF_IMAGE_DATAS //Structure used to cleanup the logo buffers +{ + GIF_ANIMATE_DATA *GifAnimateData; + struct GIF_IMAGE_DATAS *Next; +}; + +struct GIF_IMAGE_DATAS *GifEntries; +GIF_ANIMATE_DATA *GifAnimateData; +extern unsigned char *pcurbuf; +extern unsigned long firstframeadd; //EIP: 53740 preserving first frame address for drawing the gif image until the time out occurs +void SaveCleanUpGifDatas (GIF_ANIMATE_DATA **GifDatas); + +// +//---------------------------------------------------------------------------- +// Procedure: GetGifNextFrame +// +// Description: +// +// Input: VOID **UgaBlt , UINTN *GifDelay +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// + +EFI_STATUS +GetGifNextFrame(IN OUT VOID **GifImageData, OUT UINTN *GifDelay) +{ + GIF_ANIMATE_DATA **GifData; + EFI_TPL OldTpl; + + GifData = (GIF_ANIMATE_DATA **)GifImageData; + + OldTpl = gBS->RaiseTPL(EFI_TPL_NOTIFY); + dofirst ((*GifData)->ImageBuffer, (unsigned long)(*GifData)->ImageSize); + while (pcurbuf != (*GifData)->GifCurBufLocation) + { + *GifDelay = donext ((unsigned char *)((*GifData)->UgaBltForGif)); + } + *GifDelay = donext ((unsigned char *)((*GifData)->UgaBltForGif)); + (*GifData)->GifCurBufLocation = pcurbuf; + gBS->RestoreTPL (OldTpl); + return EFI_SUCCESS; +} + +// +//---------------------------------------------------------------------------- +// Procedure: NextFrame +// +// Description: function to get the next frame. +// +// Input: EFI_EVENT Event, VOID *Context +// +// Output: void +// +//---------------------------------------------------------------------------- +// + +VOID NextFrame(IN EFI_EVENT Event, VOID *Context) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + GIF_ANIMATE_DATA *GifContextData = (GIF_ANIMATE_DATA *)Context; + + if (NULL == GifContextData) + { //Add clean up function + return; + } + if (gPostStatus > TSE_POST_STATUS_IN_BOOT_TIME_OUT)// if boot timeout is occured then we have to clean the logo and return + { + CleanUpLogo (); + return; + } + GetGifNextFrame (&GifContextData, &gGifDelay); + if (gGifDelay >= 0) + { + DrawBltBuffer (GifContextData->UgaBltForGif, GifContextData->GifAttribute, GifContextData->GifWidth, GifContextData->GifHeight, GifContextData->GifX, GifContextData->GifY, GifContextData->GifBufferWidth); + //DrawBltBuffer(UgaBltForGif, GifAttribute, GifWidth, GifHeight, GifX, GifY, GifBufferWidth); + Status = gBS->SetTimer (GifContextData->GifEvent, TimerRelative, gGifDelay*10000); + if (EFI_ERROR (Status)) + TimerStopTimer (GifAnimateData->GifEvent); + } + else + { + CleanUpLogo (); + } + + if ((0 == gGifDelay) && (gPostStatus <= TSE_POST_STATUS_IN_BOOT_TIME_OUT))// checking gGifDelay and boot timeout to assing the first frame address to the current buffer pointer + { + GifContextData->GifCurBufLocation = (unsigned char *)GifContextData->FistFrameAddress; + } + return; +} + +// +//---------------------------------------------------------------------------- +// Procedure: DoGifAnimate +// +// Description: function to Handle gif logo animation +// +// Input: CO_ORD_ATTRIBUTE Attribute, +// INTN CoordinateX,INTN CoordinateY +// +// Output: None +// +//---------------------------------------------------------------------------- +// + +VOID DoGifAnimate(CO_ORD_ATTRIBUTE Attribute,INTN CoordinateX,INTN CoordinateY) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + + if (animateDelay) + { + GifAnimateData->GifX = CoordinateX; + GifAnimateData->GifY = CoordinateY; + GifAnimateData->GifAttribute = Attribute; + + Status = gBS -> CreateEvent ( + EFI_EVENT_TIMER|EFI_EVENT_NOTIFY_SIGNAL, + EFI_TPL_NOTIFY, + &NextFrame, + GifAnimateData, //NULL + &GifAnimateData->GifEvent); //NextFrameEvent + if (gEnterSetup == TRUE && !(EFI_ERROR (Status))) + { + CleanUpLogo(); + return; + } + Status = gBS->SetTimer (GifAnimateData->GifEvent, TimerRelative, animateDelay*10000); + if (EFI_ERROR (Status)) { + TimerStopTimer (GifAnimateData->GifEvent); + } + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: ConvertGifToUgaBlt +// +// Description: Convert a *.GIF graphics image to a UGA blt buffer. If a +// NULL UgaBlt buffer is passed in a UgaBlt buffer will be +// allocated by this routine. If a UgaBlt buffer is passed in +// it will be used if it is big enough. +// +// Input: GifImage - Pointer to GIF file +// GifImageSize - Number of bytes in BmpImage +// UgaBlt - Buffer containing UGA version of GifImage. +// UgaBltSize - Size of UgaBlt in bytes. +// PixelHeight - Height of UgaBlt/BmpImage in pixels +// PixelWidth - Width of UgaBlt/BmpImage in pixels +// GifDelay - +// +// Output: EFI_SUCCESS - UgaBlt and UgaBltSize are returned. +// EFI_UNSUPPORTED - GifImage is not a valid *.GIF image +// EFI_BUFFER_TOO_SMALL - The passed in UgaBlt buffer is not big enough. +// UgaBltSize will contain the required size. +// EFI_OUT_OF_RESOURCES - No enough buffer to allocate +// +//---------------------------------------------------------------------------- +// + +EFI_STATUS +ConvertGifToUgaBlt ( + IN VOID *GifImage, + IN UINTN GifImageSize, + IN OUT VOID **UgaBlt, + IN OUT UINTN *UgaBltSize, + OUT UINTN *PixelHeight, + OUT UINTN *PixelWidth, + OUT UINTN *GifDelay + ) +{ + UINT64 BltBufferSize; + UINTN Height; + UINTN Width; + EFI_TPL OldTpl; + unsigned char *TempCurBuf = NULL; + unsigned long tempfirstframeadd; + +// unsigned long tempstartunreadbuf; + + OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY); // prepare BLT buffer for the GIF image + BltBufferSize = dofirst (GifImage, (unsigned long)GifImageSize); + gBS->RestoreTPL (OldTpl); + + Width = (UINTN)RShiftU64(BltBufferSize,16); + Height = (UINTN)(BltBufferSize & 0xffff); + + // Make sure to do x64 Mul + BltBufferSize = MultU64x32((UINT64)Width , Height); + + /// Check whether the Size exceeds the limit... + // 4GB/PIXEL_SIZE becoz we need Resolution*PIXEL_SIZE for bltbuffer + if ( BltBufferSize >= (FOUR_GB_LIMIT/sizeof (EFI_UGA_PIXEL))) { + // The buffer size extends the limitation + return EFI_UNSUPPORTED; + } + BltBufferSize = MultU64x32( BltBufferSize ,sizeof (EFI_UGA_PIXEL)); + + if (*UgaBlt == NULL) + { + *UgaBltSize = (UINTN)BltBufferSize; + *UgaBlt = EfiLibAllocatePool (*UgaBltSize); + if (*UgaBlt == NULL) return EFI_OUT_OF_RESOURCES; + } + else + { + if (*UgaBltSize < (UINTN)BltBufferSize) + { + *UgaBltSize = (UINTN)BltBufferSize; + return EFI_BUFFER_TOO_SMALL; + } + } + + //corrected the assignment. + *PixelWidth = Width; + *PixelHeight = Height; + OldTpl = gBS->RaiseTPL(EFI_TPL_NOTIFY); + BltBufferSize = dofirst (GifImage, (unsigned long)GifImageSize); + tempfirstframeadd = firstframeadd; //Using temp variable because call to allocatepool + gGifDelay = *GifDelay = donext ((unsigned char *)(*UgaBlt)); //may lead to trigger the previous gif events so pcurbuf value might change + TempCurBuf = pcurbuf; + gBS->RestoreTPL (OldTpl); + if (*GifDelay) + { + GifAnimateData = (GIF_ANIMATE_DATA *)EfiLibAllocateZeroPool (sizeof (GIF_ANIMATE_DATA)); + if (NULL == GifAnimateData) + { + return EFI_OUT_OF_RESOURCES; + } + GifAnimateData->ImageBuffer = GifImage; + GifAnimateData->ImageSize = GifImageSize; + GifAnimateData->FistFrameAddress = tempfirstframeadd; + GifAnimateData->GifWidth = Width; + GifAnimateData->GifHeight = Height; + GifAnimateData->GifBufferWidth = Width; + GifAnimateData->UgaBltForGif = *UgaBlt; + GifAnimateData->GifCurBufLocation = TempCurBuf; + GetGifNextFrame ((void **)&GifAnimateData, &gGifDelay); + animateDelay = gGifDelay; + SaveCleanUpGifDatas (&GifAnimateData); + } + return EFI_SUCCESS; +} + +// +//---------------------------------------------------------------------------- +// Procedure: CleanUpGif +// +// Description: Cleans the gif datas +// +// Input: void +// +// Output: void +// +//---------------------------------------------------------------------------- +// + +VOID CleanUpGif (VOID) +{ + while (NULL != GifEntries) + { + gBS->CloseEvent (GifEntries->GifAnimateData->GifEvent); + MemFreePointer( (VOID **)&GifEntries->GifAnimateData->UgaBltForGif); + MemFreePointer( (VOID **)&GifEntries->GifAnimateData->ImageBuffer); + GifEntries = GifEntries->Next; + } +} +// +//---------------------------------------------------------------------------- +// Procedure: SaveCleanUpGifDatas +// +// Description: Saves the structures used for preserving the gif images +// +// +// Input: GifDatas - Pointer to a pointer for GIF image structure +// +// Output: void +// +//---------------------------------------------------------------------------- +// + +void SaveCleanUpGifDatas (GIF_ANIMATE_DATA **GifDatas) +{ + struct GIF_IMAGE_DATAS *HoldGifData = NULL, *tempGifEntries = NULL; + + HoldGifData = (struct GIF_IMAGE_DATAS *)EfiLibAllocateZeroPool (sizeof (struct GIF_IMAGE_DATAS)); + if (NULL == HoldGifData) + { + return; + } + HoldGifData->GifAnimateData = *GifDatas; + HoldGifData->Next = NULL; + tempGifEntries = GifEntries; + if (NULL == tempGifEntries) + { + GifEntries = HoldGifData; + } + else + { + while (NULL != tempGifEntries->Next) + { + tempGifEntries = tempGifEntries->Next; + } + tempGifEntries->Next = HoldGifData; + } +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/iJpeg.c b/EDK/MiniSetup/TseAdvanced/iJpeg.c new file mode 100644 index 0000000..42f2546 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/iJpeg.c @@ -0,0 +1,253 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/iJpeg.c $ +// +// $Author: Arunsb $ +// +// $Revision: 8 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/iJpeg.c $ +// +// 8 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 11 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 7 5/10/11 10:43a Madhans +// [TAG] EIP59139 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Jpeg image with the resolution 1366x768 is not displayed in +// Screen resolution 1366x768. +// [RootCause] Jepg Algorithem does the decoding in 16 pixel boudary. As +// 1366 is not in 16 bit boundary the image width is returned as 1376 to +// make 16bit boundary. +// [Solution] Once decoded the Blt buffer is formed with orginal +// resolution from the image. +// [Files] ijpeg.c +// +// 6 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 9 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 8 1/09/10 4:43a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 7 9/02/09 7:39p Madhans +// To fix the Logo Security issue correctly. +// +// 6 8/13/09 12:15p Blaines +// Move Image support to binary module +// +// 5 7/08/09 3:34p Madhans +// Coding Standards. +// +// 4 6/24/09 6:10p Madhans +// Made TSE_USE_EDK_LIBRARY=OFF to not to refer EDK module. +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 9/26/06 4:03p Madhans +// JpegC Implimentation +// +// 2 9/15/06 9:57a Shirinmd +// Initialized UgaBlt buffer to 0 +// +// 1 8/01/06 8:03a Shirinmd +// Files for JPEG decoding (C version) +// +//*****************************************************************// +//*****************************************************************// +// +// +// Name: iJpeg.c +// +// Description: Adds jpeg Support. +// +// +//*****************************************************************// +#include "jpeg.h" + +BOOL GetJPEGDimensions(BYTE * pbyJPEGInputData, UINT32 * pun32Width, UINT32 * pun32Height); +BOOL DecodeJPEG(WORD wXPos, WORD wYPos, BYTE * pbyJPEGInputData, BYTE * pbyJPEGOutputData, UINT32 un32BufferWidth, UINT32 un32BufferHeight); + + +// +//---------------------------------------------------------------------------- +// Procedure: ConvertJPEGToUgaBlt +// +// Description: Decode the JPEG and store the output in UGA format. The +// JPEG images are stored in 16X16 blocks. Hence Buffer will +// require width and hieght that are equal to or more than +// the actual width and hieght. Buffer Width and Height will +// be the lowest multipe of 16 that is equal to or greater than +// the actual width and height. +// Eg: For decoding an image with Actual sizes being 17X33 will +// require a buffer of 32X48. +// +// Input: IN VOID *JPEGImage - Pointer to the memory that has the +// JPEG Image that need to be decoded. +// IN UINT32 JPEGImageSize - Size of the JPEG Image +// IN OUT VOID **UgaBlt - Two cases +// Case 1: Memory is expected to be allocated by the callee. +// Address provided as input should be NULL. +// pointer that will recieve the address of the UGA buffer. +// The buffer is allocated by callee. +// This buffer need to be freed by the caller. +// Case 2: Memory is allocated by the caller +// IN OUT UINT32 *UgaBltSize - Pointer that stores Size of UgaBlt +// in bytes. This will be treated as an input. This should have +// value ZERO for Case 2 above. +// OUT UINT32 *PixelHeight - Height of UgaBlt/JPEG Image in pixels +// OUT UINT32 *PixelWidth - Width of UgaBlt/JPEG Image in pixels +// OUT UINT32 *pun32BufferWidth - Width of UgaBlt/JPEG Buffer +// +// Output: EFI_SUCCESS - The image was successfully decoded and placed in the buffer +// EFI_UNSUPPORTED +// EFI_BUFFER_TOO_SMALL +// EFI_OUT_OF_RESOURCES +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ConvertJPEGToUgaBlt ( IN VOID *JPEGImage, IN UINT32 JPEGImageSize, IN OUT VOID **UgaBlt, IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth, OUT UINT32 *pun32BufferWidth) +{ + BOOL bStatus=FALSE; + EFI_STATUS Status = EFI_UNSUPPORTED; + UINT64 BltBufferSize =0; + UINT32 un32PadWidth= 0, un32PadHeight=0; + + bStatus = GetJPEGDimensions(JPEGImage, PixelWidth, PixelHeight); + + if(bStatus){ +//We need to add a little memory to deal cases when the Width or height is not a +//multiple of 16 or else we need to add a fix with in output_8x8_image function + un32PadWidth = 16 - (*PixelWidth)%16; + if(un32PadWidth==16){ + un32PadWidth = 0; + } + un32PadHeight = 16 - (*PixelHeight)%16; + if(un32PadHeight==16){ + un32PadHeight = 0; + } + *pun32BufferWidth = *PixelWidth + un32PadWidth; + + // Make sure to do x64 Mul + BltBufferSize = MultU64x32((UINT64)(*pun32BufferWidth) ,(*PixelHeight + un32PadHeight)); + + /// Check whether the Size exceeds the limit... + // 4GB/PIXEL_SIZE becoz we need Resolution*PIXEL_SIZE for bltbuffer + if ( BltBufferSize >= (FOUR_GB_LIMIT/sizeof (EFI_UGA_PIXEL))) { + // The buffer size extends the limitation + return EFI_UNSUPPORTED; + } + + BltBufferSize = MultU64x32( BltBufferSize ,sizeof (EFI_UGA_PIXEL)); + + if(NULL!=*UgaBlt) + { + if (*UgaBltSize < (UINT32)BltBufferSize) + { + *UgaBltSize = (UINT32)BltBufferSize; + bStatus = FALSE; + Status = EFI_BUFFER_TOO_SMALL; + } + } + else + { + *UgaBltSize = (UINT32)BltBufferSize; + *UgaBlt = EfiLibAllocatePool((UINT32)BltBufferSize); + if(*UgaBlt == NULL) + { + Status = EFI_OUT_OF_RESOURCES; + bStatus = FALSE; + } + + } + if(TRUE==bStatus) + { + memset(*UgaBlt, (UINT32)BltBufferSize, 0 ); + bStatus = DecodeJPEG(0,0, JPEGImage, *UgaBlt, *pun32BufferWidth , (*PixelHeight + un32PadHeight)); + if(bStatus){ + Status = EFI_SUCCESS; + if(un32PadWidth) + { + // Padding Done. Need to discard the Extra Width and Height. + EFI_UGA_PIXEL *BltBuf = NULL; + UINT32 i; + + // Recalculate the actual Buffer + BltBufferSize = MultU64x32((UINT64)(*PixelWidth) ,*PixelHeight); + BltBufferSize = MultU64x32( BltBufferSize ,sizeof (EFI_UGA_PIXEL)); + BltBuf = EfiLibAllocatePool((UINT32)BltBufferSize); + + if(BltBuf == NULL) + { // Out of resources. + MemFreePointer( (VOID **)UgaBlt); + Status = EFI_OUT_OF_RESOURCES; + bStatus = FALSE; + } + // Copy the bltbuf for *PixelWidth in each line. + for(i=0;i<*PixelHeight;i++) + { + gBS->CopyMem((VOID*)&(BltBuf[(*PixelWidth * i)]),(VOID*)&(((EFI_UGA_PIXEL*)(*UgaBlt))[(*pun32BufferWidth * i)]),sizeof(EFI_UGA_PIXEL) * *PixelWidth); + } + *pun32BufferWidth = *PixelWidth; // Unpadded Width. + MemFreePointer( (VOID **)UgaBlt); // Free the Orgianl Blt. + *UgaBlt = (VOID*)BltBuf; // New blt + *UgaBltSize = (UINT32)BltBufferSize; // New size + } + } + } + } + + return Status; +} +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/ipcx.c b/EDK/MiniSetup/TseAdvanced/ipcx.c new file mode 100644 index 0000000..ddc222c --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/ipcx.c @@ -0,0 +1,188 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/ipcx.c $ +// +// $Author: Arunsb $ +// +// $Revision: 7 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/ipcx.c $ +// +// 7 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 10 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 6 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 8 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 7 1/09/10 4:44a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 6 9/02/09 7:39p Madhans +// To Realy fix the Logo Security issue +// +// 5 8/13/09 12:16p Blaines +// Move Image support to binary module +// +// 4 6/24/09 6:10p Madhans +// Made TSE_USE_EDK_LIBRARY=OFF to not to refer EDK module. +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 2 7/06/06 6:41p Arunkumars +// include minisetup.h +// include tiano.h instead of efi.h +// +// 1 6/30/06 4:22p Madhans +// PCX image support in C. +// +// 2 6/26/06 8:41a Shirinmd +// Modifications based on design change suggested by Madhan +// +// 1 6/16/06 8:15a Shirinmd +// Added PCX Support in C for Minisetup +// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: ipcx.c +// +// Description: This file contains code related to pcx image handling +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" + +#include "MyDefs.h" + + +BOOL DecodePCX(BYTE * pbyPCXInputData, BYTE * pbyPCXOutputData, DWORD dwPCXImageSize); //Function implemented in PCX_ADV.c +BOOL GetPCXDimensions( BYTE * pbyPCXImageData, UINT32 * pun32Width, UINT32 * pun32Height); //Function implemented in PCX_ADV.c + +// +//---------------------------------------------------------------------------- +// Procedure: ConvertPCXToUgaBlt +// +// Description: Decode the PCX Image and store the output in UGA Format +// +// Input: VOID *PCXImage - Pointer to the memory that has the PCX +// Image that need to be decoded. +// UINT32 PCXImageSize - Size of the PCX Image +// OUT VOID **UgaBlt - Two cases +// Case 1: Memory is expected to be allocated by the callee. +// Address provided as input should be NULL. +// pointer that will receive the address of the UGA buffer. +// The buffer is allocated by callee. +// This buffer need to be freed by the caller. +// Case 2: Memory is allocated by the caller +// OUT UINT32 *UgaBltSize - Pointer that stores Size of UgaBlt in bytes. +// This will be treated as an input. This should have value ZERO for Case 2 above. +// UINT32 *PixelHeight - Height of UgaBlt/PCX Image in pixels +// UINT32 *PixelWidth - Width of UgaBlt/PCX Image in pixels +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ConvertPCXToUgaBlt ( IN VOID *PCXImage, IN UINT32 PCXImageSize, IN OUT VOID **UgaBlt, IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth){ + BOOL bStatus = FALSE; + EFI_STATUS Status = EFI_UNSUPPORTED; + UINT64 unBltBufferSize = 0; + bStatus = GetPCXDimensions(PCXImage, PixelWidth, PixelHeight); + if(bStatus) + { + // Make sure to do x64 Mul + unBltBufferSize = MultU64x32((UINT64)(*PixelWidth), (*PixelHeight)); + + /// Check whether the Size exceeds the limit... + // 4GB/PIXEL_SIZE becoz we need Resolution*PIXEL_SIZE for bltbuffer + if ( unBltBufferSize >= (FOUR_GB_LIMIT/sizeof (EFI_UGA_PIXEL))) { + // The buffer size extends the limitation + return EFI_UNSUPPORTED; + } + + unBltBufferSize = MultU64x32( unBltBufferSize ,sizeof (EFI_UGA_PIXEL)); + + if(NULL!=*UgaBlt) + { + if(*UgaBltSize<(UINT32)unBltBufferSize) + { + *UgaBltSize = (UINT32)unBltBufferSize; + Status = EFI_BUFFER_TOO_SMALL; + bStatus = FALSE; + } + } + else + { + *UgaBltSize = (UINT32)unBltBufferSize; + *UgaBlt = EfiLibAllocatePool((UINT32)unBltBufferSize); + if(NULL == *UgaBlt) + { + Status = EFI_OUT_OF_RESOURCES; + bStatus = FALSE; + } + } + if(bStatus) + { + MemSet(*UgaBlt,*UgaBltSize,0); + bStatus = DecodePCX(PCXImage, *UgaBlt, PCXImageSize); + if(bStatus) + Status = EFI_SUCCESS; + } + } + return Status; +} +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/jpeg.h b/EDK/MiniSetup/TseAdvanced/jpeg.h new file mode 100644 index 0000000..39d66eb --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/jpeg.h @@ -0,0 +1,106 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/jpeg.h $ +// +// $Author: Arunsb $ +// +// $Revision: 5 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/jpeg.h $ +// +// 5 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 7 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 5 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 4 1/09/10 4:44a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 3 6/16/09 2:16p Presannar +// Added File Headers for Header Files +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 9/26/06 4:03p Madhans +// JpegC Implimentation +// +// 1 8/01/06 8:03a Shirinmd +// Files for JPEG decoding (C version) +// +//*****************************************************************// +// +//---------------------------------------------------------------------------- +// +// Name: jpeg.h +// +// Description: Header file for jpeg image format related code +// +//---------------------------------------------------------------------------- +// + +#ifndef _JPEG_H_ +#define _JPEG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "MyDefs.h" +#include "jpeg6.h" + +EFI_STATUS ConvertJPEGToUgaBlt ( IN VOID *JPEGImage, IN UINT32 JPEGImageSize, IN OUT VOID **UgaBlt, IN OUT UINT32 *UgaBltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth, OUT UINT32 *pun32BufferWidth); + +#ifdef __cplusplus +} +#endif + +#endif //#ifndef _JPEG_H_ + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/jpeg6.c b/EDK/MiniSetup/TseAdvanced/jpeg6.c new file mode 100644 index 0000000..4ba6534 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/jpeg6.c @@ -0,0 +1,1320 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/jpeg6.c $ +// +// $Author: Premkumara $ +// +// $Revision: 11 $ +// +// $Date: 5/21/13 1:29a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/jpeg6.c $ +// +// 11 5/21/13 1:29a Premkumara +// [TAG] EIP114841 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] When use the broken JPG file as user logo, system hangs up +// CP:0xb4 +// [RootCause] When corrupted Jpeg image has no proper AC co-efficent +// value in Huffman table then dc_value_length is incremented beyond its +// range value. +// [Solution] Checked dc_value_length boundary value. +// [Files] Jpeg6.c +// +// 10 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 14 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 9 4/26/12 3:25a Arunsb +// [TAG] EIP78033 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] YUV122 sampling JPEG image not displayed +// [RootCause] No support for YUV122 sampling +// [Solution] Support added for YUV122 sampling +// [Files] jpeg6.c +// +// 8 5/03/11 1:42p Madhans +// [TAG] EIP59177 +// [Category] Improvement +// [Description] Support for JPEG with RSI markers. Fix to support logo +// size that bigger then Screen resolution. +// [Files] Logo.c +// Jpeg6.c +// commonHelper.c +// +// 7 4/29/11 4:44p Madhans +// [TAG] EIP59177 +// [Category] Improvement +// [Description] Support for JPEG with RSI markers. Fix to support logo +// size that bigger then Screen resolution. +// [Files] Logo.c +// Jpeg6.c +// commonHelper.c +// +// 6 9/27/10 7:47a Mallikarjunanv +// EIP 40555 : To avoid Compilation issues with Fareast Windows. +// +// 5 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 8 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 7 1/09/10 4:43a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 6 8/13/09 12:16p Blaines +// Move Image support to binary module +// +// 5 7/08/09 3:34p Madhans +// Coding Standards. +// +// 4 6/29/09 12:46p Blaines +// EIP #22305 Fix for improper JPEG Image size calculation logic +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 9/26/06 4:03p Madhans +// JpegC Implimentation +// +// 5 9/22/06 3:23a Shirinmd +// Added Support for JPEG Images having 1 Huffman Table and 1 Quantization +// table +// +// 4 9/15/06 9:54a Shirinmd +// Added the check to find the type of Huffman table +// +// 3 8/03/06 7:16a Shirinmd +// Removed initialization of global buffers in InitGlobals function to +// reduce code size +// +// 2 8/02/06 8:55a Shirinmd +// Made changes to reduce the code size +// +// 1 8/01/06 8:03a Shirinmd +// Files for JPEG decoding (C version) +// +//*****************************************************************// +//*****************************************************************// +// +// +// Name: jpeg6.c +// +// Description: Support for JPEG decoding +// +// +//*****************************************************************// + +#include "Mydefs.h" +#include "Jpeg6.h" + + +//Globals_START + +UINTN unBitStreamOFFSET; +BYTE bNumBitsRead; +BYTE btempBitStreamByte; + +UINTN unSOF0; +WORD wDCLumtable[13*3]; +WORD wACLumtable[170*3]; +WORD wDCChrtable[13*3]; +WORD wACChrtable[170*3]; + +WORD space_image[256*4]; +AMI_TRUECOLOR_PIXEL_JPEG * ScreenBufferJPEG = (AMI_TRUECOLOR_PIXEL_JPEG *)NULL; + +WORD image_Y[64]; +WORD image_Y1[64]; +WORD image_Y2[64]; +WORD image_Y3[64]; +WORD image_Cr[64]; +WORD image_Cb[64]; +UINTN QT[2]; +UINTN HT[4]; +BYTE bQTLumTable[64]; +BYTE bQTChrTable[64]; +WORD jpeg_zigzag_order[] = { \ + 0, 1, 5, 6, 14, 15, 27, 28, \ + 2, 4, 7, 13, 16, 26, 29, 42, \ + 3, 8, 12, 17, 25, 30, 41, 43, \ + 9, 11, 18, 24, 31, 40, 44, 53, \ + 10, 19, 23, 32, 39, 45, 52, 54, \ + 20, 22, 33, 38, 46, 51, 55, 60, \ + 21, 34, 37, 47, 50, 56, 59, 61, \ + 35, 36, 48, 49, 57, 58, 62, 63 \ + }; + +WORD jpeg_zigzag_order_temp[64]; + + +WORD diff_Y ; +WORD diff_Cr; +WORD diff_Cb; +WORD gRsi = 0; +UINT32 g_un32BufferWidth ; +UINT32 g_un32BufferHeight; + +//Globals_End + + +//Function Declarations +void BuildHuffmanCodeTable(WORD * pwHuffCodeTable ,BYTE * pbySrcHT); +void HuffmanDecoding(WORD * pwDCCoeffTable, WORD * pwACCoeffTable, WORD * pwImage); +void GetDCValue(WORD * pwHuffmanTable, WORD * pwValue, WORD * pwLengthDC_RunSizeAC); +BOOL SearchHuffmanCode(WORD * pwSearchTablePos, WORD * pwHuffmanCodeValue, WORD wDc_value_length); +BOOL GetEncodedBit(); +void ReadJPEGImage(WORD * pwDCCoeffTable, WORD * pwACCoeffTable, WORD * pwImage, WORD * diff, BYTE * pbySrcQT, int nLumFlag); +void ReadJPEGImage_YUV(DWORD * pdwBuffer, WORD wSampling); +void OutputJPEGImage_YUV(WORD wXPos, WORD wYPos, WORD wXLength, WORD wYLength, WORD wSampling); +void Output8x8Image(WORD wLeft, WORD wTop, BYTE * pspace_image); +BOOL InitJpegParams(BYTE * pbyImage); +DWORD ConvertYCbCrToRGB(short Y, short Cb, short Cr); +void InvertDCT(WORD * pwSource); +void InvertDCT_xy(WORD * pwSource, WORD wVal); +void GetTables(BYTE bNumQT, BYTE bNumHT); + + +// +//---------------------------------------------------------------------------- +// Procedure: InitGlobals +// +// Description: Initializes required global variables +// +// Input: None +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void InitGlobals(){ + diff_Y = 0; + diff_Cr = 0; + diff_Cb = 0; + bNumBitsRead = 8; + btempBitStreamByte = 0; +} + +// +//---------------------------------------------------------------------------- +// Procedure: DecodeJPEG +// +// Description: Decode the JPEG image into the given buffer at given position, +// subject to the limit of the Buffer Width and Height +// +// Input: WORD wXPos - X Start Postion with in the Buffer +// where the image need to be decoded +// WORD wYPos - Y Start Postion with in the Buffer +// where the image need to be decoded +// BYTE * pbyJPEGInputData - Pointer that gives the memory location +// where the Input data is available +// BYTE * pbyJPEGOutputData - Pointer that gives the pointer +// for the output buffer +// UINT32 un32BufferWidth - Width of the output Buffer +// UINT32 un32BufferHeight - Height of the output Buffer +// +// Output: BOOL - TRUE/FALSE Indicate whether the Decoding was successful +// +//---------------------------------------------------------------------------- +// +BOOL DecodeJPEG(WORD wXPos, WORD wYPos, BYTE * pbyJPEGInputData, BYTE * pbyJPEGOutputData, UINT32 un32BufferWidth, UINT32 un32BufferHeight){ + WORD wX_Length=0, wY_Length=0; + ScreenBufferJPEG = (AMI_TRUECOLOR_PIXEL_JPEG *)pbyJPEGOutputData; + g_un32BufferWidth = un32BufferWidth ; + g_un32BufferHeight = un32BufferHeight; + + gRsi = 0; + InitGlobals(); + + if(InitJpegParams(pbyJPEGInputData)){ + wX_Length = (*(WORD*)((BYTE *)unSOF0+5)<<8)|*((BYTE *)unSOF0+6); + wY_Length = (*(WORD*)((BYTE *)unSOF0+3)<<8)|*((BYTE *)unSOF0+4); + +if((0x11==(*(BYTE *)(unSOF0+3+4+1+1+3)))&&(0x11==((*(BYTE *)(unSOF0+3+4+1+1+3+3))))) + { +#if MKF_JPEG_YUV111_SUPPORT + if(0x11==(*(BYTE *)(unSOF0+3+4+1+1))) + OutputJPEGImage_YUV(wXPos, wYPos, wX_Length, wY_Length, 0x111); + else +#endif + if(0x22==(*(BYTE *)(unSOF0+3+4+1+1))) + OutputJPEGImage_YUV(wXPos, wYPos, wX_Length, wY_Length, 0x122); + } + return TRUE; + } + else + return FALSE; + +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetJPEGDimensions +// +// Description: Get the dimensions (Width and Height) for the JPEG image +// +// Input: BYTE * pbyJPEGInputData - Pointer that gives the memory +// location where the Input data is available +// UINT32 * pun32Width - Pointer to the UINT32 variable that +// will recieve the Width of the Image +// UINT32 * pun32Height - Pointer to the UINT32 variable that +// will recieve the Height of the Image +// +// Output: BOOL - TRUE/FALSE. +// +//---------------------------------------------------------------------------- +// +BOOL GetJPEGDimensions(BYTE * pbyJPEGInputData, UINT32 * pun32Width, UINT32 * pun32Height){ + if(InitJpegParams(pbyJPEGInputData)){ + *pun32Width = (WORD)((*(WORD*)((BYTE *)unSOF0+5)<<8)|*((BYTE *)unSOF0+6)); + *pun32Height= (WORD)((*(WORD*)((BYTE *)unSOF0+3)<<8)|*((BYTE *)unSOF0+4)); + return TRUE; + } + else return FALSE; +} + +// +//---------------------------------------------------------------------------- +// Procedure: BuildHuffmanCodeTable +// +// Description: Builds the Huffman codes for the particular JPEG Huffman table. +// By incrementing the offset of the Huffman table by 3, +// the offset of the actual data is obtained. The first +// 16 bytes represent the no: of code words for a paricular +// bit-size. Having the bit-size and the no: of code words +// for each bit-size, the Huffman code table is built. +// +// Input: WORD * pwHuffCodeTable - Pointer to the memory location +// that contains the Huffman codes for the particular JPEG Huffman table. +// BYTE * pbySrcHT - Pointer to the memory location that contains +// the offset of the JPEG Huffman Table. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void BuildHuffmanCodeTable(WORD * pwHuffCodeTable ,BYTE * pbySrcHT){ + + BYTE * pbySrcHTCopy = NULL; + int nCounter=0; + int nOffSet=0; + BYTE wCodeSize = 1; + WORD wCodeWord = 0; + + pbySrcHT += 1; + pbySrcHTCopy = pbySrcHT; + do{ + for(nCounter=*pbySrcHT;nCounter>0; nCounter--){ + pwHuffCodeTable[nOffSet++] = wCodeSize; + pwHuffCodeTable[nOffSet++] = wCodeWord++; + pwHuffCodeTable[nOffSet++] = *(pbySrcHTCopy+16); + pbySrcHTCopy++; + } + wCodeWord<<=1; + pbySrcHT++; + wCodeSize++; + }while(wCodeSize<=16); + pwHuffCodeTable[nOffSet] = 17; +} + +// +//---------------------------------------------------------------------------- +// Procedure: ReadJPEGImage +// +// Description: Reads the 8x8 matrix data for each of Y_0,Y_1,Y_2,Y_3,Cb and Cr. +// The final output will be image data after inverse DCT is applied. +// +// Input: WORD * pwDCCoeffTable - DC Luminance/ Chrominance Huffman Table. +// WORD * pwACCoeffTable - AC Luminance/ Chrominance Huffman Table. +// WORD * pwImage - Pointer to the 8x8 matrix data for each of Y_0,Y_1,Y_2,Y_3,Cb and Cr. +// WORD * pwDiff - Pointer to the variable that hold the differences of the DC coefficients. +// Adds the difference to the Prev Dc coefficient value to get the present DC coefficient value. +// BYTE * pbySrcQT - Pointer to the Quantization table. +// int nLumFlag - Flag if it is set, indicates that the image component is luminance. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void ReadJPEGImage(WORD * pwDCCoeffTable, WORD * pwACCoeffTable, WORD * pwImage, WORD * diff, BYTE * pbySrcQT, int nLumFlag) +{ + int nCounter; + HuffmanDecoding(pwDCCoeffTable, pwACCoeffTable, pwImage); + *diff = *diff + pwImage[0]; + pwImage[0] = *diff; + + //DeQuantization + for(nCounter=0; nCounter<64; nCounter++) + { + pwImage[nCounter] = pwImage[nCounter] * (WORD)pbySrcQT[nCounter]; + } + + //InvertZigZagOrder + for(nCounter=0; nCounter<64; nCounter++) + { + jpeg_zigzag_order_temp[nCounter] = *((WORD *)((BYTE *)pwImage+(jpeg_zigzag_order[nCounter]<<1))); + } + memcpy(pwImage,jpeg_zigzag_order_temp, 128); + InvertDCT(pwImage); + + if(nLumFlag) + { + //Add128 + for(nCounter=0; nCounter<64; nCounter++) + pwImage[nCounter] +=128; + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: ReadJPEGImage_YUV +// +// Description: Reads the 8x8 matrix data for each of Y_0,Y_1,Y_2,Y_3,Cb and Cr. +// The final output will be RGB pixel data. +// +// Input: DWORD * pdwBuffer - RGB format of image data. +// WORD wSampling - Value tells whether image is YUV111(luminance +// as well as chrominance is taken for every pixel) or +// YUV122(luminance is taken for every pixel while chrominance +// is taken as medium value for 2x2 block of pixels). +// Since the sampling factor for Luminance is 2, all the pixel +// values are stored, where as for Cb and Cr, only the average +// of 2x2 pixels is stored. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void ReadJPEGImage_YUV(DWORD * pdwBuffer, WORD wSampling){ + int nCounter = 0; + int nCbCrCounter = 0; + ReadJPEGImage(wDCLumtable, wACLumtable, image_Y, &diff_Y, bQTLumTable, 1); + + if(0x122 ==wSampling) + { + ReadJPEGImage(wDCLumtable, wACLumtable, image_Y1,&diff_Y, bQTLumTable, 1); + ReadJPEGImage(wDCLumtable, wACLumtable, image_Y2,&diff_Y, bQTLumTable, 1); + ReadJPEGImage(wDCLumtable, wACLumtable, image_Y3,&diff_Y, bQTLumTable, 1); + } + + ReadJPEGImage(wDCChrtable, wACChrtable, image_Cr,&diff_Cr, bQTChrTable, 0); + ReadJPEGImage(wDCChrtable, wACChrtable, image_Cb,&diff_Cb, bQTChrTable, 0); + + for(nCounter=0; nCounter< 64; nCounter++){ +#if MKF_JPEG_YUV111_SUPPORT + if(0x111 ==wSampling) + pdwBuffer[nCounter] = ConvertYCbCrToRGB(image_Y[nCounter], image_Cr[nCounter], image_Cb[nCounter]); + else +#endif + if(0x122 ==wSampling) + { + nCbCrCounter = (nCounter&0xfff7)/2; + pdwBuffer[nCounter] = ConvertYCbCrToRGB(image_Y[nCounter], image_Cr[nCbCrCounter], image_Cb[nCbCrCounter]); + pdwBuffer[64+nCounter] = ConvertYCbCrToRGB(image_Y1[nCounter], image_Cr[nCbCrCounter + 4], image_Cb[nCbCrCounter + 4]); + pdwBuffer[128+nCounter] = ConvertYCbCrToRGB(image_Y2[nCounter], image_Cr[nCbCrCounter + 32], image_Cb[nCbCrCounter + 32]); + pdwBuffer[192+nCounter] = ConvertYCbCrToRGB(image_Y3[nCounter], image_Cr[nCbCrCounter + 32 + 4], image_Cb[nCbCrCounter + 32 + 4]); + } + } + +} + +// +//---------------------------------------------------------------------------- +// Procedure: HuffmanDecoding +// +// Description: This routine decodes the AC and DC coefficients using the +// Huffman tables stored in the JPEG image. +// +// Input: WORD * pwDCCoeffTable - DC Luminance/ Chrominance Huffman Table. +// WORD * pwACCoeffTable - AC Luminance/ Chrominance Huffman Table. +// WORD * pwImage -Pointer to the memory location that contains the decoded data. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void HuffmanDecoding(WORD * pwDCCoeffTable, WORD * pwACCoeffTable, WORD * pwImage) +{ + int nBlockCount=0; + + WORD wLengthDC_RunSizeAC = 0; + WORD wCoeffVal = 0; + + memset(pwImage,(64*sizeof(WORD)),0); + + GetDCValue(pwDCCoeffTable, &wCoeffVal, &wLengthDC_RunSizeAC); + pwImage[nBlockCount++] = wCoeffVal; // DC coefficient Value + + for(;nBlockCount<64;nBlockCount++) + { + GetDCValue(pwACCoeffTable, &wCoeffVal, &wLengthDC_RunSizeAC); + if(0==wLengthDC_RunSizeAC){ + break; + } + wLengthDC_RunSizeAC&=0x0F0; + wLengthDC_RunSizeAC>>=4; + + for(;wLengthDC_RunSizeAC>0;wLengthDC_RunSizeAC--){ + pwImage[nBlockCount++] = 0; + } + + pwImage[nBlockCount] = wCoeffVal; // AC coefficient Value + } + + return; +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetDCValue +// +// Description: This routine returns the differences(DCCoefficientpresent - +// DCCoefficientprev) for the DC coefficient. For AC coefficients, +// it returns the actual AC coefficient value and Run/Size. +// +// Input: WORD * pwHuffmanTable - Pointer to the huffman table ?DC Luminance, +// DC Chrominance, AC Luminance, AC Chrominance. +// WORD * pwValue - Code Word (Actual Bit representation). +// WORD * pwLengthDC_RunSizeAC - Indicates the no: of zeroes. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void GetDCValue(WORD * pwHuffmanTable, WORD * pwValue, WORD * pwLengthDC_RunSizeAC) +{ + WORD dc_value_length=0; + WORD wCoeffLen=0; + DWORD dwCoeffVal=0; + int i=0; + + while(1) + { + wCoeffLen<<=1; + if(GetEncodedBit()) + wCoeffLen|=0x1; + + dc_value_length++; + + if( 0xffff == dc_value_length ) //EIP-114841 Corrupted Jpeg + return; + + if(SearchHuffmanCode(pwHuffmanTable, (WORD*)&wCoeffLen,dc_value_length)){ + break; + } + }; + + + *pwLengthDC_RunSizeAC = wCoeffLen; + + wCoeffLen&=0x0f; + + for(i=0;i>= (wCoeffLen&0xff); + dwCoeffVal++; + } + } + + *pwValue = (WORD)dwCoeffVal; + return; +} + +// +//---------------------------------------------------------------------------- +// Procedure: SearchHuffmanCode +// +// Description: Searches the Huffman code of the DC/AC Luminance/Chrominace +// values in Huffman code tables and find the appropriate HuffmanCodeValue. +// +// Input: WORD * pwSearchTablePos - Pointer to the huffman table ?DC Luminance, +// DC Chrominance, AC Luminance, AC Chrominance. +// WORD * pwHuffmanCodeValue - Pointer to the variable that contains +// the Huffman code value. +// WORD wDc_value_length - No: of bits in the Huffman code. +// +// Output: BOOL - TRUE/FALSE. +// +//---------------------------------------------------------------------------- +// +BOOL SearchHuffmanCode(WORD * pwSearchTablePos, WORD * pwHuffmanCodeValue, WORD wDc_value_length) +{ + BOOL bReturn = FALSE; + + while(wDc_value_length>=(*pwSearchTablePos)) + { + if(wDc_value_length==(*pwSearchTablePos)) + { + if(*pwHuffmanCodeValue==*(pwSearchTablePos+1)) + { + *pwHuffmanCodeValue=*(pwSearchTablePos+2); + bReturn = TRUE; + break; + } + } + pwSearchTablePos+=3; + } + return bReturn; +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetEncodedBit +// +// Description: Reads bits from the stream and returns whether the carry +// flag is set or not. +// +// Input: None +// +// Output: BOOL - TRUE/FALSE depending on whether the Carry flag is set or not. +// +//---------------------------------------------------------------------------- +// +BOOL GetEncodedBit() +{ + + UINTN unBitStreamOFFSETCopy; + BYTE bStreamData; + + unBitStreamOFFSETCopy = unBitStreamOFFSET; + if(8==bNumBitsRead){ + bStreamData=*(BYTE *)(unBitStreamOFFSETCopy++); + if(0xff==bStreamData){ + if(0!=(*(BYTE *)(unBitStreamOFFSETCopy++))){ + bStreamData=*(BYTE *)(unBitStreamOFFSETCopy++); + } + } + unBitStreamOFFSET = unBitStreamOFFSETCopy; + btempBitStreamByte = bStreamData; + bNumBitsRead=0; + } + bNumBitsRead++; + bStreamData = btempBitStreamByte; + + if( (bStreamData&(0x1<<(8-bNumBitsRead))) ){ + return TRUE; + } + else{ + return FALSE; + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: OutputJPEGImage_YUV +// +// Description: This functions writes to the Global Screen Buffer by calling +// Output8x8Image function. +// +// Input: WORD wX_position - X Start Position within the output buffer +// from where the image needs to be decoded. +// WORD wY_position - Y Start Position within the output buffer +// from where the image needs to be decoded. +// WORD wX_length - Width of the image. +// WORD wY_length - Height of the image. +// WORD wSampling - Value tells whether image is YUV111(luminance +// as well as chrominance is taken for every pixel) or YUV122 +// (luminance is taken for every pixel while chrominance is +// taken as medium value for 2x2 block of pixels). +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void OutputJPEGImage_YUV(WORD wX_position, WORD wY_position, WORD wX_length, WORD wY_length, WORD wSampling) +{ + WORD Temp_X_Pos= wX_position; + WORD Temp_X_Len= wX_length; + UINTN BlkCount=0; + + if(wSampling==0x122) + { + wY_length+= 0x0f; + wY_length >>=4; + } +#if MKF_JPEG_YUV111_SUPPORT + else if(wSampling==0x111) + { + wY_length+= 0x07; + wY_length >>=3; + } +#endif + for(;wY_length>0;wY_length--) + { + wX_position = Temp_X_Pos; + wX_length = Temp_X_Len; + + if(wSampling==0x122) + { + wX_length+= 0x0f; + wX_length >>=4; + + for(;wX_length>0;wX_length--) + { +// memset(space_image,sizeof(space_image),0); + { + ReadJPEGImage_YUV((DWORD *)space_image,wSampling); + Output8x8Image(wX_position, wY_position, (BYTE *)space_image); + Output8x8Image(wX_position+8, wY_position, (BYTE *)space_image+256); + Output8x8Image(wX_position, wY_position+8, (BYTE *)space_image+(256*2)); + Output8x8Image(wX_position+8, wY_position+8, (BYTE *)space_image+(256*3)); + wX_position+=16; + BlkCount++; + // if Restart Interval valid Support for YUV122 + if(gRsi && ((BlkCount%gRsi) == 0)) + { + UINT8 *jpgScan = (UINT8*)unBitStreamOFFSET; + // It is going to be 0xFFD0 .. 0xFFD7 + if((jpgScan[0] == 0xFF) && ((jpgScan[1]& 0xF8 ) == 0xD0)) + { + // Restart the scan params + InitGlobals(); + // Skip the Rsi maraker + unBitStreamOFFSET+=2; + } + } + } + } + wY_position+=16; + } +#if MKF_JPEG_YUV111_SUPPORT + else if(wSampling==0x111) + { + wX_length+= 0x07; + wX_length >>=3; + for(;wX_length>0;wX_length--) + { + //memset(space_image,sizeof(space_image),wSampling); + ReadJPEGImage_YUV((DWORD *)space_image,wSampling); + Output8x8Image(wX_position, wY_position, (BYTE *)space_image); + wX_position+=8; + BlkCount++; + // if Restart Interval valid + if(gRsi && ((BlkCount%gRsi) == 0)) + { + UINT8 *jpgScan = (UINT8*)unBitStreamOFFSET; + // It is going to be 0xFFD0 .. 0xFFD7 + if((jpgScan[0] == 0xFF) && ((jpgScan[1]& 0xF8 ) == 0xD0)) + { + // Restart the scan params + InitGlobals(); + // Skip the Rsi maraker + unBitStreamOFFSET+=2; + } + } + } + wY_position+=8; + } +#endif + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: Output8x8Image +// +// Description: This functions writes to the Global Screen Buffer. +// +// Input: WORD wLeft - Left coordinate from where the Screen buffer +// is to be filled. +// WORD wTop - Top coordinate from where the Screen buffer is to be filled. +// BYTE * pspace_image - Pointer to 8x8 block of image. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void Output8x8Image(WORD wLeft, WORD wTop, BYTE * pspace_image){ + int nCounterY=0; + int nCounterX=0; + AMI_TRUECOLOR_PIXEL_JPEG * pStartofLineInScreenBuffer = (AMI_TRUECOLOR_PIXEL_JPEG *)ScreenBufferJPEG + wTop * g_un32BufferWidth + wLeft; + + for(;nCounterY<8;nCounterY++){ + if((UINT32)(wTop + nCounterY) >= g_un32BufferHeight){ + break; + } + for(nCounterX=0;nCounterX<8; nCounterX++){ + if( (UINT32)(wLeft + nCounterX) < g_un32BufferWidth){ + (pStartofLineInScreenBuffer + nCounterX)->Red = *pspace_image; + (pStartofLineInScreenBuffer + nCounterX)->Green = *(pspace_image+1); + (pStartofLineInScreenBuffer + nCounterX)->Blue = *(pspace_image+2); + } + pspace_image+=4; + } + pStartofLineInScreenBuffer+=g_un32BufferWidth; + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetTables +// +// Description: Gets the 2 Quantization Tables and 4 Huffman Tables. +// Checks the type of table and then builds the corresponding table. +// +// Input: BYTE bNumQT - Number of Quantization Tables. +// BYTE bNumHT - Number of Huffman Tables. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void GetTables(BYTE bNumQT, BYTE bNumHT) +{ + int i,j; + + for(j=0;j +//---------------------------------------------------------------------------- +// Procedure: InitJpegParams +// +// Description: Reads the image parameters and checks whether the image +// is supported or not. +// TSE Jpeg Algorithm Supports following Markers +// ================================================== +// 0C0h - Start Of Frame (Baseline DCT) (REQUIRED) +// 0C4h - Define Huffman Table (REQUIRED) +// 0D0h - RSI0 Marker (OPTIONAL) +// 0D1h - RSI1 Marker (OPTIONAL) +// 0D2h - RSI2 Marker (OPTIONAL) +// 0D3h - RSI3 Marker (OPTIONAL) +// 0D4h - RSI4 Marker (OPTIONAL) +// 0D5h - RSI5 Marker (OPTIONAL) +// 0D6h - RSI6 Marker (OPTIONAL) +// 0D7h - RSI7 Marker (OPTIONAL) +// 0D8h - Start of Image (REQUIRED) +// 0D9h - End of Image (REQUIRED) +// 0DAh - Start Of Scan (REQUIRED) +// 0DBh - Define Quantization Table (REQUIRED) +// 0DDh - Define Restart Interval (OPTIONAL) +// 0E0h - 0xEF - APPx Markers (Does Depend on and just Skips marker) (DON'T CARE) +// 0F0h - 0xFD - Reserved for JPEG extensions (Does Depend on and just Skips marker) (DON'T CARE) +// 0FEh - Jpeg Comment (Does Depend on and just Skips marker) (DON'T CARE) +// +// TSE Jpeg Algorithom Does not Support following Markers +// ====================================================== +// 000h-0BFh - RESERVED +// 0C1h - Start Of Frame (Extended sequential DCT) +// 0C2h - Start Of Frame (Progressive DCT) +// 0C3h - Start Of Frame (Lossless (sequential)) +// 0C5h - Start Of Frame (Differential sequential DCT) +// 0C6h - Start Of Frame (Differential progressive DCT) +// 0C7h - Start Of Frame (Differential lossless (sequential)) +// 0C8h - Start Of Frame (Reserved for JPEG extensions) +// 0C9h - Start Of Frame (Extended sequential DCT) +// 0CAh - Start Of Frame (Progressive DCT) +// 0CBh - Start Of Frame (Lossless (sequential)) +// 0CDh - Start Of Frame (Differential sequential DCT) +// 0CEh - Start Of Frame (Differential progressive DCT) +// 0CFh - Start Of Frame (Differential lossless (sequential)) +// 0CCh - Arithmetic coding conditioning +// 0DCh - Define number of lines +// 0DEh - Define hierarchical progression +// 0DFh - Expand reference component(s) +// 0FFh - RESERVED +// +// Input: BYTE * pbyImage - Pointer to the JPEG image. +// +// Output: BOOL TRUE/FALSE. +// +//---------------------------------------------------------------------------- +// +BOOL InitJpegParams(BYTE * pbyImage) +{ + + BYTE bJpegImageFlag = 0; + BYTE bCount = 0; + int i = 0; + BYTE bNumHT=0; + BYTE bNumQT=0; + WORD wLen = 0; + + if ( ( *pbyImage != 0xFF ) || ( *(pbyImage+1) != 0xD8 ) ) // if marker is not Start Of Image + return FALSE; + do{ + if(0x0FF== *pbyImage){ + pbyImage++; + //; start of image + if ( 0xD8 == *pbyImage ) + { + pbyImage++; + continue; + } + //; end of image + if(0x0D9== *pbyImage){ + break; + } + if(*pbyImage){ + // APPx Marks No information needed for us + if((0x0F0 & *pbyImage) == 0x0E0){ + } + // ; if maker is Start Of Frame + else if(0x0C0== *pbyImage){ + bJpegImageFlag|=2; + unSOF0 = (UINTN)(pbyImage+1); + } + //; if maker is Define Huffman Table + else if(0x0C4== *pbyImage){ + HT[bNumHT] = (UINTN)(pbyImage+3); + bNumHT++; + } + else if((0x0F0 & *pbyImage) == 0xC0){ + // ; if Frame markers + switch(*pbyImage) + { + //Unsupported Frame Markers + case 0x0C1: //Start Of Frame (Extended sequential DCT) + case 0x0C2: //Start Of Frame (Progressive DCT) + case 0x0C3: //Start Of Frame (Lossless (sequential)) + case 0x0C5: //Start Of Frame (Differential sequential DCT) + case 0x0C6: //Start Of Frame (Differential progressive DCT) + case 0x0C7: //Start Of Frame (Differential lossless (sequential)) + case 0x0C8: //Start Of Frame (Reserved for JPEG extensions) + case 0x0C9: //Start Of Frame (Extended sequential DCT) + case 0x0CA: //Start Of Frame (Progressive DCT) + case 0x0CB: //Start Of Frame (Lossless (sequential)) + case 0x0CD: //Start Of Frame (Differential sequential DCT) + case 0x0CE: //Start Of Frame (Differential progressive DCT) + case 0x0CF: //Start Of Frame (Differential lossless (sequential)) + //Arithmetic coding conditioning + case 0x0CC: + return FALSE; + default: + // Never comes here as C4 and C0 is handled above + break; + } + } + //; if maker is Start Of Scan + else if(0x0DA== *pbyImage){ + //SOS = (UINTN)(pbyImage+1); + unBitStreamOFFSET = (UINTN)(pbyImage+13); + break; + } + //; if maker is Define Quantization Table + else if(0x0DB== *pbyImage){ + QT[bNumQT] = (UINTN)(pbyImage+3); + bNumQT++; + } + //; if marker is Define Restart Interval Start + else if(0x0DD== *pbyImage){ + *((BYTE *)&gRsi) = *(pbyImage+4); + *((BYTE *)&gRsi+1) = *(pbyImage+3); + } + // if Restart RSIx Marker + else if((*pbyImage & 0xF8 ) == 0xD0){ + } + //; if marker is Define number of lines + else if(0x0DC== *pbyImage){ + return FALSE; + } + //; if marker is Define hierarchical progression + else if(0x0DE== *pbyImage){ + return FALSE; + } + + //; if marker is Expand reference component(s) + else if(0x0DF== *pbyImage){ + return FALSE; + } + // Reserved for JPEG extensions and Comment. Skip it + else if((*pbyImage >= 0xF0) && (*pbyImage <= 0xFE)){ + } + // if the Marker is Less then 0xC0 Or 0xFF then they are reserved marker. No Valid + // JPEG file may use it. We don't handle such files + // that is ((*pbyImage < 0xC0) || (*pbyImage == 0xFF)) + else + { + return FALSE; + } + pbyImage++; + *((BYTE *)&wLen) = *(pbyImage+1); + *((BYTE *)&wLen+1) = *pbyImage; + pbyImage += wLen; + } + else + { + return FALSE; + } + } + else + { + return FALSE; + } + }while(1); + + //Support for 1 QT + if(1 == bNumQT) + { + QT[bNumQT++] = (UINTN)(QT[0]+65); + } + + //Support for 1 HT + if(1 == bNumHT) + { + while(bNumHT<4) + { + bCount = 0; + for(i=0;i<16;i++) + { + bCount = bCount + *(BYTE*)(HT[bNumHT-1]+i+1); + } + HT[bNumHT++] = (UINTN)(HT[bNumHT-1]+bCount+17); + } + } +// Check for 4 HT and 2 QT and SOF0 + if((4==bNumHT)&&(2==bNumQT)&&(0x02 & bJpegImageFlag)) + { + GetTables(bNumQT, bNumHT); + return TRUE; + } +else +return FALSE; + +} + +// +//---------------------------------------------------------------------------- +// Procedure: Check +// +// Description: Internal function for doing a check for each color component +// +// Input: INT32 n32ColorComp - Color Component (R, G or B). +// +// Output: The color component value after the check. +// +//---------------------------------------------------------------------------- +// +INT32 Check(INT32 n32ColorComp) +{ + n32ColorComp>>=14; + if(0x8000==(n32ColorComp&0x8000)) + n32ColorComp=0; + + if((n32ColorComp&0xffff)>255) + n32ColorComp=0x00ff;//mov CX,255 + + return n32ColorComp; +} + +// +//---------------------------------------------------------------------------- +// Procedure: ConvertYCbCrToRGB +// +// Description: Converts the luminance(Y) and chrominance(Cb and Cr) values +// of the image to R, G, B values. The R,G, B values are stored +// in a DWORD variable. +// +// Input: short Y - Y is the luminance value. +// short Cb - Cb is the chrominance Hue value. +// short Cr - Cr is the chrominance Saturation value. +// +// Output: Variable having the RGB value, which is a DWORD. +// +//---------------------------------------------------------------------------- +// +DWORD ConvertYCbCrToRGB(short Y, short Cb, short Cr) +{ + DWORD dwRGB =0; + INT32 n32ColorComp =0; + INT32 YComp = (((INT32)(Y))<<14); + INT32 CrComp = (((INT32)(Cr))*c_g_cr); + INT32 CbComp = ((INT32)(Cb) * c_g_cb); + //;;;cal r + n32ColorComp = Check((YComp + (CrComp<<1))); + dwRGB = ((n32ColorComp<<16)|((unsigned int)n32ColorComp>>16)); + + //;;;cal g + n32ColorComp = Check((YComp-CrComp-CbComp)); + *(((char *)(&dwRGB))+1) = *(char *)(&n32ColorComp); + + //;;;cal b + n32ColorComp = Check((YComp + CbComp + (CbComp<<2) + (CbComp>>3))); + *(char *)(&dwRGB) = *(char *)(&n32ColorComp); + + return dwRGB; + +} + +// +//---------------------------------------------------------------------------- +// Procedure: InvertDCT +// +// Description: Performs inverse discrete cosine transform on dequantized data. +// +// Input: WORD * pwSource - Input is dequantized array of 8x8 pixels and +// output is data after applying inverse discrete cosine transform. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void InvertDCT(WORD * pwSource){ + WORD * pwSourceCopy=pwSource; + int nCounter=0; + + for(nCounter=0; nCounter<8; nCounter++){ + InvertDCT_xy(pwSource,1); + pwSource+=8; + } + pwSource = pwSourceCopy; + for(nCounter=0; nCounter<8; nCounter++){ + InvertDCT_xy(pwSource,8); + pwSource++; + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: InvertDCT_xy +// +// Description: Performs inverse discrete cosine transform on dequantized +// data in x and y direction. +// +// Input: WORD * pwSource - Input is dequantized array of 8x8 pixels +// and output is data after applying inverse discrete cosine transform. +// WORD wVal - +// wVal = 1, then the routine performs inverse discrete +// cosine transform on dequantized data in x direction. +// wVal = 8, then the routine performs inverse discrete cosine +// transform on dequantized data in y direction. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void InvertDCT_xy(WORD * pwSource, WORD wVal) +{ +INT32 buf1[8]; +INT32 buf2[8]; +int Index[8]; +int i=0; +for(;i<8;i++) +Index[i] = i*wVal; + +//;;;stage 1, 2 ,3 + +// ;;o0=x0 and normalize + buf2[0] = (((INT32)(INT16)(pwSource[0])*c1_sqrt2))>>14; + + +// ;;o1=x4*c1_4 + buf2[1] = (((INT32)(INT16)(pwSource[Index[4]]))*c1_4)>>14; + +// ;;o2=x2 + + buf2[2] = ((INT32)(INT16)(pwSource[Index[2]])); +// ;;;o3=(x2+x6)*c1_4 + + buf2[3] = ((((buf2[2] + (INT32)(INT16)(pwSource[Index[6]]))*c1_4))>>14); + +// ;;o4=x1 + + buf2[4] = (INT32)(INT16)(pwSource[Index[1]]); + +// ;;;o6=x1+x3 + + buf2[6] = buf2[4] + (INT32)(INT16)(pwSource[Index[3]]); + +// ;;;o7=(x1+x3+x5+x7)*c1_4 + + buf2[7] = (((buf2[6]+((INT32)(INT16)(pwSource[Index[5]]))+((INT32)(INT16)(pwSource[Index[7]])))*c1_4)>>14); + +// ;;;o5=(x3+x5)*c1_4 + + buf2[5] = (((((INT32)(INT16)(pwSource[Index[3]]))+((INT32)(INT16)(pwSource[Index[5]])))*c1_4)>>14); + +//;;;stage 4, 5 + +// ;;b0=o0+o1 + buf1[0] = buf2[0]+buf2[1]; + +// ;;b1=o0-o1 + buf1[1] = buf2[0]-buf2[1]; + +// ;;b2=(o2+o3)*c1_8 + + buf1[2]=(((buf2[2]+buf2[3])*c1_8)>>14); + +// ;;b3=(o2-o3)*c3_8 + + buf1[3]=(((buf2[2]-buf2[3])*c3_8)>>14); + +// ;;b4=o4+o5 + buf1[4] = buf2[4]+buf2[5]; + +// ;;b5=o4-o5 + buf1[5] = buf2[4]-buf2[5]; + +// ;;b6=(o6+o7)*c1_8 + + buf1[6]=(((buf2[6]+buf2[7])*c1_8)>>14); + +// ;;b7=(o6-o7)*c3_8 + + buf1[7]=(((buf2[6]-buf2[7])*c3_8)>>14); + +//;;;stage 6, 7 + +// ;;o0=b0+b2 + buf2[0] = buf1[0]+buf1[2]; + +// ;;o2=b0-b2 + buf2[2] = buf1[0]-buf1[2]; + +// ;;o1=b1+b3 + buf2[1] = buf1[1]+buf1[3]; + +// ;;o3=b1-b3 + buf2[3] = buf1[1]-buf1[3]; + +// ;;o4=(b4+b6)*c1_16 + + buf2[4] = (((buf1[4]+buf1[6])*c1_16)>>14); + +// ;;o6=(b4-b6)*c7_16 + + buf2[6] = (((buf1[4]-buf1[6])*c7_16)>>14); + +// ;;o5=(b5+b7)*c3_16 + + buf2[5] = (((buf1[5]+buf1[7])*c3_16)>>14); + +// ;;o7=(b5-b7)*c5_16 + + buf2[7] = (((buf1[5]-buf1[7])*c5_16)>>14); + +//;;;stage 8 + +// ;;b0=o0+o4 + + pwSource[0] = (WORD)((buf2[0]+buf2[4])>>1); + +// ;;b7=o0-o4 + + pwSource[Index[7]] = (WORD)((buf2[0]-buf2[4])>>1); + +// ;;b1=o1+o5 + + pwSource[Index[1]] = (WORD)((buf2[1]+buf2[5])>>1); + +// ;;b6=o1-o5 + + pwSource[Index[6]] = (WORD)((buf2[1]-buf2[5])>>1); + +// ;;b2=o3+o7 + + pwSource[Index[2]] = (WORD)((buf2[3]+buf2[7])>>1); + +// ;;b5=o3-o7 + + pwSource[Index[5]] = (WORD)((buf2[3]-buf2[7])>>1); + +// ;;b3=o2+o6 + + pwSource[Index[3]] = (WORD)((buf2[2]+buf2[6])>>1); + +// ;;b4=o2-o6 + + pwSource[Index[4]] = (WORD)((buf2[2]-buf2[6])>>1); + } +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/pcx.h b/EDK/MiniSetup/TseAdvanced/pcx.h new file mode 100644 index 0000000..0295c8d --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/pcx.h @@ -0,0 +1,138 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcx.h $ +// +// $Author: Arunsb $ +// +// $Revision: 4 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcx.h $ +// +// 4 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 6 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 3 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 4 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 3 6/16/09 2:16p Presannar +// Added File Headers for Header Files +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 6/30/06 4:22p Madhans +// PCX image support in C. +// +// 1 6/16/06 8:15a Shirinmd +// Added PCX Support in C for Minisetup +// +//*****************************************************************// +// +//---------------------------------------------------------------------------- +// +// Name: pcx.h +// +// Description: Header file for pcx image format related code +// +//---------------------------------------------------------------------------- +// + + +#ifndef _PCX_H_13_JUNE_2006 +#define _PCX_H_13_JUNE_2006 + +#include "MyDefs.h" + +#pragma pack(1) + +typedef struct _AMI_TRUECOLOR_PIXEL{ + BYTE Blue; + BYTE Green; + BYTE Red; + BYTE Reserved; +}AMI_TRUECOLOR_PIXEL, *PAMI_TRUECOLOR_PIXEL; + +#pragma pack() + + +//PCX File Header (128 bytes) +typedef struct _PCX_HEADER{ + BYTE bManufacturer; + BYTE bVersion; + BYTE bEncoding; + BYTE bBitsPerPixel; + WORD wXmin; + WORD wYmin; + WORD wXmax; + WORD wYmax; + WORD wHres; + WORD wVres; + BYTE bPalette[48]; + BYTE bReserved; + BYTE bColorPlanes; + WORD wBytesPerLine; + WORD wPaletteType; + WORD wHorizontalSize; + WORD wVerticalSize; + BYTE bFiller[54]; +}PCX_HEADER; + +typedef struct _PCX_INFO{ + WORD wImageWidth; + WORD wImageHeight; + WORD wBytesPerLine; + BYTE bBitsPerPixel; + DWORD dwPCXImageSize; + BYTE *bpPCXData; + BYTE *bpPalette; +}PCX_INFO; + + +#endif //#ifndef _PCX_H_13_JUNE_2006 + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2007, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/pcxc.c b/EDK/MiniSetup/TseAdvanced/pcxc.c new file mode 100644 index 0000000..6c1f9fc --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/pcxc.c @@ -0,0 +1,321 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcxc.c $ +// +// $Author: Arunsb $ +// +// $Revision: 5 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcxc.c $ +// +// 5 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 8 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 6 2/19/10 8:11a Mallikarjunanv +// updated year in copyright message +// +// 5 8/13/09 12:16p Blaines +// Move Image support to binary module +// +// 4 8/04/09 10:23a Madhans +// Fix to support big PCX images.(previously it was not supporing 800x600 +// images.) +// +// 3 6/23/09 7:09p Blaines +// Coding standard update, +// Remove spaces from file header to allow proper chm function list +// creation. +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 3 7/05/06 11:19a Madhans +// +// 2 7/05/06 11:09a Madhans +// DecodePCX function optimized. +// +// 1 6/30/06 4:22p Madhans +// PCX image support in C. +// +// 2 6/26/06 8:41a Shirinmd +// Modifications based on design change suggested by Madhan +// +// 1 6/16/06 8:15a Shirinmd +// Added PCX Support in C for Minisetup +// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: pcx.c +// +// Description: This file contains code for pcx image handling +// +//---------------------------------------------------------------------------- +// + +#include "pcx.h" + + +AMI_TRUECOLOR_PIXEL * ScreenBuffer = (AMI_TRUECOLOR_PIXEL *)NULL; + +//Functions +BOOL PCX_Init(BYTE * pbyPCXImage, PCX_INFO *pPCX_INFO, DWORD dwPCXImageSize); +BOOL GetPCXDimensions( BYTE * pbyPCXImageData, UINT32 * pn32Width, UINT32 * pn32Height); +BOOL DecodePCX(BYTE * pbyPCXInputData, BYTE * pbyPCXOutputData, DWORD dwPCXImageSize); +void Decode_Line(DWORD *wCountX, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer); +void Output_Line(DWORD wTop, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer); + +// +//---------------------------------------------------------------------------- +// Procedure: PCX_Init +// +// Description: This routine is used to fill the PCX_INFO structure. +// +// Input: BYTE * pbyPCXImage - Pointer that gives the memory location +// where the PCX input data is available. +// PCX_INFO *pPCX_INFO - Pointer to PCX_INFO structure +// DWORD dwPCXImageSize - Size of the PCX Image +// +// Output: BOOL - TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOL PCX_Init(BYTE * pbyPCXImage, PCX_INFO *pPCX_INFO, DWORD dwPCXImageSize) +{ + PCX_HEADER *pPCX_HEADER = (PCX_HEADER *)pbyPCXImage; + + if(pPCX_HEADER->bVersion != 5 || pPCX_HEADER->bBitsPerPixel == 1 || pPCX_HEADER->bBitsPerPixel == 2 || pPCX_HEADER->bColorPlanes != 1) + return FALSE; + + pPCX_INFO->wImageWidth = pPCX_HEADER->wXmax - pPCX_HEADER->wXmin + 1; + pPCX_INFO->wImageHeight = pPCX_HEADER->wYmax - pPCX_HEADER->wYmin + 1; + pPCX_INFO->wBytesPerLine = pPCX_HEADER->wBytesPerLine; + pPCX_INFO->bBitsPerPixel = pPCX_HEADER->bBitsPerPixel; + pPCX_INFO->dwPCXImageSize = dwPCXImageSize; + pPCX_INFO->bpPCXData = pbyPCXImage + 128; + if(pPCX_HEADER->bBitsPerPixel == 8) //256 color image palette at the end + pPCX_INFO->bpPalette = pbyPCXImage + dwPCXImageSize - 768; + else if(pPCX_HEADER->bBitsPerPixel == 4) //16 color image palette in the header + pPCX_INFO->bpPalette = pPCX_HEADER->bPalette; + return TRUE; + +} + +// +//---------------------------------------------------------------------------- +// Procedure: GetPCXDimensions +// +// Description: Get the dimensions (Width and Height of the PCX Image). +// +// Input: BYTE * pbyPCXImageData - Pointer to the buffer that contains the PCX data +// UINT32 * pun32Width - Pointer to the UINT32 variable that will +// receive the Width of the PCX Image +// UINT32 * pun32Height - Pointer to the UINT32 variable that +// will receive the Height of the PCX Image +// +// Output: BOOL - TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOL GetPCXDimensions( BYTE * pbyPCXImageData, UINT32 * pun32Width, UINT32 * pun32Height){ + BOOL bReturn = FALSE; + WORD wWidth = 0; + WORD wHeight= 0; + wWidth = *((WORD*)(pbyPCXImageData+8)) - *((WORD*)(pbyPCXImageData+4)) + 1; + wHeight = *((WORD*)(pbyPCXImageData+10)) - *((WORD*)(pbyPCXImageData+6)) + 1; + if( (wWidth > 0) && (wHeight > 0)) + { + *pun32Width = (UINT32)wWidth; + *pun32Height = (UINT32)wHeight; + bReturn = TRUE; + } + return bReturn; + +} + +// +//---------------------------------------------------------------------------- +// Procedure: Decode_Line +// +// Description: This routine will first check whether the PCX image is 16 +// color or 256 color and then decode the PCX image data one +// line at a time and put the decoded data in a One Line Buffer. +// +// Input: WORD *wCountX - Pointer to the index of the image data after 128 byte header +// PCX_INFO *pPCX_INFO - Pointer to PCX_INFO structure +// BYTE *pbOneLineBuffer - Pointer to the buffer that holds one line of decoded data. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void Decode_Line(DWORD *wCountX, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer) +{ + WORD wOffset_of_buffer = 0; + int nDataCount = 0; + WORD wLength_of_buffer = 0; + while(wLength_of_buffer < (pPCX_INFO->wImageWidth)) + { + if((pPCX_INFO->bpPCXData[*wCountX] & 0xC0) >= 0xC0) + nDataCount = (pPCX_INFO->bpPCXData[(*wCountX)++] & 0x3f); + else + nDataCount = 1; + + while(nDataCount--) + { + if(pPCX_INFO->bBitsPerPixel == 8) + { + pbOneLineBuffer[wOffset_of_buffer++] = pPCX_INFO->bpPCXData[*wCountX]; + (wLength_of_buffer)++; + } + else if(pPCX_INFO->bBitsPerPixel == 4) + { + pbOneLineBuffer[wOffset_of_buffer++] = ((pPCX_INFO->bpPCXData[*wCountX]) >> 4); + pbOneLineBuffer[wOffset_of_buffer++] = ((pPCX_INFO->bpPCXData[*wCountX]) & 0x0f); + (wLength_of_buffer) = (wLength_of_buffer)+2; + } + } + (*wCountX)++; + } + + + if(pPCX_INFO->bBitsPerPixel == 8) + { + if((pPCX_INFO->wImageWidth) != (pPCX_INFO->wBytesPerLine)) + (*wCountX)++; + } + else if(pPCX_INFO->bBitsPerPixel == 4) + { + if(wLength_of_buffer < ((pPCX_INFO->wBytesPerLine)<<1)) + (*wCountX)++; + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: Output_Line +// +// Description: This routine is used to map the decoded data to the palette +// and fill the global Screen Buffer. +// +// Input: WORD wTop - This variable gives the position from where a +// line should start in the Screen Buffer +// PCX_INFO *pPCX_INFO - Pointer to PCX_INFO structure +// BYTE *pbOneLineBuffer - Pointer to the buffer that holds one line of decoded data. +// +// Output: None +// +//---------------------------------------------------------------------------- +// +void Output_Line(DWORD wTop, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer) +{ + WORD wCountX; + int nIndex; + AMI_TRUECOLOR_PIXEL * pStartofLineInScreenBuffer = (AMI_TRUECOLOR_PIXEL *)ScreenBuffer + (wTop*(pPCX_INFO->wImageWidth)); + + for(wCountX = 0; wCountX< pPCX_INFO->wImageWidth; wCountX++) + { + nIndex = (3 * (int)(pbOneLineBuffer[wCountX])); + pStartofLineInScreenBuffer->Red = pPCX_INFO->bpPalette[nIndex]; + pStartofLineInScreenBuffer->Green = pPCX_INFO->bpPalette[nIndex + 1]; + pStartofLineInScreenBuffer->Blue = pPCX_INFO->bpPalette[nIndex + 2]; + pStartofLineInScreenBuffer++; + } + + +} + +// +//---------------------------------------------------------------------------- +// Procedure: DecodePCX +// +// Description: This routine will call functions to decode both 16 and 256 +// color PCX images of version 5 (with palette information) and +// fill the Screen Buffer. +// +// Input: BYTE * pbyPCXInputData - Pointer that gives the memory location +// where the PCX input data is available. +// BYTE * pbyPCXOutputData - Pointer to the buffer that will +// receive the decoded PCX image +// DWORD dwPCXImageSize - Size of the PCX Image +// +// Output: BOOL - TRUE/FALSE +// +//---------------------------------------------------------------------------- +// +BOOL DecodePCX(BYTE * pbyPCXInputData, BYTE * pbyPCXOutputData, DWORD dwPCXImageSize) +{ + PCX_INFO pcx_info; + BYTE * bOneLineBuffer = NULL; + DWORD wCountY = 0; + DWORD wCountX = 0; + + bOneLineBuffer = EfiLibAllocatePool(sizeof(BYTE)*1280); + if(bOneLineBuffer == NULL) + return FALSE; + + ScreenBuffer = (AMI_TRUECOLOR_PIXEL *)pbyPCXOutputData; + if(PCX_Init(pbyPCXInputData, &pcx_info, dwPCXImageSize)) + { + for(wCountY = 0; wCountY < pcx_info.wImageHeight; wCountY++) + { + Decode_Line(&wCountX, &pcx_info, bOneLineBuffer); + Output_Line(wCountY, &pcx_info, bOneLineBuffer); + } + MemFreePointer( (VOID **)&bOneLineBuffer); + return TRUE; + } + else + { + MemFreePointer( (VOID **)&bOneLineBuffer); + return FALSE; + } +} +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/png.c b/EDK/MiniSetup/TseAdvanced/png.c new file mode 100644 index 0000000..b2abf2e --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/png.c @@ -0,0 +1,1353 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/png.c $ +// +// $Author: Arunsb $ +// +// $Revision: 3 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/png.c $ +// +// 3 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 2 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 2 6/20/11 1:20p Rajashakerg +// [TAG] EIP60910 +// [Description] Updated with respect to the review comments. +// +// 1 6/13/11 12:21p Rajashakerg +// EIP:60910 -PNG image support in TSE. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: png.c +// +// Description: This file contains code for png image handling +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" +#include "png.h" +#include EFI_PROTOCOL_DEFINITION(GraphicsOutput) +//--------------------------------------------------------------------------- +// Macros +//--------------------------------------------------------------------------- +#define MakeDword(a,b,c,d) ((a)*0x1000000+(b)*0x10000+(c)*0x100+(d)) +#define IHDR MakeDword('I','H','D','R') +#define IDAT MakeDword('I','D','A','T') +#define PLTE MakeDword('P','L','T','E') +#define IEND MakeDword('I','E','N','D') +#define pHYs MakeDword('p','H','y','s') +#define tRNS MakeDword('t','R','N','S') +#define gAMA MakeDword('g','A','M','A') +#define PNG_SIGNATURE_LENGTH 8 +#define CHUNK_LENGTH 4 +#define CHUNK_TYPE 4 +#define CRC_LENGTH 4 + +static unsigned char *ImageBuffer = (unsigned char *)NULL; + + +// +//---------------------------------------------------------------------------- +// +// Name: PngGetUnsignedInt() +// +// Description: To get decimal values +// +// Input: const unsigned char dat[] +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned int PngGetUnsignedInt(const unsigned char dat[4]) +{ + return (unsigned)dat[3] + (unsigned)dat[2] * 0x100 + (unsigned)dat[1] * 0x10000 + (unsigned)dat[0] * 0x1000000; +} + +// +//---------------------------------------------------------------------------- +// +// Name: FindImageSize() +// +// Description: To find the PNG image size +// +// Input: none +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned int FindImageSize() +{ + unsigned char *dwBuf = (unsigned char *)NULL; + UINT32 i = 0; + unsigned int ImageSize = 0; + unsigned int length = 0; + unsigned int chunkType = 0; + + ImageBuffer = ImageBuffer + PNG_SIGNATURE_LENGTH; + dwBuf = (unsigned char *)EfiLibAllocateZeroPool(CHUNK_LENGTH); + if (dwBuf == NULL) { + goto ERREND; + } + ImageSize = PNG_SIGNATURE_LENGTH; + while (chunkType != IEND) //IEND is end of PNG image file + { + for (i = 0; i < CHUNK_LENGTH; i++) { + dwBuf[i] = ImageBuffer[i]; + } + ImageSize = ImageSize + CHUNK_LENGTH; //Adding 4 byte for Chunk Length to move the pointer to Chunk type field + ImageBuffer = ImageBuffer + CHUNK_LENGTH; + + length = PngGetUnsignedInt(dwBuf); + + for (i = 0; i < CHUNK_TYPE; i++) { + dwBuf[i] = ImageBuffer[i]; + } + ImageSize = ImageSize + CHUNK_TYPE; //Adding 4 byte for Chunk type to move the pointer to Chunk data field + ImageBuffer = ImageBuffer + CHUNK_TYPE; + + chunkType = PngGetUnsignedInt(dwBuf); + ImageSize = ImageSize + length + CRC_LENGTH; //Adding Chunk data length and CRC length to move the pointer to next Chunk + ImageBuffer = ImageBuffer + length + CRC_LENGTH; + } + if (dwBuf) { + MemFreePointer(&dwBuf); + } + + return ImageSize; +ERREND: + return 0; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Header_Decode() +// +// Description: To Store the header values in the PngHeader variables +// +// Input: unsigned char dat[] +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void Header_Decode(unsigned char dat[]) +{ + gPng_Info.hdr.width = PngGetUnsignedInt(dat); + gPng_Info.hdr.height = PngGetUnsignedInt(dat+4); + gPng_Info.hdr.bitDepth = dat[8]; // Storing IHDR values in PngHeader structure + gPng_Info.hdr.colorType = dat[9]; + gPng_Info.hdr.compressionMethod = dat[10]; + gPng_Info.hdr.filterMethod = dat[11]; + gPng_Info.hdr.interlaceMethod = dat[12]; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Palette_Decode() +// +// Description: To store the PLTE data values in PngPalette variables +// +// Input: unsigned length,unsigned char dat[] +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS Palette_Decode(unsigned length, unsigned char dat[]) +{ + if (length%3 != 0) //PLTE Length should be divisable by three + { + return EFI_UNSUPPORTED; + } + + if (gPng_Info.plt.entry != NULL) + { + MemFreePointer(&gPng_Info.plt.entry); + gPng_Info.plt.nEntry = 0; + } + + if (length > 0) + { + gPng_Info.plt.entry = (unsigned char *)EfiLibAllocateZeroPool(length); + if (gPng_Info.plt.entry != NULL) + { + unsigned int i; + gPng_Info.plt.nEntry = length/3; + for (i = 0; i < length; i++) + { + gPng_Info.plt.entry[i] = dat[i]; + } + } + } + + return EFI_SUCCESS; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Transparency_Decode() +// +// Description: To store the tRNS data values in PngPalette variables +// +// Input: unsigned int length,unsigned char dat[],unsigned int colorType +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS Transparency_Decode(unsigned int length, unsigned char dat[], unsigned int colorType) +{ + unsigned int i; + switch (colorType) //See PNG specification for the color Types + { + case 0: + if (length >= 2) + { + gPng_Info.trns.col[0] = (unsigned int)dat[0] * 256 + (unsigned int)dat[1]; + return EFI_SUCCESS; + } + break; + case 2: + if (length >= 6) + { + gPng_Info.trns.col[0] = (unsigned int)dat[0] * 256 + (unsigned int)dat[1]; + gPng_Info.trns.col[1] = (unsigned int)dat[2] * 256 + (unsigned int)dat[3]; + gPng_Info.trns.col[2] = (unsigned int)dat[4] * 256 + (unsigned int)dat[5]; + return EFI_SUCCESS; + } + break; + case 3: + for (i=0; i < 3 && i < length; i++) + { + gPng_Info.trns.col[i] = dat[i]; + } + return EFI_SUCCESS; + } + return EFI_ABORTED; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Initialize() +// +// Description: to initialize the PngImageDecoder member variables +// +// Input: none +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void Initialize(void) +{ + gPng_Info.gamma = gamma_default; + gPng_Info.trns.col[0] = 0x7fffffff; + gPng_Info.trns.col[1] = 0x7fffffff; + gPng_Info.trns.col[2] = 0x7fffffff; +} + +// +//---------------------------------------------------------------------------- +// +// Name: ReadChunk() +// +// Description: To Read all the chunk data +// +// Input: unsigned &length,unsigned char *&buf,unsigned &chunkType,unsigned &crc +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ReadChunk(unsigned *length, unsigned char **buf, unsigned *chunkType, unsigned *crc) +{ + unsigned char *dwBuf = (unsigned char *)NULL; + UINT32 i = 0; + EFI_STATUS Status = EFI_SUCCESS; + + dwBuf = (unsigned char *)EfiLibAllocateZeroPool(4); + if (dwBuf == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto EndRead; + } + for (i = 0; i < 4; i++) { + dwBuf[i] = ImageBuffer[i]; + } + ImageBuffer = ImageBuffer + CHUNK_LENGTH; //Adding 4 byte for Chunk Length to move the pointer to Chunk type field + + *length = PngGetUnsignedInt(dwBuf); + + for (i = 0; i < 4; i++) { + dwBuf[i] = ImageBuffer[i]; + } + ImageBuffer = ImageBuffer + CHUNK_TYPE; //Adding 4 byte for Chunk type to move the pointer to Chunk data field + + *chunkType = PngGetUnsignedInt(dwBuf); + + if(*length > 0) + { + *buf = (unsigned char *)EfiLibAllocateZeroPool(*length); + if (*buf == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto EndRead; + } + for (i = 0; i < *length; i++) { + (*buf)[i] = ImageBuffer[i]; + } + } + else + { + *buf = (unsigned char *)NULL; + } + ImageBuffer = ImageBuffer + *length; //Adding Chunk data length to move the pointer to CRC field + + for (i = 0; i < 4; i++) { + dwBuf[i] = ImageBuffer[i]; + } + ImageBuffer = ImageBuffer + CRC_LENGTH; //Adding 4 byte for CRC length to move the pointer to next Chunk + + *crc = PngGetUnsignedInt(dwBuf); + +EndRead: + + if (dwBuf) { //Fix for Fortify issue - Memory Leak + MemFreePointer(&dwBuf); + } + + return Status; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Decode() +// +// Description: Read all the PNG chunks and do convert the png format to RGB format. +// +// Input: unsigned char *PNGImage,UINT32 PNGImageSize +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS Decode(unsigned char *PNGImage, UINT32 PNGImageSize) +{ + unsigned char *datBuf = (unsigned char *)NULL; + unsigned datBufUsed; + unsigned char *buf; + unsigned length,chunkType,crc; + + if (PNGImage) + { + ImageBuffer = PNGImage; + PNGImageSize = FindImageSize(); //Find the png image size if the PNGImageSize is zero + + datBufUsed = 0; + datBuf = (unsigned char *)EfiLibAllocateZeroPool(PNGImageSize); + if (datBuf == NULL) { + goto ERREND; + } + + ImageBuffer = PNGImage + PNG_SIGNATURE_LENGTH; //Adding 8 bytes to move the pointer to Chunk length + while (ReadChunk(&length,&buf,&chunkType,&crc) == EFI_SUCCESS && chunkType != IEND) //Read the Chunk data upto IEND(End of the PNG image) + { + if(buf == NULL){ + break; //If the buffer is invalid, break from the loop + } + switch (chunkType) + { + case IHDR: + if (length >= 13) + { + Header_Decode(buf); //Stores the IHDR values in the PngHeader structure + } + MemFreePointer(&buf); + break; + case PLTE: + if (Palette_Decode(length,buf)) //Stores the PLTE values in the PngPalette structure + { + MemFreePointer(&buf); + goto ERREND; + } + MemFreePointer(&buf); + break; + case tRNS: + if (Transparency_Decode(length,buf,gPng_Info.hdr.colorType)) //Stores the tRNS values in the PngTransparency structure + { + MemFreePointer(&buf); + goto ERREND; + } + MemFreePointer(&buf); + break; + case gAMA: + if(length >= 4) + { + gPng_Info.gamma = PngGetUnsignedInt(buf); //Stores the gAMA chunk values + MemFreePointer(&buf); + } + break; + case IDAT: + if (buf != NULL) + { + unsigned i; + for (i = 0; i < length; i++) + { + datBuf[datBufUsed+i] = buf[i]; //Stores the IDAT chunk value in datbuf[] + } + datBufUsed += length; //datBufUsed used to store consecutive IDAT chunk sequentialy + MemFreePointer(&buf); + } + break; + default: + MemFreePointer(&buf); //Modified to remove the fortify warning + break; + } + } + + if (PrepareOutput() == EFI_SUCCESS) // Check the combination of Color type and bit debth + { + //PngUncompressor uncompressor; + //uncompressor.output = this; + if (Uncompress(datBufUsed,datBuf)) { //Convert the PNG image data into the RGB format in PngImageDecoder.rgba variable + goto ERREND; + } + } else { + goto ERREND; + } + + MemFreePointer(&datBuf); + return EFI_SUCCESS; + } + +ERREND: + if (datBuf) { + MemFreePointer(&datBuf); + } + return EFI_ABORTED; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Paeth() +// +// Description: +// +// Input: unsigned int ua,unsigned int ub,unsigned int uc +// +// Output: unsigned char +// +//---------------------------------------------------------------------------- +// +unsigned char Paeth(unsigned int ua,unsigned int ub,unsigned int uc) +{ + int a,b,c,p,pa,pb,pc; + + a = (int)ua; + b = (int)ub; + c = (int)uc; + + p = a + b - c; + pa = (p>a ? p-a : a-p); //Paeth filtering as per the PNG Specification + pb = (p>b ? p-b : b-p); + pc = (p>c ? p-c : c-p); + + if (pa <= pb && pa <= pc) + { + return (unsigned char)a; //Fix for Fortify issue - Type Mismatch : Signed to Unsigned + } + else if(pb <= pc) + { + return (unsigned char)b; //Fix for Fortify issue - Type Mismatch : Signed to Unsigned + } + else + { + return (unsigned char)c; //Fix for Fortify issue - Type Mismatch : Signed to Unsigned + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: Filter8() +// +// Description: +// +// Input: unsigned char curLine[],unsigned char prvLine[],int x,int y,int unitLng,int filter +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void Filter8(unsigned char curLine[],unsigned char prvLine[],int x,int y,int unitLng,int filter) +{ + int i; + switch (filter) //filtering algorithm + { + case 1: + if (x > 0) + { + for (i = 0; i < unitLng; i++) + { + curLine[ x * unitLng + i] = curLine[ x * unitLng + i] + curLine[ x * unitLng + i - unitLng]; + } + } + break; + case 2: + if (y > 0) + { + for (i = 0; i < unitLng; i++) + { + curLine[x * unitLng + i] = curLine[x * unitLng + i] + prvLine[ x * unitLng + i]; + } + } + break; + case 3: + for (i = 0; i < unitLng; i++) + { + unsigned int a; + a = (x > 0 ? curLine[x * unitLng + i - unitLng] : 0); + a += (y > 0 ? prvLine[x * unitLng + i] : 0); + curLine[x * unitLng + i] += (unsigned char)a / 2; + } + break; + case 4: + for (i = 0; i < unitLng; i++) + { + unsigned int a,b,c; + a = (x > 0 ? curLine[x * unitLng + i - unitLng] : 0); + b = (y > 0 ? prvLine[x * unitLng + i] : 0); + c = ((x > 0 && y > 0) ? prvLine[x * unitLng - unitLng + i] : 0); + curLine[x * unitLng + i] = curLine[x * unitLng + i] + Paeth(a,b,c); + } + break; + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: ShiftTwoLineBuf() +// +// Description: +// +// Input: none +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void ShiftTwoLineBuf(void) +{ + if (gPng_Info.twoLineBuf8 != NULL) + { + unsigned char *swap; + swap = gPng_Info.curLine8; + gPng_Info.curLine8 = gPng_Info.prvLine8; + gPng_Info.prvLine8 = swap; + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: PrepareOutput() +// +// Description: To validate the colorType and bitDepth combination and prepare the output data +// +// Input: none +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS PrepareOutput(void) +{ + int supported; + unsigned int twoLineBufLngPerLine = 0; + + supported = 0; + switch ( gPng_Info.hdr.colorType) + { + case 0: // Greyscale + switch (gPng_Info.hdr.bitDepth) + { + case 8: + case 1: + supported = 1; + break; + case 2: + case 4: + case 16: + break; + } + break; + case 2: // Truecolor + switch (gPng_Info.hdr.bitDepth) + { + case 8: + case 16: + supported = 1; + break; + } + break; + case 3: // Indexed-color + switch (gPng_Info.hdr.bitDepth) + { + case 4: + case 8: + supported = 1; + break; + case 1: + case 2: + break; + } + break; + case 4: // Greyscale with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + supported = 1; + break; + case 16: + break; + } + break; + case 6: // Truecolor with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + supported = 1; + break; + case 16: + break; + } + break; + } + + if (supported == 0) + { + return EFI_UNSUPPORTED; + } + + gPng_Info.wid = gPng_Info.hdr.width; + gPng_Info.hei =gPng_Info.hdr.height; + if(gPng_Info.autoDeleteRgbaBuffer == 1 && gPng_Info.rgba != NULL) + { + MemFreePointer(&gPng_Info.rgba); + gPng_Info.rgba = (unsigned char *)NULL; + } + gPng_Info.rgba = (unsigned char *)EfiLibAllocateZeroPool(gPng_Info.wid * gPng_Info.hei * 4); + gPng_Info.x = -1; + gPng_Info.y = 0; + gPng_Info.filter = 0; + gPng_Info.inLineCount = 0; + gPng_Info.inPixelCount = 0; + gPng_Info.firstByte = 1; + gPng_Info.index = 0; + gPng_Info.interlacePass = 1; + + if (gPng_Info.twoLineBuf8 != NULL) + { + MemFreePointer(&gPng_Info.twoLineBuf8); + } + + + switch (gPng_Info.hdr.colorType) + { + case 0: // Greyscale + switch(gPng_Info.hdr.bitDepth) + { + case 1: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 7) /8; + break; + case 2: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 3) / 4; + break; + case 4: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 1) / 2; + break; + case 8: + twoLineBufLngPerLine = gPng_Info.hdr.width; + break; + case 16: + twoLineBufLngPerLine = gPng_Info.hdr.width * 2; + break; + } + break; + case 2: // Truecolor + switch (gPng_Info.hdr.bitDepth) + { + case 8: + twoLineBufLngPerLine = gPng_Info.hdr.width * 3; + break; + case 16: + twoLineBufLngPerLine = gPng_Info.hdr.width * 6; + break; + } + break; + case 3: // Indexed-color + switch (gPng_Info.hdr.bitDepth) + { + case 1: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 7) / 8; + break; + case 2: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 3) / 4; + break; + case 4: + twoLineBufLngPerLine = (gPng_Info.hdr.width + 1) / 2; + break; + case 8: + twoLineBufLngPerLine = gPng_Info.hdr.width; + break; + } + break; + case 4: // Greyscale with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + twoLineBufLngPerLine = gPng_Info.hdr.width * 2; + break; + case 16: + twoLineBufLngPerLine = gPng_Info.hdr.width * 4; + break; + } + break; + case 6: // Truecolor with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + twoLineBufLngPerLine = gPng_Info.hdr.width * 4; + break; + case 16: + twoLineBufLngPerLine = gPng_Info.hdr.width * 8; + break; + } + break; + } + + gPng_Info.twoLineBuf8 = (unsigned char *) EfiLibAllocateZeroPool(twoLineBufLngPerLine*2); + gPng_Info.curLine8 = gPng_Info.twoLineBuf8; + gPng_Info.prvLine8 = gPng_Info.twoLineBuf8 + twoLineBufLngPerLine; + + return EFI_SUCCESS; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Output() +// +// Description: To create the output values in the RGB format. +// +// Input: unsigned char dat +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS Output(unsigned char dat) +{ + unsigned int i; + unsigned int colIdx; + unsigned int interlaceWid,interlaceHei,interlaceX,interlaceY; + + if (gPng_Info.y >= gPng_Info.hei || (gPng_Info.rgba == NULL)) + { + return EFI_UNSUPPORTED; + } + + if (gPng_Info.x == -1) // First byte is filter type for the line. + { + gPng_Info.filter = dat; // See PNG Specification for filtering + gPng_Info.inLineCount = 0; + gPng_Info.inPixelCount = 0; + gPng_Info.x++; + return EFI_SUCCESS; + } + else + { + switch (gPng_Info.hdr.interlaceMethod) + { + case 0: // Non-Interlace + switch (gPng_Info.hdr.colorType) // See PNG Specification for colortype and values + { + case 0: // Grayscale + switch (gPng_Info.hdr.bitDepth) + { + case 1: + gPng_Info.curLine8[gPng_Info.x/8] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x/8, gPng_Info.y, 1, gPng_Info.filter); + + for (i = 0; i < 8 && gPng_Info.x < gPng_Info.wid; i++) + { + colIdx = (gPng_Info.curLine8[gPng_Info.x/8] >> (7 - i))&1; + colIdx = (colIdx << 1) + colIdx; + colIdx = (colIdx << 2) + colIdx; + colIdx = (colIdx << 4) + colIdx; + + gPng_Info.rgba[gPng_Info.index] = (char)colIdx; + gPng_Info.rgba[gPng_Info.index+1] = (char)colIdx; + gPng_Info.rgba[gPng_Info.index+2] = (char)colIdx; + gPng_Info.rgba[gPng_Info.index+3] = 0; + gPng_Info.x++; + gPng_Info.index += 4; + } + break; + + case 8: + gPng_Info.curLine8[gPng_Info.x] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 1, gPng_Info.filter); + + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.x]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.x]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.x]; + if (gPng_Info.curLine8[gPng_Info.x] == gPng_Info.trns.col[0] || gPng_Info.curLine8[gPng_Info.x] == gPng_Info.trns.col[1] || gPng_Info.curLine8[gPng_Info.x] == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + + gPng_Info.x++; + gPng_Info.index += 4; + break; + } + break; + + case 2: //True color + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 3) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x,gPng_Info.y, 3, gPng_Info.filter); + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + + if (gPng_Info.curLine8[gPng_Info.inLineCount] == gPng_Info.trns.col[0] && + gPng_Info.curLine8[gPng_Info.inLineCount+1] == gPng_Info.trns.col[1] && + gPng_Info.curLine8[gPng_Info.inLineCount+2] == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + + gPng_Info.x++; + gPng_Info.index += 4; + gPng_Info.inLineCount += 3; + gPng_Info.inPixelCount = 0; + } + break; + case 16: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 6) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 6, gPng_Info.filter); + gPng_Info.rgba[gPng_Info.index] =gPng_Info. curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+4]; + + gPng_Info.r = gPng_Info.curLine8[gPng_Info.inLineCount] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.g = gPng_Info.curLine8[gPng_Info.inLineCount+2] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+3]; + gPng_Info.b = gPng_Info.curLine8[gPng_Info.inLineCount+4] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+5]; + if (gPng_Info.r == gPng_Info.trns.col[0] && gPng_Info.g == gPng_Info.trns.col[1] && gPng_Info.b == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + gPng_Info.x++; + gPng_Info.index += 4; + gPng_Info.inLineCount += 6; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + + case 3: // Indexed color + switch (gPng_Info.hdr.bitDepth) + { + case 4: + gPng_Info.curLine8[gPng_Info.x/2] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x/2, gPng_Info.y, 1, gPng_Info.filter); + + for (i = 0; i<2 && gPng_Info.x < gPng_Info.wid; i++) + { + colIdx = (gPng_Info.curLine8[gPng_Info.x/2] >> ((1 - i) * 4))&0x0f; + + if (colIdx < gPng_Info.plt.nEntry) + { + gPng_Info.rgba[gPng_Info.index] = gPng_Info.plt.entry[colIdx*3]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.plt.entry[colIdx*3+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.plt.entry[colIdx*3+2]; + if (colIdx == gPng_Info.trns.col[0] || colIdx == gPng_Info.trns.col[1] || colIdx == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + } + gPng_Info.x++; + gPng_Info.index += 4; + } + break; + + case 8: + gPng_Info.curLine8[gPng_Info.x] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 1, gPng_Info.filter); + colIdx = gPng_Info.curLine8[gPng_Info.x]; + + if (colIdx < gPng_Info.plt.nEntry) + { + gPng_Info.rgba[gPng_Info.index] = gPng_Info.plt.entry[colIdx*3]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.plt.entry[colIdx*3+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.plt.entry[colIdx*3+2]; + if (colIdx == gPng_Info.trns.col[0] || colIdx == gPng_Info.trns.col[1] || colIdx == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + } + gPng_Info.x++; + gPng_Info.index += 4; + break; + } + break; + + case 4: // Greyscale with alpha + switch(gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount + gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 2) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 2, gPng_Info.filter); + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+3] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.index += 4; + gPng_Info.x++; + gPng_Info.inLineCount += 2; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + + case 6: // Truecolor with alpha + switch(gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 4) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8,gPng_Info.x, gPng_Info.y, 4, gPng_Info.filter); + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + gPng_Info.rgba[gPng_Info.index+3] = gPng_Info.curLine8[gPng_Info.inLineCount+3]; + gPng_Info.index += 4; + gPng_Info.x++; + gPng_Info.inLineCount += 4; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + } // switch(hdr.colorType) + + if (gPng_Info.x >= gPng_Info.wid) + { + gPng_Info.y++; + gPng_Info.x = -1; + ShiftTwoLineBuf(); + } + + return EFI_SUCCESS; + + case 1: // Interlace + // 1 6 4 6 2 6 4 6 + // 7 7 7 7 7 7 7 7 + // 5 6 5 6 5 6 5 6 + // 7 7 7 7 7 7 7 7 + // 3 6 4 6 3 6 4 6 + // 7 7 7 7 7 7 7 7 + // 5 6 5 6 5 6 5 6 + // 7 7 7 7 7 7 7 7 + switch (gPng_Info.interlacePass) + { + case 1: + interlaceWid = (gPng_Info.wid + 7) / 8; + interlaceHei = (gPng_Info.hei + 7) / 8; + interlaceX = gPng_Info.x * 8; + interlaceY = gPng_Info.y * 8; + break; + case 2: + interlaceWid = (gPng_Info.wid + 3) / 8; + interlaceHei = (gPng_Info.hei + 7) / 8; + interlaceX = 4 + gPng_Info.x * 8; + interlaceY = gPng_Info.y * 8; + break; + case 3: + interlaceWid = (gPng_Info.wid + 3) / 4; + interlaceHei = (gPng_Info.hei + 3) / 8; + interlaceX = gPng_Info.x * 4; + interlaceY = 4 + gPng_Info.y * 8; + break; + case 4: + interlaceWid = (gPng_Info.wid + 1) / 4; + interlaceHei = (gPng_Info.hei + 3) / 4; + interlaceX = 2 + gPng_Info.x * 4; + interlaceY = gPng_Info.y * 4; + break; + case 5: + interlaceWid = (gPng_Info.wid + 1) / 2; + interlaceHei = (gPng_Info.hei + 1) / 4; + interlaceX = gPng_Info.x * 2; + interlaceY = 2 + gPng_Info.y * 4; + break; + case 6: + interlaceWid = (gPng_Info.wid) / 2; + interlaceHei = (gPng_Info.hei + 1) / 2; + interlaceX = 1 + gPng_Info.x * 2; + interlaceY = gPng_Info.y * 2; + break; + case 7: + interlaceWid = gPng_Info.wid; + interlaceHei = gPng_Info.hei / 2; + interlaceX = gPng_Info.x; + interlaceY = 1 + gPng_Info.y * 2; + break; + default: + return EFI_UNSUPPORTED; + } // switch(interlacePass) + + switch (gPng_Info.hdr.colorType) // See PNG Specification for Colour types and values + { + case 0: // Grayscale + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 1, gPng_Info.filter); + + gPng_Info.index = interlaceX * 4 + interlaceY * gPng_Info.wid * 4; + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount]; + + if (gPng_Info.curLine8[gPng_Info.inLineCount] == gPng_Info.trns.col[0] || + gPng_Info.curLine8[gPng_Info.inLineCount] == gPng_Info.trns.col[1] || + gPng_Info.curLine8[gPng_Info.inLineCount] == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + + gPng_Info.x++; + gPng_Info.inLineCount++; + break; + } + break; + + case 2: // True color + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 3) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 3, gPng_Info.filter); + + gPng_Info.index = interlaceX * 4 + interlaceY * gPng_Info.wid * 4; + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + + if ( gPng_Info.curLine8[ gPng_Info.inLineCount] == gPng_Info.trns.col[0] && + gPng_Info.curLine8[ gPng_Info.inLineCount+1] == gPng_Info.trns.col[1] && + gPng_Info.curLine8[ gPng_Info.inLineCount+2] == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[ gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[ gPng_Info.index+3] = 255; + } + + gPng_Info.x++; + gPng_Info.inLineCount += 3; + gPng_Info.inPixelCount = 0; + } + break; + + case 16: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 6) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 6, gPng_Info.filter); + gPng_Info.index = interlaceX * 4 + interlaceY * gPng_Info.wid * 4; + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+4]; + + gPng_Info.r = gPng_Info.curLine8[gPng_Info.inLineCount] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.g = gPng_Info.curLine8[gPng_Info.inLineCount+2] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+3]; + gPng_Info.b = gPng_Info.curLine8[gPng_Info.inLineCount+4] * 256 + gPng_Info.curLine8[gPng_Info.inLineCount+5]; + + if(gPng_Info.r==gPng_Info.trns.col[0] && gPng_Info.g==gPng_Info.trns.col[1] && gPng_Info.b==gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + + gPng_Info.x++; + gPng_Info.inLineCount += 6; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + + case 3: // Indexed color + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount] = dat; + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 1, gPng_Info.filter); + + gPng_Info.index = interlaceX * 4 + interlaceY *gPng_Info.wid * 4; + colIdx = gPng_Info.curLine8[gPng_Info.inLineCount]; + if (colIdx < gPng_Info.plt.nEntry) + { + gPng_Info.rgba[gPng_Info.index] = gPng_Info.plt.entry[colIdx*3]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.plt.entry[colIdx*3+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.plt.entry[colIdx*3+2]; + if (colIdx == gPng_Info.trns.col[0] || colIdx == gPng_Info.trns.col[1] || colIdx == gPng_Info.trns.col[2]) + { + gPng_Info.rgba[gPng_Info.index+3] = 0; + } + else + { + gPng_Info.rgba[gPng_Info.index+3] = 255; + } + } + + gPng_Info.x++; + gPng_Info.inLineCount++; + break; + } + break; + + case 4: // Greyscale with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 2) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 2, gPng_Info.filter); + + gPng_Info.index = interlaceX * 4 + interlaceY * gPng_Info.wid * 4; + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+3] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + + gPng_Info.x++; + gPng_Info.inLineCount += 2; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + + case 6: // Truecolor with alpha + switch (gPng_Info.hdr.bitDepth) + { + case 8: + gPng_Info.curLine8[gPng_Info.inLineCount+gPng_Info.inPixelCount] = dat; + gPng_Info.inPixelCount++; + if (gPng_Info.inPixelCount == 4) + { + Filter8(gPng_Info.curLine8, gPng_Info.prvLine8, gPng_Info.x, gPng_Info.y, 4, gPng_Info.filter); + + gPng_Info.index = interlaceX * 4 + interlaceY * gPng_Info.wid * 4; + gPng_Info.rgba[gPng_Info.index] = gPng_Info.curLine8[gPng_Info.inLineCount]; + gPng_Info.rgba[gPng_Info.index+1] = gPng_Info.curLine8[gPng_Info.inLineCount+1]; + gPng_Info.rgba[gPng_Info.index+2] = gPng_Info.curLine8[gPng_Info.inLineCount+2]; + gPng_Info.rgba[gPng_Info.index+3] = gPng_Info.curLine8[gPng_Info.inLineCount+3]; + + gPng_Info.x++; + gPng_Info.inLineCount += 4; + gPng_Info.inPixelCount = 0; + } + break; + } + break; + } // switch(hdr.colorType) + + if (gPng_Info.x >= (int)interlaceWid) + { + gPng_Info.y++; + gPng_Info.x = -1; + ShiftTwoLineBuf(); + if (gPng_Info.y >= (int)interlaceHei) + { + gPng_Info.y = 0; + gPng_Info.interlacePass++; + } + } + + return EFI_SUCCESS; + default: + return EFI_UNSUPPORTED; + } + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: ConvertPNGToBlt() +// +// Description: Decode the PNG and store the output in RGB format +// +// Input: IN VOID *PNGImage, IN UINT32 PNGImageSize, IN OUT VOID **Blt, +// IN OUT UINTN *BltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS ConvertPNGToUgaBlt( IN VOID *PNGImage, IN UINT32 PNGImageSize, IN OUT VOID **Blt, IN OUT UINTN *BltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth ) +{ + //PngImageDecoder pngDecoder; + //pngDecoder.Initialize(); + EFI_STATUS Status = EFI_SUCCESS; + unsigned int x,y; + EFI_UGA_PIXEL *buf = (EFI_UGA_PIXEL *)NULL; + unsigned char *tempRGBA; + PNGImageSize = 0; + Initialize(); + if (Decode((unsigned char*)PNGImage, PNGImageSize) == EFI_SUCCESS) //Decodes the PNG image to convert PNG image data to RGB format + { + + + *PixelHeight = gPng_Info.hei; + *PixelWidth = gPng_Info.wid; + *BltSize = (*PixelHeight) * (*PixelWidth) * 4; + + *Blt = EfiLibAllocateZeroPool(*BltSize); + if (*Blt == NULL) + { + Status = EFI_OUT_OF_RESOURCES; + return Status; + } + + buf = (EFI_UGA_PIXEL *)*Blt; + + for(y = 0; y < *PixelHeight; y++) { + for(x = 0; x < *PixelWidth; x++) { + + if(x < (unsigned int)gPng_Info.wid) + { + tempRGBA = gPng_Info.rgba + (y * gPng_Info.wid + x) * 4; + } + else + { + tempRGBA = gPng_Info.rgba + (y * gPng_Info.wid + gPng_Info.wid - 1) * 4; + } + + buf->Blue = tempRGBA[2]; + buf->Green = tempRGBA[1]; //Stores the converted image data(RGB format) + buf->Red = tempRGBA[0]; + buf++; + } + } + } else { + Status = EFI_ABORTED; + } + return Status; +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/png.h b/EDK/MiniSetup/TseAdvanced/png.h new file mode 100644 index 0000000..3e18132 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/png.h @@ -0,0 +1,136 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/png.h $ +// +// $Author: Arunsb $ +// +// $Revision: 2 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/png.h $ +// +// 2 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 2 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 1 6/13/11 12:21p Rajashakerg +// EIP:60910 -PNG image support in TSE. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: png.h +// +// Description: Header file for png image format related code +// +//---------------------------------------------------------------------------- +// + + +#include "MyDefs.h" + +#include EFI_PROTOCOL_DEFINITION(GraphicsOutput) +#ifndef _PNG_H_ +#define _PNG_H_ + +EFI_STATUS ConvertPNGToBlt ( IN VOID *PNGImage, IN UINT32 PNGImageSize, IN OUT VOID **Blt, IN OUT UINTN *BltSize, OUT UINT32 *PixelHeight, OUT UINT32 *PixelWidth); + +typedef struct _PngHeader //information about the PNG image +{ + unsigned int width; //width of the image in pixels + unsigned int height; //height of the image in pixels + unsigned int bitDepth; + unsigned int colorType; + unsigned int compressionMethod; //compression method of the original file + unsigned int filterMethod; //filter method of the original file + unsigned int interlaceMethod; //interlace method of the original file +} PngHeader; + +typedef struct _PngPalette +{ + unsigned int nEntry; + unsigned char *entry; +} PngPalette; + +typedef struct _PngTransparency +{ + unsigned int col[3]; +} PngTransparency; + +enum{ + gamma_default=100000 + }; + +typedef struct _PngImageDecoder +{ + PngHeader hdr; + PngPalette plt; + PngTransparency trns; + int wid,hei; + unsigned char *rgba; // Raw data of R,G,B,A + int autoDeleteRgbaBuffer; + int filter,x,y,firstByte; + int inLineCount; + int inPixelCount; + unsigned int r,g,b,msb; // msb for reading 16 bit depth + unsigned int index; + unsigned int interlacePass; + unsigned char *twoLineBuf8,*curLine8,*prvLine8; // For filtering + unsigned int gamma; +}PngImageDecoder; + +PngImageDecoder gPng_Info; + +void Initialize(void); + int CheckSignature(CHAR8 *PNGImage); + EFI_STATUS ReadChunk(unsigned *length,unsigned char **buf,unsigned *chunkType,unsigned *crc); + void Header_Decode(unsigned char dat[]); + EFI_STATUS Palette_Decode(unsigned length,unsigned char dat[]); + EFI_STATUS Transparency_Decode(unsigned length,unsigned char dat[],unsigned int colorType); + EFI_STATUS Decode(unsigned char *PNGImage,UINT32 PNGImageSize); + void ShiftTwoLineBuf(void); + EFI_STATUS PrepareOutput(void); + EFI_STATUS Output(unsigned char dat); + EFI_STATUS EndOutput(void); +EFI_STATUS Uncompress(unsigned length, unsigned char dat[]); + + +#endif //#ifndef _PNG_H_ + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** diff --git a/EDK/MiniSetup/TseAdvanced/pnguncmp.c b/EDK/MiniSetup/TseAdvanced/pnguncmp.c new file mode 100644 index 0000000..655994f --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/pnguncmp.c @@ -0,0 +1,879 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2011, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pnguncmp.c $ +// +// $Author: Arunsb $ +// +// $Revision: 3 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pnguncmp.c $ +// +// 3 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 2 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 2 6/20/11 1:19p Rajashakerg +// [TAG] EIP60910 +// [Description] Updated with respect to the review comments. +// +// 1 6/13/11 12:21p Rajashakerg +// EIP:60910 -PNG image support in TSE. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: pnguncmp.c +// +// Description: This file contains code for pcx image handling +// +//---------------------------------------------------------------------------- +// + +#include "png.h" +#define codeLengthLen 19 + +typedef struct _PngHuffmanTree +{ + unsigned dat; + struct _PngHuffmanTree *zero, *one; +}PngHuffmanTree; + +void MakeFixedHuffmanCode(unsigned *hLength, unsigned *hCode); +void MakeDynamicHuffmanCode(unsigned hLength[288], unsigned hCode[288], unsigned nLng, unsigned lng[]); +EFI_STATUS DecodeDynamicHuffmanCode + (unsigned int *hLit, unsigned int *hDist, unsigned int*hCLen, + unsigned int **hLengthLiteral, unsigned int **hCodeLiteral, + unsigned int **hLengthDist, unsigned int **hCodeDist, + unsigned int *hLengthBuf, unsigned int *hCodeBuf, + const unsigned char dat[], unsigned int *bytePtr, unsigned int *bitPtr); + +PngHuffmanTree *MakeHuffmanTree(unsigned n, unsigned *hLength, unsigned *hCode); +void DeleteHuffmanTree(PngHuffmanTree *node); + +unsigned GetCopyLength(unsigned value, unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr); +unsigned GetBackwardDistance(unsigned distCode, unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr); + + +// +//---------------------------------------------------------------------------- +// +// Name: GetNextBit() +// +// Description: To get the Next Bit +// +// Input: const unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned int GetNextBit(const unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr) +{ + unsigned a; + unsigned b; + a = dat[*bytePtr] & *bitPtr; + *bitPtr <<= 1; + if(*bitPtr >= 256) + { + *bitPtr = 1; + (*bytePtr)++; + } + b = (a != 0 ? 1 : 0); + return b; +} + +// +//---------------------------------------------------------------------------- +// +// Name: GetNextMultiBit() +// +// Description: To get the Next multiple Bits. +// +// Input: const unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr, unsigned n +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned int GetNextMultiBit(const unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr, unsigned n) +{ + unsigned value,mask,i; + value = 0; + mask = 1; + for(i = 0; i < n; i++) + { + if(GetNextBit(dat,bytePtr,bitPtr)) + { + value |= mask; + } + mask <<= 1; + } + return value; +} + +// +//---------------------------------------------------------------------------- +// +// Name: MakeFixedHuffmanCode() +// +// Description: To make the fixed huffman code +// +// Input: unsigned hLength[288],unsigned hCode[288] +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void MakeFixedHuffmanCode(unsigned *hLength, unsigned *hCode) +{ + unsigned i; + for(i = 0; i <= 143; i++) + { + hLength[i] = 8; + hCode[i] = 0x30+i; + } + for(i = 144; i <= 255; i++) + { + hLength[i] = 9; + hCode[i] = 0x190 + (i-144); + } + for(i = 256; i <= 279; i++) + { + hLength[i] = 7; + hCode[i] = i - 256; + } + for(i=280; i<=287; i++) + { + hLength[i] = 8; + hCode[i] = 0xc0 + (i-280); + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: MakeDynamicHuffmanCode() +// +// Description: To make the Dynamic Huffman Code +// +// Input: unsigned hLength[],unsigned hCode[],unsigned nLng,unsigned lng[] +// +// Output: none +// +//---------------------------------------------------------------------------- +// +void MakeDynamicHuffmanCode(unsigned hLength[], unsigned hCode[], unsigned nLng, unsigned lng[]) +{ + unsigned i, maxLng, code, *bl_count, *next_code, bits, n; + + for(i = 0; i < nLng; i++) + { + hLength[i] = lng[i]; + hCode[i] = 0; + } + + maxLng = 0; + for(i = 0; i < nLng; i++) + { + if(maxLng < lng[i]) + { + maxLng = lng[i]; + } + } + + bl_count = (unsigned int *) EfiLibAllocateZeroPool((maxLng+1)*sizeof(unsigned)); + if (!bl_count) { + return; + } + next_code = (unsigned int *) EfiLibAllocateZeroPool((maxLng+1)*sizeof(unsigned)); + if (!next_code) { + MemFreePointer(&bl_count); + return; + } + for(i = 0; i < maxLng+1; i++) + { + bl_count[i] = 0; + next_code[i] = 0; + } + for(i = 0; i < nLng; i++) + { + bl_count[lng[i]]++; + } + + code = 0; + bl_count[0] = 0; + for (bits = 1; bits <= maxLng; bits++) + { + code = (code + bl_count[bits-1]) << 1; + next_code[bits] = code; + } + + for (n = 0; n < nLng; n++) + { + unsigned len; + len = lng[n]; + if (len > 0) + { + hCode[n] = next_code[len]++; + } + } + + if (bl_count != NULL) + { + MemFreePointer(&bl_count); + } + if (next_code != NULL) + { + MemFreePointer(&next_code); + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: DecodeDynamicHuffmanCode() +// +// Description: Decodeing the Dynamic Huffman Code +// +// Input: unsigned int &hLit,unsigned int &hDist,unsigned int &hCLen, +// unsigned int *&hLengthLiteral,unsigned int *&hCodeLiteral, +// unsigned int *&hLengthDist,unsigned int *&hCodeDist, +// unsigned int hLengthBuf[322],unsigned int hCodeBuf[322], +// const unsigned char dat[],unsigned int &bytePtr,unsigned int &bitPtr +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS DecodeDynamicHuffmanCode + (unsigned int *hLit, unsigned int *hDist, unsigned int *hCLen, + unsigned int **hLengthLiteral, unsigned int **hCodeLiteral, + unsigned int **hLengthDist, unsigned int **hCodeDist, + unsigned int *hLengthBuf, unsigned int *hCodeBuf, + const unsigned char dat[], unsigned int *bytePtr, unsigned int *bitPtr) +{ + unsigned int i; + unsigned int nExtr=0; + PngHuffmanTree *lengthTree, *lengthTreePtr; + unsigned value, copyLength; + unsigned codeLengthOrder[codeLengthLen] = + { + 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 + }; + unsigned codeLengthCode[codeLengthLen]; + unsigned hLengthCode[codeLengthLen],hCodeCode[codeLengthLen]; + + *hLit = 0; + *hDist = 0; + *hCLen = 0; + + *hLit = GetNextMultiBit(dat, bytePtr, bitPtr, 5); + *hDist = GetNextMultiBit(dat, bytePtr, bitPtr, 5); + *hCLen = GetNextMultiBit(dat, bytePtr, bitPtr, 4); + + for (i = 0; i < codeLengthLen; i++) + { + codeLengthCode[i] = 0; + } + for (i = 0; i < *hCLen+4; i++) + { + codeLengthCode[codeLengthOrder[i]] = GetNextMultiBit(dat, bytePtr, bitPtr, 3); + } + + MakeDynamicHuffmanCode(hLengthCode, hCodeCode, codeLengthLen, codeLengthCode); + + *hLengthLiteral = hLengthBuf; + *hCodeLiteral = hCodeBuf; + *hLengthDist = hLengthBuf + *hLit + 257; + *hCodeDist = hCodeBuf+ *hLit + 257; + + + lengthTree = MakeHuffmanTree(codeLengthLen, hLengthCode, hCodeCode); + if (lengthTree == NULL) { + return EFI_ABORTED; + } + + lengthTreePtr = lengthTree; + while (nExtr < *hLit + 257 + *hDist +1) + { + if (GetNextBit(dat, bytePtr, bitPtr)) + { + if(lengthTreePtr->one){ + lengthTreePtr = lengthTreePtr->one; + } + } + else + { + if(lengthTreePtr->zero){ + lengthTreePtr = lengthTreePtr->zero; + } + } + if (lengthTreePtr->zero == NULL && lengthTreePtr->one == NULL) + { + + value = lengthTreePtr->dat; + + if (value <= 15) + { + hLengthBuf[nExtr++] = value; + } + else if (value == 16) + { + copyLength = 3 + GetNextMultiBit(dat, bytePtr, bitPtr, 2); + while (copyLength > 0) + { + hLengthBuf[nExtr] = hLengthBuf[nExtr-1]; + nExtr++; + copyLength--; + } + } + else if (value == 17) + { + copyLength = 3 + GetNextMultiBit(dat, bytePtr, bitPtr, 3); + while (copyLength > 0) + { + hLengthBuf[nExtr++] = 0; + copyLength--; + } + } + else if (value == 18) + { + copyLength = 11 + GetNextMultiBit(dat, bytePtr, bitPtr, 7); + while (copyLength > 0) + { + hLengthBuf[nExtr++] = 0; + copyLength--; + } + } + + lengthTreePtr = lengthTree; + } + } + + MakeDynamicHuffmanCode(*hLengthLiteral, *hCodeLiteral, *hLit+257, *hLengthLiteral); + MakeDynamicHuffmanCode(*hLengthDist, *hCodeDist, *hDist+1, *hLengthDist); + + DeleteHuffmanTree(lengthTree); + + return EFI_SUCCESS; +} + +// +//---------------------------------------------------------------------------- +// +// Name: MakeHuffmanTree() +// +// Description: To create the huffman tree +// +// Input: unsigned n,unsigned hLength[],unsigned hCode[] +// +// Output: PngHuffmanTree +// +//---------------------------------------------------------------------------- +// +PngHuffmanTree *MakeHuffmanTree(unsigned n, unsigned *hLength, unsigned *hCode) +{ + unsigned i, j, mask; + PngHuffmanTree *root, *ptr; + + root = EfiLibAllocateZeroPool(sizeof(PngHuffmanTree)); + if (root == NULL) { + return (PngHuffmanTree *)NULL; + } + + for (i = 0; i < n; i++) + { + if (hLength[i] > 0) + { + ptr = root; + mask = (1<<(hLength[i]-1)); + for (j = 0; j < hLength[i]; j++) + { + if (hCode[i] & mask) + { + if (ptr->one == NULL) + { + ptr->one = EfiLibAllocateZeroPool(sizeof(PngHuffmanTree)); + } + ptr = ptr->one; + } + else + { + if (ptr->zero == NULL) + { + ptr->zero = EfiLibAllocateZeroPool(sizeof(PngHuffmanTree)); + } + ptr = ptr->zero; + } + mask >>= 1; + } + ptr->dat = i; + } + } + + return root; +} + +// +//---------------------------------------------------------------------------- +// +// Name: DeleteHuffmanTree() +// +// Description: Deleting the created Trees +// +// Input: PngHuffmanTree *node +// +// Output: String size +// +//---------------------------------------------------------------------------- +// +void DeleteHuffmanTree(PngHuffmanTree *node) +{ + if (node != NULL) + { + DeleteHuffmanTree(node->zero); //Delete the Huffman tree + DeleteHuffmanTree(node->one); + MemFreePointer( &node); + } +} + +// +//---------------------------------------------------------------------------- +// +// Name: GetCopyLength() +// +// Description: To Get the correct Copy Length +// +// Input: unsigned value,unsigned char dat[],unsigned &bytePtr,unsigned &bitPtr +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned GetCopyLength(unsigned value, unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr) +{ + unsigned copyLength; + unsigned base,offset,extBits; + + if (value <= 264) + { + copyLength = 3 + (value - 257); + } + else if (value >= 285) + { + copyLength = 258; + } + else + { + extBits = 1 + (value-265) / 4; + base = (8 << ((value-265) / 4)) + 3; + offset = ((value-265) & 3) * (2 << ((value - 265) / 4)); + + copyLength = GetNextMultiBit(dat, bytePtr, bitPtr, extBits); + copyLength += base+offset; + } + + return copyLength; +} + +// +//---------------------------------------------------------------------------- +// +// Name: GetBackwardDistance() +// +// Description: To get the Backward Distance +// +// Input: unsigned distCode,unsigned char dat[],unsigned &bytePtr,unsigned &bitPtr +// +// Output: unsigned int +// +//---------------------------------------------------------------------------- +// +unsigned GetBackwardDistance + (unsigned distCode, unsigned char dat[], unsigned *bytePtr, unsigned *bitPtr) +{ + unsigned backDist; + unsigned base, offset, extBits; + + if (distCode <= 3) + { + backDist = distCode + 1; + } + else + { + + + base = (4 << ((distCode - 4) / 2)) + 1; + offset = (distCode&1) * (2 << ((distCode - 4) / 2)); + extBits = (distCode - 2) / 2; + + backDist = GetNextMultiBit(dat,bytePtr,bitPtr,extBits); + backDist += base + offset; + } + + return backDist; +} + +// +//---------------------------------------------------------------------------- +// +// Name: Uncompress() +// +// Description: Used to Uncompress the Image data and to convert the RGB format. +// +// Input: unsigned length,unsigned char dat[] +// +// Output: int +// +//---------------------------------------------------------------------------- +// +EFI_STATUS Uncompress(unsigned length, unsigned char dat[]) +{ + unsigned windowUsed; + unsigned char *windowBuf; + unsigned nByteExtracted; + PngHuffmanTree *codeTree, *codeTreePtr; + PngHuffmanTree *distTree, *distTreePtr; + unsigned bytePtr, bitPtr; + unsigned char cmf, flg; + unsigned cm, cInfo, windowSize; + unsigned fDict; + unsigned *hLengthBuf = (unsigned *)NULL; + unsigned *hCodeBuf = (unsigned *)NULL; + unsigned *hLength = (unsigned *)NULL; + unsigned *hCode = (unsigned *)NULL; + unsigned value; + unsigned copyLength,distCode,backDist; + int i=0; + windowBuf = (unsigned char *)NULL; + + codeTree = (PngHuffmanTree *)NULL; + distTree = (PngHuffmanTree *)NULL; + bytePtr = 0; + bitPtr = 1; + nByteExtracted = 0; + + cmf = dat[bytePtr++]; + flg = dat[bytePtr++]; + + cm = cmf&0x0f; + if (cm != 8) + { + goto ERREND; + } + + cInfo = (cmf&0xf0)>>4; + windowSize = 1 << (cInfo + 8); + + windowBuf = (unsigned char *)EfiLibAllocateZeroPool(windowSize); + windowUsed = 0; + + fDict = (flg&32) >> 5; + + if (fDict != 0) + { + goto ERREND; + } + + while (1) + { + unsigned bFinal,bType; + + bFinal = GetNextBit(dat, &bytePtr, &bitPtr); + bType = GetNextMultiBit(dat, &bytePtr, &bitPtr, 2); + + if (bytePtr >= length) + { + goto ERREND; + } + + if (bType == 0) // No Compression + { + unsigned len; + if (bitPtr != 1) //Skip the current byte. + { + bitPtr = 1; + bytePtr++; + } + if (bytePtr >= length) + { + goto ERREND; + } + + len = dat[bytePtr] + dat[bytePtr + 1] * 256; + bytePtr += 4; //Skip bytes for length(2 bytes) and 1's complement of length(2 bytes). + + for( i=0; i<(int)len; i++) //Feed the image data that is not compressed to output buffer. + { + Output(dat[bytePtr+i]); + } + bytePtr += len; + } + else if (bType == 1 || bType == 2) + { + codeTree = (PngHuffmanTree *)NULL; + + if (bType == 1) + { + hLength = (unsigned *)EfiLibAllocateZeroPool(288 * sizeof(unsigned)); //Prefast issue fix - Exceeds stack size issue + hCode = (unsigned *)EfiLibAllocateZeroPool(288 * sizeof(unsigned)); + if (!hLength || !hCode) { + goto ERREND; + } + MakeFixedHuffmanCode(hLength, hCode); + codeTree = MakeHuffmanTree(288, hLength, hCode); + distTree = (PngHuffmanTree *)NULL; + if (hLength) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hLength); + } + if (hCode) { + MemFreePointer( &hCode); + } + } + else + { + unsigned hLit, hDist, hCLen; + unsigned *hLengthLiteral, *hCodeLiteral; + unsigned *hLengthDist, *hCodeDist; + + hLengthBuf = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); //Prefast issue fix - Exceeds stack size issue + hCodeBuf = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); + + /*Changes + hLengthLiteral = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); + hCodeLiteral = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); + hLengthDist = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); + hCodeDist = (unsigned *)EfiLibAllocateZeroPool(322 * sizeof(unsigned)); + + */ + if (!hLengthBuf || !hCodeBuf) { + goto ERREND; + } + + if (DecodeDynamicHuffmanCode + (&hLit, &hDist, &hCLen, + &hLengthLiteral, &hCodeLiteral, &hLengthDist, &hCodeDist, hLengthBuf, hCodeBuf, + dat, &bytePtr, &bitPtr)) { + goto ERREND; + } + + codeTree = MakeHuffmanTree(hLit+257, hLengthLiteral, hCodeLiteral); + if (codeTree == NULL) { + goto ERREND; + } + distTree = MakeHuffmanTree(hDist+1, hLengthDist, hCodeDist); + if (distTree == NULL) { + goto ERREND; + } + /* + if (hLengthLiteral) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hLengthLiteral); + } + if (hCodeLiteral) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hCodeLiteral); + } + if (hLengthDist) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hLengthDist); + } + if (hCodeDist) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hCodeDist); + } + */ + if (hLengthBuf) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hLengthBuf); + } + if (hCodeBuf) { + MemFreePointer( &hCodeBuf); + } + } + + codeTreePtr = codeTree; + if (codeTree != NULL) + { + while (1) + { + if (GetNextBit(dat, &bytePtr, &bitPtr)) + { + codeTreePtr = codeTreePtr->one; + } + else + { + codeTreePtr = codeTreePtr->zero; + } + + if (codeTreePtr == NULL) + { + goto ERREND; + } + + if (codeTreePtr->zero == NULL && codeTreePtr->one == NULL) + { + + value = codeTreePtr->dat; + if (value < 256) + { + windowBuf[windowUsed++] = (unsigned char)value; + windowUsed &= (windowSize - 1); + if (Output((unsigned char)value)) + { + goto ERREND; + } + nByteExtracted++; + } + else if (value == 256) + { + break; + } + else if (value <= 285) + { + + copyLength = GetCopyLength(value, dat, &bytePtr, &bitPtr); + + if (bType == 1) + { + distCode = 16 * GetNextBit(dat, &bytePtr, &bitPtr); // 5 bits fixed + distCode += 8 * GetNextBit(dat, &bytePtr, &bitPtr); // Reversed order + distCode += 4 * GetNextBit(dat, &bytePtr, &bitPtr); + distCode += 2 * GetNextBit(dat, &bytePtr, &bitPtr); + distCode += GetNextBit(dat, &bytePtr, &bitPtr); + } + else + { + distTreePtr = distTree; + while (distTreePtr->zero != NULL || distTreePtr->one != NULL) + { + if (GetNextBit(dat,&bytePtr,&bitPtr)) + { + if (distTreePtr->one) //Fix for Fortify issue - Null Dereference + distTreePtr = distTreePtr->one; + } + else + { + if (distTreePtr->zero) //Fix for Fortify issue - Null Dereference + distTreePtr = distTreePtr->zero; + } + } + distCode = distTreePtr->dat; + } + backDist = GetBackwardDistance(distCode,dat,&bytePtr,&bitPtr); + + + for(i=0; i < (int)copyLength; i++) + { + unsigned char dat; + dat = windowBuf[(windowUsed-backDist)&(windowSize-1)]; + if (Output(dat)) + { + goto ERREND; + } + nByteExtracted++; + windowBuf[windowUsed++] = dat; + windowUsed &= (windowSize-1); + } + } + + codeTreePtr = codeTree; + } + + if (length <= bytePtr) + { + goto ERREND; + } + } + } + + + DeleteHuffmanTree(codeTree); + DeleteHuffmanTree(distTree); + codeTree = (PngHuffmanTree *)NULL; + distTree = (PngHuffmanTree *)NULL; + } + else + { + goto ERREND; + } + + + if (bFinal != 0) + { + break; + } + } + + MemFreePointer( &windowBuf); + windowBuf = (unsigned char *)NULL; + + return EFI_SUCCESS; + +ERREND: + if (windowBuf != NULL) + { + MemFreePointer( &windowBuf); + } + if (codeTree != NULL) + { + DeleteHuffmanTree(codeTree); + codeTree = (PngHuffmanTree *)NULL; + } + if (distTree != NULL) + { + DeleteHuffmanTree(distTree); + distTree = (PngHuffmanTree *)NULL; + } + if (hLength) { //Prefast issue fix - Exceeds stack size issue + MemFreePointer( &hLength); + } + if (hCode) { + MemFreePointer( &hCode); + } + if (hLengthBuf) { + MemFreePointer( &hLengthBuf); + } + if (hCodeBuf) { + MemFreePointer( &hCodeBuf); + } + return EFI_ABORTED; +} + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** + + + + \ No newline at end of file diff --git a/EDK/MiniSetup/TseAdvanced/special.c b/EDK/MiniSetup/TseAdvanced/special.c new file mode 100644 index 0000000..1ab3ef6 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/special.c @@ -0,0 +1,1898 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2014, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/special.c $ +// +// $Author: Premkumara $ +// +// $Revision: 47 $ +// +// $Date: 8/28/14 11:49a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/special.c $ +// +// 47 8/28/14 11:49a Premkumara +// [TAG] EIP174031 +// [Category] Improvement +// [Description] Removed TODO comments and added proper comments in those +// places +// [Files] commonoem.c, commonhelper.c, special.c, submenu.c, +// minisetupext.c, uefi21wapper.c and legacy.c +// +// 46 5/02/14 12:55p Premkumara +// [TAG] EIP131549 +// [Category] Bug Fix +// [Severity:] Important +// [Symptom:] After adding boot/driver options and Loading defaults causes +// crashing issue. +// [Root Cause] While discarding boot/driver options the boot order get +// corrupted by copying extra data because of wrong size. +// [Solution] Handled proper size to copy boot/driver options while +// loading defaults +// [Files] AddBootOption.c, Special.c +// +// 45 2/11/14 7:47p Arunsb +// [TAG] EIP140870 +// [Category] Bug Fix +// [Severity:] Normal +// [Symptom:] BBS EFI OS boot entry will not disappear after remove EFI OS +// Hdd. +// [Root Cause] Once EFI-HDD is removed still NVRAM is giving boot data +// for +// EFI-HDD(Windows BootManager) with the Active = 0x9(Active+Hidden). +// But TSE is not checking this Active flag for BootOverride menu. +// [Solution] Checked Boot option for Hidden or Active before creating +// controlInfo +// [Files] special.c +// +// 44 12/04/13 2:18p Premkumara +// [TAG] EIP131549 +// [Category] Bug Fix +// [Severity:] Important +// [Symptom:] After adding boot/driver options and Loading defaults causes +// crashing issue. +// [Root Cause] While discarding boot/driver options the boot order get +// corrupted by copying extra data because of wrong size. +// [Solution] Handled proper size to copy boot/driver options while +// loading defaults +// [Files] AddBootOption.c, Special.c +// +// 43 4/11/13 3:36a Arunsb +// [TAG] EIP117538 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Boot override of BSU could not see the deivces +// [RootCause] Hidden boot devices not handled properly +// [Solution] Hidden boot devices included in all boot options display +// related cases. +// [Files] special.c +// +// 42 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 21 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 40 9/25/12 5:41a Arunsb +// [TAG] EIP100099 +// [Category] Improvement +// [Description] Added submenu icon for driver health options +// [Files] special.c +// +// 39 9/21/12 9:43a Premkumara +// [TAG] EIP 97704 +// [Category] Improvement +// [Description] Support BootFFFF variable +// [Files] Boot.h, Boot.c, Special.c +// +// 38 9/17/12 6:08a Rajashakerg +// Updated EIP changes for 2.16 release. +// +// 36 8/29/12 8:43a Premkumara +// [TAG] EIP-91817 +// [Description] To avoid comparing garbage gBootData for +// LoadOptionHidden when SETUP_SHOW_ALL_BBS_DEVICES = 1 +// [Files] Special.c +// +// 35 4/03/12 12:40a Premkumara +// [TAG] EIP83704 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] HDD user password and Admin password entries are +// disappeared. +// [RootCause] When HDD is freeze VARIABLE_ID_IDE_SECURITY variable is +// not updated while navigating to page by page +// [Solution] Updated VARIABLE_ID_IDE_SECURITY variable when HDD is +// freeze before navigate to pages. +// [Files] Special.c +// +// 34 1/31/12 6:13a Premkumara +// [TAG] EIP79955 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] GEOMETRICSHAPE_RIGHT_TRIANGLE Mark is missing for AddBoot +// option in TSE advanced +// [RootCause] Since AddBoot Option is a special control +// GEOMETRICSHAPE_RIGHT_TRIANGLE is not drawn. +// [Solution] Drawn GEOMETRICSHAPE_RIGHT_TRIANGLE for AddBoot Option +// control +// [Files] Special.c +// +// 33 1/13/12 1:24a Arunsb +// [TAG] EIP80360 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] HDDSecurity module - Issue in login with TSE, Master +// password disabled +// [RootCause] Cache not updated +// [Solution] Cache updated properly +// [Files] Tseadvanced.c, special.c and uefi21wapper.c +// +// 32 1/04/12 4:10p Blaines +// [TAG] EIP 78627 +// [Category] Sighting +// [Symptom] SAS controller card items in the main list should begin +// with an > (arrow/sideways triagle) +// [RootCause] TSE dynamically creates submenu links (controls with the +// SubMenuType = 2, draw without arrow ) to Dynamic Pages (Hii pages +// published by offboard cards with UEFI Option Rom). +// [Solution] For Dynamic pages, set the control's property submenu-> +// SubMenuType = 1, to draw the control text with an arrow. +// +// [Files Changed] +// - special.c +// +// [Functions Changed] +// - _SpecialControlExtras +// +// 31 12/08/11 9:11p Arunsb +// Wrapper function added for GetFormSetTitleAndHelp fnc to resolve the +// build error in 2.0 +// +// 30 12/01/11 7:16p Blaines +// Fix build errors in Uefi2.0 +// +// 29 11/30/11 1:29p Premkumara +// [TAG] EIP75352 +// [Category] Improvement +// [Description] Suppress the warnings from static code analyzer +// [Files] Boot.c, bbs.c, TseAdvanced.c, Special.c, Variable.c, +// TseLiteHelper.c, PopupSel.c, AddBootOption.c, Hii.c, FormBrowser2.c +// +// 28 11/30/11 12:26a Premkumara +// [TAG] EIP75351 +// [Category] Improvement +// [Description] Static code analysis.Suppress the warnings from static +// code analyzer +// [Files] String.c, HiiString21.c, TseAdvanced.c, Special.c, +// UefiAction., Time.c, PopupEdit.c, MessageBox.c, Label.c, Edit.c, Date.c +// +// 27 11/13/11 12:38p Arunsb +// [TAG] EIP70421 +// [Category] New Feature +// [Description] Support for driver order in TSE +// [Files] AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini, +// boot.c, +// minisetup.h, bbs.c, special.c, special.h, tseadvanced.c, +// addbootoption.c, +// callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h, +// TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h, +// TseElink.h, variable.h, +// setup.h, Boot.vfr and Setup.uni +// +// 26 10/31/11 9:43a Rajashakerg +// [TAG] EIP71120,71512 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] BIOS gets stuck in infinite loop On enabling +// TSE_LOAD_OPTION_HIDDEN token,In first boot incorrect devices is +// disabled in Setup & BBS table but in second boot the correct device is +// disabled in both places. +// [Solution] Hidden option handled properly. +// [Files] TseLite\variable.c, TseLite\minisetupext.c, TseAdvanced.c, +// special.c, BootOnly\minisetup.h,BootOnly\boot.c, BootOnly\bbs.c +// +// 25 10/20/11 12:25p Blaines +// Correct the comments. +// +// 24 10/20/11 11:48a Blaines +// [TAG] EIP 72333 +// [Category] Sighting +// [Symptom] Some SAS controller card HII Screen Titles are displaying +// the wrong information +// [RootCause] Menu tab always displays the root page title when +// navigating submenu pages. TSE did not support the display of Formset +// Help. +// +// [Solution] Display Formset Help for Dynamic page, Display page title of +// submenu pages in the menu tab. +// +// [Files Changed] +// - AMITSE.sdl, CommonHelper.c, special.c, Menu.c, minisetupext.h, +// TseUefiHii.h, Uefi21Wapper.c +// +// 23 6/30/11 4:12a Arunsb +// [TAG] EIP57661 +// [Category] New Feature +// [Description] Boot manager algorithm for interaction with Driver +// Health protocol. +// Driver health special controls handled. +// [Files] amitse.cif, amitse.sdl, faketokens.c, amitsestr.uni, +// commonhelper.c, uefisetup.ini, tsedrvhealth.h, +// amivfr.h, minisetupbin.mak, +// hiistring21.c, hiistring20.c, tseadvanced.c, special.c, +// special.h, boot.h, minisetup.h, +// uefi20wapper.c, formbrowser2.c, hii.c, parse.c and +// uefi21wapper.c. +// +// 22 6/28/11 4:37p Madhans +// [TAG] EIP55290 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] Keeping Different Default Language other then English will +// cause Lanuage options to show same language repeated. +// [RootCause] The Language name was not updated protperly. +// [Solution] Fix to read to update token. +// [Files] special.c +// +// 21 6/20/11 11:50a Rajashakerg +// [TAG] EIP59417 +// [Category] New Feature +// [Description] Spport LOAD_OPTION_HIDDEN option in TSE +// [Files] boot.h, AMITSE.sdl, CommonHelper.c, bbs.c, boot.c, +// minisetup.h, special.c, callback.c +// +// 20 6/01/11 4:14p Madhans +// [TAG] EIP61588 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] In Advanced page Iscsi page link disappears when any update +// happens +// [RootCause] When pages are updated dynamically we might have few +// invalidated PageInfo. Dynamic page grouping special control want not +// checking them +// [Solution] Dynamic page grouping special control check if the page is +// valid or not. +// [Files] Special.c +// Parse.c +// +// 19 4/29/11 4:31p Arunsb +// For 2.13 public patch release IFR RefX feature is omitted +// +// 16 3/23/11 8:38p Blaines +// [TAG] - EIP 23601 +// [Category]- Enhancement +// [Symptom]- Add support for OEM special controls. +// [Files] - AmiTse.sdl, CommonHelper.c, Setup.ini, UefiSetup.ini, +// AmiVfr.h, minisetup.h, minisetup.sdl, variable.c, special.c +// +// 15 3/15/11 5:18a Rajashakerg +// [TAG] EIP51671 +// [Category] New Feature +// [Description] Boot overide menu devices are not disable +// [Files] boot.c, minisetup.h, special.c, minisetupext.c, AMITSE.sdl, +// boot.h, CommonHelper.c +// +// 14 2/10/11 12:32p Blaines +// [TAG] - EIP 53146 +// [Category]- New Feature +// [Description] -Add the support to Move the Dynamic IFR Pages under +// subpages. It should be customizable to move around. +// +// 13 1/10/11 9:36a Mallikarjunanv +// Updated the file with respect to new changes regarding EIP51619 +// +// 12 1/07/11 12:28a Mallikarjunanv +// [TAG] EIP51619 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] Changing the option in the "HDD BBS Priority" option not +// reflected in the boot options list. +// [RootCause] Boot page is not updated properly with changes made by +// BBS HDD BBS Priority +// [Solution] Updated the boot page with changes made by BBS HDD BBS +// Priority +// [Files] special.c, variable.c +// +// 11 12/25/10 6:44a Mallikarjunanv +// [TAG] EIP48391 +// [Category] Bug Fix +// [Severity] Important +// [Symptom] BOOT menu string disappeared, and BOOT page not displayed +// properly while adding more than 100 boot options using "Add boot +// option" +// [RootCause] if the number of options exceeds the option limit which +// is UINT16, it get crashed +// [Solution] Added a new function GetSpecialBootoptionToken(), in which +// by updating the strings in hii for those tokens which are previously +// not updated. If for a token the string is already udpated, we will +// skipt that token. +// [Files] special.c +// +// 10 10/27/10 3:15p Madhans +// [TAG] EIP45785 +// [Category] Defect +// [Symptom] Grayingout the BBS priorities is not working. only supporess +// the first one. for UEFI 2.0 +// [RootCause] The condition showing only one disabled option is not +// affecting the original condition. +// [Solution] The control condition will not be updated if it evaluates to +// not COND_NONE. +// [Files] Special.c +// +// 9 9/20/10 6:47p Madhans +// [TAG] EIP44542 +// [Category] BUILD ISSUE FIX +// [Symptom] Build issues with TSE label (INT)4.6.2_TSE_2_10_1207_TEST +// when IdeSecurity and FastBoot modules added to the project +// [RootCause] - +// [Solution] Build issues resolved +// [Files] CommonHelper.c, Tsecommon.h, Hiilib.h, Boot.h, minisetup.h, +// bbs.c, special.c, Bds.c TseLitehelp +// +// 8 9/16/10 8:38p Madhans +// Update for TSE 2.10. Refer Changelog.log for more details. +// +// 15 9/16/10 3:14p Madhans +// To Avoid build issues with TSE_USE_EDK_LIBRARY Building. +// +// 14 8/27/10 5:04a Mallikarjunanv +// EIP-39334: support to build TSE without the CSM module support +// +// 13 8/19/10 12:50p Mallikarjunanv +// EIP-42520: Updated to get the BBS group type from the Board module in +// case of a non standard type. +// +// 12 8/12/10 1:04p Blaines +// Use of reference to gFrame.AddControl to allow option to customization +// outside of +// +// 11 7/07/10 7:45p Madhans +// Changes to Support Adding Conditions to Suppress or Grayout the Special +// controls. +// +// 10 4/02/10 4:37p Madhans +// To get ride of TSEOEM.H referance in TSE. Oem hearder files can be +// refered only in Tse Binary. +// +// 9 3/23/10 5:10p Blaines +// Add new style module hook +// +// 8 2/19/10 8:12a Mallikarjunanv +// updated year in copyright message +// +// 7 2/08/10 5:39a Mallikarjunanv +// EIP-34679: Typo error fix +// +// 6 1/09/10 4:55a Mallikarjunanv +// Updated TSE2.01 Release sources with coding standards +// +// 5 12/18/09 2:27p Madhans +// EIP: 32350 To fix the Add/Delete Boot option issues with TSE 2.0. +// +// 4 9/15/09 9:37a Sudhirv +// added support for SETUP_OEM_SPECIAL_CONTROL_SUPPORT and updated the +// Handling of Add Del Boot Option related sources +// +// 3 8/13/09 7:37a Mallikarjunanv +// eip:24971 - supporting tse features without tse sources +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 2 4/29/09 9:02p Madhans +// Bug Fixes after unit Testing.. +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// +//*****************************************************************// +//*****************************************************************// + +// +//---------------------------------------------------------------------------- +// +// Name: Special.c +// +// Description: This file contains code to handle special Operations +// +//---------------------------------------------------------------------------- +// + +#include "minisetup.h" +#include "Special.h" + +#define BOOT_OPTION_SIZE sizeof(UINT16) + +extern VOID UefiSetHelpField(VOID *IfrPtr,UINT16 Token); +EFI_STATUS GetFormSetTitleAndHelpWrapper (VOID *Handle, UINT16 *Title, UINT16 *Help); +extern BOOLEAN gSetupUpdated;//EIP:51619 Flag which represents the setup update +VOID _SpecialControlExtras(CONTROL_DATA *ctrlData); +VOID _SpecialFixupBootOrder( CONTROL_INFO *control , UINT16 value); +VOID _SpecialFixupLanguages( CONTROL_INFO *control ); +VOID _SpecialFixupBBSOrder( CONTROL_INFO *control, UINT16 value ); +VOID _SpecialFixupBBSCondition(UINT16 ControlIndex,CONTROL_INFO *control,UINT16 PrevControlQuestionID); +VOID _SpecialFixupBootCondition(UINT16 ControlIndex,CONTROL_INFO *control,UINT16 PrevControlQuestionID); + +UINT32 FindVarFromITKQuestionId(UINT16 QuestionId); +VOID _SpecialFixupAddBootOption( CONTROL_INFO *control); +UINT16 GetNoVarStoreBootCountOffset(); + +UINT16 BBSGetNonStandardGroupType(UINT16 DeviceType); //EIP-42520 + +#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT +extern UINT16 OEMSpecialGetControlCount(CONTROL_INFO *controlInfo); +extern VOID OEMSpecialOneOfFixup( CONTROL_INFO *control , UINT16 value ); +extern VOID OEMSpecialGotoFixup(CONTROL_INFO *control, UINT16 value ); +#endif //#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT +extern STYLECOLORS Colors; + +//EIP 57661 Driver health support +CHAR16 *FindDriverHealthDriverName (UINT16); +CHAR16 *GetCtrlNameAndHealth (UINT16 ControllerEntry); +//EIP 57661 Ends +//EIP70421 Support for Driver Order starts +VOID *gDriverPageHandle = NULL; +UINTN gDriverOptionTokenCount; +UINT16 *gDriverOptionTokenArray; +BOOLEAN CheckForAddDelDriverOption (VOID); +VOID _SpecialFixupDriverOrder (CONTROL_INFO *control, UINT16 value); +//EIP70421 Support for Driver Order ends + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialGetIfrPtr +// +// Description: function to handle the operation of getting the Ifr Pointer. +// +// Input: VOID* conditional, +// UINT32 variable, +// GUID_INFO **guidInfo +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID *_SpecialGetIfrPtr( CONTROL_INFO *controlInfo, UINT32 * variable, GUID_INFO **guidInfo ) +{ + *variable = (UINT32)GetControlConditionVarId(controlInfo); + return UefiGetSpecialEqIDIfrPtr(controlInfo, variable, guidInfo); +} + +// +//---------------------------------------------------------------------------- +// Procedure: SpecialGetValue +// +// Description: function to handle the operation of getting the Ifr Value. +// +// Input: CONTROL_DATA *control, +// GUID_INFO **guidInfo +// +// Output: UINT16 +// +//---------------------------------------------------------------------------- +// +UINT16 SpecialGetValue( CONTROL_DATA *control, GUID_INFO **guidInfo ) +{ + return UefiGetSpecialEqIDValue(&control->ControlData, guidInfo); +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialGetValue +// +// Description: function to handle the operation of getting the Ifr Value. +// +// Input: CONTROL_INFO *controlinfo, +// GUID_INFO **guidInfo +// +// Output: UINT16 +// +//---------------------------------------------------------------------------- +// +UINT16 _SpecialGetValue( CONTROL_INFO *controlinfo, GUID_INFO **guidInfo ) +{ + return UefiGetSpecialEqIDValue(controlinfo, guidInfo); +} + + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialAddControl +// +// Description: function to Handle adding a control. +// +// Input: FRAME_DATA *frame , +// CONTROL_INFO *controlinfo, +// BOOLEAN *SetFocus +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +// +EFI_STATUS _SpecialAddControl(FRAME_DATA *frame , CONTROL_INFO *ControlInfo, BOOLEAN *SetFocus) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + STYLECOLORS saveColors ; + + + //Save original style colors + saveColors = Colors ; + + //Special control color scheme... + StyleControlColor(frame, &Colors); + + //Adds controls to this frame... + Status = gFrame.AddControl( frame, ControlInfo ); + + //Restore original style colors + Colors = saveColors; + + if ( EFI_ERROR(Status) ) + return Status; + + if ( *SetFocus ) + { + if ( _FrameSetControlFocus( frame, frame->ControlCount-1 ) ) + { + frame->CurrentControl = frame->ControlCount-1; + *SetFocus = FALSE; + } + } + + return Status; + +} +// +//---------------------------------------------------------------------------- +// Procedure: DoAddBootOptionFixup +// +// Description: +// +// Input: CONTROL_INFO *newControlInfo +// +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID DoAddBootOptionFixup( CONTROL_INFO *newControlInfo ) +{ + _SpecialFixupAddBootOption(newControlInfo); +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialAddMultipleControls +// +// Description: Adds Multiple controls for special controls +// +// Input: FRAME_DATA *frame , CONTROL_INFO *controlInfo, GUID_INFO *guidInfo, BOOLEAN *SetFocus +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID _SpecialAddMultipleControls( FRAME_DATA *frame , CONTROL_INFO *controlInfo, GUID_INFO *guidInfo, BOOLEAN *SetFocus ) +{ + CONTROL_INFO *newControlInfo; + VARIABLE_INFO *varInfo = NULL; + UINT8 *dataPtr; + VOID *ifrPtr; + CHAR16 *name = NULL; + + UINT16 count, max = 0, value = 0, HiddenBootOptionCount=0;//EIP : 59417 Declaration for the Hidden Boot option count + UINT16 PrevControlQuestionID=0; + + UINT32 varnum=0; + UINTN condSize; + + if ( frame == NULL ) + return; + + if ( guidInfo->GuidFlags.GuidLaunchCallbackUpdateTemplate ) + { + UefiSpecialGuidCallback( controlInfo->ControlHandle, 0xFFFE, &guidInfo->GuidValue); + } + + varnum = GetControlConditionVarId(controlInfo); //controlInfo->ControlConditionalVariable[0]; + ifrPtr = _SpecialGetIfrPtr( controlInfo, &varnum, NULL ); // TO get the special variable. + + if(NoVarStoreSupport()) + { + //More info needed. + if(varnum == VARIABLE_ID_SETUP) + { + ifrPtr = _SpecialGetIfrPtr( controlInfo, &varnum, NULL ); + + //The variable supplied is setup find the right variable + varnum = FindVarFromITKQuestionId(UefiGetEqIDQuestionID(ifrPtr)); + } + } + + if( varnum == VARIABLE_ID_ERROR_MANAGER ) // if it is error manager variable, get the real updated nvram data. + VarUpdateVariable(varnum); + + varInfo = ((VARIABLE_INFO *)((UINT8 *)gVariables + gVariables->VariableList[varnum])); + name = GetGUIDNameByID(VARIABLE_ID_LANGUAGE); + //The following is replaced by Name comparision + //if ( ((VARIABLE_INFO *)((UINT8 *)gVariables + gVariables->VariableList[varnum]))->VariableID == LANGUAGE_CODES_KEY_ID ) + if(EfiStrCmp(varInfo->VariableName, name) == 0) + { + MemFreePointer(&name); + max = 1; + } + else if ( + ( + CheckForAddDelBootOption () && + ((VARIABLE_ID_DEL_BOOT_OPTION == controlInfo->ControlVariable) || (VARIABLE_ID_ADD_BOOT_OPTION == controlInfo->ControlVariable)) + ) || + ( + CheckForAddDelDriverOption () && //EIP70421 & 70422 + ((VARIABLE_ID_DEL_DRIVER_OPTION == controlInfo->ControlVariable) || (VARIABLE_ID_ADD_DRIVER_OPTION == controlInfo->ControlVariable)) + ) + ) + { + max = 1; + } +#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT + else if(varnum == VARIABLE_ID_OEM_TSE_VAR ) + { + max = OEMSpecialGetControlCount(controlInfo); + } +#endif + else + { + VarGetValue( varnum, 0, sizeof(UINT16), &max ); + } + for (count = 0; count < max; count++) + { + if ( ( controlInfo->ControlPtr == 0 ) || ( controlInfo->ControlConditionalPtr == 0 ) ) + continue; + if ( + (gLoadOptionHidden && ((VARIABLE_ID_BOOT_MANAGER == varnum) || (VARIABLE_ID_BOOT_NOW == varnum) || (VARIABLE_ID_DRIVER_MANAGER == varnum))) && + (VARIABLE_ID_DEL_BOOT_OPTION != controlInfo->ControlVariable) && //For deleting the boot/driver option max is 1 so if first option is hidden nothing will proceed + (VARIABLE_ID_ADD_BOOT_OPTION != controlInfo->ControlVariable) && + (VARIABLE_ID_DEL_DRIVER_OPTION != controlInfo->ControlVariable) && + (VARIABLE_ID_ADD_DRIVER_OPTION != controlInfo->ControlVariable) + ) + { + if (count < gBootOptionCount) //EIP-91817 To avoid comparing garbage gBootData for LoadOptionHidden when SETUP_SHOW_ALL_BBS_DEVICES = 1 + { + if ((VARIABLE_ID_DRIVER_MANAGER == varnum) ? (LoadOptionhidden (count, DRIVER_ORDER_OPTION)) : (LoadOptionhidden (count, BOOT_ORDER_OPTION))) + { + HiddenBootOptionCount ++; // If the Boot option has the attribute Hidden increment the HiddenBootOptionCount + continue; + } + } + } + newControlInfo = EfiLibAllocatePool( sizeof( CONTROL_INFO ) ); + if ( newControlInfo == NULL ) + continue; + + MemCopy( newControlInfo, controlInfo, sizeof( CONTROL_INFO ) ); + condSize = (UINTN)controlInfo->ControlPtr - (UINTN)controlInfo->ControlConditionalPtr; + + // 256 should be replaced by ControlDataLength, but HPKTool currently does not set it + dataPtr = EfiLibAllocateZeroPool( 256 + condSize ); + if(dataPtr == NULL) + { + MemFreePointer((void**)&newControlInfo); + continue; + } + + newControlInfo->ControlConditionalPtr = dataPtr; + MemCopy( dataPtr, (VOID *)controlInfo->ControlConditionalPtr, condSize ); + dataPtr += condSize; + newControlInfo->ControlPtr = dataPtr; + MemCopy( dataPtr, (VOID *)controlInfo->ControlPtr, 256 ); + + ifrPtr = _SpecialGetIfrPtr( newControlInfo, &varnum, NULL ); + + if ( ifrPtr != NULL ) + { + if ((UefiIsOneOfControl ((VOID *)dataPtr)) && ((VARIABLE_ID_BOOT_MANAGER == varnum) || (VARIABLE_ID_DRIVER_MANAGER == varnum))) + { + UefiSetEqIDValue (ifrPtr, count - HiddenBootOptionCount); + } + else + { + UefiSetEqIDValue (ifrPtr, count); + } + } + ifrPtr = (VOID *)dataPtr; + + // EIP:51671 START + //Depending on the value of the token hide of the disabled boot options is done + if (gSetupHideDisableBootOptions) + { + if(((VARIABLE_ID_BOOT_MANAGER == varnum)||(VARIABLE_ID_BOOT_NOW == varnum))&&(!(UefiIsOneOfControl( ifrPtr )))) + { + if (IsBootDeviceEnabled (count, gShowAllBbsDev, BootNowInBootOrderSupport (), 1)) + continue; + } + } + // EIP:51671 END + // EIP:59417 START + //Checking for the Bootmanger variable and the token for Load Option hidden + + // EIP:59417 END + if (UefiIsOneOfControl (ifrPtr)) + { + UINTN size; + CHAR16 *newText; + CHAR16 *text ; + + text = HiiGetString( controlInfo->ControlHandle, UefiGetPromptField(ifrPtr) ); + //EIP-75351 Suppress the warnings from static code analyzer + if (NULL == text) { + text = EfiLibAllocateZeroPool(2*sizeof(CHAR16)); + if(!text) + return; + EfiStrCpy(text,L" "); + } + + size = sizeof(CHAR16) * ( EfiStrLen( text ) + 10 ); + newText = EfiLibAllocateZeroPool( size ); + + SPrint( newText, size, text, count + 1 - HiddenBootOptionCount ); + + value = _SpecialGetValue( newControlInfo, &guidInfo ); + UefiSetPromptField(ifrPtr, HiiAddString( controlInfo->ControlHandle, newText )); + + // update boot order , bbs and language tokens, prevent double initialization + // this code was part of AddControlExtras(). + UefiUpdateControlVarOffset (newControlInfo->ControlPtr, value * sizeof(UINT16)); + + switch ( guidInfo->GuidKey ) + { + case GUID_KEY_BOOT_NOW: + if (NoVarStoreSupport()) + { + _SpecialFixupBootOrder (newControlInfo, value); + } + else + { + if (newControlInfo->ControlVariable == VARIABLE_ID_BOOT_ORDER) + { + _SpecialFixupBootOrder (newControlInfo, value); + //if count not eq to 0 and count-1 Control is Disabled then supress the current control. + _SpecialFixupBootCondition(count,newControlInfo,PrevControlQuestionID); + PrevControlQuestionID = UefiGetQuestionID(newControlInfo); + } + else if (newControlInfo->ControlVariable == VARIABLE_ID_DEL_BOOT_OPTION) + { + TSESpecialFixupDelBootOption (newControlInfo); + } + } + break; + case GUID_KEY_ADD_BOOT_OPTION: + if ((CheckForAddDelBootOption()) && (newControlInfo->ControlVariable == VARIABLE_ID_ADD_BOOT_OPTION)) + { + UefiUpdateControlVarOffset(newControlInfo->ControlPtr, UefiGetQuestionOffset(controlInfo->ControlPtr)); + TseDoAddBootOptionFixup( newControlInfo ); + } + break; + + case GUID_KEY_LANG_CODES: + if ( gLangCount > 0 ) + _SpecialFixupLanguages( newControlInfo ); + break; + + case GUID_KEY_BBS_ORDER: + _SpecialFixupBBSOrder( newControlInfo, value); + if(!NoVarStoreSupport()) + { + //if count not eq to 0 and count-1 Control is Disabled then supress the current control. + _SpecialFixupBBSCondition(count,newControlInfo,PrevControlQuestionID); + PrevControlQuestionID = UefiGetQuestionID(newControlInfo); + } + break; + case GUID_KEY_DRIVER_OPTION: //EIP70421 & 70422 + if (VARIABLE_ID_DRIVER_ORDER == newControlInfo->ControlVariable) + { + _SpecialFixupDriverOrder (newControlInfo, value); + //if count not eq to 0 and count-1 Control is Disabled then supress the current control. + _SpecialFixupBootCondition (count, newControlInfo, PrevControlQuestionID); + PrevControlQuestionID = UefiGetQuestionID(newControlInfo); + } + else if (VARIABLE_ID_DEL_DRIVER_OPTION == newControlInfo->ControlVariable) + { + TSESpecialFixupDelDriverOption (newControlInfo); + } + break; +#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT + case GUID_KEY_OEM_CONTROL: + // Do the OEM Special Control's OneOf Fixup + OEMSpecialOneOfFixup( newControlInfo, value); + break; +#endif + default: + break; + } + + MemFreePointer( (VOID **)&newText ); + MemFreePointer( (VOID **)&text ); + } + _SpecialAddControl( frame, newControlInfo, SetFocus ); + // update optional info specially for boot order controls + _SpecialControlExtras((frame->ControlList[frame->ControlCount-1])); + MemFreePointer( (VOID **)&newControlInfo ); + } + + gSetupUpdated = FALSE; //EIP:51619 Reset the SetupUpdated Flag here. +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupLanguages +// +// Description: function to fixup the languages +// +// Input: CONTROL_INFO *control +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupLanguages( CONTROL_INFO *control ) +{ + VOID *ifrPtr, *templatePtr, *oneOf; + VOID *tempPtr; + UINTN i, length = 0; + BOOLEAN flag = FALSE; + + ifrPtr = (VOID *)control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + + if(PlatformLangVerSupport()) + UefiSetWidth(ifrPtr, 6); + else + UefiSetWidth(ifrPtr, 3); + + tempPtr = UefiCreateOneOfWithOptionsTemplate( gLangCount, control ); + if ( tempPtr == NULL ) + return; + + templatePtr = (UINT8*)ifrPtr + length; + oneOf = (UINT8*)tempPtr + length; + length = UefiGetIfrLength(templatePtr); + for ( i = 0; i < gLangCount; i++ ) + { + MemCopy( oneOf, templatePtr, length ); + flag = 0; + gLanguages[i].Token = HiiChangeString( gHiiHandle, gLanguages[i].Token, gLanguages[i].LangString ); + UefiSetOneOfOption(oneOf, i, BOOT_OPTION_SIZE, flag, gLanguages[i].Token); + oneOf = (UINT8*)oneOf +length; + } + + // Add an End op to close scope of the One of control + UefiAddEndOp(oneOf); + + tempPtr = HiiGetString( control->ControlHandle, UefiGetPromptField(ifrPtr) ); + UefiSetPromptField (control->ControlPtr,HiiAddString( gHiiHandle, tempPtr )); + + MemFreePointer( (VOID **)&tempPtr ); + tempPtr = HiiGetString( control->ControlHandle, UefiGetHelpField(ifrPtr) ); + + control->ControlHelp = HiiAddString( gHiiHandle, tempPtr ); + control->ControlHandle = gHiiHandle; + + MemFreePointer( (VOID **)&tempPtr ); +} + +//EIP-48391: Start + +static VOID *gBootPageHandle = NULL; +static UINTN gBootOptionTokenCount; +static UINT16 *gBootOptionTokenArray; + +// +//---------------------------------------------------------------------------- +// Procedure: GetSpecialBootoptionToken +// +// Description: function to get the boot option token properly when loading the boot page +// +// Input: VOID* handle, UINTN Index +// +// Output: TOKEN +// +//---------------------------------------------------------------------------- +// +UINT16 GetSpecialBootoptionToken(VOID* handle, UINTN Index) +{ + UINTN i; + + // EIP:51619 TO make sure it is called by _SpecialFixupBootOrder() and Boot page not modified + if (gBootPageHandle == handle) + { + if(FALSE == gSetupUpdated) + { + if(!gBootOptionTokenCount) + { + // Create the gBootOptionTokenArray + gBootOptionTokenArray = EfiLibAllocateZeroPool (sizeof(UINT16) * gBootOptionCount); + gBootOptionTokenCount = gBootOptionCount; + for(i=0;i< gBootOptionTokenCount;i++) + { + gBootOptionTokenArray[i] = INVALID_TOKEN; + } + } + else if(gBootOptionTokenCount < gBootOptionCount) + { // Boot options added. Update gBootOptionTokenArray + gBootOptionTokenArray = MemReallocateZeroPool(gBootOptionTokenArray, (sizeof(UINT16) * gBootOptionTokenCount), (sizeof(UINT16) * gBootOptionCount)); + for(i= gBootOptionTokenCount; i< gBootOptionCount ;i++) + { + gBootOptionTokenArray[i] = INVALID_TOKEN; + } + gBootOptionTokenCount = gBootOptionCount; + } + + if(gBootOptionTokenArray[Index] == INVALID_TOKEN) + gBootOptionTokenArray[Index] = HiiAddString(handle, BootGetOptionName( &(gBootData[Index]) ) ); + else + { + // Check if Update is needed + CHAR16 *text; + text = HiiGetString( handle, gBootOptionTokenArray[Index]); + + if (NULL == text) //EIP-131549 + return (UINT16)EFI_OUT_OF_RESOURCES; + + if(EfiStrCmp(text, BootGetOptionName( &(gBootData[Index]) )) != 0) + { + // need to update the token with new BootoptionName. + UINT16 Token = HiiChangeString( handle, gBootOptionTokenArray[Index], BootGetOptionName( &(gBootData[Index]) )); + if(Token != gBootOptionTokenArray[Index]) + gBootOptionTokenArray[Index] = Token; + } + MemFreePointer((VOID **)&text); + } + } + else { + //If the some control modified with respect to boot page.. + gBootOptionTokenArray[Index] = HiiAddString(handle, BootGetOptionName( &(gBootData[Index]) ) ); + } + return gBootOptionTokenArray[Index]; + + } + else + //If the call is not from _SpecialFixupBootOrder() + return HiiAddString(handle, BootGetOptionName( &(gBootData[Index]) ) ); +} +//EIP-48391: End + +//EIP70421 & 70422 Support for Driver Order starts +// +//------------------------------------------------------------------------------------------- +// Procedure: _GetSpecialDriveroptionToken +// +// Description: function to get the boot option token properly when loading the boot page +// +// Input: VOID* handle, UINTN Index +// +// Output: TOKEN +// +//------------------------------------------------------------------------------------------- +// +UINT16 _GetSpecialDriveroptionToken (VOID* handle, UINTN Index) +{ + UINTN i; + + if (gDriverPageHandle == handle) + { + if(FALSE == gSetupUpdated) + { + if (!gDriverOptionTokenCount) + { + // Create the gDriverOptionTokenArray + gDriverOptionTokenArray = EfiLibAllocateZeroPool (sizeof(UINT16) * gDriverOptionCount); + gDriverOptionTokenCount = gDriverOptionCount; + for (i = 0; i < gDriverOptionTokenCount; i ++) + { + gDriverOptionTokenArray [i] = INVALID_TOKEN; + } + } + else if (gDriverOptionTokenCount < gDriverOptionCount) + { // Drivers options added. Update gDriverOptionTokenArray + gDriverOptionTokenArray = MemReallocateZeroPool (gDriverOptionTokenArray, (sizeof (UINT16) * gDriverOptionTokenCount), (sizeof (UINT16) * gDriverOptionCount) ); + for (i = gDriverOptionTokenCount; i < gDriverOptionCount ; i ++) + { + gDriverOptionTokenArray [i] = INVALID_TOKEN; + } + gDriverOptionTokenCount = gDriverOptionCount; + } + + if (gDriverOptionTokenArray [Index] == INVALID_TOKEN) + gDriverOptionTokenArray [Index] = HiiAddString (handle, DriverGetOptionName (&(gDriverData [Index]) ) ); + else + { + // Check if Update is needed + CHAR16 *text; + text = HiiGetString( handle, gDriverOptionTokenArray [Index]); + if(EfiStrCmp(text, DriverGetOptionName ( &(gDriverData[Index]) )) != 0) + { + // need to update the token with new DriveroptionName. + UINT16 Token = HiiChangeString( handle, gDriverOptionTokenArray [Index], DriverGetOptionName( &(gDriverData[Index]) )); + if(Token != gDriverOptionTokenArray [Index]) + gDriverOptionTokenArray [Index] = Token; + } + MemFreePointer((VOID **)&text); + } + } + else { + //If the some control modified with respect to boot page.. + gDriverOptionTokenArray [Index] = HiiAddString (handle, DriverGetOptionName (&(gDriverData [Index]) ) ); + } + return gDriverOptionTokenArray [Index]; + + } + else + //If the call is not from _SpecialFixupBootOrder() + return HiiAddString(handle, DriverGetOptionName (&(gDriverData [Index]) ) ); +} +//EIP70421 & 70422 Support for Driver Order ends + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupBootOrder +// +// Description: function to fixup the Boot device order +// +// Input: CONTROL_INFO *control, +// UINT16 value +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupBootOrder (CONTROL_INFO *control, UINT16 value) +{ + VOID *tempPtr, *ifrPtr; + VOID *templatePtr, *oneOf; + UINTN i; + CHAR16 *text; + UINT8 length = 0; + UINT16 option = 0; + UINT8 flag = 0; + + ifrPtr = control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + //Create one one_of_option for each boot option + 1 for Disable option + tempPtr = UefiCreateOneOfWithOptionsTemplate (gBootOptionCount+1, control); + if ( tempPtr == NULL ) + return; + + templatePtr = ((UINT8*)ifrPtr + length); + oneOf = ((UINT8*)tempPtr + length); + length = UefiGetIfrLength(templatePtr); + +//EIP-48391: Start + gBootPageHandle = control->ControlHandle; //++ + for ( i = 0; i < gBootOptionCount; i++ ) { + flag = (i == value)? (UINT8)HiiGetDefaultMask() : 0; + //option = HiiAddString( control->ControlHandle, BootGetOptionName( &(gBootData[i]) ) ); // -- + //EIP:59417 - Checking the LOAD_OPTION_HIDDEN for the boot option + if (gLoadOptionHidden && (gBootData [i].Active & LOAD_OPTION_HIDDEN) ) + continue; + option = GetSpecialBootoptionToken (control->ControlHandle, i); + MemCopy (oneOf, templatePtr, length); + // Add one of option + UefiSetOneOfOption (oneOf, gBootData[i].Option, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + } +//EIP-48391: End + + //Create one of option for Disabled + flag = 0; + MemCopy (oneOf, templatePtr, length); + text = HiiGetString (gHiiHandle, STR_CTRL_CHKBOX_DISABLE); + option = HiiAddString (control->ControlHandle, text); + + //UefiSetOneOfOption (oneOf, 0xFFFF, BOOT_OPTION_SIZE, flag, option); //EIP-97704 BootFFFF + UefiSetOneOfOption (oneOf, DISABLED_BOOT_OPTION, BOOT_OPTION_SIZE, flag, option); + + MemFreePointer((VOID **)&text); + oneOf = (UINT8*)oneOf +length; + + // Add an End op to close scope of the One of control + UefiAddEndOp(oneOf); + + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField(ifrPtr); + + if(NoVarStoreSupport()) + { + VOID *ifrPtr; + UINT16 QuestionId; + + control->ControlVariable = VARIABLE_ID_BOOT_ORDER; + control->ControlConditionalVariable[0] = VARIABLE_ID_BOOT_MANAGER; + + ifrPtr = _SpecialGetIfrPtr( control, VARIABLE_ID_SETUP, NULL); + QuestionId = UefiGetEqIDQuestionID(ifrPtr); + QuestionId = QuestionId - GetNoVarStoreBootCountOffset(); + UefiSetEqIDQuestionID(ifrPtr, QuestionId); + } +} + +//EIP70421 & 70422 Support for driver order starts +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupDriverOrder +// +// Description: Function to fixup the driver order +// +// Input: CONTROL_INFO *control, +// UINT16 value +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupDriverOrder (CONTROL_INFO *control, UINT16 value) +{ + VOID *tempPtr, *ifrPtr; + VOID *templatePtr, *oneOf; + UINTN i; + CHAR16 *text; + UINT8 length = 0; + UINT16 option = 0; + UINT8 flag = 0; + + ifrPtr = control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + //Create one one_of_option for each driver option + 1 for Disable option + tempPtr = UefiCreateOneOfWithOptionsTemplate (gDriverOptionCount+1, control); + if (NULL == tempPtr) + return; + templatePtr = ((UINT8*)ifrPtr + length); + oneOf = ((UINT8*)tempPtr + length); + length = UefiGetIfrLength(templatePtr); + gDriverPageHandle = control->ControlHandle; + + for ( i = 0; i < gDriverOptionCount; i++ ) + { + flag = (i == value)? (UINT8)HiiGetDefaultMask() : 0; + if (gLoadOptionHidden && (gDriverData [i].Active & LOAD_OPTION_HIDDEN)) + continue; + option = _GetSpecialDriveroptionToken (control->ControlHandle, i); + MemCopy (oneOf, templatePtr, length); + // Add one of option + UefiSetOneOfOption (oneOf, gDriverData [i].Option, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + } + //Create one of option for Disabled + flag = 0; + MemCopy (oneOf, templatePtr, length); + text = HiiGetString (gHiiHandle, STR_CTRL_CHKBOX_DISABLE); + option = HiiAddString (control->ControlHandle, text); + + //UefiSetOneOfOption (oneOf, 0xFFFF, BOOT_OPTION_SIZE, flag, option); //EIP-97704 DriverFFFF + UefiSetOneOfOption (oneOf, DISABLED_DRIVER_OPTION, BOOT_OPTION_SIZE, flag, option); + + MemFreePointer((VOID **)&text); + oneOf = (UINT8*)oneOf +length; + + // Add an End op to close scope of the One of control + UefiAddEndOp(oneOf); + + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField(ifrPtr); +} +//EIP70421 & 70422 Support for driver order ends + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupBootCondition +// +// Description: This function updates the Condition to avoid more then one +// disabled option in Boot order. +// +// Input: ControlIndex, Control Info, PrevControlQuestionID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupBootCondition (UINT16 ControlIndex,CONTROL_INFO *control,UINT16 PrevControlQuestionID) +{ + // Don't Update the Condition for First option + if(!ControlIndex) + return; + else + { + UINT8 u8ChkResult = CheckControlCondition( control ); + if(u8ChkResult == COND_NONE) + { + VARIABLE_INFO *VarInfo; + VarInfo = VarGetVariableInfoIndex(control->ControlVariable); + if(NULL != VarInfo){//EIP-75352 Suppress the warnings from static code analyzer + UefiCreateDynamicControlCondition(control,(UINT16)VarInfo->VariableID,PrevControlQuestionID,DISABLED_BOOT_OPTION); + } + } + } + +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupBBSCondition +// +// Description: This function updates the Condition to avoid more then one +// disabled option in BBS Dev order. +// +// Input: ControlIndex, Control Info, PrevControlQuestionID +// +// Output: VOID +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupBBSCondition(UINT16 ControlIndex,CONTROL_INFO *control,UINT16 PrevControlQuestionID) +{ + // Don't Update the Condition for First option + if(!ControlIndex) + return; + else + { + UINT8 u8ChkResult = CheckControlCondition( control ); + if(u8ChkResult == COND_NONE) + { + VARIABLE_INFO *VarInfo; + VarInfo = VarGetVariableInfoIndex(control->ControlVariable); + if(NULL != VarInfo){//EIP-75352 Suppress the warnings from static code analyzer + UefiCreateDynamicControlCondition(control,(UINT16)VarInfo->VariableID,PrevControlQuestionID,DISABLED_BOOT_OPTION); + } + } + } + +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupBBSOrder +// +// Description: function to fixup the Legacy Boot device order +// +// Input: CONTROL_INFO *control, +// UINT16 value +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupBBSOrder( CONTROL_INFO *control, UINT16 value ) +{ + VOID *ifrPtr, *templatePtr, *oneOf, *tempPtr; + UINTN i; + UINT16 count,option; + UINT16 length = 0; + CHAR16 *text; + UINT8 flag; + + count = gCurrLegacyBootData->LegacyDevCount; + + ifrPtr = (VOID *)control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + //Create one one_of_option for each device + 1 for Disable option + tempPtr = UefiCreateOneOfWithOptionsTemplate(count + 1, control); + if ( tempPtr == NULL ) + return; + + + // set real offset into bbs variable for this control. + BBSUpdateControlOffset(control); + + templatePtr = (UINT8*)ifrPtr + length; + oneOf = (UINT8*)tempPtr + length; + length = UefiGetIfrLength(templatePtr); + + for ( i = 0; i < count; i++) + { + UINT16 bbsOptionVal = 0; + + MemCopy( oneOf, templatePtr, length ); + flag = (i == value)? (UINT8)HiiGetDefaultMask() : 0; + option = HiiAddString( control->ControlHandle, BBSGetOptionName( &bbsOptionVal,(UINT16)i ) ); + MemCopy( oneOf, templatePtr, length ); + // Add one of option + UefiSetOneOfOption(oneOf, bbsOptionVal, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + } + + //Create one of option for Disabled + flag = 0; + MemCopy( oneOf, templatePtr, length ); + text = HiiGetString(gHiiHandle,STR_CTRL_CHKBOX_DISABLE); + option = HiiAddString( control->ControlHandle, text ); + + //UefiSetOneOfOption(oneOf, 0xFFFF, BOOT_OPTION_SIZE, flag, option); //EIP-97704 BootFFFF + UefiSetOneOfOption(oneOf, DISABLED_BOOT_OPTION, BOOT_OPTION_SIZE, flag, option); + + MemFreePointer((VOID **)&text); + oneOf = (UINT8*)oneOf +length; + + // Add an End op to close scope of the One of control + UefiAddEndOp(oneOf); + + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField(ifrPtr); +} + +// +//---------------------------------------------------------------------------- +// Procedure: SpecialFixupDelBootOption +// +// Description: function to fixup the deletion of a boot device option +// +// Input: CONTROL_INFO *control, +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID SpecialFixupDelBootOption (CONTROL_INFO *control) +{ + VOID *ifrPtr, *templatePtr, *oneOf; + VOID *tempPtr; + UINTN i, length = 0; + + ifrPtr = (VOID *)control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + //Create one one_of_option for each boot option + 1 for Disable option + tempPtr = UefiCreateOneOfWithOptionsTemplate (gBootOptionCount + 1, control); + if ( tempPtr == NULL ) + return; + + templatePtr = (UINT8*)ifrPtr + length; + oneOf = (UINT8*)tempPtr + length; + length = UefiGetIfrLength (templatePtr); + + //Copy the first option and skip to next + MemCopy( oneOf, templatePtr, length ); + oneOf = (UINT8*)oneOf +length; + + for ( i = 0; i < gBootOptionCount; i++ ) + { + if( + ((gBootData[i].DevicePath->Type == BBS_DEVICE_PATH) && (gBootData[i].DevicePath->SubType == BBS_BBS_DP)) || + (gLoadOptionHidden && (gBootData [i].Active & LOAD_OPTION_HIDDEN)) + ) + { + continue; + } + else + { + UINT16 option = 0; + UINT8 flag = 0; + + MemCopy( oneOf, templatePtr, length ); + option = HiiAddString (control->ControlHandle, BootGetOptionName (&(gBootData[i]))); + // Add one of option + UefiSetOneOfOption (oneOf, gBootData[i].Option, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + } + } + + // Add an End op to close scope of the One of control + UefiAddEndOp (oneOf); + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField (ifrPtr); +} +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialFixupAddBootOption +// +// Description: function to fixup the adding of a boot device option +// +// Input: CONTROL_INFO *control, +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialFixupAddBootOption( CONTROL_INFO *control) +{ + VOID *ifrPtr, *templatePtr, *oneOf; + VOID *tempPtr; + UINTN i, length = 0; + + ifrPtr = (VOID *)control->ControlPtr; + length = UefiGetIfrLength(ifrPtr); + //Create one one_of_option for each file sys + tempPtr = UefiCreateOneOfWithOptionsTemplate( gFsCount, control ); + if ( tempPtr == NULL ) + return; + + UefiUpdateControlVarOffset(control, STRUCT_OFFSET(NEW_BOOT_OPTION, SelFs)); + + templatePtr = (UINT8*)ifrPtr + length; + oneOf = (UINT8*)tempPtr + length; + length = UefiGetIfrLength(templatePtr); + + for ( i = 0; i < gFsCount; i++) + { + UINT16 option = 0; + UINT8 flag = 0; + + MemCopy( oneOf, templatePtr, length ); + // Add one of option + option = HiiAddString( control->ControlHandle, gFsList[i].FsId); + UefiSetOneOfOption(oneOf, (UINT16)i, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + + } + + // Add an End op to close scope of the One of control + UefiAddEndOp(oneOf); + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField(ifrPtr); +} + +//EIP70421 & 70422 Support for driver order starts +// +//---------------------------------------------------------------------------- +// Procedure: SpecialFixupDelDriverOption +// +// Description: Function to fixup the deletion of a driver option +// +// Input: CONTROL_INFO *control, +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID SpecialFixupDelDriverOption (CONTROL_INFO *control) +{ + VOID *ifrPtr, *templatePtr, *oneOf; + VOID *tempPtr; + UINTN i, length = 0; + + ifrPtr = (VOID *)control->ControlPtr; + length = UefiGetIfrLength (ifrPtr); + //Create one one_of_option for each driver option + 1 for Disable option + tempPtr = UefiCreateOneOfWithOptionsTemplate (gDriverOptionCount + 1, control); + if (NULL == tempPtr) + return; + + templatePtr = (UINT8*)ifrPtr + length; + oneOf = (UINT8*)tempPtr + length; + length = UefiGetIfrLength (templatePtr); + + //Copy the first option and skip to next + MemCopy (oneOf, templatePtr, length); + oneOf = (UINT8*)oneOf +length; + + for (i = 0; i < gDriverOptionCount; i++) + { + if( + ((gDriverData [i].DevicePath->Type == BBS_DEVICE_PATH) && (gDriverData [i].DevicePath->SubType == BBS_BBS_DP)) || + (gLoadOptionHidden && (gDriverData [i].Active & LOAD_OPTION_HIDDEN)) + ) + { + continue; + } + else + { + UINT16 option = 0; + UINT8 flag = 0; + MemCopy (oneOf, templatePtr, length); + option = HiiAddString (control->ControlHandle, DriverGetOptionName (&(gDriverData [i]))); + // Add one of option + UefiSetOneOfOption (oneOf, gDriverData [i].Option, BOOT_OPTION_SIZE, flag, option); + oneOf = (UINT8*)oneOf +length; + } + } + // Add an End op to close scope of the One of control + UefiAddEndOp (oneOf); + ifrPtr = control->ControlPtr; + control->ControlHelp = UefiGetHelpField(ifrPtr); +} +//EIP70421 & 70422 Support for driver order ends + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialExplodeControl +// +// Description: function to explode a perticular contorller +// +// Input: FRAME_DATA *frame, +// CONTROL_INFO *ctrlData, +// BOOLEAN *SetFocus +// +// Output: control Value +// +//---------------------------------------------------------------------------- +// +INT16 _SpecialExplodeControl( FRAME_DATA *frame, CONTROL_INFO *ctrlData, BOOLEAN *SetFocus ) +{ + UINT16 value; + GUID_INFO *guidInfo; + + value = _SpecialGetValue( ctrlData, &guidInfo ); + if ( value == (UINT16)-1 ) + _SpecialAddMultipleControls( frame,ctrlData, guidInfo, SetFocus ); + + return value; +} + +// +//---------------------------------------------------------------------------- +// Procedure: _SpecialControlExtras +// +// Description: special handling of extra operations +// +// Input: CONTROL_DATA *ctrlData +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID _SpecialControlExtras(CONTROL_DATA *ctrlData) +{ + GUID_INFO *guidInfo = NULL; + UINT16 token = 0; + + UINT16 value = _SpecialGetValue( &ctrlData->ControlData, &guidInfo ); + if ( value != (UINT16)-2 ) + { + switch(ctrlData->ControlData.ControlType) + { + case CONTROL_TYPE_SUBMENU:// submenu control + if (guidInfo->GuidKey != GUID_KEY_ADD_BOOT_OPTION)//EIP-79955 To draw GEOMETRICSHAPE_RIGHT_TRIANGLE for AddBootOption + ((SUBMENU_DATA*)ctrlData)->SubMenuType = 2; + if (guidInfo->GuidKey == GUID_KEY_BOOT_NOW) + { +///EIP - 24971 + token = HiiAddString( ctrlData->ControlData.ControlHandle, BootGetBootNowName(value,gShowAllBbsDev,BootNowInBootOrderSupport())); +///EIP - 24971 + //Update the submenu prompt field. + UefiSetPromptField(ctrlData->ControlData.ControlPtr, token); + } + else if ( guidInfo->GuidKey == GUID_KEY_ERROR_MANAGER ) + { + UINTN size = 0; + ERROR_MANAGER *errManager = VarGetNvram( VARIABLE_ID_ERROR_MANAGER, &size ); + + if ( ( errManager != NULL ) && ( value < errManager->ErrorCount ) ) + { + ERROR_LIST *errList = &(errManager->ErrorList[value]); + + // Update the submenu prompt field. + UefiSetPromptField(ctrlData->ControlData.ControlPtr, errList->Summary); + ctrlData->ControlData.ControlHelp = errList->DetailInfo; + ctrlData->ControlData.ControlHandle = (VOID*)errList->Handle; + MemFreePointer( (VOID **)&errManager ); + } + } + else if (guidInfo->GuidKey == GUID_KEY_DYNAMIC_PAGE) + { + UINTN i = 0,j; + UINTN Index=0; + PAGE_INFO *pageInfo; + PAGE_INFO *tmppageInfo; + PAGE_DATA **page; + + //EIP 78627: To maintain consistency, show arrow when displaying submenu (SubMenuType=0). + ((SUBMENU_DATA*)ctrlData)->SubMenuType = 0; + + //Scan for dynamic pages + for(i = 0; i < gPages->PageCount; i++) + { + pageInfo = (PAGE_INFO *)((UINTN)gApplicationData + gPages->PageList[i]); + + + if((pageInfo->PageFlags.PageDynamic == TRUE) && (pageInfo->PageHandle != NULL)) + { + if(Index == value) + { + + CHAR16 *text; + UINT16 Title=0, Help=0 ; + + // Get Formset Title and Help for Dynamic page + GetFormSetTitleAndHelpWrapper (pageInfo->PageHandle, &Title, &Help); + + // Add the Prompt + text = HiiGetString( pageInfo->PageHandle, pageInfo->PageSubTitle); + token = HiiAddString( ctrlData->ControlData.ControlHandle, text); + UefiSetPromptField(ctrlData->ControlData.ControlPtr, token); + + //EIP# 72333, Display Formset Help for Dynamic page + if(Help != 0) + { + MemFreePointer( (VOID **)&text ); + text = HiiGetString( pageInfo->PageHandle, Help); + token = HiiAddString( ctrlData->ControlData.ControlHandle, text); + UefiSetHelpField(ctrlData->ControlData.ControlPtr, token); + ctrlData->ControlData.ControlHelp = token ; + }//EIP# 72333 End + + // Fix the parent pageID + ctrlData->ControlData.ControlDestPageID = pageInfo->PageID ; + pageInfo->PageParentID = gApp->CurrentPage; + gDynamicParentPage = gApp->CurrentPage; + // Reinitilize the Page. + for(j = i; j < gPages->PageCount; j++) + { + tmppageInfo = (PAGE_INFO *)((UINTN)gApplicationData + gPages->PageList[j]); + if(pageInfo->PageHandle == tmppageInfo->PageHandle ) + { + page = &gApp->PageList[tmppageInfo->PageID]; + gPage.Destroy( *page, FALSE ); + gPage.Initialize( *page, tmppageInfo ); + } + } + MemFreePointer( (VOID **)&text ); + } + Index++; + } + } + + } + else if (guidInfo->GuidKey == GUID_KEY_IDE_SECURITY) + { + CHAR16 *text; + UINT16 IDEStrToken = TSEIDEPasswordGetName(value); + + + if(IDEStrToken) + { + UINTN size; + IDE_SECURITY_CONFIG *ideSecConfig; + size = 0; + //Update mem copy of the IDE sec variable + ideSecConfig = VarGetVariable( VARIABLE_ID_IDE_SECURITY, &size ); + if (NULL == ideSecConfig) { + break; + } + TSEIDEUpdateConfig(ideSecConfig, value); + VarSetValue( VARIABLE_ID_IDE_SECURITY, 0, size, ideSecConfig ); //EIP-83704 to update VARIABLE_ID_IDE_SECURITY variable when HDD is frozen in setup + MemFreePointer((VOID **)&ideSecConfig); + + //VarUpdateVariable (VARIABLE_ID_IDE_SECURITY); + text = HiiGetString( gHiiHandle, IDEStrToken); + token = HiiAddString( ctrlData->ControlData.ControlHandle, text); + //Update the submenu prompt field. + UefiSetPromptField(ctrlData->ControlData.ControlPtr, token); + MemFreePointer( (VOID **)&text ); + } + } +#if SETUP_OEM_SPECIAL_CONTROL_SUPPORT + else if ( guidInfo->GuidKey == GUID_KEY_OEM_CONTROL ) + { + OEMSpecialGotoFixup(&ctrlData->ControlData,value); + } +#endif +/**/ + else if (guidInfo->GuidKey == GUID_KEY_BBS_ORDER) + { + CHAR16 *text = NULL; + UINTN i,j; + BOOT_DATA *bootData; + + for(i=0,j=0; iActive & LOAD_OPTION_HIDDEN)) + continue; + + if ( BBSValidDevicePath(bootData->DevicePath) ) + { + if(value == j) + { + BBS_BBS_DEVICE_PATH *DevPath = (BBS_BBS_DEVICE_PATH *)bootData->DevicePath; + + switch(DevPath->DeviceType) + { + case BBS_TYPE_FLOPPY: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_FLOPPY_DISK_ORDER)); + break; + case BBS_TYPE_HARDDRIVE: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_HARD_DISK_ORDER)); + break; + case BBS_TYPE_CDROM: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_CDROM_ORDER)); + break; + + case BBS_TYPE_PCMCIA: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_PCMCIA_ORDER)); + break; + + case BBS_TYPE_USB: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_USB_ORDER)); + break; + + case BBS_TYPE_EMBEDDED_NETWORK: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_NETWORK_ORDER)); + break; + case BBS_TYPE_DEV: + text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_BEV_ORDER)); + break; + default: + /// EIP-42520: Updated to get the BBS group type from the Board module in case of a non standard type. + text = HiiGetString( gHiiHandle, BBSGetNonStandardGroupType(DevPath->DeviceType)); + break; + } + + token = HiiAddString( ctrlData->ControlData.ControlHandle, text); + //Update the submenu prompt field. + UefiSetPromptField(ctrlData->ControlData.ControlPtr, token); + + MemFreePointer( (VOID **)&text ); + + break; + } + j++; + } + } + } + else if (GUID_KEY_DRIVER_HEALTH == guidInfo->GuidKey) + { + CHAR16 *text; + ((SUBMENU_DATA*)ctrlData)->SubMenuType = 0; //EIP100099 showing submenu triangle + text = FindDriverHealthDriverName (value); + if (NULL != text) + { + token = HiiAddString (ctrlData->ControlData.ControlHandle, text); + UefiSetPromptField (ctrlData->ControlData.ControlPtr, token); + } + } + else if (GUID_KEY_DRV_HEALTH_CTRL_COUNT == guidInfo->GuidKey) + { + CHAR16 *text; + text = GetCtrlNameAndHealth (value); + if (NULL != text) + { + token = HiiAddString (ctrlData->ControlData.ControlHandle, text); + UefiSetPromptField (ctrlData->ControlData.ControlPtr, token); + } + } + else if (GUID_KEY_DRIVER_HEALTH_ENB == guidInfo->GuidKey) + { + ((SUBMENU_DATA*)ctrlData)->SubMenuType = 0; //EIP100099 showing submenu triangle + } + break; + default: + break; + } + } +} + +// +//---------------------------------------------------------------------------- +// Procedure: SpecialUpdatePageControls +// +// Description: special fucntion to update the page controls +// +// Input: UINT32 CurrentPage +// +// Output: None +// +//---------------------------------------------------------------------------- +// +VOID SpecialUpdatePageControls(UINT32 CurrentPage) +{ + PAGE_INFO *thisPage; + UINT16 i=MAIN_FRAME,j=0, k=0; + INT16 Value=0; + CONTROL_INFO *control; + CONTROL_DATA **ControlData; + CONTROL_INFO *ControlInfo; + GUID_INFO *guidInfo; + FRAME_DATA *fdata; + BOOLEAN ExitUpdate=FALSE, SetFocus =TRUE; +//Fix EIP:18142 - start + UINT32 tmpControlCount,tmpCurrentControl,tmpFirstVisibleCtrl; +//Fix EIP:18142 - end + + i = (UINT16) StyleFrameIndexOf(MAIN_FRAME) ; + thisPage = (PAGE_INFO*)((UINTN)gApplicationData + gPages->PageList[CurrentPage]); + // find if controls in page need to be exploded + // i=0; + //while(i< thisPage->FrameCount ) + //{ + // for now search main frame only, if needed uncomment code above to do this for all frames in page + for(j=0;j < thisPage->PageControls.ControlCount;j++) + { + control = (CONTROL_INFO*)((UINT8 *)(gControlInfo) + thisPage->PageControls.ControlList[j]); + + switch( _SpecialGetValue( control, &guidInfo )) + { + case (UINT16)-2: + break; + default: + // special case, need to reinitialize this frame + //pdata = (PAGE_DATA*)gApp->PageList[CurrentPage]; + fdata = ((PAGE_DATA*)gApp->PageList[CurrentPage])->FrameList[i]; + //clist = ((PAGE_DATA*)gApp->PageList[CurrentPage])->FrameList[i]->ControlList; + ControlData = ((PAGE_DATA*)gApp->PageList[CurrentPage])->FrameList[i]->ControlList; + +//Fix EIP:18142 - Start + tmpControlCount = fdata->ControlCount; + tmpCurrentControl = fdata->CurrentControl; + tmpFirstVisibleCtrl = fdata->FirstVisibleCtrl; +//Fix EIP:18142 - End + for ( k = 0; k < fdata/*gApp->PageList[CurrentPage]->FrameList[i]*/->ControlCount; k++, ControlData++ ) + (*ControlData)->Methods->Destroy( *ControlData, TRUE ); + + fdata/*gApp->PageList[CurrentPage]->FrameList[i]*/->ControlCount =0; + fdata/*gApp->PageList[CurrentPage]->FrameList[i]*/->CurrentControl =0; + fdata/*gApp->PageList[CurrentPage]->FrameList[i]*/->NullCount =0; + fdata->FirstVisibleCtrl = 0; + + // loop for al acontrols to either add it "as is" or explode it + for ( k = 0; k < thisPage->PageControls.ControlCount; k++ ) + { + ControlInfo = (CONTROL_INFO*)((UINT8 *)gControlInfo + (UINT32)thisPage->PageControls.ControlList[k]); + switch(Value=_SpecialExplodeControl(fdata,ControlInfo, &SetFocus)) + { + case -1: + break; + default: + if( _SpecialAddControl(fdata,ControlInfo, &SetFocus ) == EFI_SUCCESS) //EIP-34679: Typo error fix + _SpecialControlExtras((fdata->ControlList[fdata->ControlCount-1])); + break; + } + + } +//Fix EIP:18142 - Start +// To retains the Control Focues in page with has special control +// If the control count is different the we will focus to first control as we don't know +// What is added or missing. + if(fdata->ControlCount == tmpControlCount) + { + fdata->CurrentControl=tmpCurrentControl; + fdata->FirstVisibleCtrl=tmpFirstVisibleCtrl; + _FrameSetControlFocus( fdata, tmpCurrentControl ); + } +//Fix EIP:18142 - End + + ExitUpdate =TRUE; + break; + } + if(ExitUpdate) + break; + } + //} +} +//#endif + +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2014, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// diff --git a/EDK/MiniSetup/TseAdvanced/special.h b/EDK/MiniSetup/TseAdvanced/special.h new file mode 100644 index 0000000..ef54db3 --- /dev/null +++ b/EDK/MiniSetup/TseAdvanced/special.h @@ -0,0 +1,196 @@ +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +//** **// +//** (C)Copyright 2010, American Megatrends, Inc. **// +//** **// +//** All Rights Reserved. **// +//** **// +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// +//** **// +//** Phone (770)-246-8600 **// +//** **// +//*****************************************************************// +//*****************************************************************// +//*****************************************************************// +// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/special.h $ +// +// $Author: Arunsb $ +// +// $Revision: 9 $ +// +// $Date: 10/18/12 5:53a $ +// +//*****************************************************************// +//*****************************************************************// +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/special.h $ +// +// 9 10/18/12 5:53a Arunsb +// Updated for 2.16.1235 QA submission +// +// 7 10/10/12 12:35p Arunsb +// Synched the source for v2.16.1232, backup with Aptio +// +// 8 1/30/12 1:27a Arunsb +// [TAG] EIP74676 +// [Category] Improvement +// [Description] Setup.ini and Upfisetup.ini to reserve 3~5 variable and +// GUID for porting purpose +// [Files] Amivfr.h, special.h, variable.h, Uefisetup.ini and setup.ini +// +// 7 11/13/11 12:39p Arunsb +// [TAG] EIP70421 +// [Category] New Feature +// [Description] Support for driver order in TSE +// [Files] AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini, +// boot.c, +// minisetup.h, bbs.c, special.c, special.h, tseadvanced.c, +// addbootoption.c, +// callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h, +// TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h, +// TseElink.h, variable.h, +// setup.h, Boot.vfr and Setup.uni +// +// 6 6/30/11 4:13a Arunsb +// [TAG] EIP57661 +// [Category] New Feature +// [Description] Boot manager algorithm for interaction with Driver +// Health protocol. +// Guid key added. +// [Files] amitse.cif, amitse.sdl, faketokens.c, amitsestr.uni, +// commonhelper.c, uefisetup.ini, tsedrvhealth.h, +// amivfr.h, minisetupbin.mak, +// hiistring21.c, hiistring20.c, tseadvanced.c, special.c, +// special.h, boot.h, minisetup.h, +// uefi20wapper.c, formbrowser2.c, hii.c, parse.c and +// uefi21wapper.c. +// +// 5 2/10/11 12:32p Blaines +// [TAG] - EIP 53146 +// [Category]- New Feature +// [Description] -Add the support to Move the Dynamic IFR Pages under +// subpages. It should be customizable to move around. +// +// 4 2/19/10 1:02p Madhans +// Updated for TSE 2.01. Refer Changelog.log for File change history. +// +// 5 2/19/10 8:12a Mallikarjunanv +// updated year in copyright message +// +// 4 9/15/09 9:38a Sudhirv +// added definition GUID_KEY_OEM_CONTROL +// +// 3 6/16/09 2:16p Presannar +// Added File Headers for Header Files +// +// 2 6/12/09 7:43p Presannar +// Initial implementation of coding standards for AMITSE2.0 +// +// 1 6/04/09 8:05p Madhans +// +// 1 4/28/09 11:16p Madhans +// Tse 2.0 Code complete Checkin. +// +// 1 4/28/09 10:27p Madhans +// Tse 2.0 Code complete Checkin. +// +// 11 10/24/07 11:23a Arunkumars +// - Moved IDE security code to binary +// - Fixed build errors under UGA draw support +// - Added EFI key password support +// - Added modifier hot key support +// - Added popup support in From browser protocol +// +// 10 1/25/07 11:06a Arunkumars +// Fixed StringWrapText function to consider words longer than width. +// Added code to correct LegacyDevOrder upon entry. +// BootOrder now has all the options and only enabled ones are booted by +// boot manager +// +// 9 1/09/07 10:15a Arunkumars +// Enable/Disable of boot/bbs option support +// Add/Del of boot option support +// +// 8 10/03/06 11:26a Natalyak +// IDE Security support +// +// 7 9/27/05 10:02p Franklynd +// Updates to BBS order capability. +// +// 6 8/01/05 4:15p Franklynd +// 1-Update boot manager and boot options pages at runtime. with latest +// boot information. +// +// 2- PopupSel using less space. +// +// +// 5 7/19/05 3:44p Jerryp +// Language fixes +// +// 4 6/27/05 2:59p Jerryp +// Support for dynamic expansion +// +// 3 6/24/05 7:35p Jerryp +// +// 2 6/24/05 10:17a Jerryp +// Added ErrorManager handling +// +// 1 5/27/05 10:24a Jerryp +// Special handling for OEM packs +// +//*****************************************************************// +//*****************************************************************// +// +//---------------------------------------------------------------------------- +// +// Name: Special.h +// +// Description: Header file for TSE special controls like AMI callback controls +// +// +//---------------------------------------------------------------------------- +// +#ifndef _SPECIAL_H_ +#define _SPECIAL_H_ + +#define GUID_KEY_BOOT_NOW 0x0001 +#define GUID_KEY_AMI_CALLBACK 0x0002 +#define GUID_KEY_ERROR_MANAGER 0x0003 +#define GUID_KEY_LANG_CODES 0x0005 +#define GUID_KEY_BBS_ORDER 0x0007 +#define GUID_KEY_IDE_SECURITY 0x0008 +#define GUID_KEY_ADD_BOOT_OPTION 0x0009 +#define GUID_KEY_OEM_CONTROL 0x000A +#define GUID_KEY_MODAL 0x000B +#define GUID_KEY_REFRESH 0x000C +#define GUID_KEY_NO_COMMIT 0x000D +#define GUID_KEY_DYNAMIC_PAGE 0x000E +#define GUID_KEY_DRIVER_HEALTH_ENB 0x000F +#define GUID_KEY_DRIVER_HEALTH 0x0010 +#define GUID_KEY_DRV_HEALTH_CTRL_COUNT 0x0011 +#define GUID_KEY_DRIVER_OPTION 0x0012 //EIP70421 & 70422 Support for driver order +#define GUID_KEY_OEMGUID1 0x0013 //EIP74676 guids for porting purpose +#define GUID_KEY_OEMGUID2 0x0014 + + +UINT16 SpecialGetValue( CONTROL_DATA *control, GUID_INFO **guidInfo ); +VOID SpecialAddMultipleControls( CONTROL_INFO *controlInfo, GUID_INFO *guidInfo ); +VOID SpecialUpdatePageControls(UINT32 CurrentPage); + +#endif /* _SPECIAL_H_ */ + +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//********************************************************************** -- cgit v1.2.3