decompressor.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <[email protected]>
  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. #ifdef CONFIG_KERNEL_BZIP2
  24. #define BOOT_HEAP_SIZE 0x400000
  25. #elif 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. #define decompress_offset ALIGN((unsigned long)_end + BOOT_HEAP_SIZE, PAGE_SIZE)
  54. unsigned long mem_safe_offset(void)
  55. {
  56. /*
  57. * due to 4MB HEAD_SIZE for bzip2
  58. * 'decompress_offset + vmlinux.image_size' could be larger than
  59. * kernel at final position + its .bss, so take the larger of two
  60. */
  61. return max(decompress_offset + vmlinux.image_size,
  62. vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
  63. }
  64. void *decompress_kernel(void)
  65. {
  66. void *output = (void *)decompress_offset;
  67. __decompress(_compressed_start, _compressed_end - _compressed_start,
  68. NULL, NULL, output, vmlinux.image_size, NULL, error);
  69. return output;
  70. }