1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
6 #include <linux/init.h>
7 #include <linux/memblock.h>
8 #include <linux/initrd.h>
13 /* Changed by uml_initrd_setup, which is a setup */
14 static char *initrd __initdata
= NULL
;
15 static int load_initrd(char *filename
, void *buf
, int size
);
17 int __init
read_initrd(void)
26 err
= os_file_size(initrd
, &size
);
31 * This is necessary because alloc_bootmem craps out if you
35 printk(KERN_ERR
"\"%s\" is a zero-size initrd\n", initrd
);
39 area
= memblock_alloc(size
, SMP_CACHE_BYTES
);
41 panic("%s: Failed to allocate %llu bytes\n", __func__
, size
);
43 if (load_initrd(initrd
, area
, size
) == -1)
46 initrd_start
= (unsigned long) area
;
47 initrd_end
= initrd_start
+ size
;
51 static int __init
uml_initrd_setup(char *line
, int *add
)
57 __uml_setup("initrd=", uml_initrd_setup
,
58 "initrd=<initrd image>\n"
59 " This is used to boot UML from an initrd image. The argument is the\n"
60 " name of the file containing the image.\n\n"
63 static int load_initrd(char *filename
, void *buf
, int size
)
67 fd
= os_open_file(filename
, of_read(OPENFLAGS()), 0);
69 printk(KERN_ERR
"Opening '%s' failed - err = %d\n", filename
,
73 n
= os_read_file(fd
, buf
, size
);
75 printk(KERN_ERR
"Read of %d bytes from '%s' failed, "