misc.c 1.8 KB

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