decompress.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. extern unsigned char __ramdisk_begin, __ramdisk_end;
  28. unsigned long initrd_size;
  29. /* debug interfaces */
  30. extern void puts(const char *s);
  31. extern void puthex(unsigned long long val);
  32. void error(char *x)
  33. {
  34. puts("\n\n");
  35. puts(x);
  36. puts("\n\n -- System halted");
  37. while (1)
  38. ; /* Halt */
  39. }
  40. /* activate the code for pre-boot environment */
  41. #define STATIC static
  42. #ifdef CONFIG_KERNEL_GZIP
  43. void *memcpy(void *dest, const void *src, size_t n)
  44. {
  45. int i;
  46. const char *s = src;
  47. char *d = dest;
  48. for (i = 0; i < n; i++)
  49. d[i] = s[i];
  50. return dest;
  51. }
  52. #include "../../../../lib/decompress_inflate.c"
  53. #endif
  54. #ifdef CONFIG_KERNEL_BZIP2
  55. void *memset(void *s, int c, size_t n)
  56. {
  57. int i;
  58. char *ss = s;
  59. for (i = 0; i < n; i++)
  60. ss[i] = c;
  61. return s;
  62. }
  63. #include "../../../../lib/decompress_bunzip2.c"
  64. #endif
  65. #ifdef CONFIG_KERNEL_LZMA
  66. #include "../../../../lib/decompress_unlzma.c"
  67. #endif
  68. void decompress_kernel(unsigned long boot_heap_start)
  69. {
  70. int zimage_size;
  71. /*
  72. * We link ourself to an arbitrary low address. When we run, we
  73. * relocate outself to that address. __image_beign points to
  74. * the part of the image where the zImage is. -- Tom
  75. */
  76. zimage_start = (char *)(unsigned long)(&__image_begin);
  77. zimage_size = (unsigned long)(&__image_end) -
  78. (unsigned long)(&__image_begin);
  79. /*
  80. * The zImage and initrd will be between start and _end, so they've
  81. * already been moved once. We're good to go now. -- Tom
  82. */
  83. puts("zimage at: ");
  84. puthex((unsigned long)zimage_start);
  85. puts(" ");
  86. puthex((unsigned long)(zimage_size + zimage_start));
  87. puts("\n");
  88. if (initrd_size) {
  89. puts("initrd at: ");
  90. puthex((unsigned long)(&__ramdisk_begin));
  91. puts(" ");
  92. puthex((unsigned long)(&__ramdisk_end));
  93. puts("\n");
  94. }
  95. /* this area are prepared for mallocing when decompressing */
  96. free_mem_ptr = boot_heap_start;
  97. free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;
  98. /* Display standard Linux/MIPS boot prompt for kernel args */
  99. puts("Uncompressing Linux at load address ");
  100. puthex(VMLINUX_LOAD_ADDRESS_ULL);
  101. puts("\n");
  102. /* Decompress the kernel with according algorithm */
  103. decompress(zimage_start, zimage_size, 0, 0,
  104. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);
  105. /* FIXME: is there a need to flush cache here? */
  106. puts("Now, booting the kernel...\n");
  107. }