From fbce1fdb8e03b8da72844585a22813ed8d2a743b Mon Sep 17 00:00:00 2001 From: d0k3 Date: Sun, 5 Jul 2026 19:24:21 +0200 Subject: [PATCH] Use random disk ID when formatting SD cards This fixes #972 --- arm9/source/filesys/fsutil.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arm9/source/filesys/fsutil.c b/arm9/source/filesys/fsutil.c index f415836..e21aed3 100644 --- a/arm9/source/filesys/fsutil.c +++ b/arm9/source/filesys/fsutil.c @@ -12,6 +12,7 @@ #include "ui.h" #include "swkbd.h" #include "language.h" +#include "timer.h" #define SKIP_CUR (1UL<<11) #define OVERWRITE_CUR (1UL<<12) @@ -39,6 +40,7 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAA }; + u32 disk_id = (u32) timer_start(); // free running HW timer, ticking since boot -> random enough u32 sd_size = getMMCDevice(1)->total_size; u32 emu_sector = 1; u32 emu_size = (u32) ((hidden_mb * 1024 * 1024) / 512); @@ -62,6 +64,7 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) { memcpy(mbrdata + 0x0C, &fat_size, 4); memcpy(mbrdata + 0x18, &emu_sector, 4); memcpy(mbrdata + 0x1C, &emu_size, 4); + memcpy(mbr + 0x1B8, &disk_id, 4); memcpy(mbr + 0x1BE, mbrdata, 0x42); if (hidden_mb) memcpy(mbr, "GATEWAYNAND", 12); // legacy else memset(mbr + 0x1CE, 0, 0x10);