From patchwork Tue Nov 12 19:02:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Hundeb=C3=B8ll?= X-Patchwork-Id: 1193774 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=geanix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=geanix.com header.i=@geanix.com header.b="YBNkz+eI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47CHFC2fP1z9s7T for ; Wed, 13 Nov 2019 06:02:55 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 0C807C21F1A; Tue, 12 Nov 2019 19:02:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 44DEEC21C51; Tue, 12 Nov 2019 19:02:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A9172C21C51; Tue, 12 Nov 2019 19:02:37 +0000 (UTC) Received: from first.geanix.com (first.geanix.com [116.203.34.67]) by lists.denx.de (Postfix) with ESMTPS id 56385C21C2F for ; Tue, 12 Nov 2019 19:02:37 +0000 (UTC) Received: from zen.localdomain (unknown [85.184.140.241]) by first.geanix.com (Postfix) with ESMTPSA id BC03351AE5; Tue, 12 Nov 2019 18:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1573585196; bh=JqiCETqZEy9JG7esTLs/JmZn/z1wGQrNk1jDWDSQMnI=; h=From:To:Cc:Subject:Date; b=YBNkz+eIzinjhdPkcVGxa89a7Yb0/yyvnpTm52CfTIS3g4vEwoyr4JSCCS+PrfG4g JUQtb4UN4Ah9oQ8dPZMBg50BdMVrRtGvAujsBU/9I/wcfrLMVWNxutH6ErIPllJNPE WFJSU7wIaJo+vDqqo/qoufd5HP+sJJkLxzQ/Zi9K5CEsmCcBRVeIoIpwwacSuUooLe T8bxTADm4ZUrFY2Pihqyst2wij0TH5IUYU46tgOYqs6wALX1J29e2SF4/IwAMAYb7I ONETv9Dy6cND09U/payTRjW67gm61AAVqIBOcTbJlHhvJe4dlTmvLfCFUXW2OLjByu O5T43JQNz9DqQ== From: =?utf-8?q?Martin_Hundeb=C3=B8ll?= To: u-boot@lists.denx.de Date: Tue, 12 Nov 2019 20:02:23 +0100 Message-Id: <20191112190223.225956-1-martin@geanix.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [U-Boot] [PATCH] tools: env: handle corrupted ubi volumes during sanity check X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" A partially written ubi volume is marked as such by the kernel. Such a mark causes the initial ubi sanity check to fail instead of falling back to the redundant environment. Fix this by special casing the EBADF return code from the UBI_IOCEBISMAP ioctl, as this is only ever returned in case of a partially written volume. The CRC checking will decide which environment to use anyways. Signed-off-by: Martin Hundebøll --- tools/env/fw_env.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index cfada0ee11..f7904ae036 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1608,7 +1608,13 @@ static int check_device_config(int dev) if (IS_UBI(dev)) { rc = ioctl(fd, UBI_IOCEBISMAP, &lnum); - if (rc < 0) { + if (rc < 0 && errno == EBADF) { + /* EBADF here means we are dealing with a partially + * written UBI volume, Leave it for now to allow the + * use of the redundant env. CRC checking will decide + * which to use */ + rc = 0; + } else if (rc < 0) { fprintf(stderr, "Cannot get UBI information for %s\n", DEVNAME(dev)); goto err;