Skip to content

Commit

Permalink
Support NDSI mode
Browse files Browse the repository at this point in the history
Resolve #1
  • Loading branch information
d3m3vilurr committed Aug 17, 2017
1 parent 9b76938 commit 6d371e3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ CFLAGS := -g -Wall -O2\
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ifneq ($(strip $(DEBUG_DUMP)),)
CFLAGS += -DDEBUG_DUMP=$(DEBUG_DUMP)
CXXFLAGS += -DDEBUG_DUMP=$(DEBUG_DUMP)
endif

ifneq ($(strip $(NDSI_MODE)),)
CFLAGS += -DNDSI_MODE
CXXFLAGS += -DNDSI_MODE
TARGET := $(TARGET)_dsi
endif

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

Expand Down Expand Up @@ -101,7 +112,7 @@ $(BUILD):
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds
@rm -fr $(BUILD) $(TARGET)*.elf $(TARGET)*.nds

#---------------------------------------------------------------------------------
else
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ DO NOT USE THIS ON NDSI
2. `python extract_binaries.py`
3. then `make`

#### Special `make` options
* `NDSI_MODE=1`
- build nds compatible mode
- remove cart swap and load & restore command
* `DEBUG_DUMP=1`
- print first 16bytes at load
* `DEBUG_DUMP=2`
- print all dumps

### Credits
* [Normmatt][normmatt] - Original implement 3DS version ntrcardhax flasher
* [SciresM][sciresm] - Parent of `boot9strap`
Expand Down
46 changes: 36 additions & 10 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,35 @@
// FIXME: not fully overwrite
u8 orig_flashrom[0xA0000] = {0};
u8 curr_flashrom[0xA0000] = {0};

#ifndef NDSI_MODE
u8 restorable = 0;
#else
// NDSI mode cannot restore
u8 restorable = 1;
#endif

Flashcart* waitCartReady() {
Flashcart *cart = NULL;
#ifndef NDSI_MODE
do {
iprintf("Please eject and remove SDCARD\n");
iprintf("Then reinsert cartridge.\n");
waitPressA();

#endif
iprintf("ChipID: %08X\n", Flashcart::getChipID());
iprintf("HW Rev: %08X\n", Flashcart::getHardwareVersion());

cart = Flashcart::detectCart();
#ifndef NDSI_MODE
} while(!cart);
#else
if (!cart) {
// cannot continue anymore.
iprintf("Supported cartridge not detected!\n");
while (true) swiWaitForVBlank();
}
#endif

iprintf("Detected: %s\n\n", cart->getDescription());

Expand All @@ -38,7 +53,6 @@ u8 dump(Flashcart *cart) {
if (length > 0xA0000) {
length = 0xA0000;
}
iprintf("%X\n", length);
memset(orig_flashrom, 0, 0xA0000);
u8 *temp = orig_flashrom;

Expand All @@ -51,17 +65,20 @@ u8 dump(Flashcart *cart) {
restorable = 1;
iprintf("\nDone\n\n");

/*
#if defined(DEBUG_DUMP)
for (int i = 0; i < length; i+=16) {
iprintf("%05X:", i);
for (int j = 0; j < 16; j++) {
iprintf("%02X ", orig_flashrom[i + j]);
iprintf("%02X", orig_flashrom[i + j]);
}
iprintf("\n");
#if DEBUG_DUMP == 2
waitPressA();
#else
break;
#endif
}
*/

#endif
return 0;
}

Expand Down Expand Up @@ -213,9 +230,6 @@ int restore() {
exit:
cart->cleanup();
iprintf("\nDone\n\n");


// TODO verify check
return 0;
}

Expand All @@ -225,22 +239,32 @@ int main(void) {

sysSetBusOwners(true, true); // give ARM9 access to the cart

iprintf("= AK2I NTRBOOTHAX FLASHER =\n\n");
iprintf("= NDS NTRBOOT FLASHER =\n\n");

iprintf("* if you use non ak2i *\n");
iprintf("* you will lost flashcart *\n");
iprintf("* feature. *\n");
#ifndef NDSI_MODE
iprintf("* DO NOT CLOSE THIS APP *\n");
iprintf("* IF YOU DONT HAVE SAME *\n");
iprintf("* FLASHCART *\n");
#else
iprintf("* WARN: ONLY TESTED WITH *\n");
iprintf("* 3DS DEVICE. *\n");
#endif
iprintf("* AT YOUR OWN RISK *\n");

waitPressA();

while (true) {
#ifndef NDSI_MODE
iprintf("You can swap flashcart for flash\n");
iprintf("X. load flashrom\n");
#endif
iprintf("A. inject ntrboothax\n");
#ifndef NDSI_MODE
iprintf("Y. restore flashrom\n");
#endif
iprintf("B. exit\n\n");

while (true) {
Expand All @@ -250,12 +274,14 @@ int main(void) {
if (keys & KEY_A) {
inject();
break;
#ifndef NDSI_MODE
} else if (keys & KEY_X) {
load();
break;
} else if (keys & KEY_Y) {
restore();
break;
#endif
} else if (keys & KEY_B) {
return 0;
}
Expand Down
9 changes: 6 additions & 3 deletions source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ void Flashcart::sendCommand(const uint8_t *cmdbuf, uint16_t response_len, uint8_
break;
}

#ifndef NDSI_MODE
// NDSL only
cardPolledTransfer(defaultFlags | CARD_ACTIVATE | CARD_nRESET,
(u32*)resp, response_len, reversed);
#else
// NDSL, DSLi, etc...
//cardPolledTransfer(flags | defaultFlags | CARD_ACTIVATE | CARD_nRESET |
// CARD_SEC_CMD | CARD_SEC_EN | CARD_SEC_DAT,
// destination, length, command);
cardPolledTransfer(defaultFlags | CARD_ACTIVATE | CARD_nRESET |
CARD_SEC_CMD | CARD_SEC_EN | CARD_SEC_DAT,
(u32*)resp, response_len, reversed);
#endif
return;
}

Expand Down

0 comments on commit 6d371e3

Please sign in to comment.