mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 10:52:13 +00:00
pm: Launch set.mitm earlier in boot.
This commit is contained in:
parent
2165555170
commit
f61f5feaf4
3 changed files with 45 additions and 8 deletions
|
@ -26,6 +26,20 @@
|
||||||
#include "pm_boot2.hpp"
|
#include "pm_boot2.hpp"
|
||||||
#include "pm_registration.hpp"
|
#include "pm_registration.hpp"
|
||||||
|
|
||||||
|
static std::vector<Boot2KnownTitleId> g_boot2_titles;
|
||||||
|
|
||||||
|
static void ClearLaunchedTitles() {
|
||||||
|
g_boot2_titles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetLaunchedTitle(Boot2KnownTitleId title_id) {
|
||||||
|
g_boot2_titles.push_back(title_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HasLaunchedTitle(Boot2KnownTitleId title_id) {
|
||||||
|
return std::find(g_boot2_titles.begin(), g_boot2_titles.end(), title_id) != g_boot2_titles.end();
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsHexadecimal(const char *str) {
|
static bool IsHexadecimal(const char *str) {
|
||||||
while (*str) {
|
while (*str) {
|
||||||
if (isxdigit(*str)) {
|
if (isxdigit(*str)) {
|
||||||
|
@ -40,6 +54,11 @@ static bool IsHexadecimal(const char *str) {
|
||||||
static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
|
static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
|
||||||
u64 local_pid;
|
u64 local_pid;
|
||||||
|
|
||||||
|
/* Don't launch a title twice during boot2. */
|
||||||
|
if (HasLaunchedTitle(title_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{(u64)title_id, storage_id}, launch_flags, &local_pid);
|
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{(u64)title_id, storage_id}, launch_flags, &local_pid);
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case 0xCE01:
|
case 0xCE01:
|
||||||
|
@ -61,6 +80,10 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
|
||||||
if (pid) {
|
if (pid) {
|
||||||
*pid = local_pid;
|
*pid = local_pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
SetLaunchedTitle(title_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ShouldForceMaintenanceMode() {
|
static bool ShouldForceMaintenanceMode() {
|
||||||
|
@ -123,25 +146,28 @@ static void MountSdCard() {
|
||||||
fsdevMountSdmc();
|
fsdevMountSdmc();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WaitForFsMitm() {
|
static void WaitForMitm(const char *service) {
|
||||||
bool fs_mitm_installed = false;
|
bool mitm_installed = false;
|
||||||
|
|
||||||
Result rc = smManagerAmsInitialize();
|
Result rc = smManagerAmsInitialize();
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
while (R_FAILED((rc = smManagerAmsHasMitm(&fs_mitm_installed, "fsp-srv"))) || !fs_mitm_installed) {
|
while (R_FAILED((rc = smManagerAmsHasMitm(&mitm_installed, service))) || !mitm_installed) {
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
svcSleepThread(1000ull);
|
svcSleepThread(1000000ull);
|
||||||
}
|
}
|
||||||
smManagerAmsExit();
|
smManagerAmsExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmbeddedBoot2::Main() {
|
void EmbeddedBoot2::Main() {
|
||||||
/* Wait until fs.mitm has installed itself. We want this to happen as early as possible. */
|
/* Wait until fs.mitm has installed itself. We want this to happen as early as possible. */
|
||||||
WaitForFsMitm();
|
WaitForMitm("fsp-srv");
|
||||||
|
|
||||||
|
/* Clear titles. */
|
||||||
|
ClearLaunchedTitles();
|
||||||
|
|
||||||
/* psc, bus, pcv is the minimal set of required titles to get SD card. */
|
/* psc, bus, pcv is the minimal set of required titles to get SD card. */
|
||||||
/* bus depends on pcie, and pcv depends on settings. */
|
/* bus depends on pcie, and pcv depends on settings. */
|
||||||
|
@ -159,6 +185,10 @@ void EmbeddedBoot2::Main() {
|
||||||
/* At this point, the SD card can be mounted. */
|
/* At this point, the SD card can be mounted. */
|
||||||
MountSdCard();
|
MountSdCard();
|
||||||
|
|
||||||
|
/* Launch set:mitm, wait for it. */
|
||||||
|
LaunchTitle(Boot2KnownTitleId::ams_set_mitm, FsStorageId_None, 0, NULL);
|
||||||
|
WaitForMitm("set:sys");
|
||||||
|
|
||||||
/* Launch usb. */
|
/* Launch usb. */
|
||||||
LaunchTitle(Boot2KnownTitleId::usb, FsStorageId_NandSystem, 0, NULL);
|
LaunchTitle(Boot2KnownTitleId::usb, FsStorageId_NandSystem, 0, NULL);
|
||||||
/* Launch tma. */
|
/* Launch tma. */
|
||||||
|
@ -206,4 +236,7 @@ void EmbeddedBoot2::Main() {
|
||||||
|
|
||||||
/* We no longer need the SD card. */
|
/* We no longer need the SD card. */
|
||||||
fsdevUnmountAll();
|
fsdevUnmountAll();
|
||||||
|
|
||||||
|
/* Clear titles. */
|
||||||
|
ClearLaunchedTitles();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,10 @@ enum class Boot2KnownTitleId : u64 {
|
||||||
jpegdec = 0x010000000000003CUL,
|
jpegdec = 0x010000000000003CUL,
|
||||||
safemode = 0x010000000000003DUL,
|
safemode = 0x010000000000003DUL,
|
||||||
olsc = 0x010000000000003EUL,
|
olsc = 0x010000000000003EUL,
|
||||||
|
|
||||||
|
|
||||||
|
/* atmosphere extensions */
|
||||||
|
ams_set_mitm = 0x0100000000000032UL,
|
||||||
};
|
};
|
||||||
|
|
||||||
class EmbeddedBoot2 {
|
class EmbeddedBoot2 {
|
||||||
|
|
|
@ -148,15 +148,15 @@ void __appExit(void) {
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Thread process_track_thread = {0};
|
HosThread process_track_thread;
|
||||||
consoleDebugInit(debugDevice_SVC);
|
consoleDebugInit(debugDevice_SVC);
|
||||||
|
|
||||||
/* Initialize and spawn the Process Tracking thread. */
|
/* Initialize and spawn the Process Tracking thread. */
|
||||||
Registration::InitializeSystemResources();
|
Registration::InitializeSystemResources();
|
||||||
if (R_FAILED(threadCreate(&process_track_thread, &ProcessTracking::MainLoop, NULL, 0x4000, 0x15, 0))) {
|
if (R_FAILED(process_track_thread.Initialize(&ProcessTracking::MainLoop, NULL, 0x4000, 0x15))) {
|
||||||
/* TODO: Panic. */
|
/* TODO: Panic. */
|
||||||
}
|
}
|
||||||
if (R_FAILED(threadStart(&process_track_thread))) {
|
if (R_FAILED(process_track_thread.Start())) {
|
||||||
/* TODO: Panic. */
|
/* TODO: Panic. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue