decompress.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. 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. #include "../../../../lib/decompress_inflate.c"
  49. #endif
  50. #ifdef CONFIG_KERNEL_BZIP2
  51. void *memset(void *s, int c, size_t n)
  52. {
  53. int i;
  54. char *ss = s;
  55. for (i = 0; i < n; i++)
  56. ss[i] = c;
  57. return s;
  58. }
  59. #include "../../../../lib/decompress_bunzip2.c"
  60. #endif
  61. #ifdef CONFIG_KERNEL_LZMA
  62. #include "../../../../lib/decompress_unlzma.c"
  63. #endif
  64. #ifdef CONFIG_KERNEL_LZO
  65. #include "../../../../lib/decompress_unlzo.c"
  66. #endif
  67. void decompress_kernel(unsigned long boot_heap_start)
  68. {
  69. unsigned long zimage_start, zimage_size;
  70. zimage_start = (unsigned long)(&__image_begin);
  71. zimage_size = (unsigned long)(&__image_end) -
  72. (unsigned long)(&__image_begin);
  73. puts("zimage at: ");
  74. puthex(zimage_start);
  75. puts(" ");
  76. puthex(zimage_size + zimage_start);
  77. puts("\n");
  78. /* This area are prepared for mallocing when decompressing */
  79. free_mem_ptr = boot_heap_start;
  80. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  81. /* Display standard Linux/MIPS boot prompt */
  82. puts("Uncompressing Linux at load address ");
  83. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  84. puts("\n");
  85. /* Decompress the kernel with according algorithm */
  86. decompress((char *)zimage_start, zimage_size, 0, 0,
  87. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  88. /* FIXME: should we flush cache here? */
  89. puts("Now, booting the kernel...\n");
  90. }