Unable to boot from an AHCI hhd in qemu

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
yanayg
Posts: 2
Joined: Thu Oct 17, 2019 10:06 am

Unable to boot from an AHCI hhd in qemu

Post by yanayg »

I recently started developing my own bootloader and kernel for educational purposes.

I started out booting from a floppy disk using

Code: Select all

qemu-system-i386 -fda image.bin
, and then from a hard drive using

Code: Select all

qemu-system-i386 -hda image.bin
I then started working on an ahci driver for reading / writing from sata hhds.

The problem is when starting qemu using these args (taken from https://stackoverflow.com/questions/483 ... ve-in-qemu)

Code: Select all

qemu-system-i386 \
 -drive id=disk,file=image.bin,if=none \
 -device ahci,id=ahci \
 -device ide-drive,drive=disk,bus=ahci.0
the bios doesn't seem to find the hard drive, it outputs-

Code: Select all

SeaBIOS (version rel-1.12.-0-ga5cab58e9a3f-prebuilt.qemu.org)

iPXE (http://ipxe.org) 00:03.0 C980 PCI2.10 PnP PMM+07F914C0+07EF14C0 C980

Booting from Hard Disk...
Boot failed: could not read the boot disk

Booting from Floppy...
Boot failed: could not read the boot disk

Booting from ROM...
...
starting qemu with

Code: Select all

-boot menu=on
does show the ahci drive, but when I select it it just prints the same output from above.

I tried using qemu 4.1.50 on both linux and windows and 2.8.1 on linux, exact same result in all versions.

A workaround I found (for working on the driver) was using

Code: Select all

qemu-system-i386 \
 -hda image.bin
 -drive id=disk,file=other.bin,if=none \
 -device ahci,id=ahci \
 -device ide-drive,drive=disk,bus=ahci.0
to boot the kernel. (But I do want to boot from the same hard drive that I interact with) I then enumerate the pci bus and find the ahci controller (as part of the driver initialization). But then reading the active ports' sata status results in an ipm of 0 and det of 1 (the device is present but the connection hasn't been initalized) , which according to AHCI the bios should initialize so for now I assume it's the same issue.
Am I doing something wrong here?

(I also posted this question to stack overflow if you happen to encounter it)
yanayg
Posts: 2
Joined: Thu Oct 17, 2019 10:06 am

Re: Unable to boot from an AHCI hhd in qemu

Post by yanayg »

After comparing my bootloader to a different os with ahci hhd support and some more research I figured out I was missing a valid partition table from my mbr, so the BIOS didn't consider it bootable.

I don't exactly know why it worked with

Code: Select all

qemu-system-i386 -hda image.bin
since it should still be a hard drive with partitions, I'll edit this answer if I figure that out.
Post Reply