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; }; /**