1 /* 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" 10 #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 */ 16 static char *initrd __initdata = NULL; 17 18 static int __init read_initrd(void) 19 { 20 void *area; 21 long long size; 22 int err; 23 24 if(initrd == NULL) 25 return 0; 26 27 err = os_file_size(initrd, &size); 28 if(err) 29 return 0; 30 31 area = alloc_bootmem(size); 32 if(area == NULL) 33 return 0; 34 35 if(load_initrd(initrd, area, size) == -1) 36 return 0; 37 38 initrd_start = (unsigned long) area; 39 initrd_end = initrd_start + size; 40 return 0; 41 } 42 43 __uml_postsetup(read_initrd); 44 45 static int __init uml_initrd_setup(char *line, int *add) 46 { 47 initrd = line; 48 return 0; 49 } 50 51 __uml_setup("initrd=", uml_initrd_setup, 52 "initrd=<initrd image>\n" 53 " This is used to boot UML from an initrd image. The argument is the\n" 54 " name of the file containing the image.\n\n" 55 ); 56 57 int load_initrd(char *filename, void *buf, int size) 58 { 59 int fd, n; 60 61 fd = os_open_file(filename, of_read(OPENFLAGS()), 0); 62 if(fd < 0){ 63 printk("Opening '%s' failed - err = %d\n", filename, -fd); 64 return -1; 65 } 66 n = os_read_file(fd, buf, size); 67 if(n != size){ 68 printk("Read of %d bytes from '%s' failed, err = %d\n", size, 69 filename, -n); 70 return -1; 71 } 72 73 os_close_file(fd); 74 return 0; 75 } 76