gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How to read the DS Card Header?

#107764 - Lick - Wed Nov 01, 2006 8:56 pm

I've tried without success. Anyone who can give me more insight on this?

Taken from hbfirmware
Code:
typedef struct {
   int id;
   int id2;
   u32 CRCs;
   int invalid;
   u8 _10[8];
} PACKED CARDINFO;
static CARDINFO *cardinfo=(CARDINFO*)0x27ff800;

typedef struct {
   u8 _00[0x20];
   u32 arm9src;
   u32 arm9exec;
   u32 arm9dst;
   u32 arm9size;
   u32 arm7src;
   u32 arm7exec;
   u32 arm7dst;
   u32 arm7size;
   u8 _40[0x20];
   u32 flags0;
   u32 flags1;
} PACKED NDSHEADER;

static NDSHEADER *head=(NDSHEADER*)0x27ffe00;

void read_card(u32 src, u32 dst, int size) {
   u32 flags;
   u32 cmd[2];

   flags=CARD_ACTIVATE | CARD_nRESET | 0x01000000 | head->flags0;
   cmd[0]=0x00000000;
   cmd[1]=0xb7000000 | (src>>8);
   while(size>0) {
      cardPolledTransfer(flags, (u32*)dst, size>512?512:size, (u8*)cmd);
      cmd[1]+=2;
      dst+=512;
      size-=512;
   }
}


Calling above code on ARM9
Code:
    sNDSHeader physicalNDSHeader;
    sysSetBusOwners(true, true);
    read_card(0, (u32)&physicalNDSHeader, 512);
    sysSetBusOwners(false, false);


I get random junk, different on each run. =(

- Lick
_________________
http://licklick.wordpress.com

#107766 - MaHe - Wed Nov 01, 2006 9:05 pm

Can't take a look at it now, but REIN does it, as far as I know (take a look at the sources):
http://www.pat.hi-ho.ne.jp/sata68/nds.shtml
_________________
[ Crimson and Black Nintendo DS Lite | CycloDS Evolution | EZ-Flash 3-in-1 | 1 GB Transcend microSD ]

#107771 - Lick - Wed Nov 01, 2006 9:22 pm

Thanks MaHe, but I searched REIN and wasn't able to find any additional header reading procedures.

- Lick
_________________
http://licklick.wordpress.com

#107785 - chishm - Wed Nov 01, 2006 11:52 pm

You can't read anything below 0x8000 once the DS card had been set into data mode. The only way to get the header directly would be to eject the card, reinsert it, then read it.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#107845 - Lick - Thu Nov 02, 2006 4:21 pm

*pukes*
Bleghh.. Well what does the Reset pin (5) do?

Thanks chishm!
- Lick
_________________
http://licklick.wordpress.com

#107846 - josath - Thu Nov 02, 2006 4:56 pm

Some notes:
1. I believe the header is copied into main RAM by the firmware, so you may be able to grab a copy of this at the beginning of your app (It might get overwritten by the homebrew, not sure)

2. The eject/insert thing -- The neoflash MK2/MK3 have a function to read what your current NDS cart is, but they require you to eject / reinsert it first.

3. Is there any possibility of doing a 'hard reset' (instead of a soft reset), where it will reset everything, and go back to the nintendo logo / firmware / etc? This would be better than nothing, if we can't get the card reading working directly.

#107848 - tepples - Thu Nov 02, 2006 5:00 pm

josath wrote:
3. Is there any possibility of doing a 'hard reset' (instead of a soft reset), where it will reset everything, and go back to the nintendo logo / firmware / etc?

Of course. Just turn the power off. This is the solution that the DS firmware itself uses to exit from PictoChat, DS Download Play, or settings.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#107854 - Lick - Thu Nov 02, 2006 5:10 pm

josath wrote:
Some notes:
1. I believe the header is copied into main RAM by the firmware, so you may be able to grab a copy of this at the beginning of your app (It might get overwritten by the homebrew, not sure)

Yes, but it seems like all devices that use PassMe as a booting solution will overwrite the RAM copy of the header. Also, my main goal is to reset back to the SLOT1 homebrew devices, and I suspect those will overwrite the RAM copy of the header as well.

Quote:
2. The eject/insert thing -- The neoflash MK2/MK3 have a function to read what your current NDS cart is, but they require you to eject / reinsert it first.

Tried it, and it seems like I am getting the header values alright! I'll still be hoping for a software method to reset the DS card. Hurray for josath again!

Quote:
3. Is there any possibility of doing a 'hard reset' (instead of a soft reset), where it will reset everything, and go back to the nintendo logo / firmware / etc? This would be better than nothing, if we can't get the card reading working directly.

You NEED to reset the card before it works. The firmware won't reset them for you, it will just assume that both SLOT1 and SLOT2 cards are resetted, because of the power off. If that's not true, perhaps the firmware will hang or something?
_________________
http://licklick.wordpress.com

#107855 - Lick - Thu Nov 02, 2006 5:12 pm

tepples wrote:
josath wrote:
3. Is there any possibility of doing a 'hard reset' (instead of a soft reset), where it will reset everything, and go back to the nintendo logo / firmware / etc?

Of course. Just turn the power off. This is the solution that the DS firmware itself uses to exit from PictoChat, DS Download Play, or settings.

What fun is that? Hehe, I mean, I always hated that the DS firmware doesn't just reset back to the mainmenu.
_________________
http://licklick.wordpress.com