예제 #1
0
/* main */
int main(int argc, char **argv)
{
	uint32_t dev_handle;
	uint64_t region_id;
	int result;

	netInitialize();

	udp_printf_init();

	PRINTF("%s:%d: start\n", __func__, __LINE__);

	dev_handle = 0;

	result = lv2_storage_open(VFLASH_DEV_ID, &dev_handle);
	if (result) {
		PRINTF("%s:%d: lv2_storage_open failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	result = lv2_storage_create_region(dev_handle, VFLASH_REGION_START_SECTOR, VFLASH_REGION_SECTOR_COUNT,
		0, VFLASH_REGION_LAID, &region_id);
	if (result) {
		PRINTF("%s:%d: lv2_storage_create_region failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	PRINTF("%s:%d: region_id (%d)\n", __func__, __LINE__, region_id);

	PRINTF("%s:%d: end\n", __func__, __LINE__);

	lv2_sm_ring_buzzer(0x1004, 0xa, 0x1b6);

done:

	result = lv2_storage_close(dev_handle);
	if (result)
		PRINTF("%s:%d: lv2_storage_close failed (0x%08x)\n", __func__, __LINE__, result);

	udp_printf_deinit();

	netDeinitialize();

	return 0;
}
예제 #2
0
/*
 * dump_nand_flash
 */
int dump_nand_flash(void)
{
#define NSECTORS	16

	uint32_t dev_handle;
	struct storage_device_info info;
	FILE *fp;
	int start_sector, sector_count;
	uint32_t unknown2;
	uint8_t buf[NAND_FLASH_SECTOR_SIZE * NSECTORS];
	int result;

	dev_handle = 0;
	fp = NULL;

	result = lv2_storage_open(NAND_FLASH_DEV_ID, &dev_handle);
	if (result) {
		printf("%s:%d: lv2_storage_open failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	fp = open_dump();
	if (!fp)
		goto done;

	result = lv2_storage_get_device_info(NAND_FLASH_DEV_ID, &info);
	if (result) {
		printf("%s:%d: lv2_storage_get_device_info failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	printf("%s:%d: capacity (0x%016llx)\n", __func__, __LINE__, info.capacity);

	start_sector = NAND_FLASH_START_SECTOR;
	//sector_count = info.capacity;
	sector_count = EEID_SIZE;

	while (sector_count >= NSECTORS) {
		printf("%s:%d: reading data start_sector (0x%08x) sector_count (0x%08x)\n",
			__func__, __LINE__, start_sector, NSECTORS);

		result = fread(buf, 1, NSECTORS * NAND_FLASH_SECTOR_SIZE, fp);
		if (result < 0) {
			printf("%s:%d: fread failed (0x%08x)\n", __func__, __LINE__, result);
			goto done;
		}

		printf("%s:%d: writing data start_sector (0x%08x) sector_count (0x%08x)\n",
			__func__, __LINE__, start_sector, NSECTORS);

		result = lv2_storage_write(dev_handle, 0, start_sector, NSECTORS, buf, &unknown2, NAND_FLASH_FLAGS);
		if (result) {
			printf("%s:%d: lv2_storage_write failed (0x%08x)\n", __func__, __LINE__, result);
			goto done;
		}

		start_sector += NSECTORS;
		sector_count -= NSECTORS;
	}

	while (sector_count) {
		printf("%s:%d: reading data start_sector (0x%08x) sector_count (0x%08x)\n",
			__func__, __LINE__, start_sector, 1);

		result = fread(buf, 1, NAND_FLASH_SECTOR_SIZE, fp);
		if (result < 0) {
			printf("%s:%d: fread failed (0x%08x)\n", __func__, __LINE__, result);
			goto done;
		}

		printf("%s:%d: writing data start_sector (0x%08x) sector_count (0x%08x)\n",
			__func__, __LINE__, start_sector, 1);

		result = lv2_storage_write(dev_handle, 0, start_sector, 1, buf, &unknown2, NAND_FLASH_FLAGS);
		if (result) {
			printf("%s:%d: lv2_storage_write failed (0x%08x)\n", __func__, __LINE__, result);
			goto done;
		}

		start_sector += 1;
		sector_count -= 1;
	}

	lv2_sm_ring_buzzer(0x1004, 0xa, 0x1b6); //write finished
	fclose(fp);

	return 0;

done:

	if (fp)
		fclose(fp);

	result = lv2_storage_close(dev_handle);
	if (result)
		printf("%s:%d: lv2_storage_close failed (0x%08x)\n", __func__, __LINE__, result);

	return result;

#undef NSECTORS
}
예제 #3
0
/*
 * main
 */
int main(int argc, char **argv)
{
	uint32_t dev_handle;
	FILE *fp;
	int start_sector, sector_count;
	uint32_t unknown2;
	uint8_t buf[VFLASH_SECTOR_SIZE * VFLASH_SECTOR_COUNT];
	int result;

	netInitialize();
	udp_printf_init();
	PRINTF("%s:%d: start\n", __func__, __LINE__);

	dev_handle = 0;
	fp = NULL;

	result = lv2_storage_open(VFLASH_DEV_ID, &dev_handle);
	if (result) {
		PRINTF("%s:%d: lv2_storage_open failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	fp = open_dump();
	if (!fp)
		goto done;

	start_sector = VFLASH_START_SECTOR;
	sector_count = VFLASH_SECTOR_COUNT;

	PRINTF("%s:%d: reading data start_sector (0x%08x) sector_count (0x%08x)\n", __func__, __LINE__, start_sector, sector_count);

	result = lv2_storage_read(dev_handle, 0, start_sector, sector_count, buf, &unknown2, VFLASH_FLAGS);
	if (result) {
		PRINTF("%s:%d: lv2_storage_read failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	usleep(10000);

	PRINTF("%s:%d: dumping data\n", __func__, __LINE__, start_sector, sector_count);

	result = fwrite(buf, 1, VFLASH_SECTOR_COUNT * VFLASH_SECTOR_SIZE, fp);
	if (result < 0) {
		PRINTF("%s:%d: fwrite failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	fclose(fp);

	PRINTF("%s:%d: end\n", __func__, __LINE__);

	lv2_sm_ring_buzzer(0x1004, 0xa, 0x1b6);

done:

	if (fp)
		fclose(fp);

	result = lv2_storage_close(dev_handle);
	if (result)
		PRINTF("%s:%d: lv2_storage_close failed (0x%08x)\n", __func__, __LINE__, result);

	udp_printf_deinit();

	netDeinitialize();

	return 0;
}
예제 #4
0
/*
 * main
 */
int main(int argc, char **argv)
{
	uint32_t dev_handle;
	int start_sector, sector_count;
	struct storage_device_info info;
	uint8_t buf[VFLASH5_SECTOR_SIZE * 16];
	struct os_area_header *hdr;
	struct os_area_params *params;
	uint32_t unknown2;
	int result;

	netInitialize();

	udp_printf_init();

	PRINTF("%s:%d: start\n", __func__, __LINE__);

	dev_handle = 0;

	result = lv2_storage_get_device_info(VFLASH5_DEV_ID, &info);
	if (result) {
		PRINTF("%s:%d: lv2_storage_get_device_info failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	PRINTF("%s:%d: capacity (0x%16llx)\n", __func__, __LINE__, info.capacity);

	if (info.capacity < VFLASH5_HEADER_SECTORS) {
		PRINTF("%s:%d: device capacity too small\n", __func__, __LINE__);
		goto done;
	}

	result = lv2_storage_open(VFLASH5_DEV_ID, &dev_handle);
	if (result) {
		PRINTF("%s:%d: lv2_storage_open failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	/* write os header and params */

	start_sector = 0;
	sector_count = VFLASH5_HEADER_SECTORS;

	PRINTF("%s:%d: reading header start_sector (0x%08x) sector_count (0x%08x)\n",
		__func__, __LINE__, start_sector, sector_count);

	memset(buf, 0, sizeof(buf));
	hdr = (struct os_area_header *) buf;
	params = (struct os_area_params *) (buf + OS_AREA_SEGMENT_SIZE);

	result = lv2_storage_read(dev_handle, 0, start_sector, sector_count, buf, &unknown2, 0);
	if (result) {
		PRINTF("%s:%d: lv2_storage_read failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	if (strncmp((const char *) hdr->magic, HEADER_MAGIC, sizeof(hdr->magic))) {
		PRINTF("%s:%d: invalid header magic\n", __func__, __LINE__, result);
		goto done;
	}

	if (hdr->version != HEADER_VERSION) {
		PRINTF("%s:%d: invalid header version\n", __func__, __LINE__, result);
		goto done;
	}

	if (params->boot_flag != PARAM_BOOT_FLAG_GAME_OS) {
		params->boot_flag = PARAM_BOOT_FLAG_GAME_OS;

		result = lv2_storage_write(dev_handle, 0, start_sector, sector_count, buf, &unknown2, 0);
		if (result) {
			PRINTF("%s:%d: lv2_storage_write failed (0x%08x)\n", __func__, __LINE__, result);
			goto done;
		}
	}

	PRINTF("%s:%d: end\n", __func__, __LINE__);

	lv2_sm_ring_buzzer(0x1004, 0xa, 0x1b6);

done:

	result = lv2_storage_close(dev_handle);
	if (result)
		PRINTF("%s:%d: lv2_storage_close failed (0x%08x)\n", __func__, __LINE__, result);

	udp_printf_deinit();

	netDeinitialize();

	return 0;
}
예제 #5
0
/*
 * setup_vflash
 */
static int setup_vflash(void)
{
	uint32_t dev_handle;
	int start_sector, sector_count;
	uint32_t unknown2;
	uint8_t buf[VFLASH_SECTOR_SIZE * VFLASH_SECTOR_COUNT];
	uint64_t *ptr;
	int result;

	printf("%s:%d: start\n", __func__, __LINE__);

	dev_handle = 0;

	result = lv2_storage_open(VFLASH_DEV_ID, &dev_handle);
	if (result) {
		printf("%s:%d: lv2_storage_open failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	start_sector = VFLASH_START_SECTOR;
	sector_count = VFLASH_SECTOR_COUNT;

	printf("%s:%d: reading data start_sector (0x%08x) sector_count (0x%08x)\n",
		__func__, __LINE__, start_sector, sector_count);

	result = lv2_storage_read(dev_handle, 0, start_sector, sector_count, buf, &unknown2, VFLASH_FLAGS);
	if (result) {
		printf("%s:%d: lv2_storage_read failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	usleep(10000);

	/* check partition table magic */

	if ((*((uint64_t *) buf + 2) != PARTITION_TABLE_MAGIC1) ||
		(*((uint64_t *) buf + 3) != PARTITION_TABLE_MAGIC2)) {
		printf("%s:%d: invalid partition table magic\n", __func__, __LINE__);
		goto done;
	}

	/* patch sector count of VFLASH 6th region */

	ptr = (uint64_t *) (buf + VFLASH_PARTITION_TABLE_6ND_REGION_OFFSET + 0x8ull);

	printf("%s:%d: VFLASH 6th region old sector_count (0x%016llx) new sector_count (0x%016llx)\n",
		__func__, __LINE__, *ptr, VFLASH_6TH_REGION_NEW_SECTOR_COUNT);

	*ptr = VFLASH_6TH_REGION_NEW_SECTOR_COUNT;

	/* patch start sector of VFLASH 7th region */

	ptr = (uint64_t *) (buf + VFLASH_PARTITION_TABLE_7TH_REGION_OFFSET);

	printf("%s:%d: VFLASH 7th region old start_sector (0x%016llx) new start_sector (0x%016llx)\n",
		__func__, __LINE__, *ptr, VFLASH_7TH_REGION_NEW_START_SECTOR);

	*ptr = VFLASH_7TH_REGION_NEW_START_SECTOR;

	printf("%s:%d: writing data start_sector (0x%08x) sector_count (0x%08x)\n",
		__func__, __LINE__, start_sector, sector_count);

	result = lv2_storage_write(dev_handle, 0, start_sector, sector_count, buf, &unknown2, VFLASH_FLAGS);
	if (result) {
		printf("%s:%d: lv2_storage_write failed (0x%08x)\n", __func__, __LINE__, result);
		goto done;
	}

	usleep(10000);

	printf("%s:%d: end\n", __func__, __LINE__);

	return 0;

done:

	result = lv2_storage_close(dev_handle);
	if (result)
		printf("%s:%d: lv2_storage_close failed (0x%08x)\n", __func__, __LINE__, result);

	return result;
}