Fix alignment warnings

Happy now, @Gemarcano? :)
This commit is contained in:
d0k3 2016-07-26 20:58:41 +02:00
parent f3bdfc2ab6
commit b46f5ab2ac
6 changed files with 31 additions and 26 deletions

View File

@ -30,7 +30,7 @@ INCLUDES := source source/fatfs source/nand
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork -flto ARCH := -mthumb -mthumb-interwork -flto
CFLAGS := -g -Wall -Wextra -Wpedantic -pedantic -O2\ CFLAGS := -g -Wall -Wextra -Wpedantic -Wcast-align -pedantic -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math -std=c99\ -ffast-math -std=c99\
$(ARCH) $(ARCH)

View File

@ -28,9 +28,12 @@
((((u32) getbe16(d))<<16) | ((u32) getbe16(d+2))) ((((u32) getbe16(d))<<16) | ((u32) getbe16(d+2)))
#define getbe64(d) \ #define getbe64(d) \
((((u64) getbe32(d))<<32) | ((u64) getbe32(d+4))) ((((u64) getbe32(d))<<32) | ((u64) getbe32(d+4)))
#define getle16(d) (*((u16*) (d))) #define getle16(d) \
#define getle32(d) (*((u32*) (d))) (((d)[1]<<8) | (d)[0])
#define getle64(d) (*((u64*) (d))) #define getle32(d) \
((((u32) getle16(d+2))<<16) | ((u32) getle16(d)))
#define getle64(d) \
((((u64) getle32(d+4))<<32) | ((u64) getle32(d)))
#define align(v,a) \ #define align(v,a) \
(((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v)) (((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v))

View File

@ -105,7 +105,7 @@ uint64_t GetSDCardSize() {
return (u64) getMMCDevice(1)->total_size * 512; return (u64) getMMCDevice(1)->total_size * 512;
} }
bool FormatSDCard(u32 hidden_mb) { bool FormatSDCard(u64 hidden_mb) {
u8 mbr[0x200] = { 0 }; u8 mbr[0x200] = { 0 };
u8 mbrdata[0x42] = { u8 mbrdata[0x42] = {
0x80, 0x01, 0x01, 0x00, 0x0C, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x01, 0x00, 0x0C, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -115,22 +115,23 @@ bool FormatSDCard(u32 hidden_mb) {
0x55, 0xAA 0x55, 0xAA
}; };
u32 sd_size = getMMCDevice(1)->total_size; u32 sd_size = getMMCDevice(1)->total_size;
u32* fat_sector = (u32*) (mbrdata + 0x08); u32 emu_sector = 1;
u32* fat_size = (u32*) (mbrdata + 0x0C); u32 emu_size = (u32) ((hidden_mb * 1024 * 1024) / 512);
u32* emu_sector = (u32*) (mbrdata + 0x18); u32 fat_sector = align(emu_sector + emu_size, 0x2000); // align to 4MB
u32* emu_size = (u32*) (mbrdata + 0x1C); u32 fat_size = (fat_sector < sd_size) ? sd_size - fat_sector : 0;
*emu_sector = 1; // FAT size check
*emu_size = hidden_mb * (1024 * 1024) / 512; if (fat_size < 0x80000) { // minimum free space: 256MB
*fat_sector = align(*emu_sector + *emu_size, 0x2000); // align to 4MB
if (sd_size < *fat_sector + 0x80000) { // minimum free space: 256MB
ShowPrompt(false, "ERROR: SD card is too small"); ShowPrompt(false, "ERROR: SD card is too small");
return false; return false;
} }
*fat_size = sd_size - *fat_sector; sd_size = fat_size;
sd_size = *fat_size;
// build the MBR // build the MBR
memcpy(mbrdata + 0x08, &fat_sector, 4);
memcpy(mbrdata + 0x0C, &fat_size, 4);
memcpy(mbrdata + 0x18, &emu_sector, 4);
memcpy(mbrdata + 0x1C, &emu_size, 4);
memcpy(mbr + 0x1BE, mbrdata, 0x42); memcpy(mbr + 0x1BE, mbrdata, 0x42);
if (hidden_mb) memcpy(mbr, "GATEWAYNAND", 12); if (hidden_mb) memcpy(mbr, "GATEWAYNAND", 12);
else memset(mbr + 0x1CE, 0, 0x10); else memset(mbr + 0x1CE, 0, 0x10);
@ -138,7 +139,7 @@ bool FormatSDCard(u32 hidden_mb) {
// one last warning.... // one last warning....
if (!ShowUnlockSequence(3, "!WARNING!\n \nProceeding will format this SD.\nThis will irreversibly delete\nALL data on it.\n")) if (!ShowUnlockSequence(3, "!WARNING!\n \nProceeding will format this SD.\nThis will irreversibly delete\nALL data on it.\n"))
return false; return false;
ShowString("Formatting SD, please wait...", hidden_mb); ShowString("Formatting SD, please wait...");
// write the MBR to disk // write the MBR to disk
// !this assumes a fully deinitialized file system! // !this assumes a fully deinitialized file system!

View File

@ -46,7 +46,7 @@ void SetFSSearch(const char* pattern, const char* path);
uint64_t GetSDCardSize(); uint64_t GetSDCardSize();
/** Format the SD card **/ /** Format the SD card **/
bool FormatSDCard(u32 hidden_mb); bool FormatSDCard(u64 hidden_mb);
/** Check if writing to this path is allowed **/ /** Check if writing to this path is allowed **/
bool CheckWritePermissions(const char* path); bool CheckWritePermissions(const char* path);

View File

@ -205,7 +205,7 @@ u32 SdFormatMenu(void) {
} while (emunand_size_mb > sdcard_size_mb); } while (emunand_size_mb > sdcard_size_mb);
if (emunand_size_mb == (u64) -1) return 1; if (emunand_size_mb == (u64) -1) return 1;
if (!FormatSDCard((u32) emunand_size_mb)) { if (!FormatSDCard(emunand_size_mb)) {
ShowPrompt(false, "Format SD: failed!"); ShowPrompt(false, "Format SD: failed!");
return 1; return 1;
} }

View File

@ -126,13 +126,13 @@ bool InitNandCrypto(void)
} }
// part #1: Get NAND CID, set up TWL/CTR counter // part #1: Get NAND CID, set up TWL/CTR counter
u8 NandCid[16]; u32 NandCid[4];
u8 shasum[32]; u8 shasum[32];
sdmmc_get_cid( 1, (uint32_t*) NandCid); sdmmc_get_cid( 1, NandCid);
sha_quick(shasum, NandCid, 16, SHA256_MODE); sha_quick(shasum, (u8*) NandCid, 16, SHA256_MODE);
memcpy(CtrNandCtr, shasum, 16); memcpy(CtrNandCtr, shasum, 16);
sha_quick(shasum, NandCid, 16, SHA1_MODE); sha_quick(shasum, (u8*) NandCid, 16, SHA1_MODE);
for(u32 i = 0; i < 16; i++) // little endian and reversed order for(u32 i = 0; i < 16; i++) // little endian and reversed order
TwlNandCtr[i] = shasum[15-i]; TwlNandCtr[i] = shasum[15-i];
@ -146,10 +146,11 @@ bool InitNandCrypto(void)
// thanks b1l1s & Normmatt // thanks b1l1s & Normmatt
// see source from https://gbatemp.net/threads/release-twltool-dsi-downgrading-save-injection-etc-multitool.393488/ // see source from https://gbatemp.net/threads/release-twltool-dsi-downgrading-save-injection-etc-multitool.393488/
const char* nintendo = "NINTENDO"; const char* nintendo = "NINTENDO";
u32* TwlKeyXW = (u32*) TwlKeyX; u32 TwlKeyXW0 = (TwlCustId[0] ^ 0xB358A6AF) | 0x80000000;
TwlKeyXW[0] = (TwlCustId[0] ^ 0xB358A6AF) | 0x80000000; u32 TwlKeyXW3 = TwlCustId[1] ^ 0x08C267B7;
TwlKeyXW[3] = TwlCustId[1] ^ 0x08C267B7;
memcpy(TwlKeyX + 4, nintendo, 8); memcpy(TwlKeyX + 4, nintendo, 8);
memcpy(TwlKeyX + 0, &TwlKeyXW0, 4);
memcpy(TwlKeyX + 12, &TwlKeyXW3, 4);
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM // see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM
u32 TwlKeyYW3 = 0xE1A00005; u32 TwlKeyYW3 = 0xE1A00005;