shithub: lwext4

Download patch

ref: 6f2630560d50340611b372d58c1f450106df5467
parent: b6a7544b8c5b52b1d13f3b9c7c94cdabb6bf5ed1
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue May 20 19:41:24 EDT 2014

Build system refactoring.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,33 +2,33 @@
 cmake_minimum_required(VERSION 2.8)
 
 
+include_directories(lwext4)
+include_directories(blockdev/filedev)
+include_directories(blockdev/filedev_win)
 
-#LIBRARY
-include_directories(. lwext4)
-aux_source_directory(lwext4 LWEXT4_SRC)
-add_library(lwext4  ${LWEXT4_SRC})
 
+#Library build
+add_subdirectory(lwext4)
+#Detect all possible warnings for lwext4 target
+set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
+
 #Examples
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
-    #Library size print
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
+if    (CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
+    #cortex-m3 demos
+    #...
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)
-    #Library size print
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
-    #Discoery disco demo
-    include(demos/stm32f429_disco/stm32f429_demo.cmake)
+    #cortex-m4 demos
+    add_subdirectory(demos/stm32f429_disco)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)
-    #Library size print
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
+    #bf518 demos
+    #...
 else()
-    #Warning setup
-    set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic -std=gnu99")
-    #Library size print
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)
     #Generic example target
-    include(demos/generic/generic.cmake)
-    include(fs_test/fs_test.cmake)
+    add_subdirectory(blockdev)
+    add_subdirectory(fs_test)
+    add_subdirectory(demos/generic)
 endif()
+
 
 #DISTRIBUTION
 set(CPACK_PACKAGE_VERSION_MAJOR "0")
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@
 generic:
 	rm -R -f build_generic
 	mkdir build_generic
-	cd build_generic && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) ..
+	cd build_generic && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/generic.cmake ..
 	
 bf518:
 	rm -R -f build_bf518
--- /dev/null
+++ b/blockdev/CMakeLists.txt
@@ -1,0 +1,5 @@
+#Blockdev library
+aux_source_directory(filedev BLOCKDEV_SRC)
+aux_source_directory(filedev_win BLOCKDEV_SRC)
+add_library(blockdev  ${BLOCKDEV_SRC})
+
--- /dev/null
+++ b/demos/generic/CMakeLists.txt
@@ -1,0 +1,4 @@
+#Generic demo
+add_executable(fileimage_demo main.c)
+target_link_libraries(fileimage_demo lwext4)
+target_link_libraries(fileimage_demo blockdev)
\ No newline at end of file
--- a/demos/generic/generic.cmake
+++ /dev/null
@@ -1,9 +1,0 @@
-include_directories(blockdev/filedev)
-include_directories(blockdev/filedev_win)
-
-aux_source_directory(blockdev/filedev GENERIC_SRC)
-aux_source_directory(blockdev/filedev_win GENERIC_SRC)
-aux_source_directory(demos/generic GENERIC_SRC)
-
-add_executable(fileimage_demo ${GENERIC_SRC})
-target_link_libraries(fileimage_demo lwext4)
\ No newline at end of file
--- a/demos/generic/main.c
+++ b/demos/generic/main.c
@@ -34,6 +34,7 @@
 #include <stdbool.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/time.h>
 
 #include <ext4_filedev.h>
 #include <io_raw.h>
