From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::244; helo=mail-pg0-x244.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9E335226CD63E for ; Sun, 22 Apr 2018 23:22:12 -0700 (PDT) Received: by mail-pg0-x244.google.com with SMTP id i29so6163863pgn.12 for ; Sun, 22 Apr 2018 23:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2oGz7se8Gs55Anf7Y/r9y2yNCg2AXWcg/IfkLB0lMq4=; b=MBXP3x+Seqahv00GknPyweYqaryVcXE6R3KBrIkQSsq+mM+2cZOmNi9crkQB4wCmEq SyBPSmKoh/KXsLUUDvXJD9w44Xo1N5FqDQFXgu/lMKVNB7esnGvMdzT6udn3hG4AOQI2 c8cUMRdK5v6j4LTuBIHywmwYbvfd9oABJDVfE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2oGz7se8Gs55Anf7Y/r9y2yNCg2AXWcg/IfkLB0lMq4=; b=KqrGH+bxDYqF8NJqJUvUcznY1gwc2+w3A5B3e+8M1+SW4vOZN5tjq81133B2zvhmQr ezU9yfjT9m5HvbRQYQYSOdR56FLivX/GnPKRL8YVyH+7niYh+qusUsEbXdaVVMUpRCZ3 OIDgqeokD5ATy6P20SY6c44lQeb4wZe06ie16ZxF8pa1M5ixHA3GaJ98uv4jMJa6za06 EH4rhfrBKy/T1utSMh6Tk+iJi1wVfNDabR9/ih9+Zi63Z/W2AO02+VMvRZ2j3DV/ZBhw 1bfuuHHZ25WICpLeC3faSzT3SlZ6Qb19PTg9fzWlkS0kddODqxSVfaLAGN0jFbVzttRz U1Ew== X-Gm-Message-State: ALQs6tDWL62lCjRKXc2qtR5RlCOSvBXKSRvRnh9EchKxG5r/9YCbcPM3 Y3je+fucDUw2VUNF6TM4tor0nh9VZRk= X-Google-Smtp-Source: AIpwx4+9j8rNiPI1F8ySOY6RpeQDnH6t9XuwztCZNPBG+Ge1JmEZ2ZabUQGPVFrpbJRBDzRA3UM2+Q== X-Received: by 10.99.123.17 with SMTP id w17mr15940503pgc.8.1524464531897; Sun, 22 Apr 2018 23:22:11 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.101]) by smtp.gmail.com with ESMTPSA id u4sm8258771pfn.3.2018.04.22.23.22.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 23:22:10 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Cc: Haojian Zhuang , Laszlo Ersek , Leif Lindholm , Ard Biesheuvel Date: Mon, 23 Apr 2018 14:21:54 +0800 Message-Id: <1524464514-14454-3-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524464514-14454-1-git-send-email-haojian.zhuang@linaro.org> References: <1524464514-14454-1-git-send-email-haojian.zhuang@linaro.org> Subject: [PATCH v4 2/2] ArmPkg/PlatformBootManagerLib: load platform boot options X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Apr 2018 06:22:12 -0000 Make platform driver to create predefined boot options and related hot keys. Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 103 +++++++++++++++++++++ .../PlatformBootManagerLib.inf | 2 + 2 files changed, 105 insertions(+) diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c index 61ab61ccc780..3456a71fbb9c 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -392,6 +393,106 @@ PlatformRegisterFvBootOption ( STATIC VOID +GetPlatformOptions ( + VOID + ) +{ + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION *CurrentBootOptions; + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + EFI_INPUT_KEY *BootKeys; + PLATFORM_BOOT_MANAGER_PROTOCOL *PlatformBootManager; + UINTN CurrentBootOptionCount; + UINTN Index; + UINTN BootCount; + + Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL, + (VOID **)&PlatformBootManager); + if (EFI_ERROR (Status)) { + return; + } + Status = PlatformBootManager->GetPlatformBootOptionsAndKeys ( + &BootCount, + &BootOptions, + &BootKeys + ); + if (EFI_ERROR (Status)) { + return; + } + // + // Fetch the existent boot options. If there are none, CurrentBootCount + // will be zeroed. + // + CurrentBootOptions = EfiBootManagerGetLoadOptions ( + &CurrentBootOptionCount, + LoadOptionTypeBoot + ); + // + // Process the platform boot options. + // + for (Index = 0; Index < BootCount; Index++) { + INTN Match; + UINTN BootOptionNumber; + + // + // If there are any preexistent boot options, and the subject platform boot + // option is already among them, then don't try to add it. Just get its + // assigned boot option number so we can associate a hotkey with it. Note + // that EfiBootManagerFindLoadOption() deals fine with (CurrentBootOptions + // == NULL) if (CurrentBootCount == 0). + // + Match = EfiBootManagerFindLoadOption ( + &BootOptions[Index], + CurrentBootOptions, + CurrentBootOptionCount + ); + if (Match >= 0) { + BootOptionNumber = CurrentBootOptions[Match].OptionNumber; + } else { + // + // Add the platform boot options as a new one, at the end of the boot + // order. Note that if the platform provided this boot option with an + // unassigned option number, then the below function call will assign a + // number. + // + Status = EfiBootManagerAddLoadOptionVariable ( + &BootOptions[Index], + MAX_UINTN + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to register \"%s\": %r\n", + __FUNCTION__, BootOptions[Index].Description, Status)); + continue; + } + BootOptionNumber = BootOptions[Index].OptionNumber; + } + + // + // Register a hotkey with the boot option, if requested. + // + if (BootKeys[Index].UnicodeChar == L'\0') { + continue; + } + + Status = EfiBootManagerAddKeyOptionVariable ( + NULL, + BootOptionNumber, + 0, + BootKeys[Index], + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n", + __FUNCTION__, BootOptions[Index].Description, Status)); + } + } + EfiBootManagerFreeLoadOptions (CurrentBootOptions, CurrentBootOptionCount); + EfiBootManagerFreeLoadOptions (BootOptions, BootCount); + FreePool (BootKeys); +} + +STATIC +VOID PlatformRegisterOptionsAndKeys ( VOID ) @@ -402,6 +503,8 @@ PlatformRegisterOptionsAndKeys ( EFI_INPUT_KEY Esc; EFI_BOOT_MANAGER_LOAD_OPTION BootOption; + GetPlatformOptions (); + // // Register ENTER as CONTINUE key // diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 71f1d04a87ee..e8cbb10dabdd 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -35,6 +35,7 @@ [Sources] PlatformBm.c [Packages] + EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec ShellPkg/ShellPkg.dec @@ -84,3 +85,4 @@ [Protocols] gEfiPciRootBridgeIoProtocolGuid gEfiSimpleFileSystemProtocolGuid gEsrtManagementProtocolGuid + gPlatformBootManagerProtocolGuid -- 2.7.4