decompress.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifdef CONFIG_KERNEL_GZIP
  38. #include "../../../../lib/decompress_inflate.c"
  39. #endif
  40. #ifdef CONFIG_KERNEL_BZIP2
  41. #include "../../../../lib/decompress_bunzip2.c"
  42. #endif
  43. #ifdef CONFIG_KERNEL_LZ4
  44. #include "../../../../lib/decompress_unlz4.c"
  45. #endif
  46. #ifdef CONFIG_KERNEL_LZMA
  47. #include "../../../../lib/decompress_unlzma.c"
  48. #endif
  49. #ifdef CONFIG_KERNEL_LZO
  50. #include "../../../../lib/decompress_unlzo.c"
  51. #endif
  52. #ifdef CONFIG_KERNEL_XZ
  53. #include "../../../../lib/decompress_unxz.c"
  54. #endif
  55. void decompress_kernel(unsigned long boot_heap_start)
  56. {
  57. unsigned long zimage_start, zimage_size;
  58. zimage_start = (unsigned long)(&__image_begin);
  59. zimage_size = (unsigned long)(&__image_end) -
  60. (unsigned long)(&__image_begin);
  61. puts("zimage at: ");
  62. puthex(zimage_start);
  63. puts(" ");
  64. puthex(zimage_size + zimage_start);
  65. puts("\n");
  66. /* This area are prepared for mallocing when decompressing */
  67. free_mem_ptr = boot_heap_start;
  68. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  69. /* Display standard Linux/MIPS boot prompt */
  70. puts("Uncompressing Linux at load address ");
  71. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  72. puts("\n");
  73. /* Decompress the kernel with according algorithm */
  74. decompress((char *)zimage_start, zimage_size, 0, 0,
  75. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  76. /* FIXME: should we flush cache here? */
  77. puts("Now, booting the kernel...\n");
  78. }