tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
qemu-riscv: Add initrd support patch
Shea Levy
8 years ago
0022708d
5dc76b39
+100
2 changed files
expand all
collapse all
unified
split
pkgs
applications
virtualization
qemu
riscv-initrd.patch
riscv.nix
+98
pkgs/applications/virtualization/qemu/riscv-initrd.patch
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
1
+
From 44b0f612499764dad425d467aadacb01fbd4a920 Mon Sep 17 00:00:00 2001
2
+
From: Shea Levy <shea@shealevy.com>
3
+
Date: Tue, 20 Feb 2018 07:59:43 -0500
4
+
Subject: [PATCH] riscv: Respect the -initrd flag.
5
+
6
+
Logic for initrd start address borrowed from arm/boot.c
7
+
---
8
+
hw/riscv/virt.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
9
+
1 file changed, 46 insertions(+), 3 deletions(-)
10
+
11
+
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
12
+
index 46d95b2b79..5c7d191a3f 100644
13
+
--- a/hw/riscv/virt.c
14
+
+++ b/hw/riscv/virt.c
15
+
@@ -77,7 +77,35 @@ static uint64_t load_kernel(const char *kernel_filename)
16
+
return kernel_entry;
17
+
}
18
+
19
+
-static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
20
+
+static hwaddr load_initrd(const char *filename, uint64_t mem_size,
21
+
+ uint64_t kernel_entry, hwaddr *start)
22
+
+{
23
+
+ int size;
24
+
+
25
+
+ /* We want to put the initrd far enough into RAM that when the
26
+
+ * kernel is uncompressed it will not clobber the initrd. However
27
+
+ * on boards without much RAM we must ensure that we still leave
28
+
+ * enough room for a decent sized initrd, and on boards with large
29
+
+ * amounts of RAM we must avoid the initrd being so far up in RAM
30
+
+ * that it is outside lowmem and inaccessible to the kernel.
31
+
+ * So for boards with less than 256MB of RAM we put the initrd
32
+
+ * halfway into RAM, and for boards with 256MB of RAM or more we put
33
+
+ * the initrd at 128MB.
34
+
+ */
35
+
+ *start = kernel_entry + MIN(mem_size / 2, 128 * 1024 * 1024);
36
+
+
37
+
+ size = load_ramdisk(filename, *start, mem_size - *start);
38
+
+ if (size == -1) {
39
+
+ size = load_image_targphys(filename, *start, mem_size - *start);
40
+
+ if (size == -1) {
41
+
+ error_report("qemu: could not load ramdisk '%s'", filename);
42
+
+ exit(1);
43
+
+ }
44
+
+ }
45
+
+ return *start + size;
46
+
+}
47
+
+
48
+
+static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
49
+
uint64_t mem_size, const char *cmdline)
50
+
{
51
+
void *fdt;
52
+
@@ -233,6 +261,8 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
53
+
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
54
+
qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
55
+
g_free(nodename);
56
+
+
57
+
+ return fdt;
58
+
}
59
+
60
+
static void riscv_virt_board_init(MachineState *machine)
61
+
@@ -246,6 +276,7 @@ static void riscv_virt_board_init(MachineState *machine)
62
+
char *plic_hart_config;
63
+
size_t plic_hart_config_len;
64
+
int i;
65
+
+ void *fdt;
66
+
67
+
/* Initialize SOC */
68
+
object_initialize(&s->soc, sizeof(s->soc), TYPE_RISCV_HART_ARRAY);
69
+
@@ -265,7 +296,8 @@ static void riscv_virt_board_init(MachineState *machine)
70
+
main_mem);
71
+
72
+
/* create device tree */
73
+
- create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline);
74
+
+ fdt = create_fdt(s, memmap, machine->ram_size,
75
+
+ machine->kernel_cmdline);
76
+
77
+
/* boot rom */
78
+
memory_region_init_ram(boot_rom, NULL, "riscv_virt_board.bootrom",
79
+
@@ -273,7 +305,18 @@ static void riscv_virt_board_init(MachineState *machine)
80
+
memory_region_add_subregion(system_memory, 0x0, boot_rom);
81
+
82
+
if (machine->kernel_filename) {
83
+
- load_kernel(machine->kernel_filename);
84
+
+ uint64_t kernel_entry = load_kernel(machine->kernel_filename);
85
+
+
86
+
+ if (machine->initrd_filename) {
87
+
+ hwaddr start;
88
+
+ hwaddr end = load_initrd(machine->initrd_filename,
89
+
+ machine->ram_size, kernel_entry,
90
+
+ &start);
91
+
+ qemu_fdt_setprop_cell(fdt, "/chosen",
92
+
+ "linux,initrd-start", start);
93
+
+ qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
94
+
+ end);
95
+
+ }
96
+
}
97
+
98
+
/* reset vector */
+2
pkgs/applications/virtualization/qemu/riscv.nix
···
15
in lib.overrideDerivation qemu (orig: {
16
name = "${(builtins.parseDrvName qemu.name).name}-${version}pre${revCount}_${shortRev}";
17
inherit src;
0
0
18
configureFlags = orig.configureFlags ++ [ "--target-list=${lib.concatStringsSep "," targets}" ];
19
postInstall = null;
20
})
···
15
in lib.overrideDerivation qemu (orig: {
16
name = "${(builtins.parseDrvName qemu.name).name}-${version}pre${revCount}_${shortRev}";
17
inherit src;
18
+
# https://github.com/riscv/riscv-qemu/pull/109
19
+
patches = orig.patches ++ [ ./riscv-initrd.patch ];
20
configureFlags = orig.configureFlags ++ [ "--target-list=${lib.concatStringsSep "," targets}" ];
21
postInstall = null;
22
})