From patchwork Mon Jan 2 13:59:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frans Meulenbroeks X-Patchwork-Id: 133843 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 42C5CB6F9A for ; Tue, 3 Jan 2012 00:59:37 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 59210282BB; Mon, 2 Jan 2012 14:59:31 +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 AGBR-X0VxAfx; Mon, 2 Jan 2012 14:59:31 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2A221282A0; Mon, 2 Jan 2012 14:59:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ADBEE282A0 for ; Mon, 2 Jan 2012 14:59:26 +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 46g4WknIKAav for ; Mon, 2 Jan 2012 14:59:26 +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 0A0872829E for ; Mon, 2 Jan 2012 14:59:24 +0100 (CET) Received: by eekc14 with SMTP id c14so16148097eek.3 for ; Mon, 02 Jan 2012 05:59:24 -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=0p68J8Os61ZgdjUn5AUDQRRb3IqU0szHfD3ATbrjtAI=; b=XORy5CkSBtUCkbGS832RBTf5WMJsRzK2bz/dudsg/+jfdmubc53BJLZQqtqFQMnY+E 9CjWh/6rXZFGWIpVEMue/hw21Wing5/LLyvYLq90+FYyAqPsfRv/F8MiZiwLjuv7RnVi bsLRdj17DL63Ekz+bzUW+w1bRzuyVO0vetepE= Received: by 10.14.29.14 with SMTP id h14mr19754660eea.70.1325512762547; Mon, 02 Jan 2012 05:59:22 -0800 (PST) Received: from localhost.localdomain (D4B26BC1.static.ziggozakelijk.nl. [212.178.107.193]) by mx.google.com with ESMTPS id y12sm190644216eeb.11.2012.01.02.05.59.19 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 02 Jan 2012 05:59:20 -0800 (PST) From: Frans Meulenbroeks To: u-boot@lists.denx.de Date: Mon, 2 Jan 2012 14:59:16 +0100 Message-Id: <1325512756-15706-1-git-send-email-fransmeulenbroeks@gmail.com> X-Mailer: git-send-email 1.7.0.4 Subject: [U-Boot] [PATCH] fw_env: use vars from the board config 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 it is quite odd that fw_printenv/fw_setenv does not use the settings from include/configs but instead redefines things. This patch uses the variables from the config file The edit in fw_env.c is only needed to resolve a name clash Signed-off-by: Frans Meulenbroeks --- Note: this is more intended to get some feedback. (also to see if I am on the right track) I did test the changes locally. (and yes, I know there are some more things that could be cleaned up). --- tools/env/fw_env.c | 20 ++++++++++---------- tools/env/fw_env.h | 36 ++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 996682e..6597fbf 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -79,7 +79,7 @@ static int dev_current; #define ENVSECTORS(i) envdevices[(i)].env_sectors #define DEVTYPE(i) envdevices[(i)].mtd_type -#define CONFIG_ENV_SIZE ENVSIZE(dev_current) +#define CFG_ENV_SIZE ENVSIZE(dev_current) #define ENV_SIZE getenvsize() @@ -216,7 +216,7 @@ static int get_config (char *); #endif static inline ulong getenvsize (void) { - ulong rc = CONFIG_ENV_SIZE - sizeof (long); + ulong rc = CFG_ENV_SIZE - sizeof (long); if (HaveRedundEnv) rc -= sizeof (char); @@ -425,7 +425,7 @@ int fw_env_write(char *name, char *value) ++env; /* * Overflow when: - * "name" + "=" + "val" +"\0\0" > CONFIG_ENV_SIZE - (env-environment) + * "name" + "=" + "val" +"\0\0" > CFG_ENV_SIZE - (env-environment) */ len = strlen (name) + 2; /* add '=' for first arg, ' ' for all others */ @@ -941,7 +941,7 @@ static int flash_write (int fd_current, int fd_target, int dev_target) DEVOFFSET (dev_target), DEVNAME (dev_target)); #endif rc = flash_write_buf (dev_target, fd_target, environment.image, - CONFIG_ENV_SIZE, DEVOFFSET (dev_target), + CFG_ENV_SIZE, DEVOFFSET (dev_target), DEVTYPE(dev_target)); if (rc < 0) return rc; @@ -980,10 +980,10 @@ static int flash_read (int fd) DEVTYPE(dev_current) = mtdinfo.type; - rc = flash_read_buf (dev_current, fd, environment.image, CONFIG_ENV_SIZE, + rc = flash_read_buf (dev_current, fd, environment.image, CFG_ENV_SIZE, DEVOFFSET (dev_current), mtdinfo.type); - return (rc != CONFIG_ENV_SIZE) ? -1 : 0; + return (rc != CFG_ENV_SIZE) ? -1 : 0; } static int flash_io (int mode) @@ -1080,11 +1080,11 @@ int fw_env_open(void) if (parse_config ()) /* should fill envdevices */ return -1; - addr0 = calloc (1, CONFIG_ENV_SIZE); + addr0 = calloc (1, CFG_ENV_SIZE); if (addr0 == NULL) { fprintf (stderr, "Not enough memory for environment (%ld bytes)\n", - CONFIG_ENV_SIZE); + CFG_ENV_SIZE); return -1; } @@ -1119,11 +1119,11 @@ int fw_env_open(void) flag0 = *environment.flags; dev_current = 1; - addr1 = calloc (1, CONFIG_ENV_SIZE); + addr1 = calloc (1, CFG_ENV_SIZE); if (addr1 == NULL) { fprintf (stderr, "Not enough memory for environment (%ld bytes)\n", - CONFIG_ENV_SIZE); + CFG_ENV_SIZE); return -1; } redundant = addr1; diff --git a/tools/env/fw_env.h b/tools/env/fw_env.h index 2dcb373..8fcc5bd 100644 --- a/tools/env/fw_env.h +++ b/tools/env/fw_env.h @@ -24,30 +24,26 @@ /* * To build the utility with the run-time configuration * uncomment the next line. - * See included "fw_env.config" sample file + * See included "fw_env.config" sample file (TRAB board) * for notes on configuration. */ -#define CONFIG_FILE "/etc/fw_env.config" +//#define CONFIG_FILE "/etc/fw_env.config" -#define HAVE_REDUND /* For systems with 2 env sectors */ -#define DEVICE1_NAME "/dev/mtd1" -#define DEVICE2_NAME "/dev/mtd2" -#define DEVICE1_OFFSET 0x0000 -#define ENV1_SIZE 0x4000 -#define DEVICE1_ESIZE 0x4000 -#define DEVICE1_ENVSECTORS 2 -#define DEVICE2_OFFSET 0x0000 -#define ENV2_SIZE 0x4000 -#define DEVICE2_ESIZE 0x4000 -#define DEVICE2_ENVSECTORS 2 +#include "config.h" -#define CONFIG_BAUDRATE 115200 -#define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */ -#define CONFIG_BOOTCOMMAND \ - "bootp; " \ - "setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \ - "ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \ - "bootm" +#define DEVICE1_NAME "/dev/mtd0" +#define DEVICE2_NAME "/dev/mtd0" +#define DEVICE1_OFFSET CONFIG_ENV_ADDR_REDUND +#define ENV1_SIZE CONFIG_ENV_SIZE +#define DEVICE1_ESIZE CONFIG_ENV_SECT_SIZE +#define DEVICE1_ENVSECTORS 1 +#ifdef CONFIG_ENV_ADDR_REDUND +#define HAVE_REDUND /* For systems with 2 env sectors */ +#define DEVICE2_OFFSET CONFIG_ENV_ADDR_REDUND +#define ENV2_SIZE CONFIG_ENV_SIZE_REDUND +#define DEVICE2_ESIZE CONFIG_ENV_SECT_SIZE +#define DEVICE2_ENVSECTORS 1 +#endif extern int fw_printenv(int argc, char *argv[]); extern char *fw_getenv (char *name);