boot: prepare for rewrite of boot sysmodule

This commit is contained in:
Michael Scire 2019-04-29 03:25:24 -07:00
parent 6034beb084
commit 7c5dc61795
12 changed files with 2902 additions and 2498 deletions

View file

@ -38,11 +38,6 @@
#include "sc7.h" #include "sc7.h"
#include "exocfg.h" #include "exocfg.h"
#define SMC_USER_HANDLERS 0x13
#define SMC_PRIV_HANDLERS 0x9
#define SMC_AMS_HANDLERS 0x2
#define DEBUG_LOG_SMCS 0 #define DEBUG_LOG_SMCS 0
#define DEBUG_PANIC_ON_FAILURE 0 #define DEBUG_PANIC_ON_FAILURE 0
@ -97,7 +92,7 @@ typedef struct {
uint32_t num_handlers; uint32_t num_handlers;
} smc_table_t; } smc_table_t;
static smc_table_entry_t g_smc_user_table[SMC_USER_HANDLERS] = { static smc_table_entry_t g_smc_user_table[] = {
{0, 4, NULL}, {0, 4, NULL},
{0xC3000401, 4, smc_set_config_user}, {0xC3000401, 4, smc_set_config_user},
{0xC3000002, 1, smc_get_config_user}, {0xC3000002, 1, smc_get_config_user},
@ -118,8 +113,9 @@ static smc_table_entry_t g_smc_user_table[SMC_USER_HANDLERS] = {
{0xC3000011, 4, smc_load_titlekey}, {0xC3000011, 4, smc_load_titlekey},
{0xC3000012, 4, smc_unwrap_aes_wrapped_titlekey} {0xC3000012, 4, smc_unwrap_aes_wrapped_titlekey}
}; };
#define SMC_USER_HANDLERS (sizeof(g_smc_user_table) / sizeof(g_smc_user_table[0]))
static smc_table_entry_t g_smc_priv_table[SMC_PRIV_HANDLERS] = { static smc_table_entry_t g_smc_priv_table[] = {
{0, 4, NULL}, {0, 4, NULL},
{0xC4000001, 4, smc_cpu_suspend}, {0xC4000001, 4, smc_cpu_suspend},
{0x84000002, 4, smc_cpu_off}, {0x84000002, 4, smc_cpu_off},
@ -130,12 +126,15 @@ static smc_table_entry_t g_smc_priv_table[SMC_PRIV_HANDLERS] = {
{0xC3000007, 1, smc_configure_carveout}, {0xC3000007, 1, smc_configure_carveout},
{0xC3000008, 1, smc_read_write_register} {0xC3000008, 1, smc_read_write_register}
}; };
#define SMC_PRIV_HANDLERS (sizeof(g_smc_priv_table) / sizeof(g_smc_priv_table[0]))
/* This is a table used for atmosphere-specific SMCs. */ /* This is a table used for atmosphere-specific SMCs. */
static smc_table_entry_t g_smc_ams_table[SMC_AMS_HANDLERS] = { static smc_table_entry_t g_smc_ams_table[] = {
{0, 4, NULL}, {0, 4, NULL},
{0xF0000201, 0, smc_ams_iram_copy}, {0xF0000201, 0, smc_ams_iram_copy},
{0xF0000002, 0, smc_read_write_register},
}; };
#define SMC_AMS_HANDLERS (sizeof(g_smc_ams_table) / sizeof(g_smc_ams_table[0]))
static smc_table_t g_smc_tables[SMC_HANDLER_COUNT + 1] = { static smc_table_t g_smc_tables[SMC_HANDLER_COUNT + 1] = {
{ /* SMC_HANDLER_USER */ { /* SMC_HANDLER_USER */
@ -168,9 +167,7 @@ void set_version_specific_smcs(void) {
case ATMOSPHERE_TARGET_FIRMWARE_100: case ATMOSPHERE_TARGET_FIRMWARE_100:
/* 1.0.0 doesn't have ConfigureCarveout or ReadWriteRegister. */ /* 1.0.0 doesn't have ConfigureCarveout or ReadWriteRegister. */
g_smc_priv_table[7].handler = NULL; g_smc_priv_table[7].handler = NULL;
/* However, it is in our interest to enable ReadWriteRegister. */ g_smc_priv_table[8].handler = NULL;
/* So we will not actually NOP it out. */
/* g_smc_priv_table[8].handler = NULL; */
/* 1.0.0 doesn't have UnwrapAesWrappedTitlekey. */ /* 1.0.0 doesn't have UnwrapAesWrappedTitlekey. */
g_smc_user_table[0x12].handler = NULL; g_smc_user_table[0x12].handler = NULL;
break; break;

View file

@ -96,7 +96,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
KIPFILES := loader.kip pm.kip sm.kip ams_mitm.kip spl.kip boot_100.kip boot_200.kip KIPFILES := loader.kip pm.kip sm.kip ams_mitm.kip spl.kip boot.kip
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) fusee-primary.bin \ BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) fusee-primary.bin \
exosphere.bin lp0fw.bin rebootstub.bin thermosphere.bin splash_screen.bmp \ exosphere.bin lp0fw.bin rebootstub.bin thermosphere.bin splash_screen.bmp \
sept-primary.bin sept-secondary.enc \ sept-primary.bin sept-secondary.enc \

View file

@ -220,10 +220,8 @@ SECTIONS
======================= */ ======================= */
PROVIDE(__ams_mitm_kip_start__ = ams_mitm_kip - __start__); PROVIDE(__ams_mitm_kip_start__ = ams_mitm_kip - __start__);
PROVIDE(__ams_mitm_kip_size__ = ams_mitm_kip_end - ams_mitm_kip); PROVIDE(__ams_mitm_kip_size__ = ams_mitm_kip_end - ams_mitm_kip);
PROVIDE(__boot_100_kip_start__ = boot_100_kip - __start__); PROVIDE(__boot_kip_start__ = boot_kip - __start__);
PROVIDE(__boot_100_kip_size__ = boot_100_kip_end - boot_100_kip); PROVIDE(__boot_kip_size__ = boot_kip_end - boot_kip);
PROVIDE(__boot_200_kip_start__ = boot_200_kip - __start__);
PROVIDE(__boot_200_kip_size__ = boot_200_kip_end - boot_200_kip);
PROVIDE(__exosphere_bin_start__ = exosphere_bin - __start__); PROVIDE(__exosphere_bin_start__ = exosphere_bin - __start__);
PROVIDE(__exosphere_bin_size__ = exosphere_bin_end - exosphere_bin); PROVIDE(__exosphere_bin_size__ = exosphere_bin_end - exosphere_bin);
PROVIDE(__fusee_primary_bin_start__ = fusee_primary_bin - __start__); PROVIDE(__fusee_primary_bin_start__ = fusee_primary_bin - __start__);

View file

@ -103,20 +103,12 @@ _content_headers:
.asciz "ams_mitm" .asciz "ams_mitm"
.align 5 .align 5
/* boot_100 content header */ /* boot content header */
.word __boot_100_kip_start__ .word __boot_kip_start__
.word __boot_100_kip_size__ .word __boot_kip_size__
.word CONTENT_TYPE_KIP .word CONTENT_TYPE_KIP
.word 0xCCCCCCCC .word 0xCCCCCCCC
.asciz "boot_100" .asciz "boot"
.align 5
/* boot_200 content header */
.word __boot_200_kip_start__
.word __boot_200_kip_size__
.word CONTENT_TYPE_KIP
.word 0xCCCCCCCC
.asciz "boot_200"
.align 5 .align 5
/* exosphere content header */ /* exosphere content header */

View file

@ -33,8 +33,7 @@
#include "pm_kip.h" #include "pm_kip.h"
#include "sm_kip.h" #include "sm_kip.h"
#include "ams_mitm_kip.h" #include "ams_mitm_kip.h"
#include "boot_100_kip.h" #include "boot_kip.h"
#include "boot_200_kip.h"
#include "spl_kip.h" #include "spl_kip.h"
#undef u8 #undef u8
#undef u32 #undef u32
@ -49,16 +48,12 @@ static bool g_stratosphere_ams_mitm_enabled = true;
static bool g_stratosphere_spl_enabled = true; static bool g_stratosphere_spl_enabled = true;
static bool g_stratosphere_boot_enabled = false; static bool g_stratosphere_boot_enabled = false;
extern const uint8_t boot_100_kip[], boot_200_kip[]; extern const uint8_t loader_kip[], pm_kip[], sm_kip[], spl_kip[], boot_kip[], ams_mitm_kip[];
extern const uint8_t loader_kip[], pm_kip[], sm_kip[], spl_kip[], ams_mitm_kip[]; extern const uint32_t loader_kip_size, pm_kip_size, sm_kip_size, spl_kip_size, boot_kip_size, ams_mitm_kip_size;
extern const uint32_t boot_100_kip_size, boot_200_kip_size;
extern const uint32_t loader_kip_size, pm_kip_size, sm_kip_size, spl_kip_size, ams_mitm_kip_size;
/* GCC doesn't consider the size as const... we have to write it ourselves. */ /* GCC doesn't consider the size as const... we have to write it ourselves. */
ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware) { ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware) {
const uint8_t *boot_kip = NULL;
uint32_t boot_kip_size = 0;
uint32_t num_processes = 0; uint32_t num_processes = 0;
uint8_t *data; uint8_t *data;
@ -66,14 +61,6 @@ ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware) {
return g_stratosphere_ini1; return g_stratosphere_ini1;
} }
if (target_firmware <= ATMOSPHERE_TARGET_FIRMWARE_100) {
boot_kip = boot_100_kip;
boot_kip_size = boot_100_kip_size;
} else {
boot_kip = boot_200_kip;
boot_kip_size = boot_200_kip_size;
}
size_t size = sizeof(ini1_header_t); size_t size = sizeof(ini1_header_t);
/* Calculate our processes' sizes. */ /* Calculate our processes' sizes. */

View file

@ -128,7 +128,7 @@ $(BUILD):
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @echo clean ...
@rm -fr $(BUILD) $(TARGET)_100.kip $(TARGET)_100.elf $(TARGET)_200.kip $(TARGET)_200.elf @rm -fr $(BUILD) $(TARGET).kip $(TARGET).elf
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@ -140,16 +140,11 @@ DEPENDS := $(OFILES:.o=.d)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# main targets # main targets
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
all : $(OUTPUT)_100.kip $(OUTPUT)_200.kip all : $(OUTPUT).kip
$(OUTPUT)_100.kip : $(OUTPUT)_100.elf $(OUTPUT).kip : $(OUTPUT).elf
$(OUTPUT)_200.kip : $(OUTPUT)_200.elf
$(OUTPUT)_100.kip : APP_JSON = $(TOPDIR)/boot_100.json $(OUTPUT).elf : $(OFILES)
$(OUTPUT)_200.kip : APP_JSON = $(TOPDIR)/boot_200.json
$(OUTPUT)_100.elf : $(OFILES)
$(OUTPUT)_200.elf : $(OFILES)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data # you need a rule like this for each extension you use as binary data

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,166 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules
AMSBRANCH := $(shell git symbolic-ref --short HEAD)
AMSREV := $(AMSBRANCH)-$(shell git rev-parse --short HEAD)
ifneq (, $(strip $(shell git status --porcelain 2>/dev/null)))
AMSREV := $(AMSREV)-dirty
endif
#---------------------------------------------------------------------------------
# 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".
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#---------------------------------------------------------------------------------
# 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 $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
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)_100.kip $(TARGET)_100.elf $(TARGET)_200.kip $(TARGET)_200.elf
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT)_100.kip $(OUTPUT)_200.kip
$(OUTPUT)_100.kip : $(OUTPUT)_100.elf
$(OUTPUT)_200.kip : $(OUTPUT)_200.elf
$(OUTPUT)_100.kip : APP_JSON = $(TOPDIR)/boot_100.json
$(OUTPUT)_200.kip : APP_JSON = $(TOPDIR)/boot_200.json
$(OUTPUT)_100.elf : $(OFILES)
$(OUTPUT)_200.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
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,165 @@
{
"name": "boot",
"title_id": "0x0100000000000005",
"main_thread_stack_size": "0x1000",
"main_thread_priority": 27,
"default_cpu_id": 3,
"process_category": 1,
"kernel_capabilities": [
{
"type": "handle_table_size",
"value": 128
},
{
"type": "syscalls",
"value": {
"svcSetHeapSize": "0x01",
"svcSetMemoryPermission": "0x02",
"svcSetMemoryAttribute": "0x03",
"svcMapMemory": "0x04",
"svcUnmapMemory": "0x05",
"svcQueryMemory": "0x06",
"svcExitProcess": "0x07",
"svcCreateThread": "0x08",
"svcStartThread": "0x09",
"svcExitThread": "0x0A",
"svcSleepThread": "0x0B",
"svcGetThreadPriority": "0x0C",
"svcSetThreadPriority": "0x0D",
"svcGetThreadCoreMask": "0x0E",
"svcSetThreadCoreMask": "0x0F",
"svcGetCurrentProcessorNumber": "0x10",
"svcSignalEvent": "0x11",
"svcClearEvent": "0x12",
"svcMapSharedMemory": "0x13",
"svcUnmapSharedMemory": "0x14",
"svcCreateTransferMemory": "0x15",
"svcCloseHandle": "0x16",
"svcResetSignal": "0x17",
"svcWaitSynchronization": "0x18",
"svcCancelSynchronization": "0x19",
"svcArbitrateLock": "0x1A",
"svcArbitrateUnlock": "0x1B",
"svcWaitProcessWideKeyAtomic": "0x1C",
"svcSignalProcessWideKey": "0x1D",
"svcGetSystemTick": "0x1E",
"svcConnectToNamedPort": "0x1F",
"svcSendSyncRequestLight": "0x20",
"svcSendSyncRequest": "0x21",
"svcSendSyncRequestWithUserBuffer": "0x22",
"svcSendAsyncRequestWithUserBuffer": "0x23",
"svcGetProcessId": "0x24",
"svcGetThreadId": "0x25",
"svcBreak": "0x26",
"svcOutputDebugString": "0x27",
"svcReturnFromException": "0x28",
"svcGetInfo": "0x29",
"svcWaitForAddress": "0x34",
"svcSignalToAddress": "0x35",
"svcReadWriteRegister": "0x4E",
"svcCreateInterruptEvent": "0x53",
"svcQueryIoMapping": "0x55",
"svcCreateDeviceAddressSpace": "0x56",
"svcAttachDeviceAddressSpace": "0x57",
"svcDetachDeviceAddressSpace": "0x58",
"svcMapDeviceAddressSpaceAligned": "0x5A",
"svcUnmapDeviceAddressSpace": "0x5C",
"svcFlushProcessDataCache": "0x5F",
"svcCallSecureMonitor": "0x7F"
}
},
{
"type": "map",
"value": {
"address": "0x50003000",
"size": "0x1000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x54200000",
"size": "0x3000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x54300000",
"size": "0x1000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x60006000",
"size": "0x1000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x6000D000",
"size": "0x1000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x70000000",
"size": "0x4000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x7000C000",
"size": "0x2000",
"is_ro": false,
"is_io": true
}
},
{
"type": "map",
"value": {
"address": "0x700E3000",
"size": "0x1000",
"is_ro": false,
"is_io": true
}
},
{
"type": "irq_pair",
"value": [
70,
116
]
},
{
"type": "irq_pair",
"value": [
124,
152
]
},
{
"type": "irq_pair",
"value": [
85,
95
]
}
]
}

File diff suppressed because it is too large Load diff