decompress.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifdef CONFIG_DEBUG_ZBOOT
  27. extern void puts(const char *s);
  28. extern void puthex(unsigned long long val);
  29. #else
  30. #define puts(s) do {} while (0)
  31. #define puthex(val) do {} while (0)
  32. #endif
  33. void error(char *x)
  34. {
  35. puts("\n\n");
  36. puts(x);
  37. puts("\n\n -- System halted");
  38. while (1)
  39. ; /* Halt */
  40. }
  41. /* activate the code for pre-boot environment */
  42. #define STATIC static
  43. #ifdef CONFIG_KERNEL_GZIP
  44. #include "../../../../lib/decompress_inflate.c"
  45. #endif
  46. #ifdef CONFIG_KERNEL_BZIP2
  47. #include "../../../../lib/decompress_bunzip2.c"
  48. #endif
  49. #ifdef CONFIG_KERNEL_LZ4
  50. #include "../../../../lib/decompress_unlz4.c"
  51. #endif
  52. #ifdef CONFIG_KERNEL_LZMA
  53. #include "../../../../lib/decompress_unlzma.c"
  54. #endif
  55. #ifdef CONFIG_KERNEL_LZO
  56. #include "../../../../lib/decompress_unlzo.c"
  57. #endif
  58. #ifdef CONFIG_KERNEL_XZ
  59. #include "../../../../lib/decompress_unxz.c"
  60. #endif
  61. unsigned long __stack_chk_guard;
  62. void __stack_chk_guard_setup(void)
  63. {
  64. __stack_chk_guard = 0x000a0dff;
  65. }
  66. void __stack_chk_fail(void)
  67. {
  68. error("stack-protector: Kernel stack is corrupted\n");
  69. }
  70. void decompress_kernel(unsigned long boot_heap_start)
  71. {
  72. unsigned long zimage_start, zimage_size;
  73. __stack_chk_guard_setup();
  74. zimage_start = (unsigned long)(&__image_begin);
  75. zimage_size = (unsigned long)(&__image_end) -
  76. (unsigned long)(&__image_begin);
  77. puts("zimage at: ");
  78. puthex(zimage_start);
  79. puts(" ");
  80. puthex(zimage_size + zimage_start);
  81. puts("\n");
  82. /* This area are prepared for mallocing when decompressing */
  83. free_mem_ptr = boot_heap_start;
  84. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  85. /* Display standard Linux/MIPS boot prompt */
  86. puts("Uncompressing Linux at load address ");
  87. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  88. puts("\n");
  89. /* Decompress the kernel with according algorithm */
  90. __decompress((char *)zimage_start, zimage_size, 0, 0,
  91. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
  92. /* FIXME: should we flush cache here? */
  93. puts("Now, booting the kernel...\n");
  94. }