blob: bf3dd9659865a4f12b689f1fe9d11e972d54cee7 [file] [log] [blame]
Jeff Dike9b67a3c2005-05-20 13:59:10 -07001/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include "linux/init.h"
7#include "linux/bootmem.h"
8#include "linux/initrd.h"
9#include "asm/types.h"
Jeff Dike9b67a3c2005-05-20 13:59:10 -070010#include "kern_util.h"
11#include "initrd.h"
12#include "init.h"
13#include "os.h"
14
15/* Changed by uml_initrd_setup, which is a setup */
16static char *initrd __initdata = NULL;
17
18static int __init read_initrd(void)
19{
20 void *area;
21 long long size;
22 int err;
23
24 if(initrd == NULL) return 0;
25 err = os_file_size(initrd, &size);
26 if(err) return 0;
27 area = alloc_bootmem(size);
28 if(area == NULL) return 0;
29 if(load_initrd(initrd, area, size) == -1) return 0;
30 initrd_start = (unsigned long) area;
31 initrd_end = initrd_start + size;
32 return 0;
33}
34
35__uml_postsetup(read_initrd);
36
37static int __init uml_initrd_setup(char *line, int *add)
38{
39 initrd = line;
40 return 0;
41}
42
43__uml_setup("initrd=", uml_initrd_setup,
44"initrd=<initrd image>\n"
45" This is used to boot UML from an initrd image. The argument is the\n"
46" name of the file containing the image.\n\n"
47);
48
49int load_initrd(char *filename, void *buf, int size)
50{
51 int fd, n;
52
53 fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
54 if(fd < 0){
55 printk("Opening '%s' failed - err = %d\n", filename, -fd);
56 return(-1);
57 }
Jeff Dikefda83a92007-05-06 14:51:41 -070058 n = os_read_file_k(fd, buf, size);
Jeff Dike9b67a3c2005-05-20 13:59:10 -070059 if(n != size){
60 printk("Read of %d bytes from '%s' failed, err = %d\n", size,
61 filename, -n);
62 return(-1);
63 }
64
65 os_close_file(fd);
66 return(0);
67}
68/*
69 * Overrides for Emacs so that we follow Linus's tabbing style.
70 * Emacs will notice this stuff at the end of the file and automatically
71 * adjust the settings for this buffer only. This must remain at the end
72 * of the file.
73 * ---------------------------------------------------------------------------
74 * Local variables:
75 * c-file-style: "linux"
76 * End:
77 */