Running raw cdrom image in bochs results in error code 005

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
User avatar
slashx
Posts: 4
Joined: Thu Jul 30, 2020 3:19 pm

Running raw cdrom image in bochs results in error code 005

Post by slashx »

I am playing around with Real Mode code. Unfortunately Bochs is unable to find my cdrom as a bootable device.
I am creating an image using these commands.

Code: Select all

i686-elf-gcc -nostdlib -ffreestanding -c boot.S -o boot.o
i686-elf-ld -nostdlib -ffreestanding boot.o -o boot.elf -Tlinker.ld
objcopy -O binary boot.elf boot.bin
dd if=/dev/zero of=image.img bs=2048 count=16
dd if=boot.bin of=image.img bs=512 conv=notrunc
Inspecting the image, shows that 0x55AA is placed at correct spot (0x1FE from the start)

bochsrc.txt:

Code: Select all

plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, iodebug=true
config_interface: textconfig
display_library: x
memory: host=32, guest=32
romimage: file="/usr/local/share/bochs/BIOS-bochs-latest", address=0x00000000, options=none
vgaromimage: file="/usr/local/share/bochs/VGABIOS-lgpl-latest"
boot: cdrom
floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=none
ata0-slave: type=cdrom, path=image.img, status=inserted
ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=false
ata3: enabled=false
The image is aligned to 2048 bytes and bochs loads the image.

Code: Select all

00000000000i[HD    ] CD on ata0-1: 'image.img'
00000000000i[CD1   ] load cdrom with path=' 'image.img'
00000000000i[CD1   ] Opening image file as a cd.
00000000000i[HD    ] Media present in CD-ROM drive
00000000000i[HD    ] Capacity is 48 sectors (0,09 MB)
Last few log lines

Code: Select all

00005191849i[BIOS  ] IDE time out
00017375870i[BIOS  ] CDROM boot failure code : 0005
00017411533p[BIOS  ] >>PANIC<< No bootable device.
========================================================================
Bochs is exiting with the following message:
[BIOS  ] No bootable device.
========================================================================
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Running raw cdrom image in bochs results in error code 0

Post by Octocontrabass »

Your CD image does not contain a valid El Torito boot record or boot catalog, so it is not bootable.

Typically, you'll want to use a tool like mkisofs or genisoimage or xorriso to create a bootable CD image, since it can be a lot of work to create the boot record and boot catalog otherwise.

The El Torito standard allows three boot modes for CDs: floppy disk emulation, hard disk emulation, and no emulation. In floppy disk and hard disk emulation, you create a floppy disk or hard disk image, then use mkisofs/genisoimage/xorriso to embed that disk image into your CD image, and the BIOS will treat the embedded disk image as if it were a real floppy disk or hard disk. (The emulation only works when you use the BIOS to access the disk.) In no emulation mode, the BIOS does not perform this emulation - you have to write a bootloader specifically for CDs.
User avatar
slashx
Posts: 4
Joined: Thu Jul 30, 2020 3:19 pm

Re: Running raw cdrom image in bochs results in error code 0

Post by slashx »

Thanks for the reply.
I'll see what can i do.

Also one question :D , do USBs also need some kind of emulation like El Torito or they work like hard drives?
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Running raw cdrom image in bochs results in error code 0

Post by Octocontrabass »

USB flash drives work like floppy disks or hard disks, but there is a trick to it. The first sector of your drive must have either a valid partition table or a valid FAT BPB. (In this case, "valid" basically means "created by Windows".) If you don't have that, some PCs won't boot your flash drive correctly.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Running raw cdrom image in bochs results in error code 0

Post by bzt »

BDPL wrote:Also one question :D , do USBs also need some kind of emulation like El Torito or they work like hard drives?
Nope, USB sticks do not need ISO9660 and El Torito Boot Catalog. They only need a boot record just like any hard drive. (More precisely UEFI is really badly specified, and it is not clear if El Torito should be supported only on CDROMs/DVDs or on other media as well. In practice UEFI firmware do not support El Torito on USBs, just like BIOS doesn't.).

FYI, since ISO9660 doesn't use the first 32k of the image, it is easy to create a hybrid image which is bootable as both CDROM (El Torito) and as a hard drive (via standard boot record). You can find such an image creator here, mkbootimg. MIT licensed, you can study the code.

BTW, for CDROMs, I've posted a very minimal ISO image dumper in another topic. You can use that to check if your Boot Catalog is correct.

Cheers,
bzt
Post Reply