From ec1f149fc83c2e6554f414279bd224fb3b479ada Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 17 Apr 2020 13:38:38 -0400 Subject: add metrowerk assembler patcher and automate it during the build. --- Makefile | 21 ++++++++++ tools/Makefile | 4 ++ tools/mwasmarm_patcher/mwasmarm_patcher.c | 70 +++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/mwasmarm_patcher/mwasmarm_patcher.c diff --git a/Makefile b/Makefile index fac3e52f..06087477 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,12 @@ default: all +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + ################ Target Executable and Sources ############### BUILD_DIR := build @@ -24,6 +30,14 @@ S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s)) # Object files O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \ $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \ + +################### Universal Dependencies ################### + +# Make tools if out of date +DUMMY != make -s -C tools >&2 || echo FAIL +ifeq ($(DUMMY),FAIL) + $(error Failed to build tools) +endif ##################### Compiler Options ####################### @@ -57,10 +71,17 @@ CFLAGS = -O4,p -proc v5te -thumb -fp soft -lang c -Cpp_exceptions off -interwork # DS TOOLS TOOLS_DIR = tools SHA1SUM = sha1sum +MWASMARM_PATCHER = tools/mwasmarm_patcher/mwasmarm_patcher$(EXE) + +DUMMY != $(MWASMARM_PATCHER) $(MWASMARM) || echo FAIL +ifeq ($(DUMMY),FAIL) + $(error MWASMARM patcher returned an error) +endif ######################### Targets ########################### all: $(ROM) + $(info Test) @$(SHA1SUM) -c $(TARGET).sha1 clean: diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 00000000..5a9eeb69 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,4 @@ +all: mwasmarm_patcher + +mwasmarm_patcher: mwasmarm_patcher/mwasmarm_patcher.c + gcc mwasmarm_patcher/mwasmarm_patcher.c -o mwasmarm_patcher/mwasmarm_patcher -lssl -lcrypto diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c new file mode 100644 index 00000000..0d7470df --- /dev/null +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include + +// mwasmarm patcher v1.0 +// Patches the Metrowerk C compiler assembler to stop the line ending bug. + +char mwasmarm_unpatched_sha1[] = "9d63877c776245129b4727b41d3e9e63cfc9cd28"; +char mwasmarm_patched_sha1[] = "f5dea73bf90791e104cb59458bebae8b08a55484"; + +void fatal_printf(char *str, ...) { + va_list args; + va_start(args, str); + vprintf(str, args); + va_end(args); + exit(1); +} + +// return size in bytes +int get_file_size (FILE * fp) { + int curpos = ftell(fp); + fseek(fp, 0, SEEK_END); + int result = ftell(fp); + fseek(fp, curpos, SEEK_SET); + return result; +} + +void print_help(void) { + printf("mwasmarm patcher usage: input (example: mwasmarm_patcher mwasmarm.exe)\n"); +} + +int main(int argc, char *argv[]) { + unsigned char temp[SHA_DIGEST_LENGTH]; + char buf[SHA_DIGEST_LENGTH*2]; + + if (argc != 2) { + print_help(); + } else { + // Open the file and sha1 read it. + FILE *f = fopen(argv[1], "rb+"); + if(f == NULL) { + fatal_printf("ERROR: No file detected\n"); + } + int fsize = get_file_size(f); + char *string = malloc(fsize + 1); + fread(string, 1, fsize, f); + + // Check if sha1 matches either known assembler hashes. + SHA1(string, fsize, temp); + + for (int i=0; i < SHA_DIGEST_LENGTH; i++) { + sprintf((char*)&(buf[i*2]), "%02x", temp[i]); + } + + if(!strcmp(buf, mwasmarm_unpatched_sha1)) { + // Unpatched, perform the patch. + fseek(f, 0x57644, SEEK_SET); + fputc(0x05, f); + printf("Supported unpatched version detected: assembler patched\n"); + } else if(!strcmp(buf, mwasmarm_patched_sha1)) { + printf("Supported patched version detected: no action needed\n"); + } else { + fatal_printf("ERROR: Unsupported mwasmarm.exe version\n"); + } + } + return 0; +} -- cgit v1.2.3 From 1c3d43b94ccb8d2bd60df4d7c2d5c3b9963920ac Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 17 Apr 2020 13:43:01 -0400 Subject: fixes --- INSTALL.md | 10 ++++++++++ Makefile | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 05073d81..482e2232 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,6 +8,16 @@ The build system requires the use of the Metrowerk C Compiler 2.0/base to compil In the future, a GCC option will be available so MWCC is not required to build, however it is required for a matching ROM. +#### 3. Dependencies + +Building the ROM requires the following packages: + +* make +* git +* build-essentials +* libssl-dev +* binutils-arm-linux-gnueabi + #### 3. Build ROM Run `make` to build the ROM. \ No newline at end of file diff --git a/Makefile b/Makefile index 06087477..cd726fe7 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,6 @@ endif ######################### Targets ########################### all: $(ROM) - $(info Test) @$(SHA1SUM) -c $(TARGET).sha1 clean: -- cgit v1.2.3 From a238294da9efc1116921db001bd786c4f522c9a1 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Fri, 17 Apr 2020 13:43:35 -0400 Subject: INSTALL.md numbering --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 482e2232..4dc41576 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,6 +18,6 @@ Building the ROM requires the following packages: * libssl-dev * binutils-arm-linux-gnueabi -#### 3. Build ROM +#### 4. Build ROM Run `make` to build the ROM. \ No newline at end of file -- cgit v1.2.3 From 6446890d29234348c6af89982db4a4d8518855d4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Apr 2020 00:00:48 -0400 Subject: tidy up dependencies and tweak Makefile to show tool being ran once at start --- INSTALL.md | 14 ++++++++++---- Makefile | 10 ++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4dc41576..29c650d8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,14 +1,16 @@ -#### 1. Copy baserom(s) into root folder +### 1. Copy baserom(s) into root folder Put a clean copy of Pokemon Diamond (US) nds rom at `./baserom.us.nds`. -#### 2. Install MWCC compiler +### 2. Install MWCC compiler The build system requires the use of the Metrowerk C Compiler 2.0/base to compile matching files. We cannot distribute the correct compiler here so join the PRET discord and download the pinned mwccarm.zip zip in #pokediamond and extract it to tools/. Run each of the executables so they ask for a license.dat and provide the one in the rar (it may also ask for it when compiling). This only needs to be done once. In the future, a GCC option will be available so MWCC is not required to build, however it is required for a matching ROM. -#### 3. Dependencies +### 3. Dependencies + +#### Linux Building the ROM requires the following packages: @@ -18,6 +20,10 @@ Building the ROM requires the following packages: * libssl-dev * binutils-arm-linux-gnueabi -#### 4. Build ROM +#### Windows + +TODO + +### 4. Build ROM Run `make` to build the ROM. \ No newline at end of file diff --git a/Makefile b/Makefile index cd726fe7..0b43fef2 100644 --- a/Makefile +++ b/Makefile @@ -73,11 +73,6 @@ TOOLS_DIR = tools SHA1SUM = sha1sum MWASMARM_PATCHER = tools/mwasmarm_patcher/mwasmarm_patcher$(EXE) -DUMMY != $(MWASMARM_PATCHER) $(MWASMARM) || echo FAIL -ifeq ($(DUMMY),FAIL) - $(error MWASMARM patcher returned an error) -endif - ######################### Targets ########################### all: $(ROM) @@ -86,12 +81,15 @@ all: $(ROM) clean: $(RM) -r $(BUILD_DIR) +patch_mwasmarm: + $(MWASMARM_PATCHER) $(MWASMARM) + ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS)) $(BUILD_DIR)/%.o: %.c $(CC) -c $(CFLAGS) -o $@ $< -$(BUILD_DIR)/%.o: %.s +$(BUILD_DIR)/%.o: %.s patch_mwasmarm $(AS) $(ASFLAGS) $< -o $@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) -- cgit v1.2.3 From 79400db47a44201382e0b7bd2be3150e5d47687c Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Apr 2020 13:09:22 -0400 Subject: update patcher tool to support multiple definitions. --- tools/mwasmarm_patcher/mwasmarm_patcher.c | 70 ++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c index 0d7470df..41271ae5 100644 --- a/tools/mwasmarm_patcher/mwasmarm_patcher.c +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -5,11 +5,49 @@ #include #include -// mwasmarm patcher v1.0 +// mwasmarm patcher v1.1 // Patches the Metrowerk C compiler assembler to stop the line ending bug. -char mwasmarm_unpatched_sha1[] = "9d63877c776245129b4727b41d3e9e63cfc9cd28"; -char mwasmarm_patched_sha1[] = "f5dea73bf90791e104cb59458bebae8b08a55484"; +// Changelog: +// v1.1: Added patch definitions and looped over them to find the matching +// definition as well as the version. + +struct PatchDef { + char *version; + char *sha1before; + char *sha1after; + int offsetPatch; + int newByte; +}; + +struct PatchDef gPatchDefs[] = { + // mwasmarm 1.2/base definition + { + "mwasmarm 1.2/base", + "87f942cc0a0e90e73550d8d6f3fffcdeb5f69fa5", + "2f1ccff22eaa443bb79235ca6477d3b86bdfd7e4", + 0x57614, + 0x5 + }, + // mwasmarm 2.0/base definition + { + "mwasmarm 2.0/base", + "9d63877c776245129b4727b41d3e9e63cfc9cd28", + "f5dea73bf90791e104cb59458bebae8b08a55484", + 0x57644, + 0x5 + }, + // mwasmarm 2.0/sp2p4 definition + { + "mwasmarm 2.0/sp2p4", + "448cb0c7f1ace4393e9a9562f819f7a9f049be83", + "c82161527277b991a1b77e14617a93bcd19cf95c", + 0x57834, + 0x5 + }, + { + } +}; void fatal_printf(char *str, ...) { va_list args; @@ -38,6 +76,7 @@ int main(int argc, char *argv[]) { if (argc != 2) { print_help(); + return 1; } else { // Open the file and sha1 read it. FILE *f = fopen(argv[1], "rb+"); @@ -47,24 +86,27 @@ int main(int argc, char *argv[]) { int fsize = get_file_size(f); char *string = malloc(fsize + 1); fread(string, 1, fsize, f); - + // Check if sha1 matches either known assembler hashes. SHA1(string, fsize, temp); for (int i=0; i < SHA_DIGEST_LENGTH; i++) { sprintf((char*)&(buf[i*2]), "%02x", temp[i]); } - - if(!strcmp(buf, mwasmarm_unpatched_sha1)) { - // Unpatched, perform the patch. - fseek(f, 0x57644, SEEK_SET); - fputc(0x05, f); - printf("Supported unpatched version detected: assembler patched\n"); - } else if(!strcmp(buf, mwasmarm_patched_sha1)) { - printf("Supported patched version detected: no action needed\n"); - } else { - fatal_printf("ERROR: Unsupported mwasmarm.exe version\n"); + + for(int i = 0; gPatchDefs[i].sha1before != NULL; i++) { + // check if already patched for the current loop. + if(!strcmp(buf, gPatchDefs[i].sha1after)) { + printf("Supported patched version detected (%s): no action needed\n", gPatchDefs[i].version); + return 0; + } else if(!strcmp(buf, gPatchDefs[i].sha1before)) { + fseek(f, gPatchDefs[i].offsetPatch, SEEK_SET); + fputc(gPatchDefs[i].newByte, f); + printf("Supported unpatched version detected (%s): assembler patched\n", gPatchDefs[i].version); + return 0; + } } + fatal_printf("ERROR: Unsupported mwasmarm.exe version\n"); } return 0; } -- cgit v1.2.3 From 5f1318919376ec679f5300257b41b28dc68e6f4f Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Apr 2020 13:51:39 -0400 Subject: update mwasmarm_patcher to get rid of libssl dependency. --- INSTALL.md | 1 - Makefile | 4 +- tools/Makefile | 4 -- tools/mwasmarm_patcher/Makefile | 7 +++ tools/mwasmarm_patcher/mwasmarm_patcher.c | 94 ++++++++++++++++++++++++++++--- 5 files changed, 95 insertions(+), 15 deletions(-) delete mode 100644 tools/Makefile create mode 100644 tools/mwasmarm_patcher/Makefile diff --git a/INSTALL.md b/INSTALL.md index 29c650d8..76059419 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -17,7 +17,6 @@ Building the ROM requires the following packages: * make * git * build-essentials -* libssl-dev * binutils-arm-linux-gnueabi #### Windows diff --git a/Makefile b/Makefile index 0b43fef2..3a21944c 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \ ################### Universal Dependencies ################### # Make tools if out of date -DUMMY != make -s -C tools >&2 || echo FAIL +DUMMY != make -s -C tools/mwasmarm_patcher >&2 || echo FAIL ifeq ($(DUMMY),FAIL) $(error Failed to build tools) endif @@ -96,7 +96,7 @@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $< $(ELF): $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) - $(LD) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) -nodead -w off + $(LD) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) -nodead -w off -interworking $(ROM): $(ELF) $(OBJCOPY) -O binary $< $@ diff --git a/tools/Makefile b/tools/Makefile deleted file mode 100644 index 5a9eeb69..00000000 --- a/tools/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: mwasmarm_patcher - -mwasmarm_patcher: mwasmarm_patcher/mwasmarm_patcher.c - gcc mwasmarm_patcher/mwasmarm_patcher.c -o mwasmarm_patcher/mwasmarm_patcher -lssl -lcrypto diff --git a/tools/mwasmarm_patcher/Makefile b/tools/mwasmarm_patcher/Makefile new file mode 100644 index 00000000..5cf20ee4 --- /dev/null +++ b/tools/mwasmarm_patcher/Makefile @@ -0,0 +1,7 @@ +CC := gcc +CFLAGS := -O3 + +all: mwasmarm_patcher + +mwasmarm_patcher: mwasmarm_patcher.c + $(CC) $(CFLAGS) -o $@ $< -lssl -lcrypto diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c index 41271ae5..1330e650 100644 --- a/tools/mwasmarm_patcher/mwasmarm_patcher.c +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -49,6 +48,76 @@ struct PatchDef gPatchDefs[] = { } }; +void sha1_process_block (const unsigned char * block, uint32_t * state); + +// Credit to ax6 for implementation +unsigned char * calculate_sha1 (const void * data, unsigned length) { + uint32_t state[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0}; + const char * current; + unsigned remaining; + for (current = data, remaining = length; remaining >= 64; current += 64, remaining -= 64) sha1_process_block(current, state); + // technically only {0} is necessary, but better safe than sorry + unsigned char last_block[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + memcpy(last_block, current, remaining); + last_block[remaining] = 0x80; + if (remaining >= 56) { + sha1_process_block(last_block, state); + memset(last_block, 0, 64); + } + unsigned long long bit_length = ((unsigned long long) length) << 3; + for (remaining = 5; remaining; remaining --) { + last_block[58 + remaining] = bit_length; + bit_length >>= 8; + } + sha1_process_block(last_block, state); + unsigned char * result = malloc(20); + for (remaining = 0; remaining < 20; remaining ++) result[remaining] = state[remaining >> 2] >> ((~remaining & 3) << 3); + return result; +} + +static inline unsigned sha1_rotate (unsigned value, unsigned count) { + return (value << count) | (value >> (32 - count)); +} + +void sha1_process_block (const unsigned char * block, uint32_t * state) { + uint32_t words[80]; + unsigned pos, temp, count, a, b, c, d, e; + // constants used by SHA-1; they are actually simply the square roots of 2, 3, 5 and 10 as a fixed-point number (2.30 format) + const uint32_t hash_constants[4] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6}; + memset(words, 0, 16 * sizeof(uint32_t)); + for (pos = 0; pos < 64; pos ++) words[pos >> 2] = (words[pos >> 2] << 8) | block[pos]; + for (pos = 16; pos < 80; pos ++) words[pos] = sha1_rotate(words[pos - 3] ^ words[pos - 8] ^ words[pos - 14] ^ words[pos - 16], 1); + a = *state; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + for (pos = 0; pos < 4; pos ++) for (count = 0; count < 20; count ++) { + temp = sha1_rotate(a, 5) + e + words[pos * 20 + count] + hash_constants[pos]; + switch (pos) { + case 0: + temp += (b & c) | (~b & d); + break; + case 2: + temp += (b & c) | (b & d) | (c & d); + break; + default: + temp += b ^ c ^ d; + } + e = d; + d = c; + c = sha1_rotate(b, 30); + b = a; + a = temp; + } + *state += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; +} + void fatal_printf(char *str, ...) { va_list args; va_start(args, str); @@ -66,14 +135,13 @@ int get_file_size (FILE * fp) { return result; } +#define SHA_DIGEST_LENGTH 20 + void print_help(void) { printf("mwasmarm patcher usage: input (example: mwasmarm_patcher mwasmarm.exe)\n"); } int main(int argc, char *argv[]) { - unsigned char temp[SHA_DIGEST_LENGTH]; - char buf[SHA_DIGEST_LENGTH*2]; - if (argc != 2) { print_help(); return 1; @@ -84,16 +152,26 @@ int main(int argc, char *argv[]) { fatal_printf("ERROR: No file detected\n"); } int fsize = get_file_size(f); - char *string = malloc(fsize + 1); - fread(string, 1, fsize, f); + unsigned char *string = malloc(fsize + 1); + if(string == NULL) { + fatal_printf("ERROR: Failed to allocate string variable\n"); + } + int readvar = fread(string, 1, fsize, f); // var to surpress warning // Check if sha1 matches either known assembler hashes. - SHA1(string, fsize, temp); + unsigned char *sha1 = calculate_sha1(string, fsize); + if(sha1 == NULL) { + fatal_printf("ERROR: Failed to retrieve sha1 hash\n"); + } + free(string); + unsigned char buf[SHA_DIGEST_LENGTH*2]; for (int i=0; i < SHA_DIGEST_LENGTH; i++) { - sprintf((char*)&(buf[i*2]), "%02x", temp[i]); + sprintf((unsigned char*)&(buf[i*2]), "%02x", sha1[i]); } + printf("SHA1: %s\n", buf); + for(int i = 0; gPatchDefs[i].sha1before != NULL; i++) { // check if already patched for the current loop. if(!strcmp(buf, gPatchDefs[i].sha1after)) { -- cgit v1.2.3 From f500ffd69377b5dca924dc159e2e2551775a3041 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Apr 2020 13:53:37 -0400 Subject: remove debug string --- tools/mwasmarm_patcher/mwasmarm_patcher.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c index 1330e650..cfea660c 100644 --- a/tools/mwasmarm_patcher/mwasmarm_patcher.c +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -170,8 +170,6 @@ int main(int argc, char *argv[]) { sprintf((unsigned char*)&(buf[i*2]), "%02x", sha1[i]); } - printf("SHA1: %s\n", buf); - for(int i = 0; gPatchDefs[i].sha1before != NULL; i++) { // check if already patched for the current loop. if(!strcmp(buf, gPatchDefs[i].sha1after)) { -- cgit v1.2.3 From 3fdec1129fa78a5bbb1893a850e0245a6d082be9 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 19 Apr 2020 01:37:04 -0400 Subject: cleanup dependencies and add WINE and devkitARM support to Makefile --- INSTALL.md | 25 +++++++++++++++++++++++-- Makefile | 28 ++++++++++++++++++++++------ tools/mwasmarm_patcher/Makefile | 2 +- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 76059419..083a0010 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -17,11 +17,32 @@ Building the ROM requires the following packages: * make * git * build-essentials -* binutils-arm-linux-gnueabi +* binutils-arm-none-eabi +* wine (to run the mwcc executables) + +NOTE: If you are using Arch/Manjaro or Void you will only need base-devel instead of build-essentials or make or git. You will still need wine. + +Also, if you are using WSL on Windows, please pass NOWINE=1 when compiling, and wine is not necessary for a WSL environment. #### Windows -TODO +Before following the respective guides, please install devkitARM and ensure the DEVKITPRO and DEVKITARM variables are added to bashrc such that: + +Msys2: +export DEVKITPRO=C:/devkitPro +export DEVKITARM=${DEVKITPRO}/devkitARM + +Cygwin: +export DEVKITPRO=/cygdrive/c/devkitPro +export DEVKITARM=${DEVKITPRO}/devkitARM + +You will still require the following packages: + +* make +* git +* build-essentials + +Install them using either the Cygwin package manager or using pacman on Msys2. ### 4. Build ROM diff --git a/Makefile b/Makefile index 3a21944c..41cd85c0 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,29 @@ # Makefile to build Pokemon Diamond image +# Try to include devkitarm if installed +TOOLCHAIN := $(DEVKITARM) + +ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) +include $(TOOLCHAIN)/base_tools +endif + ### Default target ### default: all +# If you are using WSL, it is recommended you build with NOWINE=1. +NOWINE ?= 0 + ifeq ($(OS),Windows_NT) EXE := .exe +WINE := else -EXE := +EXE := +WINE := wine +endif + +ifeq ($(NOWINE),1) +WINE := endif ################ Target Executable and Sources ############### @@ -43,7 +59,7 @@ endif MWCCVERSION := 2.0/base -CROSS := arm-linux-gnueabi- +CROSS := arm-none-eabi- MWCCARM := tools/mwccarm/$(MWCCVERSION)/mwccarm.exe # Argh... due to EABI version shenanigans, we can't use GNU LD to link together @@ -54,10 +70,10 @@ MWCCARM := tools/mwccarm/$(MWCCVERSION)/mwccarm.exe MWLDARM := tools/mwccarm/$(MWCCVERSION)/mwldarm.exe MWASMARM := tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe -AS := $(MWASMARM) -CC := $(MWCCARM) +AS := $(WINE)$(MWASMARM) +CC := $(WINE)$(MWCCARM) CPP := cpp -P -LD := $(MWLDARM) +LD := $(WINE)$(MWLDARM) AR := $(CROSS)ar OBJDUMP := $(CROSS)objdump OBJCOPY := $(CROSS)objcopy @@ -96,7 +112,7 @@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $< $(ELF): $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) - $(LD) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) -nodead -w off -interworking + $(LD) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) -nodead -w off $(ROM): $(ELF) $(OBJCOPY) -O binary $< $@ diff --git a/tools/mwasmarm_patcher/Makefile b/tools/mwasmarm_patcher/Makefile index 5cf20ee4..bc3082dc 100644 --- a/tools/mwasmarm_patcher/Makefile +++ b/tools/mwasmarm_patcher/Makefile @@ -4,4 +4,4 @@ CFLAGS := -O3 all: mwasmarm_patcher mwasmarm_patcher: mwasmarm_patcher.c - $(CC) $(CFLAGS) -o $@ $< -lssl -lcrypto + $(CC) $(CFLAGS) -o $@ $< -- cgit v1.2.3 From 668d5ecfff5a394428fa8a59a7fb7bbbe753bc4b Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 19 Apr 2020 10:54:54 -0400 Subject: wine quotes --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 41cd85c0..71efca0f 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ EXE := .exe WINE := else EXE := -WINE := wine +WINE := "wine " endif ifeq ($(NOWINE),1) -- cgit v1.2.3 From b3306f5d5a899cae77b9a954ae2798e9b648c899 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 19 Apr 2020 11:07:15 -0400 Subject: phony targets --- Makefile | 7 ++++++- tools/mwasmarm_patcher/Makefile | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 71efca0f..3b9d1431 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ # Makefile to build Pokemon Diamond image +.PHONY: clean tidy all default + # Try to include devkitarm if installed TOOLCHAIN := $(DEVKITARM) @@ -94,7 +96,10 @@ MWASMARM_PATCHER = tools/mwasmarm_patcher/mwasmarm_patcher$(EXE) all: $(ROM) @$(SHA1SUM) -c $(TARGET).sha1 -clean: +clean: tidy + make -C tools/mwasmarm_patcher clean + +tidy: $(RM) -r $(BUILD_DIR) patch_mwasmarm: diff --git a/tools/mwasmarm_patcher/Makefile b/tools/mwasmarm_patcher/Makefile index bc3082dc..df3f5c20 100644 --- a/tools/mwasmarm_patcher/Makefile +++ b/tools/mwasmarm_patcher/Makefile @@ -1,7 +1,11 @@ +.PHONY: all clean + CC := gcc CFLAGS := -O3 all: mwasmarm_patcher +clean: ; rm -f mwasmarm_patcher$(EXE) + mwasmarm_patcher: mwasmarm_patcher.c $(CC) $(CFLAGS) -o $@ $< -- cgit v1.2.3 From cf55512d13a434105036e1101391bd24ee682262 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 19 Apr 2020 12:08:28 -0400 Subject: wine spacing --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3b9d1431..6a43a9c8 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ EXE := .exe WINE := else EXE := -WINE := "wine " +WINE := wine endif ifeq ($(NOWINE),1) @@ -72,10 +72,10 @@ MWCCARM := tools/mwccarm/$(MWCCVERSION)/mwccarm.exe MWLDARM := tools/mwccarm/$(MWCCVERSION)/mwldarm.exe MWASMARM := tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe -AS := $(WINE)$(MWASMARM) -CC := $(WINE)$(MWCCARM) +AS := $(WINE) $(MWASMARM) +CC := $(WINE) $(MWCCARM) CPP := cpp -P -LD := $(WINE)$(MWLDARM) +LD := $(WINE) $(MWLDARM) AR := $(CROSS)ar OBJDUMP := $(CROSS)objdump OBJCOPY := $(CROSS)objcopy -- cgit v1.2.3 From ba0e96995f8a84936c26cda1ba1b799b0d1b89f3 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 19 Apr 2020 12:15:09 -0400 Subject: update .gitignore --- .gitignore | 3 +++ tools/mwasmarm_patcher/.gitignore | 1 + 2 files changed, 4 insertions(+) create mode 100644 tools/mwasmarm_patcher/.gitignore diff --git a/.gitignore b/.gitignore index f35ecba0..74eab542 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ cmake-build-debug/ # ROM *.nds *.srl + +# Tool executables +*.exe diff --git a/tools/mwasmarm_patcher/.gitignore b/tools/mwasmarm_patcher/.gitignore new file mode 100644 index 00000000..f03366b2 --- /dev/null +++ b/tools/mwasmarm_patcher/.gitignore @@ -0,0 +1 @@ +mwasmarm_patcher -- cgit v1.2.3