--- /dev/null
+++ b/demos/stm32f429_disco/CMakeLists.txt
@@ -1,0 +1,37 @@
+#Discoery disco demo
+enable_language(ASM)
+set (STM32F429_DEMO_ASM
+    startup.S
+)
+
+
+include_directories(.)
+include_directories(cmsis)
+include_directories(stm/lcd_utils)
+include_directories(stm/stm32f4_spl/inc)
+include_directories(stm/stm32f429)
+include_directories(stm/usb_dev/Core/inc)
+include_directories(stm/usb_host/Core/inc)
+include_directories(stm/usb_host/Class/MSC/inc)
+include_directories(stm/usb_otg/inc)
+include_directories(stm/usb_user)
+
+aux_source_directory(. STM32F429_DEMO)
+aux_source_directory(cmsis STM32F429_DEMO)
+aux_source_directory(stm/lcd_utils STM32F429_DEMO)
+aux_source_directory(stm/stm32f4_spl/src STM32F429_DEMO)
+aux_source_directory(stm/stm32f429 STM32F429_DEMO)
+aux_source_directory(stm/usb_host/Core/src STM32F429_DEMO)
+aux_source_directory(stm/usb_host/Class/MSC/src STM32F429_DEMO)
+aux_source_directory(stm/usb_otg/src STM32F429_DEMO)
+aux_source_directory(stm/usb_user STM32F429_DEMO)
+add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})
+
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")
+
+set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")
+target_link_libraries(stm324f29_demo lwext4)
+
+add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
\ No newline at end of file
--- a/demos/stm32f429_disco/stm32f429_demo.cmake
+++ /dev/null
@@ -1,38 +1,0 @@
-#Discoery disco demo
-enable_language(ASM)
-set (STM32F429_DEMO_ASM
-    demos/stm32f429_disco/startup.S
-)
-
-
-include_directories(demos/stm32f429_disco)
-include_directories(demos/stm32f429_disco/cmsis)
-include_directories(demos/stm32f429_disco/stm/lcd_utils)
-include_directories(demos/stm32f429_disco/stm/stm32f4_spl/inc)
-include_directories(demos/stm32f429_disco/stm/stm32f429)
-include_directories(demos/stm32f429_disco/stm/usb_dev/Core/inc)
-include_directories(demos/stm32f429_disco/stm/usb_host/Core/inc)
-include_directories(demos/stm32f429_disco/stm/usb_host/Class/MSC/inc)
-include_directories(demos/stm32f429_disco/stm/usb_otg/inc)
-include_directories(demos/stm32f429_disco/stm/usb_user)
-
-aux_source_directory(demos/stm32f429_disco STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/cmsis STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/lcd_utils STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/stm32f4_spl/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/stm32f429 STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Core/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Class/MSC/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_otg/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_user STM32F429_DEMO)
-
-add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})
-
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")
-
-set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")
-target_link_libraries(stm324f29_demo lwext4)
-
-add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
\ No newline at end of file
--- a/ext4.h
+++ /dev/null
@@ -1,345 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup lwext4
- * @{
- */
-/**
- * @file  ext4.h
- * @brief Ext4 high level operations (files, directories, mount points...).
- *        Client has to include only this file.
- */
-
-#ifndef EXT4_H_
-#define EXT4_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <stdint.h>
-
-/********************************FILE OPEN FLAGS*****************************/
-
-#ifndef O_RDONLY
-#define O_RDONLY    00
-#endif
-
-#ifndef O_WRONLY
-#define O_WRONLY    01
-#endif
-
-#ifndef O_RDWR
-#define O_RDWR      02
-#endif
-
-#ifndef O_CREAT
-#define O_CREAT     0100
-#endif
-
-#ifndef O_EXCL
-#define O_EXCL      0200
-#endif
-
-#ifndef O_TRUNC
-#define O_TRUNC     01000
-#endif
-
-#ifndef O_APPEND
-#define O_APPEND    02000
-#endif
-
-/********************************FILE SEEK FLAGS*****************************/
-
-#ifndef SEEK_SET
-#define SEEK_SET    0
-#endif
-
-#ifndef SEEK_CUR
-#define SEEK_CUR    1
-#endif
-
-#ifndef SEEK_END
-#define SEEK_END    2
-#endif
-
-/********************************OS LOCK INFERFACE***************************/
-
-/**@brief   OS dependent lock interface.*/
-struct ext4_lock {
-
-    /**@brief   Lock access to mount point*/
-    void (*lock)(void);
-
-    /**@brief   Unlock access to mount point*/
-    void (*unlock)(void);
-};
-
-
-/********************************FILE DESCRIPTOR*****************************/
-
-/**@brief   File descriptor*/
-typedef struct ext4_file {
-
-    /**@brief   Mount point handle.*/
-    struct ext4_mountpoint *mp;
-
-    /**@brief   File inode id*/
-    uint32_t inode;
-
-    /**@brief   Open flags.*/
-    uint32_t flags;
-
-    /**@brief   File size.*/
-    uint64_t fsize;
-
-    /**@brief   File position*/
-    uint64_t fpos;
-}ext4_file;
-
-/*****************************DIRECTORY DESCRIPTOR***************************/
-/**@brief   Directory entry types. Copy from ext4_types.h*/
-enum  {
-    EXT4_DIRENTRY_UNKNOWN = 0,
-    EXT4_DIRENTRY_REG_FILE,
-    EXT4_DIRENTRY_DIR,
-    EXT4_DIRENTRY_CHRDEV,
-    EXT4_DIRENTRY_BLKDEV,
-    EXT4_DIRENTRY_FIFO,
-    EXT4_DIRENTRY_SOCK,
-    EXT4_DIRENTRY_SYMLINK
-};
-
-/**@brief   Directory entry descriptor. Copy from ext4_types.h*/
-typedef struct {
-    uint32_t inode;
-    uint16_t entry_length;
-    uint8_t name_length;
-    uint8_t inode_type;
-    uint8_t name[255];
-}ext4_direntry;
-
-typedef struct  {
-    /**@brief   File descriptor*/
-    ext4_file f;
-    /**@brief   Current directory entry.*/
-    ext4_direntry de;
-}ext4_dir;
-
-/********************************MOUNT OPERATIONS****************************/
-
-/**@brief   Register a block device to a name.
- *          @warning Block device has to be filled by
- *          @ref EXT4_BLOCKDEV_STATIC_INSTANCE. Block cache may be created
- *          @ref EXT4_BCACHE_STATIC_INSTANCE.
- *          Block cache may by created automatically when bc parameter is 0.
- * @param   bd block device
- * @param   bd block device cache (0 = automatic cache mode)
- * @param   dev_name register name
- * @param   standard error code*/
-int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,
-        const char *dev_name);
-
-/**@brief   Mount a block device with EXT4 partition to the mount point.
- * @param   dev_name block device name (@ref ext4_device_register)
- * @param   mount_point mount point, for example
- *          -   /
- *          -   /my_partition/
- *          -   /my_second_partition/
- *
- * @return standard error code */
-int ext4_mount(const char * dev_name,  char *mount_point);
-
-/**@brief   Umount operation.
- * @param   mount_point mount name
- * @return  standard error code */
-int ext4_umount(char *mount_point);
-
-
-/**@brief   Some of the filesystem stats.*/
-struct ext4_mount_stats {
-    uint32_t inodes_count;
-    uint32_t free_inodes_count;
-    uint64_t blocks_count;
-    uint64_t free_blocks_count;
-
-    uint32_t block_size;
-    uint32_t block_group_count;
-    uint32_t blocks_per_group;
-    uint32_t inodes_per_group;
-
-    char volume_name[16];
-};
-
-/**@brief   Get file system params.
- * @param   mount_point mount path
- * @param   stats ext fs stats
- * @return  standard error code */
-int ext4_mount_point_stats(const char *mount_point,
-    struct ext4_mount_stats *stats);
-
-
-/**@brief   Enable/disable write back cache mode.
- * @warning Default model of cache is write trough. It means that when You do:
- *
- *          ext4_fopen(...);
- *          ext4_fwrie(...);
- *                           < --- data is flushed to physical drive
- *
- *          When you do:
- *          ext4_cache_write_back(..., 1);
- *          ext4_fopen(...);
- *          ext4_fwrie(...);
- *                           < --- data is NOT flushed to physical drive
- *          ext4_cache_write_back(..., 0);
- *                           < --- when write back mode is disabled all
- *                                 cache data will be flushed
- * To enable write back mode permanently just call this function
- * once after ext4_mount (and disable before ext4_umount).
- *
- * Some of the function use write back cache mode internally.
- * If you enable write back mode twice you have to disable it twice
- * to flush all data:
- *
- *      ext4_cache_write_back(..., 1);
- *      ext4_cache_write_back(..., 1);
- *
- *      ext4_cache_write_back(..., 0);
- *      ext4_cache_write_back(..., 0);
- *
- * Write back mode is useful when you want to create a lot of empty
- * files/directories.
- *
- * @param   path mount point path
- * @param   on enable/disable
- *
- * @return  standard error code */
-int ext4_cache_write_back(const char *path, bool on);
-
-/********************************FILE OPERATIONS*****************************/
-
-/**@brief   Remove file by path.
- * @param   path path to file
- * @return  standard error code */
-int ext4_fremove(const char *path);
-
-/**@brief   File open function.
- * @param   filename, (has to start from mount point)
- *          /my_partition/my_file
- * @param   flags open file flags
- *  |---------------------------------------------------------------|
- *  |   r or rb                 O_RDONLY                            |
- *  |---------------------------------------------------------------|
- *  |   w or wb                 O_WRONLY|O_CREAT|O_TRUNC            |
- *  |---------------------------------------------------------------|
- *  |   a or ab                 O_WRONLY|O_CREAT|O_APPEND           |
- *  |---------------------------------------------------------------|
- *  |   r+ or rb+ or r+b        O_RDWR                              |
- *  |---------------------------------------------------------------|
- *  |   w+ or wb+ or w+b        O_RDWR|O_CREAT|O_TRUNC              |
- *  |---------------------------------------------------------------|
- *  |   a+ or ab+ or a+b        O_RDWR|O_CREAT|O_APPEND             |
- *  |---------------------------------------------------------------|
- *
- * @return  standard error code*/
-int ext4_fopen (ext4_file *f, const char *path, const char *flags);
-
-/**@brief   File close function.
- * @param   f file handle
- * @return  standard error code*/
-int ext4_fclose(ext4_file *f);
-
-/**@brief   Read data from file.
- * @param   f file handle
- * @param   buf output buffer
- * @param   size bytes to read
- * @param   rcnt bytes read (may be NULL)
- * @return  standard error code*/
-int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);
-
-/**@brief   Write data to file.
- * @param   f file handle
- * @param   buf data to write
- * @param   size write length
- * @param   wcnt bytes written (may be NULL)
- * @return  standard error code*/
-int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);
-
-/**@brief   File seek operation.
- * @param   f file handle
- * @param   offset offset to seek
- * @param   origin seek type:
- *              @ref SEEK_SET
- *              @ref SEEK_CUR
- *              @ref SEEK_END
- * @return  standard error code*/
-int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);
-
-/**@brief   Get file position.
- * @param   f file handle
- * @return  actual file position */
-uint64_t ext4_ftell (ext4_file *f);
-
-/**@brief   Get file size.
- * @param   f file handle
- * @return  file size */
-uint64_t ext4_fsize (ext4_file *f);
-
-/*********************************DIRECTORY OPERATION***********************/
-
-/**@brief   Recursive directory remove.
- * @param   path directory path to remove
- * @return  standard error code*/
-int ext4_dir_rm(const char *path);
-
-/**@brief   Create new directory.
- * @param   name new directory name
- * @return  standard error code*/
-int ext4_dir_mk(const char *path);
-
-/**@brief   Directory open.
- * @param   d directory handle
- * @param   path directory path
- * @return  standard error code*/
-int ext4_dir_open (ext4_dir *d, const char *path);
-
-/**@brief   Directory close.
- * @param   d directory handle
- * @return  standard error code*/
-int ext4_dir_close(ext4_dir *d);
-
-
-/**@brief   Return directory entry by id.
- * @param   d directory handle
- * @param   id entry id
- * @return  directory entry id (NULL id no entry)*/
-ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);
-
-#endif /* EXT4_H_ */
-
-/**
- * @}
- */
--- a/fs_test.mk
+++ b/fs_test.mk
@@ -1,10 +1,10 @@
 
 ifeq ($(OS),Windows_NT)
