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>
25 #include <linux/list.h>
27 #include <jffs2/load_kernel.h>
32 #define CONFIG_MMC_BOOT_DEV 0
34 DECLARE_GLOBAL_DATA_PTR;
36 static void __maybe_unused memdmp(void *addr, size_t len)
40 for (i = 0; i < len; i+= 16) {
44 debug("%p: ", addr + i);
45 for (j = 0; j < 4; j++) {
46 debug(" %08x", wp[j]);
52 #define MAX_SEARCH_PARTITIONS 16
54 static int find_efi_partition(const char *ifname, int devno, const char *part_str,
55 block_dev_desc_t **dev_desc,
56 disk_partition_t *info)
64 printf("Searching for partition '%s'\n", part_str);
66 dd = get_dev(ifname, devno);
67 if (!dd || dd->type == DEV_TYPE_UNKNOWN) {
68 printf("** Bad device %s %d **\n", ifname, devno);
74 * No partition table on device,
75 * or user requested partition 0 (entire device).
77 if (dd->part_type == PART_TYPE_UNKNOWN) {
78 printf("** No partition table - %s %d **\n", ifname,
84 for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
85 ret = get_partition_info(dd, p, info);
89 if (strcmp((char *)info->name, part_str) == 0) {
91 dd->log2blksz = LOG2(dd->blksz);
96 printf("** No valid partitions found **\n");
109 int karo_load_mmc_part(const char *part, void *addr, size_t len)
113 disk_partition_t part_info;
114 int devno = CONFIG_MMC_BOOT_DEV;
115 uint blk_start, blk_cnt;
117 mmc = find_mmc_device(devno);
119 printf("Failed to find mmc%u\n", devno);
125 // mmc_boot_part_access(mmc, 1, part_num, part_num);
127 block_dev_desc_t *mmc_dev;
129 ret = find_efi_partition("mmc", devno, part, &mmc_dev, &part_info);
131 printf("eMMC partition '%s' not found: %d\n", part, ret);
134 mmc_switch_part(devno, ret);
137 blk_cnt = DIV_ROUND_UP(len, part_info.blksz);
139 printf("Using mmc%d blksz %lu blks %lu\n", devno,
140 mmc_dev->blksz, mmc_dev->lba);
142 debug("Found partition '%s': offset=%08x size=%08lx\n",
143 part, blk_start, part_info.size);
144 if (part_info.size < blk_cnt) {
145 printf("Warning: partition '%s' smaller than requested size: %u; truncating data to %lu blocks\n",
146 part, len, part_info.size * mmc->read_bl_len);
147 blk_cnt = part_info.size;
150 debug("Reading %u blks from MMC partition '%s' offset %u to %p\n",
151 blk_cnt, part, blk_start, addr);
152 ret = mmc->block_dev.block_read(devno, blk_start, blk_cnt, addr);
154 printf("Failed to read MMC partition %s\n", part);
157 debug("Read %u byte from partition '%s' @ offset %08x\n",
158 ret * mmc->read_bl_len, part, blk_start);
162 // mmc_boot_part_access(mmc, 1, part_num, 0);
163 mmc_switch_part(devno, 0);