blob: 32c46255dd25e76471d4e8fb02a2982fe4b90432 [file] [log] [blame]
Lasse Collinbcc4b362009-03-22 13:12:47 +02001
2XZ Embedded
3===========
4
5 XZ Embedded is a relatively small, limited implementation of the .xz
6 file format. Currently only decoding is implemented.
7
8 XZ Embedded was written for use in the Linux kernel, but the code can
9 be easily used in other environments too, including regular userspace
Lasse Colline111c272012-03-31 10:39:09 +030010 applications. See userspace/xzminidec.c for an example program.
Lasse Collinbcc4b362009-03-22 13:12:47 +020011
12 This README contains information that is useful only when the copy
13 of XZ Embedded isn't part of the Linux kernel tree. You should also
14 read linux/Documentation/xz.txt even if you aren't using XZ Embedded
15 as part of Linux; information in that file is not repeated in this
16 README.
17
18Compiling the Linux kernel module
19
Lasse Collinbcc4b362009-03-22 13:12:47 +020020 The xz_dec module depends on crc32 module, so make sure that you have
21 it enabled (CONFIG_CRC32).
22
Lasse Collin87d16052009-04-26 23:00:31 +030023 Building the xz_dec and xz_dec_test modules without support for BCJ
24 filters:
Lasse Collind8505562009-04-18 00:43:42 +030025
26 cd linux/lib/xz
27 make -C /path/to/kernel/source \
28 KCPPFLAGS=-I"$(pwd)/../../include" M="$(pwd)" \
Lasse Collin87d16052009-04-26 23:00:31 +030029 CONFIG_XZ_DEC=m CONFIG_XZ_DEC_TEST=m
Lasse Collind8505562009-04-18 00:43:42 +030030
Lasse Collin87d16052009-04-26 23:00:31 +030031 Building the xz_dec and xz_dec_test modules with support for BCJ
32 filters:
Lasse Collind8505562009-04-18 00:43:42 +030033
34 cd linux/lib/xz
35 make -C /path/to/kernel/source \
36 KCPPFLAGS=-I"$(pwd)/../../include" M="$(pwd)" \
Lasse Collin87d16052009-04-26 23:00:31 +030037 CONFIG_XZ_DEC=m CONFIG_XZ_DEC_TEST=m CONFIG_XZ_DEC_BCJ=y \
Lasse Collinc66c8902023-04-14 16:27:27 +030038 CONFIG_XZ_DEC_X86=y CONFIG_XZ_DEC_ARM=y \
39 CONFIG_XZ_DEC_ARMTHUMB=y CONFIG_XZ_DEC_ARM64=y \
40 CONFIG_XZ_DEC_POWERPC=y CONFIG_XZ_DEC_IA64=y \
41 CONFIG_XZ_DEC_SPARC=y
Lasse Collind8505562009-04-18 00:43:42 +030042
43 If you want only one or a few of the BCJ filters, omit the appropriate
44 variables. CONFIG_XZ_DEC_BCJ=y is always required to build the support
45 code shared between all BCJ filters.
46
Lasse Collin87d16052009-04-26 23:00:31 +030047 Most people don't need the xz_dec_test module. You can skip building
48 it by omitting CONFIG_XZ_DEC_TEST=m from the make command line.
49
Lasse Collinbcc4b362009-03-22 13:12:47 +020050Compiler requirements
51
52 XZ Embedded should compile as either GNU-C89 (used in the Linux
53 kernel) or with any C99 compiler. Getting the code to compile with
54 non-GNU C89 compiler or a C++ compiler should be quite easy as
55 long as there is a data type for unsigned 64-bit integer (or the
56 code is modified not to support large files, which needs some more
57 care than just using 32-bit integer instead of 64-bit).
58
Lasse Collinca721662010-11-18 20:21:30 +020059 If you use GCC, try to use a recent version. For example, on x86-32,
Lasse Collinbcc4b362009-03-22 13:12:47 +020060 xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when
61 compiled with GCC 4.3.3.
62
63Embedding into userspace applications
64
65 To embed the XZ decoder, copy the following files into a single
66 directory in your source code tree:
67
68 linux/include/linux/xz.h
69 linux/lib/xz/xz_crc32.c
70 linux/lib/xz/xz_dec_lzma2.c
71 linux/lib/xz/xz_dec_stream.c
72 linux/lib/xz/xz_lzma2.h
73 linux/lib/xz/xz_private.h
74 linux/lib/xz/xz_stream.h
Lasse Collin780d6ad2009-04-26 21:04:29 +030075 userspace/xz_config.h
Lasse Collinbcc4b362009-03-22 13:12:47 +020076
77 Alternatively, xz.h may be placed into a different directory but then
78 that directory must be in the compiler include path when compiling
79 the .c files.
80
81 Your code should use only the functions declared in xz.h. The rest of
82 the .h files are meant only for internal use in XZ Embedded.
83
Lasse Collin780d6ad2009-04-26 21:04:29 +030084 You may want to modify xz_config.h to be more suitable for your build
85 environment. Probably you should at least skim through it even if the
86 default file works as is.
87
Lasse Collin6f0e0c42021-05-06 20:18:46 +030088Supporting concatenated .xz files
89
90 Regular .xz files can be concatenated as is and the xz command line
91 tool will decompress all streams from a concatenated file (a few
92 other popular formats and tools support this too). This kind of .xz
93 files aren't as uncommon as one might think because pxz, an early
94 threaded XZ compressor, created this kind of .xz files.
95
96 The xz_dec_run() function will stop after decompressing one stream.
97 This is good when XZ data is stored inside some other file format.
98 However, if one is decompressing regular standalone .xz files, one
99 will want to decompress all streams in the file. This is easy with
100 xz_dec_catrun(). To include support for xz_dec_catrun(), you need
101 to #define XZ_DEC_CONCATENATED in xz_config.h or in compiler flags.
102
Lasse Collin25a02242013-02-27 09:34:49 +0200103Integrity check support
104
105 XZ Embedded always supports the integrity check types None and
106 CRC32. Support for CRC64 is optional. SHA-256 is currently not
107 supported in XZ Embedded although the .xz format does support it.
108 The xz tool from XZ Utils uses CRC64 by default, but CRC32 is usually
109 enough in embedded systems to keep the code size smaller.
110
111 If you want support for CRC64, you need to copy linux/lib/xz/xz_crc64.c
112 into your application, and #define XZ_USE_CRC64 in xz_config.h or in
113 compiler flags.
114
115 When using the internal CRC32 or CRC64, their lookup tables need to be
116 initialized with xz_crc32_init() and xz_crc64_init(), respectively.
117 See xz.h for details.
118
119 To use external CRC32 or CRC64 code instead of the code from
120 xz_crc32.c or xz_crc64.c, the following #defines may be used
121 in xz_config.h or in compiler flags:
122
123 #define XZ_INTERNAL_CRC32 0
124 #define XZ_INTERNAL_CRC64 0
125
126 Then it is up to you to provide compatible xz_crc32() or xz_crc64()
127 functions.
128
129 If the .xz file being decompressed uses an integrity check type that
130 isn't supported by XZ Embedded, it is treated as an error and the
131 file cannot be decompressed. For multi-call mode, this can be modified
132 by #defining XZ_DEC_ANY_CHECK. Then xz_dec_run() will return
133 XZ_UNSUPPORTED_CHECK when unsupported check type is detected. After
134 that decompression can be continued normally except that the
135 integrity check won't be verified. In single-call mode there's
136 no way to continue decoding, so XZ_DEC_ANY_CHECK is almost useless
137 in single-call mode.
138
Lasse Collind8505562009-04-18 00:43:42 +0300139BCJ filter support
140
141 If you want support for one or more BCJ filters, you need to copy also
142 linux/lib/xz/xz_dec_bcj.c into your application, and use appropriate
Lasse Collin780d6ad2009-04-26 21:04:29 +0300143 #defines in xz_config.h or in compiler flags. You don't need these
144 #defines in the code that just uses XZ Embedded via xz.h, but having
145 them always #defined doesn't hurt either.
Lasse Collind8505562009-04-18 00:43:42 +0300146
147 #define Instruction set BCJ filter endianness
Lasse Collinca721662010-11-18 20:21:30 +0200148 XZ_DEC_X86 x86-32 or x86-64 Little endian only
Lasse Collind8505562009-04-18 00:43:42 +0300149 XZ_DEC_POWERPC PowerPC Big endian only
150 XZ_DEC_IA64 Itanium (IA-64) Big or little endian
151 XZ_DEC_ARM ARM Little endian only
152 XZ_DEC_ARMTHUMB ARM-Thumb Little endian only
153 XZ_DEC_SPARC SPARC Big or little endian
154
155 While some architectures are (partially) bi-endian, the endianness
156 setting doesn't change the endianness of the instructions on all
157 architectures. That's why Itanium and SPARC filters work for both big
158 and little endian executables (Itanium has little endian instructions
159 and SPARC has big endian instructions).
160
161 There currently is no filter for little endian PowerPC or big endian
162 ARM or ARM-Thumb. Implementing filters for them can be considered if
163 there is a need for such filters in real-world applications.
164
165Notes about shared libraries
166
Lasse Collinbcc4b362009-03-22 13:12:47 +0200167 If you are including XZ Embedded into a shared library, you very
168 probably should rename the xz_* functions to prevent symbol
169 conflicts in case your library is linked against some other library
170 or application that also has XZ Embedded in it (which may even be
171 a different version of XZ Embedded). TODO: Provide an easy way
172 to do this.
173
Lasse Collind8505562009-04-18 00:43:42 +0300174 Please don't create a shared library of XZ Embedded itself unless
175 it is fine to rebuild everything depending on that shared library
176 everytime you upgrade to a newer version of XZ Embedded. There are
177 no API or ABI stability guarantees between different versions of
178 XZ Embedded.
Lasse Collinbcc4b362009-03-22 13:12:47 +0200179