Example #1
0
int omap4_mmc_init(void)
{
	int i;
	char booticmd[20];
	int boot_slot = get_boot_slot();

	/* If we booted off of SD slot, initialize SD card as well. */
	if (boot_slot == 0) {
		printf("Initializing SD(0) Slot.\n");
		/* Temporarily set mmc_slot to SD */
		mmc_slot = 0;
		if (mmc_init(boot_slot)) {
			printf("mmc init failed?\n");
			return 1;
		}
		load_ptbl();
	}

	/* Default back to eMMC(1) slot
	  * If someone wants to flash all partitions to SD slot
	  * they need to explicty give "fastboot oem set_boot_slot:SD"
	  */
	mmc_slot = 1;

	if (mmc_init(mmc_slot)) {
		printf("mmc init failed?\n");
		return 1;
	}
	sprintf(booticmd, "booti mmc%d", boot_slot);
	setenv("bootcmd", booticmd);
	printf("efi partition table:\n");
	return load_ptbl();
}
Example #2
0
int board_late_init(void)
{
	if (mmc_init(1)) {
		printf("mmc init failed?\n");
		return 1;
	}
	printf("\nefi partition table:\n");
	return load_ptbl();
}
Example #3
0
/**
*  get_partition_sz: Returns size of requested paritition in eMMC
* @buf: Caller buffer pointer the size will be returned in
* @partname: partittion name being requested
*/
char * get_partition_sz(char *buf, const char *partname)
{
	struct ptable *ptbl = &the_ptable;
	struct efi_header *hdr = &ptbl->header;
	struct efi_entry *entry = ptbl->entry;
	unsigned n, i;
	char curr_partname[EFI_NAMELEN];
	u64 fist_lba, last_lba, sz;
	u32 crc_orig;
	u32 crc;
	u32 *szptr = (u32 *) &sz;

	if (mmc_read(mmc_slot, 0,  (void *)ptbl, sizeof(struct ptable)) != 1){
		printf("\n ERROR Reading Partition Table \n");
		return buf;
	}

	/*Make sure there is a legit partition table*/
	if (load_ptbl()){
		printf("\n INVALID PARTITION TABLE \n");
		return buf;
	}

	/*crc needs to be computed with crc zeroed out.*/
	crc_orig = hdr->crc32;
	hdr->crc32 = 0;
	crc = crc32(0,0,0);
	crc = crc32(0, (void *) &ptbl->header, sizeof(ptbl->header));
	if (crc != crc_orig){
		printf("\n INVALID HEADER CRC!!\n");
		return buf;
	}

	for (n=0; n < EFI_ENTRIES; n++, entry++) {
		for (i = 0; i < EFI_NAMELEN; i++)
			curr_partname[i] = (char) entry->name[i];
		if (!strcmp(curr_partname, partname)){
			if (entry->last_lba < entry->first_lba){
				printf("\n REDICULOUS LENGTH!! \n");
				break;
			}
			sz = (entry->last_lba - entry->first_lba)/2;
			if (sz >= 0xFFFFFFFF)
				sprintf(buf, "0x%08x , %08x KB", szptr[1], szptr[0]);
			else
				sprintf(buf, "%d KB", szptr[0]);

			break;
		}
	}
	return buf;
}
Example #4
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;
}
Example #5
0
int do_booti(struct bootloader_ops *boot_ops, char *info, void *download_addr)
{
	boot_img_hdr *hdr;
	u32 addr;
	u64 sector1, sector2;
	char *ptn = "boot";
	int boot_from_mmc = 0;
	u64 num_sectors = 0;
	int sector_sz = 0;
	int ret = 0;
	unsigned dbt_addr = CONFIG_ADDR_ATAGS;
	unsigned cfg_machine_type = CONFIG_BOARD_MACH_TYPE;
	void (*theKernel)(int zero, int arch, void *);

	if (!(strcmp(info, "storage")))
		boot_from_mmc = 1;

	if (download_addr != NULL)
		addr = (u32) download_addr;
	else
		addr = CONFIG_ADDR_DOWNLOAD;

	hdr = (boot_img_hdr *) addr;

	if (boot_from_mmc) {

		struct fastboot_ptentry *pte;

		ret = load_ptbl(boot_ops->storage_ops, 0);
		if (ret != 0)
			goto fail;

		dbt_addr = load_dev_tree(boot_ops, dbt_addr);
		if (dbt_addr < 0)
			goto fail;

		pte = fastboot_flash_find_ptn(ptn);
		if (!pte) {
			printf("booti: cannot find '%s' partition\n", ptn);
			goto fail;
		}

		sector_sz = boot_ops->storage_ops->get_sector_size();
		num_sectors =  sizeof(boot_img_hdr) / sector_sz;
		ret = boot_ops->storage_ops->read(pte->start, num_sectors,
							(void *) hdr);
		if (ret != 0) {
			printf("booti: failed to read bootimg header\n");
			goto fail;
		} else
			bootimg_print_image_hdr(hdr);

		ret = memcmp(hdr->magic, BOOT_MAGIC, 8);
		if (ret != 0) {
			printf("booti: bad boot image magic\n");
			goto fail;
		}

		sector1 = pte->start + (hdr->page_size / sector_sz);

		sector2 = sector1 +
			ALIGN(hdr->kernel_size, hdr->page_size) / sector_sz;

		num_sectors = CEIL(hdr->kernel_size, sector_sz);
		if (num_sectors <= (hdr->kernel_size / sector_sz))
			num_sectors = (hdr->kernel_size / sector_sz);

		DBG("Reading kernel from start sector %d and reading %d "
			"number of sectors\n", (int)sector1, (int)num_sectors);

		ret = boot_ops->storage_ops->read(sector1, num_sectors,
					(void *) hdr->kernel_addr);
		if (ret != 0) {
			printf("mmc read failed\n");
			goto fail;
		}

		DBG("Done reading kernel from mmc\n");

		num_sectors = CEIL(hdr->ramdisk_size, sector_sz);
		if (num_sectors <= (hdr->ramdisk_size / sector_sz))
			num_sectors = (hdr->ramdisk_size / sector_sz);

		DBG("Reading ramdisk from start sector %d and reading %d "
			"number of sectors\n", (int)sector2, (int)num_sectors);

		ret = boot_ops->storage_ops->read(sector2, num_sectors,
					(void *) hdr->ramdisk_addr);
		if (ret != 0) {
			printf("mmc read failed\n");
			goto fail;
		}

		DBG("Done reading ramdisk from mmc\n");

	} else {
		u32 kaddr, raddr;

		DBG("user wants to boot an image downloaded using "
							"fastboot\n");

		ret = memcmp(hdr->magic, BOOT_MAGIC, 8);
		if (ret != 0) {
			printf("booti: bad boot image magic\n");
			goto fail;
		}

		bootimg_print_image_hdr(hdr);

		kaddr = addr + hdr->page_size;

		raddr = kaddr + ALIGN(hdr->kernel_size, hdr->page_size);

		memmove((void *) hdr->kernel_addr, (void *)kaddr,
							hdr->kernel_size);
		memmove((void *) hdr->ramdisk_addr, (void *)raddr,
							hdr->ramdisk_size);
	}

	printf("kernel   @ %08x (%d)\n", hdr->kernel_addr, hdr->kernel_size);
	printf("ramdisk  @ %08x (%d)\n", hdr->ramdisk_addr, hdr->ramdisk_size);

#if defined CONFIG_OMAP4_ANDROID_CMD_LINE || \
	defined CONFIG_OMAP5_ANDROID_CMD_LINE
	boot_settings(boot_ops, &hdr[0], CONFIG_ADDR_ATAGS);
#endif

#if defined START_HYPERVISOR_MODE && defined CONFIG_IS_OMAP5
	if (!(strcmp(boot_ops->proc_ops->proc_get_type(), "GP"))) {
		printf("Starting ARM Hyp mode\n");
		start_hyp_mode(MONITOR_API_START_HYPERVISOR);
	}
#endif

	theKernel = (void (*)(int, int, void *))(hdr->kernel_addr);

	printf("booting kernel...\n");
	theKernel(0, cfg_machine_type, (void *)dbt_addr);

fail:
	ret = boot_ops->usb_ops->usb_open(boot_ops->usb_ops->usb, INIT_USB,
							boot_ops->proc_ops);
	if (ret != 0) {
		printf("\nusb_open failed\n");
		return ret;
	}
	do_fastboot(boot_ops);
	return 0;
}
Example #6
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;
}