diff options
author | lijuang <lijuang@codeaurora.org> | 2016-07-27 19:31:04 +0800 |
---|---|---|
committer | lijuang <lijuang@codeaurora.org> | 2016-08-10 16:27:42 +0800 |
commit | 593d735a0b1f249f648622a8ccff63f362792471 (patch) | |
tree | a33b91115a638c84be4a2376281bece9da9967fe | |
parent | 463e3cb21296547fc6af374c5b349378aa9a28e7 (diff) |
QcomModulePkg: Add support for verified boot menu
Add functions to draw verified boot menu
CRs-Fixed: 1042864
Change-Id: I3c7f301e688cf4b658207dfb34626b1c64eacebf
-rw-r--r-- | QcomModulePkg/Include/Library/VerifiedBootMenu.h | 45 | ||||
-rw-r--r-- | QcomModulePkg/Library/BootLib/BootLib.inf | 1 | ||||
-rw-r--r-- | QcomModulePkg/Library/BootLib/VerifiedBootMenu.c | 241 |
3 files changed, 287 insertions, 0 deletions
diff --git a/QcomModulePkg/Include/Library/VerifiedBootMenu.h b/QcomModulePkg/Include/Library/VerifiedBootMenu.h new file mode 100644 index 0000000000..bbab66cab2 --- /dev/null +++ b/QcomModulePkg/Include/Library/VerifiedBootMenu.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _VERIFIEDBOOTMENU_H_ +#define _VERIFIEDBOOTMENU_H_ + +#include <DrawUI.h> + +#if VERIFIED_BOOT +VOID DisplayVerifiedBootMenu(INTN Type); +VOID VerifiedBootOptionMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo); +VOID VerifiedBootMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo, INTN Type); +#else +STATIC inline VOID DisplayVerifiedBootMenu(UINT32 type) {} +STATIC inline VOID VerifiedBootOptionMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo) {} +STATIC inline VOID VerifiedBootMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo, INTN Type) {} +#endif + +#endif diff --git a/QcomModulePkg/Library/BootLib/BootLib.inf b/QcomModulePkg/Library/BootLib/BootLib.inf index b0008226c2..881655f175 100644 --- a/QcomModulePkg/Library/BootLib/BootLib.inf +++ b/QcomModulePkg/Library/BootLib/BootLib.inf @@ -55,6 +55,7 @@ MenuKeysDetection.c UnlockMenu.c FastbootMenu.c + VerifiedBootMenu.c [Packages] ArmPkg/ArmPkg.dec diff --git a/QcomModulePkg/Library/BootLib/VerifiedBootMenu.c b/QcomModulePkg/Library/BootLib/VerifiedBootMenu.c new file mode 100644 index 0000000000..b9114abe41 --- /dev/null +++ b/QcomModulePkg/Library/BootLib/VerifiedBootMenu.c @@ -0,0 +1,241 @@ +/* Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiHiiServicesLib.h> +#include <Library/DeviceInfo.h> +#include <Library/DrawUI.h> +#include <Library/UnlockMenu.h> +#include <Library/MenuKeysDetection.h> +#include <Library/UpdateDeviceTree.h> +#include <Protocol/EFIVerifiedBoot.h> + +#define VERIFIED_BOOT_OPTION_NUM 5 +STATIC OPTION_MENU_INFO gMenuInfo; + +typedef struct { + MENU_MSG_INFO WarningMsg; + MENU_MSG_INFO UrlMsg; + MENU_MSG_INFO Fingerprint; + MENU_MSG_INFO CommonMsg; +} WARNING_COMMON_MSG_INFO; + +STATIC MENU_MSG_INFO mTitleMsgInfo[] = { + {{"Start >"}, + BIG_FACTOR, BGR_WHITE, BGR_BLACK, ALIGN_RIGHT, 0, NOACTION}, + {{"Continue boot\n"}, + COMMON_FACTOR, BGR_SILVER, BGR_BLACK, ALIGN_RIGHT, 0, NOACTION}, + {{"< More options"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"Press VOLUME keys\n\n"}, + COMMON_FACTOR, BGR_SILVER, BGR_BLACK, COMMON, 0, NOACTION}, +}; + +STATIC WARNING_COMMON_MSG_INFO mCommonMsgInfo[] = { + [DISPLAY_MENU_YELLOW] = { + {{"Your device has loaded a different operating system\n\n"\ + "Visit this link on another device:\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"g.co/ABH\n\n"}, + COMMON_FACTOR, BGR_YELLOW, BGR_BLACK, COMMON, 0, NOACTION}, + {{""},COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"If no key pressed:\nYour device will boot in 5 seconds\n\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}}, + [DISPLAY_MENU_ORANGE] = { + {{"Your device software can't be checked for corruption. "\ + "Please lock the bootloader\n\n"\ + "Visit this link on another device:\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"g.co/ABH\n\n"}, + COMMON_FACTOR, BGR_ORANGE, BGR_BLACK, COMMON, 0, NOACTION}, + {NULL}, + {{"If no key pressed:\nYour device will boot in 5 seconds\n\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}}, + [DISPLAY_MENU_RED] = { + {{"Your device is corrupt. It can't be trusted and will not boot\n\n"\ + "Visit this link on another device:\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"g.co/ABH\n\n"}, + COMMON_FACTOR, BGR_RED, BGR_BLACK, COMMON, 0, NOACTION}, + {NULL}, + {{"If no key pressed:\nYour device will boot in 5 seconds\n\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}}, + [DISPLAY_MENU_LOGGING] = { + {{"The dm-verity is not started in enforcing mode and may "\ + "not work properly\n\n"\ + "Visit this link on another device:\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"g.co/ABH\n\n"}, + COMMON_FACTOR, BGR_RED, BGR_BLACK, COMMON, 0, NOACTION}, + {NULL}, + {{"If no key pressed:\nYour device will boot in 5 seconds\n\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}}, +}; + +STATIC MENU_MSG_INFO mOptionMenuMsgInfo[] = { + {{"Options menu:\n"}, + BIG_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"\nPress volume key to select, and press power key to select\n\n"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, COMMON, 0, NOACTION}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, + {{"Power off"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, OPTION_ITEM, 0, POWEROFF}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, + {{"Restart"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, OPTION_ITEM, 0, RESTART}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, + {{"Recovery"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, OPTION_ITEM, 0, RECOVER}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, + {{"Fastboot"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, OPTION_ITEM, 0, FASTBOOT}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, + {{"Back to previous page"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, OPTION_ITEM, 0, BACK}, + {{"____________________"}, + COMMON_FACTOR, BGR_WHITE, BGR_BLACK, LINEATION, 0, NOACTION}, +}; + +/** + Draw the verified boot option menu + @param[out] OptionMenuInfo The option info + **/ +VOID VerifiedBootOptionMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo) +{ + UINT32 Location = 0; + UINT32 Height = 0; + UINT32 i = 0; + UINT32 j = 0; + + /* Clear the screen before launch the verified boot option menu */ + gST->ConOut->ClearScreen (gST->ConOut); + ZeroMem(&OptionMenuInfo->Info, sizeof(MENU_OPTION_ITEM_INFO)); + + OptionMenuInfo->Info.MsgInfo = mOptionMenuMsgInfo; + for (i = 0; i < ARRAY_SIZE(mOptionMenuMsgInfo); i++) { + if (OptionMenuInfo->Info.MsgInfo[i].Attribute == OPTION_ITEM) { + if (j < VERIFIED_BOOT_OPTION_NUM) { + OptionMenuInfo->Info.OptionItems[j] = i; + j++; + } + } + OptionMenuInfo->Info.MsgInfo[i].Location = Location; + DrawMenu(&OptionMenuInfo->Info.MsgInfo[i], &Height); + Location += Height; + } + + OptionMenuInfo->Info.MenuType = DISPLAY_MENU_MORE_OPTION; + OptionMenuInfo->Info.OptionNum = VERIFIED_BOOT_OPTION_NUM; + + /* Initialize the option index */ + OptionMenuInfo->Info.OptionIndex = VERIFIED_BOOT_OPTION_NUM; +} + +/** + Draw the verified boot menu + @param[in] Type The warning menu type + @param[out] OptionMenuInfo The option info + **/ +VOID VerifiedBootMenuShowScreen(OPTION_MENU_INFO *OptionMenuInfo, + INTN Type) +{ + UINT32 Location = 0; + UINT32 Height = 0; + UINT32 URLFgColor = 0; + UINT32 i = 0; + + /* Clear the screen before launch the verified boot menu */ + gST->ConOut->ClearScreen (gST->ConOut); + ZeroMem(&OptionMenuInfo->Info, sizeof(MENU_OPTION_ITEM_INFO)); + + for (i = 0; i < ARRAY_SIZE(mTitleMsgInfo); i++) { + mTitleMsgInfo[i].Location = Location; + DrawMenu(&mTitleMsgInfo[i], &Height); + Location += Height; + } + + mCommonMsgInfo[Type].WarningMsg.Location = Location; + DrawMenu(&mCommonMsgInfo[Type].WarningMsg, &Height); + Location += Height; + + mCommonMsgInfo[Type].UrlMsg.Location = Location; + DrawMenu(&mCommonMsgInfo[Type].UrlMsg, &Height); + Location += Height; + + if (Type == DISPLAY_MENU_YELLOW) { + mCommonMsgInfo[Type].Fingerprint.Location = Location; + AsciiSPrint(mCommonMsgInfo[Type].Fingerprint.Msg, + MAX_MSG_SIZE, "ID: %a\n", "unsupported"); + DrawMenu(&mCommonMsgInfo[Type].Fingerprint, &Height); + Location += Height; + } + + mCommonMsgInfo[Type].CommonMsg.Location = Location; + DrawMenu(&mCommonMsgInfo[Type].CommonMsg, &Height); + Location += Height; + + OptionMenuInfo->Info.MenuType = Type; + /* Initialize the time out time: 5s */ + OptionMenuInfo->Info.TimeoutTime = 5; +} + +/** + Draw the verified boot menu and start to detect the key's status + @param[in] Type The type of the warning menu: + [DISPLAY_MENU_YELLOW] ----- Yellow warning menu + [DISPLAY_MENU_ORANGE] ----- Orange warning menu + [DISPLAY_MENU_RED] ----- Red warning menu + [DISPLAY_MENU_LOGGING] ----- Logging warning menu +**/ +VOID DisplayVerifiedBootMenu(INTN Type) +{ + OPTION_MENU_INFO *OptionMenuInfo; + OptionMenuInfo = &gMenuInfo; + + if (FixedPcdGetBool(EnableDisplayMenu)) { + /* Initialize the last_msg_type */ + OptionMenuInfo->LastMenuType = + OptionMenuInfo->Info.MenuType; + + VerifiedBootMenuShowScreen(OptionMenuInfo, Type); + + MenuKeysDetectionInit(OptionMenuInfo); + DEBUG((EFI_D_INFO, "Creating boot verify keys detect event\n")); + } else { + DEBUG((EFI_D_INFO, "Display menu is not enabled!\n")); + } +} |