misc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/m32r/boot/compressed/misc.c
  4. *
  5. * This is a collection of several routines from gzip-1.0.3
  6. * adapted for Linux.
  7. *
  8. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  9. *
  10. * Adapted for SH by Stuart Menefy, Aug 1999
  11. *
  12. * 2003-02-12: Support M32R by Takeo Takahashi
  13. */
  14. /*
  15. * gzip declarations
  16. */
  17. #define STATIC static
  18. #undef memset
  19. #undef memcpy
  20. #define memzero(s, n) memset ((s), 0, (n))
  21. static void error(char *m);
  22. #include "m32r_sio.c"
  23. static unsigned long free_mem_ptr;
  24. static unsigned long free_mem_end_ptr;
  25. #ifdef CONFIG_KERNEL_BZIP2
  26. void *memset(void *s, int c, size_t n)
  27. {
  28. char *ss = s;
  29. while (n--)
  30. *ss++ = c;
  31. return s;
  32. }
  33. #endif
  34. #ifdef CONFIG_KERNEL_GZIP
  35. void *memcpy(void *dest, const void *src, size_t n)
  36. {
  37. char *d = dest;
  38. const char *s = src;
  39. while (n--)
  40. *d++ = *s++;
  41. return dest;
  42. }
  43. #define BOOT_HEAP_SIZE 0x10000
  44. #include "../../../../lib/decompress_inflate.c"
  45. #endif
  46. #ifdef CONFIG_KERNEL_BZIP2
  47. #define BOOT_HEAP_SIZE 0x400000
  48. #include "../../../../lib/decompress_bunzip2.c"
  49. #endif
  50. #ifdef CONFIG_KERNEL_LZMA
  51. #define BOOT_HEAP_SIZE 0x10000
  52. #include "../../../../lib/decompress_unlzma.c"
  53. #endif
  54. static void error(char *x)
  55. {
  56. puts("\n\n");
  57. puts(x);
  58. puts("\n\n -- System halted");
  59. while(1); /* Halt */
  60. }
  61. void
  62. decompress_kernel(int mmu_on, unsigned char *zimage_data,
  63. unsigned int zimage_len, unsigned long heap)
  64. {
  65. unsigned char *input_data = zimage_data;
  66. int input_len = zimage_len;
  67. unsigned char *output_data;
  68. output_data = (unsigned char *)CONFIG_MEMORY_START + 0x2000
  69. + (mmu_on ? 0x80000000 : 0);
  70. free_mem_ptr = heap;
  71. free_mem_end_ptr = free_mem_ptr + BOOT_HEAP_SIZE;
  72. puts("\nDecompressing Linux... ");
  73. __decompress(input_data, input_len, NULL, NULL, output_data, 0,
  74. NULL, error);
  75. puts("done.\nBooting the kernel.\n");
  76. }