Memory Stick info?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Memory Stick info?

Post by Art »

Hi Guys,
I'm chasing any method of finding any Memory Stick info besides
the obvious free space and scanning files to calculate space consumed.
Then there's the sum of both to estimate the total capacity.

Particularly, there must be an easy way for the PSP to gain some device
information prior to formatting any Memory Stick.
Art.
If not actually, then potentially.
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

About capacity did you try to open it as a block device and do a sceIoLseek ? (to have the exact size)

[edit] and multiply the result by 512[/edit]
--pspZorba--
NO to K1.5 !
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Well, there is a way.... This is a little library for the MS we used for some various applications (Credits to C+D and Booster, and various places i took constants and structs from) as well as a 1.5 test (you just need to make a PRX for 3.x) application which reads out the MS Pro attributes to memory stick and shows the MS name and unique ID on the screen:
ms_drv.h:

Code: Select all

#define WSBW&#40;d&#41; &#40;&#40;&#40;&#40;d&#41;&0x000000ff&#41; << 24&#41; | &#40;&#40;&#40;d&#41;&0x0000ff00&#41; << 8&#41; | &#40;&#40;&#40;d&#41;&0x00ff0000&#41; >> 8&#41; | &#40;&#40;&#40;d&#41;&0xff000000&#41; >> 24&#41;&#41;
#define WSBH&#40;d&#41; &#40;&#40;&#40;&#40;d&#41;&0x00ff&#41; << 8&#41; | &#40;&#40;&#40;d&#41;&0xff00&#41; >> 8&#41;&#41;

#define MSPRO_DEVINFOID_SYSINFO                         &#40;0x10&#41;
#define MSPRO_DEVINFOID_MODELNAME                       &#40;0x15&#41;
#define MSPRO_DEVINFOID_MBR                             &#40;0x20&#41;
#define MSPRO_DEVINFOID_PBR16                           &#40;0x21&#41;
#define MSPRO_DEVINFOID_PBR32                           &#40;0x22&#41;
#define MSPRO_DEVINFOID_SPECFILEVALUES1                 &#40;0x25&#41;
#define MSPRO_DEVINFOID_SPECFILEVALUES2                 &#40;0x26&#41;
#define MSPRO_DEVINFOID_IDENTIFYDEVINFO                 &#40;0x30&#41;

typedef struct tag_wbmspro_attribute &#123;
        u16 signature;
        u16 version;
        u8 device_information_entry_count;
        u8 reserved&#91;11&#93;;
&#125; __attribute__ &#40;&#40;packed&#41;&#41; wbmspro_attribute_t;

typedef struct tag_wbmspro_device_info_entry_item &#123;
        u32 address;
        u32 size;
        u8 info_id;
        u8 reserved&#91;3&#93;;
&#125; __attribute__ &#40;&#40;packed&#41;&#41; wbmspro_device_info_entry_item_t;

typedef struct tag_wbmspro_sys_info &#123;
        u8 class;               // must be ?
        u8 reserved;            // see below
        u16 block_size;         // n KB
        u16 block_count;        // number of physical block
        u16 user_block_count;   // number of logical block
        u16 page_size;          // must be 0x200
        u8 reserved1&#91;2&#93;;        // MS original Extra data size and format reserved
        u8 assembly_date&#91;8&#93;;
        u32 serial_number;
        u8 assembly_maker_code;
        u8 assembly_model_code&#91;3&#93;;
        u16 memory_maker_code;
        u16 memory_model_code;
        u8 reserved2&#91;4&#93;;        //reserved&#91;6&#93;
        u8 vcc;
        u8 vpp;
        u16 controller_number;
        u16 controller_function;
        u16 start_sector;
        u16 unit_size;
        u8 ms_sub_class;
        u8 reserved3&#91;4&#93;;
        u8 interface_type;
        u16 controller_code;
        u8 format_type;
        u8 reserved4;;
        u8 device_type;
        u8 reserved5&#91;7&#93;;
        u8 mspro_id&#91;16&#93;;
        u8 reserved6&#91;16&#93;;
&#125; __attribute__ &#40;&#40;packed&#41;&#41; wbmspro_sys_info_t;

#define SHOW_READ_DATA     0
#define SHOW_ERR_MSG       0
#define SHOW_SECTOR_ACCESS 0
#define SHOW_STATUS_REG    0

