]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/um/kernel/initrd.c
Merge tag 'driver-core-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.git] / arch / um / kernel / initrd.c
CommitLineData
9b67a3c4 1/*
0983a88b 2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
9b67a3c4
JD
3 * Licensed under the GPL
4 */
5
37185b33
AV
6#include <linux/init.h>
7#include <linux/bootmem.h>
8#include <linux/initrd.h>
9#include <asm/types.h>
10#include <init.h>
11#include <os.h>
9b67a3c4
JD
12
13/* Changed by uml_initrd_setup, which is a setup */
14static char *initrd __initdata = NULL;
549e78db 15static int load_initrd(char *filename, void *buf, int size);
9b67a3c4
JD
16
17static int __init read_initrd(void)
18{
19 void *area;
20 long long size;
21 int err;
22
0983a88b 23 if (initrd == NULL)
dc764e50
JD
24 return 0;
25
9b67a3c4 26 err = os_file_size(initrd, &size);
0983a88b 27 if (err)
dc764e50
JD
28 return 0;
29
0983a88b
JD
30 /*
31 * This is necessary because alloc_bootmem craps out if you
32 * ask for no memory.
33 */
34 if (size == 0) {
4631a9a1 35 printk(KERN_ERR "\"%s\" is a zero-size initrd\n", initrd);
0983a88b
JD
36 return 0;
37 }
38
9b67a3c4 39 area = alloc_bootmem(size);
dc764e50 40
0983a88b 41 if (load_initrd(initrd, area, size) == -1)
dc764e50
JD
42 return 0;
43
9b67a3c4
JD
44 initrd_start = (unsigned long) area;
45 initrd_end = initrd_start + size;
46 return 0;
47}
48
49__uml_postsetup(read_initrd);
50
51static int __init uml_initrd_setup(char *line, int *add)
52{
53 initrd = line;
54 return 0;
55}
56
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"
61);
62
549e78db 63static int load_initrd(char *filename, void *buf, int size)
9b67a3c4
JD
64{
65 int fd, n;
66
67 fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
0983a88b
JD
68 if (fd < 0) {
69 printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
70 -fd);
dc764e50 71 return -1;
9b67a3c4 72 }
a6ea4cce 73 n = os_read_file(fd, buf, size);
0983a88b
JD
74 if (n != size) {
75 printk(KERN_ERR "Read of %d bytes from '%s' failed, "
76 "err = %d\n", size,
9b67a3c4 77 filename, -n);
dc764e50 78 return -1;
9b67a3c4
JD
79 }
80
81 os_close_file(fd);
dc764e50 82 return 0;
9b67a3c4 83}