summaryrefslogtreecommitdiffstats
path: root/lib/xz/xz_stream.h
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-10-17 15:36:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-11-04 12:18:55 +0100
commitccb281647704d6857d3491dc71746d2f7ce38fa7 (patch)
tree174abba08cfce552c97535d9c0abd1f8b32a99f5 /lib/xz/xz_stream.h
parent2f81d316d21113ab4288fbd3e84c03bf6f0c08ed (diff)
downloadbarebox-ccb281647704d6857d3491dc71746d2f7ce38fa7.tar.gz
barebox-ccb281647704d6857d3491dc71746d2f7ce38fa7.tar.xz
Add xz decompression support
This adds xz decompression support from the kernel. Both compressing the barebox binary with xz and decompressing xz files on the commandline is supported. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/xz/xz_stream.h')
-rw-r--r--lib/xz/xz_stream.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/xz/xz_stream.h b/lib/xz/xz_stream.h
new file mode 100644
index 0000000000..4b333e394b
--- /dev/null
+++ b/lib/xz/xz_stream.h
@@ -0,0 +1,61 @@
+/*
+ * Definitions for handling the .xz file format
+ *
+ * Author: Lasse Collin <lasse.collin@tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_STREAM_H
+#define XZ_STREAM_H
+
+#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
+# undef crc32
+# define xz_crc32(buf, size, crc) \
+ (~crc32_le(~(uint32_t)(crc), buf, size))
+#endif
+
+/*
+ * See the .xz file format specification at
+ * http://tukaani.org/xz/xz-file-format.txt
+ * to understand the container format.
+ */
+
+#define STREAM_HEADER_SIZE 12
+
+#define HEADER_MAGIC "\3757zXZ"
+#define HEADER_MAGIC_SIZE 6
+
+#define FOOTER_MAGIC "YZ"
+#define FOOTER_MAGIC_SIZE 2
+
+/*
+ * Variable-length integer can hold a 63-bit unsigned integer or a special
+ * value indicating that the value is unknown.
+ *
+ * Experimental: vli_type can be defined to uint32_t to save a few bytes
+ * in code size (no effect on speed). Doing so limits the uncompressed and
+ * compressed size of the file to less than 256 MiB and may also weaken
+ * error detection slightly.
+ */
+typedef uint64_t vli_type;
+
+#define VLI_MAX ((vli_type)-1 / 2)
+#define VLI_UNKNOWN ((vli_type)-1)
+
+/* Maximum encoded size of a VLI */
+#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
+
+/* Integrity Check types */
+enum xz_check {
+ XZ_CHECK_NONE = 0,
+ XZ_CHECK_CRC32 = 1,
+ XZ_CHECK_CRC64 = 4,
+ XZ_CHECK_SHA256 = 10
+};
+
+/* Maximum possible Check ID */
+#define XZ_CHECK_MAX 15
+
+#endif