diff --git a/binfmt/binfmt_dumpmodule.c b/binfmt/binfmt_dumpmodule.c index a28f4cefee..a94f76930c 100644 --- a/binfmt/binfmt_dumpmodule.c +++ b/binfmt/binfmt_dumpmodule.c @@ -49,22 +49,6 @@ #if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_DEBUG_BINFMT) && !defined(CONFIG_BINFMT_DISABLE) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/binfmt/binfmt_exepath.c b/binfmt/binfmt_exepath.c index 7e286c1336..18af9643ca 100644 --- a/binfmt/binfmt_exepath.c +++ b/binfmt/binfmt_exepath.c @@ -52,10 +52,6 @@ #if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -67,14 +63,6 @@ struct exepath_s }; #define SIZEOF_EXEPATH_S(n) (sizeof(struct exepath_s) + (n) - 1) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/binfmt/binfmt_loadmodule.c b/binfmt/binfmt_loadmodule.c index ea5def2acb..1eade3b38c 100644 --- a/binfmt/binfmt_loadmodule.c +++ b/binfmt/binfmt_loadmodule.c @@ -51,18 +51,6 @@ #ifndef CONFIG_BINFMT_DISABLE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/binfmt/binfmt_register.c b/binfmt/binfmt_register.c index 48ddfc1daa..343217aabc 100644 --- a/binfmt/binfmt_register.c +++ b/binfmt/binfmt_register.c @@ -50,22 +50,6 @@ #ifndef CONFIG_BINFMT_DISABLE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -97,6 +81,7 @@ int register_binfmt(FAR struct binfmt_s *binfmt) sched_unlock(); return OK; } + return -EINVAL; } diff --git a/binfmt/binfmt_unloadmodule.c b/binfmt/binfmt_unloadmodule.c index d3c23058bd..8c472f5fe5 100644 --- a/binfmt/binfmt_unloadmodule.c +++ b/binfmt/binfmt_unloadmodule.c @@ -52,18 +52,6 @@ #ifndef CONFIG_BINFMT_DISABLE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/configs/sama5d4-ek/README.txt b/configs/sama5d4-ek/README.txt index fa063560b7..66779056b4 100644 --- a/configs/sama5d4-ek/README.txt +++ b/configs/sama5d4-ek/README.txt @@ -3920,6 +3920,18 @@ Configurations Application Configurations -> Examples -> ELF Loader Example CONFIG_EXAMPLES_ELF_SYSCALL=y : Link apps with the SYStem call library + 5. By default, this configuration uses the ROMFS file system. It can also + be modified to use the compressed CROMFS: + + -CONFIG_PATH_INITIAL="/mnt/romfs" + +CONFIG_PATH_INITIAL="/mnt/cromfs" + + -CONFIG_FS_ROMFS=y + +CONFIG_FS_CROMFS=y + + -CONFIG_EXAMPLES_ELF_ROMFS=y + +CONFIG_EXAMPLES_ELF_CROMFS=y + STATUS: 2014-8-24: This configuration works with the address environment and system call options disabled. diff --git a/configs/stm32f4discovery/README.txt b/configs/stm32f4discovery/README.txt index 360711e85e..ab7738c1e3 100644 --- a/configs/stm32f4discovery/README.txt +++ b/configs/stm32f4discovery/README.txt @@ -1150,7 +1150,19 @@ Where is one of the following: CONFIG_EXAMPLES_ELF_CXXINITIALIZE=y CONFIG_EXAMPLES_ELF_UCLIBCXX=y - 4. The network initialization thread is enabled in this configuration. + 7. By default, this configuration uses the ROMFS file system. It can also + be modified to use the compressed CROMFS: + + -CONFIG_PATH_INITIAL="/mnt/romfs" + +CONFIG_PATH_INITIAL="/mnt/cromfs" + + -CONFIG_FS_ROMFS=y + +CONFIG_FS_CROMFS=y + + -CONFIG_EXAMPLES_ELF_ROMFS=y + +CONFIG_EXAMPLES_ELF_CROMFS=y + + 8. The network initialization thread is enabled in this configuration. As a result, networking initialization is performed asynchronously with NSH bring-up. diff --git a/fs/cromfs/Kconfig b/fs/cromfs/Kconfig index 1928bc7c2a..c4932088f1 100644 --- a/fs/cromfs/Kconfig +++ b/fs/cromfs/Kconfig @@ -8,6 +8,7 @@ config FS_CROMFS default n depends on !DISABLE_MOUNTPOINT select FS_READABLE + select LIBC_LZF ---help--- Enable Compessed Read-Only Filesystem (CROMFS) support diff --git a/fs/cromfs/README.txt b/fs/cromfs/README.txt index 408c3ea07f..2beb37f6e6 100644 --- a/fs/cromfs/README.txt +++ b/fs/cromfs/README.txt @@ -236,13 +236,21 @@ configuration: CONFIG_LIBC_LZF=y + NOTE: This should be selected automatically when CONFIG_FS_CROMFS + is enabled. + 2. Enable the CROMFS file system: CONFIG_FS_CROMFS=y -3. Enable the apps/examples/cromfs example if you like: +3. Enable the apps/examples/cromfs example: CONFIG_EXAMPLES_CROMFS=y + Or the apps/examples/elf example if you like: + + CONFIG_EXAMPLES_ELF=y + CONFIG_EXAMPLES_ELF_CROMFS=y + Or implement your own custom CROMFS file system that example as a guideline. diff --git a/fs/cromfs/fs_cromfs.c b/fs/cromfs/fs_cromfs.c index d985934399..3a186af8c9 100644 --- a/fs/cromfs/fs_cromfs.c +++ b/fs/cromfs/fs_cromfs.c @@ -71,6 +71,8 @@ struct cromfs_file_s { FAR const struct cromfs_node_s *ff_node; /* The open file node */ + uint32_t ff_offset; /* Cached offset (zero means none) */ + uint32_t ff_ulen; /* Length of uncompressed data in cache */ FAR uint8_t *ff_buffer; /* Decompression buffer */ }; @@ -720,31 +722,49 @@ static ssize_t cromfs_read(FAR struct file *filep, FAR char *buffer, src = (FAR const uint8_t *)currhdr + LZF_TYPE0_HDR_SIZE; memcpy(dest, &src[copyoffs], copysize); + + finfo("blkoffs=%lu ulen=%u copysize=%u\n", + (unsigned long)blkoffs, ulen, copysize); } else { - unsigned int decomplen; - /* If the source of the data is at the beginning of the compressed - * data buffer, then we can decompress directly into the user buffer. + * data buffer and if the uncompressed data would not overrun the + * buffer, then we can decompress directly into the user buffer. */ - if (filep->f_pos <= blkoffs) + if (filep->f_pos <= blkoffs && ulen <= remaining) { + uint32_t voloffs; + copyoffs = 0; copysize = ulen; - if (copysize > remaining) + + /* Get the address and offset in the CROMFS image to obtain + * the data. Check if we already have this offset in the + * cache. + */ + + src = (FAR const uint8_t *)currhdr + LZF_TYPE1_HDR_SIZE; + voloffs = cromfs_addr2offset(fs, src); + if (voloffs != ff->ff_offset) { - copysize = remaining; + unsigned int decomplen; + + decomplen = lzf_decompress(src, clen, dest, fs->cv_bsize); + + ff->ff_offset = voloffs; + ff->ff_ulen = decomplen; } - src = (FAR const uint8_t *)currhdr + LZF_TYPE1_HDR_SIZE; - decomplen = lzf_decompress(src, clen, dest, copysize); - DEBUGASSERT(decomplen == copysize); + finfo("voloffs=%lu blkoffs=%lu ulen=%u ff_offset=%u copysize=%u\n", + (unsigned long)voloffs, (unsigned long)blkoffs, ulen, + ff->ff_offset, copysize); + DEBUGASSERT(ff->ff_ulen >= copysize); } else { - unsigned int outsize; + uint32_t voloffs; /* No, we will need to decompress into the our intermediate * decompression buffer. @@ -759,12 +779,26 @@ static ssize_t cromfs_read(FAR struct file *filep, FAR char *buffer, copysize = remaining; } - outsize = copyoffs + copysize; - DEBUGASSERT(outsize <= fs->cv_bsize); + DEBUGASSERT((copyoffs + copysize) <= fs->cv_bsize); src = (FAR const uint8_t *)currhdr + LZF_TYPE1_HDR_SIZE; - decomplen = lzf_decompress(src, clen, ff->ff_buffer, outsize); - DEBUGASSERT(decomplen == outsize); + voloffs = cromfs_addr2offset(fs, src); + if (voloffs != ff->ff_offset) + { + unsigned int decomplen; + + decomplen = lzf_decompress(src, clen, ff->ff_buffer, + fs->cv_bsize); + + ff->ff_offset = voloffs; + ff->ff_ulen = decomplen; + } + + finfo("voloffs=%lu blkoffs=%lu ulen=%u clen=%u ff_offset=%u " + "copyoffs=%u copysize=%u\n", + (unsigned long)voloffs, (unsigned long)blkoffs, ulen, + clen, ff->ff_offset, copyoffs, copysize); + DEBUGASSERT(ff->ff_ulen >= (copyoffs + copysize)); /* Then copy to user buffer */ diff --git a/libc/lzf/lzf_d.c b/libc/lzf/lzf_d.c index 386b95c669..87bd3561f6 100644 --- a/libc/lzf/lzf_d.c +++ b/libc/lzf/lzf_d.c @@ -233,7 +233,7 @@ unsigned int lzf_decompress (FAR const void *const in_data, #ifdef lzf_movsb len += 2; - lzf_movsb (op, ref, len); + lzf_movsb(op, ref, len); #else switch (len) {