Commit b5b838f1a726e9ab7eea505740e8169b55e90ed6
Committed by
Jaehoon Chung
1 parent
ce9eca9438
Exists in
v2017.01-smarct4x
and in
25 other branches
mmc: Tinification of the mmc code
Add new configuration option CONFIG_MMC_TINY which strips away all memory allocation within the MMC code and code for handling multiple cards. This allows extremely space-constrained SPL code use the MMC framework. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Marek Vasut <marex@denx.de> Cc: Tom Rini <trini@konsulko.com> Cc: Jaehoon Chung <jh80.chung@samsung.com>
Showing 5 changed files with 83 additions and 2 deletions Side-by-side Diff
common/spl/spl_mmc.c
... | ... | @@ -306,7 +306,11 @@ |
306 | 306 | if (part == 7) |
307 | 307 | part = 0; |
308 | 308 | |
309 | - err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part); | |
309 | + if (CONFIG_IS_ENABLED(MMC_TINY)) | |
310 | + err = mmc_switch_part(mmc, part); | |
311 | + else | |
312 | + err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part); | |
313 | + | |
310 | 314 | if (err) { |
311 | 315 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
312 | 316 | puts("spl: mmc partition switch failed\n"); |
drivers/mmc/Kconfig
... | ... | @@ -26,6 +26,21 @@ |
26 | 26 | option will be removed as soon as all DM_MMC drivers use it, as it |
27 | 27 | will the only supported behaviour. |
28 | 28 | |
29 | +config SPL_MMC_TINY | |
30 | + bool "Tiny MMC framework in SPL" | |
31 | + help | |
32 | + Enable MMC framework tinification support. This option is useful if | |
33 | + if your SPL is extremely size constrained. Heed the warning, enable | |
34 | + this option if and only if you know exactly what you are doing, if | |
35 | + you are reading this help text, you most likely have no idea :-) | |
36 | + | |
37 | + The MMC framework is reduced to bare minimum to be useful. No malloc | |
38 | + support is needed for the MMC framework operation with this option | |
39 | + enabled. The framework supports exactly one MMC device and exactly | |
40 | + one MMC driver. The MMC driver can be adjusted to avoid any malloc | |
41 | + operations too, which can remove the need for malloc support in SPL | |
42 | + and thus further reduce footprint. | |
43 | + | |
29 | 44 | config MSM_SDHCI |
30 | 45 | bool "Qualcomm SDHCI controller" |
31 | 46 | depends on DM_MMC && BLK && DM_MMC_OPS |
drivers/mmc/mmc.c
... | ... | @@ -30,6 +30,29 @@ |
30 | 30 | SZ_16M / 512, (SZ_16M + SZ_8M) / 512, SZ_32M / 512, SZ_64M / 512, |
31 | 31 | }; |
32 | 32 | |
33 | +#if CONFIG_IS_ENABLED(MMC_TINY) | |
34 | +static struct mmc mmc_static; | |
35 | +struct mmc *find_mmc_device(int dev_num) | |
36 | +{ | |
37 | + return &mmc_static; | |
38 | +} | |
39 | + | |
40 | +void mmc_do_preinit(void) | |
41 | +{ | |
42 | + struct mmc *m = &mmc_static; | |
43 | +#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT | |
44 | + mmc_set_preinit(m, 1); | |
45 | +#endif | |
46 | + if (m->preinit) | |
47 | + mmc_start_init(m); | |
48 | +} | |
49 | + | |
50 | +struct blk_desc *mmc_get_blk_desc(struct mmc *mmc) | |
51 | +{ | |
52 | + return &mmc->block_dev; | |
53 | +} | |
54 | +#endif | |
55 | + | |
33 | 56 | #ifndef CONFIG_DM_MMC_OPS |
34 | 57 | __weak int board_mmc_getwp(struct mmc *mmc) |
35 | 58 | { |
... | ... | @@ -259,7 +282,11 @@ |
259 | 282 | if (!mmc) |
260 | 283 | return 0; |
261 | 284 | |
262 | - err = blk_dselect_hwpart(block_dev, block_dev->hwpart); | |
285 | + if (CONFIG_IS_ENABLED(MMC_TINY)) | |
286 | + err = mmc_switch_part(mmc, block_dev->hwpart); | |
287 | + else | |
288 | + err = blk_dselect_hwpart(block_dev, block_dev->hwpart); | |
289 | + | |
263 | 290 | if (err < 0) |
264 | 291 | return 0; |
265 | 292 | |
266 | 293 | |
... | ... | @@ -1804,7 +1831,9 @@ |
1804 | 1831 | initialized = 1; |
1805 | 1832 | |
1806 | 1833 | #ifndef CONFIG_BLK |
1834 | +#if !CONFIG_IS_ENABLED(MMC_TINY) | |
1807 | 1835 | mmc_list_init(); |
1836 | +#endif | |
1808 | 1837 | #endif |
1809 | 1838 | ret = mmc_probe(bis); |
1810 | 1839 | if (ret) |
drivers/mmc/mmc_legacy.c
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | static struct list_head mmc_devices; |
14 | 14 | static int cur_dev_num = -1; |
15 | 15 | |
16 | +#if !CONFIG_IS_ENABLED(MMC_TINY) | |
16 | 17 | struct mmc *find_mmc_device(int dev_num) |
17 | 18 | { |
18 | 19 | struct mmc *m; |
... | ... | @@ -62,6 +63,7 @@ |
62 | 63 | mmc_start_init(m); |
63 | 64 | } |
64 | 65 | } |
66 | +#endif | |
65 | 67 | |
66 | 68 | void mmc_list_init(void) |
67 | 69 | { |
68 | 70 | |
... | ... | @@ -109,8 +111,37 @@ |
109 | 111 | void print_mmc_devices(char separator) { } |
110 | 112 | #endif |
111 | 113 | |
114 | +#if CONFIG_IS_ENABLED(MMC_TINY) | |
115 | +static struct mmc mmc_static = { | |
116 | + .dsr_imp = 0, | |
117 | + .dsr = 0xffffffff, | |
118 | + .block_dev = { | |
119 | + .if_type = IF_TYPE_MMC, | |
120 | + .removable = 1, | |
121 | + .devnum = 0, | |
122 | + .block_read = mmc_bread, | |
123 | + .block_write = mmc_bwrite, | |
124 | + .block_erase = mmc_berase, | |
125 | + .part_type = 0, | |
126 | + }, | |
127 | +}; | |
128 | + | |
112 | 129 | struct mmc *mmc_create(const struct mmc_config *cfg, void *priv) |
113 | 130 | { |
131 | + struct mmc *mmc = &mmc_static; | |
132 | + | |
133 | + mmc->cfg = cfg; | |
134 | + mmc->priv = priv; | |
135 | + | |
136 | + return mmc; | |
137 | +} | |
138 | + | |
139 | +void mmc_destroy(struct mmc *mmc) | |
140 | +{ | |
141 | +} | |
142 | +#else | |
143 | +struct mmc *mmc_create(const struct mmc_config *cfg, void *priv) | |
144 | +{ | |
114 | 145 | struct blk_desc *bdesc; |
115 | 146 | struct mmc *mmc; |
116 | 147 | |
... | ... | @@ -157,6 +188,7 @@ |
157 | 188 | /* only freeing memory for now */ |
158 | 189 | free(mmc); |
159 | 190 | } |
191 | +#endif | |
160 | 192 | |
161 | 193 | static int mmc_select_hwpartp(struct blk_desc *desc, int hwpart) |
162 | 194 | { |
include/mmc.h
... | ... | @@ -515,6 +515,7 @@ |
515 | 515 | * @return 0 if there is no MMC device, else the number of devices |
516 | 516 | */ |
517 | 517 | int get_mmc_num(void); |
518 | +int mmc_switch_part(struct mmc *mmc, unsigned int part_num); | |
518 | 519 | int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf, |
519 | 520 | enum mmc_hwpart_conf_mode mode); |
520 | 521 |