From b4c908ba9f2af7eb52a8701c63c48985a1105710 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 14 Nov 2020 14:14:07 -0800 Subject: [PATCH] exo/program: release, debug, audit configs --- .gitignore | 4 + exosphere/program/Makefile | 121 +++++++++++------- exosphere/program/source/secmon_error.cpp | 2 + exosphere/program/split_program.py | 8 +- libraries/libexosphere/arm.mk | 6 +- libraries/libexosphere/arm64.mk | 6 +- libraries/libexosphere/source/log/log_api.cpp | 2 +- .../libvapours/include/vapours/common.hpp | 14 +- 8 files changed, 104 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index c8c423006..78f859ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,7 @@ sept/sept-secondary/KEYS.py **/out **/build +**/build_nintendo_nx_arm64 +**/build_nintendo_nx_arm +**/build_nintendo_nx_x64 +**/build_nintendo_nx_x86 diff --git a/exosphere/program/Makefile b/exosphere/program/Makefile index 81dc502b7..f9b061cc6 100644 --- a/exosphere/program/Makefile +++ b/exosphere/program/Makefile @@ -7,30 +7,24 @@ export ATMOSPHERE_CPU := arm-cortex-a57 #--------------------------------------------------------------------------------- # pull in common atmosphere configuration #--------------------------------------------------------------------------------- +THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST))) +CURRENT_DIRECTORY := $(abspath $(dir $(THIS_MAKEFILE))) include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../libraries/config/templates/exosphere.mk #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional # rules for different file extensions #--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) +ifneq ($(__RECURSIVE__),1) #--------------------------------------------------------------------------------- -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) -export DEPSDIR := $(CURDIR)/$(BUILD) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ - $(TOPDIR)/sc7fw \ - $(TOPDIR)/rebootstub +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) $(CURDIR)/include \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) CFILES := $(call FIND_SOURCE_FILES,$(SOURCES),c) CPPFILES := $(call FIND_SOURCE_FILES,$(SOURCES),cpp) SFILES := $(call FIND_SOURCE_FILES,$(SOURCES),s) -BINFILES := sc7fw.bin rebootstub.bin - #--------------------------------------------------------------------------------- # use CXX for linking C++ projects, CC for standard C #--------------------------------------------------------------------------------- @@ -45,77 +39,118 @@ else endif #--------------------------------------------------------------------------------- -export OFILES_BIN := $(addsuffix .o,$(BINFILES)) export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) -export OFILES := $(OFILES_BIN) $(OFILES_SRC) -export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(subst -,_,$(BINFILES)))) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) rebootstub.bin.o sc7fw.bin.o export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ -I. -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib -L$(dir)/$(ATMOSPHERE_LIBRARY_DIR)) +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/$(ATMOSPHERE_LIBRARY_DIR)) -.PHONY: $(BUILD) clean all +export TOPDIR := $(CURRENT_DIRECTORY) + +OUTPUT_BASE := $(TOPDIR)/$(notdir $(TOPDIR)) #--------------------------------------------------------------------------------- -all: $(BUILD) check_libexo -$(BUILD): check_libexo check_firmwares +ATMOSPHERE_BUILD_CONFIGS := +all: release + +define ATMOSPHERE_ADD_TARGET + +ATMOSPHERE_BUILD_CONFIGS += $(strip $1) + +$(strip $1): check_libexo_$(strip $1) $$(ATMOSPHERE_BUILD_DIR)/$(strip $1) + @$$(MAKE) __RECURSIVE__=1 OUTPUT=$$(OUTPUT_BASE)$(strip $2) $(3) \ + ATMOSPHERE_BUILD_TARGET_IDENTIFIER=$(strip $1)\ + ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX=$(strip $2)\ + DEPSDIR=$$(CURDIR)/$$(ATMOSPHERE_BUILD_DIR)/$(strip $1) \ + LIBEXOSPHERE_NAME=exosphere$(strip $2) \ + --no-print-directory -C $$(ATMOSPHERE_BUILD_DIR)/$(strip $1) \ + -f $$(THIS_MAKEFILE) + +check_libexo_$(strip $1): + @$$(MAKE) --no-print-directory -C $$(ATMOSPHERE_LIBRARIES_DIR)/libexosphere $$(ATMOSPHERE_ARCH_NAME)-$(strip $1) + +clean-$(strip $1): + @echo clean $(strip $1) ... + @rm -fr $$(ATMOSPHERE_BUILD_DIR)/$(strip $1) $$(OUTPUT_BASE)$(strip $2).bin $$(OUTPUT_BASE)$(strip $2).elf $$(OUTPUT_BASE)$(strip $2).lz4 boot_code$(strip $2).lz4 + +endef + +$(eval $(call ATMOSPHERE_ADD_TARGET, release, , \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS" \ +)) + +$(eval $(call ATMOSPHERE_ADD_TARGET, debug, _debug, \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_DEBUGGING" \ +)) + +$(eval $(call ATMOSPHERE_ADD_TARGET, audit, _audit, \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_AUDITING" \ +)) + +$(ATMOSPHERE_BUILD_DIR)/%: @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -check_libexo: - @$(MAKE) --no-print-directory -C ../../libraries/libexosphere arm64 - -check_firmwares: - @$(MAKE) -C $(TOPDIR)/sc7fw all - @$(MAKE) -C $(TOPDIR)/rebootstub all #--------------------------------------------------------------------------------- -clean: - @echo clean ... - @$(MAKE) -C $(TOPDIR)/sc7fw clean - @$(MAKE) -C $(TOPDIR)/rebootstub clean - @rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf *.lz4 +clean: $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),clean-$(config)) + +.PHONY: all clean $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),$(config) clean-$(config)) #--------------------------------------------------------------------------------- else -.PHONY: all DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- -all : $(OUTPUT).lz4 $(OUTPUT).lz4 : $(OUTPUT).bin - @python ../split_program.py $(OUTPUT).bin $(dir $(OUTPUT)) + @python $(TOPDIR)/split_program.py $(OUTPUT).bin $(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX) $(dir $(OUTPUT)) @echo built ... $(notdir $@) $(OUTPUT).bin : $(OUTPUT).elf $(OBJCOPY) -S -O binary --set-section-flags .bss=alloc,load,contents $< $@ @echo built ... $(notdir $@) -$(OUTPUT).elf : $(OFILES) ../../../libraries/libexosphere/$(ATMOSPHERE_LIBRARY_DIR)/libexosphere.a +$(OUTPUT).elf : $(OFILES) + +$(OFILES) : $(ATMOSPHERE_LIBRARIES_DIR)/libexosphere/$(ATMOSPHERE_LIBRARY_DIR)/lib$(LIBEXOSPHERE_NAME).a secmon_crt0_cpp.o secmon_make_page_table.o : CFLAGS += -fno-builtin +rebootstub.bin.o rebootstub_bin.h: $(TOPDIR)/rebootstub/rebootstub$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin + @echo $(notdir $<) + @rm -rf tmp_rebootstub_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + @mkdir -p tmp_rebootstub_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + @cp $(TOPDIR)/rebootstub/rebootstub$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin tmp_rebootstub_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER)/rebootstub.bin + @bin2s -a 8 -H rebootstub_bin.h tmp_rebootstub_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER)/rebootstub.bin | $(AS) -o rebootstub.bin.o + @rm -rf tmp_rebootstub_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + +$(TOPDIR)/rebootstub/rebootstub$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin: + @$(MAKE) --no-print-directory -C $(TOPDIR)/rebootstub $(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + +sc7fw.bin.o sc7fw_bin.h: $(TOPDIR)/sc7fw/sc7fw$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin + @echo $(notdir $<) + @rm -rf tmp_sc7fw_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + @mkdir -p tmp_sc7fw_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + @cp $(TOPDIR)/sc7fw/sc7fw$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin tmp_sc7fw_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER)/sc7fw.bin + @bin2s -a 8 -H sc7fw_bin.h tmp_sc7fw_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER)/sc7fw.bin | $(AS) -o sc7fw.bin.o + @rm -rf tmp_sc7fw_$(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + +$(TOPDIR)/sc7fw/sc7fw$(ATMOSPHERE_BUILD_TARGET_BINARY_SUFFIX).bin: + @$(MAKE) --no-print-directory -C $(TOPDIR)/sc7fw $(ATMOSPHERE_BUILD_TARGET_IDENTIFIER) + %.elf: @echo linking $(notdir $@) $(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ @$(NM) -CSn $@ > $(notdir $*.lst) -$(OFILES_SRC) : $(HFILES_BIN) +$(OFILES_SRC) : rebootstub_bin.h sc7fw_bin.h -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o %_bin.h: %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) -include $(DEPENDS) diff --git a/exosphere/program/source/secmon_error.cpp b/exosphere/program/source/secmon_error.cpp index 4c7d7752c..d025d5675 100644 --- a/exosphere/program/source/secmon_error.cpp +++ b/exosphere/program/source/secmon_error.cpp @@ -71,6 +71,8 @@ namespace ams::diag { secmon::ErrorReboot(); } + #include + } namespace ams::secmon { diff --git a/exosphere/program/split_program.py b/exosphere/program/split_program.py index e8806c16b..158aa6c69 100644 --- a/exosphere/program/split_program.py +++ b/exosphere/program/split_program.py @@ -19,17 +19,17 @@ def split_binary(data): boot_code = data[BOOT_CODE_START - START:BOOT_CODE_END - BOOT_CODE_START] program = data[PROGRAM_START - START:] - return [('boot_code.lz4', lz4_compress(boot_code)), ('program.lz4', lz4_compress(program))] + return [('boot_code%s.lz4', lz4_compress(boot_code)), ('program%s.lz4', lz4_compress(program))] def main(argc, argv): - if argc != 3: - print('Usage: %s in outdir' % argv[0]) + if argc != 4: + print('Usage: %s in suffix outdir' % argv[0]) return 1 with open(argv[1], 'rb') as f: data = f.read() assert len(data) >= 0x40 for (fn, fdata) in split_binary(data): - with open('%s/%s' % (argv[2], fn), 'wb') as f: + with open('%s/%s' % (argv[3], fn % argv[2]), 'wb') as f: f.write(fdata) return 0 diff --git a/libraries/libexosphere/arm.mk b/libraries/libexosphere/arm.mk index f6acfd8de..3b3abcd84 100644 --- a/libraries/libexosphere/arm.mk +++ b/libraries/libexosphere/arm.mk @@ -96,15 +96,15 @@ clean-$(strip $1): endef $(eval $(call ATMOSPHERE_ADD_TARGET, release, $(TARGET).a, \ - ATMOSPHERE_BUILD_SETTINGS="" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS " \ )) $(eval $(call ATMOSPHERE_ADD_TARGET, debug, $(TARGET)_debug.a, \ - ATMOSPHERE_BUILD_SETTINGS="-DAMS_BUILD_FOR_DEBUGGING" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_DEBUGGING" \ )) $(eval $(call ATMOSPHERE_ADD_TARGET, audit, $(TARGET)_audit.a, \ - ATMOSPHERE_BUILD_SETTINGS="-DAMS_BUILD_FOR_AUDITING" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_AUDITING" \ )) #--------------------------------------------------------------------------------- diff --git a/libraries/libexosphere/arm64.mk b/libraries/libexosphere/arm64.mk index f59111300..624a28bb5 100644 --- a/libraries/libexosphere/arm64.mk +++ b/libraries/libexosphere/arm64.mk @@ -96,15 +96,15 @@ clean-$(strip $1): endef $(eval $(call ATMOSPHERE_ADD_TARGET, release, $(TARGET).a, \ - ATMOSPHERE_BUILD_SETTINGS="" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS " \ )) $(eval $(call ATMOSPHERE_ADD_TARGET, debug, $(TARGET)_debug.a, \ - ATMOSPHERE_BUILD_SETTINGS="-DAMS_BUILD_FOR_DEBUGGING" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_DEBUGGING" \ )) $(eval $(call ATMOSPHERE_ADD_TARGET, audit, $(TARGET)_audit.a, \ - ATMOSPHERE_BUILD_SETTINGS="-DAMS_BUILD_FOR_AUDITING" \ + ATMOSPHERE_BUILD_SETTINGS="-DAMS_FORCE_DISABLE_DETAILED_ASSERTIONS -DAMS_BUILD_FOR_AUDITING" \ )) #--------------------------------------------------------------------------------- diff --git a/libraries/libexosphere/source/log/log_api.cpp b/libraries/libexosphere/source/log/log_api.cpp index 93ce0d7cd..068dddc20 100644 --- a/libraries/libexosphere/source/log/log_api.cpp +++ b/libraries/libexosphere/source/log/log_api.cpp @@ -68,7 +68,7 @@ namespace ams::log { SetupUart(); /* Initialize the target uart port. */ - uart::Initialize(UartLogPort, 115200, UartPortFlags); + uart::Initialize(UartLogPort, UartBaudRate, UartPortFlags); /* Note that we've initialized. */ g_initialized_uart = true; diff --git a/libraries/libvapours/include/vapours/common.hpp b/libraries/libvapours/include/vapours/common.hpp index 15060a031..b037b31d4 100644 --- a/libraries/libvapours/include/vapours/common.hpp +++ b/libraries/libvapours/include/vapours/common.hpp @@ -17,19 +17,23 @@ #include #include +#if defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS) && defined(AMS_FORCE_ENABLE_DETAILED_ASSERTIONS) + #error "Invalid detailed assertions state" +#endif + #ifdef AMS_BUILD_FOR_AUDITING -#define AMS_BUILD_FOR_DEBUGGING + #define AMS_BUILD_FOR_DEBUGGING -#if !defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS) - #define AMS_ENABLE_DETAILED_ASSERTIONS -#endif + #if !defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS) + #define AMS_ENABLE_DETAILED_ASSERTIONS + #endif #endif #ifdef AMS_BUILD_FOR_DEBUGGING -#define AMS_ENABLE_ASSERTIONS + #define AMS_ENABLE_ASSERTIONS #if !defined(AMS_ENABLE_DETAILED_ASSERTIONS) && !defined(AMS_FORCE_DISABLE_DETAILED_ASSERTIONS)