From: Bean Huo <jackyard88@gmail.com>
To: richard@nod.at, dedekind1@gmail.com, adrian.hunter@intel.com,
computersforpeace@gmail.com, boris.brezillon@free-electrons.com
Cc: beanhuo@micron.com, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org, zszubbocsev@micron.com,
peterpandong@micron.com
Subject: [PATCH v2 14/17] drivers:mtd:ubi:add backup operation in ubi_io_write
Date: Tue, 2 Feb 2016 02:30:49 +0000 [thread overview]
Message-ID: <1454380252-16170-15-git-send-email-jackyard88@gmail.com> (raw)
In-Reply-To: <1454380252-16170-1-git-send-email-jackyard88@gmail.com>
From: Bean Huo <beanhuo@micron.com>
This patch is to add backup lower page data codes in ubi_io_write.
If programming lower page, bakvol module will duplicate this lower page
data, then program to two different plane pages by multiple plane page program.
Signed-off-by: BeanHuo <beanhuo@micron.com>
---
drivers/mtd/ubi/io.c | 73 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 61 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 5bbd1f0..6905929 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -222,6 +222,7 @@ retry:
* @pnum: physical eraseblock number to write to
* @offset: offset within the physical eraseblock where to write
* @len: how many bytes to write
+ * @safeguard: if these data has to be duplicated to backup
*
* This function writes @len bytes of data from buffer @buf to offset @offset
* of physical eraseblock @pnum. If all the data were successfully written,
@@ -233,11 +234,12 @@ retry:
* to the flash media, but may be some garbage.
*/
int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
- int len)
+ int len, int safeguard)
{
int err;
- size_t written;
+ size_t retlen;
loff_t addr;
+ int skip;
dbg_io("write %d bytes to PEB %d:%d", len, pnum, offset);
@@ -281,14 +283,61 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
}
addr = (loff_t)pnum * ubi->peb_size + offset;
- err = mtd_write(ubi->mtd, addr, len, &written, buf);
- if (err) {
- ubi_err(ubi, "error %d while writing %d bytes to PEB %d:%d, written %zd bytes",
- err, len, pnum, offset, written);
- dump_stack();
- ubi_dump_flash(ubi, pnum, offset, len);
+#ifdef CONFIG_MTD_UBI_MLC_NAND_BAKVOL
+ skip = 0;
+ if (((offset == 0) && (len == ubi->peb_size)) ||
+ !safeguard)
+ skip = 1;
+
+ if (ubi_check_bakvol_module(ubi) && (!skip)) {
+ loff_t addr_temp;
+ unsigned char *buf_temp = (unsigned char *)buf;
+ int len_temp;
+ int writelen = 0;
+
+ addr_temp = addr;
+
+ for (len_temp = len; len_temp > 0; len_temp -= ubi->min_io_size,
+ addr_temp += ubi->min_io_size,
+ buf_temp += ubi->min_io_size) {
+ /* Split data according to min_io_size */
+
+ if (len_temp/ubi->min_io_size)
+ writelen = ubi->min_io_size;
+ else
+ writelen %= ubi->min_io_size;
+
+ if (is_backup_need(ubi, addr_temp)) {
+ err = ubi_duplicate_data_to_bakvol(ubi,
+ addr_temp, writelen, &retlen, buf_temp);
+ } else
+ err = mtd_write(ubi->mtd, addr_temp, writelen,
+ &retlen, buf_temp);
+
+ if (err) {
+ ubi_err(ubi, "Writing %d byptes to PEB %d:%d",
+ writelen, pnum, offset);
+ ubi_err(ubi, "Error %d", err);
+ ubi_err(ubi, "Written %d bytes", retlen);
+ dump_stack();
+ ubi_dump_flash(ubi, pnum, offset, writelen);
+ } else
+ ubi_assert(retlen == writelen);
+ }
} else
- ubi_assert(written == len);
+#endif
+ {
+ err = mtd_write(ubi->mtd, addr, len, &retlen, buf);
+ if (err) {
+ ubi_err(ubi, "Writing %d byptes to PEB %d:%d",
+ len, pnum, offset);
+ ubi_err(ubi, "Error %d", err);
+ ubi_err(ubi, "Written %zd bytes", retlen);
+ dump_stack();
+ ubi_dump_flash(ubi, pnum, offset, len);
+ } else
+ ubi_assert(retlen == len);
+ }
if (!err) {
err = self_check_write(ubi, buf, pnum, offset, len);
@@ -438,7 +487,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
/* Write a pattern and check it */
memset(ubi->peb_buf, patterns[i], ubi->peb_size);
- err = ubi_io_write(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size);
+ err = ubi_io_write(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size, 0);
if (err)
goto out;
@@ -862,7 +911,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
if (ubi_dbg_power_cut(ubi, POWER_CUT_EC_WRITE))
return -EROFS;
- err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
+ err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize, 0);
return err;
}
@@ -1114,7 +1163,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
p = (char *)vid_hdr - ubi->vid_hdr_shift;
err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
- ubi->vid_hdr_alsize);
+ ubi->vid_hdr_alsize, 0);
return err;
}
--
1.9.1
next prev parent reply other threads:[~2016-02-02 2:33 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-02 2:30 [PATCH v2 00/17] Add a bakvol module in UBI layer for MLC paired page power loss issue Bean Huo
2016-02-02 2:30 ` [PATCH v2 01/17] include:mtd:add multi-plane page program command Bean Huo
2016-02-02 2:30 ` [PATCH v2 02/17] include:mtd:add multi-plane program in mtd_info Bean Huo
2016-02-02 2:30 ` [PATCH v2 03/17] drivers:mtd:add dual plane page program support in partition layer Bean Huo
2016-02-02 3:00 ` kbuild test robot
2016-02-02 2:30 ` [PATCH v2 04/17] drivers:mtd:nand:enable dual plane page program function Bean Huo
2016-02-02 3:04 ` kbuild test robot
2016-02-02 2:30 ` [PATCH v2 05/17] drivers:mtd:ubi:add bakvol on-flash and RAM data structures Bean Huo
2016-02-02 2:30 ` [PATCH v2 06/17] drivers:mtd:ubi:add bakvol function define in ubi layer Bean Huo
2016-02-02 3:05 ` kbuild test robot
2016-02-02 3:08 ` kbuild test robot
2016-02-02 2:30 ` [PATCH v2 07/17] fs:ubifs:add bakvol function define in ubifs layer Bean Huo
2016-02-02 2:30 ` [PATCH v2 08/17] drivers:mtd:ubi:disable bakvol function while writing volume table Bean Huo
2016-02-02 2:30 ` [PATCH v2 09/17] drivers:mtd:ubi:get PEB according to specfied plane number Bean Huo
2016-02-02 2:30 ` [PATCH v2 10/17] drivers:mtd:ubi:enable bakvol function for fastmap operation Bean Huo
2016-02-02 2:30 ` [PATCH v2 11/17] drivers:mtd:ubi:add disable/enable bakvol while ubi write Bean Huo
2016-02-02 2:30 ` [PATCH v2 12/17] drivers:mtd:ubi:add disable bakvol while ubi detach Bean Huo
2016-02-02 2:30 ` [PATCH v2 13/17] drivers:mtd:ubi:add bakvol init while attach ubi Bean Huo
2016-02-02 2:30 ` Bean Huo [this message]
2016-02-02 3:22 ` [PATCH v2 14/17] drivers:mtd:ubi:add backup operation in ubi_io_write kbuild test robot
2016-02-02 2:30 ` [PATCH v2 15/17] fs:ubifs:enable bakvol module and recover operation Bean Huo
2016-02-02 2:30 ` Bean Huo
2016-02-02 2:30 ` [PATCH v2 16/17] driver:mtd:ubi:add new bakvol module in ubi layer Bean Huo
2016-02-02 2:30 ` [PATCH v2 17/17] drivers:mtd:ubi: Kconfig Makefile Bean Huo
2016-02-02 3:22 ` kbuild test robot
2016-02-02 3:56 ` kbuild test robot
2016-02-02 3:58 ` kbuild test robot
2016-02-02 4:15 ` Bean Huo 霍斌斌 (beanhuo)
2016-02-03 0:46 ` Brian Norris
2016-02-03 6:14 ` Bean Huo 霍斌斌 (beanhuo)
2016-02-02 23:06 ` [PATCH v2 00/17] Add a bakvol module in UBI layer for MLC paired page power loss issue Richard Weinberger
2016-02-03 6:11 ` Bean Huo 霍斌斌 (beanhuo)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454380252-16170-15-git-send-email-jackyard88@gmail.com \
--to=jackyard88@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=beanhuo@micron.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=dedekind1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=peterpandong@micron.com \
--cc=richard@nod.at \
--cc=zszubbocsev@micron.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.