blob: a19ec5a4e4095888ad8aaba63496d84328f18040 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Simple MTD partitioning layer
3 *
David Woodhousea1452a32010-08-08 20:58:20 +01004 * Copyright © 2000 Nicolas Pitre <nico@fluxnic.net>
5 * Copyright © 2002 Thomas Gleixner <gleixner@linutronix.de>
6 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
David Woodhousea1452a32010-08-08 20:58:20 +01008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
David Woodhousea1452a32010-08-08 20:58:20 +010013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
Thomas Gleixner97894cd2005-11-07 11:15:26 +000022 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/kmod.h>
30#include <linux/mtd/mtd.h>
31#include <linux/mtd/partitions.h>
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +030032#include <linux/err.h>
Dan Ehrenberg727dc612015-04-02 15:15:10 -070033#include <linux/kconfig.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Jamie Ileseea72d52011-05-23 10:23:42 +010035#include "mtdcore.h"
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/* Our partition linked list */
38static LIST_HEAD(mtd_partitions);
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +030039static DEFINE_MUTEX(mtd_partitions_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* Our partition node structure */
42struct mtd_part {
43 struct mtd_info mtd;
44 struct mtd_info *master;
Adrian Hunter69423d92008-12-10 13:37:21 +000045 uint64_t offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047};
48
49/*
50 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
51 * the pointer to that structure with this macro.
52 */
53#define PART(x) ((struct mtd_part *)(x))
54
Thomas Gleixner97894cd2005-11-07 11:15:26 +000055
56/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * MTD methods which simply translate the effective address and pass through
58 * to the _real_ device.
59 */
60
Atsushi Nemotob33a2882008-07-19 01:00:33 +090061static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
62 size_t *retlen, u_char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 struct mtd_part *part = PART(mtd);
Yauhen Kharuzhyd8877f12009-03-27 00:41:09 +020065 struct mtd_ecc_stats stats;
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +020066 int res;
67
Yauhen Kharuzhyd8877f12009-03-27 00:41:09 +020068 stats = part->master->ecc_stats;
Mike Dunn994c8402012-03-03 13:13:06 -080069 res = part->master->_read(part->master, from + part->offset, len,
70 retlen, buf);
Mike Dunnedbc45402012-04-25 12:06:11 -070071 if (unlikely(mtd_is_eccerr(res)))
72 mtd->ecc_stats.failed +=
73 part->master->ecc_stats.failed - stats.failed;
74 else
75 mtd->ecc_stats.corrected +=
76 part->master->ecc_stats.corrected - stats.corrected;
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +020077 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Atsushi Nemotob33a2882008-07-19 01:00:33 +090080static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
81 size_t *retlen, void **virt, resource_size_t *phys)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 struct mtd_part *part = PART(mtd);
Artem Bityutskiy5def4892012-02-03 16:23:52 +020084
Mike Dunn994c8402012-03-03 13:13:06 -080085 return part->master->_point(part->master, from + part->offset, len,
86 retlen, virt, phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
Thomas Gleixner9223a452006-05-23 17:21:03 +020088
Artem Bityutskiy5e4e6e32012-02-03 13:20:43 +020089static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 struct mtd_part *part = PART(mtd);
92
Mike Dunn994c8402012-03-03 13:13:06 -080093 return part->master->_unpoint(part->master, from + part->offset, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
David Howells402d3262009-02-12 10:40:00 +000096static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
97 unsigned long len,
98 unsigned long offset,
99 unsigned long flags)
100{
101 struct mtd_part *part = PART(mtd);
102
103 offset += part->offset;
Mike Dunn994c8402012-03-03 13:13:06 -0800104 return part->master->_get_unmapped_area(part->master, len, offset,
105 flags);
David Howells402d3262009-02-12 10:40:00 +0000106}
107
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200108static int part_read_oob(struct mtd_info *mtd, loff_t from,
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900109 struct mtd_oob_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 struct mtd_part *part = PART(mtd);
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200112 int res;
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (from >= mtd->size)
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200115 return -EINVAL;
Vitaly Wool70145682006-11-03 18:20:38 +0300116 if (ops->datbuf && from + ops->len > mtd->size)
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200117 return -EINVAL;
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200118
Artem Bityutskiy154bf892011-01-16 17:50:54 +0200119 /*
120 * If OOB is also requested, make sure that we do not read past the end
121 * of this partition.
122 */
123 if (ops->oobbuf) {
124 size_t len, pages;
125
Brian Norris0612b9d2011-08-30 18:45:40 -0700126 if (ops->mode == MTD_OPS_AUTO_OOB)
Artem Bityutskiy154bf892011-01-16 17:50:54 +0200127 len = mtd->oobavail;
128 else
129 len = mtd->oobsize;
130 pages = mtd_div_by_ws(mtd->size, mtd);
131 pages -= mtd_div_by_ws(from, mtd);
132 if (ops->ooboffs + ops->ooblen > pages * len)
133 return -EINVAL;
134 }
135
Mike Dunn994c8402012-03-03 13:13:06 -0800136 res = part->master->_read_oob(part->master, from + part->offset, ops);
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200137 if (unlikely(res)) {
Brian Norrisd57f40542011-09-20 18:34:25 -0700138 if (mtd_is_bitflip(res))
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200139 mtd->ecc_stats.corrected++;
Brian Norrisd57f40542011-09-20 18:34:25 -0700140 if (mtd_is_eccerr(res))
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200141 mtd->ecc_stats.failed++;
142 }
143 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900146static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
147 size_t len, size_t *retlen, u_char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800150 return part->master->_read_user_prot_reg(part->master, from, len,
151 retlen, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Christian Riesch4b78fc42014-01-28 09:29:44 +0100154static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
155 size_t *retlen, struct otp_info *buf)
Nicolas Pitref77814d2005-02-08 17:11:19 +0000156{
157 struct mtd_part *part = PART(mtd);
Christian Riesch4b78fc42014-01-28 09:29:44 +0100158 return part->master->_get_user_prot_info(part->master, len, retlen,
159 buf);
Nicolas Pitref77814d2005-02-08 17:11:19 +0000160}
161
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900162static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
163 size_t len, size_t *retlen, u_char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800166 return part->master->_read_fact_prot_reg(part->master, from, len,
167 retlen, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Christian Riesch4b78fc42014-01-28 09:29:44 +0100170static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
171 size_t *retlen, struct otp_info *buf)
Nicolas Pitref77814d2005-02-08 17:11:19 +0000172{
173 struct mtd_part *part = PART(mtd);
Christian Riesch4b78fc42014-01-28 09:29:44 +0100174 return part->master->_get_fact_prot_info(part->master, len, retlen,
175 buf);
Nicolas Pitref77814d2005-02-08 17:11:19 +0000176}
177
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900178static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
179 size_t *retlen, const u_char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800182 return part->master->_write(part->master, to + part->offset, len,
183 retlen, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900186static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
187 size_t *retlen, const u_char *buf)
Richard Purdie388bbb02008-02-06 10:17:15 +0000188{
189 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800190 return part->master->_panic_write(part->master, to + part->offset, len,
191 retlen, buf);
Richard Purdie388bbb02008-02-06 10:17:15 +0000192}
193
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200194static int part_write_oob(struct mtd_info *mtd, loff_t to,
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900195 struct mtd_oob_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
197 struct mtd_part *part = PART(mtd);
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (to >= mtd->size)
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200200 return -EINVAL;
Vitaly Wool70145682006-11-03 18:20:38 +0300201 if (ops->datbuf && to + ops->len > mtd->size)
Thomas Gleixner8593fbc2006-05-29 03:26:58 +0200202 return -EINVAL;
Mike Dunn994c8402012-03-03 13:13:06 -0800203 return part->master->_write_oob(part->master, to + part->offset, ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900206static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
207 size_t len, size_t *retlen, u_char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800210 return part->master->_write_user_prot_reg(part->master, from, len,
211 retlen, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900214static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
215 size_t len)
Nicolas Pitref77814d2005-02-08 17:11:19 +0000216{
217 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800218 return part->master->_lock_user_prot_reg(part->master, from, len);
Nicolas Pitref77814d2005-02-08 17:11:19 +0000219}
220
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900221static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
222 unsigned long count, loff_t to, size_t *retlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800225 return part->master->_writev(part->master, vecs, count,
226 to + part->offset, retlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900229static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 struct mtd_part *part = PART(mtd);
232 int ret;
Artem Bityutskiy664addc2012-02-03 18:13:23 +0200233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 instr->addr += part->offset;
Mike Dunn994c8402012-03-03 13:13:06 -0800235 ret = part->master->_erase(part->master, instr);
Adrian Hunter74641d72007-03-08 12:20:12 +0200236 if (ret) {
Adrian Hunterbb0eb212008-08-12 12:40:50 +0300237 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
Adrian Hunter74641d72007-03-08 12:20:12 +0200238 instr->fail_addr -= part->offset;
239 instr->addr -= part->offset;
240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return ret;
242}
243
244void mtd_erase_callback(struct erase_info *instr)
245{
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200246 if (instr->mtd->_erase == part_erase) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 struct mtd_part *part = PART(instr->mtd);
248
Adrian Hunterbb0eb212008-08-12 12:40:50 +0300249 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 instr->fail_addr -= part->offset;
251 instr->addr -= part->offset;
252 }
253 if (instr->callback)
254 instr->callback(instr);
255}
256EXPORT_SYMBOL_GPL(mtd_erase_callback);
257
Adrian Hunter69423d92008-12-10 13:37:21 +0000258static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800261 return part->master->_lock(part->master, ofs + part->offset, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Adrian Hunter69423d92008-12-10 13:37:21 +0000264static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800267 return part->master->_unlock(part->master, ofs + part->offset, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
Richard Cochran99384242010-06-14 18:10:33 +0200270static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
271{
272 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800273 return part->master->_is_locked(part->master, ofs + part->offset, len);
Richard Cochran99384242010-06-14 18:10:33 +0200274}
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276static void part_sync(struct mtd_info *mtd)
277{
278 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800279 part->master->_sync(part->master);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282static int part_suspend(struct mtd_info *mtd)
283{
284 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800285 return part->master->_suspend(part->master);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288static void part_resume(struct mtd_info *mtd)
289{
290 struct mtd_part *part = PART(mtd);
Mike Dunn994c8402012-03-03 13:13:06 -0800291 part->master->_resume(part->master);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Ezequiel Garcia8471bb72014-05-21 19:06:12 -0300294static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
295{
296 struct mtd_part *part = PART(mtd);
297 ofs += part->offset;
298 return part->master->_block_isreserved(part->master, ofs);
299}
300
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900301static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct mtd_part *part = PART(mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 ofs += part->offset;
Mike Dunn994c8402012-03-03 13:13:06 -0800305 return part->master->_block_isbad(part->master, ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900308static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 struct mtd_part *part = PART(mtd);
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200311 int res;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 ofs += part->offset;
Mike Dunn994c8402012-03-03 13:13:06 -0800314 res = part->master->_block_markbad(part->master, ofs);
Thomas Gleixnerf1a28c02006-05-30 00:37:34 +0200315 if (!res)
316 mtd->ecc_stats.badblocks++;
317 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300320static inline void free_partition(struct mtd_part *p)
321{
322 kfree(p->mtd.name);
323 kfree(p);
324}
325
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000326/*
327 * This function unregisters and destroy all slave MTD objects which are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * attached to the given master MTD object.
329 */
330
331int del_mtd_partitions(struct mtd_info *master)
332{
Chris Malley71a928c2008-05-19 20:11:50 +0100333 struct mtd_part *slave, *next;
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300334 int ret, err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300336 mutex_lock(&mtd_partitions_mutex);
Chris Malley71a928c2008-05-19 20:11:50 +0100337 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (slave->master == master) {
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300339 ret = del_mtd_device(&slave->mtd);
340 if (ret < 0) {
341 err = ret;
342 continue;
343 }
Chris Malley71a928c2008-05-19 20:11:50 +0100344 list_del(&slave->list);
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300345 free_partition(slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300347 mutex_unlock(&mtd_partitions_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300349 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300352static struct mtd_part *allocate_partition(struct mtd_info *master,
353 const struct mtd_partition *part, int partno,
354 uint64_t cur_offset)
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900355{
356 struct mtd_part *slave;
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300357 char *name;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900358
359 /* allocate the partition structure */
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900360 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300361 name = kstrdup(part->name, GFP_KERNEL);
362 if (!name || !slave) {
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900363 printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300364 master->name);
365 kfree(name);
366 kfree(slave);
367 return ERR_PTR(-ENOMEM);
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900368 }
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900369
370 /* set up the MTD object for this partition */
371 slave->mtd.type = master->type;
372 slave->mtd.flags = master->flags & ~part->mask_flags;
373 slave->mtd.size = part->size;
374 slave->mtd.writesize = master->writesize;
Anatolij Gustschin7fa33ac2010-12-16 23:42:18 +0100375 slave->mtd.writebufsize = master->writebufsize;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900376 slave->mtd.oobsize = master->oobsize;
377 slave->mtd.oobavail = master->oobavail;
378 slave->mtd.subpage_sft = master->subpage_sft;
379
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300380 slave->mtd.name = name;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900381 slave->mtd.owner = master->owner;
382
Dan Ehrenberg727dc612015-04-02 15:15:10 -0700383 /* NOTE: Historically, we didn't arrange MTDs as a tree out of
384 * concern for showing the same data in multiple partitions.
385 * However, it is very useful to have the master node present,
386 * so the MTD_PARTITIONED_MASTER option allows that. The master
387 * will have device nodes etc only if this is set, so make the
388 * parent conditional on that option. Note, this is a way to
389 * distinguish between the master and the partition in sysfs.
David Brownell1f24b5a2009-03-26 00:42:41 -0700390 */
Dan Ehrenberg727dc612015-04-02 15:15:10 -0700391 slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
392 &master->dev :
393 master->dev.parent;
David Brownell1f24b5a2009-03-26 00:42:41 -0700394
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200395 slave->mtd._read = part_read;
396 slave->mtd._write = part_write;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900397
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200398 if (master->_panic_write)
399 slave->mtd._panic_write = part_panic_write;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900400
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200401 if (master->_point && master->_unpoint) {
402 slave->mtd._point = part_point;
403 slave->mtd._unpoint = part_unpoint;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900404 }
405
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200406 if (master->_get_unmapped_area)
407 slave->mtd._get_unmapped_area = part_get_unmapped_area;
408 if (master->_read_oob)
409 slave->mtd._read_oob = part_read_oob;
410 if (master->_write_oob)
411 slave->mtd._write_oob = part_write_oob;
412 if (master->_read_user_prot_reg)
413 slave->mtd._read_user_prot_reg = part_read_user_prot_reg;
414 if (master->_read_fact_prot_reg)
415 slave->mtd._read_fact_prot_reg = part_read_fact_prot_reg;
416 if (master->_write_user_prot_reg)
417 slave->mtd._write_user_prot_reg = part_write_user_prot_reg;
418 if (master->_lock_user_prot_reg)
419 slave->mtd._lock_user_prot_reg = part_lock_user_prot_reg;
420 if (master->_get_user_prot_info)
421 slave->mtd._get_user_prot_info = part_get_user_prot_info;
422 if (master->_get_fact_prot_info)
423 slave->mtd._get_fact_prot_info = part_get_fact_prot_info;
424 if (master->_sync)
425 slave->mtd._sync = part_sync;
426 if (!partno && !master->dev.class && master->_suspend &&
427 master->_resume) {
428 slave->mtd._suspend = part_suspend;
429 slave->mtd._resume = part_resume;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900430 }
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200431 if (master->_writev)
432 slave->mtd._writev = part_writev;
433 if (master->_lock)
434 slave->mtd._lock = part_lock;
435 if (master->_unlock)
436 slave->mtd._unlock = part_unlock;
437 if (master->_is_locked)
438 slave->mtd._is_locked = part_is_locked;
Ezequiel Garcia8471bb72014-05-21 19:06:12 -0300439 if (master->_block_isreserved)
440 slave->mtd._block_isreserved = part_block_isreserved;
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200441 if (master->_block_isbad)
442 slave->mtd._block_isbad = part_block_isbad;
443 if (master->_block_markbad)
444 slave->mtd._block_markbad = part_block_markbad;
445 slave->mtd._erase = part_erase;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900446 slave->master = master;
447 slave->offset = part->offset;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900448
449 if (slave->offset == MTDPART_OFS_APPEND)
450 slave->offset = cur_offset;
451 if (slave->offset == MTDPART_OFS_NXTBLK) {
452 slave->offset = cur_offset;
Adrian Hunter69423d92008-12-10 13:37:21 +0000453 if (mtd_mod_by_eb(cur_offset, master) != 0) {
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900454 /* Round up to next erasesize */
Adrian Hunter69423d92008-12-10 13:37:21 +0000455 slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900456 printk(KERN_NOTICE "Moving partition %d: "
Adrian Hunter69423d92008-12-10 13:37:21 +0000457 "0x%012llx -> 0x%012llx\n", partno,
458 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900459 }
460 }
Dmitry Eremin-Solenikov1a313682011-06-06 18:04:14 +0400461 if (slave->offset == MTDPART_OFS_RETAIN) {
462 slave->offset = cur_offset;
463 if (master->size - slave->offset >= slave->mtd.size) {
464 slave->mtd.size = master->size - slave->offset
465 - slave->mtd.size;
466 } else {
467 printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
468 part->name, master->size - slave->offset,
469 slave->mtd.size);
470 /* register to preserve ordering */
471 goto out_register;
472 }
473 }
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900474 if (slave->mtd.size == MTDPART_SIZ_FULL)
475 slave->mtd.size = master->size - slave->offset;
476
Adrian Hunter69423d92008-12-10 13:37:21 +0000477 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset,
478 (unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name);
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900479
480 /* let's do some sanity checks */
481 if (slave->offset >= master->size) {
Atsushi Nemotof636ffb2008-07-19 01:01:22 +0900482 /* let's register it anyway to preserve ordering */
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900483 slave->offset = 0;
484 slave->mtd.size = 0;
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900485 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900486 part->name);
Atsushi Nemotof636ffb2008-07-19 01:01:22 +0900487 goto out_register;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900488 }
489 if (slave->offset + slave->mtd.size > master->size) {
490 slave->mtd.size = master->size - slave->offset;
Adrian Hunter69423d92008-12-10 13:37:21 +0000491 printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
492 part->name, master->name, (unsigned long long)slave->mtd.size);
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900493 }
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900494 if (master->numeraseregions > 1) {
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900495 /* Deal with variable erase size stuff */
Atsushi Nemoto6910c132008-07-19 01:00:57 +0900496 int i, max = master->numeraseregions;
Adrian Hunter69423d92008-12-10 13:37:21 +0000497 u64 end = slave->offset + slave->mtd.size;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900498 struct mtd_erase_region_info *regions = master->eraseregions;
499
Atsushi Nemoto6910c132008-07-19 01:00:57 +0900500 /* Find the first erase regions which is part of this
501 * partition. */
502 for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900503 ;
Atsushi Nemoto6910c132008-07-19 01:00:57 +0900504 /* The loop searched for the region _behind_ the first one */
Roel Kluina57ca042009-09-18 12:51:50 -0700505 if (i > 0)
506 i--;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900507
Atsushi Nemoto6910c132008-07-19 01:00:57 +0900508 /* Pick biggest erasesize */
509 for (; i < max && regions[i].offset < end; i++) {
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900510 if (slave->mtd.erasesize < regions[i].erasesize) {
511 slave->mtd.erasesize = regions[i].erasesize;
512 }
513 }
Atsushi Nemoto6910c132008-07-19 01:00:57 +0900514 BUG_ON(slave->mtd.erasesize == 0);
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900515 } else {
516 /* Single erase size */
517 slave->mtd.erasesize = master->erasesize;
518 }
519
520 if ((slave->mtd.flags & MTD_WRITEABLE) &&
Adrian Hunter69423d92008-12-10 13:37:21 +0000521 mtd_mod_by_eb(slave->offset, &slave->mtd)) {
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900522 /* Doesn't start on a boundary of major erase size */
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900523 /* FIXME: Let it be writable if it is on a boundary of
524 * _minor_ erase size though */
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900525 slave->mtd.flags &= ~MTD_WRITEABLE;
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900526 printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900527 part->name);
528 }
529 if ((slave->mtd.flags & MTD_WRITEABLE) &&
Adrian Hunter69423d92008-12-10 13:37:21 +0000530 mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) {
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900531 slave->mtd.flags &= ~MTD_WRITEABLE;
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900532 printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900533 part->name);
534 }
535
536 slave->mtd.ecclayout = master->ecclayout;
Huang Shijiebdf69c42013-08-16 10:10:06 +0800537 slave->mtd.ecc_step_size = master->ecc_step_size;
Mike Dunn6a918ba2012-03-11 14:21:11 -0700538 slave->mtd.ecc_strength = master->ecc_strength;
Mike Dunnd062d4e2012-04-25 12:06:08 -0700539 slave->mtd.bitflip_threshold = master->bitflip_threshold;
540
Artem Bityutskiy3c3c10b2012-01-30 14:58:32 +0200541 if (master->_block_isbad) {
Adrian Hunter69423d92008-12-10 13:37:21 +0000542 uint64_t offs = 0;
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900543
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900544 while (offs < slave->mtd.size) {
Ezequiel Garciafdf43a42014-03-21 08:57:44 -0300545 if (mtd_block_isreserved(master, offs + slave->offset))
546 slave->mtd.ecc_stats.bbtblocks++;
547 else if (mtd_block_isbad(master, offs + slave->offset))
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900548 slave->mtd.ecc_stats.badblocks++;
549 offs += slave->mtd.erasesize;
550 }
551 }
552
Atsushi Nemotof636ffb2008-07-19 01:01:22 +0900553out_register:
Atsushi Nemoto7788ba72008-07-19 01:00:18 +0900554 return slave;
555}
556
Geert Uytterhoeven26a6d242013-11-12 20:11:26 +0100557int mtd_add_partition(struct mtd_info *master, const char *name,
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300558 long long offset, long long length)
559{
560 struct mtd_partition part;
561 struct mtd_part *p, *new;
562 uint64_t start, end;
563 int ret = 0;
564
565 /* the direct offset is expected */
566 if (offset == MTDPART_OFS_APPEND ||
567 offset == MTDPART_OFS_NXTBLK)
568 return -EINVAL;
569
570 if (length == MTDPART_SIZ_FULL)
571 length = master->size - offset;
572
573 if (length <= 0)
574 return -EINVAL;
575
576 part.name = name;
577 part.size = length;
578 part.offset = offset;
579 part.mask_flags = 0;
580 part.ecclayout = NULL;
581
582 new = allocate_partition(master, &part, -1, offset);
583 if (IS_ERR(new))
584 return PTR_ERR(new);
585
586 start = offset;
587 end = offset + length;
588
589 mutex_lock(&mtd_partitions_mutex);
590 list_for_each_entry(p, &mtd_partitions, list)
591 if (p->master == master) {
592 if ((start >= p->offset) &&
593 (start < (p->offset + p->mtd.size)))
594 goto err_inv;
595
596 if ((end >= p->offset) &&
597 (end < (p->offset + p->mtd.size)))
598 goto err_inv;
599 }
600
601 list_add(&new->list, &mtd_partitions);
602 mutex_unlock(&mtd_partitions_mutex);
603
604 add_mtd_device(&new->mtd);
605
606 return ret;
607err_inv:
608 mutex_unlock(&mtd_partitions_mutex);
609 free_partition(new);
610 return -EINVAL;
611}
612EXPORT_SYMBOL_GPL(mtd_add_partition);
613
614int mtd_del_partition(struct mtd_info *master, int partno)
615{
616 struct mtd_part *slave, *next;
617 int ret = -EINVAL;
618
619 mutex_lock(&mtd_partitions_mutex);
620 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
621 if ((slave->master == master) &&
622 (slave->mtd.index == partno)) {
623 ret = del_mtd_device(&slave->mtd);
624 if (ret < 0)
625 break;
626
627 list_del(&slave->list);
628 free_partition(slave);
629 break;
630 }
631 mutex_unlock(&mtd_partitions_mutex);
632
633 return ret;
634}
635EXPORT_SYMBOL_GPL(mtd_del_partition);
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637/*
638 * This function, given a master MTD object and a partition table, creates
639 * and registers slave MTD objects which are bound to the master according to
640 * the partition definitions.
David Brownell1f24b5a2009-03-26 00:42:41 -0700641 *
Dan Ehrenberg727dc612015-04-02 15:15:10 -0700642 * For historical reasons, this function's caller only registers the master
643 * if the MTD_PARTITIONED_MASTER config option is set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 */
645
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000646int add_mtd_partitions(struct mtd_info *master,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 const struct mtd_partition *parts,
648 int nbparts)
649{
650 struct mtd_part *slave;
Adrian Hunter69423d92008-12-10 13:37:21 +0000651 uint64_t cur_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 int i;
653
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900654 printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 for (i = 0; i < nbparts; i++) {
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300657 slave = allocate_partition(master, parts + i, i, cur_offset);
658 if (IS_ERR(slave))
659 return PTR_ERR(slave);
660
661 mutex_lock(&mtd_partitions_mutex);
662 list_add(&slave->list, &mtd_partitions);
663 mutex_unlock(&mtd_partitions_mutex);
664
665 add_mtd_device(&slave->mtd);
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 cur_offset = slave->offset + slave->mtd.size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 }
669
670 return 0;
671}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673static DEFINE_SPINLOCK(part_parser_lock);
674static LIST_HEAD(part_parsers);
675
676static struct mtd_part_parser *get_partition_parser(const char *name)
677{
Chris Malley71a928c2008-05-19 20:11:50 +0100678 struct mtd_part_parser *p, *ret = NULL;
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 spin_lock(&part_parser_lock);
681
Chris Malley71a928c2008-05-19 20:11:50 +0100682 list_for_each_entry(p, &part_parsers, list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 if (!strcmp(p->name, name) && try_module_get(p->owner)) {
684 ret = p;
685 break;
686 }
Chris Malley71a928c2008-05-19 20:11:50 +0100687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 spin_unlock(&part_parser_lock);
689
690 return ret;
691}
692
Dmitry Eremin-Solenikov953b3bd2011-06-23 15:26:14 +0400693#define put_partition_parser(p) do { module_put((p)->owner); } while (0)
694
Axel Lin6e14a612013-12-01 19:01:06 +0800695void register_mtd_parser(struct mtd_part_parser *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 spin_lock(&part_parser_lock);
698 list_add(&p->list, &part_parsers);
699 spin_unlock(&part_parser_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900701EXPORT_SYMBOL_GPL(register_mtd_parser);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Axel Lincf3b2b12013-12-01 18:59:15 +0800703void deregister_mtd_parser(struct mtd_part_parser *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
705 spin_lock(&part_parser_lock);
706 list_del(&p->list);
707 spin_unlock(&part_parser_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
Atsushi Nemotob33a2882008-07-19 01:00:33 +0900709EXPORT_SYMBOL_GPL(deregister_mtd_parser);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Artem Bityutskiyad274ce2011-06-08 11:42:27 +0300711/*
712 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
713 * are changing this array!
714 */
Artem Bityutskiyccef4dc2013-03-12 10:51:35 +0200715static const char * const default_mtd_part_types[] = {
Dmitry Eremin-Solenikovd26c87d2011-05-29 21:32:33 +0400716 "cmdlinepart",
717 "ofpart",
718 NULL
719};
Dmitry Eremin-Solenikov5c4eefb2011-06-02 18:51:16 +0400720
Artem Bityutskiyad274ce2011-06-08 11:42:27 +0300721/**
722 * parse_mtd_partitions - parse MTD partitions
723 * @master: the master partition (describes whole MTD device)
724 * @types: names of partition parsers to try or %NULL
725 * @pparts: array of partitions found is returned here
Dmitry Eremin-Solenikovc7975332011-06-10 18:18:28 +0400726 * @data: MTD partition parser-specific data
Artem Bityutskiyad274ce2011-06-08 11:42:27 +0300727 *
728 * This function tries to find partition on MTD device @master. It uses MTD
729 * partition parsers, specified in @types. However, if @types is %NULL, then
730 * the default list of parsers is used. The default list contains only the
Dmitry Eremin-Solenikovd26c87d2011-05-29 21:32:33 +0400731 * "cmdlinepart" and "ofpart" parsers ATM.
Huang Shijiec51803d2012-08-18 13:07:41 -0400732 * Note: If there are more then one parser in @types, the kernel only takes the
733 * partitions parsed out by the first parser.
Artem Bityutskiyad274ce2011-06-08 11:42:27 +0300734 *
735 * This function may return:
736 * o a negative error code in case of failure
737 * o zero if no partitions were found
738 * o a positive number of found partitions, in which case on exit @pparts will
739 * point to an array containing this number of &struct mtd_info objects.
740 */
Artem Bityutskiy26a47342013-03-11 15:38:48 +0200741int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
Dmitry Eremin-Solenikovc7975332011-06-10 18:18:28 +0400742 struct mtd_partition **pparts,
743 struct mtd_part_parser_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
745 struct mtd_part_parser *parser;
746 int ret = 0;
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000747
Dmitry Eremin-Solenikov5c4eefb2011-06-02 18:51:16 +0400748 if (!types)
749 types = default_mtd_part_types;
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 for ( ; ret <= 0 && *types; types++) {
752 parser = get_partition_parser(*types);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (!parser && !request_module("%s", *types))
Stefan Roese58edc902012-01-25 11:24:36 +0100754 parser = get_partition_parser(*types);
Artem Bityutskiy7c802fb2011-05-17 11:13:17 +0300755 if (!parser)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 continue;
Dmitry Eremin-Solenikovc7975332011-06-10 18:18:28 +0400757 ret = (*parser->parse_fn)(master, pparts, data);
Huang Shijiec51803d2012-08-18 13:07:41 -0400758 put_partition_parser(parser);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (ret > 0) {
Thomas Gleixner97894cd2005-11-07 11:15:26 +0000760 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 ret, parser->name, master->name);
Huang Shijiec51803d2012-08-18 13:07:41 -0400762 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 return ret;
766}
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300767
Richard Genoud5dee4672012-07-10 18:23:39 +0200768int mtd_is_partition(const struct mtd_info *mtd)
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300769{
770 struct mtd_part *part;
Roman Tereshonkova7e93dc2010-11-23 14:17:17 +0200771 int ispart = 0;
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300772
773 mutex_lock(&mtd_partitions_mutex);
774 list_for_each_entry(part, &mtd_partitions, list)
775 if (&part->mtd == mtd) {
Roman Tereshonkova7e93dc2010-11-23 14:17:17 +0200776 ispart = 1;
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300777 break;
778 }
779 mutex_unlock(&mtd_partitions_mutex);
780
Roman Tereshonkova7e93dc2010-11-23 14:17:17 +0200781 return ispart;
Roman Tereshonkov5daa7b22010-09-17 13:31:41 +0300782}
Roman Tereshonkova7e93dc2010-11-23 14:17:17 +0200783EXPORT_SYMBOL_GPL(mtd_is_partition);
Richard Genoud62082e52012-07-10 18:23:40 +0200784
785/* Returns the size of the entire flash chip */
786uint64_t mtd_get_device_size(const struct mtd_info *mtd)
787{
788 if (!mtd_is_partition(mtd))
789 return mtd->size;
790
791 return PART(mtd)->master->size;
792}
793EXPORT_SYMBOL_GPL(mtd_get_device_size);