soc/intel/xeon_sp/ibl: Update registers for reach bootable
[coreboot2.git] / payloads / libpayload / liblzma / lzma.c
blob1845afc88387372fbf94b4a84ea512dcfec1964c
1 /*
2 * coreboot interface to memory-saving variant of LZMA decoder
4 * Copyright (C) 2006 Carl-Daniel Hailfinger
5 * Released under the BSD license
7 * Parts of this file are based on C/7zip/Compress/LZMA_C/LzmaTest.c from the LZMA
8 * SDK 4.42, which is written and distributed to public domain by Igor Pavlov.
12 #include <lzma.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include "lzmadecode.c"
18 unsigned long ulzman(const unsigned char *src, unsigned long srcn,
19 unsigned char *dst, unsigned long dstn)
21 unsigned char properties[LZMA_PROPERTIES_SIZE];
22 const int data_offset = LZMA_PROPERTIES_SIZE + 8;
23 UInt32 outSize;
24 SizeT inProcessed;
25 SizeT outProcessed;
26 int res;
27 CLzmaDecoderState state;
28 SizeT mallocneeds;
29 unsigned char *scratchpad;
31 if (srcn < data_offset) {
32 printf("lzma: Input too small.\n");
33 return 0;
36 memcpy(properties, src, LZMA_PROPERTIES_SIZE);
37 memcpy(&outSize, src + LZMA_PROPERTIES_SIZE, sizeof(outSize));
38 if (outSize > dstn)
39 outSize = dstn;
40 if (LzmaDecodeProperties(&state.Properties, properties,
41 LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
42 printf("lzma: Incorrect stream properties.\n");
43 return 0;
45 mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
46 scratchpad = malloc(mallocneeds);
47 if (!scratchpad) {
48 printf("lzma: Cannot allocate %u bytes for scratchpad!\n",
49 mallocneeds);
50 return 0;
52 state.Probs = (CProb *)scratchpad;
53 res = LzmaDecode(&state, src + data_offset, srcn - data_offset,
54 &inProcessed, dst, outSize, &outProcessed);
55 free(scratchpad);
56 if (res != 0) {
57 printf("lzma: Decoding error = %d\n", res);
58 return 0;
60 return outProcessed;
63 unsigned long ulzma(const unsigned char *src, unsigned char *dst)
65 return ulzman(src, (unsigned long)(-1), dst, (unsigned long)(-1));