diff --git a/stratosphere/boot2/Makefile b/stratosphere/boot2/Makefile deleted file mode 100644 index 74ee337..0000000 --- a/stratosphere/boot2/Makefile +++ /dev/null @@ -1,185 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITPRO)),) -$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITPRO)/libnx/switch_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm". -# -# NO_ICON: if set to anything, do not use icon. -# NO_NACP: if set to anything, no .nacp file is generated. -# APP_TITLE is the name of the app stored in the .nacp file (Optional) -# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) -# APP_VERSION is the version of the app stored in the .nacp file (Optional) -# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) -# ICON is the filename of the icon (.jpg), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .jpg -# - icon.jpg -# - /default_icon.jpg -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -EXEFS_SRC := exefs_src - -DEFINES := -DDISABLE_IPC - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE - -CFLAGS := -g -Wall -O2 -ffunction-sections \ - $(ARCH) $(DEFINES) - -CFLAGS += $(INCLUDE) -D__SWITCH__ - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lstratosphere -lnx - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../libstratosphere - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.jpg) - ifneq (,$(findstring $(TARGET).jpg,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).jpg - else - ifneq (,$(findstring icon.jpg,$(icons))) - export APP_ICON := $(TOPDIR)/icon.jpg - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_ICON)),) - export NROFLAGS += --icon=$(APP_ICON) -endif - -ifeq ($(strip $(NO_NACP)),) - export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp -endif - -ifneq ($(APP_TITLEID),) - export NACPFLAGS += --titleid=$(APP_TITLEID) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else -.PHONY: all - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -all : $(OUTPUT).pfs0 $(OUTPUT).nro - -$(OUTPUT).pfs0 : $(OUTPUT).nso - -$(OUTPUT).nso : $(OUTPUT).elf - -ifeq ($(strip $(NO_NACP)),) -$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp -else -$(OUTPUT).nro : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp deleted file mode 100644 index 998a22c..0000000 --- a/stratosphere/boot2/source/boot2_main.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#define PMC_BASE 0x7000E400 - -extern "C" { - extern u32 __start__; - - u32 __nx_applet_type = AppletType_None; - - #define INNER_HEAP_SIZE 0x200000 - size_t nx_inner_heap_size = INNER_HEAP_SIZE; - char nx_inner_heap[INNER_HEAP_SIZE]; - - void __libnx_initheap(void); - void __appInit(void); - void __appExit(void); -} - -void __libnx_initheap(void) { - void* addr = nx_inner_heap; - size_t size = nx_inner_heap_size; - - /* Newlib */ - extern char* fake_heap_start; - extern char* fake_heap_end; - - fake_heap_start = (char*)addr; - fake_heap_end = (char*)addr + size; -} - -void __appInit(void) { - Result rc; - - rc = smInitialize(); - if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); - - rc = fsInitialize(); - if (R_FAILED(rc)) - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); - - rc = pmshellInitialize(); - if (R_FAILED(rc)) - fatalSimple(0xCAFE << 4 | 1); -} - -void __appExit(void) { - /* Cleanup services. */ - pmshellExit(); - fsExit(); - smExit(); -} - -void LaunchTitle(u64 title_id, u64 storage_id, u32 launch_flags, u64 *pid) { - u64 local_pid; - Result rc = pmshellLaunchProcess(launch_flags, title_id, storage_id, &local_pid); - switch (rc) { - case 0xCE01: - /* Out of resource! */ - /* TODO: Panic(). */ - break; - case 0xDE01: - /* Out of memory! */ - /* TODO: Panic(). */ - break; - case 0xD001: - /* Limit Reached! */ - /* TODO: Panic(). */ - break; - default: - /* We don't care about other issues. */ - break; - } - if (pid) { - *pid = local_pid; - } -} - -bool ShouldForceMaintenanceMode() { - /* TODO: Contact set:sys, retrieve boot!force_maintenance, read plus/minus buttons. */ - return false; -} - -static const std::tuple g_additional_launch_programs[] = { - {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 */ -}; - -int main(int argc, char **argv) -{ - consoleDebugInit(debugDevice_SVC); - - /* NOTE: Order for initial programs is modified. */ - /* This is to launch things required for Loader to mount SD card ASAP. */ - - /* Launch psc. */ - LaunchTitle(0x0100000000000021, 3, 0, NULL); - /* Launch bus. */ - LaunchTitle(0x010000000000000A, 3, 0, NULL); - /* Launch pcv. */ - LaunchTitle(0x010000000000001A, 3, 0, NULL); - /* Launch settings. */ - LaunchTitle(0x0100000000000009, 3, 0, NULL); - /* Launch usb. */ - LaunchTitle(0x0100000000000006, 3, 0, NULL); - /* Launch pcie. */ - LaunchTitle(0x010000000000001D, 3, 0, NULL); - /* Launch tma. */ - LaunchTitle(0x0100000000000007, 3, 0, NULL); - - bool maintenance = ShouldForceMaintenanceMode(); - for (auto &launch_program : g_additional_launch_programs) { - if (!maintenance || std::get(launch_program)) { - LaunchTitle(std::get(launch_program), 3, 0, NULL); - } - } - - return 0; -} diff --git a/stratosphere/pm/source/pm_boot2.cpp b/stratosphere/pm/source/pm_boot2.cpp new file mode 100644 index 0000000..f3995eb --- /dev/null +++ b/stratosphere/pm/source/pm_boot2.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +#include + +#include +#include +#include "pm_boot2.hpp" +#include "pm_registration.hpp" + +static void LaunchTitle(u64 title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) { + u64 local_pid; + + Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{title_id, storage_id}, launch_flags, &local_pid); + switch (rc) { + case 0xCE01: + /* Out of resource! */ + /* TODO: Panic(). */ + break; + case 0xDE01: + /* Out of memory! */ + /* TODO: Panic(). */ + break; + case 0xD001: + /* Limit Reached! */ + /* TODO: Panic(). */ + break; + default: + /* We don't care about other issues. */ + break; + } + if (pid) { + *pid = local_pid; + } +} + +static bool ShouldForceMaintenanceMode() { + /* TODO: Contact set:sys, retrieve boot!force_maintenance, read plus/minus buttons. */ + return false; +} + +static const std::tuple g_additional_launch_programs[] = { + {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 */ +}; + +void EmbeddedBoot2::Main() { + /* TODO: Modify initial program launch order, to get SD card mounted faster. */ + + /* Launch psc. */ + LaunchTitle(0x0100000000000021, FsStorageId_NandSystem, 0, NULL); + /* Launch settings. */ + LaunchTitle(0x0100000000000009, FsStorageId_NandSystem, 0, NULL); + /* Launch usb. */ + LaunchTitle(0x0100000000000006, FsStorageId_NandSystem, 0, NULL); + /* Launch pcie. */ + LaunchTitle(0x010000000000001D, FsStorageId_NandSystem, 0, NULL); + /* Launch bus. */ + LaunchTitle(0x010000000000000A, FsStorageId_NandSystem, 0, NULL); + /* Launch tma. */ + LaunchTitle(0x0100000000000007, FsStorageId_NandSystem, 0, NULL); + /* Launch pcv. */ + LaunchTitle(0x010000000000001A, FsStorageId_NandSystem, 0, NULL); + + bool maintenance = ShouldForceMaintenanceMode(); + for (auto &launch_program : g_additional_launch_programs) { + if (!maintenance || std::get(launch_program)) { + LaunchTitle(std::get(launch_program), FsStorageId_NandSystem, 0, NULL); + } + } +} diff --git a/stratosphere/pm/source/pm_boot2.hpp b/stratosphere/pm/source/pm_boot2.hpp new file mode 100644 index 0000000..20d2a19 --- /dev/null +++ b/stratosphere/pm/source/pm_boot2.hpp @@ -0,0 +1,10 @@ +#pragma once + +enum class TitleId : u64 { + x = 0UL, +}; + +class EmbeddedBoot2 { + public: + static void Main(); +}; \ No newline at end of file diff --git a/stratosphere/pm/source/pm_shell.cpp b/stratosphere/pm/source/pm_shell.cpp index ffdab1b..78b72a8 100644 --- a/stratosphere/pm/source/pm_shell.cpp +++ b/stratosphere/pm/source/pm_shell.cpp @@ -3,6 +3,7 @@ #include "pm_registration.hpp" #include "pm_resource_limits.hpp" #include "pm_shell.hpp" +#include "pm_boot2.hpp" static bool g_has_boot_finished = false; @@ -148,10 +149,9 @@ } std::tuple ShellService::notify_boot_finished() { - u64 boot2_pid; if (!g_has_boot_finished) { g_has_boot_finished = true; - return {Registration::LaunchProcess(BOOT2_TITLE_ID, FsStorageId_NandSystem, 0, &boot2_pid)}; + EmbeddedBoot2::Main(); } return {0}; }