-LWEXT4_CLIENT = @build_generic\\lwext4_client
-LWEXT4_SERVER = @build_generic\\lwext4_server
+LWEXT4_CLIENT = @build_generic\\fs_test\\lwext4_client
+LWEXT4_SERVER = @build_generic\\fs_test\\lwext4_server
 else
-LWEXT4_CLIENT = @build_generic/lwext4_client
-LWEXT4_SERVER = @build_generic/lwext4_server
+LWEXT4_CLIENT = @build_generic/fs_test/lwext4_client
+LWEXT4_SERVER = @build_generic/fs_test/lwext4_server
 endif
 
 TEST_DIR = /test
@@ -504,4 +504,4 @@
 server_ext4:
 	$(LWEXT4_SERVER) -i ext_images/ext4
 
-all_tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20
\ No newline at end of file
+tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20
\ No newline at end of file
--- /dev/null
+++ b/fs_test/CMakeLists.txt
@@ -1,0 +1,12 @@
+#fs_test executables
+add_executable(lwext4_server lwext4_server.c)
+target_link_libraries(lwext4_server lwext4)
+target_link_libraries(lwext4_server blockdev)
+if(WIN32)
+target_link_libraries(lwext4_server ws2_32)
+endif(WIN32)
+add_executable(lwext4_client lwext4_client.c)
+target_link_libraries(lwext4_client lwext4)
+if(WIN32)
+target_link_libraries(lwext4_client ws2_32)
+endif(WIN32)
--- a/fs_test/fs_test.cmake
+++ /dev/null
@@ -1,17 +1,0 @@
-include_directories(blockdev/filedev)
-include_directories(blockdev/filedev_win)
-
-aux_source_directory(blockdev/filedev BLOCKDEV_SRC)
-aux_source_directory(blockdev/filedev_win BLOCKDEV_SRC)
-
-
-add_executable(lwext4_server fs_test/lwext4_server.c ${BLOCKDEV_SRC})
-target_link_libraries(lwext4_server lwext4)
-if(WIN32)
-target_link_libraries(lwext4_server ws2_32)
-endif(WIN32)
-add_executable(lwext4_client fs_test/lwext4_client.c ${BLOCKDEV_SRC})
-target_link_libraries(lwext4_client lwext4)
-if(WIN32)
-target_link_libraries(lwext4_client ws2_32)
-endif(WIN32)
\ No newline at end of file
--- a/fs_test/lwext4_server.c
+++ b/fs_test/lwext4_server.c
@@ -35,6 +35,7 @@
 #include <stdbool.h>
 #include <getopt.h>
 #include <time.h>
