From 432b91c39009da7fd978667add7714a14abbddc0 Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Thu, 18 Nov 2021 13:20:10 +0100 Subject: [PATCH] Add support for zephyr RTOS Zephyr does not provide compression libraries such as gzip or zlib. Uzlib is a good candidate as a small footprint library. This adds support to integrate and build uzlib as zephyr module. Changes: * Use <> type include instead of quote includes for uzlib_conf.h to be able to override conf for zephyr. * Added zephyr directory for module build variant * Ported uzlib configuration to Kconfig Features: * Module can be configured to build for compression or/and decompression * Uzlib configuration through Kconfig --- src/makefile | 2 +- src/uzlib.h | 2 +- zephyr/CMakeLists.txt | 21 +++++++++++++++++++++ zephyr/Kconfig | 41 +++++++++++++++++++++++++++++++++++++++++ zephyr/module.yml | 3 +++ zephyr/uzlib_conf.h | 27 +++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 zephyr/CMakeLists.txt create mode 100644 zephyr/Kconfig create mode 100644 zephyr/module.yml create mode 100644 zephyr/uzlib_conf.h diff --git a/src/makefile b/src/makefile index 3ced616..37b023a 100644 --- a/src/makefile +++ b/src/makefile @@ -27,7 +27,7 @@ $(target): $(objects) ranlib $@ %.o : %.c - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(CFLAGS) -o $@ -I. -c $< %.o : %.nas nasm -o $@ -f elf -D_ELF_ -O3 -Inasm/ $< diff --git a/src/uzlib.h b/src/uzlib.h index 681ad74..98e8aaa 100644 --- a/src/uzlib.h +++ b/src/uzlib.h @@ -43,7 +43,7 @@ extern "C" { #endif -#include "uzlib_conf.h" +#include #if UZLIB_CONF_DEBUG_LOG #include #endif diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt new file mode 100644 index 0000000..bf70ffa --- /dev/null +++ b/zephyr/CMakeLists.txt @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: Apache-2.0 +if(CONFIG_UZLIB) +zephyr_include_directories( + . + ../src +) + +zephyr_library_sources( + ../src/crc32.c +) +zephyr_library_sources_ifdef(CONFIG_UZLIB_DECOMPRESS + ../src/adler32.c + ../src/tinflate.c + ../src/tinfgzip.c + ../src/tinfzlib.c +) +zephyr_library_sources_ifdef(CONFIG_UZLIB_COMPRESS + ../src/genlz77.c + ../src/defl_static.c +) +endif() \ No newline at end of file diff --git a/zephyr/Kconfig b/zephyr/Kconfig new file mode 100644 index 0000000..086eaa2 --- /dev/null +++ b/zephyr/Kconfig @@ -0,0 +1,41 @@ +# uzlib module configuration options + +config UZLIB + bool "Enable uzlib library" + +if UZLIB + +config UZLIB_COMPRESS + bool "Enable compression" + default y + +config UZLIB_DECOMPRESS + bool "Enable decompression" + default n + +config UZLIB_DEBUG_LOG + int "Debug log level" + default 0 + help + Debug logging level 0, 1, 2, etc. + +config UZLIB_PARANOID_CHECKS + bool "Enable paranoid checks" + default n + help + Perform extra checks on the input stream, even if they aren't proven + to be strictly required (== lack of them wasn't proven to lead to + crashes). + +config UZLIB_USE_MEMCPY + bool "Enable memcpy" + default n + help + Use memcpy() for copying data out of LZ window or uncompressed blocks, + instead of doing this byte by byte. For well-compressed data, this + may noticeably increase decompression speed. But for less compressed, + it can actually deteriorate it (due to the fact that many memcpy() + implementations are optimized for large blocks of data, and have + too much overhead for short strings of just a few bytes). + +endif # UZLIB diff --git a/zephyr/module.yml b/zephyr/module.yml new file mode 100644 index 0000000..cbff6a1 --- /dev/null +++ b/zephyr/module.yml @@ -0,0 +1,3 @@ +build: + cmake: zephyr + kconfig: zephyr/Kconfig diff --git a/zephyr/uzlib_conf.h b/zephyr/uzlib_conf.h new file mode 100644 index 0000000..18c56e4 --- /dev/null +++ b/zephyr/uzlib_conf.h @@ -0,0 +1,27 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + */ +#ifndef UZLIB_CONF_H_INCLUDED +#define UZLIB_CONF_H_INCLUDED + +#include + +/* Debug logging level 0, 1, 2, etc. */ +#define UZLIB_CONF_DEBUG_LOG CONFIG_UZLIB_DEBUG_LOG + +/* Perform extra checks on the input stream, even if they aren't proven + to be strictly required (== lack of them wasn't proven to lead to + crashes). */ +#define UZLIB_CONF_PARANOID_CHECKS IS_ENABLED(CONFIG_UZLIB_PARANOID_CHECKS) + +/* Use memcpy() for copying data out of LZ window or uncompressed blocks, + instead of doing this byte by byte. For well-compressed data, this + may noticeably increase decompression speed. But for less compressed, + it can actually deteriorate it (due to the fact that many memcpy() + implementations are optimized for large blocks of data, and have + too much overhead for short strings of just a few bytes). */ +#define UZLIB_CONF_USE_MEMCPY IS_ENABLED(CONFIG_UZLIB_USE_MEMCPY) + +#endif /* UZLIB_CONF_H_INCLUDED */