switch-l4t-atf/common/image_decompress.c
Antonio Nino Diaz 09d40e0e08 Sanitise includes across codebase
Enforce full include path for includes. Deprecate old paths.

The following folders inside include/lib have been left unchanged:

- include/lib/cpus/${ARCH}
- include/lib/el3_runtime/${ARCH}

The reason for this change is that having a global namespace for
includes isn't a good idea. It defeats one of the advantages of having
folders and it introduces problems that are sometimes subtle (because
you may not know the header you are actually including if there are two
of them).

For example, this patch had to be created because two headers were
called the same way: e0ea0928d5b7 ("Fix gpio includes of mt8173 platform
to avoid collision."). More recently, this patch has had similar
problems: 46f9b2c3a282 ("drivers: add tzc380 support").

This problem was introduced in commit 4ecca33988b9 ("Move include and
source files to logical locations"). At that time, there weren't too
many headers so it wasn't a real issue. However, time has shown that
this creates problems.

Platforms that want to preserve the way they include headers may add the
removed paths to PLAT_INCLUDES, but this is discouraged.

Change-Id: I39dc53ed98f9e297a5966e723d1936d6ccf2fc8f
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2019-01-04 10:43:17 +00:00

81 lines
2.2 KiB
C

/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <stdint.h>
#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/image_decompress.h>
static uintptr_t decompressor_buf_base;
static uint32_t decompressor_buf_size;
static decompressor_t *decompressor;
static struct image_info saved_image_info;
void image_decompress_init(uintptr_t buf_base, uint32_t buf_size,
decompressor_t *_decompressor)
{
decompressor_buf_base = buf_base;
decompressor_buf_size = buf_size;
decompressor = _decompressor;
}
void image_decompress_prepare(struct image_info *info)
{
/*
* If the image is compressed, it should be loaded into the temporary
* buffer instead of its final destination. We save image_info, then
* override ->image_base and ->image_max_size so that load_image() will
* transfer the compressed data to the temporary buffer.
*/
saved_image_info = *info;
info->image_base = decompressor_buf_base;
info->image_max_size = decompressor_buf_size;
}
int image_decompress(struct image_info *info)
{
uintptr_t compressed_image_base, image_base, work_base;
uint32_t compressed_image_size, work_size;
int ret;
/*
* The size of compressed data has been filled by load_image().
* Read it out before restoring image_info.
*/
compressed_image_size = info->image_size;
compressed_image_base = info->image_base;
*info = saved_image_info;
assert(compressed_image_size <= decompressor_buf_size);
image_base = info->image_base;
/*
* Use the rest of the temporary buffer as workspace of the
* decompressor since the decompressor may need additional memory.
*/
work_base = compressed_image_base + compressed_image_size;
work_size = decompressor_buf_size - compressed_image_size;
ret = decompressor(&compressed_image_base, compressed_image_size,
&image_base, info->image_max_size,
work_base, work_size);
if (ret) {
ERROR("Failed to decompress image (err=%d)\n", ret);
return ret;
}
/* image_base is updated to the final pos when decompressor() exits. */
info->image_size = image_base - info->image_base;
flush_dcache_range(info->image_base, info->image_size);
return 0;
}