exo: use #embed for loader stub

This commit is contained in:
Michael Scire 2025-05-04 13:23:19 -07:00 committed by SciresM
parent 2c50ef717a
commit 66acab02db
3 changed files with 21 additions and 29 deletions

View file

@ -15,13 +15,12 @@ ifneq ($(__RECURSIVE__),1)
export ATMOSPHERE_TOPDIR := $(CURRENT_DIRECTORY)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) $(CURDIR)/include \
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(CURRENT_DIRECTORY)/../program/$(ATMOSPHERE_OUT_DIR)
$(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 := program.lz4 boot_code.lz4
BINFILES :=
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
@ -102,13 +101,7 @@ $(OUTPUT).elf : $(OFILES)
$(OFILES) : $(ATMOSPHERE_LIBRARIES_DIR)/libexosphere/$(ATMOSPHERE_LIBRARY_DIR)/libexosphere.a
program.lz4.o: program.lz4
@echo $(notdir $<)
@$(bin2o)
boot_code.lz4.o: boot_code.lz4
@echo $(notdir $<)
@$(bin2o)
secmon_loader_main.o: CXXFLAGS += --embed-dir="$(CURRENT_DIRECTORY)/../program/$(ATMOSPHERE_OUT_DIR)/"
%.elf:
@echo linking $(notdir $@)
@ -117,14 +110,6 @@ boot_code.lz4.o: boot_code.lz4
$(OFILES_SRC) : $(OFILES_BIN)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h: %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------

View file

@ -15,21 +15,31 @@
*/
#include <exosphere.hpp>
#include "secmon_loader_uncompress.hpp"
#include "program_lz4.h"
#include "boot_code_lz4.h"
namespace ams::secmon::loader {
NORETURN void UncompressAndExecute(const void *program, const void *boot_code) {
namespace {
constexpr const u8 SecmonProgramLz4[] = {
#embed <program.lz4>
};
constexpr const u8 SecmonBootCodeLz4[] = {
#embed <boot_code.lz4>
};
}
NORETURN void UncompressAndExecute() {
/* Uncompress the program image. */
Uncompress(secmon::MemoryRegionPhysicalTzramFullProgramImage.GetPointer(), secmon::MemoryRegionPhysicalTzramFullProgramImage.GetSize(), program, program_lz4_size);
Uncompress(secmon::MemoryRegionPhysicalTzramFullProgramImage.GetPointer(), secmon::MemoryRegionPhysicalTzramFullProgramImage.GetSize(), SecmonProgramLz4, sizeof(SecmonProgramLz4));
/* Copy the boot image to the end of IRAM */
u8 *relocated_boot_code = secmon::MemoryRegionPhysicalIramBootCodeImage.GetEndPointer<u8>() - boot_code_lz4_size;
std::memcpy(relocated_boot_code, boot_code, boot_code_lz4_size);
u8 *relocated_boot_code = secmon::MemoryRegionPhysicalIramBootCodeImage.GetEndPointer<u8>() - sizeof(SecmonBootCodeLz4);
std::memcpy(relocated_boot_code, SecmonBootCodeLz4, sizeof(SecmonBootCodeLz4));
/* Uncompress the boot image. */
Uncompress(secmon::MemoryRegionPhysicalIramBootCodeImage.GetPointer(), secmon::MemoryRegionPhysicalIramBootCodeImage.GetSize(), relocated_boot_code, boot_code_lz4_size);
Uncompress(secmon::MemoryRegionPhysicalIramBootCodeImage.GetPointer(), secmon::MemoryRegionPhysicalIramBootCodeImage.GetSize(), relocated_boot_code, sizeof(SecmonBootCodeLz4));
/* Jump to the boot image. */
reinterpret_cast<void (*)()>(secmon::MemoryRegionPhysicalIramBootCodeImage.GetAddress())();

View file

@ -98,8 +98,5 @@ _start:
ldr x20, =0x7C020000
mov sp, x20
adr x0, program_lz4
adr x1, boot_code_lz4
/* Uncompress the program and iram boot code images. */
b _ZN3ams6secmon6loader20UncompressAndExecuteEPKvS3_
b _ZN3ams6secmon6loader20UncompressAndExecuteEv