meso: commit wip (thanks fincs) rewrite to support build targets

This commit is contained in:
Michael Scire 2020-10-27 11:48:59 -07:00
parent 1c71d12d9d
commit a8a90e6324
4 changed files with 91 additions and 53 deletions

View file

@ -15,8 +15,10 @@ endif
endif endif
ATMOSPHERE_BUILD_SETTINGS ?=
export ATMOSPHERE_DEFINES := -DATMOSPHERE export ATMOSPHERE_DEFINES := -DATMOSPHERE
export ATMOSPHERE_SETTINGS := -fPIE -g export ATMOSPHERE_SETTINGS := -fPIE -g $(ATMOSPHERE_BUILD_SETTINGS)
export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \
-fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector \ -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector \
-Wno-format-truncation -Wno-format-zero-length -Wno-stringop-truncation -Wno-format-truncation -Wno-format-zero-length -Wno-stringop-truncation
@ -132,10 +134,11 @@ FIND_SOURCE_FILES=$(foreach dir,$1,$(filter-out $(notdir $(wildcard $(dir)/*.arc
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),os,$(ATMOSPHERE_OS_NAME),$2)) \ $(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),os,$(ATMOSPHERE_OS_NAME),$2)) \
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES_EX,$(dir),cpu,$(ATMOSPHERE_CPU_NAME) $(ATMOSPHERE_CPU_EXTENSIONS),$2)) $(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES_EX,$(dir),cpu,$(ATMOSPHERE_CPU_NAME) $(ATMOSPHERE_CPU_EXTENSIONS),$2))
ATMOSPHERE_GCH_IDENTIFIER ?= ams_placeholder_gch_identifier
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# Rules for compiling pre-compiled headers # Rules for compiling pre-compiled headers
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.gch: %.hpp %.hpp.gch/$(ATMOSPHERE_GCH_IDENTIFIER): %.hpp %.hpp.gch
@echo $< $(SILENTMSG) Precompiling $(notdir $<) for $(ATMOSPHERE_GCH_IDENTIFIER)
$(CXX) -w -x c++-header -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER) $(SILENTCMD)$(CXX) -w -x c++-header -MMD -MP -MQ$@ -MF $(DEPSDIR)/$(notdir $*).d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
@cp $@ $(<).gch

View file

@ -1,12 +1,14 @@
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# pull in common atmosphere configuration # pull in common atmosphere configuration
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../config/common.mk THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIRECTORY := $(abspath $(dir $(THIS_MAKEFILE)))
include $(CURRENT_DIRECTORY)/../config/common.mk
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
PRECOMPILED_HEADERS := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/include/mesosphere.hpp PRECOMPILED_HEADERS := include/mesosphere.hpp
DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE
SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Wextra -Werror -fno-non-call-exceptions SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Wextra -Werror -fno-non-call-exceptions
@ -28,7 +30,7 @@ LIBDIRS := $(ATMOSPHERE_LIBRARIES_DIR)/libvapours
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional
# rules for different file extensions # rules for different file extensions
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR))) ifneq ($(__RECURSIVE__),1)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) $(CURDIR)/include \ export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) $(CURDIR)/include \
@ -54,7 +56,7 @@ endif
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export GCH_FILES := $(foreach hdr,$(PRECOMPILED_HEADERS:.hpp=.gch),$(notdir $(hdr))) export GCH_DIRS := $(PRECOMPILED_HEADERS:.hpp=.hpp.gch)
export OFILES := $(OFILES_BIN) $(OFILES_SRC) export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
@ -62,41 +64,64 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I. -I.
.PHONY: clean all #---------------------------------------------------------------------------------
ATMOSPHERE_BUILD_CONFIGS :=
all: release
define ATMOSPHERE_ADD_TARGET
ATMOSPHERE_BUILD_CONFIGS += $(strip $1)
$(strip $1): $$(ATMOSPHERE_LIBRARY_DIR)/$(strip $2)
$$(ATMOSPHERE_LIBRARY_DIR)/$(strip $2) : $$(ATMOSPHERE_LIBRARY_DIR) $$(ATMOSPHERE_BUILD_DIR)/$(strip $1) $$(SOURCES) $$(INCLUDES) $$(GCH_DIRS)
@$$(MAKE) __RECURSIVE__=1 OUTPUT=$$(CURDIR)/$$@ $(3) \
ATMOSPHERE_GCH_IDENTIFIER="$$(ATMOSPHERE_BOARD_NAME)_$$(ATMOSPHERE_ARCH_NAME)_$(strip $1)" \
DEPSDIR=$$(CURDIR)/$$(ATMOSPHERE_BUILD_DIR)/$(strip $1) \
--no-print-directory -C $$(ATMOSPHERE_BUILD_DIR)/$(strip $1) \
-f $$(THIS_MAKEFILE)
endef
$(eval $(call ATMOSPHERE_ADD_TARGET, release, $(TARGET).a, \
ATMOSPHERE_BUILD_SETTINGS="" \
))
$(eval $(call ATMOSPHERE_ADD_TARGET, debug, $(TARGET)_debug.a, \
ATMOSPHERE_BUILD_SETTINGS="-DMESOSPHERE_BUILD_FOR_DEBUGGING" \
))
$(eval $(call ATMOSPHERE_ADD_TARGET, audit, $(TARGET)_audit.a, \
ATMOSPHERE_BUILD_SETTINGS="-DMESOSPHERE_BUILD_FOR_AUDITING" \
))
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
all: lib/$(TARGET).a
lib: -include $(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME).mk
ALL_GCH_IDENTIFIERS := $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)_$(config))
ALL_GCH_FILES := $(foreach hdr,$(PRECOMPILED_HEADERS:.hpp=.hpp.gch),$(foreach id,$(ALL_GCH_IDENTIFIERS),$(hdr)/$(id)))
.PHONY: clean all $(ATMOSPHERE_BUILD_CONFIGS)
$(ATMOSPHERE_LIBRARY_DIR) $(GCH_DIRS):
@[ -d $@ ] || mkdir -p $@ @[ -d $@ ] || mkdir -p $@
release: $(ATMOSPHERE_BUILD_DIR)/%:
@[ -d $@ ] || mkdir -p $@ @[ -d $@ ] || mkdir -p $@
lib/$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
dist-bin: all
@tar --exclude=*~ -cjf $(TARGET).tar.bz2 include lib
dist-src:
@tar --exclude=*~ -cjf $(TARGET)-src.tar.bz2 include source Makefile
dist: dist-src dist-bin
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @echo clean ...
@rm -fr release lib *.bz2 @rm -fr $(ATMOSPHERE_BUILD_DIR) $(ATMOSPHERE_LIBRARY_DIR) *.bz2 $(ALL_GCH_FILES)
@for i in $(GCH_DIRS); do [ -d $$i ] && rmdir --ignore-fail-on-non-empty $$i || true; done
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else
DEPENDS := $(OFILES:.o=.d) $(GCH_FILES:.gch=.d) GCH_FILES := $(foreach hdr,$(PRECOMPILED_HEADERS:.hpp=.hpp.gch),$(CURRENT_DIRECTORY)/$(hdr)/$(ATMOSPHERE_GCH_IDENTIFIER))
DEPENDS := $(OFILES:.o=.d) $(foreach hdr,$(GCH_FILES),$(notdir $(patsubst %.hpp.gch/,%.d,$(dir $(hdr)))))
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# main targets # main targets

View file

@ -1,26 +1,36 @@
TARGETS := kernel.bin kernel_ldr.bin ATMOSPHERE_BUILD_CONFIGS :=
CLEAN_TARGETS := $(foreach target,$(TARGETS),$(target:.bin=)-clean) all: release
SUBFOLDERS := $(MODULES) define ATMOSPHERE_ADD_TARGET
all: mesosphere.bin ATMOSPHERE_BUILD_CONFIGS += $(strip $1)
clean: $(CLEAN_TARGETS) $(strip $1): mesosphere$(strip $2).bin
@rm -f mesosphere.bin
mesosphere.bin: $(TARGETS) mesosphere$(strip $2).bin: kernel/kernel$(strip $2).bin kernel_ldr/kernel_ldr$(strip $2).bin
@python build_mesosphere.py @python build_mesosphere.py kernel/kernel$(strip $2).bin kernel_ldr/kernel_ldr$(strip $2).bin mesosphere$(strip $2).bin
@echo "Built mesosphere.bin..." @echo "Built mesosphere$(strip $2).bin..."
$(TARGETS): check_libmeso kernel/kernel$(strip $2).bin: check_libmeso$(strip $1)
$(MAKE) -C $(@:.bin=) @$$(MAKE) -C kernel $(strip $1)
@cp $(@:.bin=)/$(@) $(@)
check_libmeso: kernel_ldr/kernel_ldr$(strip $2).bin: check_libmeso$(strip $1)
@$(MAKE) --no-print-directory -C ../libraries/libmesosphere @$$(MAKE) -C kernel_ldr $(strip $1)
$(CLEAN_TARGETS): check_libmeso$(strip $1):
$(MAKE) -C $(@:-clean=) clean @$$(MAKE) -C ../libraries/libmesosphere $(strip $1)
@rm -f $(@:-clean=).bin
.PHONY: all clean $(CLEAN_TARGETS) $(strip $1)-clean:
@$$(MAKE) -C kernel $(strip $1)-clean
@$$(MAKE) -C kernel_ldr $(strip $1)-clean
@rm -f mesosphere$(strip $2).bin
endef
$(eval $(call ATMOSPHERE_ADD_TARGET, release, ,))
$(eval $(call ATMOSPHERE_ADD_TARGET, debug, _debug,))
$(eval $(call ATMOSPHERE_ADD_TARGET, audit, _audit,))
clean: $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),$(config)-clean)
.PHONY: all clean $(ATMOSPHERE_BUILD_CONFIGS) $(foreach config,$(ATMOSPHERE_BUILD_CONFIGS),$(target)-clean)

View file

@ -11,12 +11,12 @@ def align_up(val, algn):
def main(argc, argv): def main(argc, argv):
if argc != 1: if argc != 4:
print('Usage: %s' % argv[0]) print('Usage: %s kernel_ldr.bin kernel.bin output.bin' % argv[0])
return 1 return 1
with open('kernel_ldr/kernel_ldr.bin', 'rb') as f: with open(argv[1], 'rb') as f:
kernel_ldr = f.read() kernel_ldr = f.read()
with open('kernel/kernel.bin', 'rb') as f: with open(argv[2], 'rb') as f:
kernel = f.read() kernel = f.read()
kernel_metadata_offset = 4 kernel_metadata_offset = 4
assert (kernel_metadata_offset <= len(kernel) - 0x40) assert (kernel_metadata_offset <= len(kernel) - 0x40)
@ -37,7 +37,7 @@ def main(argc, argv):
kernel_ldr_end = kernel_ldr_offset + len(kernel_ldr) kernel_ldr_end = kernel_ldr_offset + len(kernel_ldr)
mesosphere_end = align_up(kernel_ldr_end, 0x1000) mesosphere_end = align_up(kernel_ldr_end, 0x1000)
with open('mesosphere.bin', 'wb') as f: with open(argv[3], 'wb') as f:
f.write(kernel[:kernel_metadata_offset + 4]) f.write(kernel[:kernel_metadata_offset + 4])
f.write(pk('<QQI', embedded_ini_offset, kernel_ldr_offset, atmosphere_target_firmware(10, 1, 0))) f.write(pk('<QQI', embedded_ini_offset, kernel_ldr_offset, atmosphere_target_firmware(10, 1, 0)))
f.write(kernel[kernel_metadata_offset + 0x18:]) f.write(kernel[kernel_metadata_offset + 0x18:])