diff --git a/.gitmodules b/.gitmodules index a1502149e..289d25b98 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "lz4"] path = native/src/external/lz4 url = https://github.com/lz4/lz4.git -[submodule "bzip2"] - path = native/src/external/bzip2 - url = https://github.com/nemequ/bzip2.git [submodule "xz"] path = native/src/external/xz url = https://github.com/xz-mirror/xz.git diff --git a/native/src/Android.mk b/native/src/Android.mk index 701ec61d7..d4a418db7 100644 --- a/native/src/Android.mk +++ b/native/src/Android.mk @@ -88,7 +88,6 @@ LOCAL_STATIC_LIBRARIES := \ libbase \ liblzma \ liblz4 \ - libbz2 \ libzopfli \ libboot-rs diff --git a/native/src/Cargo.lock b/native/src/Cargo.lock index dba9b12c6..efa10ab38 100644 --- a/native/src/Cargo.lock +++ b/native/src/Cargo.lock @@ -446,6 +446,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "libbz2-rs-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0864a00c8d019e36216b69c2c4ce50b83b7bd966add3cf5ba554ec44f8bebcf5" +dependencies = [ + "libc", +] + [[package]] name = "libc" version = "0.2.170" @@ -498,6 +507,7 @@ dependencies = [ "der", "digest", "fdt", + "libbz2-rs-sys", "libz-rs-sys", "num-traits", "p256", diff --git a/native/src/Cargo.toml b/native/src/Cargo.toml index 17374a381..d56a51d33 100644 --- a/native/src/Cargo.toml +++ b/native/src/Cargo.toml @@ -35,6 +35,7 @@ quote = "1" proc-macro2 = "1" argh = { version = "0.1.13", default-features = false } libz-rs-sys = { version = "0.4.2", default-features = false, features=["c-allocator"] } +libbz2-rs-sys = { version = "0.1.3", default-features = false, features = ["c-allocator"] } # Pin version to prevent cargo update break builds block-buffer = "=0.11.0-rc.3" diff --git a/native/src/boot/Cargo.toml b/native/src/boot/Cargo.toml index ffa9af7c9..40f012821 100644 --- a/native/src/boot/Cargo.toml +++ b/native/src/boot/Cargo.toml @@ -33,3 +33,4 @@ fdt = { workspace = true } bytemuck = { workspace = true, features = ["derive", "min_const_generics"] } num-traits = { workspace = true } libz-rs-sys = { workspace = true } +libbz2-rs-sys = { workspace = true } diff --git a/native/src/boot/bzlib.h b/native/src/boot/bzlib.h new file mode 100644 index 000000000..96e1b546d --- /dev/null +++ b/native/src/boot/bzlib.h @@ -0,0 +1,287 @@ + +/*-------------------------------------------------------------*/ +/*--- Public header file for the library. ---*/ +/*--- bzlib.h ---*/ +/*-------------------------------------------------------------*/ + +/* ------------------------------------------------------------------ + This file is part of bzip2/libbzip2, a program and library for + lossless, block-sorting data compression. + + bzip2/libbzip2 version 1.1.0 of 6 September 2010 + Copyright (C) 1996-2010 Julian Seward + + Please read the WARNING, DISCLAIMER and PATENTS sections in the + README file. + + This program is released under the terms of the license contained + in the file LICENSE. + ------------------------------------------------------------------ */ + + +#ifndef _BZLIB_H +#define _BZLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define BZ_RUN 0 +#define BZ_FLUSH 1 +#define BZ_FINISH 2 + +#define BZ_OK 0 +#define BZ_RUN_OK 1 +#define BZ_FLUSH_OK 2 +#define BZ_FINISH_OK 3 +#define BZ_STREAM_END 4 +#define BZ_SEQUENCE_ERROR (-1) +#define BZ_PARAM_ERROR (-2) +#define BZ_MEM_ERROR (-3) +#define BZ_DATA_ERROR (-4) +#define BZ_DATA_ERROR_MAGIC (-5) +#define BZ_IO_ERROR (-6) +#define BZ_UNEXPECTED_EOF (-7) +#define BZ_OUTBUFF_FULL (-8) +#define BZ_CONFIG_ERROR (-9) + +typedef + struct { + char *next_in; + unsigned int avail_in; + unsigned int total_in_lo32; + unsigned int total_in_hi32; + + char *next_out; + unsigned int avail_out; + unsigned int total_out_lo32; + unsigned int total_out_hi32; + + void *state; + + void *(*bzalloc)(void *,int,int); + void (*bzfree)(void *,void *); + void *opaque; + } + bz_stream; + + +#ifndef BZ_IMPORT +#define BZ_EXPORT +#endif + +#ifndef BZ_NO_STDIO +/* Need a definitition for FILE */ +#include +#endif + +#ifdef _WIN32 +# include +# ifdef small + /* windows.h define small to char */ +# undef small +# endif +# ifndef WINAPI +# define WINAPI +# endif +# ifdef BZ_EXPORT +# define BZ_API(func) WINAPI func +# define BZ_EXTERN extern +# else + /* import windows dll dynamically */ +# define BZ_API(func) (WINAPI * func) +# define BZ_EXTERN +# endif +#else +# define BZ_API(func) func +#endif + +#ifndef BZ_EXTERN +#define BZ_EXTERN extern +#endif + +/*-- Core (low-level) library functions --*/ + +BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( + bz_stream* strm, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN int BZ_API(BZ2_bzCompress) ( + bz_stream* strm, + int action + ); + +BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( + bz_stream* strm + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( + bz_stream *strm, + int verbosity, + int small + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( + bz_stream* strm + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( + bz_stream *strm + ); + + + +/*-- High(er) level library functions --*/ + +#ifndef BZ_NO_STDIO +#define BZ_MAX_UNUSED 5000 + +typedef void BZFILE; + +BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( + int* bzerror, + FILE* f, + int verbosity, + int small, + void* unused, + int nUnused + ); + +BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( + int* bzerror, + BZFILE* b + ); + +BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( + int* bzerror, + BZFILE* b, + void** unused, + int* nUnused + ); + +BZ_EXTERN int BZ_API(BZ2_bzRead) ( + int* bzerror, + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( + int* bzerror, + FILE* f, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN void BZ_API(BZ2_bzWrite) ( + int* bzerror, + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( + int* bzerror, + BZFILE* b, + int abandon, + unsigned int* nbytes_in, + unsigned int* nbytes_out + ); + +BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( + int* bzerror, + BZFILE* b, + int abandon, + unsigned int* nbytes_in_lo32, + unsigned int* nbytes_in_hi32, + unsigned int* nbytes_out_lo32, + unsigned int* nbytes_out_hi32 + ); +#endif + + +/*-- Utility functions --*/ + +BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( + char* dest, + unsigned int* destLen, + char* source, + unsigned int sourceLen, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( + char* dest, + unsigned int* destLen, + char* source, + unsigned int sourceLen, + int small, + int verbosity + ); + + +/*-- + Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) + to support better zlib compatibility. + This code is not _officially_ part of libbzip2 (yet); + I haven't tested it, documented it, or considered the + threading-safeness of it. + If this code breaks, please contact both Yoshioka and me. +--*/ + +BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( + void + ); + +#ifndef BZ_NO_STDIO +BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( + const char *path, + const char *mode + ); + +BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( + int fd, + const char *mode + ); + +BZ_EXTERN int BZ_API(BZ2_bzread) ( + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN int BZ_API(BZ2_bzwrite) ( + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN int BZ_API(BZ2_bzflush) ( + BZFILE* b + ); + +BZ_EXTERN void BZ_API(BZ2_bzclose) ( + BZFILE* b + ); + +BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( + BZFILE *b, + int *errnum + ); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/*-------------------------------------------------------------*/ +/*--- end bzlib.h ---*/ +/*-------------------------------------------------------------*/ diff --git a/native/src/boot/compress.cpp b/native/src/boot/compress.cpp index cb099c666..c99a8aa3c 100644 --- a/native/src/boot/compress.cpp +++ b/native/src/boot/compress.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "bzlib.h" #include #include #include diff --git a/native/src/boot/lib.rs b/native/src/boot/lib.rs index 43f03e457..d628aa2ef 100644 --- a/native/src/boot/lib.rs +++ b/native/src/boot/lib.rs @@ -4,6 +4,7 @@ #![feature(try_blocks)] pub use libz_rs_sys::*; +pub use libbz2_rs_sys::*; pub use base; use cpio::cpio_commands; use dtb::dtb_commands; diff --git a/native/src/external/Android.mk b/native/src/external/Android.mk index 083ba4803..1e9e6baa9 100644 --- a/native/src/external/Android.mk +++ b/native/src/external/Android.mk @@ -23,21 +23,6 @@ LOCAL_SRC_FILES := \ lz4/lib/xxhash.c include $(BUILD_STATIC_LIBRARY) -# libbz2.a -include $(CLEAR_VARS) -LOCAL_MODULE := libbz2 -LOCAL_C_INCLUDES := $(LOCAL_PATH)/bzip2 -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) -LOCAL_SRC_FILES := \ - bzip2/blocksort.c \ - bzip2/huffman.c \ - bzip2/crctable.c \ - bzip2/randtable.c \ - bzip2/compress.c \ - bzip2/decompress.c \ - bzip2/bzlib.c -include $(BUILD_STATIC_LIBRARY) - # liblzma.a include $(CLEAR_VARS) LOCAL_MODULE := liblzma diff --git a/native/src/external/bzip2 b/native/src/external/bzip2 deleted file mode 160000 index 67d818584..000000000 --- a/native/src/external/bzip2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 67d818584d505503c2bdbd15aec43e6219642762