2018-05-01 18:58:19 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
#include <stratosphere.hpp>
|
2018-07-27 11:23:53 +02:00
|
|
|
#include "pm_boot2.hpp"
|
|
|
|
#include "pm_registration.hpp"
|
2018-05-01 18:58:19 +02:00
|
|
|
|
2018-07-27 11:23:53 +02:00
|
|
|
static void LaunchTitle(u64 title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
|
2018-05-01 18:58:19 +02:00
|
|
|
u64 local_pid;
|
2018-07-27 11:23:53 +02:00
|
|
|
|
|
|
|
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{title_id, storage_id}, launch_flags, &local_pid);
|
2018-05-01 18:58:19 +02:00
|
|
|
switch (rc) {
|
|
|
|
case 0xCE01:
|
|
|
|
/* Out of resource! */
|
|
|
|
/* TODO: Panic(). */
|
|
|
|
break;
|
|
|
|
case 0xDE01:
|
|
|
|
/* Out of memory! */
|
|
|
|
/* TODO: Panic(). */
|
|
|
|
break;
|
|
|
|
case 0xD001:
|
2018-05-01 19:04:39 +02:00
|
|
|
/* Limit Reached! */
|
2018-05-01 18:58:19 +02:00
|
|
|
/* TODO: Panic(). */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* We don't care about other issues. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pid) {
|
|
|
|
*pid = local_pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 11:23:53 +02:00
|
|
|
static bool ShouldForceMaintenanceMode() {
|
2018-05-01 18:58:19 +02:00
|
|
|
/* TODO: Contact set:sys, retrieve boot!force_maintenance, read plus/minus buttons. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const std::tuple<u64, bool> g_additional_launch_programs[] = {
|
2018-05-05 20:41:39 +02:00
|
|
|
{0x0100000000000023, true}, /* am */
|
|
|
|
{0x0100000000000019, true}, /* nvservices */
|
|
|
|
{0x010000000000001C, true}, /* nvnflinger */
|
|
|
|
{0x010000000000002D, true}, /* vi */
|
|
|
|
{0x010000000000001F, true}, /* ns */
|
|
|
|
{0x0100000000000015, true}, /* lm */
|
|
|
|
{0x010000000000001B, true}, /* ppc */
|
|
|
|
{0x0100000000000010, true}, /* ptm */
|
|
|
|
{0x0100000000000013, true}, /* hid */
|
|
|
|
{0x0100000000000014, true}, /* audio */
|
|
|
|
{0x0100000000000029, true}, /* lbl */
|
|
|
|
{0x0100000000000016, true}, /* wlan */
|
|
|
|
{0x010000000000000B, true}, /* bluetooth */
|
|
|
|
{0x0100000000000012, true}, /* bsdsockets */
|
|
|
|
{0x010000000000000F, true}, /* nifm */
|
|
|
|
{0x0100000000000018, true}, /* ldn */
|
|
|
|
{0x010000000000001E, true}, /* account */
|
|
|
|
{0x010000000000000E, false}, /* friends */
|
|
|
|
{0x0100000000000020, true}, /* nfc */
|
|
|
|
{0x010000000000003C, true}, /* jpegdec */
|
|
|
|
{0x0100000000000022, true}, /* capsrv */
|
|
|
|
{0x0100000000000024, true}, /* ssl */
|
|
|
|
{0x0100000000000025, true}, /* nim */
|
|
|
|
{0x010000000000000C, false}, /* bcat */
|
|
|
|
{0x010000000000002B, true}, /* erpt */
|
|
|
|
{0x0100000000000033, true}, /* es */
|
|
|
|
{0x010000000000002E, true}, /* pctl */
|
|
|
|
{0x010000000000002A, true}, /* btm */
|
|
|
|
{0x0100000000000030, false}, /* eupld */
|
|
|
|
{0x0100000000000031, true}, /* glue */
|
|
|
|
{0x0100000000000032, true}, /* eclct */
|
|
|
|
{0x010000000000002F, false}, /* npns */
|
|
|
|
{0x0100000000000034, true}, /* fatal */
|
|
|
|
{0x0100000000000037, true}, /* ro */
|
|
|
|
{0x0100000000000038, true}, /* doesn't exist on retail systems */
|
|
|
|
{0x0100000000000039, true}, /* sdb */
|
|
|
|
{0x010000000000003A, true}, /* migration */
|
|
|
|
{0x0100000000000035, true}, /* grc */
|
2018-05-01 18:58:19 +02:00
|
|
|
};
|
|
|
|
|
2018-07-27 11:23:53 +02:00
|
|
|
void EmbeddedBoot2::Main() {
|
|
|
|
/* TODO: Modify initial program launch order, to get SD card mounted faster. */
|
2018-05-01 18:58:19 +02:00
|
|
|
|
|
|
|
/* Launch psc. */
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(0x0100000000000021, FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
/* Launch settings. */
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(0x0100000000000009, FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
/* Launch usb. */
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(0x0100000000000006, FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
/* Launch pcie. */
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(0x010000000000001D, FsStorageId_NandSystem, 0, NULL);
|
|
|
|
/* Launch bus. */
|
|
|
|
LaunchTitle(0x010000000000000A, FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
/* Launch tma. */
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(0x0100000000000007, FsStorageId_NandSystem, 0, NULL);
|
|
|
|
/* Launch pcv. */
|
|
|
|
LaunchTitle(0x010000000000001A, FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
|
|
|
|
bool maintenance = ShouldForceMaintenanceMode();
|
2018-05-04 01:24:34 +02:00
|
|
|
for (auto &launch_program : g_additional_launch_programs) {
|
|
|
|
if (!maintenance || std::get<bool>(launch_program)) {
|
2018-07-27 11:23:53 +02:00
|
|
|
LaunchTitle(std::get<u64>(launch_program), FsStorageId_NandSystem, 0, NULL);
|
2018-05-01 18:58:19 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-04 01:24:34 +02:00
|
|
|
}
|