From 23869bf80b68af9ef1802b9e556f4fd0e9e57fe5 Mon Sep 17 00:00:00 2001 From: Dustin Byford Date: Thu, 6 Mar 2014 20:48:22 -0800 Subject: fw_env: calculate default number of env sectors The assumed number of environment sectors (always 1) leads to an incorrect top_of_range calculation in fw.env.c when a flash device has an erase block size smaller than the environment data size (number of environment sectors > 1). This change updates the default number of environment sectors to at least cover the size of the environment. Also corrected a false statement about the number of sectors column in fw_env.config. Signed-off-by: Dustin Byford --- tools/env/fw_env.c | 14 ++++++++------ tools/env/fw_env.config | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 577ce2de472..649db0493a9 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1246,9 +1246,10 @@ static int parse_config () strcpy (DEVNAME (0), DEVICE1_NAME); DEVOFFSET (0) = DEVICE1_OFFSET; ENVSIZE (0) = ENV1_SIZE; - /* Default values are: erase-size=env-size, #sectors=1 */ + /* Default values are: erase-size=env-size */ DEVESIZE (0) = ENVSIZE (0); - ENVSECTORS (0) = 1; + /* #sectors=env-size/erase-size (rounded up) */ + ENVSECTORS (0) = (ENVSIZE(0) + DEVESIZE(0) - 1) / DEVESIZE(0); #ifdef DEVICE1_ESIZE DEVESIZE (0) = DEVICE1_ESIZE; #endif @@ -1260,9 +1261,10 @@ static int parse_config () strcpy (DEVNAME (1), DEVICE2_NAME); DEVOFFSET (1) = DEVICE2_OFFSET; ENVSIZE (1) = ENV2_SIZE; - /* Default values are: erase-size=env-size, #sectors=1 */ + /* Default values are: erase-size=env-size */ DEVESIZE (1) = ENVSIZE (1); - ENVSECTORS (1) = 1; + /* #sectors=env-size/erase-size (rounded up) */ + ENVSECTORS (1) = (ENVSIZE(1) + DEVESIZE(1) - 1) / DEVESIZE(1); #ifdef DEVICE2_ESIZE DEVESIZE (1) = DEVICE2_ESIZE; #endif @@ -1320,8 +1322,8 @@ static int get_config (char *fname) DEVESIZE(i) = ENVSIZE(i); if (rc < 5) - /* Default - 1 sector */ - ENVSECTORS (i) = 1; + /* Assume enough env sectors to cover the environment */ + ENVSECTORS (i) = (ENVSIZE(i) + DEVESIZE(i) - 1) / DEVESIZE(i); i++; } diff --git a/tools/env/fw_env.config b/tools/env/fw_env.config index 90e499da1e0..c9b9f6a1609 100644 --- a/tools/env/fw_env.config +++ b/tools/env/fw_env.config @@ -1,7 +1,7 @@ # Configuration file for fw_(printenv/setenv) utility. # Up to two entries are valid, in this case the redundant # environment sector is assumed present. -# Notice, that the "Number of sectors" is ignored on NOR and SPI-dataflash. +# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash. # Futhermore, if the Flash sector size is ommitted, this value is assumed to # be the same as the Environment size, which is valid for NOR and SPI-dataflash -- cgit v1.2.3 From 4b774ff114201175ea9c05dfa12eef3ff1704753 Mon Sep 17 00:00:00 2001 From: Dustin Byford Date: Thu, 6 Mar 2014 20:48:23 -0800 Subject: fw_env: correct writes to devices with small erase blocks Some NOR flash devices have a small erase block size. For example, the Micron N25Q512 can erase in 4K blocks. These devices expose a bug in fw_env.c where flash_write_buf() incorrectly calculates bytes written and attempts to write past the environment sectors. Luckily, a range check prevents any real damage, but this does cause fw_setenv to fail with an error. This change corrects the write length calculation. The bug was introduced with commit 56086921 from 2008 and only affects configurations where the erase block size is smaller than the total environment data size. Signed-off-by: Dustin Byford --- tools/env/fw_env.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 649db0493a9..d228cc34da8 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -863,9 +863,9 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, if (mtd_type != MTD_ABSENT) ioctl(fd, MEMLOCK, &erase); - processed += blocklen; + processed += erasesize; block_seek = 0; - blockstart += blocklen; + blockstart += erasesize; } if (write_total > count) -- cgit v1.2.3 From 01286329b27b27eaeda045b469d41b1d9fce545a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 11 Mar 2014 11:05:20 +0900 Subject: kbuild: rename SRCTREE to srctree Prior to Kbuild, $(TOPDIR) or $(SRCTREE) was used for pointing to the top of source directory. (No difference between the two.) In Kbuild style, $(srctree) is used for instead. This commit renames SRCTREE to srctree and deletes the defition of SRCTREE. Note that SRCTREE in scripts/kernel-doc, scripts/docproc.c, doc/DocBook/Makefile should be keep. Signed-off-by: Masahiro Yamada --- tools/Makefile | 6 +++--- tools/env/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/Makefile b/tools/Makefile index bac6aafc80b..097cc1df178 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -172,10 +172,10 @@ endif # !LOGO_BMP # Define __KERNEL_STRICT_NAMES to prevent typedef overlaps # Define _GNU_SOURCE to obtain the getline prototype from stdio.h # -HOST_EXTRACFLAGS += -include $(SRCTREE)/include/libfdt_env.h \ +HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \ $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ - -I$(SRCTREE)/lib/libfdt \ - -I$(SRCTREE)/tools \ + -I$(srctree)/lib/libfdt \ + -I$(srctree)/tools \ -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \ -DUSE_HOSTCC \ -D__KERNEL_STRICT_NAMES \ diff --git a/tools/env/Makefile b/tools/env/Makefile index 6ad81fdb330..fcb752ddb44 100644 --- a/tools/env/Makefile +++ b/tools/env/Makefile @@ -12,7 +12,7 @@ HOSTCC = $(CC) # Compile for a hosted environment on the target HOST_EXTRACFLAGS = $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \ - -idirafter $(SRCTREE)/tools/env \ + -idirafter $(srctree)/tools/env \ -DUSE_HOSTCC \ -DTEXT_BASE=$(TEXT_BASE) -- cgit v1.2.3