What is a structure of u-boot flash file? ( ARM versatile pb ) - arm

I'm working on creating file that I can load with -kernel option of qemu. I mostly mind here u-boot config file that I have found information should be placed somewhere in file. That file have to contain u-boot binary, freebsd kernel and RTOS to run ( so i can choose which kernel to load or do some experimental developement in loading 2 OS at same time - eg. FreeBSD is loaded by u-boot and then FreeBSD loads FreeRTOS on 2nd core - so called ASMP ). It seems there is no tools around to do that in automatic way ( I mean supporting multiple kernels in one flash file ). So I need to know how is u-boot flash file structured to make my own and pass it to qemu emulating am versatilepb.
qemu-system-arm -M versatilepb -m 128M -nographic -kernel myflashfile

So the answer here depends in part on the board you are emulating with QEMU. Next, unfortunately the versatilepb has been dropped from mainline U-Boot some time ago (and being ARM926EJS it is not the ideal core for ASMP, you may wish to try vexpress a9 instead). Now, all of that said, you want -pflash to pass along a binary file you control the contents of as the parallel flash device used by the machine. And you lay that out however you like since you're still using -kernel u-boot.bin to boot the machine. You may however find it easier to use -tftp /some/dir and load the files via the network instead.

Related

what is the kernel map address in qemu arm when bios option is also given

I am trying to make a baremetal arm os in qemu with baremetal bios as well as kernel.
When I try qemu-system-arm -machine virt -bios boot.bin -nographic boot.bin gets mapped to 0x00 and when i try qemu-system-arm -machine virt -kernel kernel.bin kernel.bin gets mapped to 0x40010000.
So when I do qemu-system-arm -machine virt -bios boot.bin -kernel kernel.bin boot.bin gets mapped to 0x00 but i don't find kernel.bin. I tried to check at 0x40000000 but there also some garbage value is there(might not be garbage but it is not kernel.bin)
I don't find any documentation telling about this, also if I were to use -drive option how can I go forward on this? like Do i need to write a driver for accessing the drive if yes where can I see documentation or something which can guide
If you pass a firmware image to the 'virt' board using -bios then QEMU will put the kernel image (and any initrd) in the 'fw-cfg' device. Guest code in the bios image can then access the fw-cfg device to tell it to DMA the kernel image to whatever address it likes. (This facility is provided primarily for the UEFI BIOS, though of course any guest code can use the fw-cfg device if it likes.)
The data at 0x40000000 is the device tree blob, which is what your bios image should be reading in order to find out where in the address map all the hardware devices are. (This part is documented, at the bottom of https://www.qemu.org/docs/master/system/arm/virt.html)
Note that '-kernel' means "I am a Linux kernel, load me in whatever seems the most appropriate way". If you didn't want that, and just wanted "load a binary image at the address I specify", have a look at the "generic loader" device instead.

MATLAB interface with QEMU

I'm trying to develop a custom machine in QEMU and kind of successful in doing so. Now I want to build a module that can communicate with QEMU to provide some inputs to QEMU and interact with it.
I have chosen MATLAB to build a model that interfaces with my custom machine in QEMU. I know MATLAB has Embedded coder interface and QEMU add on that runs QEMU as third party software internally(downloads the QEMU itself).
But since I have customized QEMU for my machine, how do I interface MATLAB with custom QEMU?
I thought it would be something like running QEMU as
qemu-system-arm -machine x -s -S -kernel x.elf so that when I run QEMU with -s it listens on a port and communicate with other modules. Is this possible with MATLAB? Or is there any other way?

qemu error while running my boot

I wrote a short boot code and tried to run it with Qemu with:
qemu-system-arm.exe -M versatilepb -cpu cortex-a9 -kernel boot.bin
I expected the code to be loaded to address 0x8400000 but qemu returned me the error
Trying to execute code outside RAM or ROM at 0x84000000
This usually means one of the following happened:
(1) You told QEMU to execute a kernel for the wrong machine type, and it crashed on startup (eg trying to run a raspberry pi kernel on a versatilepb QEMU machine)
(2) You didn't give QEMU a kernel or BIOS filename at all, and QEMU executed a ROM full of no-op instructions until it fell off the end
(3) Your guest kernel has a bug and crashed by jumping off into nowhere
This is almost always one of the first two, so check your command line and that you are using the right type of kernel for this machine.
If you think option (3) is likely then you can try debugging your guest with the -d debug options; in particular -d guest_errors will cause the log to include a dump of the guest register state at this point.
Execution cannot continue; stopping here.
So I guess my code has not yet started running because it is not loaded into the right place
What am I wrong about?
Thanks
You say "I expected the code to be loaded to address 0x8400000" but QEMU's error message says "0x84000000" which is not the same number (it has an extra 0). This suggests that you have a typo in your linker script or whatever is creating your boot.bin file. (I am assuming that boot.bin is an ELF file, which QEMU loads at the addresses the ELF file specifies, because otherwise it will be loaded into RAM anyhow on the assumption that it's a Linux kernel image capable of self-relocation.)

