From patchwork Wed Dec 28 19:01:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frans Meulenbroeks X-Patchwork-Id: 133457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B5E97B6FA0 for ; Thu, 29 Dec 2011 06:32:04 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5673280D0; Wed, 28 Dec 2011 20:32:01 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 28N7nwlDOyq9; Wed, 28 Dec 2011 20:32:01 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AF9B6280E7; Wed, 28 Dec 2011 20:31:58 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BF00828103 for ; Wed, 28 Dec 2011 20:02:01 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YlfBEgwLI7Hr for ; Wed, 28 Dec 2011 20:02:01 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ee0-f44.google.com (mail-ee0-f44.google.com [74.125.83.44]) by theia.denx.de (Postfix) with ESMTPS id 2DD6928102 for ; Wed, 28 Dec 2011 20:01:59 +0100 (CET) Received: by eekc14 with SMTP id c14so13238363eek.3 for ; Wed, 28 Dec 2011 11:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=idLy4DTapq9d3dJ4t99Q4j7mUGjNWEJsc8eYhoxSRmI=; b=ujIstQi5quge9A5knmMRxFijn7NCgkbSptRbK2kuWya/2OQJxOBTMrd27MIo+Edevj c4/snbin2BiHrDvw9T20TV8cv7D9LsbCf4z4vSI+limdnwdKSYVpXX7XPA1Igd/Y3gAI 05Un+olhOpCb24ZkRpx6z7qdRAytrzZAewMmA= Received: by 10.213.35.12 with SMTP id n12mr9917237ebd.25.1325098919280; Wed, 28 Dec 2011 11:01:59 -0800 (PST) Received: from localhost.localdomain (a2038.upc-a.chello.nl. [62.163.2.38]) by mx.google.com with ESMTPS id u53sm75970680eeu.6.2011.12.28.11.01.57 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Dec 2011 11:01:58 -0800 (PST) From: Frans Meulenbroeks To: u-boot@lists.denx.de Date: Wed, 28 Dec 2011 20:01:53 +0100 Message-Id: <1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com> X-Mailer: git-send-email 1.7.8.1 X-Mailman-Approved-At: Wed, 28 Dec 2011 20:31:56 +0100 Subject: [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de If the config file cannot be opened currently one gets an error even though the build in names/sizes are probably ok. By setting the default values first and only exit if there is a read error and not when the config file can be opened the program will try the default settings. In order to detect that the config file open fails get_config returns -2 to signal this; all other errors return -1 Signed-off-by: Frans Meulenbroeks --- tools/env/fw_env.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 996682e..992835f 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1225,14 +1225,6 @@ static int parse_config () { struct stat st; -#if defined(CONFIG_FILE) - /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */ - if (get_config (CONFIG_FILE)) { - fprintf (stderr, - "Cannot parse config file: %s\n", strerror (errno)); - return -1; - } -#else strcpy (DEVNAME (0), DEVICE1_NAME); DEVOFFSET (0) = DEVICE1_OFFSET; ENVSIZE (0) = ENV1_SIZE; @@ -1261,6 +1253,14 @@ static int parse_config () #endif HaveRedundEnv = 1; #endif + +#if defined(CONFIG_FILE) + /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */ + if (get_config (CONFIG_FILE) == -1) { + fprintf (stderr, + "Cannot parse config file: %s\n", strerror (errno)); + return -1; + } #endif if (stat (DEVNAME (0), &st)) { fprintf (stderr, @@ -1288,7 +1288,7 @@ static int get_config (char *fname) fp = fopen (fname, "r"); if (fp == NULL) - return -1; + return -2; while (i < 2 && fgets (dump, sizeof (dump), fp)) { /* Skip incomplete conversions and comment strings */