0

I'm trying to run an elf image for an embedded system in Qemu. I read that we can pass elf binaries to Qemu with -kernel option and it configures itself to run the code from the entry address specified in the elf header.

Qemu only allows max 256MB of ram for the specific machine type that I'm trying to emulate. But the entry address in the elf file is out of the range of address space of 256MB ram. So when I connect with gdb and read ram contents starting from the entry address, all I get is 0s.

So my question is, is there any option in the qemu to map a specific address space to the available RAM?

I ran objcopy and got a binary file but its size too large to fit into the ram of qemu(max 256MB).

1 Answers1

0

No. You need to build your binary for the machine type you ask QEMU to use -- the binary and the machine must agree about where RAM and other devices are in the address map. So either pick the right machine type for the binary, or else build the binary for the machine type you want to use. You cannot run an arbitrary binary on any machine type you like.

Regarding -kernel, if you are not trying to load a Linux kernel, you may not want to use that option (though it will work for an ELF file). See this question for a summary of the ways you can ask QEMU to load guest code.

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25
  • Hello @peter, thank you for your answer. I couldn't find any options for mapping an address range to the available ram. I suppose there isn't any option as you have said. But I solved my problem by adding a sub region to sysram with `memory_region_add_subregion` in the source code of qemu and recompiling qemu. – Nurullah Cirit Nov 13 '22 at 22:12