misc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/uaccess.h>
  10. #include <asm/page.h>
  11. #include <asm/sclp.h>
  12. #include <asm/ipl.h>
  13. #include "sizes.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. /* Symbols defined by linker scripts */
  24. extern char input_data[];
  25. extern int input_len;
  26. extern char _end[];
  27. extern char _bss[], _ebss[];
  28. static void error(char *m);
  29. static unsigned long free_mem_ptr;
  30. static unsigned long free_mem_end_ptr;
  31. #ifdef CONFIG_HAVE_KERNEL_BZIP2
  32. #define HEAP_SIZE 0x400000
  33. #else
  34. #define HEAP_SIZE 0x10000
  35. #endif
  36. #ifdef CONFIG_KERNEL_GZIP
  37. #include "../../../../lib/decompress_inflate.c"
  38. #endif
  39. #ifdef CONFIG_KERNEL_BZIP2
  40. #include "../../../../lib/decompress_bunzip2.c"
  41. #endif
  42. #ifdef CONFIG_KERNEL_LZ4
  43. #include "../../../../lib/decompress_unlz4.c"
  44. #endif
  45. #ifdef CONFIG_KERNEL_LZMA
  46. #include "../../../../lib/decompress_unlzma.c"
  47. #endif
  48. #ifdef CONFIG_KERNEL_LZO
  49. #include "../../../../lib/decompress_unlzo.c"
  50. #endif
  51. #ifdef CONFIG_KERNEL_XZ
  52. #include "../../../../lib/decompress_unxz.c"
  53. #endif
  54. static int puts(const char *s)
  55. {
  56. sclp_early_printk(s);
  57. return 0;
  58. }
  59. static void error(char *x)
  60. {
  61. unsigned long long psw = 0x000a0000deadbeefULL;
  62. puts("\n\n");
  63. puts(x);
  64. puts("\n\n -- System halted");
  65. asm volatile("lpsw %0" : : "Q" (psw));
  66. }
  67. unsigned long decompress_kernel(void)
  68. {
  69. void *output, *kernel_end;
  70. output = (void *) ALIGN((unsigned long) _end + HEAP_SIZE, PAGE_SIZE);
  71. kernel_end = output + SZ__bss_start;
  72. #ifdef CONFIG_BLK_DEV_INITRD
  73. /*
  74. * Move the initrd right behind the end of the decompressed
  75. * kernel image. This also prevents initrd corruption caused by
  76. * bss clearing since kernel_end will always be located behind the
  77. * current bss section..
  78. */
  79. if (INITRD_START && INITRD_SIZE && kernel_end > (void *) INITRD_START) {
  80. memmove(kernel_end, (void *) INITRD_START, INITRD_SIZE);
  81. INITRD_START = (unsigned long) kernel_end;
  82. }
  83. #endif
  84. /*
  85. * Clear bss section. free_mem_ptr and free_mem_end_ptr need to be
  86. * initialized afterwards since they reside in bss.
  87. */
  88. memset(_bss, 0, _ebss - _bss);
  89. free_mem_ptr = (unsigned long) _end;
  90. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  91. __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
  92. return (unsigned long) output;
  93. }