linux/arch/s390/boot/compressed/decompressor.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * Definitions and wrapper functions for kernel decompressor
   4 *
   5 * Copyright IBM Corp. 2010
   6 *
   7 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
   8 */
   9
  10#include <linux/kernel.h>
  11#include <linux/string.h>
  12#include <asm/page.h>
  13#include "decompressor.h"
  14
  15/*
  16 * gzip declarations
  17 */
  18#define STATIC static
  19
  20#undef memset
  21#undef memcpy
  22#undef memmove
  23#define memmove memmove
  24#define memzero(s, n) memset((s), 0, (n))
  25
  26/* Symbols defined by linker scripts */
  27extern char _end[];
  28extern unsigned char _compressed_start[];
  29extern unsigned char _compressed_end[];
  30
  31#ifdef CONFIG_HAVE_KERNEL_BZIP2
  32#define BOOT_HEAP_SIZE  0x400000
  33#else
  34#define BOOT_HEAP_SIZE  0x10000
  35#endif
  36
  37static unsigned long free_mem_ptr = (unsigned long) _end;
  38static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
  39
  40#ifdef CONFIG_KERNEL_GZIP
  41#include "../../../../lib/decompress_inflate.c"
  42#endif
  43
  44#ifdef CONFIG_KERNEL_BZIP2
  45#include "../../../../lib/decompress_bunzip2.c"
  46#endif
  47
  48#ifdef CONFIG_KERNEL_LZ4
  49#include "../../../../lib/decompress_unlz4.c"
  50#endif
  51
  52#ifdef CONFIG_KERNEL_LZMA
  53#include "../../../../lib/decompress_unlzma.c"
  54#endif
  55
  56#ifdef CONFIG_KERNEL_LZO
  57#include "../../../../lib/decompress_unlzo.c"
  58#endif
  59
  60#ifdef CONFIG_KERNEL_XZ
  61#include "../../../../lib/decompress_unxz.c"
  62#endif
  63
  64#define decompress_offset ALIGN((unsigned long)_end + BOOT_HEAP_SIZE, PAGE_SIZE)
  65
  66unsigned long mem_safe_offset(void)
  67{
  68        /*
  69         * due to 4MB HEAD_SIZE for bzip2
  70         * 'decompress_offset + vmlinux.image_size' could be larger than
  71         * kernel at final position + its .bss, so take the larger of two
  72         */
  73        return max(decompress_offset + vmlinux.image_size,
  74                   vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
  75}
  76
  77void *decompress_kernel(void)
  78{
  79        void *output = (void *)decompress_offset;
  80
  81        __decompress(_compressed_start, _compressed_end - _compressed_start,
  82                     NULL, NULL, output, 0, NULL, error);
  83        return output;
  84}
  85