Skip to content

Commit

Permalink
Move to libarchive
Browse files Browse the repository at this point in the history
Use libarchive for all the decompression operations, in order to reduce
the complexity while supporting more input formats.

Signed-off-by: Francesco Valla <[email protected]>
  • Loading branch information
WallaceIT committed Dec 18, 2024
1 parent 06cf526 commit 32b8036
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 262 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get --no-install-recommends install -y bmap-tools libssl-dev libxml2-dev zlib1g-dev liblzma-dev cppcheck
run: sudo apt-get update && sudo apt-get --no-install-recommends install -y bmap-tools libssl-dev libxml2-dev libarchive-dev cppcheck

- name: Cppcheck
run: cppcheck --enable=all --suppress=missingIncludeSystem *.cpp
Expand Down
29 changes: 6 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,20 @@ else()
message(FATAL_ERROR "OpenSSL not found")
endif()

# Find zlib
find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
# Find libarchive
find_package(LibArchive REQUIRED)
if (LibArchive_FOUND)
include_directories(${LIBARCHIVE_INCLUDE_DIR})
else()
message(FATAL_ERROR "zlib not found")
endif()

# Find liblzma
find_package(LibLZMA REQUIRED)
if (LIBLZMA_FOUND)
include_directories(${LIBLZMA_INCLUDE_DIRS})
else()
message(FATAL_ERROR "liblzma not found")
endif()

# Find libzstd
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET libzstd)
if (ZSTD_FOUND)
include_directories(${ZSTD_INCLUDE_DIRS})
else()
message(FATAL_ERROR "libzstd not found")
message(FATAL_ERROR "libarchive not found")
endif()

# Add the executable
add_executable(bmap-writer bmap-writer.cpp)
target_compile_options(bmap-writer PUBLIC -Wformat -Wformat-security -Wconversion -Wsign-conversion -pedantic -Werror)

# Link the libraries
target_link_libraries(bmap-writer ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBLZMA_LIBRARIES} ${ZSTD_LIBRARIES})
target_link_libraries(bmap-writer ${LIBXML2_LIBRARIES} ${OPENSSL_LIBRARIES} ${LibArchive_LIBRARIES})

# Specify the install rules
install(TARGETS bmap-writer DESTINATION bin)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Unlike the Yocto BMAP tool, `bmap-writer` is C++ based does not require Python a

- **Alternative to Yocto BMAP Tool**: Provides a lightweight alternative specifically for embedded systems.
- **No Python Required**: Does not require Python, making it easier to integrate into various environments.
- **Support for Compressed Images**: Handles gzip, xz anz zstd compressed images, decompressing them on-the-fly during the writing process.
- **Support for Compressed Images**: Handles all compression filters that are supported by `libarchive`, decompressing the data on-the-fly during the writing process.
- **Checksum Verification**: Ensures data integrity by verifying checksums for each block.
- **Efficient Writing**: Writes only the necessary blocks, reducing the overall write time and wear on storage devices.

Expand Down
47 changes: 46 additions & 1 deletion bmap-writer-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,44 @@ if [ ! -f test.img ]; then
dd if=/dev/urandom of=test.img bs=4k count=1 seek=131072 conv=notrunc > /dev/null 2>&1
fi

if [ ! -f test.img.tar ]; then
echo "## Enclose the file inside tar"
tar -cf test.img.tar test.img
fi

if [ ! -f test.img.tar.gz ]; then
echo "## Enclose the file inside tar.gz"
tar -czf test.img.tar.gz test.img
fi

if [ ! -f test.img.bz2 ]; then
echo "## Compress the file with bzip2"
bzip2 -f -k -c test.img > test.img.bz2
fi

if [ ! -f test.img.gz ]; then
echo "## Compress the file with gzip"
gzip -9 test.img -c > test.img.gz
fi

if [ ! -f test.img.lz4 ]; then
echo "## Compress the file with lz4"
lz4 -f -k -c test.img > test.img.lz4
fi

if [ ! -f test.img.lzo ]; then
echo "## Compress the file with lzo"
lzop -f -k -c test.img > test.img.lzo
fi

if [ ! -f test.img.xz ]; then
echo "## Compress the file with xz"
xz -z test.img -c > test.img.xz
fi

if [ ! -f test.img.zst ]; then
echo "## Compress the file with zstd"
zstd -f -k -c -3 --threads=8 test.img > test.img.zst
zstd -f -k -c test.img > test.img.zst
fi

if [ ! -f test.img.bmap ] ; then
Expand All @@ -37,10 +62,30 @@ echo "## Write the file with bmap-writer"
./bmap-writer test.img test.img.bmap test.none.img.out
cmp test.img.out test.none.img.out

echo "## Write the file with bmap-writer and tar"
./bmap-writer test.img.tar test.img.bmap test.tar.img.out
cmp test.img.out test.tar.img.out

echo "## Write the file with bmap-writer and tar+gzip"
./bmap-writer test.img.tar.gz test.img.bmap test.tar.gz.img.out
cmp test.img.out test.tar.gz.img.out

echo "## Write the file with bmap-writer and bzip2"
./bmap-writer test.img.bz2 test.img.bmap test.bz2.img.out
cmp test.img.out test.bz2.img.out

echo "## Write the file with bmap-writer and gzip"
./bmap-writer test.img.gz test.img.bmap test.gz.img.out
cmp test.img.out test.gz.img.out

echo "## Write the file with bmap-writer and lz4"
./bmap-writer test.img.lz4 test.img.bmap test.lz4.img.out
cmp test.img.out test.lz4.img.out

echo "## Write the file with bmap-writer and lzo"
./bmap-writer test.img.lzo test.img.bmap test.lzo.img.out
cmp test.img.out test.lzo.img.out

echo "## Write the file with bmap-writer and xz"
./bmap-writer test.img.xz test.img.bmap test.xz.img.out
cmp test.img.out test.xz.img.out
Expand Down
Loading

0 comments on commit 32b8036

Please sign in to comment.