#define IO_MEM_STICK_CMD *&#40;&#40;volatile int*&#41;&#40;0xBD200030&#41;&#41;
#define IO_MEM_STICK_DATA *&#40;&#40;volatile int*&#41;&#40;0xBD200034&#41;&#41;
#define IO_MEM_STICK_STATUS *&#40;&#40;volatile int*&#41;&#40;0xBD200038&#41;&#41;
#define IO_MEM_STICK_SYS *&#40;&#40;volatile int*&#41;&#40;0xBD20003C&#41;&#41;

#define MSRST 0x8000

#define MS_FIFO_RW 0x4000
#define MS_RDY 0x1000
#define MS_TIME_OUT 0x100
#define MS_CRC_ERROR 0x200


#define READ_PAGE_DATA 0x2000
#define READ_REG 0x4000
#define GET_INT 0x7000
#define SET_RW_REG_ADRS 0x8000
#define EX_SET_CMD 0x9000

#define WRITE_REG               &#40;0xB000&#41;
#define SET_CMD                 &#40;0xE000&#41;

#define INT_REG_CED   0x80
#define INT_REG_ERR   0x40
#define INT_REG_BREQ  0x20
#define INT_REG_CMDNK 0x01
/*
;NORM_COMP       = &#40;ced && !err&#41;
;CMD_ERR_TER     = &#40;ced && err&#41;
;NORM_DATA_TRANS = &#40;!err && breq&#41;
;DATA_REQ_ERR    = &#40;err && breq&#41;
;CMD_EXE         = &#40;!ced && !breq&#41;
;CMD_NOT_EXE     = cmdnk
*/
//PROTOTYPES&#58;
void pspMsBootStart&#40;&#41;;
int pspMsInit&#40;void&#41;;
int pspMsReadSector&#40;int sector, void *addr&#41;;
int pspMsReadAttrB&#40;int attr, void *addr&#41;;
int pspMsWriteSector&#40;int sector, void *addr&#41;;
ms_drv.c:

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "ms_drv.h"

/****************************************************************************
****************************************************************************/
static int ms_wait_ready&#40;void&#41;
&#123;
        int status;
//Kprintf&#40;"ms_wait_ready\n"&#41;;
        do&#123;
                status = IO_MEM_STICK_STATUS;
        &#125;while&#40;!&#40;status & MS_RDY&#41;&#41;;

        if &#40;status & &#40;MS_CRC_ERROR|MS_TIME_OUT&#41;&#41;
        &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;ms_wait_ready %08X\n",status&#41;;
#endif
                return -1;
        &#125;
        return 0;
&#125;

/****************************************************************************
****************************************************************************/
static int send_data_and_sync&#40;int arg1, int arg2&#41;
&#123;
  int ret;
  IO_MEM_STICK_DATA = arg1;
  IO_MEM_STICK_DATA = arg2;
  ret = ms_wait_ready&#40;&#41;;
  return ret;
&#125;
/****************************************************************************
****************************************************************************/
static int ms_get_reg_int&#40;void&#41;
&#123;
  int ret, dummy, status;

  IO_MEM_STICK_CMD = GET_INT | 0x1;

  do&#123;
    status = IO_MEM_STICK_STATUS;
    if&#40;status & MS_TIME_OUT&#41;
    &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;get_reg_int timeout\n"&#41;;
#endif
         return -1;
        &#125;
  &#125;while&#40;!&#40;status & MS_FIFO_RW&#41;&#41;;

  ret = IO_MEM_STICK_DATA;
  dummy = IO_MEM_STICK_DATA;

  do&#123;
    status = IO_MEM_STICK_STATUS;
    if&#40;status & MS_TIME_OUT&#41;
    &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;get_reg_int timeout\n"&#41;;
#endif
         return -1;
        &#125;
  &#125;while&#40;!&#40;status & MS_RDY&#41;&#41;;

  return ret & 0xff;
&#125;
/****************************************************************************
****************************************************************************/
static int read_data&#40;void *addr, int count&#41;
&#123;
  int i;
  int status;
  for&#40;i = 0; i<count; i+= 4&#41;&#123;
    do&#123;
      status = IO_MEM_STICK_STATUS;
      if &#40;status & MS_TIME_OUT&#41; return -1;
    &#125;while&#40;!&#40;status & MS_FIFO_RW&#41;&#41;;
    *&#40;&#40;volatile int*&#41;&#40;addr + i&#41;&#41; = IO_MEM_STICK_DATA;

