2 * (C) Copyright 2014 Lothar Waßmann <LW@KARO-electronics.de>
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
21 #include <fdt_support.h>
24 #include <linux/list.h>
26 #include <jffs2/load_kernel.h>
31 #define CONFIG_MMC_BOOT_DEV 0
33 DECLARE_GLOBAL_DATA_PTR;
35 #define MAX_SEARCH_PARTITIONS 16
37 static int find_efi_partition(const char *ifname, int devno, const char *part_str,
38 block_dev_desc_t **dev_desc,
39 disk_partition_t *info)
47 dd = get_dev(ifname, devno);
48 if (!dd || dd->type == DEV_TYPE_UNKNOWN) {
49 printf("** Bad device %s %d **\n", ifname, devno);
55 * No partition table on device,
56 * or user requested partition 0 (entire device).
58 if (dd->part_type == PART_TYPE_UNKNOWN) {
59 printf("** No partition table - %s %d **\n", ifname,
65 for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
66 ret = get_partition_info(dd, p, info);
70 if (strcmp((char *)info->name, part_str) == 0) {
72 dd->log2blksz = LOG2(dd->blksz);
77 printf("** No valid partitions found **\n");
90 int karo_load_mmc_part(const char *part, void *addr, size_t len)
94 disk_partition_t part_info;
95 int devno = CONFIG_MMC_BOOT_DEV;
96 uint blk_start, blk_cnt;
97 block_dev_desc_t *mmc_dev;
99 mmc = find_mmc_device(devno);
101 printf("Failed to find mmc%u\n", devno);
107 ret = find_efi_partition("mmc", devno, part, &mmc_dev, &part_info);
109 printf("eMMC partition '%s' not found: %d\n", part, ret);
112 mmc_switch_part(devno, ret);
115 blk_cnt = DIV_ROUND_UP(len, part_info.blksz);
117 debug("Found partition '%s': offset=%08x size=%08lx\n",
118 part, blk_start, part_info.size);
119 if (part_info.size < blk_cnt)
120 blk_cnt = part_info.size;
122 debug("Reading %u blks from MMC partition '%s' offset %u to %p\n",
123 blk_cnt, part, blk_start, addr);
124 ret = mmc->block_dev.block_read(devno, blk_start, blk_cnt, addr);
126 printf("Failed to read MMC partition %s\n", part);
130 debug("Read %u byte from partition '%s' @ offset %08x\n",
131 ret * mmc->read_bl_len, part, blk_start);
133 mmc_switch_part(devno, 0);
134 return ret < 0 ? ret : 0;