decompress.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. & Institute of Computing Technology
  9. * Author: Wu Zhangjin <wuzj@lemote.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. void decompress_kernel(unsigned long boot_heap_start)
  67. {
  68. int zimage_size;
  69. /*
  70. * We link ourself to an arbitrary low address. When we run, we
  71. * relocate outself to that address. __image_beign points to
  72. * the part of the image where the zImage is. -- Tom
  73. */
  74. zimage_start = (char *)(unsigned long)(&__image_begin);
  75. zimage_size = (unsigned long)(&__image_end) -
  76. (unsigned long)(&__image_begin);
  77. /*
  78. * The zImage and initrd will be between start and _end, so they've
  79. * already been moved once. We're good to go now. -- Tom
  80. */
  81. puts("zimage at: ");
  82. puthex((unsigned long)zimage_start);
  83. puts(" ");
  84. puthex((unsigned long)(zimage_size + zimage_start));
  85. puts("\n");
  86. /* this area are prepared for mallocing when decompressing */
  87. free_mem_ptr = boot_heap_start;
  88. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  89. /* Display standard Linux/MIPS boot prompt for kernel args */
  90. puts("Uncompressing Linux at load address ");
  91. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  92. puts("\n");
  93. /* Decompress the kernel with according algorithm */
  94. decompress(zimage_start, zimage_size, 0, 0,
  95. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  96. /* FIXME: is there a need to flush cache here? */
  97. puts("Now, booting the kernel...\n");
  98. }