#if SHOW_READ_DATA
Kprintf&#40;"%08X ",*&#40;&#40;volatile int*&#41;&#40;addr + i&#41;&#41;&#41;;
if&#40; &#40;i%0x20&#41; ==0x1c&#41; Kprintf&#40;"\n"&#41;;
#endif

  &#125;
  return 0;
&#125;

static int write_data&#40;void *addr, int count&#41;
&#123;
  int i;
  int status;
  for&#40;i = 0; i<count; i+= 4&#41;&#123;
    do&#123;
      status = IO_MEM_STICK_STATUS;
      if &#40;status & MS_TIME_OUT&#41; return -1;
    &#125;while&#40;!&#40;status & MS_FIFO_RW&#41;&#41;;
    IO_MEM_STICK_DATA = *&#40;&#40;volatile int*&#41;&#40;addr + i&#41;&#41;;

#if SHOW_READ_DATA
Kprintf&#40;"%08X ",*&#40;&#40;volatile int*&#41;&#40;addr + i&#41;&#41;&#41;;
if&#40; &#40;i%0x20&#41; ==0x1c&#41; Kprintf&#40;"\n"&#41;;
#endif

  &#125;
  return 0;
&#125;

/****************************************************************************
****************************************************************************/
static int ms_get_reg&#40;void *buffer, int reg&#41;&#123;
  int ret;

//Kprintf&#40;"READ_REG\n"&#41;;
  IO_MEM_STICK_CMD = READ_REG | reg;
  ret = read_data&#40;buffer, reg&#41;;

  return ret;
&#125;


/****************************************************************************
****************************************************************************/
static void ms_wait_unk1&#40;void&#41;
&#123;
        while&#40;!&#40;IO_MEM_STICK_STATUS & 0x2000&#41;&#41;;
&#125;

/****************************************************************************
****************************************************************************/
static void ms_wait_ced&#40;void&#41;
&#123;
        int result;
//Kprintf&#40;"wait CED\n"&#41;;
        do&#123;
                result = ms_get_reg_int&#40;&#41;;
        &#125;while&#40;&#40;result < 0&#41; || &#40; &#40;result & INT_REG_CED&#41; == 0&#41;&#41;;
&#125;
/****************************************************************************
        setup & check status register
****************************************************************************/
static int ms_check_status&#40;void&#41;
&#123;
        int ret;
        u8 sts&#91;8&#93;;

        //set rw reg addrs of type reg &#40;?&#41;
        IO_MEM_STICK_CMD = SET_RW_REG_ADRS | 0x4;
#if 1
        ret = send_data_and_sync&#40;0x06100800,0x00000000&#41;;
#else
        IO_MEM_STICK_DATA = 0x06100800;
        IO_MEM_STICK_DATA = 0x00000000;
        ret = ms_wait_ready&#40;&#41;;
#endif
        if &#40;ret != 0&#41; return -1;

        ms_get_reg&#40;sts, 8&#41;;
#if SHOW_STATUS_REG
Kprintf&#40;"STATUS %02X CHK&#91;%02X&#93; %02X %02X PRO&#91;%02X&#93; %02X %02X %02X \n",sts&#91;0&#93;,sts&#91;1&#93;,sts&#91;2&#93;,sts&#91;3&#93;,sts&#91;4&#93;,sts&#91;5&#93;,sts&#91;6&#93;,sts&#91;7&#93;&#41;;
#endif

#if 1
        if&#40;sts&#91;4&#93; != 0x01&#41;
        &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"PRE-IPL Supported MS Pro only!\n"&#41;;
#endif
                return -1;
        &#125;

        if&#40; &#40;sts&#91;2&#93; & 0x15&#41; != 0&#41; return -1;
#else
        // status 0 to 7
        u32 val_a = *&#40;&#40;volatile int*&#41;&#40;&sts&#91;0&#93;&#41;&#41;;
        u32 val_b = *&#40;&#40;volatile int*&#41;&#40;&sts&#91;4&#93;&#41;&#41;;

        // STS&#91;02&#93;
        if &#40;&#40;val_a >> 16&#41; & 0x15 != 0&#41; return -1;
#endif
        return 0;
&#125;

