ia64/xen-unstable

view xen/arch/x86/bzimage.c @ 19835:edfdeb150f27

Fix buildsystem to detect udev > version 124

udev removed the udevinfo symlink from versions higher than 123 and
xen's build-system could not detect if udev is in place and has the
required version.

Signed-off-by: Marc-A. Dahlhaus <mad@wol.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:02:37 2009 +0100 (2009-06-25)
parents 728d8dee880b
children
line source
1 #include <xen/cache.h>
2 #include <xen/errno.h>
3 #include <xen/lib.h>
4 #include <xen/mm.h>
5 #include <xen/string.h>
6 #include <xen/types.h>
8 #define HEAPORDER 3
10 static unsigned char *window;
11 #define memptr long
12 static memptr free_mem_ptr;
13 static memptr free_mem_end_ptr;
15 #define WSIZE 0x80000000
17 static unsigned char *inbuf;
18 static unsigned insize;
20 /* Index of next byte to be processed in inbuf: */
21 static unsigned inptr;
23 /* Bytes in output buffer: */
24 static unsigned outcnt;
26 #define OF(args) args
27 #define STATIC static
29 #define memzero(s, n) memset((s), 0, (n))
31 typedef unsigned char uch;
32 typedef unsigned short ush;
33 typedef unsigned long ulg;
35 #define INIT __init
37 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
39 /* Diagnostic functions */
40 #ifdef DEBUG
41 # define Assert(cond, msg) do { if (!(cond)) error(msg); } while (0)
42 # define Trace(x) do { fprintf x; } while (0)
43 # define Tracev(x) do { if (verbose) fprintf x ; } while (0)
44 # define Tracevv(x) do { if (verbose > 1) fprintf x ; } while (0)
45 # define Tracec(c, x) do { if (verbose && (c)) fprintf x ; } while (0)
46 # define Tracecv(c, x) do { if (verbose > 1 && (c)) fprintf x ; } while (0)
47 #else
48 # define Assert(cond, msg)
49 # define Trace(x)
50 # define Tracev(x)
51 # define Tracevv(x)
52 # define Tracec(c, x)
53 # define Tracecv(c, x)
54 #endif
56 static long bytes_out;
57 static void flush_window(void);
59 static __init void error(char *x)
60 {
61 panic("%s\n", x);
62 }
64 static __init int fill_inbuf(void)
65 {
66 error("ran out of input data");
67 return 0;
68 }
71 #include "../../common/inflate.c"
73 static __init void flush_window(void)
74 {
75 /*
76 * The window is equal to the output buffer therefore only need to
77 * compute the crc.
78 */
79 unsigned long c = crc;
80 unsigned n;
81 unsigned char *in, ch;
83 in = window;
84 for ( n = 0; n < outcnt; n++ )
85 {
86 ch = *in++;
87 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
88 }
89 crc = c;
91 bytes_out += (unsigned long)outcnt;
92 outcnt = 0;
93 }
95 static __init int gzip_length(char *image, unsigned long image_len)
96 {
97 return *(uint32_t *)&image[image_len - 4];
98 }
100 static __init int perform_gunzip(char *output, char **_image_start, unsigned long *image_len)
101 {
102 char *image = *_image_start;
103 int rc;
104 unsigned char magic0 = (unsigned char)image[0];
105 unsigned char magic1 = (unsigned char)image[1];
107 if ( magic0 != 0x1f || ( (magic1 != 0x8b) && (magic1 != 0x9e) ) )
108 return 0;
110 window = (unsigned char *)output;
112 free_mem_ptr = (unsigned long)alloc_xenheap_pages(HEAPORDER, 0);
113 free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE << HEAPORDER);
115 inbuf = (unsigned char *)image;
116 insize = *image_len;
117 inptr = 0;
119 makecrc();
121 if ( gunzip() < 0 )
122 {
123 rc = -EINVAL;
124 }
125 else
126 {
127 *_image_start = (char *)window;
128 *image_len = gzip_length(image, *image_len);
129 rc = 0;
130 }
132 free_xenheap_pages((void *)free_mem_ptr, HEAPORDER);
134 return rc;
135 }
137 struct setup_header {
138 uint8_t _pad0[0x1f1]; /* skip uninteresting stuff */
139 uint8_t setup_sects;
140 uint16_t root_flags;
141 uint32_t syssize;
142 uint16_t ram_size;
143 uint16_t vid_mode;
144 uint16_t root_dev;
145 uint16_t boot_flag;
146 uint16_t jump;
147 uint32_t header;
148 #define HDR_MAGIC "HdrS"
149 #define HDR_MAGIC_SZ 4
150 uint16_t version;
151 #define VERSION(h,l) (((h)<<8) | (l))
152 uint32_t realmode_swtch;
153 uint16_t start_sys;
154 uint16_t kernel_version;
155 uint8_t type_of_loader;
156 uint8_t loadflags;
157 uint16_t setup_move_size;
158 uint32_t code32_start;
159 uint32_t ramdisk_image;
160 uint32_t ramdisk_size;
161 uint32_t bootsect_kludge;
162 uint16_t heap_end_ptr;
163 uint16_t _pad1;
164 uint32_t cmd_line_ptr;
165 uint32_t initrd_addr_max;
166 uint32_t kernel_alignment;
167 uint8_t relocatable_kernel;
168 uint8_t _pad2[3];
169 uint32_t cmdline_size;
170 uint32_t hardware_subarch;
171 uint64_t hardware_subarch_data;
172 uint32_t payload_offset;
173 uint32_t payload_length;
174 } __attribute__((packed));
176 static __init int bzimage_check(struct setup_header *hdr, unsigned long len)
177 {
178 if ( len < sizeof(struct setup_header) )
179 return 0;
181 if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) != 0 )
182 return 0;
184 if ( hdr->version < VERSION(2,8) ) {
185 printk("Cannot load bzImage v%d.%02d at least v2.08 is required\n",
186 hdr->version >> 8, hdr->version & 0xff);
187 return -EINVAL;
188 }
189 return 1;
190 }
192 int __init bzimage_headroom(char *image_start, unsigned long image_length)
193 {
194 struct setup_header *hdr = (struct setup_header *)image_start;
195 char *img;
196 int err, headroom;
198 err = bzimage_check(hdr, image_length);
199 if (err < 1)
200 return 0;
202 img = image_start + (hdr->setup_sects+1) * 512;
203 img += hdr->payload_offset;
205 headroom = gzip_length(img, hdr->payload_length);
206 headroom += headroom >> 12; /* Add 8 bytes for every 32K input block */
207 headroom += (32768 + 18); /* Add 32K + 18 bytes of extra headroom */
208 headroom = (headroom + 4095) & ~4095;
210 return headroom;
211 }
213 int __init bzimage_parse(char *image_base, char **image_start, unsigned long *image_len)
214 {
215 struct setup_header *hdr = (struct setup_header *)(*image_start);
216 int err = bzimage_check(hdr, *image_len);
218 if (err < 1)
219 return err;
221 BUG_ON(!(image_base < *image_start));
223 *image_start += (hdr->setup_sects+1) * 512;
224 *image_start += hdr->payload_offset;
225 *image_len = hdr->payload_length;
227 if ( (err = perform_gunzip(image_base, image_start, image_len)) < 0 )
228 return err;
230 return 0;
231 }
233 /*
234 * Local variables:
235 * mode: C
236 * c-set-style: "BSD"
237 * c-basic-offset: 4
238 * tab-width: 4
239 * indent-tabs-mode: nil
240 * End:
241 */