mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-16 01:44:34 +00:00
lib: Mark lz4 as relocation code
Mark the lz4 decompression code as needed by relocation. This is used to decompress the next-phase image. Drop the 'safe' versions from SPL as they are not needed. Change the static array to a local one, to avoid a crash errors when trying to access the data from relocated code. Make this conditional to avoid a code-size increase when SPL_RELOC is not used/ Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
3b52337c75
commit
6e5b3d4265
2 changed files with 27 additions and 12 deletions
35
lib/lz4.c
35
lib/lz4.c
|
@ -33,15 +33,16 @@
|
||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
#include <asm/unaligned.h>
|
#include <asm/unaligned.h>
|
||||||
#include <u-boot/lz4.h>
|
#include <u-boot/lz4.h>
|
||||||
|
#include <asm/sections.h>
|
||||||
|
|
||||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||||
|
|
||||||
static FORCE_INLINE u16 LZ4_readLE16(const void *src)
|
__rcode static FORCE_INLINE u16 LZ4_readLE16(const void *src)
|
||||||
{
|
{
|
||||||
return get_unaligned_le16(src);
|
return get_unaligned_le16(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void LZ4_copy8(void *dst, const void *src)
|
__rcode static FORCE_INLINE void LZ4_copy8(void *dst, const void *src)
|
||||||
{
|
{
|
||||||
put_unaligned(get_unaligned((const u64 *)src), (u64 *)dst);
|
put_unaligned(get_unaligned((const u64 *)src), (u64 *)dst);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ typedef int32_t S32;
|
||||||
typedef uint64_t U64;
|
typedef uint64_t U64;
|
||||||
typedef uintptr_t uptrval;
|
typedef uintptr_t uptrval;
|
||||||
|
|
||||||
static FORCE_INLINE void LZ4_write32(void *memPtr, U32 value)
|
__rcode static FORCE_INLINE void LZ4_write32(void *memPtr, U32 value)
|
||||||
{
|
{
|
||||||
put_unaligned(value, (U32 *)memPtr);
|
put_unaligned(value, (U32 *)memPtr);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +64,7 @@ static FORCE_INLINE void LZ4_write32(void *memPtr, U32 value)
|
||||||
**************************************/
|
**************************************/
|
||||||
|
|
||||||
/* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */
|
/* customized version of memcpy, which may overwrite up to 7 bytes beyond dstEnd */
|
||||||
static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
|
__rcode static void LZ4_wildCopy(void *dstPtr, const void *srcPtr, void *dstEnd)
|
||||||
{
|
{
|
||||||
BYTE* d = (BYTE*)dstPtr;
|
BYTE* d = (BYTE*)dstPtr;
|
||||||
const BYTE* s = (const BYTE*)srcPtr;
|
const BYTE* s = (const BYTE*)srcPtr;
|
||||||
|
@ -111,6 +112,17 @@ typedef enum { decode_full_block = 0, partial_decode = 1 } earlyEnd_directive;
|
||||||
#define assert(condition) ((void)0)
|
#define assert(condition) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* spl_reloc needs all necessary data to be set up within its code, since the
|
||||||
|
* code is relocated at runtime. Unfortunately this increase code-size slightly
|
||||||
|
* so only do it if spl_reloc is enabled
|
||||||
|
*/
|
||||||
|
#if CONFIG_IS_ENABLED(RELOC_LOADER)
|
||||||
|
#define STATIC
|
||||||
|
#else
|
||||||
|
#define STATIC static
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LZ4_decompress_generic() :
|
* LZ4_decompress_generic() :
|
||||||
* This generic decompression function covers all use cases.
|
* This generic decompression function covers all use cases.
|
||||||
|
@ -118,7 +130,7 @@ typedef enum { decode_full_block = 0, partial_decode = 1 } earlyEnd_directive;
|
||||||
* Note that it is important for performance that this function really get inlined,
|
* Note that it is important for performance that this function really get inlined,
|
||||||
* in order to remove useless branches during compilation optimization.
|
* in order to remove useless branches during compilation optimization.
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE int LZ4_decompress_generic(
|
__rcode static FORCE_INLINE int LZ4_decompress_generic(
|
||||||
const char * const src,
|
const char * const src,
|
||||||
char * const dst,
|
char * const dst,
|
||||||
int srcSize,
|
int srcSize,
|
||||||
|
@ -141,6 +153,8 @@ static FORCE_INLINE int LZ4_decompress_generic(
|
||||||
const size_t dictSize
|
const size_t dictSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
STATIC const unsigned int inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4};
|
||||||
|
STATIC const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3};
|
||||||
const BYTE *ip = (const BYTE *) src;
|
const BYTE *ip = (const BYTE *) src;
|
||||||
const BYTE * const iend = ip + srcSize;
|
const BYTE * const iend = ip + srcSize;
|
||||||
|
|
||||||
|
@ -149,8 +163,6 @@ static FORCE_INLINE int LZ4_decompress_generic(
|
||||||
BYTE *cpy;
|
BYTE *cpy;
|
||||||
|
|
||||||
const BYTE * const dictEnd = (const BYTE *)dictStart + dictSize;
|
const BYTE * const dictEnd = (const BYTE *)dictStart + dictSize;
|
||||||
static const unsigned int inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4};
|
|
||||||
static const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3};
|
|
||||||
|
|
||||||
const int safeDecode = (endOnInput == endOnInputSize);
|
const int safeDecode = (endOnInput == endOnInputSize);
|
||||||
const int checkOffset = ((safeDecode) && (dictSize < (int)(64 * KB)));
|
const int checkOffset = ((safeDecode) && (dictSize < (int)(64 * KB)));
|
||||||
|
@ -514,7 +526,8 @@ _output_error:
|
||||||
return (int) (-(((const char *)ip) - src)) - 1;
|
return (int) (-(((const char *)ip) - src)) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LZ4_decompress_safe(const char *source, char *dest,
|
#ifndef CONFIG_SPL_BUILD
|
||||||
|
__rcode int LZ4_decompress_safe(const char *source, char *dest,
|
||||||
int compressedSize, int maxDecompressedSize)
|
int compressedSize, int maxDecompressedSize)
|
||||||
{
|
{
|
||||||
return LZ4_decompress_generic(source, dest,
|
return LZ4_decompress_generic(source, dest,
|
||||||
|
@ -523,11 +536,13 @@ int LZ4_decompress_safe(const char *source, char *dest,
|
||||||
noDict, (BYTE *)dest, NULL, 0);
|
noDict, (BYTE *)dest, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LZ4_decompress_safe_partial(const char *src, char *dst,
|
__rcode int LZ4_decompress_safe_partial(const char *src, char *dst,
|
||||||
int compressedSize, int targetOutputSize, int dstCapacity)
|
int compressedSize,
|
||||||
|
int targetOutputSize, int dstCapacity)
|
||||||
{
|
{
|
||||||
dstCapacity = min(targetOutputSize, dstCapacity);
|
dstCapacity = min(targetOutputSize, dstCapacity);
|
||||||
return LZ4_decompress_generic(src, dst, compressedSize, dstCapacity,
|
return LZ4_decompress_generic(src, dst, compressedSize, dstCapacity,
|
||||||
endOnInputSize, partial_decode,
|
endOnInputSize, partial_decode,
|
||||||
noDict, (BYTE *)dst, NULL, 0);
|
noDict, (BYTE *)dst, NULL, 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U
|
#define LZ4F_BLOCKUNCOMPRESSED_FLAG 0x80000000U
|
||||||
|
|
||||||
int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn)
|
__rcode int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn)
|
||||||
{
|
{
|
||||||
const void *end = dst + *dstn;
|
const void *end = dst + *dstn;
|
||||||
const void *in = src;
|
const void *in = src;
|
||||||
|
|
Loading…
Add table
Reference in a new issue