/****************************************************************************
****************************************************************************/
int pspMsInit&#40;void&#41;
&#123;
//Kprintf&#40;"_ms_init\n"&#41;;

  //initialize the hardware
        *&#40;&#40;volatile int*&#41;&#40;0xBC100054&#41;&#41; |= 0x00000100;
        *&#40;&#40;volatile int*&#41;&#40;0xBC100050&#41;&#41; |= 0x00000400;
        *&#40;&#40;volatile int*&#41;&#40;0xBC100078&#41;&#41; |= 0x00000010;
        *&#40;&#40;volatile int*&#41;&#40;0xBC10004C&#41;&#41; &= 0xFFFFFEFF;

printf&#40;"reset\n"&#41;;

        //reset the controller
        IO_MEM_STICK_SYS = MSRST;
        while&#40;IO_MEM_STICK_SYS & MSRST&#41;;

printf&#40;"check status\n"&#41;;
        ms_check_status&#40;&#41;;
        printf&#40;"wait ready status\n"&#41;;
        ms_wait_ready&#40;&#41;;
        printf&#40;"wait ced\n"&#41;;
        //ms_wait_ced&#40;&#41;;

        return 0;
&#125;
/****************************************************************************
****************************************************************************/
int pspMsReadSector&#40;int sector, void *addr&#41;
&#123;
        int ret;

#if SHOW_SECTOR_ACCESS
Kprintf&#40;"ms_read_sector&#40;%08X,%08X&#41;\n",sector,addr&#41;;
#endif

/*
MS format
SYS_PARAM_REG           &#40;0x10&#41;
BLOCK_ADD_REG2          &#40;0x11&#41;
BLOCK_ADD_REG1          &#40;0x12&#41;
BLOCK_ADD_REG0          &#40;0x13&#41;
CMD_PARAM_REG           &#40;0x14&#41;
PAGE_ADD_REG            &#40;0x15&#41;
OVER_WR_FLAG_REG        &#40;0x16&#41;

MSPro format
//size = 1;
buf&#91;0&#93; = mode; // 0x10
buf&#91;1&#93; = &#40;size & 0xFF00&#41; >> 8;
buf&#91;2&#93; = &#40;size & 0xFF&#41;;
buf&#91;3&#93; = &#40;address & 0xFF000000&#41; >> 24;
buf&#91;4&#93; = &#40;address & 0x00FF0000&#41; >> 16;
buf&#91;5&#93; = &#40;address & 0x0000FF00&#41; >> 8;
buf&#91;6&#93; = &#40;address & 0x000000FF&#41;;
buf&#91;7&#93; = 0x00;

*/
  //send a command with 8 bytes of params, reverse endian. &#40;0x200001XX 0xYYYYYY00&#41; => READ_DATA
  IO_MEM_STICK_CMD = EX_SET_CMD | 0x7;
  ret = send_data_and_sync&#40;0x010020 | &#40;sector>>24&#41;<<24, &#40;&#40;sector>>16&#41;&0xff&#41; | &#40;sector&0xff00&#41; | &#40;&#40;sector<<16&#41;&0xff0000&#41; &#41;;
  if &#40;ret < 0&#41; return -1;

  ms_wait_unk1&#40;&#41;;

//Kprintf&#40;"wait BREQ\n"&#41;;
  do&#123;
    ret = ms_get_reg_int&#40;&#41;;
    if &#40;ret < 0&#41; return -1;
  &#125;while&#40;&#40;ret & INT_REG_BREQ&#41; == 0&#41;;

  if &#40;ret & INT_REG_ERR&#41;
  &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;ms wait int\n"&#41;;
#endif
     return -1;
  &#125;

//Kprintf&#40;"READ_PAGE_DATA\n"&#41;;

        //send command to read data and get the data.
        IO_MEM_STICK_CMD = READ_PAGE_DATA | 512;
        ret = read_data&#40;addr, 512&#41;;
        if &#40;ret < 0&#41; return -1;

        if &#40;ms_wait_ready&#40;&#41; < 0&#41; return -1;
        ms_wait_unk1&#40;&#41;;
        ms_wait_ced&#40;&#41;;

  return 0;
&#125;

