Example #1
0
int mload_module(void *addr, int len)
{
int ret;
void *buf=NULL;


	if(mload_init()<0) return -1;

    if(hid>=0)
		{
		iosDestroyHeap(hid);
		hid=-1;
		}

	hid = iosCreateHeap(len+0x800);
    
	if(hid<0) return hid;

	buf= iosAlloc(hid, len);

	if(!buf) {ret= -1;goto out;}

	
	memcpy(buf, addr,len);

	ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_LOAD_MODULE, ":d", buf, len);

	if(ret<0) goto out;
	
	ret=IOS_IoctlvFormat(hid, mload_fd, MLOAD_RUN_MODULE, ":");

	if(ret<0) {ret= -666;goto out;}
	
out:
	if(hid>=0)
		{
		iosDestroyHeap(hid);
		hid=-1;
		}
	
return ret;

}
Example #2
0
int mload_close()
{
int ret;

	if(hid>=0)
		{
		iosDestroyHeap(hid);
		hid=-1;
		}

	if(mload_fd<0) return -1;
	
	ret=IOS_Close(mload_fd);
	
	mload_fd=-1;

return ret;
}
Example #3
0
int mload_init()
{
int n;

	if(hid<0) hid = iosCreateHeap(0x800);

	if(hid<0)
		{
		if(mload_fd>=0)
			IOS_Close(mload_fd);

		mload_fd=-1;

		return hid;
		}

	if(mload_fd>=0) 
		{
		return 0;
		}

	for(n=0;n<20;n++) // try 5 seconds
	{
		mload_fd=IOS_Open(mload_fs, 0);
		
		if(mload_fd>=0) break;

		usleep(250*1000);
	}

	if(mload_fd<0)
		{
		
		if(hid>=0)
			{
			iosDestroyHeap(hid);
			hid=-1;
			}
		}

return mload_fd;
}
Example #4
0
int load_fatffs_module(u8 *discid)
{
	static char fs[] ATTRIBUTE_ALIGN(32) = "fat";
	s32 hid = -1, fd = -1;
	static char file_name[256]  ALIGNED(0x20)="SD:";
	int n;
	char *p;
	s32 ret;

	p=&file_name[0];

	if(mload_init()<0) return -1;

	mload_elf((void *) fatffs_module_bin, &my_data_elf);
	my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);
	if(my_thread_id<0) return -1;

    global_mount &=~0xc;

	if(discid)
		{
		sd_ok=ud_ok=1;
				
		/* Function get_fat_name not implemented, this should return the path to the save file */
		// p=get_fat_name(discid);
		p = NULL;
				
		sd_ok=ud_ok=0;
				
		if(!p) return -1;

		global_mount &=~0xf;
			
		// change 'ud:' by 'usb:'
		if(p[0]=='U') {global_mount|=2;file_name[0]='U';file_name[1]='S';file_name[2]='B';memcpy(file_name+3, (void *)p+2, 253);}			   
		else {global_mount|=1;memcpy(file_name, (void *) p, 256);}

		// copy filename to dip_plugin filename area
		mload_seek(*((u32 *) (dip_plugin+14*4)), SEEK_SET);	// offset 14 (filename Address - 256 bytes)
		mload_write(file_name, sizeof(file_name));
		mload_close();

		
		}
	else
		{
		if((global_mount & 3)==0) return 0;
		if(global_mount & 1) p[0]='s';
		if(global_mount & 2) p[0]='u';
		}
	usleep(350*1000);

	/* Create heap */
	if (hid < 0) {
		hid = iosCreateHeap(0x100);
		if (hid < 0)
			return -1; 
	}

	/* Open USB device */
	fd = IOS_Open(fs, 0);
	
	if (fd < 0)
		{
		if(hid>=0)
			{
			iosDestroyHeap(hid);
			hid=-1;
			}
		return -1;
		}
  
	n=30; // try 20 times
	while(n>0)
	{
		if((global_mount & 10)==2) {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTUSB, ":");if(ret==0) global_mount|=8;}
		else {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) {global_mount|=4;}}
		
		if((global_mount & 7)==3 && ret==0)	 
			{ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) global_mount|=4;}

    if((global_mount & 3)==((global_mount>>2) & 3) && (global_mount & 3)) {ret=0;break;} else ret=-1;
	
	//ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");
	//if(ret==0) break;
	usleep(500*1000);
	n--;
	}
Example #5
0
File: usb.c Project: comex/libogc
s32 USB_Deinitialize()
{
	if(hId<0) return IPC_EINVAL;
	return iosDestroyHeap(hId);
}