decompress.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Misc. bootloader code for many machines.
  3. *
  4. * Copyright 2001 MontaVista Software Inc.
  5. * Author: Matt Porter <mporter@mvista.com> Derived from
  6. * arch/ppc/boot/prep/misc.c
  7. *
  8. * Copyright (C) 2009 Lemote, Inc.
  9. * Author: Wu Zhangjin <wuzhangjin@gmail.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <asm/addrspace.h>
  19. /* These two variables specify the free mem region
  20. * that can be used for temporary malloc area
  21. */
  22. unsigned long free_mem_ptr;
  23. unsigned long free_mem_end_ptr;
  24. char *zimage_start;
  25. /* The linker tells us where the image is. */
  26. extern unsigned char __image_begin, __image_end;
  27. /* debug interfaces */
  28. extern void puts(const char *s);
  29. extern void puthex(unsigned long long val);
  30. void error(char *x)
  31. {
  32. puts("\n\n");
  33. puts(x);
  34. puts("\n\n -- System halted");
  35. while (1)
  36. ; /* Halt */
  37. }
  38. /* activate the code for pre-boot environment */
  39. #define STATIC static
  40. #ifdef CONFIG_KERNEL_GZIP
  41. void *memcpy(void *dest, const void *src, size_t n)
  42. {
  43. int i;
  44. const char *s = src;
  45. char *d = dest;
  46. for (i = 0; i < n; i++)
  47. d[i] = s[i];
  48. return dest;
  49. }
  50. #include "../../../../lib/decompress_inflate.c"
  51. #endif
  52. #ifdef CONFIG_KERNEL_BZIP2
  53. void *memset(void *s, int c, size_t n)
  54. {
  55. int i;
  56. char *ss = s;
  57. for (i = 0; i < n; i++)
  58. ss[i] = c;
  59. return s;
  60. }
  61. #include "../../../../lib/decompress_bunzip2.c"
  62. #endif
  63. #ifdef CONFIG_KERNEL_LZMA
  64. #include "../../../../lib/decompress_unlzma.c"
  65. #endif
  66. #ifdef CONFIG_KERNEL_LZO
  67. #include "../../../../lib/decompress_unlzo.c"
  68. #endif
  69. void decompress_kernel(unsigned long boot_heap_start)
  70. {
  71. int zimage_size;
  72. /*
  73. * We link ourself to an arbitrary low address. When we run, we
  74. * relocate outself to that address. __image_beign points to
  75. * the part of the image where the zImage is. -- Tom
  76. */
  77. zimage_start = (char *)(unsigned long)(&__image_begin);
  78. zimage_size = (unsigned long)(&__image_end) -
  79. (unsigned long)(&__image_begin);
  80. /*
  81. * The zImage and initrd will be between start and _end, so they've
  82. * already been moved once. We're good to go now. -- Tom
  83. */
  84. puts("zimage at: ");
  85. puthex((unsigned long)zimage_start);
  86. puts(" ");
  87. puthex((unsigned long)(zimage_size + zimage_start));
  88. puts("\n");
  89. /* this area are prepared for mallocing when decompressing */
  90. free_mem_ptr = boot_heap_start;
  91. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  92. /* Display standard Linux/MIPS boot prompt for kernel args */
  93. puts("Uncompressing Linux at load address ");
  94. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  95. puts("\n");
  96. /* Decompress the kernel with according algorithm */
  97. decompress(zimage_start, zimage_size, 0, 0,
  98. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  99. /* FIXME: is there a need to flush cache here? */
  100. puts("Now, booting the kernel...\n");
  101. }