From 587fdbbae263810c291e0b705c8df758d2e61a32 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sat, 13 Jun 2009 23:39:42 +0000 Subject: [PATCH] *Reverting some stuff to the OLD way before new IOS222 Now if you use 249 there is no change to R492 before 222. So if you still get blackscreens it wasnt caused by that. --- source/libwbfs/libwbfs.c | 155 ++++++++---------------------------- source/libwbfs/libwbfs.h | 9 --- source/libwbfs/libwbfs_os.h | 3 +- source/menu.cpp | 14 +--- source/sys.cpp | 11 +-- source/usbloader/disc.c | 4 +- source/usbloader/disc.h | 2 +- source/usbloader/wbfs.c | 32 +------- source/usbloader/wbfs.h | 8 +- source/usbloader/wdvd.c | 14 ++-- source/usbloader/wdvd.h | 2 +- 11 files changed, 57 insertions(+), 197 deletions(-) diff --git a/source/libwbfs/libwbfs.c b/source/libwbfs/libwbfs.c index bc6032c9..b891c3b5 100644 --- a/source/libwbfs/libwbfs.c +++ b/source/libwbfs/libwbfs.c @@ -25,131 +25,42 @@ static u8 size_to_shift(u32 size) size>>=1; } return ret-1; -} - +} #define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)) -u32 WBFS_part_list[4]={0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}; - - -u32 wbfs_get_partition_LBA(int index) -{ - return WBFS_part_list[index & 3]; -} - - -wbfs_t*wbfs_open_hd(rw_sector_callback_t read_hdsector, - rw_sector_callback_t write_hdsector, - void *callback_data, - int hd_sector_size, int num_hd_sector __attribute((unused)), int reset) -{ - int i=num_hd_sector,ret; - u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size); - u8 part_table[16*4]; - int l; - - ret = read_hdsector(callback_data,0,1,tmp_buffer); - if(ret) - { - wbfs_iofree(tmp_buffer); - return 0; - } - //find wbfs partition - wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4); - ptr = part_table; - - for(l=0;l<4;l++) WBFS_part_list[l]=0xFFFFFFFF; - - l=0; - - for(i=0;i<4;i++,ptr+=16) - { - u32 part_lba = read_le32_unaligned(ptr+0x8); - wbfs_head_t *head = (wbfs_head_t *)tmp_buffer; - - #if 1 - if(head->magic != wbfs_htonl(WBFS_MAGIC)) - if(ptr[4]==0) continue; - - if(ptr[4]==0xf) - { - u32 part_lba2=part_lba; - u32 next_lba2=0; - int n; - - for(n=0;n<8;n++) // max 8 logic partitions (i think it is sufficient!) - { - ret = read_hdsector(callback_data,part_lba+next_lba2 ,1,tmp_buffer); - if(ret) - { - wbfs_iofree(tmp_buffer); - return 0; - } - - part_lba2=part_lba+next_lba2+read_le32_unaligned(tmp_buffer+0x1C6); - next_lba2=read_le32_unaligned(tmp_buffer+0x1D6); - - ret = read_hdsector(callback_data,part_lba2,1,tmp_buffer); - if(ret) - { - wbfs_iofree(tmp_buffer); - return 0; - } - // verify there is the magic. - if (head->magic == wbfs_htonl(WBFS_MAGIC)) - { - - WBFS_part_list[l]=part_lba2; - if(l>0 && WBFS_part_list[l-1]==WBFS_part_list[l]) WBFS_part_list[l]=0xFFFFFFFF; - else l++; if(l>=4) break; - - /*wbfs_t*p = wbfs_open_partition(read_hdsector,write_hdsector, - callback_data,hd_sector_size,0,part_lba2,reset); - return p;*/ - } - - if(next_lba2==0) break; - } - } - else - #endif - { - ret = read_hdsector(callback_data,part_lba,1,tmp_buffer); - - if(ret) - { - wbfs_iofree(tmp_buffer); - return 0; - } - // verify there is the magic. - if (head->magic == wbfs_htonl(WBFS_MAGIC)) - { - WBFS_part_list[l]=part_lba; - if(l>0 && WBFS_part_list[l-1]==WBFS_part_list[l]) WBFS_part_list[l]=0xFFFFFFFF; - else l++; if(l>=4) break; - /* - wbfs_t*p = wbfs_open_partition(read_hdsector,write_hdsector, - callback_data,hd_sector_size,0,part_lba,reset); - return p;*/ - } - } - - if(l>=4) break; - } - - wbfs_iofree(tmp_buffer); - - if(WBFS_part_list[0]==0xFFFFFFFF) return 0; - - // open the first partition finded - - wbfs_t*p = wbfs_open_partition(read_hdsector,write_hdsector, - callback_data,hd_sector_size,0,WBFS_part_list[0],reset); - return p; - -} - +wbfs_t*wbfs_open_hd(rw_sector_callback_t read_hdsector, + rw_sector_callback_t write_hdsector, + void *callback_data, + int hd_sector_size, int num_hd_sector __attribute((unused)), int reset) +{ + int i=num_hd_sector,ret; + u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size); + u8 part_table[16*4]; + ret = read_hdsector(callback_data,0,1,tmp_buffer); + if(ret) + return 0; + //find wbfs partition + wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4); + ptr = part_table; + for(i=0;i<4;i++,ptr+=16) + { + u32 part_lba = read_le32_unaligned(ptr+0x8); + wbfs_head_t *head = (wbfs_head_t *)tmp_buffer; + ret = read_hdsector(callback_data,part_lba,1,tmp_buffer); + // verify there is the magic. + if (head->magic == wbfs_htonl(WBFS_MAGIC)) + { + wbfs_t*p = wbfs_open_partition(read_hdsector,write_hdsector, + callback_data,hd_sector_size,0,part_lba,reset); + return p; + } + } + if(reset)// XXX make a empty hd partition.. + { + } + return 0; +} wbfs_t*wbfs_open_partition(rw_sector_callback_t read_hdsector, rw_sector_callback_t write_hdsector, void *callback_data, diff --git a/source/libwbfs/libwbfs.h b/source/libwbfs/libwbfs.h index d5ef15c7..2f6f1a9f 100644 --- a/source/libwbfs/libwbfs.h +++ b/source/libwbfs/libwbfs.h @@ -122,15 +122,6 @@ wbfs_t*wbfs_open_hd(rw_sector_callback_t read_hdsector, rw_sector_callback_t write_hdsector, void *callback_data, int hd_sector_size, int num_hd_sector, int reset); - -/* call wbfs_open_hd at first time to find the WBFS partition on the HDD (max 4 partitions) - -wbfs_get_partition_LBA receive 0 to 3 as partition index (first, second...) and return 0xFFFFFFFF if WBFS partition is not finded - - -*/ - -u32 wbfs_get_partition_LBA(int index); /*! @brief open a wbfs partition @param read_hdsector,write_hdsector: accessors to the partition diff --git a/source/libwbfs/libwbfs_os.h b/source/libwbfs/libwbfs_os.h index fe910aae..7b3efbaa 100644 --- a/source/libwbfs/libwbfs_os.h +++ b/source/libwbfs/libwbfs_os.h @@ -14,8 +14,7 @@ #define wbfs_malloc(x) malloc(x) #define wbfs_free(x) free(x) -#define wbfs_ioalloc(x) memalign(32, x) -#define wbfs_iofree(x) free(x) // XXX should allocate in a ios heap +#define wbfs_ioalloc(x) memalign(32, x) #define wbfs_iofree(x) free(x) #define wbfs_be16(x) (*((u16*)(x))) #define wbfs_be32(x) (*((u32*)(x))) diff --git a/source/menu.cpp b/source/menu.cpp index 90b157bc..90d41384 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -1324,7 +1324,7 @@ static int MenuInstall() int menu = MENU_NONE; static struct discHdr headerdisc ATTRIBUTE_ALIGN(32); - Disc_SetUSB(NULL, GetPartition()); + Disc_SetUSB(NULL); int ret, choice = 0; char *name; @@ -1582,10 +1582,7 @@ static int MenuFormat() menu = MENU_SETTINGS; } else { - for(int i = 0; i < 4; i++) { - ret = WBFS_Open2(i); - if(ret == 0) break; - } + ret = WBFS_Open(); sprintf(text, "%s %s", text,LANGUAGE.formated); WindowPrompt(LANGUAGE.Success,text,LANGUAGE.ok,0,0,0); menu = MENU_DISCLIST; @@ -1700,10 +1697,7 @@ static int MenuCheck() Sys_LoadMenu(); } - for(i = 0; i < 4; i++) { - ret2 = WBFS_Open2(i); - if(ret2 == 0) break; - } + ret2 = WBFS_Open(); if (ret2 < 0) { choice = WindowPrompt(LANGUAGE.NoWBFSpartitionfound, LANGUAGE.Youneedtoformatapartition, @@ -1871,7 +1865,7 @@ int MainMenu(int menu) Sys_IosReload(249); } } - ret = Disc_SetUSB(header->id, GetPartition()); + ret = Disc_SetUSB(header->id); if(ret < 0) Sys_BackToLoader(); ret = Disc_Open(); if(ret < 0) Sys_BackToLoader(); diff --git a/source/sys.cpp b/source/sys.cpp index a01725c3..8c6b7846 100644 --- a/source/sys.cpp +++ b/source/sys.cpp @@ -81,15 +81,14 @@ int Sys_IosReload(int IOS) SDCard_deInit(); USBDevice_deInit(); - mload_close(); - WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); - USBStorage_Deinit(); WDVD_Close(); + USBStorage_Deinit(); + if(IOS == 249 || IOS == 222 || IOS == 223) { for(int i = 0; i < 10; i++) { ret = IOS_ReloadIOS(IOS); @@ -102,12 +101,8 @@ int Sys_IosReload(int IOS) } if(ret>=0) { ret = Disc_Init(); - int i = 0; if(ret>=0) { - for(i = 0; i < 4; i++) { - ret = WBFS_Open2(i); - if(ret == 0) break; - } + ret = WBFS_Open(); } } else Sys_BackToLoader(); } diff --git a/source/usbloader/disc.c b/source/usbloader/disc.c index 32eeca29..51a6c9d9 100644 --- a/source/usbloader/disc.c +++ b/source/usbloader/disc.c @@ -217,10 +217,10 @@ s32 Disc_Wait(void) return 0; } -s32 Disc_SetUSB(u8 *id, int ios222) +s32 Disc_SetUSB(u8 *id) { /* Set USB mode */ - return WDVD_SetUSBMode(id, ios222); + return WDVD_SetUSBMode(id); } s32 Disc_ReadHeader(void *outbuf) diff --git a/source/usbloader/disc.h b/source/usbloader/disc.h index d7d3f82c..d78366ab 100644 --- a/source/usbloader/disc.h +++ b/source/usbloader/disc.h @@ -43,7 +43,7 @@ s32 Disc_Init(void); s32 Disc_Open(void); s32 Disc_Wait(void); void __Disc_SetLowMem(void); -s32 Disc_SetUSB(u8 *, int ios222); +s32 Disc_SetUSB(u8 *); s32 Disc_ReadHeader(void *); s32 Disc_IsWii(void); s32 Disc_BootPartition(u64, u8, u8, u8, u8, u8); diff --git a/source/usbloader/wbfs.c b/source/usbloader/wbfs.c index 9214c489..539d35c7 100644 --- a/source/usbloader/wbfs.c +++ b/source/usbloader/wbfs.c @@ -21,8 +21,7 @@ static wbfs_t *hdd = NULL; /* WBFS callbacks */ static rw_sector_callback_t readCallback = NULL; -static rw_sector_callback_t writeCallback = NULL; -static int current_partition = 0; +static rw_sector_callback_t writeCallback = NULL; /* Variables */ @@ -75,35 +74,6 @@ void __WBFS_Spinner(s32 x, s32 max) wbfs_t *GetHddInfo(void) { return hdd; -} - -s32 WBFS_Open2(int index) // index 0-3 -{ - u32 lba; - /* Close hard disk */ - if (hdd) - wbfs_close(hdd);hdd=0; - - lba = wbfs_get_partition_LBA(index); - - current_partition = index & 3; - - if(lba==0xFFFFFFFF) - { - if((index & 3)==0) return WBFS_Open(); - return -1; - } - /* Open hard disk */ - hdd = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, 0, lba, 0); - if (!hdd) - return -1; - - return 0; -} - -s32 GetPartition() -{ - return current_partition; } s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf) diff --git a/source/usbloader/wbfs.h b/source/usbloader/wbfs.h index 2f8c4dfa..b396c00e 100644 --- a/source/usbloader/wbfs.h +++ b/source/usbloader/wbfs.h @@ -20,9 +20,7 @@ enum { /* Prototypes */ s32 WBFS_Init(u32); -s32 WBFS_Open(); -s32 WBFS_Open2(int partition); -s32 GetPartition(); +s32 WBFS_Open(void); s32 WBFS_Close(void); s32 WBFS_Format(u32, u32); s32 WBFS_GetCount(u32 *); @@ -37,6 +35,10 @@ s32 WBFS_DiskSpace(f32 *, f32 *); s32 WBFS_RenameGame(u8 *, const void *); f32 WBFS_EstimeGameSize(void); +s32 __WBFS_ReadUSB(void *fp, u32 lba, u32 count, void *iobuf); +s32 __WBFS_WriteUSB(void *fp, u32 lba, u32 count, void *iobuf); + + #ifdef __cplusplus } #endif diff --git a/source/usbloader/wdvd.c b/source/usbloader/wdvd.c index dad5ea3e..cbb3b3ef 100644 --- a/source/usbloader/wdvd.c +++ b/source/usbloader/wdvd.c @@ -322,7 +322,7 @@ s32 WDVD_DisableReset(u8 val) } /** Hermes **/ -s32 WDVD_SetUSBMode(u8 *id, s32 partition) +s32 WDVD_SetUSBMode(u8 *id) { s32 ret; @@ -334,19 +334,17 @@ s32 WDVD_SetUSBMode(u8 *id, s32 partition) /* Copy ID */ - if (id) - { + if (id) { memcpy(&inbuf[2], id, 6); - inbuf[5] = partition; - } + } ret = IOS_Ioctl(di_fd, IOCTL_DI_SETUSBMODE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if(ret!=1) - { // Try old cIOS 222 + if(ret!=1) { + // Try old cIOS 222 /* Set USB mode */ inbuf[0] = DI_SETWBFSMODE << 24; ret = IOS_Ioctl(di_fd, DI_SETWBFSMODE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - } + } if (ret < 0) return ret; diff --git a/source/usbloader/wdvd.h b/source/usbloader/wdvd.h index e3a41799..3d2bd710 100644 --- a/source/usbloader/wdvd.h +++ b/source/usbloader/wdvd.h @@ -23,7 +23,7 @@ s32 WDVD_Read(void *, u32, u64); s32 WDVD_WaitForDisc(void); s32 WDVD_GetCoverStatus(u32 *); s32 WDVD_DisableReset(u8); -s32 WDVD_SetUSBMode(u8 *, s32); +s32 WDVD_SetUSBMode(u8 *); #ifdef __cplusplus }