Path: blob/master/arch/mips/boot/compressed/decompress.c
10818 views
/*1* Copyright 2001 MontaVista Software Inc.2* Author: Matt Porter <[email protected]>3*4* Copyright (C) 2009 Lemote, Inc.5* Author: Wu Zhangjin <[email protected]>6*7* This program is free software; you can redistribute it and/or modify it8* under the terms of the GNU General Public License as published by the9* Free Software Foundation; either version 2 of the License, or (at your10* option) any later version.11*/1213#include <linux/types.h>14#include <linux/kernel.h>1516#include <asm/addrspace.h>1718/*19* These two variables specify the free mem region20* that can be used for temporary malloc area21*/22unsigned long free_mem_ptr;23unsigned long free_mem_end_ptr;2425/* The linker tells us where the image is. */26extern unsigned char __image_begin, __image_end;2728/* debug interfaces */29extern void puts(const char *s);30extern void puthex(unsigned long long val);3132void error(char *x)33{34puts("\n\n");35puts(x);36puts("\n\n -- System halted");3738while (1)39; /* Halt */40}4142/* activate the code for pre-boot environment */43#define STATIC static4445#ifdef CONFIG_KERNEL_GZIP46void *memcpy(void *dest, const void *src, size_t n)47{48int i;49const char *s = src;50char *d = dest;5152for (i = 0; i < n; i++)53d[i] = s[i];54return dest;55}56#include "../../../../lib/decompress_inflate.c"57#endif5859#ifdef CONFIG_KERNEL_BZIP260void *memset(void *s, int c, size_t n)61{62int i;63char *ss = s;6465for (i = 0; i < n; i++)66ss[i] = c;67return s;68}69#include "../../../../lib/decompress_bunzip2.c"70#endif7172#ifdef CONFIG_KERNEL_LZMA73#include "../../../../lib/decompress_unlzma.c"74#endif7576#ifdef CONFIG_KERNEL_LZO77#include "../../../../lib/decompress_unlzo.c"78#endif7980void decompress_kernel(unsigned long boot_heap_start)81{82unsigned long zimage_start, zimage_size;8384zimage_start = (unsigned long)(&__image_begin);85zimage_size = (unsigned long)(&__image_end) -86(unsigned long)(&__image_begin);8788puts("zimage at: ");89puthex(zimage_start);90puts(" ");91puthex(zimage_size + zimage_start);92puts("\n");9394/* This area are prepared for mallocing when decompressing */95free_mem_ptr = boot_heap_start;96free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE;9798/* Display standard Linux/MIPS boot prompt */99puts("Uncompressing Linux at load address ");100puthex(VMLINUX_LOAD_ADDRESS_ULL);101puts("\n");102103/* Decompress the kernel with according algorithm */104decompress((char *)zimage_start, zimage_size, 0, 0,105(void *)VMLINUX_LOAD_ADDRESS_ULL, 0, error);106107/* FIXME: should we flush cache here? */108puts("Now, booting the kernel...\n");109}110111112