[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Initialize RAM from a file and save it to the file
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: Initialize RAM from a file and save it to the file |
Date: |
Mon, 19 Jul 2021 12:01:10 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
Hi Hiroko,
On 7/19/21 11:34 AM, Hiroko Shimizu wrote:
> Hello,
> I'd like to initialize RAM from a specific file when RAM is created.
> Then, I tried using memory_region_init_ram_from_file().
To load a file after the machine is created and before the VM is started
I use the 'generic loader device'.
> I wonder what file format is necessary. I tried using a binary file,
> however the contents of the file wasn't recognized and file_size(defined
> in qemu_ram_alloc_from_fd()) was zero.
See the doc in docs/system/generic-loader.rst:
The loader device also allows files to be loaded into memory.
It can load ELF, U-Boot, and Intel HEX executable formats as
well as raw images. The syntax is shown below:
-device
loader,file=<file>[,addr=<addr>][,cpu-num=<cpu-num>][,force-raw=<raw>]
> Could you tell me what I need to do or another way to initialize RAM
> from a file?
>
> Also, is it possible to save RAM's value to the file when a value is
> written to RAM which is initialized memory_region_init_ram_from_file()?
2 years ago I was using -mem-path /dev/shm/ (and maybe -mem-prealloc) to
keep the ram sync on a file, pause the VM and analyse the memory, but it
stopped working after the global memdev refactor. I don't think my use
case was the expected one. Maybe I simply need to adapt to a new command
line format :)
Now I use 'pmemsave' from the monitor:
pmemsave addr size file -- save to disk physical memory dump starting at
'addr' of size 'size'
If attached from GDB:
(gdb) monitor pmemsave 0x20000000 0x1000000 /tmp/ram.dump
There are other commands and probably a clever way to do that.
See also the VM snapshot feature, described here, which might be
what you are looking for:
https://translatedcode.wordpress.com/2015/07/06/tricks-for-debugging-qemu-savevm-snapshots/
Regards,
Phil.