summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/fdtdec.c3
-rw-r--r--lib/lmb.c2
-rw-r--r--lib/lz4_wrapper.c95
-rw-r--r--lib/zlib/inftrees.c19
4 files changed, 50 insertions, 69 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 0dd7ff1ac3f..934944d97fd 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1582,7 +1582,8 @@ int fdtdec_resetup(int *rescan)
#ifdef CONFIG_NR_DRAM_BANKS
int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
- phys_addr_t *basep, phys_size_t *sizep, bd_t *bd)
+ phys_addr_t *basep, phys_size_t *sizep,
+ struct bd_info *bd)
{
int addr_cells, size_cells;
const u32 *cell, *end;
diff --git a/lib/lmb.c b/lib/lmb.c
index 008bcc7930d..2d680d8d02f 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -111,7 +111,7 @@ static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
}
/* Initialize the struct, add memory and call arch/board reserve functions */
-void lmb_init_and_reserve(struct lmb *lmb, bd_t *bd, void *fdt_blob)
+void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob)
{
#ifdef CONFIG_NR_DRAM_BANKS
int i;
diff --git a/lib/lz4_wrapper.c b/lib/lz4_wrapper.c
index 1e1e8d50853..e0f7d3688ee 100644
--- a/lib/lz4_wrapper.c
+++ b/lib/lz4_wrapper.c
@@ -9,6 +9,7 @@
#include <lz4.h>
#include <linux/kernel.h>
#include <linux/types.h>
+#include <asm/unaligned.h>
static u16 LZ4_readLE16(const void *src) { return le16_to_cpu(*(u16 *)src); }
static void LZ4_copy4(void *dst, const void *src) { *(u32 *)dst = *(u32 *)src; }
@@ -22,45 +23,10 @@ typedef uint64_t U64;
#define FORCE_INLINE static inline __attribute__((always_inline))
-/* Unaltered (except removing unrelated code) from github.com/Cyan4973/lz4. */
+/* lz4.c is unaltered (except removing unrelated code) from github.com/Cyan4973/lz4. */
#include "lz4.c" /* #include for inlining, do not link! */
-struct lz4_frame_header {
- u32 magic;
- union {
- u8 flags;
- struct {
- u8 reserved0:2;
- u8 has_content_checksum:1;
- u8 has_content_size:1;
- u8 has_block_checksum:1;
- u8 independent_blocks:1;
- u8 version:2;
- };
- };
- union {
- u8 block_descriptor;
- struct {
- u8 reserved1:4;
- u8 max_block_size:3;
- u8 reserved2:1;
- };
- };
- /* + u64 content_size iff has_content_size is set */
- /* + u8 header_checksum */
-} __packed;
-
-struct lz4_block_header {
- union {
- u32 raw;
- struct {
- u32 size:31;
- u32 not_compressed:1;
- };
- };
- /* + size bytes of data */
- /* + u32 block_checksum iff has_block_checksum is set */
-} __packed;
+#define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U
int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn)
{
@@ -72,53 +38,70 @@ int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn)
*dstn = 0;
{ /* With in-place decompression the header may become invalid later. */
- const struct lz4_frame_header *h = in;
+ u32 magic;
+ u8 flags, version, independent_blocks, has_content_size;
+ u8 block_desc;
- if (srcn < sizeof(*h) + sizeof(u64) + sizeof(u8))
+ if (srcn < sizeof(u32) + 3*sizeof(u8))
return -EINVAL; /* input overrun */
+ magic = get_unaligned_le32(in);
+ in += sizeof(u32);
+ flags = *(u8 *)in;
+ in += sizeof(u8);
+ block_desc = *(u8 *)in;
+ in += sizeof(u8);
+
+ version = (flags >> 6) & 0x3;
+ independent_blocks = (flags >> 5) & 0x1;
+ has_block_checksum = (flags >> 4) & 0x1;
+ has_content_size = (flags >> 3) & 0x1;
+
/* We assume there's always only a single, standard frame. */
- if (le32_to_cpu(h->magic) != LZ4F_MAGIC || h->version != 1)
+ if (magic != LZ4F_MAGIC || version != 1)
return -EPROTONOSUPPORT; /* unknown format */
- if (h->reserved0 || h->reserved1 || h->reserved2)
- return -EINVAL; /* reserved must be zero */
- if (!h->independent_blocks)
+ if ((flags & 0x03) || (block_desc & 0x8f))
+ return -EINVAL; /* reserved bits must be zero */
+ if (!independent_blocks)
return -EPROTONOSUPPORT; /* we can't support this yet */
- has_block_checksum = h->has_block_checksum;
- in += sizeof(*h);
- if (h->has_content_size)
+ if (has_content_size) {
+ if (srcn < sizeof(u32) + 3*sizeof(u8) + sizeof(u64))
+ return -EINVAL; /* input overrun */
in += sizeof(u64);
+ }
+ /* Header checksum byte */
in += sizeof(u8);
}
while (1) {
- struct lz4_block_header b;
+ u32 block_header, block_size;
- b.raw = le32_to_cpu(*(u32 *)in);
- in += sizeof(struct lz4_block_header);
+ block_header = get_unaligned_le32(in);
+ in += sizeof(u32);
+ block_size = block_header & ~LZ4F_BLOCKUNCOMPRESSED_FLAG;
- if (in - src + b.size > srcn) {
+ if (in - src + block_size > srcn) {
ret = -EINVAL; /* input overrun */
break;
}
- if (!b.size) {
+ if (!block_size) {
ret = 0; /* decompression successful */
break;
}
- if (b.not_compressed) {
- size_t size = min((ptrdiff_t)b.size, end - out);
+ if (block_header & LZ4F_BLOCKUNCOMPRESSED_FLAG) {
+ size_t size = min((ptrdiff_t)block_size, end - out);
memcpy(out, in, size);
out += size;
- if (size < b.size) {
+ if (size < block_size) {
ret = -ENOBUFS; /* output overrun */
break;
}
} else {
/* constant folding essential, do not touch params! */
- ret = LZ4_decompress_generic(in, out, b.size,
+ ret = LZ4_decompress_generic(in, out, block_size,
end - out, endOnInputSize,
full, 0, noDict, out, NULL, 0);
if (ret < 0) {
@@ -128,7 +111,7 @@ int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn)
out += ret;
}
- in += b.size;
+ in += block_size;
if (has_block_checksum)
in += sizeof(u32);
}
diff --git a/lib/zlib/inftrees.c b/lib/zlib/inftrees.c
index b71b9695a84..caee502f885 100644
--- a/lib/zlib/inftrees.c
+++ b/lib/zlib/inftrees.c
@@ -50,7 +50,7 @@ int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes,
code FAR *next; /* next available space in table */
const unsigned short FAR *base; /* base value table to use */
const unsigned short FAR *extra; /* extra bits table to use */
- int end; /* use base and extra for symbol > end */
+ unsigned match; /* use base and extra for symbol >= match */
unsigned short count[MAXBITS+1]; /* number of codes of each length */
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
@@ -178,19 +178,17 @@ int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes,
switch (type) {
case CODES:
base = extra = work; /* dummy value--not used */
- end = 19;
+ match = 20;
break;
case LENS:
base = lbase;
- base -= 257;
extra = lext;
- extra -= 257;
- end = 256;
+ match = 257;
break;
default: /* DISTS */
base = dbase;
extra = dext;
- end = -1;
+ match = 0;
}
/* initialize state for loop */
@@ -212,13 +210,12 @@ int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes,
for (;;) {
/* create table entry */
this.bits = (unsigned char)(len - drop);
- if ((int)(work[sym]) < end) {
+ if (work[sym] + 1 < match) {
this.op = (unsigned char)0;
this.val = work[sym];
- }
- else if ((int)(work[sym]) > end) {
- this.op = (unsigned char)(extra[work[sym]]);
- this.val = base[work[sym]];
+ } else if (work[sym] >= match) {
+ this.op = (unsigned char)(extra[work[sym] - match]);
+ this.val = base[work[sym] - match];
}
else {
this.op = (unsigned char)(32 + 64); /* end of block */