From patchwork Sun Dec 14 14:13:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gergely Kiss X-Patchwork-Id: 420864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CB2281400B7 for ; Mon, 15 Dec 2014 01:13:34 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 83E29280222; Sun, 14 Dec 2014 15:11:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8679C280222 for ; Sun, 14 Dec 2014 15:11:19 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-wi0-f173.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 14 Dec 2014 15:11:18 +0100 (CET) Received: by mail-wi0-f173.google.com with SMTP id r20so6588077wiv.0 for ; Sun, 14 Dec 2014 06:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=a6G8fz+v/Yxl7LoCtmUxiQIDU37KqESn7gBZg0PActo=; b=Ai6BcqZswqQN8HKQgLKhA50mz0Gq6fN1fYmkiXDoGp1oB5GAxSMsysa4bDDDyDzSCK eE/UG8Ue1iHzEdrqb7hzYI8cZqWM62YCGLGPqHfueEiw05op1vYgwX73WvDw2AQvJ517 D6NrLaz+yOEqDBfvPrss1BHQZ1YeQWIuF+PKR0mpo5oiMpe2FKLuuLPu0uy/UWW20+Sz /7pD1sWs/kL/VzRPx2ole14BWpprQIUjtn1T4sNfKLX7BWPTTUUJnglO475H8bfcS129 RvPgTqYsHgOhjuq8Sv/I6PvrvmPFaiQV5QDT2iBEUMgO4aT71uTwIemPr8NKHK8dhu8I Kkew== X-Received: by 10.194.2.164 with SMTP id 4mr42691145wjv.55.1418566386218; Sun, 14 Dec 2014 06:13:06 -0800 (PST) Received: from nb.nb (catv-80-99-31-146.catv.broadband.hu. [80.99.31.146]) by mx.google.com with ESMTPSA id td6sm9522721wic.15.2014.12.14.06.13.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Dec 2014 06:13:05 -0800 (PST) Message-ID: <548D9AEF.9080303@gmail.com> Date: Sun, 14 Dec 2014 15:13:03 +0100 From: Gergely Kiss User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: blogic@openwrt.org Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH v2] [package] fstools: make extroot functionality work with ubifs X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From 730494a0accbc5b70e57d376ca11e81453868422 Mon Sep 17 00:00:00 2001 From: Gergely Kiss Date: Sun, 14 Dec 2014 14:23:05 +0100 Subject: [PATCH v2] [package] fstools: make extroot functionality work with ubifs Signed-off-by: Gergely Kiss Tested-by: Gergely Kiss --- Hi John, here's the new version of my patch providing the following improvements: * Whitespace issues should be fixed now (changed to a new MUA), however while applying the patch, there are some warnings generated. I couldn't make them disappear, sorry. If that's a problem please let me know how to fix it (I'm still a newbie on how to make properly formatted patches). * Config option added to enable/disable extroot support as requested (enabled by default if NAND_SUPPORT is defined, otherwise hidden). Hope everything will be fine with the patch this time. Regards, Gergely package/system/fstools/Makefile | 12 ++ .../system/fstools/patches/001-ubifs-extroot.patch | 165 +++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 package/system/fstools/patches/001-ubifs-extroot.patch diff --git a/package/system/fstools/Makefile b/package/system/fstools/Makefile index 2688f49..9eca044 100644 --- a/package/system/fstools/Makefile +++ b/package/system/fstools/Makefile @@ -31,12 +31,24 @@ include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/cmake.mk TARGET_LDFLAGS += $(if $(CONFIG_USE_EGLIBC),-lrt) +CMAKE_OPTIONS += $(if $(CONFIG_FSTOOLS_UBIFS_EXTROOT),-DCMAKE_UBIFS_EXTROOT=y) define Package/fstools SECTION:=base CATEGORY:=Base system DEPENDS:=+ubox +USE_EGLIBC:librt +NAND_SUPPORT:ubi-utils TITLE:=OpenWrt filesystem tools + MENU:=1 +endef + +define Package/fstools/config + config FSTOOLS_UBIFS_EXTROOT + depends on PACKAGE_fstools + depends on NAND_SUPPORT + bool "Support extroot functionality with UBIFS" + default y + help + This option makes it possible to use extroot functionality if the root filesystem resides on an UBIFS partition endef define Package/block-mount diff --git a/package/system/fstools/patches/001-ubifs-extroot.patch b/package/system/fstools/patches/001-ubifs-extroot.patch new file mode 100644 index 0000000..9ddfb6c --- /dev/null +++ b/package/system/fstools/patches/001-ubifs-extroot.patch @@ -0,0 +1,165 @@ +diff -rupN fstools-2014-12-01.orig/block.c fstools-2014-12-01/block.c +--- fstools-2014-12-01.orig/block.c 2014-12-14 14:15:20.000000000 +0100 ++++ fstools-2014-12-01/block.c 2014-12-14 14:19:33.537985812 +0100 +@@ -36,6 +36,10 @@ + + #include "libblkid-tiny/libblkid-tiny.h" + ++#ifdef UBIFS_EXTROOT ++#include "libubi/libubi.h" ++#endif ++ + #define ERROR(fmt, ...) do { \ + syslog(LOG_ERR, fmt, ## __VA_ARGS__); \ + fprintf(stderr, "block: "fmt, ## __VA_ARGS__); \ +@@ -823,13 +827,77 @@ static int find_block_mtd(char *name, ch + return 0; + } + ++#ifdef UBIFS_EXTROOT ++static int find_ubi_vol(libubi_t libubi, char *name, int *dev_num, int *vol_id) ++{ ++ int dev = 0; ++ ++ while (ubi_dev_present(libubi, dev)) ++ { ++ struct ubi_dev_info dev_info; ++ struct ubi_vol_info vol_info; ++ ++ if (ubi_get_dev_info1(libubi, dev++, &dev_info)) ++ continue; ++ if (ubi_get_vol_info1_nm(libubi, dev_info.dev_num, name, &vol_info)) ++ continue; ++ ++ *dev_num = dev_info.dev_num; ++ *vol_id = vol_info.vol_id; ++ ++ return 0; ++ } ++ ++ return -1; ++} ++ ++static int find_block_ubi(libubi_t libubi, char *name, char *part, int plen) ++{ ++ int dev_num; ++ int vol_id; ++ int err = -1; ++ ++ err = find_ubi_vol(libubi, name, &dev_num, &vol_id); ++ if (!err) ++ snprintf(part, plen, "/dev/ubi%d_%d", dev_num, vol_id); ++ ++ return err; ++} ++ ++static int find_block_ubi_RO(libubi_t libubi, char *name, char *part, int plen) ++{ ++ int dev_num; ++ int vol_id; ++ int err = -1; ++ ++ err = find_ubi_vol(libubi, name, &dev_num, &vol_id); ++ if (!err) ++ snprintf(part, plen, "/dev/ubiblock%d_%d", dev_num, vol_id); ++ ++ return err; ++} ++#endif ++ + static int check_extroot(char *path) + { + struct blkid_struct_probe *pr = NULL; + char fs[32]; + ++#ifdef UBIFS_EXTROOT ++ if (find_block_mtd("rootfs", fs, sizeof(fs))) { ++ int err = -1; ++ libubi_t libubi; ++ ++ libubi = libubi_open(); ++ err = find_block_ubi_RO(libubi, "rootfs", fs, sizeof(fs)); ++ libubi_close(libubi); ++ if (err) ++ return -1; ++ } ++#else + if (find_block_mtd("rootfs", fs, sizeof(fs))) + return -1; ++#endif + + list_for_each_entry(pr, &devices, list) { + if (!strcmp(pr->dev, fs)) { +@@ -933,6 +1001,9 @@ static int main_extroot(int argc, char * + char fs[32] = { 0 }; + char fs_data[32] = { 0 }; + int err = -1; ++#ifdef UBIFS_EXTROOT ++ libubi_t libubi; ++#endif + + if (!getenv("PREINIT")) + return -1; +@@ -947,8 +1018,18 @@ static int main_extroot(int argc, char * + + find_block_mtd("rootfs", fs, sizeof(fs)); + if (!fs[0]) { ++#ifdef UBIFS_EXTROOT ++ libubi = libubi_open(); ++ find_block_ubi_RO(libubi, "rootfs", fs, sizeof(fs)); ++ libubi_close(libubi); ++ if (!fs[0]) { ++ ERROR("extroot: unable to locate rootfs mtdblock / ubiblock\n"); ++ return -2; ++ } ++#else + ERROR("extroot: unable to locate rootfs mtdblock\n"); + return -2; ++#endif + } + + pr = find_block_info(NULL, NULL, fs); +@@ -975,6 +1056,26 @@ static int main_extroot(int argc, char * + } + } + ++#ifdef UBIFS_EXTROOT ++ memset(fs_data, 0, sizeof(fs_data)); ++ libubi = libubi_open(); ++ find_block_ubi(libubi, "rootfs_data", fs_data, sizeof(fs_data)); ++ libubi_close(libubi); ++ if (fs_data[0]) { ++ char cfg[] = "/tmp/ubifs_cfg"; ++ ++ mkdir_p(cfg); ++ if (!mount(fs_data, cfg, "ubifs", MS_NOATIME, NULL)) { ++ err = mount_extroot(cfg); ++ umount2(cfg, MNT_DETACH); ++ } ++ if (err < 0) ++ rmdir("/tmp/overlay"); ++ rmdir(cfg); ++ return err; ++ } ++#endif ++ + return mount_extroot(NULL); + } + +diff -rupN fstools-2014-12-01.orig/CMakeLists.txt fstools-2014-12-01/CMakeLists.txt +--- fstools-2014-12-01.orig/CMakeLists.txt 2014-12-14 14:15:20.000000000 +0100 ++++ fstools-2014-12-01/CMakeLists.txt 2014-12-14 14:19:18.140667538 +0100 +@@ -48,7 +48,12 @@ TARGET_LINK_LIBRARIES(mount_root fstools + INSTALL(TARGETS mount_root RUNTIME DESTINATION sbin) + + ADD_EXECUTABLE(block block.c) +-TARGET_LINK_LIBRARIES(block blkid-tiny uci ubox blobmsg_json) ++IF(DEFINED CMAKE_UBIFS_EXTROOT) ++ ADD_DEFINITIONS(-DUBIFS_EXTROOT) ++ TARGET_LINK_LIBRARIES(block blkid-tiny uci ubox blobmsg_json ubi-utils) ++ELSE(DEFINED CMAKE_UBIFS_EXTROOT) ++ TARGET_LINK_LIBRARIES(block blkid-tiny uci ubox blobmsg_json) ++ENDIF(DEFINED CMAKE_UBIFS_EXTROOT) + INSTALL(TARGETS block RUNTIME DESTINATION sbin) + + ADD_EXECUTABLE(jffs2reset jffs2reset.c)