From patchwork Thu Aug 25 08:26:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Olofsson X-Patchwork-Id: 111501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8E6C9B6F6F for ; Thu, 25 Aug 2011 18:27:17 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwVH7-00079c-91; Thu, 25 Aug 2011 08:26:57 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QwVH6-00067s-Pw; Thu, 25 Aug 2011 08:26:56 +0000 Received: from mail-gy0-f177.google.com ([209.85.160.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwVH3-00067b-6O for linux-mtd@lists.infradead.org; Thu, 25 Aug 2011 08:26:53 +0000 Received: by gyh20 with SMTP id 20so1843132gyh.36 for ; Thu, 25 Aug 2011 01:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=wnkBtuLW3YEsDBP0QobgVuQfEcTl0LeW53a4IIBjZ4A=; b=GgKFZDOJASPLCDAW2Otr8pj5m6yOIvA8SgFABPsHoBkss4aDHQDficA50z0dz9tjVR YKzbmeW0Ldcm3l1IYqrDBCuK4jh4IOYL6/3jEb57mT+rMkbWX7V12tDVN4xVm9xKRqRf 1cyWFyq4opI+fP2sLm+RrlK9gymFk6k6T/ulY= MIME-Version: 1.0 Received: by 10.236.187.74 with SMTP id x50mr37730382yhm.76.1314260809811; Thu, 25 Aug 2011 01:26:49 -0700 (PDT) Received: by 10.236.110.169 with HTTP; Thu, 25 Aug 2011 01:26:49 -0700 (PDT) Date: Thu, 25 Aug 2011 10:26:49 +0200 Message-ID: Subject: mtd-utils: ubiformat: writing images on flash with badblocks. From: Anton Olofsson To: linux-mtd@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110825_042653_506055_52CC34ED X-CRM114-Status: UNSURE ( 7.94 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (anol.martinsson[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi! We encountered some problems with ubiformat and writing ubi-images onto flash with badblocks. If a badblock was encountered during write ubiformat would skip writing that “file-block” altogether, and this would eventually result in EOF while trying to read the image file. The quick fix was to rewind the filedescriptor for the next pass. Im not sure if others have encountered this problem or even if this is the correct way to handle this situation. Here is the change made though: if (++written_ebs >= img_ebs) --- a/ubi-utils/ubiformat.c +++ b/ubi-utils/ubiformat.c @@ -546,6 +546,11 @@ static int flash_image(libmtd_t libmtd, const struct mtd_dev_info *mtd, if (mark_bad(mtd, si, eb)) goto out_close; } + /*rewind fd so next read_all(...) reads correct block*/ + if (lseek(fd, -mtd->eb_size, SEEK_CUR) == -1) { + sys_errmsg("unable to rewind file"); + goto out_close; + } continue; }