decompressor.c 1.7 KB

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