How to use QEMU properly with multi boot headers

I am learning the basic of OS making. I have made a multi boot header compliant .asm file and a .c file. The code in the .asm file calls the main function of .c file.
The problem is that QEMU is unable to boot from the file produced after the compilation and linking of the .asm and the .c file .
It simply says that it can't find a bootable device.
Although, I am able to boot from a simple .asm file like :-
mov ax, 0x0e
mov al, 'H'
int 10h
times 510 - ($ - $$) db 0
jmp $
dw 0xaa55
Is there something more which I have to do?
QEMU 2.0.0 does support multiboot
man qemu says:
-kernel bzImage
Use bzImage as kernel image. The kernel can be either a Linux kernel or in multiboot format.
I have uploaded a minimal hello world example at: https://github.com/cirosantilli/x86-bare-metal-examples/tree/dbbed23e4753320aff59bed7d252fb98ef57832f/multiboot
It generates a GAS + C multiboot file, and uses QEMU to run it.
grub-mkrescue can also convert a multiboot binary to a bootable .iso image which is another good approach.
Barry mentions that multiboot2 is not supported. How to generate a multiboot2 image in case you want to test it: How to compile the simple kernel in multiboot2 Spec corrently?
QEMU doesn't have native support for multiboot. Instead, you'll need to create a virtual hard drive image and install some sort of multiboot boot loader (such as grub), then put your multiboot image somewhere on the drive (i.e. in a file on a partition).
As far as actually installing grub onto a virtual HDD, there's multiple ways to do it, but here's the process I always use:
Use qemu-img or dd if=/dev/zero to create your HDD image.
Download a Linux installer ISO (I typically use Arch Linux).
Boot qemu with the blank HDD image and ISO using -hda <HDD-image-filename> -cdrom <ISO-file-name> -boot once=d. The last bit ensures qemu will try to boot from CD first.
Use fdisk/parted/etc to format the disk.
Mount your boot partition (the one you want to install grub to) and use grub-install.
Unmount and shut down the emulator.
Then, you'll be able to boot off the HDD image and use grub or whatever loader you choose to boot your multiboot image.
The reason your simple ASM example works is because you're effectively emulating the MBR, the first sector of a typical hard drive, so QEMU's BIOS will boot from it (specifically, it sees that 0xaa55 signature).
No, QEMU does have native support for the old multiboot spec, although it does not support VBE, ex.. Just compile from a freestanding compiler with the correct legacy multiboot header into an ELF executable and run with the -kernel option

How to add new QEMU machine types without modifying the mainline source code?

Can a new machine type be added for qemu-system-arm -M <MachineType> without having to recompile qemu or write code? Are there docs to do this? I would like to be able to emulate raspberry pi and pandaboard using qemu.
I know that meego's fork of qemu supports pandaboard, but I am trying to stick with the main stream qemu that I can manage from the apt-get package manager. the main stream qemu now supports beagleboard rev C and beagleboard xm that were previously supported only in the meego fork.
without having to recompile qemu or write code?
No. There must be some code doing the device specific emulation, like for example the way the Raspberry Pi or the Pandaboard implement video output. This is not a matter of just a few config files.
I've been able to emulate the Pi with -M versatilepb: https://raspberrypi.stackexchange.com/questions/165/emulation-on-a-linux-pc/53991#53991 and -M raspi2 has was later added in QEMU 2.6.
Maybe this feature is feasible to implement, see my experience with adding a new platform device: How to add a new device in QEMU source code?
There, I only needed to add a single line to attach a new device to versatilepb:
sysbus_create_simple("lkmc_platform_device", 0x101e9000, pic[18]);
so maybe we could have a config file containing lines of type:
type name regid irq
sysbus lkmc_platform_device 0x101e9000 18
Related: out-of-tree devices: How to create out-of-tree QEMU devices?

Resources