+#include <sys/time.h>
 
 #ifdef WIN32
 #include <winsock2.h>
--- /dev/null
+++ b/lwext4/CMakeLists.txt
@@ -1,0 +1,8 @@
+
+#LIBRARY
+include_directories(.)
+aux_source_directory(. LWEXT4_SRC)
+add_library(lwext4  ${LWEXT4_SRC})
+add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
+
+
--- /dev/null
+++ b/lwext4/ext4.h
@@ -1,0 +1,345 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup lwext4
+ * @{
+ */
+/**
+ * @file  ext4.h
+ * @brief Ext4 high level operations (files, directories, mount points...).
+ *        Client has to include only this file.
+ */
+
+#ifndef EXT4_H_
+#define EXT4_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <stdint.h>
+
+/********************************FILE OPEN FLAGS*****************************/
+
+#ifndef O_RDONLY
+#define O_RDONLY    00
+#endif
+
+#ifndef O_WRONLY
+#define O_WRONLY    01
+#endif
+
+#ifndef O_RDWR
+#define O_RDWR      02
+#endif
+
+#ifndef O_CREAT
+#define O_CREAT     0100
+#endif
+
+#ifndef O_EXCL
+#define O_EXCL      0200
+#endif
+
+#ifndef O_TRUNC
+#define O_TRUNC     01000
+#endif
+
+#ifndef O_APPEND
+#define O_APPEND    02000
+#endif
+
+/********************************FILE SEEK FLAGS*****************************/
+
+#ifndef SEEK_SET
+#define SEEK_SET    0
+#endif
+
+#ifndef SEEK_CUR
+#define SEEK_CUR    1
+#endif
+
+#ifndef SEEK_END
+#define SEEK_END    2
+#endif
+
+/********************************OS LOCK INFERFACE***************************/
+
+/**@brief   OS dependent lock interface.*/
+struct ext4_lock {
+
+    /**@brief   Lock access to mount point*/
+    void (*lock)(void);
+
+    /**@brief   Unlock access to mount point*/
+    void (*unlock)(void);
+};
+
+
+/********************************FILE DESCRIPTOR*****************************/
+
+/**@brief   File descriptor*/
+typedef struct ext4_file {
+
+    /**@brief   Mount point handle.*/
+    struct ext4_mountpoint *mp;
+
+    /**@brief   File inode id*/
+    uint32_t inode;
+
+    /**@brief   Open flags.*/
+    uint32_t flags;
+
+    /**@brief   File size.*/
+    uint64_t fsize;
+
+    /**@brief   File position*/
+    uint64_t fpos;
+}ext4_file;
+
+/*****************************DIRECTORY DESCRIPTOR***************************/
+/**@brief   Directory entry types. Copy from ext4_types.h*/
+enum  {
+    EXT4_DIRENTRY_UNKNOWN = 0,
+    EXT4_DIRENTRY_REG_FILE,
+    EXT4_DIRENTRY_DIR,
+    EXT4_DIRENTRY_CHRDEV,
+    EXT4_DIRENTRY_BLKDEV,
+    EXT4_DIRENTRY_FIFO,
+    EXT4_DIRENTRY_SOCK,
+    EXT4_DIRENTRY_SYMLINK
+};
+
+/**@brief   Directory entry descriptor. Copy from ext4_types.h*/
+typedef struct {
+    uint32_t inode;
+    uint16_t entry_length;
+    uint8_t name_length;
+    uint8_t inode_type;
+    uint8_t name[255];
+}ext4_direntry;
+
+typedef struct  {
+    /**@brief   File descriptor*/
+    ext4_file f;
+    /**@brief   Current directory entry.*/
+    ext4_direntry de;
+}ext4_dir;
+
+/********************************MOUNT OPERATIONS****************************/
+
+/**@brief   Register a block device to a name.
+ *          @warning Block device has to be filled by
+ *          @ref EXT4_BLOCKDEV_STATIC_INSTANCE. Block cache may be created
+ *          @ref EXT4_BCACHE_STATIC_INSTANCE.
+ *          Block cache may by created automatically when bc parameter is 0.
+ * @param   bd block device
+ * @param   bd block device cache (0 = automatic cache mode)
+ * @param   dev_name register name
+ * @param   standard error code*/
+int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,
+        const char *dev_name);
+
+/**@brief   Mount a block device with EXT4 partition to the mount point.
+ * @param   dev_name block device name (@ref ext4_device_register)
+ * @param   mount_point mount point, for example
+ *          -   /
+ *          -   /my_partition/
+ *          -   /my_second_partition/
+ *
+ * @return standard error code */
+int ext4_mount(const char * dev_name,  char *mount_point);
+
+/**@brief   Umount operation.
+ * @param   mount_point mount name
+ * @return  standard error code */
+int ext4_umount(char *mount_point);
+
+
+/**@brief   Some of the filesystem stats.*/
+struct ext4_mount_stats {
+    uint32_t inodes_count;
+    uint32_t free_inodes_count;
+    uint64_t blocks_count;
+    uint64_t free_blocks_count;
+
+    uint32_t block_size;
+    uint32_t block_group_count;
+    uint32_t blocks_per_group;
+    uint32_t inodes_per_group;
+
+    char volume_name[16];
+};
+
+/**@brief   Get file system params.
+ * @param   mount_point mount path
+ * @param   stats ext fs stats
+ * @return  standard error code */
+int ext4_mount_point_stats(const char *mount_point,
+    struct ext4_mount_stats *stats);
+
+
+/**@brief   Enable/disable write back cache mode.
+ * @warning Default model of cache is write trough. It means that when You do:
+ *
+ *          ext4_fopen(...);
+ *          ext4_fwrie(...);
+ *                           < --- data is flushed to physical drive
+ *
+ *          When you do:
+ *          ext4_cache_write_back(..., 1);
+ *          ext4_fopen(...);
+ *          ext4_fwrie(...);
+ *                           < --- data is NOT flushed to physical drive
+ *          ext4_cache_write_back(..., 0);
+ *                           < --- when write back mode is disabled all
+ *                                 cache data will be flushed
+ * To enable write back mode permanently just call this function
+ * once after ext4_mount (and disable before ext4_umount).
+ *
+ * Some of the function use write back cache mode internally.
+ * If you enable write back mode twice you have to disable it twice
+ * to flush all data:
+ *
+ *      ext4_cache_write_back(..., 1);
+ *      ext4_cache_write_back(..., 1);
+ *
+ *      ext4_cache_write_back(..., 0);
+ *      ext4_cache_write_back(..., 0);
+ *
+ * Write back mode is useful when you want to create a lot of empty
+ * files/directories.
+ *
+ * @param   path mount point path
+ * @param   on enable/disable
+ *
+ * @return  standard error code */
+int ext4_cache_write_back(const char *path, bool on);
+
+/********************************FILE OPERATIONS*****************************/
+
+/**@brief   Remove file by path.
+ * @param   path path to file
+ * @return  standard error code */
+int ext4_fremove(const char *path);
+
+/**@brief   File open function.
+ * @param   filename, (has to start from mount point)
+ *          /my_partition/my_file
+ * @param   flags open file flags
+ *  |---------------------------------------------------------------|
+ *  |   r or rb                 O_RDONLY                            |
+ *  |---------------------------------------------------------------|
+ *  |   w or wb                 O_WRONLY|O_CREAT|O_TRUNC            |
+ *  |---------------------------------------------------------------|
+ *  |   a or ab                 O_WRONLY|O_CREAT|O_APPEND           |
+ *  |---------------------------------------------------------------|
+ *  |   r+ or rb+ or r+b        O_RDWR                              |
+ *  |---------------------------------------------------------------|
+ *  |   w+ or wb+ or w+b        O_RDWR|O_CREAT|O_TRUNC              |
+ *  |---------------------------------------------------------------|
+ *  |   a+ or ab+ or a+b        O_RDWR|O_CREAT|O_APPEND             |
+ *  |---------------------------------------------------------------|
+ *
+ * @return  standard error code*/
+int ext4_fopen (ext4_file *f, const char *path, const char *flags);
+
+/**@brief   File close function.
+ * @param   f file handle
+ * @return  standard error code*/
+int ext4_fclose(ext4_file *f);
+
+/**@brief   Read data from file.
+ * @param   f file handle
+ * @param   buf output buffer
+ * @param   size bytes to read
+ * @param   rcnt bytes read (may be NULL)
+ * @return  standard error code*/
+int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);
+
+/**@brief   Write data to file.
+ * @param   f file handle
+ * @param   buf data to write
+ * @param   size write length
+ * @param   wcnt bytes written (may be NULL)
+ * @return  standard error code*/
+int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);
+
+/**@brief   File seek operation.
+ * @param   f file handle
+ * @param   offset offset to seek
+ * @param   origin seek type:
+ *              @ref SEEK_SET
+ *              @ref SEEK_CUR
+ *              @ref SEEK_END
+ * @return  standard error code*/
+int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);
+
+/**@brief   Get file position.
+ * @param   f file handle
+ * @return  actual file position */
+uint64_t ext4_ftell (ext4_file *f);
+
+/**@brief   Get file size.
+ * @param   f file handle
+ * @return  file size */
+uint64_t ext4_fsize (ext4_file *f);
+
+/*********************************DIRECTORY OPERATION***********************/
+
+/**@brief   Recursive directory remove.
+ * @param   path directory path to remove
+ * @return  standard error code*/
+int ext4_dir_rm(const char *path);
+
+/**@brief   Create new directory.
+ * @param   name new directory name
+ * @return  standard error code*/
+int ext4_dir_mk(const char *path);
+
+/**@brief   Directory open.
+ * @param   d directory handle
+ * @param   path directory path
+ * @return  standard error code*/
+int ext4_dir_open (ext4_dir *d, const char *path);
+
+/**@brief   Directory close.
+ * @param   d directory handle
+ * @return  standard error code*/
+int ext4_dir_close(ext4_dir *d);
+
+
+/**@brief   Return directory entry by id.
+ * @param   d directory handle
+ * @param   id entry id
+ * @return  directory entry id (NULL id no entry)*/
+ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);
+
+#endif /* EXT4_H_ */
+
+/**
+ * @}
+ */
--- a/toolchain/bf518.cmake
+++ b/toolchain/bf518.cmake
@@ -1,5 +1,5 @@
 # Name of the target