int pspMsReadAttrB&#40;int attr, void *addr&#41;
&#123;
        int ret;


  IO_MEM_STICK_CMD = EX_SET_CMD | 0x7;
  ret = send_data_and_sync&#40;0x010024 | &#40;attr>>24&#41;<<24, &#40;&#40;attr>>16&#41;&0xff&#41; | &#40;attr&0xff00&#41; | &#40;&#40;attr<<16&#41;&0xff0000&#41; &#41;;
  if &#40;ret < 0&#41; return -1;

  ms_wait_unk1&#40;&#41;;

//Kprintf&#40;"wait BREQ\n"&#41;;
  do&#123;
    ret = ms_get_reg_int&#40;&#41;;
    if &#40;ret < 0&#41; return -1;
  &#125;while&#40;&#40;ret & INT_REG_BREQ&#41; == 0&#41;;

  if &#40;ret & INT_REG_ERR&#41;
  &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;ms wait int\n"&#41;;
#endif
     return -1;
  &#125;
        IO_MEM_STICK_CMD = READ_PAGE_DATA | 512;
        ret = read_data&#40;addr, 512&#41;;
        if &#40;ret < 0&#41; return -1;

        if &#40;ms_wait_ready&#40;&#41; < 0&#41; return -1;
        ms_wait_unk1&#40;&#41;;
        ms_wait_ced&#40;&#41;;

  return 0;
&#125;

int pspMsWriteSector&#40;int sector, void *addr&#41;
&#123;
        int ret;

#if SHOW_SECTOR_ACCESS
Kprintf&#40;"ms_read_sector&#40;%08X,%08X&#41;\n",sector,addr&#41;;
#endif

/*
MS format
SYS_PARAM_REG           &#40;0x10&#41;
BLOCK_ADD_REG2          &#40;0x11&#41;
BLOCK_ADD_REG1          &#40;0x12&#41;
BLOCK_ADD_REG0          &#40;0x13&#41;
CMD_PARAM_REG           &#40;0x14&#41;
PAGE_ADD_REG            &#40;0x15&#41;
OVER_WR_FLAG_REG        &#40;0x16&#41;

MSPro format
//size = 1;
buf&#91;0&#93; = mode; // 0x10
buf&#91;1&#93; = &#40;size & 0xFF00&#41; >> 8;
buf&#91;2&#93; = &#40;size & 0xFF&#41;;
buf&#91;3&#93; = &#40;address & 0xFF000000&#41; >> 24;
buf&#91;4&#93; = &#40;address & 0x00FF0000&#41; >> 16;
buf&#91;5&#93; = &#40;address & 0x0000FF00&#41; >> 8;
buf&#91;6&#93; = &#40;address & 0x000000FF&#41;;
buf&#91;7&#93; = 0x00;

*/
  //send a command with 8 bytes of params, reverse endian. &#40;0x200001XX 0xYYYYYY00&#41; => READ_DATA
  IO_MEM_STICK_CMD = EX_SET_CMD | 0x7;
  ret = send_data_and_sync&#40;0x010021 | &#40;sector>>24&#41;<<24, &#40;&#40;sector>>16&#41;&0xff&#41; | &#40;sector&0xff00&#41; | &#40;&#40;sector<<16&#41;&0xff0000&#41; &#41;;
  if &#40;ret < 0&#41; return -1;

  ms_wait_unk1&#40;&#41;;

//Kprintf&#40;"wait BREQ\n"&#41;;
  do&#123;
    ret = ms_get_reg_int&#40;&#41;;
    if &#40;ret < 0&#41; return -1;
  &#125;while&#40;&#40;ret & INT_REG_BREQ&#41; == 0&#41;;

  if &#40;ret & INT_REG_ERR&#41;
  &#123;
#if SHOW_ERR_MSG
Kprintf&#40;"err&#58;ms wait int\n"&#41;;
#endif
     return -1;
  &#125;

//Kprintf&#40;"READ_PAGE_DATA\n"&#41;;

        //send command to read data and get the data.
        IO_MEM_STICK_CMD = 0xD000 | 512;
        ret = write_data&#40;addr, 512&#41;;
        if &#40;ret < 0&#41; return -1;

        if &#40;ms_wait_ready&#40;&#41; < 0&#41; return -1;
        ms_wait_unk1&#40;&#41;;
        ms_wait_ced&#40;&#41;;

  return 0;
&#125;

static int send_data_and_syncw&#40;int arg1&#41;
&#123;
  int ret;
  IO_MEM_STICK_DATA = arg1;
  ret = ms_wait_ready&#40;&#41;;
  return ret;
