Skip to content

Commit

Permalink
Use devkitARM Makefile rules
Browse files Browse the repository at this point in the history
  • Loading branch information
angelsl committed Oct 30, 2017
1 parent 6f4eee6 commit 00d1fa6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
62 changes: 33 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,54 @@ endif
include $(DEVKITARM)/ds_rules

TARGET := dsfirmverify
BUILD := obj

CFILES := main.c aes/aes.c sha256.c
CFILES := main.c aes.c sha256.c
BINFILES := blowfish_retail.bin blowfish_dev.bin

ARCH := -marm
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g $(ARCH) -O2 -fdiagnostics-color=always -D_GNU_SOURCE -DARM9 \
-Wall -Wextra -pedantic -std=gnu11 \
-march=armv5te -mtune=arm946e-s \
-fomit-frame-pointer -ffast-math \
-ffunction-sections -fdata-sections \
-I$(LIBNDS)/include -Ilibncgc/include/
-I$(LIBNDS)/include -I$(TOPDIR)/libncgc/include
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(@).map \
-L$(LIBNDS)/lib -Llibncgc/out/ntr
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lnds9 -lncgc

# ------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))

OBJFILES := $(OBJFILES) $(patsubst %,obj/%.o,$(CFILES)) \
obj/blowfish_retail.bin.o obj/blowfish_dev.bin.o
export TOPDIR := $(CURDIR)

$(TARGET).nds: obj/$(TARGET).nds
@cp $^ $@
@echo Built $@
.PHONY: $(BUILD) libncgc clean

obj/$(TARGET).elf: $(OBJFILES) libncgc/out/ntr/libncgc.a
@echo Linking $@
@$(CC) $(LDFLAGS) -o $@ $(OBJFILES) $(LIBS)
$(BUILD): libncgc
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

obj/%.c.o: src/%.c
@mkdir -p $(dir $@)
@echo $^ =\> $@
@$(CC) -MMD -MP -MF obj/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
libncgc:
@$(MAKE) PLATFORM=ntr -C $(CURDIR)/libncgc

obj/%.bin.o: src/%.bin
@mkdir -p $(dir $@)
@echo $^ =\> $@
@$(PREFIX)ld -r -b binary $< -o $@
clean:
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds

libncgc/out/ntr/libncgc.a:
@$(MAKE) PLATFORM=ntr -C libncgc
else

clean:
@rm -vrf obj $(TARGET).nds
export LD := $(CC)
export VPATH := $(TOPDIR)/src $(TOPDIR)/src/aes
export OUTPUT := $(TOPDIR)/$(TARGET)
export DEPSDIR := $(TOPDIR)/$(BUILD)
export OFILES := $(BINFILES:.bin=.o) $(CFILES:.c=.o)
export LIBPATHS := -L$(LIBNDS)/lib -L$(TOPDIR)/libncgc/out/ntr
DEPENDS := $(OFILES:.o=.d)

$(OUTPUT).nds: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

.PHONY: clean
%.o: %.bin
@echo $(notdir $<)
$(bin2o)

-include $(patsubst %,obj/%.d,$(CFILES))
-include $(DEPENDS)

endif
2 changes: 1 addition & 1 deletion libncgc
7 changes: 2 additions & 5 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ const char signature_dev[] = { 0x18, 0x72, 0x2B, 0xC7, 0x6D, 0xC3, 0x60, 0x2E, 0
const char aeskey_retail[] = { 0x07, 0x55, 0x0C, 0x97, 0x0C, 0x3D, 0xBD, 0x9E, 0xDD, 0xA9, 0xFB, 0x5D, 0x4C, 0x7F, 0xB7, 0x13 };
const char aeskey_dev[] = { 0x4D, 0xAD, 0x21, 0x24, 0xC2, 0xD3, 0x29, 0x73, 0x10, 0x0F, 0xBF, 0xBD, 0x16, 0x04, 0xC6, 0xF1 };

extern char _binary_src_blowfish_retail_bin_start;
extern char _binary_src_blowfish_dev_bin_start;

const char *blowfish_retail = &_binary_src_blowfish_retail_bin_start;
const char *blowfish_dev = &_binary_src_blowfish_dev_bin_start;
extern const char blowfish_retail_bin[];
extern const char blowfish_dev_bin[];

_Static_assert(sizeof(signature_retail) == 0x100, "Wrong signature_retail size");
_Static_assert(sizeof(signature_dev) == 0x100, "Wrong signature_dev size");
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int main(void) {
}
}

const char *const blowfish_key = dev ? blowfish_dev : blowfish_retail;
const char *const blowfish_key = dev ? blowfish_dev_bin : blowfish_retail_bin;
const char *const signature = dev ? signature_dev : signature_retail;
const char *const aes_key = dev ? aeskey_dev : aeskey_retail;

Expand Down

0 comments on commit 00d1fa6

Please sign in to comment.