Skip to content

Commit e0b77b3

Browse files
committed
Add SD card brand detection
Does not work for flashcards
1 parent cd2bb67 commit e0b77b3

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

booter/arm7/source/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define SD_IRQ_STATUS (*(vu32*)0x400481C)
3333

3434
void my_installSystemFIFO(void);
35+
void my_sdmmc_get_cid(int devicenumber, u32 *cid);
3536

3637
//---------------------------------------------------------------------------------
3738
void ReturntoDSiMenu() {
@@ -117,6 +118,10 @@ int main() {
117118
fifoSendValue32(FIFO_USER_04, SD_IRQ_STATUS);
118119
*(u32*)0x02FFFD0C = 0;
119120
}
121+
if (*(u32*)0x02FFFD0C == 0x47444943) { // 'CIDG'
122+
my_sdmmc_get_cid(0, (u32*)0x02810000);
123+
*(u32*)0x02FFFD0C = 0;
124+
}
120125
// fifocheck();
121126
swiWaitForVBlank();
122127
}

booter/arm9/source/main.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,84 @@ int main(int argc, char **argv) {
200200
fadeType = true;
201201

202202
extern const DISC_INTERFACE __my_io_dsisd;
203+
const bool fatInited = fatMountSimple("sd", &__my_io_dsisd);
203204

204-
if (!fatMountSimple("sd", &__my_io_dsisd)) {
205+
*(u32*)0x0CFFFD0C = 0x47444943; // 'CIDG'
206+
while (*(u32*)0x0CFFFD0C != 0) { swiDelay(100); }
207+
208+
{
209+
DC_FlushRange((void*)0x02810000, 16);
210+
211+
const u16 manufID = *(u16*)0x0281000E;
212+
const char oemID[3] = {*(char*)0x0281000D, *(char*)0x0281000C, 0};
213+
214+
// Source: https://web.archive.org/web/20130728131543/https://wiki.linaro.org/WorkingGroups/KernelArchived/Projects/FlashCardSurvey?action=show&redirect=WorkingGroups%2FKernel%2FProjects%2FFlashCardSurvey
215+
if (
216+
(manufID == 0x0001 && strcmp(oemID, "PA") == 0) // Panasonic
217+
|| (manufID == 0x0002 && strcmp(oemID, "TM") == 0) // Kingston/PNY
218+
|| (manufID == 0x0003 && strcmp(oemID, "SD") == 0) // SanDisk
219+
|| (manufID == 0x0009 && strcmp(oemID, "AP") == 0) // Lexar
220+
|| (manufID == 0x001B && strcmp(oemID, "SM") == 0) // PNY
221+
|| (manufID == 0x0027 && strcmp(oemID, "PH") == 0) // Sony
222+
|| (manufID == 0x0028 && strcmp(oemID, "BE") == 0) // Lexar/Polaroid
223+
|| (manufID == 0x0041 && strcmp(oemID, "42") == 0) // Kingston
224+
){
225+
// SD card is compatible!
226+
} else {
227+
char manufIdText[40];
228+
sprintf(manufIdText, "Manufacturer ID: %04X", manufID);
229+
char oemIdText[16];
230+
sprintf(oemIdText, "OEM ID: %s", oemID);
231+
232+
waitBeforeFade = false;
233+
234+
clearText();
235+
int yPos = 4;
236+
printSmall(false, 4, yPos, manufIdText);
237+
yPos += 8;
238+
printSmall(false, 4, yPos, oemIdText);
239+
yPos += 8*2;
240+
if (
241+
(manufID == 0x001D && strcmp(oemID, "AD") == 0) // A-Data/extrememory/Microcenter
242+
|| (manufID == 0x0000 && strcmp(oemID, " ") == 0) // Brandless
243+
){
244+
printSmall(false, 4, yPos, "The inserted SD card is not");
245+
yPos += 8;
246+
printSmall(false, 4, yPos, "compatible. Please switch to an");
247+
yPos += 8;
248+
printSmall(false, 4, yPos, "SD card of a well-known brand.");
249+
yPos += 8*2;
250+
printSmall(false, 4, yPos, "Press B to return to menu.");
251+
252+
goto pressB;
253+
} else {
254+
printSmall(false, 4, yPos, "The inserted SD card has not");
255+
yPos += 8;
256+
printSmall(false, 4, yPos, "been tested, and is possible that");
257+
yPos += 8;
258+
printSmall(false, 4, yPos, "it will not work correctly.");
259+
yPos += 8*2;
260+
printSmall(false, 4, yPos, "If you encounter any issues,");
261+
yPos += 8;
262+
printSmall(false, 4, yPos, "please switch to an SD card");
263+
yPos += 8;
264+
printSmall(false, 4, yPos, "of a well-known brand.");
265+
yPos += 8*2;
266+
printSmall(false, 4, yPos, "A: Continue");
267+
yPos += 8;
268+
printSmall(false, 4, yPos, "B: Return to menu");
269+
270+
while (1) {
271+
scanKeys();
272+
if (keysHeld() & KEY_A) break;
273+
else if (keysHeld() & KEY_B) goto pressedB;
274+
swiWaitForVBlank();
275+
}
276+
}
277+
}
278+
}
279+
280+
if (!fatInited) {
205281
waitBeforeFade = false;
206282
// fadeType = true;
207283

@@ -268,12 +344,14 @@ int main(int argc, char **argv) {
268344
printSmall(false, 4, returnTextPos, "Press B to return to menu.");
269345
}
270346

347+
pressB:
271348
while (1) {
272349
scanKeys();
273350
if (keysHeld() & KEY_B) break;
274351
swiWaitForVBlank();
275352
}
276353

354+
pressedB:
277355
fadeType = false;
278356
for (int i = 0; i < 24; i++) {
279357
swiWaitForVBlank();

0 commit comments

Comments
 (0)