From patchwork Fri Aug 17 20:49:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 178373 X-Patchwork-Delegate: trini@ti.com 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 6DEC02C00C5 for ; Sat, 18 Aug 2012 06:50:43 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F405288FB; Fri, 17 Aug 2012 22:50:32 +0200 (CEST) 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 cVbml8XVhXWw; Fri, 17 Aug 2012 22:50:32 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D7772883B; Fri, 17 Aug 2012 22:50:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DBE472880C for ; Fri, 17 Aug 2012 22:50:01 +0200 (CEST) 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 x30ejPGlpDxD for ; Fri, 17 Aug 2012 22:50:01 +0200 (CEST) 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 spamkiller05.natinst.com (mailserver5.natinst.com [130.164.80.5]) by theia.denx.de (Postfix) with ESMTP id 3585B2880E for ; Fri, 17 Aug 2012 22:49:57 +0200 (CEST) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller05.natinst.com (8.14.4/8.14.4) with ESMTP id q7HKntfj009153; Fri, 17 Aug 2012 15:49:55 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012081715495544-1270330 ; Fri, 17 Aug 2012 15:49:55 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Fri, 17 Aug 2012 15:49:35 -0500 Message-Id: <1345236586-19076-2-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1345236586-19076-1-git-send-email-joe.hershberger@ni.com> References: <20100622222932.DCDB71524EE@gemini.denx.de> <1345236586-19076-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 08/17/2012 03:49:55 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 08/17/2012 03:49:55 PM, Serialize complete at 08/17/2012 03:49:55 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855, 1.0.260, 0.0.0000 definitions=2012-08-17_03:2012-08-17, 2012-08-17, 1970-01-01 signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH 01/12] tools/env: Use a board-specific default env 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 Originally added in aa701b94336b358798d676eef12a7b90bdac23f5 Before this patch, there was a hard-coded env that was used as default if the env in flash is detected as invalid. Now this tool (compiled for a given board) will share the default env with the u-boot for the board. Fix include of config.h Need to define "TEXT_BASE" when building the fw_env tool so that the default env will be correct for environments which use it. Define __ASSEMBLY__ when calling #include so that we only get #defines (all we're interested in). Signed-off-by: Joe Hershberger --- tools/env/Makefile | 5 +++-- tools/env/fw_env.c | 28 +++++++++++++--------------- tools/env/fw_env.h | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/tools/env/Makefile b/tools/env/Makefile index 07634bc..ab73c8c 100644 --- a/tools/env/Makefile +++ b/tools/env/Makefile @@ -24,13 +24,14 @@ include $(TOPDIR)/config.mk HOSTSRCS := $(SRCTREE)/lib/crc32.c fw_env.c fw_env_main.c -HEADERS := fw_env.h +HEADERS := fw_env.h $(OBJTREE)/include/config.h # Compile for a hosted environment on the target HOSTCPPFLAGS = -idirafter $(SRCTREE)/include \ -idirafter $(OBJTREE)/include2 \ -idirafter $(OBJTREE)/include \ - -DUSE_HOSTCC + -DUSE_HOSTCC \ + -DTEXT_BASE=$(TEXT_BASE) ifeq ($(MTD_VERSION),old) HOSTCPPFLAGS += -DMTD_OLD diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index e292d2b..e46791d 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -45,8 +45,6 @@ #include "fw_env.h" -#include - #define WHITESPACE(c) ((c == '\t') || (c == ' ')) #define min(x, y) ({ \ @@ -81,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 CUR_ENVSIZE ENVSIZE(dev_current) #define ENV_SIZE getenvsize() @@ -218,7 +216,7 @@ static int get_config (char *); #endif static inline ulong getenvsize (void) { - ulong rc = CONFIG_ENV_SIZE - sizeof (long); + ulong rc = CUR_ENVSIZE - sizeof(long); if (HaveRedundEnv) rc -= sizeof (char); @@ -434,7 +432,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" > CUR_ENVSIZE - (env-environment) */ len = strlen (name) + 2; /* add '=' for first arg, ' ' for all others */ @@ -949,8 +947,8 @@ static int flash_write (int fd_current, int fd_target, int dev_target) printf ("Writing new environment at 0x%lx on %s\n", DEVOFFSET (dev_target), DEVNAME (dev_target)); #endif - rc = flash_write_buf (dev_target, fd_target, environment.image, - CONFIG_ENV_SIZE, DEVOFFSET (dev_target), + rc = flash_write_buf(dev_target, fd_target, environment.image, + CUR_ENVSIZE, DEVOFFSET(dev_target), DEVTYPE(dev_target)); if (rc < 0) return rc; @@ -989,10 +987,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, CUR_ENVSIZE, DEVOFFSET (dev_current), mtdinfo.type); - return (rc != CONFIG_ENV_SIZE) ? -1 : 0; + return (rc != CUR_ENVSIZE) ? -1 : 0; } static int flash_io (int mode) @@ -1089,11 +1087,11 @@ int fw_env_open(void) if (parse_config ()) /* should fill envdevices */ return -1; - addr0 = calloc (1, CONFIG_ENV_SIZE); + addr0 = calloc(1, CUR_ENVSIZE); if (addr0 == NULL) { - fprintf (stderr, + fprintf(stderr, "Not enough memory for environment (%ld bytes)\n", - CONFIG_ENV_SIZE); + CUR_ENVSIZE); return -1; } @@ -1128,11 +1126,11 @@ int fw_env_open(void) flag0 = *environment.flags; dev_current = 1; - addr1 = calloc (1, CONFIG_ENV_SIZE); + addr1 = calloc(1, CUR_ENVSIZE); if (addr1 == NULL) { - fprintf (stderr, + fprintf(stderr, "Not enough memory for environment (%ld bytes)\n", - CONFIG_ENV_SIZE); + CUR_ENVSIZE); return -1; } redundant = addr1; diff --git a/tools/env/fw_env.h b/tools/env/fw_env.h index ad32446..a1a6807 100644 --- a/tools/env/fw_env.h +++ b/tools/env/fw_env.h @@ -21,6 +21,15 @@ * MA 02111-1307 USA */ +/* Pull in the current config to define the default environment */ +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ /* get only #defines from config.h */ +#include +#undef __ASSEMBLY__ +#else +#include +#endif + /* * To build the utility with the static configuration * comment out the next line. @@ -29,6 +38,7 @@ */ #define CONFIG_FILE "/etc/fw_env.config" +#ifndef CONFIG_FILE #define HAVE_REDUND /* For systems with 2 env sectors */ #define DEVICE1_NAME "/dev/mtd1" #define DEVICE2_NAME "/dev/mtd2" @@ -40,14 +50,23 @@ #define ENV2_SIZE 0x4000 #define DEVICE2_ESIZE 0x4000 #define DEVICE2_ENVSECTORS 2 +#endif +#ifndef CONFIG_BAUDRATE #define CONFIG_BAUDRATE 115200 +#endif + +#ifndef CONFIG_BOOTDELAY #define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */ +#endif + +#ifndef CONFIG_BOOTCOMMAND #define CONFIG_BOOTCOMMAND \ "bootp; " \ "setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \ "ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \ "bootm" +#endif extern int fw_printenv(int argc, char *argv[]); extern char *fw_getenv (char *name);