source: src/linux/universal/linux-3.18/arch/s390/boot/compressed/misc.c @ 31885

Last change on this file since 31885 was 31885, checked in by brainslayer, 5 weeks ago

update

File size: 3.9 KB
Line 
1/*
2 * Definitions and wrapper functions for kernel decompressor
3 *
4 * Copyright IBM Corp. 2010
5 *
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7 */
8
9#include <asm/uaccess.h>
10#include <asm/page.h>
11#include <asm/ipl.h>
12#include "sizes.h"
13
14/*
15 * gzip declarations
16 */
17#define STATIC static
18
19#undef memset
20#undef memcpy
21#undef memmove
22#define memmove memmove
23#define memzero(s, n) memset((s), 0, (n))
24
25/* Symbols defined by linker scripts */
26extern char input_data[];
27extern int input_len;
28extern char _text, _end;
29extern char _bss, _ebss;
30
31static void error(char *m);
32
33static unsigned long free_mem_ptr;
34static unsigned long free_mem_end_ptr;
35
36#ifdef CONFIG_HAVE_KERNEL_BZIP2
37#define HEAP_SIZE       0x400000
38#else
39#define HEAP_SIZE       0x10000
40#endif
41
42#ifdef CONFIG_KERNEL_GZIP
43#include "../../../../lib/decompress_inflate.c"
44#endif
45
46#ifdef CONFIG_KERNEL_BZIP2
47#include "../../../../lib/decompress_bunzip2.c"
48#endif
49
50#ifdef CONFIG_KERNEL_LZ4
51#include "../../../../lib/decompress_unlz4.c"
52#endif
53
54#ifdef CONFIG_KERNEL_LZMA
55#include "../../../../lib/decompress_unlzma.c"
56#endif
57
58#ifdef CONFIG_KERNEL_LZO
59#include "../../../../lib/decompress_unlzo.c"
60#endif
61
62#ifdef CONFIG_KERNEL_XZ
63#include "../../../../lib/decompress_unxz.c"
64#endif
65
66extern _sclp_print_early(const char *);
67
68static int puts(const char *s)
69{
70        _sclp_print_early(s);
71        return 0;
72}
73
74void *memset(void *s, int c, size_t n)
75{
76        char *xs;
77
78        xs = s;
79        while (n--)
80                *xs++ = c;
81        return s;
82}
83
84void *memcpy(void *dest, const void *src, size_t n)
85{
86        const char *s = src;
87        char *d = dest;
88
89        while (n--)
90                *d++ = *s++;
91        return dest;
92}
93
94void *memmove(void *dest, const void *src, size_t n)
95{
96        const char *s = src;
97        char *d = dest;
98
99        if (d <= s) {
100                while (n--)
101                        *d++ = *s++;
102        } else {
103                d += n;
104                s += n;
105                while (n--)
106                        *--d = *--s;
107        }
108        return dest;
109}
110
111static void error(char *x)
112{
113        unsigned long long psw = 0x000a0000deadbeefULL;
114
115        puts("\n\n");
116        puts(x);
117        puts("\n\n -- System halted");
118
119        asm volatile("lpsw %0" : : "Q" (psw));
120}
121
122/*
123 * Safe guard the ipl parameter block against a memory area that will be
124 * overwritten. The validity check for the ipl parameter block is complex
125 * (see cio_get_iplinfo and ipl_save_parameters) but if the pointer to
126 * the ipl parameter block intersects with the passed memory area we can
127 * safely assume that we can read from that memory. In that case just copy
128 * the memory to IPL_PARMBLOCK_ORIGIN even if there is no ipl parameter
129 * block.
130 */
131static void check_ipl_parmblock(void *start, unsigned long size)
132{
133        void *src, *dst;
134
135        src = (void *)(unsigned long) S390_lowcore.ipl_parmblock_ptr;
136        if (src + PAGE_SIZE <= start || src >= start + size)
137                return;
138        dst = (void *) IPL_PARMBLOCK_ORIGIN;
139        memmove(dst, src, PAGE_SIZE);
140        S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
141}
142
143unsigned long decompress_kernel(void)
144{
145        void *output, *kernel_end;
146
147        output = (void *) ALIGN((unsigned long) &_end + HEAP_SIZE, PAGE_SIZE);
148        kernel_end = output + SZ__bss_start;
149        check_ipl_parmblock((void *) 0, (unsigned long) kernel_end);
150
151#ifdef CONFIG_BLK_DEV_INITRD
152        /*
153         * Move the initrd right behind the end of the decompressed
154         * kernel image. This also prevents initrd corruption caused by
155         * bss clearing since kernel_end will always be located behind the
156         * current bss section..
157         */
158        if (INITRD_START && INITRD_SIZE && kernel_end > (void *) INITRD_START) {
159                check_ipl_parmblock(kernel_end, INITRD_SIZE);
160                memmove(kernel_end, (void *) INITRD_START, INITRD_SIZE);
161                INITRD_START = (unsigned long) kernel_end;
162        }
163#endif
164
165        /*
166         * Clear bss section. free_mem_ptr and free_mem_end_ptr need to be
167         * initialized afterwards since they reside in bss.
168         */
169        memset(&_bss, 0, &_ebss - &_bss);
170        free_mem_ptr = (unsigned long) &_end;
171        free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
172
173        puts("Uncompressing Linux... ");
174        decompress(input_data, input_len, NULL, NULL, output, NULL, error);
175        puts("Ok, booting the kernel.\n");
176        return (unsigned long) output;
177}
178
Note: See TracBrowser for help on using the repository browser.