Esempio n. 1
0
int load_ptbl(int mmc_cont)
{
	static unsigned char data[512];
	static struct efi_entry entry[4];
	int n,m,r;

	fastboot_flash_reset_ptn();
	r = mmc_read(mmc_cont, 1, data, 512);
	if (r != 1) {
		printf("error reading partition table\n");
		return -1;
	}
	if (memcmp(data, "EFI PART", 8)) {
		//printf("efi partition table not found\n");
		return -1;
	}

	for (n = 0; n < (128/4); n++) {
		r = mmc_read(mmc_cont, 2 + n, (void*) entry, 512);
		if (r != 1) {
			printf("partition read failed\n");
			return 1;
		}
		for (m = 0; m < 4; m ++)
			import_efi_partition(entry + m);
	}
	return 0;
}
Esempio n. 2
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;
}