decompress.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. void *memcpy(void *dest, const void *src, size_t n)
  39. {
  40. int i;
  41. const char *s = src;
  42. char *d = dest;
  43. for (i = 0; i < n; i++)
  44. d[i] = s[i];
  45. return dest;
  46. }
  47. #include "../../../../lib/decompress_inflate.c"
  48. #endif
  49. #ifdef CONFIG_KERNEL_BZIP2
  50. void *memset(void *s, int c, size_t n)
  51. {
  52. int i;
  53. char *ss = s;
  54. for (i = 0; i < n; i++)
  55. ss[i] = c;
  56. return s;
  57. }
  58. #include "../../../../lib/decompress_bunzip2.c"
  59. #endif
  60. #ifdef CONFIG_KERNEL_LZMA
  61. #include "../../../../lib/decompress_unlzma.c"
  62. #endif
  63. #ifdef CONFIG_KERNEL_LZO
  64. #include "../../../../lib/decompress_unlzo.c"
  65. #endif
  66. void decompress_kernel(unsigned long boot_heap_start)
  67. {
  68. unsigned long zimage_start, zimage_size;
  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. }