decompress.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <linux/string.h>
  16. #include <asm/addrspace.h>
  17. /*
  18. * These two variables specify the free mem region
  19. * that can be used for temporary malloc area
  20. */
  21. unsigned long free_mem_ptr;
  22. unsigned long free_mem_end_ptr;
  23. /* The linker tells us where the image is. */
  24. extern unsigned char __image_begin, __image_end;
  25. /* debug interfaces */
  26. extern void puts(const char *s);
  27. extern void puthex(unsigned long long val);
  28. void error(char *x)
  29. {
  30. puts("\n\n");
  31. puts(x);
  32. puts("\n\n -- System halted");
  33. while (1)
  34. ; /* Halt */
  35. }
  36. /* activate the code for pre-boot environment */
  37. #define STATIC static
  38. #ifdef CONFIG_KERNEL_GZIP
  39. #include "../../../../lib/decompress_inflate.c"
  40. #endif
  41. #ifdef CONFIG_KERNEL_BZIP2
  42. #include "../../../../lib/decompress_bunzip2.c"
  43. #endif
  44. #ifdef CONFIG_KERNEL_LZ4
  45. #include "../../../../lib/decompress_unlz4.c"
  46. #endif
  47. #ifdef CONFIG_KERNEL_LZMA
  48. #include "../../../../lib/decompress_unlzma.c"
  49. #endif
  50. #ifdef CONFIG_KERNEL_LZO
  51. #include "../../../../lib/decompress_unlzo.c"
  52. #endif
  53. #ifdef CONFIG_KERNEL_XZ
  54. #include "../../../../lib/decompress_unxz.c"
  55. #endif
  56. unsigned long __stack_chk_guard;
  57. void __stack_chk_guard_setup(void)
  58. {
  59. __stack_chk_guard = 0x000a0dff;
  60. }
  61. void __stack_chk_fail(void)
  62. {
  63. error("stack-protector: Kernel stack is corrupted\n");
  64. }
  65. void decompress_kernel(unsigned long boot_heap_start)
  66. {
  67. unsigned long zimage_start, zimage_size;
  68. __stack_chk_guard_setup();
  69. zimage_start = (unsigned long)(&__image_begin);
  70. zimage_size = (unsigned long)(&__image_end) -
  71. (unsigned long)(&__image_begin);
  72. puts("zimage at: ");
  73. puthex(zimage_start);
  74. puts(" ");
  75. puthex(zimage_size + zimage_start);
  76. puts("\n");
  77. /* This area are prepared for mallocing when decompressing */
  78. free_mem_ptr = boot_heap_start;
  79. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  80. /* Display standard Linux/MIPS boot prompt */
  81. puts("Uncompressing Linux at load address ");
  82. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  83. puts("\n");
  84. /* Decompress the kernel with according algorithm */
  85. decompress((char *)zimage_start, zimage_size, 0, 0,
  86. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  87. /* FIXME: should we flush cache here? */
  88. puts("Now, booting the kernel...\n");
  89. }