From patchwork Wed Jun 13 21:23:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929093 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uZ9rP8wQ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fth2bcYz9s2g for ; Thu, 14 Jun 2018 07:25:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AN2DAWMGAn6AYjGaU6R6OZLH27ezaWohdwqUnEWr6GQ=; b=uZ9rP8wQvxNhA/ulgNTz9vKUyb +sznH9nq3L8otgZRM5OTIH3qEBhkw60U/2SSy9DUckeHQnWlvLKweoYnRvt7oSfvJUXqWTh9CwAkE xAEbCfSua+pV63LP/BYbUGXmGqW+5xFGhtN09CWtEeY9mUfg9CU6WQonUFqXLjSg3NDKW/zno8/aB 5/gGQF5TyOreDAy8Vr5fqT50k7RvyQ6C+KWholDxWErQEfgX02yEEu8uO6Pjoan9ezyk5h6xg2fSD bcxIFZ8rmX16D+1HsbQq6TkfyasZJ07otybHKckUOizAXJREiGc5dzytA2htrMlAHJWRSz5OsbkTZ rwM1K1+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDGq-0006vF-V5; Wed, 13 Jun 2018 21:25:37 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFV-0004qK-Ha for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:17 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id A4792181B5049; Wed, 13 Jun 2018 23:24:00 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 01/14] ubi: fastmap: Read PEB numbers more carefully Date: Wed, 13 Jun 2018 23:23:31 +0200 Message-Id: <20180613212344.11608-2-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142413_937374_30B96F5D X-CRM114-Status: GOOD ( 14.72 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org PEB numbers can be used as indices, make sure that they are within bounds. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 71 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 462526a10537..768fa8a76867 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -101,6 +101,29 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi) return roundup(size, ubi->leb_size); } +static bool read_pnum(struct ubi_device *ubi, struct ubi_attach_info *ai, + __be32 pnum, int *out_pnum) +{ + int ret = true; + int max_pnum = ubi->peb_count; + + pnum = be32_to_cpu(pnum); + if (pnum == UBI_UNKNOWN) { + *out_pnum = pnum; + goto out; + } + + if (pnum < 0 || pnum >= max_pnum) { + ubi_err(ubi, "fastmap references PEB out of range: %i", pnum); + ret = false; + goto out; + } else { + *out_pnum = pnum; + } + +out: + return ret; +} /** * new_fm_vhdr - allocate a new volume header for fastmap usage. @@ -438,7 +461,10 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai, int scrub = 0; int image_seq; - pnum = be32_to_cpu(pebs[i]); + if (!read_pnum(ubi, ai, pebs[i], &pnum)) { + ret = UBI_BAD_FASTMAP; + goto out; + } if (ubi_io_is_bad(ubi, pnum)) { ubi_err(ubi, "bad PEB in fastmap pool!"); @@ -565,7 +591,7 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, struct ubi_fm_ec *fmec; struct ubi_fm_volhdr *fmvhdr; struct ubi_fm_eba *fm_eba; - int ret, i, j, pool_size, wl_pool_size; + int ret, i, j, pool_size, wl_pool_size, pnum; size_t fm_pos = 0, fm_size = ubi->fm_size; unsigned long long max_sqnum = 0; void *fm_raw = ubi->fm_buf; @@ -647,8 +673,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 0); + if (!read_pnum(ubi, ai, fmec->pnum, &pnum)) + goto fail_bad; + + add_aeb(ai, &ai->free, pnum, be32_to_cpu(fmec->ec), 0); } /* read EC values from used list */ @@ -658,8 +686,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 0); + if (!read_pnum(ubi, ai, fmec->pnum, &pnum)) + goto fail_bad; + + add_aeb(ai, &used, pnum, be32_to_cpu(fmec->ec), 0); } /* read EC values from scrub list */ @@ -669,8 +699,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 1); + if (!read_pnum(ubi, ai, fmec->pnum, &pnum)) + goto fail_bad; + + add_aeb(ai, &used, pnum, be32_to_cpu(fmec->ec), 1); } /* read EC values from erase list */ @@ -680,8 +712,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 1); + if (!read_pnum(ubi, ai, fmec->pnum, &pnum)) + goto fail_bad; + + add_aeb(ai, &ai->erase, pnum, be32_to_cpu(fmec->ec), 1); } ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); @@ -731,7 +765,8 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, } for (j = 0; j < be32_to_cpu(fm_eba->reserved_pebs); j++) { - int pnum = be32_to_cpu(fm_eba->pnum[j]); + if (!read_pnum(ubi, ai, fm_eba->pnum[j], &pnum)) + goto fail_bad; if (pnum < 0) continue; @@ -954,7 +989,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, for (i = 0; i < used_blocks; i++) { int image_seq; - pnum = be32_to_cpu(fmsb->block_loc[i]); + if (!read_pnum(ubi, ai, fmsb->block_loc[i], &pnum)) { + ret = UBI_BAD_FASTMAP; + goto free_hdr; + } if (ubi_io_is_bad(ubi, pnum)) { ret = UBI_BAD_FASTMAP; @@ -1068,7 +1106,14 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, goto free_hdr; } - e->pnum = be32_to_cpu(fmsb2->block_loc[i]); + if (!read_pnum(ubi, ai, fmsb2->block_loc[i], &e->pnum)) { + while (i--) + kmem_cache_free(ubi_wl_entry_slab, fm->e[i]); + + ret = -ENOMEM; + goto free_hdr; + } + e->ec = be32_to_cpu(fmsb2->block_ec[i]); fm->e[i] = e; } From patchwork Wed Jun 13 21:23:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929091 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IyjjK0b6"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fsd0cs3z9s01 for ; Thu, 14 Jun 2018 07:24:53 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xDqnpZMKbWQXcVnVgia7n6aI+6nJDYx7ij6kLGfM0bc=; b=IyjjK0b6aGgsISmAP/oVcjlfau 7ZQFg9i/QA+nywXysv8Jd19PMgCl529gHsM/dP+NmarcBu+AfDlTufcJJmoFVi17PPsVJm9ejgVMA Nunqy3rkw76Q7cYrPusIhdIl4gaBAPknsRR24e587emMfr4CuXIaRnRD0SCInn1knHCUwjB/dOiQP t0z9xa0xT1zBoDx2uhxDfDcqiBeeaTvbtUH2Kizx87Ko55SIru96M2ulBMkIcfIKjE9BL3pZ/7cam uVpffbIN2aIGfle/b7ZSbMjUY6yzQlOXx24kbgw2a6RvTMdfuFjwW9ZmRyg/E+aynMZBL9QNG89rJ uaZGLfyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFu-00059G-Tr; Wed, 13 Jun 2018 21:24:38 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFV-0004qL-HY for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:15 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id ED503181B504D; Wed, 13 Jun 2018 23:24:00 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 02/14] ubi: Fix assert in ubi_wl_init Date: Wed, 13 Jun 2018 23:23:32 +0200 Message-Id: <20180613212344.11608-3-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142413_770788_D0B4FA5A X-CRM114-Status: GOOD ( 15.78 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When multiple PEBs are used for a fastmap, found_pebs can be wrong and the assert triggers. The current approach is broken in two ways: 1. The "continue" in list_for_each_entry() over all fastmap PEBs misses the counter at all. 2. When the fastmap changes in size, growing due to a preseeded fastmap or shrinking due to new bad blocks, iterating over the current fastmap will give wrong numbers. We have to exclude the fastmap size at all from the calculation to be able to compare the numbers. At this stage we simply have no longer the information whether the fastmap changed in size. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/wl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index f66b3b22f328..6bbb968fe9da 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1695,11 +1695,19 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) err = erase_aeb(ubi, aeb, sync); if (err) goto out_free; - } - found_pebs++; + /* + * If no fastmap is used, all fastmap PEBs will get be + * erased and are member of ai->fastmap. + */ + if (!ubi->fm) + found_pebs++; + } } + if (ubi->fm) + found_pebs += ubi->fm->used_blocks; + dbg_wl("found %i PEBs", found_pebs); ubi_assert(ubi->good_peb_count == found_pebs); From patchwork Wed Jun 13 21:23:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929094 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LS2y7bqV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fvJ6Z7jz9s01 for ; Thu, 14 Jun 2018 07:26:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BFqvN2sP5KqHQiVGrNwFsrVUXXxEU9ONwAjTNz5Tfng=; b=LS2y7bqV7EiptKHWSKeE6x6Pfa oHR8z7TPKJ9ONThzFxcEGwlyjLysBT0NPgnwGuKHHBx6RDn6hw3JeVEvP0e9dY6NqY5tRSVYygAmt FI5bvSETxNexm+g6nCL7w0O+F8PLJ3VFTKeD8yYunyDPiH6nCyU4Si4ZAGOr9Lf1YyMm8Ldwi8aJ5 skb/MevIQR7JZDOhdBdP9N1P3ptECOUCXMMRrfUTig5tFuI5kY5HXA6uPhieJLRxG4I/3/2rU59S3 d/khyCRx+aKa4uVH09HUdTDuCp/u+qzapeFJGWdCBx3k40GqMB1zsZD97uXEFjr6fdKKsKfy63SQu m3xNaPHQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDHN-0007Hw-B7; Wed, 13 Jun 2018 21:26:09 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFV-0004qS-HU for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:25 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 381AA181B504C; Wed, 13 Jun 2018 23:24:02 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 03/14] ubi: fastmap: Add support for flags Date: Wed, 13 Jun 2018 23:23:33 +0200 Message-Id: <20180613212344.11608-4-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142413_935782_7302B630 X-CRM114-Status: GOOD ( 17.79 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org With version 2 of fastmap, flags are supported. We fall back to scanning mode if unsupported flags are found. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 24 ++++++++++++++++++++---- drivers/mtd/ubi/ubi-media.h | 11 +++++++++-- drivers/mtd/ubi/ubi.h | 2 ++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 768fa8a76867..1ebb5d15ab1a 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -949,9 +949,24 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, goto free_fm_sb; } - if (fmsb->version != UBI_FM_FMT_VERSION) { - ubi_err(ubi, "bad fastmap version: %i, expected: %i", - fmsb->version, UBI_FM_FMT_VERSION); + fm->flags = be32_to_cpu(fmsb->flags); + + if (fmsb->version == 1) { + if (fm->flags != 0) { + ubi_err(ubi, "fastmap flags are non-zero: %#x", + fm->flags); + ret = UBI_BAD_FASTMAP; + goto free_fm_sb; + } + } else if (fmsb->version == 2) { + if ((fm->flags & UBI_FM_SB_FLG_MASK) != UBI_FM_SB_FLG_MASK) { + ubi_err(ubi, "unsupported fastmap flags present: %#x", + fm->flags); + ret = UBI_BAD_FASTMAP; + goto free_fm_sb; + } + } else { + ubi_err(ubi, "bad fastmap version: %i", fmsb->version); ret = UBI_BAD_FASTMAP; goto free_fm_sb; } @@ -1229,10 +1244,11 @@ static int ubi_write_fastmap(struct ubi_device *ubi, ubi_assert(fm_pos <= ubi->fm_size); fmsb->magic = cpu_to_be32(UBI_FM_SB_MAGIC); - fmsb->version = UBI_FM_FMT_VERSION; + fmsb->version = UBI_FM_FMT_WRITE_VERSION; fmsb->used_blocks = cpu_to_be32(new_fm->used_blocks); /* the max sqnum will be filled in while *reading* the fastmap */ fmsb->sqnum = 0; + fmsb->flags = 0; fmh->magic = cpu_to_be32(UBI_FM_HDR_MAGIC); free_peb_count = 0; diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h index 195ff8ca8211..6136a97f4844 100644 --- a/drivers/mtd/ubi/ubi-media.h +++ b/drivers/mtd/ubi/ubi-media.h @@ -365,7 +365,10 @@ struct ubi_vtbl_record { #define UBI_FM_DATA_VOLUME_ID (UBI_LAYOUT_VOLUME_ID + 2) /* fastmap on-flash data structure format version */ -#define UBI_FM_FMT_VERSION 1 +#define UBI_FM_FMT_VERSION 2 + +/* this implementation writes always version 1 */ +#define UBI_FM_FMT_WRITE_VERSION 1 #define UBI_FM_SB_MAGIC 0x7B11D69F #define UBI_FM_HDR_MAGIC 0xD4B82EF7 @@ -387,6 +390,8 @@ struct ubi_vtbl_record { #define UBI_FM_MIN_POOL_SIZE 8 #define UBI_FM_MAX_POOL_SIZE 256 +#define UBI_FM_SB_FLG_MASK 0 + /** * struct ubi_fm_sb - UBI fastmap super block * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC) @@ -396,6 +401,7 @@ struct ubi_vtbl_record { * @block_loc: an array containing the location of all PEBs of the fastmap * @block_ec: the erase counter of each used PEB * @sqnum: highest sequence number value at the time while taking the fastmap + * @flags: fastmap specific flags, only used with @version > 1, zero otherwise * */ struct ubi_fm_sb { @@ -407,7 +413,8 @@ struct ubi_fm_sb { __be32 block_loc[UBI_FM_MAX_BLOCKS]; __be32 block_ec[UBI_FM_MAX_BLOCKS]; __be64 sqnum; - __u8 padding2[32]; + __be32 flags; + __u8 padding2[28]; } __packed; /** diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index f5ba97c46160..4fab3790733b 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -249,6 +249,7 @@ struct ubi_volume_desc; * @used_blocks: number of used PEBs * @max_pool_size: maximal size of the user pool * @max_wl_pool_size: maximal size of the pool used by the WL sub-system + * @flags: fastmap flags */ struct ubi_fastmap_layout { struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS]; @@ -256,6 +257,7 @@ struct ubi_fastmap_layout { int used_blocks; int max_pool_size; int max_wl_pool_size; + int flags; }; /** From patchwork Wed Jun 13 21:23:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929092 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="POB5jcel"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415ft563xQz9s01 for ; Thu, 14 Jun 2018 07:25:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rSGb5Wz3bVxk7ho6InvuQA0K4AFj3rkmr2F2BrrhqNE=; b=POB5jcel1tz2WgX3vcbrOtn+Lg GIF7OTaqK7qeSJAxOx/RRm56ybjugTYB/2lho/07grmOnC5pmp5ZfFuBspa5U3PelieeIbwDwSbJb Fx65KXNJxcr6qpVQrMtOmvHQwDrcgTbDqMJVbi2RBATNs7gH8sHQotVbeOSTr8XTi9sv/g/Hkfl5G J3WDAiMdB5u6jY2bEjyh8Gz1xQJyd08TpoFv2zZvBxd1BCy8BNEIrV5YWChxACS300tHu3heso2Kc inC9obzqrhNUUt2J9YQraGr9VhlRXKQyokwaF3bChhmDuYm7g3vy/HukyWbheqQ9LE00LtFf5ayZP wn0EROTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDGO-0005gE-Ns; Wed, 13 Jun 2018 21:25:08 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFV-0004qT-Hc for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:17 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 8CDA7181A2F30; Wed, 13 Jun 2018 23:24:02 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 04/14] ubi: fastmap: Add UBI_FM_SB_PRESEEDED_FLG flag Date: Wed, 13 Jun 2018 23:23:34 +0200 Message-Id: <20180613212344.11608-5-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142413_774406_B395705F X-CRM114-Status: GOOD ( 12.58 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This flag indicates that the fastmap was preseeded, which means it was created offline by a tool such as ubinize which cannot know the whole MTD state such as real size and bad blocks. As consequence UBI has to take special care to use that fastmap. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/ubi-media.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h index 6136a97f4844..be339fb924af 100644 --- a/drivers/mtd/ubi/ubi-media.h +++ b/drivers/mtd/ubi/ubi-media.h @@ -390,7 +390,11 @@ struct ubi_vtbl_record { #define UBI_FM_MIN_POOL_SIZE 8 #define UBI_FM_MAX_POOL_SIZE 256 -#define UBI_FM_SB_FLG_MASK 0 +enum { + UBI_FM_SB_PRESEEDED_FLG = 0x1, +}; + +#define UBI_FM_SB_FLG_MASK (UBI_FM_SB_PRESEEDED_FLG) /** * struct ubi_fm_sb - UBI fastmap super block From patchwork Wed Jun 13 21:23:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929104 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V4Y7xxNN"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415g0r60Wcz9s01 for ; Thu, 14 Jun 2018 07:31:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AHT2xGlycFVNdV7U4YJr2tzxjkCwvt5IkORs4RPSrac=; b=V4Y7xxNNf/alVj7BCr/80V4MWf 2Ec0r+ozBBSQ5UnuspDz/SX0xM6d2L12hrOdPb6WwVSvQw00nbd+Pz6Q2LYFZPsAurlw/IX7DCFVm ofQZdKEpgWtfTxc2V8b6M2EOqCJiI1HqIe5h6k5N1vfdPpRTiKmJavL/fN3p6TLFmANpvFeVRpWoD MtITt34jLgrRssGy3yrToloZxipgws4kodWrsl5qgacfrFBSZE3x4rJLNJF1Ayk33/tc8OWHBh/Ec 5ywUuEkN3Bb4oYB2zx35MBeg2xl/LpkjLwTtNIUQoXMxizU9Rq17Bj4ZHvZvOoHXfNKXrvCwLYFNu /LfwvBtA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDM1-00038k-HG; Wed, 13 Jun 2018 21:30:57 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004u6-Ni for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:25:01 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 85D32181B5055; Wed, 13 Jun 2018 23:24:03 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 05/14] ubi: fastmap: Implement PEB translation Date: Wed, 13 Jun 2018 23:23:35 +0200 Message-Id: <20180613212344.11608-6-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142427_171848_308B2ED1 X-CRM114-Status: GOOD ( 19.75 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When a fastmap is preseeded we have to translate PEB numbers because during the creation of the fastmap the creation tool cannot know which blocks are bad on the target(s). Therefore fastmap has to learn all bad blocks during attach and changes PEB numbers accordingly. This feature assumes that bad blocks are skipped while the image was flashed, what nandwrite does by default. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/attach.c | 1 + drivers/mtd/ubi/fastmap.c | 74 +++++++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/ubi/ubi.h | 2 ++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c index 93ceea4f27d5..9a8072cf458c 100644 --- a/drivers/mtd/ubi/attach.c +++ b/drivers/mtd/ubi/attach.c @@ -1370,6 +1370,7 @@ static void destroy_ai(struct ubi_attach_info *ai) } kmem_cache_destroy(ai->aeb_slab_cache); + kfree(ai->bb_trans); kfree(ai); } diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 1ebb5d15ab1a..279d02874297 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -107,6 +107,9 @@ static bool read_pnum(struct ubi_device *ubi, struct ubi_attach_info *ai, int ret = true; int max_pnum = ubi->peb_count; + if (ai->bb_trans) + max_pnum -= ai->bad_peb_count; + pnum = be32_to_cpu(pnum); if (pnum == UBI_UNKNOWN) { *out_pnum = pnum; @@ -117,10 +120,13 @@ static bool read_pnum(struct ubi_device *ubi, struct ubi_attach_info *ai, ubi_err(ubi, "fastmap references PEB out of range: %i", pnum); ret = false; goto out; - } else { - *out_pnum = pnum; } + if (!ai->bb_trans) + *out_pnum = pnum; + else + *out_pnum = ai->bb_trans[pnum]; + out: return ret; } @@ -880,6 +886,61 @@ static struct ubi_ainf_peb *clone_aeb(struct ubi_attach_info *ai, return new; } +/* + * build_bb_trans_table - create a translation table to fix PEB numbers. + * @ubi: UBI device object + * @ai: UBI attach info object + * + * A preseeded Fastmap has no knowledge of bad blocks. During first attach + * UBI has to update PEB numbers to leave out existing bad blocks. + */ +static int build_bb_trans_table(struct ubi_device *ubi, + struct ubi_attach_info *ai) +{ + int pnum, new_pnum, ret; + unsigned long *claimed_blocks; + + ret = -ENOMEM; + claimed_blocks = kcalloc(BITS_TO_LONGS(ubi->peb_count), + sizeof(unsigned long), GFP_KERNEL); + if (!claimed_blocks) + goto out; + + /* ai->bb_trans will get free'ed via destroy_ai() */ + ai->bb_trans = kcalloc(ubi->peb_count, sizeof(int), GFP_KERNEL); + if (!ai->bb_trans) + goto out; + + /* Find all bad blocks and mark them as claimed */ + for (pnum = 0; pnum < ubi->peb_count; pnum++) { + ret = ubi_io_is_bad(ubi, pnum); + if (ret < 0) + goto out; + + if (ret == 1) { + set_bit(pnum, claimed_blocks); + ai->bad_peb_count++; + } + } + + /* + * Start with PEB 0 and try to place each PEB around all bad blocks + * to create the translation table. + */ + for (pnum = 0; pnum < ubi->peb_count - ai->bad_peb_count; pnum++) { + ubi_assert(!bitmap_full(claimed_blocks, ubi->peb_count)); + + new_pnum = find_first_zero_bit(claimed_blocks, ubi->peb_count); + ai->bb_trans[pnum] = new_pnum; + set_bit(new_pnum, claimed_blocks); + } + +out: + kfree(claimed_blocks); + + return ret; +} + /** * ubi_scan_fastmap - scan the fastmap. * @ubi: UBI device object @@ -987,6 +1048,15 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, goto free_fm_sb; } + if (fm->flags & UBI_FM_SB_PRESEEDED_FLG) { + ubi_msg(ubi, "preseeded fastmap found"); + ret = build_bb_trans_table(ubi, ai); + if (ret) { + ubi_err(ubi, "failed to construct bb translation table"); + goto free_fm_sb; + } + } + ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); if (!ech) { ret = -ENOMEM; diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 4fab3790733b..28af5115d180 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -760,6 +760,7 @@ struct ubi_ainf_volume { * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects * @ech: temporary EC header. Only available during scan * @vidh: temporary VID buffer. Only available during scan + * @bb_trans: bad block translation table, used by fastmap, NULL otherwise * * This data structure contains the result of attaching an MTD device and may * be used by other UBI sub-systems to build final UBI data structures, further @@ -790,6 +791,7 @@ struct ubi_attach_info { struct kmem_cache *aeb_slab_cache; struct ubi_ec_hdr *ech; struct ubi_vid_io_buf *vidb; + int *bb_trans; }; /** From patchwork Wed Jun 13 21:23:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929099 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZD7MM59o"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fxy38NDz9s2g for ; Thu, 14 Jun 2018 07:28:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ifIQS6PGokOJgq7sVRINlrmeikFyDjKsSas/+7/GX80=; b=ZD7MM59ol+N8xlB53KKUOXmeGr mgTNbG0bOsLWTWxU0EJojoCOkY9s1RXomvnT8nuHkkhp7C+4c4Wtu0fIq7rxreNs3U+TuNgoTSgY9 HwaFL4uAUvktdQl4aPkq+CaHXP9QhcRER7tqqfxEOO98qLcWC23YPZHGLUURSIFGZ5k6Hodv2vUNC Q+zlBAPXqHeV6YOWUCiWup8rB62H2Kio9GY9jh85AvXEVSYP94eeLoa7YrVOfPlCoaAW1RnY1i0eK NmO+L9s46fUroUeL35Pes4bq6k/AJJQ7qSoFrojnzHMWuH71sTgPMUNKk778uW7wzi1y6UZxrlWYI lppUEKNw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDJe-0000EV-2A; Wed, 13 Jun 2018 21:28:30 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004u5-O6 for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:38 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id DE6F5181B5052; Wed, 13 Jun 2018 23:24:03 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 06/14] ubi: fastmap: Handle bad block count for preseeded fastmap case Date: Wed, 13 Jun 2018 23:23:36 +0200 Message-Id: <20180613212344.11608-7-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142427_001984_8A4CBE16 X-CRM114-Status: GOOD ( 14.41 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If the fastmap is preseeded the bad block count is created while scanning for bad blocks in the PEB fixup code. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 279d02874297..69b855b3cf2a 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -725,7 +725,16 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, } ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count); - ai->bad_peb_count = be32_to_cpu(fmhdr->bad_peb_count); + + if (fm->flags & UBI_FM_SB_PRESEEDED_FLG) { + /* When we have a preseeded Fastmap we cannot use the provided bad block number */ + if (be32_to_cpu(fmhdr->bad_peb_count) != 0) { + ubi_err(ubi, "Bad block count in preseeded Fastmap is non-zero"); + goto fail_bad; + } + } else { + ai->bad_peb_count = be32_to_cpu(fmhdr->bad_peb_count); + } /* Iterate over all volumes and read their EBA table */ for (i = 0; i < be32_to_cpu(fmhdr->vol_count); i++) { From patchwork Wed Jun 13 21:23:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929095 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NuuFZMNV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fvt10njz9s01 for ; Thu, 14 Jun 2018 07:26:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0K1Jsi5MW9OwCtjWHRZhed5GVG9CNb65KBttJSq4tIM=; b=NuuFZMNV+QuIRBXQQhExcxGUVm Q5Nirt7x1gH9kddjxFJM72WnoblHmbEUvJQ/Eba9KkZ3TOfZHxF4dLV4c95LJjzIVNCv61DjsQ4Jf iG5QSK9OPHX/xAyx62dVfc8gQWIIHU6g51Ko0qpBI9ElSy6K2Smpa70+0WTRV9XkoKLO1o4l0XyeT bQTVFTAZn288I7mh7EZqnozbI9nQ0/vY4jEhQg6zVNe7ptq2nIurumkr/m17WoW5H+ldHR0uZQwrq qqHvMKa3sT18+cuCSXcV16qqTEErSq0U2iP2SN5Y5z2U6NCf15+zRkJC4IDIR2BI3fxUxuVz44ZWn fwEbifXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDHq-0007XZ-Jm; Wed, 13 Jun 2018 21:26:38 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004u7-Nk for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:37 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 339BE181A2BDA; Wed, 13 Jun 2018 23:24:04 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 07/14] ubi: fastmap: Fixup pool sizes for preseeded fastmaps Date: Wed, 13 Jun 2018 23:23:37 +0200 Message-Id: <20180613212344.11608-8-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142426_975702_9DE93708 X-CRM114-Status: GOOD ( 13.10 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org A preseeded fastmap has, by definition, no dirty PEBs and therefore all pools are empty. The creation tool can also not calculate the maximal pool sizes. This means we have to set them during attach. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 69b855b3cf2a..976d371d7cef 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -645,8 +645,15 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, pool_size = be16_to_cpu(fmpl->size); wl_pool_size = be16_to_cpu(fmpl_wl->size); - fm->max_pool_size = be16_to_cpu(fmpl->max_size); - fm->max_wl_pool_size = be16_to_cpu(fmpl_wl->max_size); + + if (fm->flags & UBI_FM_SB_PRESEEDED_FLG) { + fm->max_pool_size = ubi->fm_pool.max_size; + fm->max_wl_pool_size = ubi->fm_wl_pool.max_size; + + } else { + fm->max_pool_size = be16_to_cpu(fmpl->max_size); + fm->max_wl_pool_size = be16_to_cpu(fmpl_wl->max_size); + } if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) { ubi_err(ubi, "bad pool size: %i", pool_size); From patchwork Wed Jun 13 21:23:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929103 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Q2j6Yl8R"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415g0D5g0wz9s01 for ; Thu, 14 Jun 2018 07:30:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dJ7X3pdbyrYZhn+3bjhCyAsadUS47uDlrsSNyaAmI5w=; b=Q2j6Yl8RA9CnRA3Vty9AKnnzUf pZH4XAXmmMvFSBqfbbAnLIfi9WwSvxYooO2qBBo/ba1+A1I1aAHNF375Y0xcPMzgQ80FRd4ihnHdi mlkyEJDCLiLKNgpaMJw19Jy5NnlTVqmsy0/QC3JjtzgkI4+1eLyuqk4xuz2brx1vHH/i7s0pBS7Lk nk4aN5Hy39kA4KY0TtMz1rh8sQ8Hwe27oYTar7E8YTiE+XDqcmOxSNvXX3w+mt+fdaksG9EdGKnmI 2G1KZv9yP79zJnCB3yC62ohwbm90Oj3lOXzHAovQ8ZsMZiAuJi0lk7WQdNa6sKoCijanKmqe+nTB7 8iObP2Rg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDLV-0002Hs-BG; Wed, 13 Jun 2018 21:30:25 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004u8-Ng for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:25:01 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 1185518198DC1; Wed, 13 Jun 2018 23:24:04 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 08/14] ubi: fastmap: Scan empty space if fastmap is preseeded Date: Wed, 13 Jun 2018 23:23:38 +0200 Message-Id: <20180613212344.11608-9-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142427_204273_4E245A04 X-CRM114-Status: GOOD ( 20.23 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The creation tool does not know the real size of the MTD, therefore the preseeded fastmap references only used PEBs. Free PEBs need to be discovered during the initial attach of the preseeded fastmap. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 123 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 976d371d7cef..09a9d3a0ccf5 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -422,6 +422,96 @@ static void unmap_peb(struct ubi_attach_info *ai, int pnum) } } } +/** + * scan_empty_space - scan empty space. + * + * @ubi: UBI device object + * @ai: attach info object + * @start: PEB number where empty space is expected to start + * + * Is is the fastmap preseeded, it references only used PEBs, the creation + * does not know the real MTD size. Therefore many PEBs are 0xff and unknown + * to the fastmap. Scan for this PEBs during attach and make them known. + * These PEBs are only allowed to be 0xff or have a valid EC header. + * EC headers are allowed because the initial scan+erase operation could be + * interrupted by a power cycle. + */ +static int scan_empty_space(struct ubi_device *ubi, struct ubi_attach_info *ai, + int start) +{ + int pnum, err, scrub, empty, image_seq; + unsigned long long ec; + struct ubi_ec_hdr *ech = NULL; + struct ubi_vid_io_buf *vb = NULL; + struct ubi_vid_hdr *vh; + + err = -ENOMEM; + + ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); + if (!ech) + goto out; + + vb = ubi_alloc_vid_buf(ubi, GFP_KERNEL); + if (!vb) + goto out; + + vh = ubi_get_vid_hdr(vb); + + ubi_msg(ubi, "scanning %i additional PEBs", ubi->peb_count - start); + + for (pnum = start; pnum < ubi->peb_count; pnum++) { + if (ubi_io_is_bad(ubi, pnum)) + continue; + + scrub = empty = ec = 0; + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); + switch (err) { + case UBI_IO_FF_BITFLIPS: + scrub = 1; + /* fall through */ + case UBI_IO_FF: + empty = 1; + break; + case UBI_IO_BITFLIPS: + scrub = 1; + /* fall through */ + case 0: + ec = be64_to_cpu(ech->ec); + image_seq = be32_to_cpu(ech->image_seq); + + if (image_seq && (image_seq != ubi->image_seq)) { + ubi_err(ubi, "bad image seq: 0x%x, expected: 0x%x", + image_seq, ubi->image_seq); + err = UBI_BAD_FASTMAP; + goto out; + } + break; + default: + ubi_err(ubi, "Unable to read EC header in empty space: %i", + err); + err = UBI_BAD_FASTMAP; + goto out; + } + + err = ubi_io_read_vid_hdr(ubi, pnum, vb, 0); + if (err != UBI_IO_FF && err != UBI_IO_FF_BITFLIPS) { + ubi_err(ubi, "Unexpected data in empty space: %i", err); + err = UBI_BAD_FASTMAP; + goto out; + } + + if (empty) + add_aeb(ai, &ai->erase, pnum, ec, scrub); + else + add_aeb(ai, &ai->free, pnum, ec, scrub); + } + + err = 0; +out: + kfree(ech); + ubi_free_vid_buf(vb); + return err; +} /** * scan_pool - scans a pool for changed (no longer empty PEBs). @@ -818,13 +908,34 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, } } - ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &free); - if (ret) - goto fail; + if (!(fm->flags & UBI_FM_SB_PRESEEDED_FLG)) { + ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &free); + if (ret) + goto fail; - ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &free); - if (ret) - goto fail; + ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &free); + if (ret) + goto fail; + } + + if (fm->flags & UBI_FM_SB_PRESEEDED_FLG) { + int empty_start = be32_to_cpu(fmhdr->used_peb_count) + \ + be32_to_cpu(fmhdr->erase_peb_count) + fm->used_blocks; + + if (empty_start + ai->bad_peb_count > ubi->peb_count) { + ubi_err(ubi, "fastmap points beyond end of device!"); + goto fail_bad; + } else if (empty_start + ai->bad_peb_count == ubi->peb_count) { + ubi_msg(ubi, "no need to scan empty space"); + } else { + if (!read_pnum(ubi, ai, cpu_to_be32(empty_start), &empty_start)) + goto fail_bad; + + ret = scan_empty_space(ubi, ai, empty_start); + if (ret) + goto fail; + } + } if (max_sqnum > ai->max_sqnum) ai->max_sqnum = max_sqnum; From patchwork Wed Jun 13 21:23:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929098 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nzFI5mT/"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fxT5pyXz9s01 for ; Thu, 14 Jun 2018 07:28:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=oKdh5B0EmRNFUzcvLhqZyZRgGX3qQWYYd5dti9u7t30=; b=nzFI5mT/xmVW+J0OU2Y01Nrk+a fIZO/p8P/aVBEOu/zau3ksVxzCXHQRk4DhYlucbGIZUShsZVhx93rQvQGGbCtS213M6nF3zHR4wEz wzZ4wPKK9NC4ic/NITx4CKS4p0BmRGynL1iOEsbKD295diTdmS3P55HHE6O50elPHlVzCV++LWp78 1UYlAVYmqnVcmv+EZwhyQ0o9Q0nhpSgmglbKtbggPIHR5ilaIkHj3Gpz2AFJEZYzwPzaBs2Yl6dBf 88xa75pba2rTqYIyIS5dfUFtbDLO6u63NxtiDP+DcqdBMu+ViHgmiqZUb0JZfiW4GrB8dNwwcTCLo Dn2XzwKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDJC-0008OZ-Kd; Wed, 13 Jun 2018 21:28:02 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004ub-O2 for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:39 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 5839418198DC3; Wed, 13 Jun 2018 23:24:05 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 09/14] ubi: fastmap: Relax size check Date: Wed, 13 Jun 2018 23:23:39 +0200 Message-Id: <20180613212344.11608-10-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142426_986726_B3004CC1 X-CRM114-Status: GOOD ( 14.90 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org While attaching via fastmap we verify whether the found fastmap is as large as we have computed. With preseeded Fastmaps this assumtion can fail since ubinize cannot know the total size of the MTD and uses the number if used PEBs for the calculation. Therefore the found fastmap might be smaller than the kernel expects. Signed-off-by: Richard Weinberger Reviewed-by: Boris Brezillon --- drivers/mtd/ubi/fastmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 09a9d3a0ccf5..dabeb01af24a 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -1168,7 +1168,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, } fm_size = ubi->leb_size * used_blocks; - if (fm_size != ubi->fm_size) { + if (fm_size > ubi->fm_size) { ubi_err(ubi, "bad fastmap size: %zi, expected: %zi", fm_size, ubi->fm_size); ret = UBI_BAD_FASTMAP; From patchwork Wed Jun 13 21:23:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929096 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iXDvlV0V"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fwN15Gxz9s01 for ; Thu, 14 Jun 2018 07:27:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=QtD/H6T4ljOmlpWeXp0hdM4XTdG4fK/06fZnxt7tlBo=; b=iXDvlV0VZUPsltbC8tuQ6TagJ+ 6NFnsJh2UW+cAM9CBNM+b2js6B83tojunQrjnF5ad6FU1XugJofC8zPdO6TAGmExwlat6ZlVl6gVN 17k88vWgHE/70+xbAEAdm6YLWbjp0FIzEDFq+/w+U59IRAyDfGppiPSX9KzffvEURw2mM/jsr4NLx jRsepJiubHLFzYAkJhBomGE9IyvWBq3FbHeB9ce731k+7LsV4PWx8rDmmPIdmk7ziH0DC0f1qs2Zf ADiV30677+VYY7Z/tv7u8hjMrFwAzy03ePSG7LxgVDbiXZ+ltbO6KyHuog29zhdzrHrCQoYBAGM9o KhJuoxsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDIF-0007oB-CU; Wed, 13 Jun 2018 21:27:03 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004ua-Nu for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:35 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 9DEAE18198DC5; Wed, 13 Jun 2018 23:24:06 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 10/14] ubi: fastmap: Change a WARN_ON() to ubi_err() Date: Wed, 13 Jun 2018 23:23:40 +0200 Message-Id: <20180613212344.11608-11-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142426_973270_139CAD46 X-CRM114-Status: GOOD ( 12.77 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This WARN_ON() was used while development of fastmap, now it can be a regular ubi_err(). Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/fastmap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index dabeb01af24a..d5506152c9f7 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -949,14 +949,16 @@ static int ubi_attach_fastmap(struct ubi_device *ubi, ubi_assert(list_empty(&free)); /* - * If fastmap is leaking PEBs (must not happen), raise a - * fat warning and fall back to scanning mode. - * We do this here because in ubi_wl_init() it's too late - * and we cannot fall back to scanning. + * The orginal purpose of this check was detecting fastmap bugs were + * it missed blocks. Now it helps to detect mis-flashed UBIs. + * E.g. when a fastmap enabled UBI is copied to another target with + * different bad blocks. */ - if (WARN_ON(count_fastmap_pebs(ai) != ubi->peb_count - - ai->bad_peb_count - fm->used_blocks)) + if (count_fastmap_pebs(ai) != ubi->peb_count - ai->bad_peb_count - + fm->used_blocks) { + ubi_err(ubi, "number of PEBs referenced by fastmap does not match MTD!"); goto fail_bad; + } return 0; From patchwork Wed Jun 13 21:23:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929097 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kibUrvij"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fwz6jPsz9s01 for ; Thu, 14 Jun 2018 07:27:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hbnoZjV3UNK0enzv3qJsHDRsUHPHUwzfw0R7w3JlTJ0=; b=kibUrvijuPHwXlnkf6l5aSHQ/X DM0UhoTkOGS0DLTkYgA/5soc0MzjfbXhzX19RH8EcpRkki4yyno6vfe+tDP8eWRSLf9dPloYxAqu4 j1iBkGoHocR7iTHV6jp9Opui1KguNUkg6936zruowdGvI9/g7THiM4ikGk3TIjITLtreQUuNDauyM Ws5bAXFqBKTNbnQiS5bimE9bP7NUaPUnSXBTkMd9zTo3XK9RmFKh7pTHvJN+TWVUa6DU/nFtMiZSt DnmddjdSD5yzh4NPVtTRqzU9yGIPCdi98SP3hrrCF0oq5WS1GO5eo14mRFadRoUU4YuYd5xtgwuTd d92jsFlg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDIk-00087p-Jq; Wed, 13 Jun 2018 21:27:34 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004ui-Nx for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:41 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 286E918198DC2; Wed, 13 Jun 2018 23:24:07 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 11/14] ubi: Add module parameter to force a full scan Date: Wed, 13 Jun 2018 23:23:41 +0200 Message-Id: <20180613212344.11608-12-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142426_982419_6CFF1A83 X-CRM114-Status: GOOD ( 15.12 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Using this parameter one can force UBI do to a full scan instead of using a fastmap. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/attach.c | 13 +++++++++---- drivers/mtd/ubi/build.c | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c index 9a8072cf458c..134b15f093c3 100644 --- a/drivers/mtd/ubi/attach.c +++ b/drivers/mtd/ubi/attach.c @@ -925,7 +925,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, return err; } -static bool vol_ignored(int vol_id) +static bool vol_ignored(struct ubi_attach_info *ai, int vol_id) { switch (vol_id) { case UBI_LAYOUT_VOLUME_ID: @@ -933,6 +933,9 @@ static bool vol_ignored(int vol_id) } #ifdef CONFIG_MTD_UBI_FASTMAP + if (ai->force_full_scan) + return false; + return ubi_is_fm_vol(vol_id); #else return false; @@ -1143,7 +1146,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, } vol_id = be32_to_cpu(vidh->vol_id); - if (vol_id > UBI_MAX_VOLUMES && !vol_ignored(vol_id)) { + if (vol_id > UBI_MAX_VOLUMES && !vol_ignored(ai, vol_id)) { int lnum = be32_to_cpu(vidh->lnum); /* Unsupported internal volume */ @@ -1581,9 +1584,11 @@ int ubi_attach(struct ubi_device *ubi, int force_scan) force_scan = 1; } - if (force_scan) + if (force_scan) { + ubi_msg(ubi, "full scan forced"); + ai->force_full_scan = 1; err = scan_all(ubi, ai, 0); - else { + } else { err = scan_fast(ubi, &ai); if (err > 0 || mtd_is_eccerr(err)) { if (err != UBI_NO_FASTMAP) { diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index d2a726654ff1..1e3f75ede985 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -83,6 +83,7 @@ static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; static bool fm_autoconvert; static bool fm_debug; #endif +static bool force_scan; /* Slab cache for wear-leveling entries */ struct kmem_cache *ubi_wl_entry_slab; @@ -956,7 +957,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, if (!ubi->fm_buf) goto out_free; #endif - err = ubi_attach(ubi, 0); + err = ubi_attach(ubi, force_scan); if (err) { ubi_err(ubi, "failed to attach mtd%d, error %d", mtd->index, err); @@ -1458,6 +1459,8 @@ module_param(fm_autoconvert, bool, 0644); MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap."); module_param(fm_debug, bool, 0); MODULE_PARM_DESC(fm_debug, "Set this parameter to enable fastmap debugging by default. Warning, this will make fastmap slow!"); +module_param(force_scan, bool, 0644); +MODULE_PARM_DESC(force_scan, "Always do a full scan of the MTD and drop possible fastmap structures from the MTD."); #endif MODULE_VERSION(__stringify(UBI_VERSION)); MODULE_DESCRIPTION("UBI - Unsorted Block Images"); From patchwork Wed Jun 13 21:23:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929101 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KTJ9RKai"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fzB3C4wz9s01 for ; Thu, 14 Jun 2018 07:29:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6bLg6oxLAlbce/Z2Aw3iac6v2V3yZLajZAHnpXYXJdY=; b=KTJ9RKaiCqtwEA7AvzT9Izs87C jBPlyAyE3GPDVKzbUJfk/6djgXDe86QXIHGhdfTg132tA+zMD5FraOfzbc6gJsi8q0zWi/3g5FpWY K9+tDtJvJkcAXrm6kglFLmy3OzqEHsz6BRRRS6fT3ucb3yfrBlcDbCIF/0H8IZz/gUjji9TnRw+yY NArx6NR+E3dzukgZAeALJkPNtS6dj1sXJeiueAU35qaOZ0A2qhLrohKwcIAyEMYrP+/YEgGerfqv3 dptIkBx2SpxRlFS44UJyF9YDBd8X8gFXp6hLscKIIT0wy49SlrfcwiNeL633+rIYlh5DDy7VZMj5R fia1PYKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDKa-0000rz-AL; Wed, 13 Jun 2018 21:29:28 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004uh-O4 for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:43 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 1993418198DC8; Wed, 13 Jun 2018 23:24:08 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 12/14] ubi: uapi: Add mode selector to attach request Date: Wed, 13 Jun 2018 23:23:42 +0200 Message-Id: <20180613212344.11608-13-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142426_993003_CC7736FC X-CRM114-Status: GOOD ( 14.56 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allows userspace, ubiattach, to force a full scan. Signed-off-by: Richard Weinberger --- include/uapi/mtd/ubi-user.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/uapi/mtd/ubi-user.h b/include/uapi/mtd/ubi-user.h index 5b04a494d139..cc0e54cfa7f9 100644 --- a/include/uapi/mtd/ubi-user.h +++ b/include/uapi/mtd/ubi-user.h @@ -235,12 +235,19 @@ enum { UBI_VOL_PROP_DIRECT_WRITE = 1, }; +enum { + UBI_ATTACH_MODE_AUTO = 0x0, + UBI_ATTACH_MODE_SCAN = 0x1, + UBI_ATTACH_MODE_MAX = UBI_ATTACH_MODE_SCAN, +}; + /** * struct ubi_attach_req - attach MTD device request. * @ubi_num: UBI device number to create * @mtd_num: MTD device number to attach * @vid_hdr_offset: VID header offset (use defaults if %0) * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs + * @attach_mode: selects the attach mode * @padding: reserved for future, not used, has to be zeroed * * This data structure is used to specify MTD device UBI has to attach and the @@ -276,13 +283,18 @@ enum { * eraseblocks for new bad eraseblocks, but attempts to use available * eraseblocks (if any). The accepted range is 0-768. If 0 is given, the * default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used. + * + * @attach_mode is %UBI_ATTACH_MODE_AUTO by default, and let's the UBI + * implementation decide how to attach. If %UBI_ATTACH_MODE_SCAN is selected + * a full scan is forced. */ struct ubi_attach_req { __s32 ubi_num; __s32 mtd_num; __s32 vid_hdr_offset; __s16 max_beb_per1024; - __s8 padding[10]; + __s8 attach_mode; + __s8 padding[9]; }; /** From patchwork Wed Jun 13 21:23:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929102 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fnS6nUuA"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fzj6gZ8z9s2g for ; Thu, 14 Jun 2018 07:30:09 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4cfRyxzj5ReRyBJNrsltmd/4iu/XZWK9AXYxQGAyQ4A=; b=fnS6nUuAQ7Fy2A6XzhAdu48hw2 4LR0C0kEQL882Hf6ee0A2jicYCsPa5YL/IH1UdJFhOPPC0QyxvtyJE0CdMVvJVowM9R0B0dSk0lKP RI7kO9f8OUaVHferl57eHoQM2ocJif4DJJ3kTLOfPkSpyXaBAf7kHRHzME943aCm56LUuc/X9gpck rbcF7bUyYACudmvCEI6rdWWDg5cHUDGdvkuqzg0E1dNbaO8HTuySc3aOb5sCwXeppPqTlFi9WoteL 7McZ+WrC4kEa6/jYmHR1+BUlsnGsty4n3sKy0zqPyYlO7X392HgI0FLeRarlhCXqb+Fl5tPAP6Qea LS7ILC0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDL3-0001AB-4e; Wed, 13 Jun 2018 21:29:57 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004zs-VQ for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:25:00 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 99B1518198DC0; Wed, 13 Jun 2018 23:24:08 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 13/14] ubi: Wire up attach mode selector Date: Wed, 13 Jun 2018 23:23:43 +0200 Message-Id: <20180613212344.11608-14-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142427_358022_10929359 X-CRM114-Status: GOOD ( 16.47 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Now userspace can specify how UBI shall attach. By default UBI decides how to attach, but userspace can also force a full scan. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/build.c | 15 ++++++++++++--- drivers/mtd/ubi/cdev.c | 7 ++++++- drivers/mtd/ubi/ubi.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 1e3f75ede985..7d08b6498b2a 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -805,6 +805,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id) * @ubi_num: number to assign to the new UBI device * @vid_hdr_offset: VID header offset * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs + * @attach_mode: selects how to attach * * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in @@ -816,10 +817,12 @@ static int autoresize(struct ubi_device *ubi, int vol_id) * @ubi_devices_mutex. */ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, - int vid_hdr_offset, int max_beb_per1024) + int vid_hdr_offset, int max_beb_per1024, + int attach_mode) { struct ubi_device *ubi; int i, err; + int do_full_scan = false; if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT) return -EINVAL; @@ -957,7 +960,12 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, if (!ubi->fm_buf) goto out_free; #endif - err = ubi_attach(ubi, force_scan); + if (force_scan) + do_full_scan = 1; + else + do_full_scan = !!attach_mode; + + err = ubi_attach(ubi, do_full_scan); if (err) { ubi_err(ubi, "failed to attach mtd%d, error %d", mtd->index, err); @@ -1240,7 +1248,8 @@ static int __init ubi_init(void) mutex_lock(&ubi_devices_mutex); err = ubi_attach_mtd_dev(mtd, p->ubi_num, - p->vid_hdr_offs, p->max_beb_per1024); + p->vid_hdr_offs, p->max_beb_per1024, + UBI_ATTACH_MODE_AUTO); mutex_unlock(&ubi_devices_mutex); if (err < 0) { pr_err("UBI error: cannot attach mtd%d\n", diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 45c329694a5e..cf9b2b00e8c5 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c @@ -1001,6 +1001,11 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, break; } + if (req.attach_mode < 0 || req.attach_mode > UBI_ATTACH_MODE_MAX) { + err = -EINVAL; + break; + } + mtd = get_mtd_device(NULL, req.mtd_num); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); @@ -1013,7 +1018,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, */ mutex_lock(&ubi_devices_mutex); err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset, - req.max_beb_per1024); + req.max_beb_per1024, req.attach_mode); mutex_unlock(&ubi_devices_mutex); if (err < 0) put_mtd_device(mtd); diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 28af5115d180..0b2f79f68986 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -949,7 +949,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, /* build.c */ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, - int vid_hdr_offset, int max_beb_per1024); + int vid_hdr_offset, int max_beb_per1024, + int attach_mode); int ubi_detach_mtd_dev(int ubi_num, int anyway); struct ubi_device *ubi_get_device(int ubi_num); void ubi_put_device(struct ubi_device *ubi); From patchwork Wed Jun 13 21:23:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 929100 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HEaS3Bdc"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415fyX5vycz9s01 for ; Thu, 14 Jun 2018 07:29:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6aIUvHiWt/c6hb2bCJcUIbHHPdzZmNcg0fD1oa5VrC8=; b=HEaS3BdczKC94m/Asp+ELnn0z6 mdfhz6LVYSM3LnBKXcj1u9nOQvS9oyTYoUyDF0Jz48ph41pCFzJsWQstmoKX+qBjWO7IWI82mKAO7 x9hrDKTTgFuGhwhdh6jY1vl8g596WKBUME+5aI0yyyDNRO0Hb5rErTAZn+3iipP+MFIG/E2pUJxh2 5JawAVOa41169/ZUWTcrGzVk2gUw4N25ugNa6GeRGjlvNBKQmf+mPhDlMfUyXYLjADU3W+p/HN7U5 N46mKhlhd+MKPH6Btz9DHy/mVOUFgdvcnGpovllB5uvk9P3FgPlQkvDsltxveOmAeHe9WBg0JJsZZ iuAcWv4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDK7-0000Yq-JZ; Wed, 13 Jun 2018 21:28:59 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTDFi-0004zr-Qy for linux-mtd@lists.infradead.org; Wed, 13 Jun 2018 21:24:47 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 187AF18198DC4; Wed, 13 Jun 2018 23:24:09 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 14/14] ubi: Remove experimental stigma from Fastmap Date: Wed, 13 Jun 2018 23:23:44 +0200 Message-Id: <20180613212344.11608-15-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180613212344.11608-1-richard@nod.at> References: <20180613212344.11608-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180613_142427_150693_DA72D3F2 X-CRM114-Status: GOOD ( 13.98 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org I've hold up this a way too long. Over the last two years Fastmap gained many users which made it possible to sort out the last issues. Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/Kconfig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index 43d131f5ae10..4de5e4e8d4ab 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig @@ -57,12 +57,9 @@ config MTD_UBI_BEB_LIMIT Leave the default value if unsure. config MTD_UBI_FASTMAP - bool "UBI Fastmap (Experimental feature)" + bool "UBI Fastmap" default n help - Important: this feature is experimental so far and the on-flash - format for fastmap may change in the next kernel versions - Fastmap is a mechanism which allows attaching an UBI device in nearly constant time. Instead of scanning the whole MTD device it only has to locate a checkpoint (called fastmap) on the device. @@ -74,6 +71,8 @@ config MTD_UBI_FASTMAP images are still usable with UBI implementations without fastmap support. On typical flash devices the whole fastmap fits into one PEB. UBI will reserve PEBs to hold two fastmaps. + While Fastmap is considered correct it weakens UBI wrt. robustness, + a full scan of the MTD allows UBI to react better to bad flashes. If in doubt, say "N".