&#125;

int pspMsEraseBlock&#40;&#41;
&#123;
        int ret;

#if SHOW_SECTOR_ACCESS
Kprintf&#40;"ms_read_sector&#40;%08X,%08X&#41;\n",sector,addr&#41;;
#endif
/*
MS format
SYS_PARAM_REG           &#40;0x10&#41;
BLOCK_ADD_REG2          &#40;0x11&#41;
BLOCK_ADD_REG1          &#40;0x12&#41;
BLOCK_ADD_REG0          &#40;0x13&#41;
CMD_PARAM_REG           &#40;0x14&#41;
PAGE_ADD_REG            &#40;0x15&#41;
OVER_WR_FLAG_REG        &#40;0x16&#41;

MSPro format
//size = 1;
buf&#91;0&#93; = mode; // 0x10
buf&#91;1&#93; = &#40;size & 0xFF00&#41; >> 8;
buf&#91;2&#93; = &#40;size & 0xFF&#41;;
buf&#91;3&#93; = &#40;address & 0xFF000000&#41; >> 24;
buf&#91;4&#93; = &#40;address & 0x00FF0000&#41; >> 16;
buf&#91;5&#93; = &#40;address & 0x0000FF00&#41; >> 8;
buf&#91;6&#93; = &#40;address & 0x000000FF&#41;;
buf&#91;7&#93; = 0x00;

*/
  //send a command with 8 bytes of params, reverse endian. &#40;0x200001XX 0xYYYYYY00&#41; => READ_DATA
  IO_MEM_STICK_CMD = EX_SET_CMD | 0x7;
  ret = send_data_and_sync&#40;0x26, 0&#41;;
  if &#40;ret < 0&#41; return -1;

  ms_wait_unk1&#40;&#41;;

        if &#40;ms_wait_ready&#40;&#41; < 0&#41; return -1;


  return 0;
&#125;

u32 FindProc&#40;const char* szMod, const char* szLib, u32 nid&#41;
&#123;
        struct SceLibraryEntryTable *entry;
        SceModule *pMod;
        void *entTab;
        int entLen;

        pMod = sceKernelFindModuleByName&#40;szMod&#41;;

        if &#40;!pMod&#41;
        &#123;
                printf&#40;"Cannot find module %s\n", szMod&#41;;
                return 0;
        &#125;

        int i = 0;

        entTab = pMod->ent_top;
        entLen = pMod->ent_size;
        //***printf&#40;"entTab %p - entLen %d\n", entTab, entLen&#41;;
        while&#40;i < entLen&#41;
    &#123;
                int count;
                int total;
                unsigned int *vars;

                entry = &#40;struct SceLibraryEntryTable *&#41; &#40;entTab + i&#41;;

        if&#40;entry->libname && !strcmp&#40;entry->libname, szLib&#41;&#41;
                &#123;
                        total = entry->stubcount + entry->vstubcount;
                        vars = entry->entrytable;

                        if&#40;entry->stubcount > 0&#41;
                        &#123;
                                for&#40;count = 0; count < entry->stubcount; count++&#41;
                                &#123;
                                        if &#40;vars&#91;count&#93; == nid&#41;
                                                return vars&#91;count+total&#93;;
                                &#125;
                        &#125;
                &#125;

                i += &#40;entry->len * 4&#41;;
        &#125;

        printf&#40;"Funtion not found.\n"&#41;;
        return 0;
&#125;
void *FindSysregFunction&#40;u32 nid&#41;
&#123;
        return &#40;void *&#41;FindProc&#40;"sceSYSREG_Driver", "sceSysreg_driver", nid&#41;;
&#125;

