blob: 95470a472d2cf793ddad131f55805385a514e65f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/boot/compressed/misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 *
9 * Adapted for SH by Stuart Menefy, Aug 1999
10 *
11 * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/uaccess.h>
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090015#include <asm/addrspace.h>
Paul Mundte2dfb912006-12-12 08:53:29 +090016#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/*
19 * gzip declarations
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define STATIC static
23
24#undef memset
25#undef memcpy
26#define memzero(s, n) memset ((s), 0, (n))
27
Paul Mundtb14c6d42009-07-11 13:30:38 -040028/* cache.c */
29#define CACHE_ENABLE 0
30#define CACHE_DISABLE 1
31int cache_control(unsigned int command);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33extern char input_data[];
34extern int input_len;
Paul Mundtdf8ce252009-07-12 01:37:30 +090035static unsigned char *output;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39int puts(const char *);
40
41extern int _text; /* Defined in vmlinux.lds.S */
42extern int _end;
43static unsigned long free_mem_ptr;
44static unsigned long free_mem_end_ptr;
45
Paul Mundt07e88e12009-07-11 13:21:19 -040046#ifdef CONFIG_HAVE_KERNEL_BZIP2
47#define HEAP_SIZE 0x400000
48#else
49#define HEAP_SIZE 0x10000
50#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Paul Mundtdf8ce252009-07-12 01:37:30 +090052#ifdef CONFIG_KERNEL_GZIP
53#include "../../../../lib/decompress_inflate.c"
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Paul Mundt07e88e12009-07-11 13:21:19 -040056#ifdef CONFIG_KERNEL_BZIP2
57#include "../../../../lib/decompress_bunzip2.c"
58#endif
59
60#ifdef CONFIG_KERNEL_LZMA
61#include "../../../../lib/decompress_unlzma.c"
62#endif
63
Paul Mundt50cfa792011-01-14 15:52:54 +090064#ifdef CONFIG_KERNEL_XZ
65#include "../../../../lib/decompress_unxz.c"
66#endif
67
Paul Mundtc7b16ef2010-01-13 13:29:19 +090068#ifdef CONFIG_KERNEL_LZO
69#include "../../../../lib/decompress_unlzo.c"
70#endif
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072int puts(const char *s)
73{
74 /* This should be updated to use the sh-sci routines */
75 return 0;
76}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78void* memset(void* s, int c, size_t n)
79{
80 int i;
81 char *ss = (char*)s;
82
83 for (i=0;i<n;i++) ss[i] = c;
84 return s;
85}
86
87void* memcpy(void* __dest, __const void* __src,
88 size_t __n)
89{
90 int i;
91 char *d = (char *)__dest, *s = (char *)__src;
92
93 for (i=0;i<__n;i++) d[i] = s[i];
94 return __dest;
95}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static void error(char *x)
98{
99 puts("\n\n");
100 puts(x);
101 puts("\n\n -- System halted");
102
103 while(1); /* Halt */
104}
105
Paul Mundtb14c6d42009-07-11 13:30:38 -0400106#ifdef CONFIG_SUPERH64
107#define stackalign 8
108#else
109#define stackalign 4
110#endif
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define STACK_SIZE (4096)
Paul Mundtb14c6d42009-07-11 13:30:38 -0400113long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
114long *stack_start = &user_stack[STACK_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116void decompress_kernel(void)
117{
Paul Mundtdf8ce252009-07-12 01:37:30 +0900118 unsigned long output_addr;
119
Paul Mundt040f43e2009-07-11 13:36:25 -0400120#ifdef CONFIG_SUPERH64
121 output_addr = (CONFIG_MEMORY_START + 0x2000);
122#else
Matt Fleming8bd642b2009-10-06 21:22:24 +0000123 output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
Paul Mundtd01447b2010-02-18 18:13:51 +0900124#if defined(CONFIG_29BIT)
Paul Mundtdf8ce252009-07-12 01:37:30 +0900125 output_addr |= P2SEG;
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900126#endif
Paul Mundt040f43e2009-07-11 13:36:25 -0400127#endif
Paul Mundtdf8ce252009-07-12 01:37:30 +0900128
129 output = (unsigned char *)output_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 free_mem_ptr = (unsigned long)&_end;
131 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 puts("Uncompressing Linux... ");
Paul Mundtb14c6d42009-07-11 13:30:38 -0400134 cache_control(CACHE_ENABLE);
Paul Mundtdf8ce252009-07-12 01:37:30 +0900135 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
Paul Mundtb14c6d42009-07-11 13:30:38 -0400136 cache_control(CACHE_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 puts("Ok, booting the kernel.\n");
138}