All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Initialize RAM from a file and save it to the file
       [not found] <CACproumcn8Dba=Mt7ww-uFtb2kHpLsF36j0DiKEKQSVDtMPpcg@mail.gmail.com>
@ 2021-07-19 10:01 ` Philippe Mathieu-Daudé
  2021-07-19 13:03   ` Igor Mammedov
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-19 10:01 UTC (permalink / raw)
  To: Hiroko Shimizu, qemu-discuss; +Cc: Igor Mammedov, qemu-devel

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Initialize RAM from a file and save it to the file
  2021-07-19 10:01 ` Initialize RAM from a file and save it to the file Philippe Mathieu-Daudé
@ 2021-07-19 13:03   ` Igor Mammedov
  0 siblings, 0 replies; 2+ messages in thread
From: Igor Mammedov @ 2021-07-19 13:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Hiroko Shimizu, qemu-discuss

On Mon, 19 Jul 2021 12:01:10 +0200
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:

> 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().   
...
> > 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

-mem-path should still work as it's aliased to default memdev,
(see: create_default_memdev), that's assumes legacy CLI and that
board uses MachineState::ram as RAM.
(it certainly worked on mainstream boards, if you share your CLI
I can look if it's expected or a bug). 

For new CLI:
it's recommended to use '-machine memory-backend=' which points to previously
specified file backend, ex:

  -object memory-backend-file,id=myram,share=yes,size=1G,mem-path=/ram-image-file \
  -machine memory-backend=myram

Above will create memory region and assign it to MachineState::ram,
so one should use that instead of manually calling memory_region_init_ram_from_file().


> 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.
> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-19 13:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CACproumcn8Dba=Mt7ww-uFtb2kHpLsF36j0DiKEKQSVDtMPpcg@mail.gmail.com>
2021-07-19 10:01 ` Initialize RAM from a file and save it to the file Philippe Mathieu-Daudé
2021-07-19 13:03   ` Igor Mammedov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.