From 716ca530e1c4515d8683c9d5be3d56b301758b66 Mon Sep 17 00:00:00 2001 From: James <> Date: Wed, 4 Nov 2015 11:49:21 +0000 Subject: trunk-47381 --- package/boot/uboot-envtools/Config.in | 9 ++ package/boot/uboot-envtools/Makefile | 112 ++++++++++++++ package/boot/uboot-envtools/files/ar71xx | 55 +++++++ package/boot/uboot-envtools/files/cns3xxx | 28 ++++ package/boot/uboot-envtools/files/imx6 | 36 +++++ package/boot/uboot-envtools/files/kirkwood | 33 +++++ package/boot/uboot-envtools/files/lantiq | 31 ++++ package/boot/uboot-envtools/files/mvebu | 28 ++++ package/boot/uboot-envtools/files/mxs | 26 ++++ package/boot/uboot-envtools/files/oxnas | 27 ++++ package/boot/uboot-envtools/files/ramips | 33 +++++ .../boot/uboot-envtools/files/uboot-envtools.sh | 36 +++++ .../boot/uboot-envtools/patches/001-compile.patch | 13 ++ .../uboot-envtools/patches/200-fw_env_no_aes.patch | 38 +++++ .../300-support-env-in-ubivol-chardev.patch | 163 +++++++++++++++++++++ 15 files changed, 668 insertions(+) create mode 100644 package/boot/uboot-envtools/Config.in create mode 100644 package/boot/uboot-envtools/Makefile create mode 100644 package/boot/uboot-envtools/files/ar71xx create mode 100644 package/boot/uboot-envtools/files/cns3xxx create mode 100644 package/boot/uboot-envtools/files/imx6 create mode 100644 package/boot/uboot-envtools/files/kirkwood create mode 100644 package/boot/uboot-envtools/files/lantiq create mode 100644 package/boot/uboot-envtools/files/mvebu create mode 100644 package/boot/uboot-envtools/files/mxs create mode 100644 package/boot/uboot-envtools/files/oxnas create mode 100644 package/boot/uboot-envtools/files/ramips create mode 100644 package/boot/uboot-envtools/files/uboot-envtools.sh create mode 100644 package/boot/uboot-envtools/patches/001-compile.patch create mode 100644 package/boot/uboot-envtools/patches/200-fw_env_no_aes.patch create mode 100644 package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch (limited to 'package/boot/uboot-envtools') diff --git a/package/boot/uboot-envtools/Config.in b/package/boot/uboot-envtools/Config.in new file mode 100644 index 0000000..8f0078f --- /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 TARGET_oxnas + 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 new file mode 100644 index 0000000..54db0dd --- /dev/null +++ b/package/boot/uboot-envtools/Makefile @@ -0,0 +1,112 @@ +# +# Copyright (C) 2006-2014 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 +PKG_DISTNAME:=u-boot +PKG_VERSION:=2015.10 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/u-boot-$(PKG_VERSION) +PKG_SOURCE:=$(PKG_DISTNAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=\ + http://mirror2.openwrt.org/sources \ + ftp://ftp.denx.de/pub/u-boot +PKG_MD5SUM:=7c203b0fc3390a122d8e8b75f147eac5 + +PKG_BUILD_DEPENDS:=+fstools + +PKG_LICENSE:=GPL-2.0 GPL-2.0+ +PKG_LICENSE_FILES:=Licenses/README + +PKG_BUILD_PARALLEL:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/uboot-envtools + SECTION:=utils + CATEGORY:=Utilities + TITLE:=read/modify U-Boot bootloader environment + URL:=http://www.denx.de/wiki/U-Boot +endef + +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 + mkdir $(PKG_BUILD_DIR)/include/generated + touch $(PKG_BUILD_DIR)/include/generated/autoconf.h +endef + +TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + CROSS_COMPILE="$(TARGET_CROSS)" \ + TARGET_CFLAGS="$(TARGET_CFLAGS)" \ + UBI="$(CONFIG_UBOOT_ENVTOOLS_UBI)" \ + env +endef + +define Package/uboot-envtools/conffiles +/etc/config/ubootenv +/etc/fw_env.config +endef + +define Package/uboot-envtools/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/tools/env/fw_printenv $(1)/usr/sbin + $(LN) fw_printenv $(1)/usr/sbin/fw_setenv + $(INSTALL_DIR) $(1)/lib + $(INSTALL_DATA) ./files/uboot-envtools.sh $(1)/lib +ifneq ($(CONFIG_TARGET_ar71xx),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/ar71xx $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_cns3xxx),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/cns3xxx $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_imx6),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/imx6 $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_kirkwood),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/kirkwood $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_lantiq),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/lantiq $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_mvebu),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/mvebu $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_mxs),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/mxs $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_oxnas),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/oxnas $(1)/etc/uci-defaults/30_uboot-envtools +endif +ifneq ($(CONFIG_TARGET_ramips),) + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_DATA) ./files/ramips $(1)/etc/uci-defaults/30_uboot-envtools +endif +endef + +$(eval $(call BuildPackage,uboot-envtools)) diff --git a/package/boot/uboot-envtools/files/ar71xx b/package/boot/uboot-envtools/files/ar71xx new file mode 100644 index 0000000..0c81f32 --- /dev/null +++ b/package/boot/uboot-envtools/files/ar71xx @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Copyright (C) 2011-2014 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/ar71xx.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(ar71xx_board_name) + +case "$board" in +all0258n | \ +cap4200ag | \ +carambola2 | \ +eap300v2 | \ +hornet-ub | \ +hornet-ub-x2 | \ +mr1750 | \ +mr600 | \ +mr600v2 | \ +mr900 | \ +mr900v2 | \ +nbg6716 | \ +om5p-an | \ +om5p | \ +tube2h | \ +wndr3700) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" + ;; +alfa-ap96 | \ +all0315n | \ +om2p | \ +om2pv2 | \ +om2p-hs | \ +om2p-hsv2 | \ +om2p-lc) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000" + ;; +wzr-hp-ag300h) + ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000" + ;; +qihoo-c301) + ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x10000" "0x10000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/cns3xxx b/package/boot/uboot-envtools/files/cns3xxx new file mode 100644 index 0000000..a56be15 --- /dev/null +++ b/package/boot/uboot-envtools/files/cns3xxx @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Copyright (C) 2013 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/cns3xxx.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(cns3xxx_board_name) + +case "$board" in +laguna) + # Laguna uboot env size/erasesize vary depending on NOR vs SPI FLASH + size=$(grep mtd1 /proc/mtd | awk '{print $2}') + erasesize=$(grep mtd1 /proc/mtd | awk '{print $3}') + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x$size" "0x$erasesize" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/imx6 b/package/boot/uboot-envtools/files/imx6 new file mode 100644 index 0000000..d7412b2 --- /dev/null +++ b/package/boot/uboot-envtools/files/imx6 @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Copyright (C) 2013-2014 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/imx6.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(imx6_board_name) + +case "$board" in +*gw5*) + if [ -c /dev/mtd1 ]; then + # board boots from NAND + ubootenv_add_uci_config /dev/mtd1 0x0 0x20000 0x40000 + ubootenv_add_uci_config /dev/mtd1 0x80000 0x20000 0x40000 + else + # board boots from microSD + ubootenv_add_uci_config /dev/mmcblk0 0xb1400 0x20000 0x20000 + ubootenv_add_uci_config /dev/mmcblk0 0xd1400 0x20000 0x20000 + fi + ;; +"wandboard") + ubootenv_add_uci_config "/dev/mmcblk0" "0x60000" "0x2000" "0x2000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/kirkwood b/package/boot/uboot-envtools/files/kirkwood new file mode 100644 index 0000000..98f85da --- /dev/null +++ b/package/boot/uboot-envtools/files/kirkwood @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright (C) 2012-2014 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/kirkwood.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(kirkwood_board_name) + +case "$board" in +"ea3500") + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x20000" + ;; +"ea4500" | \ +"guruplug-server-plus" | \ +"ib62x0" | \ +"pogo_e02" | \ +"sheevaplug" | \ +"sheevaplug-esata" ) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/lantiq b/package/boot/uboot-envtools/files/lantiq new file mode 100644 index 0000000..b152061 --- /dev/null +++ b/package/boot/uboot-envtools/files/lantiq @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Copyright (C) 2012 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/functions/lantiq.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(lantiq_board_name) + +case "$board" in +GIGASX76X) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1" + ;; +BTHOMEHUBV2B) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1" + ;; +P2812HNUF1) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x2000" "0x20000" "1" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/mvebu b/package/boot/uboot-envtools/files/mvebu new file mode 100644 index 0000000..2362bc3 --- /dev/null +++ b/package/boot/uboot-envtools/files/mvebu @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Copyright (C) 2014-2015 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/mvebu.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(mvebu_board_name) + +case "$board" in +armada-385-linksys-caiman|armada-385-linksys-cobra|armada-385-linksys-shelby) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x40000" + ;; +armada-xp-linksys-mamba) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/mxs b/package/boot/uboot-envtools/files/mxs new file mode 100644 index 0000000..ab8b4ef --- /dev/null +++ b/package/boot/uboot-envtools/files/mxs @@ -0,0 +1,26 @@ +#!/bin/sh +# +# Copyright (C) 2013 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/mxs.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(mxs_board_name) + +case "$board" in +duckbill) + ubootenv_add_uci_config "/dev/mmcblk0" "0x20000" "0x20000" + ubootenv_add_uci_config "/dev/mmcblk0" "0x40000" "0x20000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/oxnas b/package/boot/uboot-envtools/files/oxnas new file mode 100644 index 0000000..063ffa0 --- /dev/null +++ b/package/boot/uboot-envtools/files/oxnas @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright (C) 2013 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/oxnas.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(oxnas_board_name) + +case "$board" in +stg212 | \ +kd20) + ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x4000" "0x1F000" "1" + ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x4000" "0x1F000" "1" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips new file mode 100644 index 0000000..4640f43 --- /dev/null +++ b/package/boot/uboot-envtools/files/ramips @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright (C) 2011-2012 OpenWrt.org +# + +[ -e /etc/config/ubootenv ] && exit 0 + +touch /etc/config/ubootenv + +. /lib/ramips.sh +. /lib/uboot-envtools.sh +. /lib/functions.sh + +board=$(ramips_board_name) + +case "$board" in +all0239-3g | \ +all0256n | \ +all5002) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" + ;; +linkits7688 | \ +wsr-600 | \ +wsr-1166 | \ +br6425) + ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000" + ;; +esac + +config_load ubootenv +config_foreach ubootenv_add_app_config ubootenv + +exit 0 diff --git a/package/boot/uboot-envtools/files/uboot-envtools.sh b/package/boot/uboot-envtools/files/uboot-envtools.sh new file mode 100644 index 0000000..e21b283 --- /dev/null +++ b/package/boot/uboot-envtools/files/uboot-envtools.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Copyright (C) 2011-2012 OpenWrt.org +# + +ubootenv_add_uci_config() { + local dev=$1 + local offset=$2 + local envsize=$3 + local secsize=$4 + local numsec=$5 + uci batch <>/etc/fw_env.config +} + diff --git a/package/boot/uboot-envtools/patches/001-compile.patch b/package/boot/uboot-envtools/patches/001-compile.patch new file mode 100644 index 0000000..1705979 --- /dev/null +++ b/package/boot/uboot-envtools/patches/001-compile.patch @@ -0,0 +1,13 @@ +--- a/tools/env/Makefile ++++ b/tools/env/Makefile +@@ -10,6 +10,10 @@ + # with "CC" here for the maximum code reuse of scripts/Makefile.host. + HOSTCC = $(CC) + ++ifneq ($(TARGET_CFLAGS),) ++HOSTCFLAGS = $(TARGET_CFLAGS) ++endif ++ + # Compile for a hosted environment on the target + HOST_EXTRACFLAGS = $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \ + -idirafter $(srctree)/tools/env \ diff --git a/package/boot/uboot-envtools/patches/200-fw_env_no_aes.patch b/package/boot/uboot-envtools/patches/200-fw_env_no_aes.patch new file mode 100644 index 0000000..9c8681f --- /dev/null +++ b/package/boot/uboot-envtools/patches/200-fw_env_no_aes.patch @@ -0,0 +1,38 @@ +--- a/tools/env/fw_env.c ++++ b/tools/env/fw_env.c +@@ -246,7 +246,7 @@ int fw_printenv (int argc, char *argv[]) + int i, n_flag; + int rc = 0; + +- if (argc >= 2 && strcmp(argv[1], "-a") == 0) { ++ if (0 && argc >= 2 && strcmp(argv[1], "-a") == 0) { + if (argc < 3) { + fprintf(stderr, + "## Error: '-a' option requires AES key\n"); +@@ -325,7 +325,7 @@ int fw_printenv (int argc, char *argv[]) + int fw_env_close(void) + { + int ret; +- if (aes_flag) { ++ if (0 && aes_flag) { + ret = env_aes_cbc_crypt(environment.data, 1); + if (ret) { + fprintf(stderr, +@@ -1223,7 +1223,7 @@ int fw_env_open(void) + + crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE); + +- if (aes_flag) { ++ if (0 && aes_flag) { + ret = env_aes_cbc_crypt(environment.data, 0); + if (ret) + return ret; +@@ -1280,7 +1280,7 @@ int fw_env_open(void) + + crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE); + +- if (aes_flag) { ++ if (0 && aes_flag) { + ret = env_aes_cbc_crypt(redundant->data, 0); + if (ret) + return ret; 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..75d3804 --- /dev/null +++ b/package/boot/uboot-envtools/patches/300-support-env-in-ubivol-chardev.patch @@ -0,0 +1,163 @@ +From 6e2630a0fc872d0db34157972f6dc3941f6d66dd Mon Sep 17 00:00:00 2001 +From: Daniel Golle +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 +--- + tools/env/Makefile | 5 ++++ + tools/env/fw_env.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++------- + 2 files changed, 71 insertions(+), 10 deletions(-) + +--- a/tools/env/Makefile ++++ b/tools/env/Makefile +@@ -24,6 +24,13 @@ ifeq ($(MTD_VERSION),old) + HOST_EXTRACFLAGS += -DMTD_OLD + endif + ++ifeq ($(UBI),y) ++HOST_EXTRACFLAGS += -DUBI ++HOST_LOADLIBES = "-Wl,--gc-sections,-lubi-utils" ++else ++HOST_LOADLIBES = "-Wl,--gc-sections" ++endif ++ + always := fw_printenv + hostprogs-y := fw_printenv + +--- a/tools/env/fw_env.c ++++ b/tools/env/fw_env.c +@@ -31,6 +31,9 @@ + # include + #endif + ++#ifdef UBI ++# include ++#endif + #include "fw_env.h" + + #include +@@ -811,6 +814,11 @@ static int flash_write_buf (int dev, int + 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 = NULL;/* pointer to libubi struct */ ++#else ++ void *libubi = NULL; ++#endif + int rc; + + /* +@@ -916,7 +924,30 @@ static int flash_write_buf (int dev, int + continue; + } + +- if (mtd_type != MTD_ABSENT) { ++#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 (libubi && rc) { ++ libubi_close(libubi); ++ libubi = NULL; ++ } ++ } ++#endif ++ if (!libubi && mtd_type != MTD_ABSENT) { + erase.start = blockstart; + ioctl(fd, MEMUNLOCK, &erase); + /* These do not need an explicit erase cycle */ +@@ -933,7 +964,8 @@ static int flash_write_buf (int dev, int + fprintf (stderr, + "Seek error on %s: %s\n", + DEVNAME (dev), strerror (errno)); +- return -1; ++ processed = -1; ++ goto out; + } + + #ifdef DEBUG +@@ -943,10 +975,11 @@ static int flash_write_buf (int dev, int + 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) ++ if (!libubi && mtd_type != MTD_ABSENT) + ioctl(fd, MEMLOCK, &erase); + + processed += erasesize; +@@ -957,6 +990,11 @@ static int flash_write_buf (int dev, int + if (write_total > count) + free (data); + ++out: ++#ifdef UBI ++ if (libubi) ++ libubi_close(libubi); ++#endif + return processed; + } + +@@ -1068,12 +1106,8 @@ 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 && ++ if (!rc && ++ mtdinfo.type != MTD_NORFLASH && + mtdinfo.type != MTD_NANDFLASH && + mtdinfo.type != MTD_DATAFLASH && + mtdinfo.type != MTD_UBIVOLUME) { +@@ -1081,6 +1115,28 @@ static int flash_read (int fd) + mtdinfo.type, DEVNAME(dev_current)); + return -1; + } ++#ifdef UBI ++ if (rc) { ++ libubi_t *libubi; ++ struct ubi_vol_info volinfo; ++ libubi = libubi_open(); ++ if (!libubi) ++ return -ENOMEM; ++ ++ rc = ubi_get_vol_info(libubi, DEVNAME(dev_current), ++ &volinfo); ++ if (rc) { ++ libubi_close(libubi); ++ return -ENODEV; ++ } ++ memset(&mtdinfo, 0, sizeof(mtdinfo)); ++ mtdinfo.type = MTD_UBIVOLUME; ++ mtdinfo.size = volinfo.data_bytes; ++ mtdinfo.erasesize = volinfo.leb_size; ++ mtdinfo.writesize = volinfo.leb_size; ++ libubi_close(libubi); ++ } ++#endif + } else { + memset(&mtdinfo, 0, sizeof(mtdinfo)); + mtdinfo.type = MTD_ABSENT; -- cgit v1.2.3