]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/common/mmc.c
karo: common: mmc: remove debug code
[karo-tx-uboot.git] / board / karo / common / mmc.c
1 /*
2  * (C) Copyright 2014 Lothar Waßmann <LW@KARO-electronics.de>
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
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.
10  *
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.
15  *
16  */
17
18 #include <common.h>
19 #include <errno.h>
20 #include <libfdt.h>
21 #include <fdt_support.h>
22 #include <mmc.h>
23 #include <mxcfb.h>
24 #include <linux/list.h>
25 #include <linux/fb.h>
26 #include <jffs2/load_kernel.h>
27 #include <malloc.h>
28
29 #include "karo.h"
30
31 #define CONFIG_MMC_BOOT_DEV 0
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 #define MAX_SEARCH_PARTITIONS 16
36
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)
40 {
41         int ret = -1;
42         char *dup_str = NULL;
43         int p;
44         int part;
45         block_dev_desc_t *dd;
46
47         dd = get_dev(ifname, devno);
48         if (!dd || dd->type == DEV_TYPE_UNKNOWN) {
49                 printf("** Bad device %s %d **\n", ifname, devno);
50                 return -1;
51         }
52         init_part(dd);
53
54         /*
55          * No partition table on device,
56          * or user requested partition 0 (entire device).
57          */
58         if (dd->part_type == PART_TYPE_UNKNOWN) {
59                 printf("** No partition table - %s %d **\n", ifname,
60                         devno);
61                 goto cleanup;
62         }
63
64         part = 0;
65         for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
66                 ret = get_partition_info(dd, p, info);
67                 if (ret)
68                         continue;
69
70                 if (strcmp((char *)info->name, part_str) == 0) {
71                         part = p;
72                         dd->log2blksz = LOG2(dd->blksz);
73                         break;
74                 }
75         }
76         if (!part) {
77                 printf("** No valid partitions found **\n");
78                 ret = -1;
79                 goto cleanup;
80         }
81
82         ret = part;
83         *dev_desc = dd;
84
85 cleanup:
86         free(dup_str);
87         return ret;
88 }
89
90 int karo_load_mmc_part(const char *part, void *addr, size_t len)
91 {
92         int ret;
93         struct mmc *mmc;
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;
98
99         mmc = find_mmc_device(devno);
100         if (!mmc) {
101                 printf("Failed to find mmc%u\n", devno);
102                 return -ENODEV;
103         }
104
105         mmc_init(mmc);
106
107         ret = find_efi_partition("mmc", devno, part, &mmc_dev, &part_info);
108         if (ret < 0) {
109                 printf("eMMC partition '%s' not found: %d\n", part, ret);
110                 goto out;
111         }
112         mmc_switch_part(devno, ret);
113
114         blk_start = 0;
115         blk_cnt = DIV_ROUND_UP(len, part_info.blksz);
116
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;
121
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);
125         if (ret == 0) {
126                 printf("Failed to read MMC partition %s\n", part);
127                 ret = -EIO;
128                 goto out;
129         }
130         debug("Read %u byte from partition '%s' @ offset %08x\n",
131                 ret * mmc->read_bl_len, part, blk_start);
132 out:
133         mmc_switch_part(devno, 0);
134         return ret < 0 ? ret : 0;
135 }