void pspMsBootStart&#40;&#41;&#123;
        int &#40;* sceSysregMsifClkDisable&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifBusClockDisable&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifResetEnable&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifResetDisble&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifClkEnable&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifBusClockEnable&#41;&#40;int&#41;;
        int &#40;* sceSysregMsifIoEnable&#41;&#40;int&#41;;

        int &#40;* sceSysconCtrlMsPower&#41;&#40;int&#41;;

        sceSysregMsifClkDisable = FindSysregFunction&#40;0x8E2D835D&#41;;
        sceSysregMsifBusClockDisable = FindSysregFunction&#40;0x826430C0&#41;;
        sceSysregMsifResetEnable = FindSysregFunction&#40;0x00C2628E&#41;;
        sceSysregMsifResetDisble = FindSysregFunction&#40;0xEC4BF81F&#41;;
        sceSysregMsifClkEnable = FindSysregFunction&#40;0x31154490&#41;;
        sceSysregMsifBusClockEnable = FindSysregFunction&#40;0x4716E71E&#41;;
        sceSysconCtrlMsPower = &#40;void *&#41;FindProc&#40;"sceSYSCON_Driver", "sceSyscon_driver", 0x99BBB24C&#41;;
        sceSysregMsifIoEnable = FindSysregFunction&#40;0xD74F1D48&#41;;
        //======================================================
        sceSysregMsifClkDisable&#40;0&#41;;
        sceSysregMsifBusClockDisable&#40;0&#41;;
        sceSysregMsifResetEnable&#40;0&#41;;
        sceSysregMsifResetDisble&#40;0&#41;;
        sceSysregMsifClkEnable&#40;0&#41;;
        sceSysregMsifBusClockEnable&#40;0&#41;;
        sceSysregMsifIoEnable&#40;0&#41;;

        printf&#40;"About to power.\n"&#41;;

        sceSysconCtrlMsPower&#40;1&#41;;
        printf&#40;"About to do stuff.\n"&#41;;
        sceKernelDelayThread&#40;10000&#41;;

        pspMsInit&#40;&#41;;
&#125;
test.c:

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "ms_drv.h"

PSP_MODULE_INFO&#40;"MemStickTest", 0x1000, 1, 0&#41;;

PSP_MAIN_THREAD_ATTR&#40;0&#41;;

#define printf  pspDebugScreenPrintf


void ErrorExit&#40;int milisecs, char *fmt, ...&#41;
&#123;
        va_list list;
        char msg&#91;256&#93;;

        va_start&#40;list, fmt&#41;;
        vsprintf&#40;msg, fmt, list&#41;;
        va_end&#40;list&#41;;

        printf&#40;msg&#41;;

        sceKernelDelayThread&#40;milisecs*1000&#41;;
        sceKernelExitGame&#40;&#41;;
&#125;



u8      buffer&#91;1024*1024&#93;;
int main&#40;&#41;
&#123;
        int i;
        u32 sysinfo_addr = 0;
        u32 modname_addr = 0;
        wbmspro_attribute_t *ptr_attr = 0;
        wbmspro_device_info_entry_item_t *ptr_entry = 0;
        wbmspro_sys_info_t* s_info = 0;

        pspDebugScreenInit&#40;&#41;;
        printf&#40;"This program makes attr0.bin on the root of the memory stick.\n"&#41;;

        printf&#40;"result for sector 0 = %08X\n", pspMsReadAttrB&#40;0, buffer&#41;&#41;;
        printf&#40;"result for sector 1 = %08X\n", pspMsReadAttrB&#40;1, buffer + 512&#41;&#41;;
        printf&#40;"result for sector 2 = %08X\n", pspMsReadAttrB&#40;2, buffer + 1024&#41;&#41;;
        printf&#40;"read from attributes and... "&#41;;
        int fd = sceIoOpen&#40;"ms0&#58;/attr0.bin", PSP_O_WRONLY | PSP_O_CREAT, 0777&#41;;
        sceIoWrite&#40;fd, buffer, 3*512&#41;;
        sceIoClose&#40;fd&#41;;
        printf&#40;"wrote to file! \n"&#41;;

        ptr_attr = &#40;wbmspro_attribute_t*&#41; buffer;
        printf&#40;"Signature&#58; %04X &#40;should be 0xA5C3&#41;\n", WSBH&#40;ptr_attr->signature&#41;&#41;;
        printf&#40;"Version&#58; %04X\n", WSBH&#40;ptr_attr->version&#41;&#41;;
        printf&#40;"Number of entries&#58; %02X\n", ptr_attr->device_information_entry_count&#41;;
        for &#40;i = 0; i < ptr_attr->device_information_entry_count; i++&#41;&#123;
                ptr_entry = &#40;wbmspro_device_info_entry_item_t*&#41; &#40;buffer+ 0x10 + 0xC*i&#41;;
                printf&#40;"Entry %d, ID is %01X\n", i, ptr_entry->info_id&#41;;
                printf&#40;"Address is %08X, size is %08X\n", &#40;unsigned int&#41;WSBW&#40;ptr_entry->address&#41;, &#40;unsigned int&#41;WSBW&#40;ptr_entry->size&#41;&#41;;

                switch &#40;ptr_entry->info_id&#41;&#123;
                        case 0x10&#58; sysinfo_addr = &#40;int&#41;buffer + WSBW&#40;ptr_entry->address&#41;; break;
                        case 0x15&#58; modname_addr = &#40;int&#41;buffer + WSBW&#40;ptr_entry->address&#41;; break;
                        default&#58; break;
                &#125;
        &#125;
        s_info = &#40;wbmspro_sys_info_t*&#41; sysinfo_addr;
        printf&#40;"====================================================================\n"&#41;;
        printf&#40;"Serial number&#58; %08X\n", &#40;unsigned int&#41;s_info->serial_number&#41;;
        printf&#40;"MSProID&#58;\n"&#41;;
        printf&#40;"0x"&#41;;
        for&#40;i = 0; i< 0x10; i++&#41;&#123;
                printf&#40;"%02X", s_info->mspro_id&#91;i&#93;&#41;;
        &#125;
        printf&#40;"\nModel name&#58; \"%s\"\n", &#40;char*&#41;modname_addr&#41;;
        ErrorExit&#40;37000, "\nFinished.\n"&#41;;

        return 0;
