From patchwork Wed Apr 3 13:30:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Molloy, Philip" X-Patchwork-Id: 1076579 X-Patchwork-Delegate: trini@ti.com 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.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=idexx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=IDEXX.onmicrosoft.com header.i=@IDEXX.onmicrosoft.com header.b="aMTtQgfM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44ZN8L2xjVz9sPc for ; Thu, 4 Apr 2019 10:49:06 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 0346DC21E1D; Wed, 3 Apr 2019 23:48:42 +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=SPF_HELO_PASS, 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 0D94CC21E34; Wed, 3 Apr 2019 23:48:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 65DD5C21DA2; Wed, 3 Apr 2019 13:30:59 +0000 (UTC) Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-eopbgr780133.outbound.protection.outlook.com [40.107.78.133]) by lists.denx.de (Postfix) with ESMTPS id 704FCC21C4A for ; Wed, 3 Apr 2019 13:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=IDEXX.onmicrosoft.com; s=selector1-idexx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2efezxtNvFZv1c+ehyI483sZHjMvXoDyYAzpWoFaWAE=; b=aMTtQgfMQwIkRo3xi7E6RRtq66ZvafY/DxrR2741yXdMmzgAtqOzAnfwcAHNmRbfRrJek5ErGE9hD1qPOFWtma6Kkvsn+BlsLtY/ZqTzaBJpNZj2nvtww8MDxc7gQ2nLrKYAx38Kc6HSoES5M8TX3yP8sUsOgOM2E9kXLDVM0dY= Received: from BN7PR02MB4978.namprd02.prod.outlook.com (20.176.26.75) by BN7PR02MB4243.namprd02.prod.outlook.com (52.135.251.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Wed, 3 Apr 2019 13:30:47 +0000 Received: from BN7PR02MB4978.namprd02.prod.outlook.com ([fe80::44a6:f977:afda:e997]) by BN7PR02MB4978.namprd02.prod.outlook.com ([fe80::44a6:f977:afda:e997%5]) with mapi id 15.20.1750.017; Wed, 3 Apr 2019 13:30:47 +0000 From: "Molloy, Philip" To: "u-boot@lists.denx.de" Thread-Topic: [PATCH 1/1] env: Exit tools when invalid CRC found Thread-Index: AQHU6iFyIHVwTdE0KkSn+J5uZ2XOvw== Date: Wed, 3 Apr 2019 13:30:47 +0000 Message-ID: <7f3c6ea239a26e247c43d1ddf6698f9f43973f76.camel@idexx.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Philip-Molloy@idexx.com; x-originating-ip: [67.244.34.8] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9c0c2f00-1de4-48bd-385d-08d6b8389518 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600139)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:BN7PR02MB4243; x-ms-traffictypediagnostic: BN7PR02MB4243: x-microsoft-antispam-prvs: x-forefront-prvs: 0996D1900D x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(376002)(39860400002)(366004)(346002)(136003)(189003)(199004)(81166006)(26005)(14444005)(8936002)(6436002)(86362001)(256004)(53936002)(99286004)(106356001)(72206003)(2351001)(36756003)(2906002)(105586002)(14454004)(478600001)(186003)(486006)(476003)(97736004)(2616005)(71190400001)(71200400001)(66066001)(25786009)(305945005)(8676002)(316002)(5640700003)(6116002)(2501003)(81156014)(6512007)(5660300002)(6486002)(6916009)(68736007)(118296001)(3846002)(6506007)(102836004)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN7PR02MB4243; H:BN7PR02MB4978.namprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: idexx.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: QR7MY1fRIiBAc6HA1ruTGpbw7Krix4485RmZekk6lO2nNT00r7MwnANBH9lFpgVkCaEj/CpaNrhfL07zOnnW21WgukIxrjsi8mdK1gtw4EhPUqccbhc+6h0PnQYm7Vk+DMXogbarDqpIk2RPt6i6nzJdE2a/kt+5RDhduq1efCMpc0ePa4oE0GoTGeN/SaSuQdlmcOoeo+OLYXv4p5Z0KInsK6iEaunuMl5MFWETxKqYRxTS3V1LpM45XfGKr+SjZ0y0B4iR3vakugvM1STXBACjiEDAYToy9wrPLxhnoIrS5heKmtEiLpJAHywt1+aTkIq8+Va1QSwP3iVXZalX3W7Rmq1O8N6YH0n24UNycC1wS/KuoTO4pOHzHPsvgMgql+16ukVct9P6xdS4gPgX+iXYFwhqIVOuuxYbm98sWtk= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: idexx.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c0c2f00-1de4-48bd-385d-08d6b8389518 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Apr 2019 13:30:47.5983 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f63b8b05-3357-43b9-bc80-230782752e4b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB4243 X-Mailman-Approved-At: Wed, 03 Apr 2019 23:48:23 +0000 Subject: [U-Boot] [PATCH 1/1] env: Exit tools when invalid CRC found 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" fw_setenv and fw_printenv currently print a warning and use a default environment compiled into the binary when an invalid CRC is found. This modifies the default behavior to print an error and exit. This is especially important when calling the tools from a script since the script depends on the exit code of the tool to know something went wrong. If the default environment is desired it should be read explicitly by the caller. A better model is to store a default environment as a separate binary or text file rather than storing it in the executable. Signed-off-by: Philip Molloy --- tools/env/fw_env.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) flag0 = *environment.flags; @@ -1500,10 +1499,8 @@ int fw_env_open(struct env_opts *opts) dev_current = 1; } else if (!crc0_ok && !crc1_ok) { fprintf(stderr, - "Warning: Bad CRC, using default environment\n"); - memcpy(environment.data, default_environment, - sizeof(default_environment)); - dev_current = 0; + "Invalid CRC found in both redundant environments\n"); + return -1; } else { switch (environment.flag_scheme) { case FLAG_BOOLEAN: diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index a5d75958e1..ef33e9e1be 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1438,9 +1438,8 @@ int fw_env_open(struct env_opts *opts) if (!have_redund_env) { if (!crc0_ok) { fprintf(stderr, - "Warning: Bad CRC, using default environment\n"); - memcpy(environment.data, default_environment, - sizeof(default_environment)); + "Invalid CRC found in environment\n"); + return -1; } } else {