Linux Audio

Check our new training course

Loading...
v5.9
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 4 */
 5
 6#include <linux/init.h>
 7#include <linux/memblock.h>
 8#include <linux/initrd.h>
 9#include <asm/types.h>
10#include <init.h>
11#include <os.h>
12
 
 
13/* Changed by uml_initrd_setup, which is a setup */
14static char *initrd __initdata = NULL;
15static int load_initrd(char *filename, void *buf, int size);
16
17int __init read_initrd(void)
18{
 
19	void *area;
20	long long size;
21	int err;
22
23	if (initrd == NULL)
24		return 0;
25
26	err = os_file_size(initrd, &size);
27	if (err)
28		return 0;
29
30	/*
31	 * This is necessary because alloc_bootmem craps out if you
32	 * ask for no memory.
33	 */
34	if (size == 0) {
35		printk(KERN_ERR "\"%s\" is a zero-size initrd\n", initrd);
36		return 0;
37	}
38
39	area = memblock_alloc(size, SMP_CACHE_BYTES);
40	if (!area)
41		panic("%s: Failed to allocate %llu bytes\n", __func__, size);
42
43	if (load_initrd(initrd, area, size) == -1)
44		return 0;
45
46	initrd_start = (unsigned long) area;
47	initrd_end = initrd_start + size;
48	return 0;
49}
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
63static int load_initrd(char *filename, void *buf, int size)
64{
65	int fd, n;
66
67	fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
68	if (fd < 0) {
69		printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
70		       -fd);
71		return -1;
72	}
73	n = os_read_file(fd, buf, size);
74	if (n != size) {
75		printk(KERN_ERR "Read of %d bytes from '%s' failed, "
76		       "err = %d\n", size,
77		       filename, -n);
78		return -1;
79	}
80
81	os_close_file(fd);
82	return 0;
83}
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 4 */
 5
 6#include <linux/init.h>
 7#include <linux/memblock.h>
 8#include <linux/initrd.h>
 9#include <asm/types.h>
10#include <init.h>
11#include <os.h>
12
13#include "um_arch.h"
14
15/* Changed by uml_initrd_setup, which is a setup */
16static char *initrd __initdata = NULL;
 
17
18int __init read_initrd(void)
19{
20	unsigned long long size;
21	void *area;
 
 
 
 
 
22
23	if (!initrd)
 
24		return 0;
25
26	area = uml_load_file(initrd, &size);
 
 
 
 
 
 
 
 
 
27	if (!area)
 
 
 
28		return 0;
29
30	initrd_start = (unsigned long) area;
31	initrd_end = initrd_start + size;
32	return 0;
33}
34
35static int __init uml_initrd_setup(char *line, int *add)
36{
37	*add = 0;
38	initrd = line;
39	return 0;
40}
41
42__uml_setup("initrd=", uml_initrd_setup,
43"initrd=<initrd image>\n"
44"    This is used to boot UML from an initrd image.  The argument is the\n"
45"    name of the file containing the image.\n\n"
46);