-SET(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_NAME bfin-elf)
 set(CMAKE_SYSTEM_PROCESSOR bf518)
 
 # Toolchain settings
@@ -12,9 +12,9 @@
 set(SIZE                bfin-elf-size)
 
 set(CMAKE_C_FLAGS   "-mcpu=bf518 -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
-set(CMAKE_CXX_FLAGS "-mcpu=bf518 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
+set(CMAKE_CXX_FLAGS "-mcpu=bf518 -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
 set(CMAKE_ASM_FLAGS "-mcpu=bf518 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mcpu=bf592" CACHE INTERNAL "exe link flags")
+set(CMAKE_EXE_LINKER_FLAGS "-mcpu=bf592 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")
 
 
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")
--- a/toolchain/cortex-m3.cmake
+++ b/toolchain/cortex-m3.cmake
@@ -1,5 +1,5 @@
 # Name of the target
-SET(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_NAME arm-none-eabi)
 set(CMAKE_SYSTEM_PROCESSOR cortex-m3)
 
 # Toolchain settings
@@ -14,7 +14,7 @@
 set(CMAKE_C_FLAGS   "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
 set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m3 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
 set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m3" CACHE INTERNAL "asm compiler flags")
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m3" CACHE INTERNAL "exe link flags")
+set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mcpu=cortex-m3 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")
 
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")
--- a/toolchain/cortex-m4.cmake
+++ b/toolchain/cortex-m4.cmake
@@ -1,5 +1,5 @@
 # Name of the target
-SET(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_NAME arm-none-eabi)
 set(CMAKE_SYSTEM_PROCESSOR cortex-m4)
 
 # Toolchain settings
@@ -14,7 +14,7 @@
 set(CMAKE_C_FLAGS   "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
 set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m4 -fno-builtin -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
 set(CMAKE_ASM_FLAGS "-mthumb -mcpu=cortex-m4" CACHE INTERNAL "asm compiler flags")
-set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -Wl,--gc-sections -mthumb -mcpu=cortex-m4" CACHE INTERNAL "exe link flags")
+set(CMAKE_EXE_LINKER_FLAGS " -mthumb -mcpu=cortex-m4 -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags")
 
 
 
@@ -24,5 +24,4 @@
 
 SET(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "c release compiler flags")
 SET(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "cxx release compiler flags")
-SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
-
+SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
\ No newline at end of file
--- /dev/null
+++ b/toolchain/generic.cmake
@@ -1,0 +1,25 @@
+# Name of the target
+set(CMAKE_SYSTEM_PROCESSOR generic)
+
+# Toolchain settings
+set(CMAKE_C_COMPILER    gcc)
+set(CMAKE_CXX_COMPILER  g++)
+set(AS                  as)
+set(AR                  ar)
+set(OBJCOPY             objcopy)
+set(OBJDUMP             objdump)
+set(SIZE                size)
+
+set(CMAKE_C_FLAGS   "-std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags")
+set(CMAKE_CXX_FLAGS "-fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags")
+set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "asm compiler flags")
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections" CACHE INTERNAL "exe link flags")
+
+
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags")
+SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags")
+
+SET(CMAKE_C_FLAGS_RELEASE "-O2" CACHE INTERNAL "c release compiler flags")
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2" CACHE INTERNAL "cxx release compiler flags")
+SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags")
\ No newline at end of file