示例#1
0
static int do_format(void)
{
	struct ptable *ptbl = &the_ptable;
	unsigned next;
	int n;
	block_dev_desc_t *dev_desc;
	unsigned long blocks_to_write, result;

	dev_desc = get_dev_by_name(FASTBOOT_BLKDEV);
	if (!dev_desc) {
		printf("error getting device %s\n", FASTBOOT_BLKDEV);
		return -1;
	}
	if (!dev_desc->lba) {
		printf("device %s has no space\n", FASTBOOT_BLKDEV);
		return -1;
	}

	printf("blocks %lu\n", dev_desc->lba);

	start_ptbl(ptbl, dev_desc->lba);
	for (n = 0, next = 0; fbt_partitions[n].name; n++) {
		u64 sz = fbt_partitions[n].size_kb * 2;
		if (fbt_partitions[n].name[0] == '-') {
			next += sz;
			continue;
		}
		if (sz == 0)
			sz = dev_desc->lba - next;
		if (add_ptn(ptbl, next, next + sz - 1, fbt_partitions[n].name))
			return -1;
		next += sz;
	}
	end_ptbl(ptbl);

	blocks_to_write = DIV_ROUND_UP(sizeof(struct ptable), dev_desc->blksz);
#if defined(CONFIG_MACH_MESON8_ODROIDC)
	/* Since the bootloader is located on MBR, the board partition must be
	 * stored in other sector. In ODROIDC, it is just after bootloader.
	 * <start sector> = <bootloader size (kB) / 512
	 */
	result = dev_desc->block_write(dev_desc->dev,
                        CONFIG_CUSTOM_MBR_LBA, blocks_to_write, ptbl);
#else
	result = dev_desc->block_write(dev_desc->dev, 0, blocks_to_write, ptbl);
#endif
	if (result != blocks_to_write) {
		printf("\nFormat failed, block_write()"
                                " returned %lu instead of %lu\n",
                                result, blocks_to_write);
		return -1;
	}

	printf("\nnew partition table of %lu %lu-byte blocks\n",
		blocks_to_write, dev_desc->blksz);
	fbt_reset_ptn();

	return 0;
}
示例#2
0
static int do_format(int fd)
{
	struct ptable *ptbl = &the_ptable;
	unsigned sector_sz, blocks;
	unsigned next;
	int n;

	if (ioctl(fd, BLKGETSIZE, &blocks) < 0) {
		printf("\n cannot read blksize on fd=%d\n", fd);
		return -1;
	}
	printf("blocks %d\n", blocks);

	start_ptbl(ptbl, blocks);
	n = 0;
	next = 0;
	for (n = 0, next = 0; partitions[n].name; n++) {
		unsigned sz = partitions[n].size_kb * 2;
		if (!strcmp(partitions[n].name,"-")) {
			next += sz;
			continue;
		}
		if (!strncmp(partitions[n].name,"reserve", 7)) {
			sz = sz / 1024;
		}
		if (sz == 0)
			sz = blocks - next;
		if (add_ptn(ptbl, next, next + sz - 1, partitions[n].name))
			return -1;
		next += sz;
	}
	end_ptbl(ptbl);

	if (lseek(fd, 0, SEEK_SET) < 0) {
		printf("\n seek error \n");
		return -1;
	}
	if (write(fd, (void*) ptbl, sizeof(struct ptable)) < 0) {
		printf("\n ptable write failure \n");
		return -1;
	}

	printf("\nWritten new partition table...\n");
	//print_ptable(fd);

	return 0;
}
示例#3
0
static int do_format(void)
{
	struct ptable *ptbl = &the_ptable;
	unsigned sector_sz, blocks;
	unsigned next;
	int n;

	printf("Formatting %s(%d) slot.\n", mmc_slot?"EMMC":"SD", mmc_slot);
	if (mmc_init(mmc_slot)) {
		printf("mmc init failed?\n");
		return -1;
	}

	mmc_info(mmc_slot, &sector_sz, &blocks);
	printf("blocks %d\n", blocks);

	start_ptbl(ptbl, blocks);
	n = 0;
	next = 0;
	for (n = 0, next = 0; partitions[n].name; n++) {
		unsigned sz = partitions[n].size_kb * 2;
		if (!strcmp(partitions[n].name,"-")) {
			next += sz;
			continue;
		}
		if (sz == 0)
			sz = blocks - next;
		if (add_ptn(ptbl, next, next + sz - 1, partitions[n].name))
			return -1;
		next += sz;
	}
	end_ptbl(ptbl);

	fastboot_flash_reset_ptn();
	if (mmc_write(mmc_slot, (void*) ptbl, 0, sizeof(struct ptable)) != 1)
		return -1;

	printf("\nnew partition table:\n");
	load_ptbl();

	return 0;
}
示例#4
0
int do_gpt_format(struct fastboot_data *fb_data)
{
	/* For testing need to pass this in better */
	struct ptable *ptbl;
	u64 total_sectors = 0;
	u64 next;
	int n;
	u32 sector_sz = fb_data->storage_ops->get_sector_size();
	u64 ptbl_sectors = 0;
	int ret = 0;

#ifdef DEBUG
	int i = 0; int j = 0;
	u8 *data;
	u32 *blocksp = &total_sectors;
	data = (u8 *)alloc_memory(sizeof(struct ptable));
#endif

	DBG("do_format\n");

	ptbl_sectors = sizeof(struct ptable) / sector_sz;

	total_sectors = fb_data->storage_ops->get_total_sectors();
	DBG("sector_sz %u\n", sector_sz);
	DBG("total_sectors 0x%x%08x\n", blocksp[1], blocksp[0]);

	ptbl = (struct ptable *) alloc_memory(sizeof(struct ptable));
	if (!ptbl) {
		printf("%s: Unable to alloc mem for ptbl\n", __func__);
		return -1;
	}
	start_ptbl(ptbl, total_sectors);
	if (fb_data->board_ops->board_get_part_tbl)
		partitions = fb_data->board_ops->board_get_part_tbl();

	n = 0;
	next = 0;
	for (n = 0, next = 0; partitions[n].name; n++) {
		u64 sz_sectors = 0;
		sz_sectors = (u64)partitions[n].size_kb << 1;
		if (!strcmp(partitions[n].name, "-")) {
			next += sz_sectors;
			continue;
		}
		if (sz_sectors == 0)
			sz_sectors = total_sectors - next;

		if (add_ptn(ptbl, next, next + sz_sectors - 1,
				partitions[n].name)) {
			printf("Unable to add_ptn\n");
			ret = -1;
			goto format_err;
		}

		next += sz_sectors;
	}

	end_ptbl(ptbl);

	DBG("writing ptable to disk: %d #of sectors\n", ptbl_sectors);
	ret = fb_data->storage_ops->write(0, ptbl_sectors, (void *)ptbl);
	if (ret) {
		printf("Write PTBL failed\n");
		goto format_err;
	}

	DBG("writing the GUID Table disk ...\n");
#ifdef DEBUG
	ret = fb_data->storage_ops->read(0, ptbl_sectors, (void *)data);
	if (ret != 0) {
		printf("error reading MBR\n");
		return ret;
	} else {
			printf("printing ptable\n");
			for (i = 0; i < sizeof(struct ptable); i++)
				printf("%02X ", data[i]);
			printf("\n");
		}
#endif
	DBG("\nnew partition table:\n");
	ret = load_ptbl(fb_data->storage_ops, 0);
	if (ret != 0) {
		printf("Failed to load partition table\n");
		goto format_err;
	}
format_err:
	free_memory(ptbl);
#ifdef DEBUG
	free_memory(data);
#endif
	return ret;
}