Path: blob/master/arch/unicore32/boot/compressed/misc.c
10818 views
/*1* linux/arch/unicore32/boot/compressed/misc.c2*3* Code specific to PKUnity SoC and UniCore ISA4*5* Copyright (C) 2001-2010 GUAN Xue-tao6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/1112#include <asm/unaligned.h>13#include <mach/uncompress.h>1415/*16* gzip delarations17*/18unsigned char *output_data;19unsigned long output_ptr;2021unsigned int free_mem_ptr;22unsigned int free_mem_end_ptr;2324#define STATIC static25#define STATIC_RW_DATA /* non-static please */2627/*28* arch-dependent implementations29*/30#ifndef ARCH_HAVE_DECOMP_ERROR31#define arch_decomp_error(x)32#endif3334#ifndef ARCH_HAVE_DECOMP_SETUP35#define arch_decomp_setup()36#endif3738#ifndef ARCH_HAVE_DECOMP_PUTS39#define arch_decomp_puts(p)40#endif4142void *memcpy(void *dest, const void *src, size_t n)43{44int i = 0;45unsigned char *d = (unsigned char *)dest, *s = (unsigned char *)src;4647for (i = n >> 3; i > 0; i--) {48*d++ = *s++;49*d++ = *s++;50*d++ = *s++;51*d++ = *s++;52*d++ = *s++;53*d++ = *s++;54*d++ = *s++;55*d++ = *s++;56}5758if (n & 1 << 2) {59*d++ = *s++;60*d++ = *s++;61*d++ = *s++;62*d++ = *s++;63}6465if (n & 1 << 1) {66*d++ = *s++;67*d++ = *s++;68}6970if (n & 1)71*d++ = *s++;7273return dest;74}7576void error(char *x)77{78arch_decomp_puts("\n\n");79arch_decomp_puts(x);80arch_decomp_puts("\n\n -- System halted");8182arch_decomp_error(x);8384for (;;)85; /* Halt */86}8788/* Heap size should be adjusted for different decompress method */89#ifdef CONFIG_KERNEL_GZIP90#include "../../../../lib/decompress_inflate.c"91#endif9293#ifdef CONFIG_KERNEL_BZIP294#include "../../../../lib/decompress_bunzip2.c"95#endif9697#ifdef CONFIG_KERNEL_LZO98#include "../../../../lib/decompress_unlzo.c"99#endif100101#ifdef CONFIG_KERNEL_LZMA102#include "../../../../lib/decompress_unlzma.c"103#endif104105unsigned long decompress_kernel(unsigned long output_start,106unsigned long free_mem_ptr_p,107unsigned long free_mem_ptr_end_p)108{109unsigned char *tmp;110111output_data = (unsigned char *)output_start;112free_mem_ptr = free_mem_ptr_p;113free_mem_end_ptr = free_mem_ptr_end_p;114115arch_decomp_setup();116117tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);118output_ptr = get_unaligned_le32(tmp);119120arch_decomp_puts("Uncompressing Linux...");121decompress(input_data, input_data_end - input_data, NULL, NULL,122output_data, NULL, error);123arch_decomp_puts(" done, booting the kernel.\n");124return output_ptr;125}126127128