From aede42a840cc6e3509048182eb204b5ce8f3187c Mon Sep 17 00:00:00 2001 From: kavsrf Date: Wed, 14 Jun 2017 12:49:40 +0300 Subject: BML update to sort "BootOrder" --- DcsBml/DcsBml.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'DcsBml') diff --git a/DcsBml/DcsBml.c b/DcsBml/DcsBml.c index f5aaf3a..3a5406f 100644 --- a/DcsBml/DcsBml.c +++ b/DcsBml/DcsBml.c @@ -33,7 +33,7 @@ typedef struct _BML_GLOBALS { } BML_GLOBALS, *PBML_GLOBALS; STATIC PBML_GLOBALS gBmlData = NULL; -STATIC BOOLEAN BootMenuLocked = FALSE; +STATIC BOOLEAN BootMenuLocked = TRUE; EFI_EVENT mBmlVirtualAddrChangeEvent; EFI_SET_VARIABLE orgSetVariable = NULL; @@ -138,6 +138,32 @@ DcsBmlUnload( return EFI_SUCCESS; } +////////////////////////////////////////////////////////////////////////// +// Boot order +////////////////////////////////////////////////////////////////////////// +EFI_STATUS +UpdateBootOrder() +{ + EFI_STATUS res; + UINT16 DcsBootNum = 0x0DC5B; + UINTN boIndex = 1; + UINTN len; + UINT32 attr; + CHAR16* tmp = NULL; + res = EfiGetVar(L"BootDC5B", &gEfiGlobalVariableGuid, &tmp, &len, &attr); + if (EFI_ERROR(res)) { + InitFS(); + res = BootMenuItemCreate(L"BootDC5B", sDcsBootEfiDesc, gFileRootHandle, sDcsBootEfi, TRUE); + res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B); + } else { + if (EFI_ERROR(BootOrderPresent(L"BootOrder", 0x0DC5B, &boIndex) || boIndex != 0)) { + res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B); + } + } + res = EfiSetVar(L"BootNext", &gEfiGlobalVariableGuid, &DcsBootNum, sizeof(DcsBootNum), EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS); + MEM_FREE(tmp); + return res; +} /** The actual entry point for the application. @@ -173,7 +199,7 @@ DcsBmlMain( ASSERT_EFI_ERROR(res); if (EFI_ERROR(res)) { - Print(L"Install protocol %r\n", res); + ERR_PRINT(L"Install protocol %r\n", res); return res; } @@ -185,7 +211,7 @@ DcsBmlMain( ); if (EFI_ERROR(res)) { - Print(L"Allocate runtime globals %r\n", res); + ERR_PRINT(L"Allocate runtime globals %r\n", res); return res; } @@ -202,29 +228,15 @@ DcsBmlMain( ); if (EFI_ERROR(res)) { - Print(L"Register notify %r\n", res); + ERR_PRINT(L"Register notify %r\n", res); return res; } + UpdateBootOrder(); + orgSetVariable = gST->RuntimeServices->SetVariable; gST->RuntimeServices->SetVariable = BmlSetVaribale; - // select boot next - { - UINT16 DcsBootNum = 0x0DC5B; - UINTN len; - UINT32 attr; - CHAR16* tmp = NULL; - res = EfiGetVar(L"BootDC5B", &gEfiGlobalVariableGuid, &tmp, &len, &attr); - if (EFI_ERROR(res)) { - InitFS(); - res = BootMenuItemCreate(L"BootDC5B", sDcsBootEfiDesc, gFileRootHandle, sDcsBootEfi, TRUE); - res = BootOrderInsert(L"BootOrder", 0, 0x0DC5B); - } - res = EfiSetVar(L"BootNext", &gEfiGlobalVariableGuid, &DcsBootNum, sizeof(DcsBootNum), EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS); - MEM_FREE(tmp); - } - // Prepare BootDC5B return EFI_SUCCESS; } -- cgit v1.2.3