decompressor.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <asm/page.h>
  12. #include "decompressor.h"
  13. #include "boot.h"
  14. /*
  15. * gzip declarations
  16. */
  17. #define STATIC static
  18. #undef memset
  19. #undef memcpy
  20. #undef memmove
  21. #define memmove memmove
  22. #define memzero(s, n) memset((s), 0, (n))
  23. #if defined(CONFIG_KERNEL_BZIP2)
  24. #define BOOT_HEAP_SIZE 0x400000
  25. #elif defined(CONFIG_KERNEL_ZSTD)
  26. #define BOOT_HEAP_SIZE 0x30000
  27. #else
  28. #define BOOT_HEAP_SIZE 0x10000
  29. #endif
  30. static unsigned long free_mem_ptr = (unsigned long) _end;
  31. static unsigned long free_mem_end_ptr = (unsigned long) _end + BOOT_HEAP_SIZE;
  32. #ifdef CONFIG_KERNEL_GZIP
  33. #include "../../../../lib/decompress_inflate.c"
  34. #endif
  35. #ifdef CONFIG_KERNEL_BZIP2
  36. #include "../../../../lib/decompress_bunzip2.c"
  37. #endif
  38. #ifdef CONFIG_KERNEL_LZ4
  39. #include "../../../../lib/decompress_unlz4.c"
  40. #endif
  41. #ifdef CONFIG_KERNEL_LZMA
  42. #include "../../../../lib/decompress_unlzma.c"
  43. #endif
  44. #ifdef CONFIG_KERNEL_LZO
  45. #include "../../../../lib/decompress_unlzo.c"
  46. #endif
  47. #ifdef CONFIG_KERNEL_XZ
  48. #include "../../../../lib/decompress_unxz.c"
  49. #endif
  50. #ifdef CONFIG_KERNEL_ZSTD
  51. #include "../../../../lib/decompress_unzstd.c"
  52. #endif
  53. unsigned long mem_safe_offset(void)
  54. {
  55. return ALIGN(free_mem_end_ptr, PAGE_SIZE);
  56. }
  57. void deploy_kernel(void *output)
  58. {
  59. __decompress(_compressed_start, _compressed_end - _compressed_start,
  60. NULL, NULL, output, vmlinux.image_size, NULL, error);
  61. }