@@ -173,6 +173,46 @@ target_ulong riscv_load_firmware(const char *firmware_filename,
173
173
exit (1 );
174
174
}
175
175
176
+ static void riscv_load_initrd (MachineState * machine , uint64_t kernel_entry )
177
+ {
178
+ const char * filename = machine -> initrd_filename ;
179
+ uint64_t mem_size = machine -> ram_size ;
180
+ void * fdt = machine -> fdt ;
181
+ hwaddr start , end ;
182
+ ssize_t size ;
183
+
184
+ g_assert (filename != NULL );
185
+
186
+ /*
187
+ * We want to put the initrd far enough into RAM that when the
188
+ * kernel is uncompressed it will not clobber the initrd. However
189
+ * on boards without much RAM we must ensure that we still leave
190
+ * enough room for a decent sized initrd, and on boards with large
191
+ * amounts of RAM we must avoid the initrd being so far up in RAM
192
+ * that it is outside lowmem and inaccessible to the kernel.
193
+ * So for boards with less than 256MB of RAM we put the initrd
194
+ * halfway into RAM, and for boards with 256MB of RAM or more we put
195
+ * the initrd at 128MB.
196
+ */
197
+ start = kernel_entry + MIN (mem_size / 2 , 128 * MiB );
198
+
199
+ size = load_ramdisk (filename , start , mem_size - start );
200
+ if (size == -1 ) {
201
+ size = load_image_targphys (filename , start , mem_size - start );
202
+ if (size == -1 ) {
203
+ error_report ("could not load ramdisk '%s'" , filename );
204
+ exit (1 );
205
+ }
206
+ }
207
+
208
+ /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
209
+ if (fdt ) {
210
+ end = start + size ;
211
+ qemu_fdt_setprop_cell (fdt , "/chosen" , "linux,initrd-start" , start );
212
+ qemu_fdt_setprop_cell (fdt , "/chosen" , "linux,initrd-end" , end );
213
+ }
214
+ }
215
+
176
216
target_ulong riscv_load_kernel (MachineState * machine ,
177
217
RISCVHartArrayState * harts ,
178
218
target_ulong kernel_start_addr ,
@@ -234,46 +274,6 @@ target_ulong riscv_load_kernel(MachineState *machine,
234
274
return kernel_entry ;
235
275
}
236
276
237
- void riscv_load_initrd (MachineState * machine , uint64_t kernel_entry )
238
- {
239
- const char * filename = machine -> initrd_filename ;
240
- uint64_t mem_size = machine -> ram_size ;
241
- void * fdt = machine -> fdt ;
242
- hwaddr start , end ;
243
- ssize_t size ;
244
-
245
- g_assert (filename != NULL );
246
-
247
- /*
248
- * We want to put the initrd far enough into RAM that when the
249
- * kernel is uncompressed it will not clobber the initrd. However
250
- * on boards without much RAM we must ensure that we still leave
251
- * enough room for a decent sized initrd, and on boards with large
252
- * amounts of RAM we must avoid the initrd being so far up in RAM
253
- * that it is outside lowmem and inaccessible to the kernel.
254
- * So for boards with less than 256MB of RAM we put the initrd
255
- * halfway into RAM, and for boards with 256MB of RAM or more we put
256
- * the initrd at 128MB.
257
- */
258
- start = kernel_entry + MIN (mem_size / 2 , 128 * MiB );
259
-
260
- size = load_ramdisk (filename , start , mem_size - start );
261
- if (size == -1 ) {
262
- size = load_image_targphys (filename , start , mem_size - start );
263
- if (size == -1 ) {
264
- error_report ("could not load ramdisk '%s'" , filename );
265
- exit (1 );
266
- }
267
- }
268
-
269
- /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */
270
- if (fdt ) {
271
- end = start + size ;
272
- qemu_fdt_setprop_cell (fdt , "/chosen" , "linux,initrd-start" , start );
273
- qemu_fdt_setprop_cell (fdt , "/chosen" , "linux,initrd-end" , end );
274
- }
275
- }
276
-
277
277
/*
278
278
* This function makes an assumption that the DRAM interval
279
279
* 'dram_base' + 'dram_size' is contiguous.
0 commit comments