Esempio n. 1
0
int mount_sd_fat(const char *path)
{
    int result = -1;

    // get command and client
    void* pClient = malloc(sizeof(FSClient));
    void* pCmd = malloc(sizeof(FSCmdBlock));

    if(!pClient || !pCmd) {
        // just in case free if not 0
        if(pClient)
            free(pClient);
        if(pCmd)
            free(pCmd);
        return -2;
    }

    FSInit();
    FSInitCmdBlock(pCmd);
    FSAddClient(pClient, -1);

    char *mountPath = NULL;

    if(MountFS(pClient, pCmd, &mountPath) == 0) {
        result = sd_fat_add_device(path, mountPath, pClient, pCmd);
        free(mountPath);
    }

    return result;
}
Esempio n. 2
0
s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition)
{
	// close
	WBFS_Close();

	dbg_printf("openpart(%d %d %d %d)\n", part_fs, part_idx, part_lba, part_size);
	if (part_fs == PART_FS_UNK) return -1;
	if (part_fs == PART_FS_WBFS) {
		if (WBFS_OpenLBA(part_lba, part_size)) return -1;
	} else {
		MountPoint *mp = mount_find_part(wbfsDev, part_lba);
		if (mp) {
			mount_name2drive(mp->name, wbfs_fs_drive);
		} else {
			if (MountFS(GAME_MOUNT, wbfsDev, part_lba, part_fs, 1)) return -1;
			mount_name2drive(GAME_MOUNT, wbfs_fs_drive);
		}
	}

	// success
	wbfs_part_fs  = part_fs;
	wbfs_part_idx = part_idx;
	wbfs_part_lba = part_lba;
	sprintf(partition, "%s%d", get_fs_name(part_fs), wbfs_part_idx);
	dbg_printf("game part=%s\n", partition);
	return 0;
}
Esempio n. 3
0
int main(void)
{
    uint8_t *buffer = (uint8_t *)(((uint32_t)padded_buffer + 15) & ~15);
    SdLoaderInfo *info = (SdLoaderInfo *)_load_start_coguser0;
    uint32_t load_address, index_width, offset_width, addr, count;
    uint32_t tags_size, cache_size, cache_lines, cache_tags, mboxes, *sp;
    VolumeInfo vinfo;
    FileInfo finfo;
    PexeFileHdr *hdr;
    int sd_id, i;
    uint8_t *p;

    // determine the cache size and setup cache variables
    index_width = info->cache_geometry >> 8;
    offset_width = info->cache_geometry & 0xff;
    tags_size = (1 << index_width) * 4;
    cache_size = 1 << (index_width + offset_width);
    cache_lines = HUB_SIZE - cache_size;
    cache_tags = cache_lines - tags_size;
    mboxes = cache_tags - sizeof(xmem_mbox_t) * 8 - 4;
    xmem_mbox = (xmem_mbox_t *)mboxes;

    // load the external memory driver
    DPRINTF("Loading external memory driver\n");
    memset((void *)mboxes, 0, sizeof(xmem_mbox_t) * 8 + 4);
    xmem_mbox[8].hubaddr = XMEM_END;
    cognew(_load_start_coguser1, mboxes);
    
    DPRINTF("Loading SD driver\n");
    sd_mbox = (uint32_t *)mboxes - 2;
    sd_mbox[0] = 0xffffffff;
    if ((sd_id = cognew(_load_start_coguser2, sd_mbox)) < 0) {
        DPRINTF("Error loading SD driver\n");
        return 1;
    }
    while (sd_mbox[0])
        ;

    DPRINTF("Initializing SD card\n");
    if (SD_Init(sd_mbox, 5) != 0) {
        DPRINTF("SD card initialization failed\n");
        return 1;
    }
	
    DPRINTF("Mounting filesystem\n");
    if (MountFS(buffer, &vinfo) != 0) {
        DPRINTF("MountFS failed\n");
        return 1;
    }
    
    // open the .pex file
    DPRINTF("Opening 'autorun.pex'\n");
    if (FindFile(buffer, &vinfo, FILENAME, &finfo) != 0) {
        DPRINTF("FindFile '%s' failed\n", FILENAME);
        return 1;
    }

	// read the file header
	DPRINTF("Reading PEX file header\n");
	if (GetNextFileSector(&finfo, kernel_image, &count) != 0 || count < PEXE_HDR_SIZE) {
	    DPRINTF("Error reading PEX file header\n");
		return 1;
	}
		
	// verify the header
    DPRINTF("Verifying PEX file header\n");
    hdr = (PexeFileHdr *)kernel_image;
    if (strncmp(hdr->tag, PEXE_TAG, sizeof(hdr->tag)) != 0 || hdr->version != PEXE_VERSION) {
        DPRINTF("Bad PEX file header\n");
        return 1;
    }
	load_address = hdr->loadAddress;
	
	// move past the header
	memmove(kernel_image, (uint8_t *)kernel_image + PEXE_HDR_SIZE, SECTOR_SIZE - PEXE_HDR_SIZE);
	p = (uint8_t *)kernel_image + SECTOR_SIZE - PEXE_HDR_SIZE;
	
    // read the .kernel cog image
    DPRINTF("Reading kernel image\n");
    for (i = 1; i < 4; ++i) {
    	if (GetNextFileSector(&finfo, p, &count) != 0 || count < SECTOR_SIZE)
    		return 1;
        p += SECTOR_SIZE;
    }
    
    // load the image
    DPRINTF("Loading image at 0x%08x\n", load_address);
    addr = load_address;
    while (GetNextFileSector(&finfo, buffer, &count) == 0) {
        write_block(addr, buffer, XMEM_SIZE_512);
        addr += SECTOR_SIZE;
    }

    // stop the sd driver
    DPRINTF("Stopping SD driver\n");
    cogstop(sd_id);
    
    // setup the stack
    // at start stack contains xmem_mbox, cache_tags, cache_lines, cache_geometry, pc
    sp = (uint32_t *)mboxes;
    *--sp = load_address;
    *--sp = info->cache_geometry;
    *--sp = cache_lines;
    *--sp = cache_tags;
    *--sp = mboxes;

    // start the xmm kernel boot code
    DPRINTF("Starting kernel\n");
    coginit(cogid(), kernel_image, sp);

    // should never reach this
    return 0;
}