[packages] new package uboot-env-mmc: hacked in support for reading/writing an uboot environment from/to none-flash devices
Signed-off-by: Michael Heimpold <mhei@heimpold.de> git-svn-id: svn://svn.openwrt.org/openwrt/packages@35271 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
a076a7ed23
commit
220fb0aa58
42
utils/uboot-envtools-mmc/Makefile
Normal file
42
utils/uboot-envtools-mmc/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=uboot-envtools-mmc
|
||||
PKG_VERSION:=20081215
|
||||
PKG_RELEASE:=1.1
|
||||
|
||||
PKG_SOURCE:=uboot-envtools_$(PKG_VERSION).orig.tar.gz
|
||||
PKG_SOURCE_URL:=http://ftp.de.debian.org/debian/pool/main/u/uboot-envtools/
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
TAR_CMD=$(HOST_TAR) --strip-components 1 -C "$(PKG_BUILD_DIR)" $(TAR_OPTIONS)
|
||||
|
||||
TARGET_CFLAGS += -DCONFIG_ENV_IS_IN_MMC
|
||||
|
||||
define Package/uboot-envtools-mmc
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=read/modify U-Boot bootloader environment in MMC flash
|
||||
DEPENDS:= +zlib
|
||||
URL:=http://www.denx.de/wiki/U-Boot
|
||||
endef
|
||||
|
||||
define Package/uboot-envtools-mmc/description
|
||||
This package includes tools to read and modify U-Boot bootloader environment.
|
||||
This package is patched to to allow reading/writing to block devices.
|
||||
endef
|
||||
|
||||
define Package/uboot-envtools-mmc/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fw_printenv $(1)/usr/sbin/
|
||||
ln -sf fw_printenv $(1)/usr/sbin/fw_setenv
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,uboot-envtools-mmc))
|
125
utils/uboot-envtools-mmc/patches/001-crc32_func_signature.patch
Normal file
125
utils/uboot-envtools-mmc/patches/001-crc32_func_signature.patch
Normal file
@ -0,0 +1,125 @@
|
||||
--- a/crc32.c
|
||||
+++ b/crc32.c
|
||||
@@ -8,11 +8,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
-#ifndef USE_HOSTCC /* Shut down "ANSI does not permit..." warnings */
|
||||
-#include <common.h>
|
||||
-#else
|
||||
#include <stdint.h>
|
||||
-#endif
|
||||
|
||||
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
||||
#include <watchdog.h>
|
||||
@@ -136,7 +132,7 @@ local const uint32_t crc_table[256] = {
|
||||
|
||||
#if 0
|
||||
/* =========================================================================
|
||||
- * This function can be used by asm versions of crc32()
|
||||
+ * This function can be used by asm versions of uboot_crc32()
|
||||
*/
|
||||
const uint32_t * ZEXPORT get_crc_table()
|
||||
{
|
||||
@@ -154,7 +150,7 @@ const uint32_t * ZEXPORT get_crc_table()
|
||||
#define DO8(buf) DO4(buf); DO4(buf);
|
||||
|
||||
/* ========================================================================= */
|
||||
-uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *buf, uInt len)
|
||||
+uint32_t ZEXPORT uboot_crc32 (uint32_t crc, const Bytef *buf, uInt len)
|
||||
{
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
@@ -217,12 +213,12 @@ uint32_t ZEXPORT crc32_wd (uint32_t crc,
|
||||
chunk = end - curr;
|
||||
if (chunk > chunk_sz)
|
||||
chunk = chunk_sz;
|
||||
- crc = crc32 (crc, curr, chunk);
|
||||
+ crc = uboot_crc32 (crc, curr, chunk);
|
||||
curr += chunk;
|
||||
WATCHDOG_RESET ();
|
||||
}
|
||||
#else
|
||||
- crc = crc32 (crc, buf, len);
|
||||
+ crc = uboot_crc32 (crc, buf, len);
|
||||
#endif
|
||||
|
||||
return crc;
|
||||
--- a/fw_env.c
|
||||
+++ b/fw_env.c
|
||||
@@ -216,9 +216,9 @@ static int parse_config (void);
|
||||
#if defined(CONFIG_FILE)
|
||||
static int get_config (char *);
|
||||
#endif
|
||||
-static inline ulong getenvsize (void)
|
||||
+static inline uint32_t getenvsize (void)
|
||||
{
|
||||
- ulong rc = CONFIG_ENV_SIZE - sizeof (long);
|
||||
+ uint32_t rc = CONFIG_ENV_SIZE - sizeof (uint32_t);
|
||||
|
||||
if (HaveRedundEnv)
|
||||
rc -= sizeof (char);
|
||||
@@ -437,7 +437,7 @@ int fw_setenv (int argc, char *argv[])
|
||||
/*
|
||||
* Update CRC
|
||||
*/
|
||||
- *environment.crc = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
|
||||
+ *environment.crc = uboot_crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
|
||||
|
||||
/* write environment back to flash */
|
||||
if (flash_io (O_RDWR)) {
|
||||
@@ -627,7 +627,7 @@ static int flash_write_buf (int dev, int
|
||||
data = malloc (erase_len);
|
||||
if (!data) {
|
||||
fprintf (stderr,
|
||||
- "Cannot malloc %u bytes: %s\n",
|
||||
+ "Cannot malloc %zu bytes: %s\n",
|
||||
erase_len, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
@@ -883,11 +883,11 @@ static char *envmatch (char * s1, char *
|
||||
static int env_init (void)
|
||||
{
|
||||
int crc0, crc0_ok;
|
||||
- char flag0;
|
||||
+ unsigned char flag0;
|
||||
void *addr0;
|
||||
|
||||
int crc1, crc1_ok;
|
||||
- char flag1;
|
||||
+ unsigned char flag1;
|
||||
void *addr1;
|
||||
|
||||
struct env_image_single *single;
|
||||
@@ -923,7 +923,7 @@ static int env_init (void)
|
||||
if (flash_io (O_RDONLY))
|
||||
return -1;
|
||||
|
||||
- crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
|
||||
+ crc0 = uboot_crc32 (0, (uint8_t *) environment.data, ENV_SIZE);
|
||||
crc0_ok = (crc0 == *environment.crc);
|
||||
if (!HaveRedundEnv) {
|
||||
if (!crc0_ok) {
|
||||
@@ -964,7 +964,7 @@ static int env_init (void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
- crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE);
|
||||
+ crc1 = uboot_crc32 (0, (uint8_t *) redundant->data, ENV_SIZE);
|
||||
crc1_ok = (crc1 == redundant->crc);
|
||||
flag1 = redundant->flags;
|
||||
|
||||
--- a/fw_env.h
|
||||
+++ b/fw_env.h
|
||||
@@ -47,8 +47,10 @@
|
||||
"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \
|
||||
"bootm"
|
||||
|
||||
+# include <stdint.h>
|
||||
+
|
||||
extern int fw_printenv(int argc, char *argv[]);
|
||||
extern char *fw_getenv (char *name);
|
||||
extern int fw_setenv (int argc, char *argv[]);
|
||||
|
||||
-extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned);
|
||||
+extern uint32_t uboot_crc32 (uint32_t, const unsigned char *, unsigned);
|
36
utils/uboot-envtools-mmc/patches/002-makefile.patch
Normal file
36
utils/uboot-envtools-mmc/patches/002-makefile.patch
Normal file
@ -0,0 +1,36 @@
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -21,12 +21,10 @@
|
||||
# MA 02111-1307 USA
|
||||
#
|
||||
|
||||
-include $(TOPDIR)/config.mk
|
||||
-
|
||||
SRCS := $(obj)crc32.c fw_env.c fw_env_main.c
|
||||
HEADERS := fw_env.h
|
||||
|
||||
-CPPFLAGS := -Wall -DUSE_HOSTCC -I$(SRCTREE)/include
|
||||
+CPPFLAGS := -Wall $(CFLAGS)
|
||||
|
||||
ifeq ($(MTD_VERSION),old)
|
||||
CPPFLAGS += -DMTD_OLD
|
||||
@@ -35,18 +33,7 @@ endif
|
||||
all: $(obj)fw_printenv
|
||||
|
||||
$(obj)fw_printenv: $(SRCS) $(HEADERS)
|
||||
- $(CROSS_COMPILE)gcc $(CPPFLAGS) $(SRCS) -o $(obj)fw_printenv
|
||||
+ $(CC) $(CPPFLAGS) $(SRCS) -o $(obj)fw_printenv
|
||||
|
||||
clean:
|
||||
rm -f $(obj)fw_printenv $(obj)crc32.c
|
||||
-
|
||||
-$(obj)crc32.c:
|
||||
- ln -s $(src)../../lib_generic/crc32.c $(obj)crc32.c
|
||||
-
|
||||
-#########################################################################
|
||||
-
|
||||
-include $(TOPDIR)/rules.mk
|
||||
-
|
||||
-sinclude $(obj).depend
|
||||
-
|
||||
-#########################################################################
|
14
utils/uboot-envtools-mmc/patches/003-nor-eraselen.patch
Normal file
14
utils/uboot-envtools-mmc/patches/003-nor-eraselen.patch
Normal file
@ -0,0 +1,14 @@
|
||||
--- a/fw_env.c
|
||||
+++ b/fw_env.c
|
||||
@@ -605,7 +605,10 @@ static int flash_write_buf (int dev, int
|
||||
erase_offset = offset & ~(blocklen - 1);
|
||||
|
||||
/* Maximum area we may use */
|
||||
- erase_len = top_of_range - erase_offset;
|
||||
+ if (mtd_type == MTD_NANDFLASH)
|
||||
+ erase_len = top_of_range - erase_offset;
|
||||
+ else
|
||||
+ erase_len = blocklen;
|
||||
|
||||
blockstart = erase_offset;
|
||||
/* Offset inside a block */
|
17
utils/uboot-envtools-mmc/patches/005-no-restrictions.patch
Normal file
17
utils/uboot-envtools-mmc/patches/005-no-restrictions.patch
Normal file
@ -0,0 +1,17 @@
|
||||
--- a/fw_env.c
|
||||
+++ b/fw_env.c
|
||||
@@ -375,12 +375,14 @@ int fw_setenv (int argc, char *argv[])
|
||||
/*
|
||||
* Ethernet Address and serial# can be set only once
|
||||
*/
|
||||
+#if 0
|
||||
if ((strcmp (name, "ethaddr") == 0) ||
|
||||
(strcmp (name, "serial#") == 0)) {
|
||||
fprintf (stderr, "Can't overwrite \"%s\"\n", name);
|
||||
errno = EROFS;
|
||||
return -1;
|
||||
}
|
||||
+#endif
|
||||
|
||||
if (*++nxt == '\0') {
|
||||
*env = '\0';
|
61
utils/uboot-envtools-mmc/patches/006-mmc-hack.patch
Normal file
61
utils/uboot-envtools-mmc/patches/006-mmc-hack.patch
Normal file
@ -0,0 +1,61 @@
|
||||
From e0c083da93fcf570f46bc74daaf72e7e7a1526a8 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Heimpold <mhei@heimpold.de>
|
||||
Date: Wed, 28 Sep 2011 23:29:12 +0200
|
||||
Subject: [PATCH] Hack to allow reading and storing env on MMC
|
||||
|
||||
---
|
||||
fw_env.c | 12 ++++++++++--
|
||||
1 files changed, 10 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/fw_env.c
|
||||
+++ b/fw_env.c
|
||||
@@ -681,6 +681,7 @@ static int flash_write_buf (int dev, int
|
||||
}
|
||||
|
||||
erase.start = blockstart;
|
||||
+#ifndef CONFIG_ENV_IS_IN_MMC
|
||||
ioctl (fd, MEMUNLOCK, &erase);
|
||||
|
||||
if (ioctl (fd, MEMERASE, &erase) != 0) {
|
||||
@@ -689,6 +690,7 @@ static int flash_write_buf (int dev, int
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
+#endif
|
||||
|
||||
if (lseek (fd, blockstart, SEEK_SET) == -1) {
|
||||
fprintf (stderr,
|
||||
@@ -706,8 +708,9 @@ static int flash_write_buf (int dev, int
|
||||
return -1;
|
||||
}
|
||||
|
||||
+#ifndef CONFIG_ENV_IS_IN_MMC
|
||||
ioctl (fd, MEMLOCK, &erase);
|
||||
-
|
||||
+#endif
|
||||
processed += blocklen;
|
||||
block_seek = 0;
|
||||
blockstart += blocklen;
|
||||
@@ -785,9 +788,10 @@ static int flash_write (int fd_current,
|
||||
|
||||
static int flash_read (int fd)
|
||||
{
|
||||
- struct mtd_info_user mtdinfo;
|
||||
int rc;
|
||||
|
||||
+#ifndef CONFIG_ENV_IS_IN_MMC
|
||||
+ struct mtd_info_user mtdinfo;
|
||||
rc = ioctl (fd, MEMGETINFO, &mtdinfo);
|
||||
if (rc < 0) {
|
||||
perror ("Cannot get MTD information");
|
||||
@@ -803,6 +807,10 @@ static int flash_read (int fd)
|
||||
|
||||
rc = flash_read_buf (dev_current, fd, environment.image, CONFIG_ENV_SIZE,
|
||||
DEVOFFSET (dev_current), mtdinfo.type);
|
||||
+#else
|
||||
+ rc = flash_read_buf (dev_current, fd, environment.image, CONFIG_ENV_SIZE,
|
||||
+ DEVOFFSET (dev_current), 0);
|
||||
+#endif
|
||||
|
||||
return (rc != CONFIG_ENV_SIZE) ? -1 : 0;
|
||||
}
|
36
utils/uboot-envtools-mmc/patches/007-fsync.patch
Normal file
36
utils/uboot-envtools-mmc/patches/007-fsync.patch
Normal file
@ -0,0 +1,36 @@
|
||||
From 9ef3d800d08dd673ccb5b7a12a69e94394cf2167 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Heimpold <mhei@heimpold.de>
|
||||
Date: Sat, 11 Aug 2012 21:33:46 +0200
|
||||
Subject: [PATCH] Ensure that data is written to disk
|
||||
|
||||
---
|
||||
fw_env.c | 12 ++++++++++++
|
||||
1 files changed, 12 insertions(+), 0 deletions(-)
|
||||
|
||||
diff --git a/fw_env.c b/fw_env.c
|
||||
index bed8fae..ee15f33 100644
|
||||
--- a/fw_env.c
|
||||
+++ b/fw_env.c
|
||||
@@ -849,7 +849,19 @@ static int flash_io (int mode)
|
||||
|
||||
rc = flash_write (fd_current, fd_target, dev_target);
|
||||
|
||||
+ if (fsync (fd_current)) {
|
||||
+ fprintf (stderr,
|
||||
+ "fsync failed on %s: %s\n",
|
||||
+ DEVNAME (dev_current), strerror (errno));
|
||||
+ }
|
||||
+
|
||||
if (HaveRedundEnv) {
|
||||
+ if (fsync (fd_target)) {
|
||||
+ fprintf (stderr,
|
||||
+ "fsync failed on %s: %s\n",
|
||||
+ DEVNAME (dev_current), strerror (errno));
|
||||
+ }
|
||||
+
|
||||
if (close (fd_target)) {
|
||||
fprintf (stderr,
|
||||
"I/O error on %s: %s\n",
|
||||
--
|
||||
1.7.2.5
|
||||
|
Loading…
x
Reference in New Issue
Block a user