SceSdstor: Difference between revisions

From Vita Development Wiki
Jump to navigation Jump to search
 
(71 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Module ==
== Module ==
SceSdstor module does not export any functions exсept module_start.


This module is responsible for initializing all storage devices. This includes:
This module is responsible for initializing all storage devices. This includes:
Line 7: Line 5:
* [[Game_Card|Game gard]]
* [[Game_Card|Game gard]]
* [[Memory_Card|Memory card]]
* [[Memory_Card|Memory card]]
* Usb Mass Storage (unknown SceUsbMassForDriver)
* USB Mass Storage
* Micro SD card / SD card


Based on layout of data segment and code of some subroutines (mbr table init, partition entry table init etc) it can be said that there are 5 devices in total.
{| class="wikitable"
However only first 3 devices are known at the moment.
|-
! Version !! World !! Privilege
|-
| 1.69-3.740.011 || Non-secure || Kernel
|}
 
== Libraries ==
 
SceSdstor module does not export any function exсept module_start.
 
== Interrupt Table ==


=== Known NIDs ===
{| class="wikitable"
{| class="wikitable"
|-
|-
! Version !! Name !! World !! Privilege !! NID
! Index !! Code !! Name
|-
| 0 || 0xDC || SceSdif0
|-
| 1 || 0xDD || SceSdif1
|-
| 2 || 0x3C || SceMsifIns
|-
|-
| 1.69 || SceSdstor || Non-secure || Kernel || 0x5804A397
| 3 || 0xF || SceUsbMass
|-
|-
| 3.60 || SceSdstor || ? || Kernel || 0xD7FBAE7C
| 4 || 0xDF || SceSdif3
|}
|}


== Libraries ==
== Block Device Naming Rules ==


=== Known NIDs ===
First level prefix: port.


{| class="wikitable"
{| class="wikitable"
|-
|-
! Version !! Name !! World !! Visibility !! NID
! Name !! Index !! Long name !! Description
|-
| int || 0 || internal || eMMC
|-
| ext || 1 || external || SD card
|-
| gcd || 1 || game card || Game Card
|-
| mcd || 2 || memory card || Memory Card
|-
| uma || 3 || usb mass || USB mass storage device
|-
| usd || 4 || micro sd || Micro SD card
|-
| xmc || 0xFF || external memory card || Actual Memory Card when internal eMMC is mounted as Memory Card
|}
 
Second level prefix: kind
 
*lp - general.
*pp - no part.
 
Third level prefix: stat
 
*ina: inactive
*act: active
*ign: ignore (same behaviour as inactive)
 
Fourth level prefix: id
 
*unused
*idstor
*sloader
*os
*vsh
*vshdata
*vtrm
*user
*userext
*gamero
*gamerw
*updater
*sysdata
*mediaid
*pidata
*entire
 
== Partition Block Devices ==
 
Each partition has a numeric alias (string) that seems to be used to reference the partition.
 
Numeric names most likely follow order of partitions in MBR.
 
To access device node use <code>/dev</code> prefix (like <code>/dev/gcd-lp-ign-gamero</code>).
 
There can be up to 16 aliases from 0 to 15 per physical device (eMMC, Game Card, Memory Card) and alias 16 is hardcoded and called <code>entire</code>.
 
Not all numeric names are fixed but <code>entire</code> numeric names are hardcoded.
 
{| class="wikitable"
|-
! Block device !! Numeric name !! Hardcoded
|-
| int-lp-ign-idstor || 000 || no
|-
| int-lp-act-sloader/int-lp-ina-sloader || 001 || no
|-
| int-lp-act-sloader/int-lp-ina-sloader || 002 || no
|-
| int-lp-act-os/int-lp-ina-os || 003 || no
|-
| int-lp-act-os/int-lp-ina-os || 004 || no
|-
| int-lp-ign-sysdata || 005 || no
|-
| int-lp-ign-vtrm || 006 || no
|-
| int-lp-ign-vsh || 007 || no
|-
| int-lp-ign-vshdata || 008 || no
|-
| int-lp-ign-updater || 009 || no
|-
| int-lp-ign-pidata || 010 || no
|-
| int-lp-ign-user || 011 || no
|-
| int-lp-ign-userext || 012 || no
|-
| int-lp-act-entire || 016 || yes
|-
| gcd-lp-ign-gamero, gcd-lp-act-mediaid (need to confirm) || 100 || no
|-
| gcd-lp-ign-gamerw (need to confirm) || 101 || no
|-
| ext-lp-act-entire || 116 || yes
|-
| mcd-lp-act-mediaid || 200 || no
|-
| mcd-lp-ign-userext || 201 || no
|-
| mcd-lp-act-entire || 216 || yes
|-
| uma-lp-act-entire || 316 || yes
|-
| usd-lp-act-entire || 416 || yes
|}
|}


== Types ==
== Types ==


<source lang="c">
It looks like SceSdstor driver uses its own device type.
typedef struct partition_entry //size is 0x1C
{
  uint32_t partitionOffset;
  uint32_t partitionSize;
  sdstor_mbr_ctx* ctx;
  void* partitionEntryPtr; //pointer to partition entry in MBR
  char* numericName; //null terminated name (000, 001, ...)
  unt8_t flags1;
  unt8_t flags2;
  uint16_t unk1;
  uint32_t unk2;
}partition_entry;


typedef struct sdstor_mbr_ctx //size is 0x238
{| class="wikitable"
{
|-
uint8_t unk_0[0x40];
! Device Type Index
! Description
|-
| 0
| MMC card
|-
| 1
| SD card
|-
| 2
| Memory Card
|-
| 3
| USB Mass Storage
|}


uint32_t unk_40;
Also see [https://github.com/vitasdk/vita-headers/blob/master/include/psp2kern/internal/sdstor.h here (vita-headers)]
sd_stor_device* unk_44;
uint32_t unk_48;
uint32_t unk_4C;


uint32_t unk_50;
<source lang="C">
void* mbr_ptr; //pointer to corresponding MBR record in array (offset 0x40)
typedef struct unknown_1C2C { // size is 0x1C
partition_entry partitions[17];
  uint8_t data[0x1C];
uint16_t unk_234;
} unknown_1C2C;
uint16_t unk_236;
 
}sdstor_mbr_ctx;
#define CARD_REMOVE_SDSTOR_REQUEST_EVENT_FLAG 0x01
#define IO_DEVCTL_SDSTOR_REQUEST_EVENT_FLAG 0x02
#define CARD_INSERT_SDSTOR_REQUEST_EVENT_FLAG 0x10
#define SUSPEND_SDSTOR_REQUEST_EVENT_FLAG 0x100
#define RESUME_SDSTOR_REQUEST_EVENT_FLAG 0x1000
 
typedef struct interrupt_argument { // size is 0x28
  uint32_t unk_0;
  SceUID SceSdstorRequest_evid; // event id
  SceUID SceSdstorOpSync_evid; // event id
  interrupt_info* intr_info; //
 
  unknown_1C2C* unk_10;
 
  // card swap protection
  char cid_rnd[0x10]; // cid of the card / randomly generated non zero byte array / zero
 
  uint8_t intr_table_index; // check interrupt table section (also sd_stor_device index)
  uint8_t unk_25; // = 0
  uint8_t unk_26; // = 0
  uint8_t unk_27;
} interrupt_argument;
 
typedef int(insert_handler)(int unk, interrupt_argument* arg);
 
typedef int(remove_handler)(int unk, interrupt_argument* arg);
 
#define SDSTOR_SUBINTERRUPT_CODE_INSERT 0
#define SDSTOR_SUBINTERRUPT_CODE_REMOVE 1
 
typedef struct interrupt_info { // size is 0xC
  insert_handler* SceSdstorCardInsert_handler;
  remove_handler* SceSdstorCardRemove_handler;
  uint8_t intr_table_index; // check interrupt table section
  uint8_t SceSdstorCardInsert_subintr_code;
  uint8_t SceSdstorCardRemove_subintr_code;
  uint8_t unk_0xB;
} interrupt_info;


//named after "SceSdStorDevice" mutex
typedef struct sd_stor_device //size is 0x54
{
  int unk_0;
  int unk_4;
  int unk_8;
  int unk_C;
 
  int unk_10;
  int unk_14;
  int unk_18;
  int unk_1C;
 
  int unk_20;
  int unk_24;
  int unk_28;
  int unk_2C;
 
  int unk_30;
  int unk_34;
  int unk_38;
  int unk_3C;
 
  char index1; // (0x00, 0x01, 0xFF, 0xFF, 0x03)
  char index2; // (0x00, 0x00, 0x02, 0x03, 0x01)
  char unk_42;
  char unk_43;
 
  int unk_44;
  int unk_48;
  int unk_4C;
 
  void* devCtx; //pointer to dev ctx (sd_context_part_mmc*) or zero
}sd_stor_device;
</source>
</source>


Line 105: Line 226:
! Address !! Size !! Description
! Address !! Size !! Description
|-
|-
| 0x0000 || 0x40 || unknown
| 0x0000 || 0x20 || unknown
|-
| 0x0020 || 0x14 || array of 5 integers (number created device handles?) (each corresponds to sd_stor_device)
|-
| 0x0034 || 0x4 || unknown
|-
| 0x0038 || 0x4 || <code>SceSdStorDeviceHandle</code> mempool SceUID of size 0x2000
|-
| 0x003C || 0x4 || unknown
|-
|-
| 0x0040 || 0x200 || [[Partitions#Master Block|MBR]] of [[EMMC|eMMC]]
| 0x0040 || 0x200 || [[Partitions#Master Block|MBR]] of [[EMMC|eMMC]]
|-
|-
| 0x0240 || 0x200 || [[Partitions#Master Block|MBR]] of [[Game_Card|Game gard]]
| 0x0240 || 0x200 || [[Partitions#Master Block|MBR]] of [[Game_Card|Game card]]
|-
|-
| 0x0440 || 0x200 || [[Partitions#Master Block|MBR]] of [[Memory_Card|Memory card]]
| 0x0440 || 0x200 || [[Partitions#Master Block|MBR]] of [[Memory_Card|Memory card]]
|-
|-
| 0x0640 || 0x200 || unknown (most likely for MBR since there are 5 elements in all arrays)
| 0x0640 || 0x200 || [[Partitions#Master Block|MBR]] of USB Mass Storage
|-
|-
| 0x0840 || 0x200 || unknown (most likely for MBR since there are 5 elements in all arrays)
| 0x0840 || 0x200 || [[Partitions#Master Block|MBR]] of micro SD card (usd device)
|-
|-
| 0x0A40 || 0x238 || sdstor_mbr_ctx element 0
| 0x0A40 || 0x238 || sdstor_mbr_ctx element 0
Line 139: Line 268:
| 0x16FC || 0x20 || [[SceIofilemgr#sceVfsAddVfs|vfs_add_data]] <code>sdstor_dev_fs</code> node
| 0x16FC || 0x20 || [[SceIofilemgr#sceVfsAddVfs|vfs_add_data]] <code>sdstor_dev_fs</code> node
|-
|-
| 0x171C || 0x04 || SceUID of mempool "SceSdStorVfs" of size 0x2000  
| 0x171C || 0x04 || <code>SceSdStorVfs</code> mempool SceUID of size 0x2000
|-
|-
| 0x1720 || 0x200 || unknown (gcd-lp-act-mediaid ?)
| 0x1720 || 0x200 || first sector of external partition (0xD) (gcd-lp-act-mediaid) of game card (interrupt index 1)
|-
|-
| 0x1920 || 0x200 || unknown (mcd-lp-act-mediaid ?)
| 0x1920 || 0x200 || first sector of external partition (0xD) (mcd-lp-act-mediaid) of memory card (interrupt index 2)
|-
|-
| 0x1B20 || 0xC8 || array of 5 structures of size 0x28
| 0x1B20 || 0xC8 || array of 5 <code>interrupt_argument</code> structures
|-
|-
| 0x1BE8 || 0x8 || suspend_register_callback opt
| 0x1BE8 || 0x8 || suspend_register_callback opt
|-
|-
| 0x1BF0 || 0x3C || array of 5 structures of size 0xC
| 0x1BF0 || 0x3C || array of 5 <code>interrupt_info</code> structures
|-
|-
| 0x1C2C || 0x8C || array of 5 structures of size 0x1C
| 0x1C2C || 0x8C || array of 5 <code>unknown_1C2C</code> structures
|-
|-
| 0x1CB8 || 0x8 || unknown
| 0x1CB8 || 0x8 || unknown
|-
|-
| 0x1CC0 || 0x200 || [[Partitions#Master Block|MBR]] of [[Game_Card|Game gard]]
| 0x1CC0 || 0x200 || [[Partitions#Master Block|MBR]] of [[Memory_Card|Memory card]] (xmc device)
|-
|}
|}


== SceSdstor ==
[[Category:ARM]]
 
[[Category:Kernel]]
=== module_start ===
{| class="wikitable"
|-
! Version !! NID
|-
| 3.60 || 0x935cd196
|}
 
<source lang="c">int module_start();</source>
 
[[Category:Modules]]
[[Category:Modules]]
[[Category:Kernel]]

Latest revision as of 11:43, 13 November 2023

Module

This module is responsible for initializing all storage devices. This includes:

Version World Privilege
1.69-3.740.011 Non-secure Kernel

Libraries

SceSdstor module does not export any function exсept module_start.

Interrupt Table

Index Code Name
0 0xDC SceSdif0
1 0xDD SceSdif1
2 0x3C SceMsifIns
3 0xF SceUsbMass
4 0xDF SceSdif3

Block Device Naming Rules

First level prefix: port.

Name Index Long name Description
int 0 internal eMMC
ext 1 external SD card
gcd 1 game card Game Card
mcd 2 memory card Memory Card
uma 3 usb mass USB mass storage device
usd 4 micro sd Micro SD card
xmc 0xFF external memory card Actual Memory Card when internal eMMC is mounted as Memory Card

Second level prefix: kind

  • lp - general.
  • pp - no part.

Third level prefix: stat

  • ina: inactive
  • act: active
  • ign: ignore (same behaviour as inactive)

Fourth level prefix: id

  • unused
  • idstor
  • sloader
  • os
  • vsh
  • vshdata
  • vtrm
  • user
  • userext
  • gamero
  • gamerw
  • updater
  • sysdata
  • mediaid
  • pidata
  • entire

Partition Block Devices

Each partition has a numeric alias (string) that seems to be used to reference the partition.

Numeric names most likely follow order of partitions in MBR.

To access device node use /dev prefix (like /dev/gcd-lp-ign-gamero).

There can be up to 16 aliases from 0 to 15 per physical device (eMMC, Game Card, Memory Card) and alias 16 is hardcoded and called entire.

Not all numeric names are fixed but entire numeric names are hardcoded.

Block device Numeric name Hardcoded
int-lp-ign-idstor 000 no
int-lp-act-sloader/int-lp-ina-sloader 001 no
int-lp-act-sloader/int-lp-ina-sloader 002 no
int-lp-act-os/int-lp-ina-os 003 no
int-lp-act-os/int-lp-ina-os 004 no
int-lp-ign-sysdata 005 no
int-lp-ign-vtrm 006 no
int-lp-ign-vsh 007 no
int-lp-ign-vshdata 008 no
int-lp-ign-updater 009 no
int-lp-ign-pidata 010 no
int-lp-ign-user 011 no
int-lp-ign-userext 012 no
int-lp-act-entire 016 yes
gcd-lp-ign-gamero, gcd-lp-act-mediaid (need to confirm) 100 no
gcd-lp-ign-gamerw (need to confirm) 101 no
ext-lp-act-entire 116 yes
mcd-lp-act-mediaid 200 no
mcd-lp-ign-userext 201 no
mcd-lp-act-entire 216 yes
uma-lp-act-entire 316 yes
usd-lp-act-entire 416 yes

Types

It looks like SceSdstor driver uses its own device type.

Device Type Index Description
0 MMC card
1 SD card
2 Memory Card
3 USB Mass Storage

Also see here (vita-headers)

typedef struct unknown_1C2C { // size is 0x1C
   uint8_t data[0x1C];
} unknown_1C2C;

#define CARD_REMOVE_SDSTOR_REQUEST_EVENT_FLAG 0x01
#define IO_DEVCTL_SDSTOR_REQUEST_EVENT_FLAG 0x02
#define CARD_INSERT_SDSTOR_REQUEST_EVENT_FLAG 0x10
#define SUSPEND_SDSTOR_REQUEST_EVENT_FLAG 0x100
#define RESUME_SDSTOR_REQUEST_EVENT_FLAG 0x1000

typedef struct interrupt_argument { // size is 0x28
  uint32_t unk_0;
  SceUID SceSdstorRequest_evid; // event id
  SceUID SceSdstorOpSync_evid; // event id
  interrupt_info* intr_info; // 
  
  unknown_1C2C* unk_10;

  // card swap protection
  char cid_rnd[0x10]; // cid of the card / randomly generated non zero byte array / zero

  uint8_t intr_table_index; // check interrupt table section (also sd_stor_device index)
  uint8_t unk_25; // = 0
  uint8_t unk_26; // = 0
  uint8_t unk_27;
} interrupt_argument;

typedef int(insert_handler)(int unk, interrupt_argument* arg);

typedef int(remove_handler)(int unk, interrupt_argument* arg);

#define SDSTOR_SUBINTERRUPT_CODE_INSERT 0
#define SDSTOR_SUBINTERRUPT_CODE_REMOVE 1

typedef struct interrupt_info { // size is 0xC
   insert_handler* SceSdstorCardInsert_handler;
   remove_handler* SceSdstorCardRemove_handler;
   uint8_t intr_table_index; // check interrupt table section
   uint8_t SceSdstorCardInsert_subintr_code;
   uint8_t SceSdstorCardRemove_subintr_code;
   uint8_t unk_0xB;
} interrupt_info;

Data segment layout

Address Size Description
0x0000 0x20 unknown
0x0020 0x14 array of 5 integers (number created device handles?) (each corresponds to sd_stor_device)
0x0034 0x4 unknown
0x0038 0x4 SceSdStorDeviceHandle mempool SceUID of size 0x2000
0x003C 0x4 unknown
0x0040 0x200 MBR of eMMC
0x0240 0x200 MBR of Game card
0x0440 0x200 MBR of Memory card
0x0640 0x200 MBR of USB Mass Storage
0x0840 0x200 MBR of micro SD card (usd device)
0x0A40 0x238 sdstor_mbr_ctx element 0
0x0C78 0x238 sdstor_mbr_ctx element 1
0x0EB0 0x238 sdstor_mbr_ctx element 2
0x10E8 0x238 sdstor_mbr_ctx element 3
0x1320 0x238 sdstor_mbr_ctx element 4
0x1558 0x54 sd_stor_device element 0
0x15AC 0x54 sd_stor_device element 1
0x1600 0x54 sd_stor_device element 2
0x1654 0x54 sd_stor_device element 3
0x16A8 0x54 sd_stor_device element 4
0x16FC 0x20 vfs_add_data sdstor_dev_fs node
0x171C 0x04 SceSdStorVfs mempool SceUID of size 0x2000
0x1720 0x200 first sector of external partition (0xD) (gcd-lp-act-mediaid) of game card (interrupt index 1)
0x1920 0x200 first sector of external partition (0xD) (mcd-lp-act-mediaid) of memory card (interrupt index 2)
0x1B20 0xC8 array of 5 interrupt_argument structures
0x1BE8 0x8 suspend_register_callback opt
0x1BF0 0x3C array of 5 interrupt_info structures
0x1C2C 0x8C array of 5 unknown_1C2C structures
0x1CB8 0x8 unknown
0x1CC0 0x200 MBR of Memory card (xmc device)