Skip to content

Commit

Permalink
Merge pull request #132 from chp-io/mono-force-bootentry
Browse files Browse the repository at this point in the history
Force UEFI boot order on service start and exit to enforce MicroV boot
  • Loading branch information
chp-io authored Sep 19, 2022
2 parents a57b338 + b1f0d41 commit 193d013
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/microv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
cp ..\microv\scripts\cmake\config\config.cmake ..
Add-Content -Path ..\config.cmake -Value "set(ENABLE_BUILD_USERSPACE ON)"
Add-Content -Path ..\config.cmake -Value "set(ENABLE_BUILD_VMM OFF)"
Add-Content -Path ..\config.cmake -Value "set(UVCTL_WINDOWS_SERVICE_FORCE_BOOTENTRY ON)"
cmake ../microv/deps/hypervisor -DCONFIG=..\config.cmake -G "Visual Studio 16 2019" -A x64
& msbuild /p:Configuration=Release /p:Platform=x64 /p:TargetVersion=Windows10 hypervisor.sln
shell: pwsh
Expand Down
7 changes: 7 additions & 0 deletions scripts/cmake/config/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,10 @@ add_config(
DEFAULT_VAL OFF
DESCRIPTION "Don't passthru ethernet devices, when passthru for network devices is enabled"
)

add_config(
CONFIG_NAME UVCTL_WINDOWS_SERVICE_FORCE_BOOTENTRY
CONFIG_TYPE BOOL
DEFAULT_VAL OFF
DESCRIPTION "Force setting MicroV UEFI boot entry"
)
5 changes: 4 additions & 1 deletion uvctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ target_sources(uvctl PRIVATE
$<$<BOOL:${WIN32}>:${OS}/service.cpp>
$<$<BOOL:${XEN_READCONSOLE_ROOTVM}>:${OS}/xen_hypercall.asm>
)
target_compile_definitions(uvctl PRIVATE $<$<BOOL:${XEN_READCONSOLE_ROOTVM}>:XEN_READCONSOLE_ROOTVM>)
target_compile_definitions(uvctl PRIVATE
$<$<BOOL:${XEN_READCONSOLE_ROOTVM}>:XEN_READCONSOLE_ROOTVM>
$<$<BOOL:${UVCTL_WINDOWS_SERVICE_FORCE_BOOTENTRY}>:UVCTL_WINDOWS_SERVICE_FORCE_BOOTENTRY>
)

fini_project()
1 change: 1 addition & 0 deletions uvctl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ int protected_main(const args_type &args)

CloseHandle(xenbus_fd);
}
service_post_tasks();
#endif
}

Expand Down
13 changes: 8 additions & 5 deletions uvctl/windows/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ DWORD WINAPI vm_worker(LPVOID param)
*/
static void set_boot_entry() noexcept
{
#ifdef UVCTL_WINDOWS_SERVICE_FORCE_BOOTENTRY
int res = system(
"C:\\windows\\system32\\bcdedit.exe /set {bootmgr} path \\EFI\\Boot\\PreLoader.efi");
if (res != 0) {
Expand All @@ -236,13 +237,19 @@ static void set_boot_entry() noexcept
log_msg("bcdedit: failed to set fwbootmgr bootsequence: exit code %d",
res);
}
#endif
}

void service_post_tasks() noexcept
{
set_boot_entry();
}

void WINAPI service_main(DWORD argc, LPTSTR *argv)
{
set_boot_entry();
if (!init()) {
log_msg("%s: init failed\n", __func__);
set_boot_entry();
return;
}

Expand All @@ -266,7 +273,6 @@ void WINAPI service_main(DWORD argc, LPTSTR *argv)
exit_code);

stop_with_error(exit_code);
set_boot_entry();
return;
}

Expand All @@ -287,7 +293,6 @@ void WINAPI service_main(DWORD argc, LPTSTR *argv)

CloseHandle(service_stop_event);
stop_with_error(exit_code);
set_boot_entry();
return;
}

Expand Down Expand Up @@ -318,8 +323,6 @@ void WINAPI service_main(DWORD argc, LPTSTR *argv)
}
}

set_boot_entry();

set_status(SERVICE_ACCEPT_NONE, SERVICE_STOPPED, NO_ERROR);

CloseHandle(service_stop_event);
Expand Down
1 change: 1 addition & 0 deletions uvctl/windows/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@

void service_start() noexcept;
void service_wait_for_stop_signal() noexcept;
void service_post_tasks() noexcept;

#endif

0 comments on commit 193d013

Please sign in to comment.