Skip to content

Commit

Permalink
Embed the VRAM tar data in the ARM9 executable (#824)
Browse files Browse the repository at this point in the history
* Embed the VRAM tar data in the ARM9 executable

* Fix Makefile dependency order

* Use address difference instead of absolute word for the VRAM drive limit
  • Loading branch information
Wolfvak authored Jul 24, 2023
1 parent 8b362c9 commit 031762a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export RELDIR := release
export COMMON_DIR := ../common

# Definitions for initial RAM disk
VRAM_OUT := $(OUTDIR)/vram0.tar
VRAM_TAR := $(OUTDIR)/vram0.tar
VRAM_DATA := data
VRAM_FLAGS := --make-new --path-limit 99 --size-limit 228864
VRAM_FLAGS := --make-new --path-limit 99 --size-limit 262144
ifeq ($(NTRBOOT),1)
VRAM_SCRIPTS := resources/gm9/scripts
endif
Expand All @@ -44,14 +44,14 @@ export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSIO
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096
ELF := arm9/arm9.elf arm11/arm11.elf

.PHONY: all firm vram0 elf release clean
.PHONY: all firm $(VRAM_TAR) elf release clean
all: firm

clean:
@set -e; for elf in $(ELF); do \
$(MAKE) --no-print-directory -C $$(dirname $$elf) clean; \
done
@rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_OUT)
@rm -rf $(OUTDIR) $(RELDIR) $(FIRM) $(FIRMD) $(VRAM_TAR)

unmarked_readme: .FORCE
@$(PY3) utils/unmark.py -f README.md data/README_internal.md
Expand Down Expand Up @@ -80,24 +80,27 @@ release: clean unmarked_readme

@-7za a $(RELDIR)/$(FLAVOR)-$(VERSION)-$(DBUILTS).zip ./$(RELDIR)/*

vram0:
@mkdir -p "$(OUTDIR)"
@echo "Creating $(VRAM_OUT)"
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_OUT) $(shell ls -d $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA)/* $(VRAM_SCRIPTS))
$(VRAM_TAR): $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA) $(VRAM_SCRIPTS)
@mkdir -p "$(@D)"
@echo "Creating $@"
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_TAR) $(shell find $^ -type f)

%.elf: .FORCE
@echo "Building $@"
@$(MAKE) --no-print-directory -C $(@D)

firm: $(ELF) vram0
@test `wc -c <$(VRAM_OUT)` -le 228864
arm9/arm9.elf: $(VRAM_TAR)

firm: $(ELF)
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
@echo "[FLAVOR] $(FLAVOR)"
@echo "[VERSION] $(VERSION)"
@echo "[BUILD] $(DBUILTL)"
@echo "[FIRM] $(FIRM)"
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -A 0x80C0000 -D $(ELF) $(VRAM_OUT) -C NDMA XDMA memcpy
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA XDMA
@echo "[FIRM] $(FIRMD)"
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -A 0x80C0000 -D $(ELF) $(VRAM_OUT) -C NDMA XDMA memcpy
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA XDMA

vram0: $(VRAM_TAR) .FORCE # legacy target name

.FORCE:
8 changes: 5 additions & 3 deletions arm9/source/system/vram0.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
#define VRAM0_EASTER_BIN "easter.bin"


#define VRAM0_OFFSET 0x080C0000
#define VRAM0_LIMIT 0x00040000
extern const char vram_data[];
extern const char vram_data_end[];

#define VRAM0_OFFSET (uintptr_t)(vram_data)
#define VRAM0_LIMIT (uintptr_t)(vram_data_end - vram_data)

#define TARDATA ((void*) VRAM0_OFFSET)
#define TARDATA_(off) ((void*) (u32) (VRAM0_OFFSET + (off)))
#define TARDATA_END TARDATA_(VRAM0_LIMIT)


#define CheckVram0Tar() \
(ValidateTarHeader(TARDATA, TARDATA_END) == 0)

Expand Down
8 changes: 8 additions & 0 deletions arm9/source/system/vram_data.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.section .rodata.vram_data

.align 2
.global vram_data
vram_data:
.incbin "../output/vram0.tar"
.global vram_data_end
vram_data_end:

0 comments on commit 031762a

Please sign in to comment.