-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memory device info to system information
- Loading branch information
1 parent
f54dcf1
commit fc4392d
Showing
5 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "mdinfo.h" | ||
#include "utils.h" | ||
|
||
// Since physical and virtual addresses match for IOS-FS, we can use these without address translation | ||
#define MDBLK_DRIVER_ADDRESS 0x11c39e78 | ||
#define MD_DEVICE_POINTERS_ADDRESS 0x10899308 | ||
|
||
// TODO turn this into a struct eventually | ||
#define MD_DEVICE_CID_OFFSET 0x58 | ||
#define MD_DEVICE_CSD_OFFSET 0x68 | ||
|
||
static MDBlkDrv blkDrvs[2] = { 0 }; | ||
static uint32_t devicePointers[8] = { 0 }; | ||
|
||
int MDReadInfo(void) | ||
{ | ||
uint32_t* dst = (uint32_t*) &blkDrvs; | ||
for (uint32_t i = 0; i < sizeof(blkDrvs) / 4; i++) { | ||
// use the kernel to read from IOS-FS memory | ||
dst[i] = kernRead32(MDBLK_DRIVER_ADDRESS + (i * 4)); | ||
} | ||
|
||
for (uint32_t i = 0; i < sizeof(devicePointers) / 4; i++) { | ||
// use the kernel to read from IOS-FS memory | ||
devicePointers[i] = kernRead32(MD_DEVICE_POINTERS_ADDRESS + (i * 4)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
MDBlkDrv* MDGetBlkDrv(int index) | ||
{ | ||
return &blkDrvs[index]; | ||
} | ||
|
||
int MDGetCID(int deviceId, uint32_t* cid) | ||
{ | ||
int idx = deviceId - 0x42; | ||
if (idx >= 8 || !devicePointers[idx]) { | ||
return -1; | ||
} | ||
|
||
for (uint32_t i = 0; i < 4; i++) { | ||
// use the kernel to read from IOS-FS memory | ||
cid[i] = kernRead32(devicePointers[idx] + MD_DEVICE_CID_OFFSET + (i * 4)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int MDGetCSD(int deviceId, uint32_t* csd) | ||
{ | ||
int idx = deviceId - 0x42; | ||
if (idx >= 8 || !devicePointers[idx]) { | ||
return -1; | ||
} | ||
|
||
for (uint32_t i = 0; i < 4; i++) { | ||
// use the kernel to read from IOS-FS memory | ||
csd[i] = kernRead32(devicePointers[idx] + MD_DEVICE_CSD_OFFSET + (i * 4)); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <assert.h> | ||
|
||
enum { | ||
SAL_DEVICE_TYPE_MLC = 5, | ||
SAL_DEVICE_TYPE_SD_CARD = 6, | ||
}; | ||
|
||
typedef struct __attribute__((packed)) SALDeviceParams { | ||
uint32_t usrptr; | ||
uint32_t mid_prv; | ||
uint32_t device_type; | ||
uint32_t unk[7]; | ||
uint64_t numBlocks; | ||
uint32_t blockSize; | ||
uint32_t unk2[6]; | ||
char name0[128]; | ||
char name1[128]; | ||
char name2[128]; | ||
uint32_t functions[12]; | ||
} SALDeviceParams; | ||
|
||
typedef struct MDBlkDrv { | ||
int32_t registered; | ||
int32_t unk[2]; | ||
struct SALDeviceParams params; | ||
int sal_handle; | ||
int deviceId; | ||
uint8_t unk2[196]; | ||
} MDBlkDrv; | ||
static_assert(sizeof(MDBlkDrv) == 724, "MDBlkDrv: wrong size"); | ||
|
||
int MDReadInfo(void); | ||
|
||
MDBlkDrv* MDGetBlkDrv(int index); | ||
|
||
int MDGetCID(int deviceId, uint32_t* cid); | ||
|
||
int MDGetCSD(int deviceId, uint32_t* csd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters