From 8da7c69e28b253c8d9db5dd9c2eb7ab9637d8836 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Sat, 16 Jun 2007 14:37:02 +0000 Subject: [PATCH] This patch provides a simple API to nrv2b and lzma. Necessary for integrating compression algorithms into lar. lar -x (extract) will be done using the decompression routines in lib/ to ease debugging (just in case - they _should_ be functionally equivalent to the decompression routines in the compression utilities) Signed-off-by: Patrick Georgi Acked-by: Stefan Reinauer git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@356 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- util/lzma/minilzma.cc | 13 +++++++++++++ util/nrv2b/nrv2b.c | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/util/lzma/minilzma.cc b/util/lzma/minilzma.cc index 05f9951b4e..605b43116b 100644 --- a/util/lzma/minilzma.cc +++ b/util/lzma/minilzma.cc @@ -234,6 +234,7 @@ const std::vector LZMADeCompress return result; } +#ifndef COMPACT int main(int argc, char *argv[]) { char *s; @@ -277,4 +278,16 @@ int main(int argc, char *argv[]) fclose(outfile); return EXIT_SUCCESS; } +#else +extern "C" { + +void do_lzma_compress(char* in, unsigned long in_len, char* out, unsigned long* out_len) { + std::vector result; + result = LZMACompress(std::vector(in,in+in_len)); + *out_len = result.size(); + std::memcpy(out, &result[0], *out_len); +} + +} +#endif diff --git a/util/nrv2b/nrv2b.c b/util/nrv2b/nrv2b.c index b9e1c10648..26f4603756 100644 --- a/util/nrv2b/nrv2b.c +++ b/util/nrv2b/nrv2b.c @@ -65,11 +65,13 @@ FILE *infile, *outfile; #define BITSIZE 32 #endif +#ifndef COMPACT static __inline__ void Error(char *message) { Fprintf((stderr, "\n%s\n", message)); exit(EXIT_FAILURE); } +#endif /* These will be a complete waste of time on a lo-endian */ /* system, but it only gets done once so WTF. */ @@ -1213,6 +1215,7 @@ int ucl_nrv2b_99_compress( } +#ifndef COMPACT void Encode(void) /* compression */ { uint8_t *in, *out; @@ -1291,9 +1294,18 @@ void Encode(void) /* compression */ #endif } +#endif #endif +#ifdef COMPACT +void do_nrv2b_compress(char* in, unsigned long in_len, char* out, unsigned long* out_len) { + *out_len = in_len + (in_len/8) + 256; + out = malloc(*out_len); + ucl_nrv2b_99_compress(in, in_len, out, out_len, 0 ); +} +#endif + #ifdef DECODE #define GETBIT_8(bb, src, ilen) \