Signed-off-by: Daniel Golle <[email protected]> --- package/boot/uboot-envtools/Config.in | 9 + package/boot/uboot-envtools/Makefile | 15 ++ .../300-support-env-in-ubivol-chardev.patch | 190 +++++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 package/boot/uboot-envtools/Config.in create mode 100644 package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch
diff --git a/package/boot/uboot-envtools/Config.in
b/package/boot/uboot-envtools/Config.in
new file mode 100644
index 0000000..9fd8103
--- /dev/null
+++ b/package/boot/uboot-envtools/Config.in
@@ -0,0 +1,9 @@
+config UBOOT_ENVTOOLS_UBI
+ bool "Support environment in UBI volume"
+ depends on PACKAGE_uboot-envtools
+ default n
+ help
+ Add support for reading and writing U-Boot environment
+ stored in UBI volume(s).
+
+ Increases binary size by about 8 kB
diff --git a/package/boot/uboot-envtools/Makefile
b/package/boot/uboot-envtools/Makefile
index 0f7c825..277c42b 100644
--- a/package/boot/uboot-envtools/Makefile
+++ b/package/boot/uboot-envtools/Makefile
@@ -21,6 +21,8 @@ PKG_MD5SUM:=6d2116d1385a66e9a59742caa9d62a54
PKG_BUILD_DIR:=$(BUILD_DIR)/u-boot-$(PKG_VERSION)
+PKG_BUILD_DEPENDS:=+fstools
+
include $(INCLUDE_DIR)/package.mk
define Package/uboot-envtools
@@ -34,15 +36,28 @@ define Package/uboot-envtools/description
This package includes tools to read and modify U-Boot bootloader environment.
endef
+define Package/uboot-envtools/config
+ source "$(SOURCE)/Config.in"
+endef
+
define Build/Configure
touch $(PKG_BUILD_DIR)/include/config.mk
touch $(PKG_BUILD_DIR)/include/config.h
endef
+TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include
+
+ifeq ($(CONFIG_UBOOT_ENVTOOLS_UBI),y)
+TARGET_LDFLAGS += -Wl,--gc-sections -L$(STAGING_DIR)/usr/lib/ -lubi-utils
+endif
+
+
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CROSS_COMPILE="$(TARGET_CROSS)" \
TARGET_CFLAGS="$(TARGET_CFLAGS)" \
+ TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
+ UBI="$(CONFIG_UBOOT_ENVTOOLS_UBI)" \
env
endef
diff --git
a/package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch
b/package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch
new file mode 100644
index 0000000..bebe8b2
--- /dev/null
+++
b/package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch
@@ -0,0 +1,190 @@
+From 5a9a602626be650ed171adb4d6ce4bff19823d01 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <[email protected]>
+Date: Mon, 19 May 2014 21:38:01 +0200
+Subject: [PATCH] tools/env: add support for env in ubi volume chardev
+
+Signed-off-by: Daniel Golle <[email protected]>
+---
+ tools/env/Makefile | 5 +++
+ tools/env/fw_env.c | 104 ++++++++++++++++++++++++++++++++++++++++++-----------
+ 2 files changed, 88 insertions(+), 21 deletions(-)
+
+diff --git a/tools/env/Makefile b/tools/env/Makefile
+index fcb752d..5bc5a77 100644
+--- a/tools/env/Makefile
++++ b/tools/env/Makefile
+@@ -20,6 +20,11 @@ ifeq ($(MTD_VERSION),old)
+ HOST_EXTRACFLAGS += -DMTD_OLD
+ endif
+
++ifeq ($(UBI),y)
++HOST_EXTRACFLAGS += -DUBI
++HOST_LOADLIBES = "-lubi-utils"
++endif
++
+ always := fw_printenv
+ hostprogs-y := fw_printenv_unstripped
+
+diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
+index d228cc3..82f1f48 100644
+--- a/tools/env/fw_env.c
++++ b/tools/env/fw_env.c
+@@ -29,6 +29,9 @@
+ # include <mtd/mtd-user.h>
+ #endif
+
++#ifdef UBI
++# include <libubi-tiny.h>
++#endif
+ #include "fw_env.h"
+
+ #define WHITESPACE(c) ((c == '\t') || (c == ' '))
+@@ -725,6 +728,9 @@ static int flash_write_buf (int dev, int fd, void *buf,
size_t count,
+ off_t top_of_range; /* end of the last block we may use */
+ loff_t blockstart; /* running start of the current block -
+ MEMGETBADBLOCK needs 64 bits */
++#ifdef UBI
++ libubi_t *libubi; /* pointer to libubi struct */
++#endif
+ int rc;
+
+ /*
+@@ -835,20 +841,51 @@ static int flash_write_buf (int dev, int fd, void *buf,
size_t count,
+ ioctl(fd, MEMUNLOCK, &erase);
+ /* These do not need an explicit erase cycle */
+ if (mtd_type != MTD_DATAFLASH)
+- if (ioctl(fd, MEMERASE, &erase) != 0) {
++ if (ioctl(fd, MEMERASE, &erase) != 0 &&
++ mtd_type != MTD_UBIVOLUME) {
+ fprintf(stderr,
+ "MTD erase error on %s: %s\n",
+ DEVNAME(dev), strerror(errno));
+ return -1;
+ }
++#ifdef UBI
++ if (mtd_type == MTD_UBIVOLUME) {
++ struct ubi_vol_info volinfo;
++ libubi = libubi_open();
++ if (libubi)
++ rc = ubi_get_vol_info(libubi,
++ DEVNAME(dev_current), &volinfo);
++ if (libubi && !rc) {
++ erasesize = volinfo.leb_size;
++ int leb = blockstart / erasesize;
++ if (volinfo.type != UBI_STATIC_VOLUME)
++ rc = ubi_leb_change_start(
++ libubi, fd, leb,
++ erasesize);
++ else
++ rc = ubi_update_start(
++ libubi, fd,
++ erasesize);
++ }
++ if (rc) {
++ if (libubi) libubi_close(libubi);
++ libubi = NULL;
++ }
++ }
++#endif
+ }
+
+- if (lseek (fd, blockstart, SEEK_SET) == -1) {
+- fprintf (stderr,
+- "Seek error on %s: %s\n",
+- DEVNAME (dev), strerror (errno));
+- return -1;
++#ifdef UBI
++ if (!libubi) {
++#endif
++ if (lseek (fd, blockstart, SEEK_SET) == -1) {
++ fprintf (stderr,
++ "Seek error on %s: %s\n",
++ DEVNAME (dev), strerror (errno));
++ }
++#ifdef UBI
+ }
++#endif
+
+ #ifdef DEBUG
+ fprintf(stderr, "Write 0x%x bytes at 0x%llx\n", erasesize,
+@@ -857,11 +894,15 @@ static int flash_write_buf (int dev, int fd, void *buf,
size_t count,
+ if (write (fd, data + processed, erasesize) != erasesize) {
+ fprintf (stderr, "Write error on %s: %s\n",
+ DEVNAME (dev), strerror (errno));
+- return -1;
++ processed = -1;
++ goto out;
+ }
+
+- if (mtd_type != MTD_ABSENT)
+- ioctl(fd, MEMLOCK, &erase);
++#ifdef UBI
++ if (!libubi)
++#endif
++ if (mtd_type != MTD_ABSENT)
++ ioctl(fd, MEMLOCK, &erase);
+
+ processed += erasesize;
+ block_seek = 0;
+@@ -871,6 +912,11 @@ static int flash_write_buf (int dev, int fd, void *buf,
size_t count,
+ if (write_total > count)
+ free (data);
+
++out:
++#ifdef UBI
++ if (libubi) libubi_close(libubi);
++#endif
++
+ return processed;
+ }
+
+@@ -959,18 +1005,34 @@ static int flash_read (int fd)
+
+ if (S_ISCHR(st.st_mode)) {
+ rc = ioctl(fd, MEMGETINFO, &mtdinfo);
+- if (rc < 0) {
+- fprintf(stderr, "Cannot get MTD information for %s\n",
+- DEVNAME(dev_current));
+- return -1;
+- }
+- if (mtdinfo.type != MTD_NORFLASH &&
+- mtdinfo.type != MTD_NANDFLASH &&
+- mtdinfo.type != MTD_DATAFLASH &&
+- mtdinfo.type != MTD_UBIVOLUME) {
+- fprintf (stderr, "Unsupported flash type %u on %s\n",
+- mtdinfo.type, DEVNAME(dev_current));
+- return -1;
++ if (rc == 0) {
++ if (mtdinfo.type != MTD_NORFLASH &&
++ mtdinfo.type != MTD_NANDFLASH &&
++ mtdinfo.type != MTD_DATAFLASH &&
++ mtdinfo.type != MTD_UBIVOLUME) {
++ fprintf (stderr, "Unsupported flash type %u on
%s\n",
++ mtdinfo.type, DEVNAME(dev_current));
++ return -1;
++ }
++#ifdef UBI
++ } else {
++ libubi_t *libubi;
++ struct ubi_vol_info volinfo;
++ libubi = libubi_open();
++ if (!libubi)
++ return -1;
++ rc = ubi_get_vol_info(libubi, DEVNAME(dev_current),
&volinfo);
++ if (rc)
++ return -1;
++ memset(&mtdinfo, 0, sizeof(mtdinfo));
++ mtdinfo.flags;
++ mtdinfo.type = MTD_UBIVOLUME;
++ mtdinfo.size = volinfo.data_bytes;
++ mtdinfo.erasesize = volinfo.leb_size;
++ mtdinfo.writesize = volinfo.leb_size;
++ mtdinfo.oobsize = 0;
++ libubi_close(libubi);
++#endif
+ }
+ } else {
+ memset(&mtdinfo, 0, sizeof(mtdinfo));
+--
+1.9.2
+
--
1.9.2
pgp4fxAxqjAIp.pgp
Description: PGP signature
_______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
