decompress.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Matt Porter <mporter@mvista.com>
  4. *
  5. * Copyright (C) 2009 Lemote, Inc.
  6. * Author: Wu Zhangjin <wuzhangjin@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <asm/addrspace.h>
  16. /*
  17. * These two variables specify the free mem region
  18. * that can be used for temporary malloc area
  19. */
  20. unsigned long free_mem_ptr;
  21. unsigned long free_mem_end_ptr;
  22. /* The linker tells us where the image is. */
  23. extern unsigned char __image_begin, __image_end;
  24. /* debug interfaces */
  25. extern void puts(const char *s);
  26. extern void puthex(unsigned long long val);
  27. void error(char *x)
  28. {
  29. puts("\n\n");
  30. puts(x);
  31. puts("\n\n -- System halted");
  32. while (1)
  33. ; /* Halt */
  34. }
  35. /* activate the code for pre-boot environment */
  36. #define STATIC static
  37. #if defined(CONFIG_KERNEL_GZIP) || defined(CONFIG_KERNEL_XZ) || \
  38. defined(CONFIG_KERNEL_LZ4)
  39. void *memcpy(void *dest, const void *src, size_t n)
  40. {
  41. int i;
  42. const char *s = src;
  43. char *d = dest;
  44. for (i = 0; i < n; i++)
  45. d[i] = s[i];
  46. return dest;
  47. }
  48. #endif
  49. #ifdef CONFIG_KERNEL_GZIP
  50. #include "../../../../lib/decompress_inflate.c"
  51. #endif
  52. #ifdef CONFIG_KERNEL_BZIP2
  53. void *memset(void *s, int c, size_t n)
  54. {
  55. int i;
  56. char *ss = s;
  57. for (i = 0; i < n; i++)
  58. ss[i] = c;
  59. return s;
  60. }
  61. #include "../../../../lib/decompress_bunzip2.c"
  62. #endif
  63. #ifdef CONFIG_KERNEL_LZ4
  64. #include "../../../../lib/decompress_unlz4.c"
  65. #endif
  66. #ifdef CONFIG_KERNEL_LZMA
  67. #include "../../../../lib/decompress_unlzma.c"
  68. #endif
  69. #ifdef CONFIG_KERNEL_LZO
  70. #include "../../../../lib/decompress_unlzo.c"
  71. #endif
  72. #ifdef CONFIG_KERNEL_XZ
  73. #include "../../../../lib/decompress_unxz.c"
  74. #endif
  75. void decompress_kernel(unsigned long boot_heap_start)
  76. {
  77. unsigned long zimage_start, zimage_size;
  78. zimage_start = (unsigned long)(&__image_begin);
  79. zimage_size = (unsigned long)(&__image_end) -
  80. (unsigned long)(&__image_begin);
  81. puts("zimage at: ");
  82. puthex(zimage_start);
  83. puts(" ");
  84. puthex(zimage_size + zimage_start);
  85. puts("\n");
  86. /* This area are prepared for mallocing when decompressing */
  87. free_mem_ptr = boot_heap_start;
  88. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  89. /* Display standard Linux/MIPS boot prompt */
  90. puts("Uncompressing Linux at load address ");
  91. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  92. puts("\n");
  93. /* Decompress the kernel with according algorithm */
  94. decompress((char *)zimage_start, zimage_size, 0, 0,
  95. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  96. /* FIXME: should we flush cache here? */
  97. puts("Now, booting the kernel...\n");
  98. }