&#125;
Makefile:

Code: Select all

TARGET = mstest
OBJS = main.o ms_drv.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = MemStick Test

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
If you look at wbmspro_sys_info_t declaration in ms_drv.h, you'll see that you can get the size, block size, assembly date...

Have fun :)
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

thank you for sharing
--pspZorba--
NO to K1.5 !
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Try this Art:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO&#40;"MS Test", PSP_MODULE_USER, 1, 1&#41;;

typedef struct
&#123;
	unsigned long	max_clusters;
	unsigned long	free_clusters;
	int				unk1;
	int				sector_size;
	int				sector_count;
	
&#125; sDevCtl;

typedef struct
&#123;
	sDevCtl *p_dev_inf;
	
&#125; sDevCommand;

int main&#40;void&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	
	sDevCtl dev_ctl;
	sDevCommand	command;

	command.p_dev_inf = &dev_ctl;

	sceIoDevctl&#40;"ms0&#58;", 0x02425818, &command, sizeof&#40;sDevCommand&#41;, NULL, 0&#41;;
	
	u64 freespace = &#40;dev_ctl.free_clusters * dev_ctl.sector_count&#41; * dev_ctl.sector_size;
	
	u64 mssize = &#40;dev_ctl.max_clusters * dev_ctl.sector_count&#41; * dev_ctl.sector_size;
	
	pspDebugScreenPrintf&#40;"Free size&#58; %0.2f\n", &#40;float&#41;freespace/1024.0f/1024.0f&#41;;
	
	pspDebugScreenPrintf&#40;"MS size&#58; %0.2f\n", &#40;float&#41;mssize/1024.0f/1024.0f&#41;;
	
	sceKernelDelayThread&#40;5*1000*1000&#41;;
	
	sceKernelExitGame&#40;&#41;;
	
	return 0;
&#125;
I'm not sure how it will handle sticks > 4gb so you may need to test that.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

That would work too :)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

pspZorba wrote:About capacity did you try to open it as a block device and do a sceIoLseek ? (to have the exact size)

[edit] and multiply the result by 512[/edit]
You don't have to multiply by 512, as the msstor driver uses the byte as unit (despite the fact that it cannot write or seek anything that is not multiple of 512, I don't know why Sony did it in that stupid way).
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

For sure that's very strange, I would have expected the same behavior as the umd ...
--pspZorba--
NO to K1.5 !
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Ah, thanks guys for the goodies :)
Will get to testing them out immediately.
edit,,,
(you just need to make a PRX for 3.x)
The whole thing appears to work under 1.50 kernel,
and works with my 8Gb, but the same eboot won't run from
a 32Mb that came with the PSP value pack.
If not actually, then potentially.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Ah... it's for MSPro only :) It uses the READ_ATRB command which is not there in normal memory stick ^^' But who uses 32MB memory sticks nowadays?
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Well I guess I can't use it with my 8Mb Memory Stick either then.
That's the one I keep the ISO collection on.
(yes there is an 8Mb MS!).
If not actually, then potentially.
Post Reply