OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Jun 16, 2021 10:36 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Help needed booting El Torito boot sector on real machine.
PostPosted: Thu May 06, 2021 8:17 am 
Offline

Joined: Thu May 06, 2021 6:49 am
Posts: 5
Location: New Brunswick, Canada
I've been trying to write a boot loader compatible with both UEFI and legacy BIOS. So far, I've gotten UEFI working fine. As well, the boot sector works in virtual box. However, when I use Win32DiskImager (I'm on Windows with WSL) to put my ISO on a USB drive, only the UEFI boot works. My boot sector should do nothing. It jumps to the start of my code, then jumps to itself. In theory, when running my boot sector, nothing should happen. Instead, when I try to execute it, the cursor jumps around on the left of the screen before returning to the boot media selection menu.
Why would this be happening?
Also, I use the isohdpfx.bin file from the isolinux Debian package. My project is licensed under GPL 3. Is it legal for me to package that file in my project. Also, do I need to give credit? If so, where should I give credit?
As well, I use gnu-efi for the UEFI bootloader portion. To include it, there is a git clone inside my Makefile. Is that OK?

Here is the command I used to make the .iso:
Code:
$ xorriso -as mkisofs -c boot/bootcat -o out/os.iso \
  -b boot/boot_sector.bin -no-emul-boot -boot-load-size 4 \
  -isohybrid-mbr boot/isohdpfx.bin \
  -eltorito-alt-boot -e boot/efi.img -no-emul-boot -isohybrid-gpt-basdat out/iso


I compiled the boot_sector.bin file with nasm:
Code:
$ nasm -f bin -o boot/boot_sector.bin boot_sector.asm


My boot sector is:
Code:
[org 0x7c00]
[bits 16]

Main:
    jmp 0x0:.start

    times 64 - ($ - $$) db 0

.start:
    jmp $


The rest of my code can be found on my GitHub:
https://github.com/ljtpetersen/jpos/


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Thu May 06, 2021 8:01 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1517
ljtpetersen wrote:
As well, the boot sector works in virtual box. However, when I use Win32DiskImager (I'm on Windows with WSL) to put my ISO on a USB drive, only the UEFI boot works.
I'm not sure what those command line argument specifies (and why you have specified "-no-emul-boot" twice), but the no emulation El Torito image needs a boot catalog which records the boot sector's LBA (in 2048 byte sectors). If you want a hybrid image, you'll need:
Code:
sector 0: mbr for HDD
...
sector N: vbr for CDROM
...
sector M: boot catalog, with two entries: sector N for legacy BIOS machines, and sector L for UEFI
...
sector L: starting sector of the ESP

Maybe take a look at my bootloader and hybrid image creator that's known to work perfectly: BOOTBOOT (mkbootimg is an all-in-one, dependency free image creator, MIT licensed, you're free to study it's code).

ljtpetersen wrote:
Also, I use the isohdpfx.bin file from the isolinux Debian package. My project is licensed under GPL 3. Is it legal for me to package that file in my project.
If you also use GPL then yes, but why do you need that in the first place? Or if you're not writing your own loader, then why don't you simply use isolinux's boot sector too?

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Thu May 06, 2021 8:11 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3122
ljtpetersen wrote:
Why would this be happening?

El Torito is for CDs only. It doesn't apply when you're booting from other media.

You've chosen "isohdpfx.bin" as your boot sector for non-CD media. The source code says it's really only meant to load ISOLINUX and nothing else. Are you sure it will load your code correctly?

bzt wrote:
I'm not sure what those command line argument specifies (and why you have specified "-no-emul-boot" twice), but the no emulation El Torito image needs a boot catalog which records the boot sector's LBA (in 2048 byte sectors).

That's what the "-c boot/bootcat" parameter is for.


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Thu May 06, 2021 9:01 pm 
Offline

Joined: Thu May 06, 2021 6:49 am
Posts: 5
Location: New Brunswick, Canada
Haha yeah I posted this topic, then continued debugging and found a solution using one of the tutorials on the wiki. https://wiki.osdev.org/Bootable_Disk
I wanted to delete this topic but it hadn't been verified by the mods yet. By the time I checked, there were already two replies.


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Fri May 07, 2021 4:51 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1517
Octocontrabass wrote:
That's what the "-c boot/bootcat" parameter is for.
Yeah, but we don't know what's in "boot/bootcat". Does it contain all the required entries with valid sector addresses?

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Fri May 07, 2021 1:55 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3122
Yes. The file is generated by xorriso.


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Sat May 08, 2021 12:15 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1517
Octocontrabass wrote:
Yes. The file is generated by xorriso.
I know, what I meant is, we don't know if the boot catalog is generated correctly, one should dump the actual file to see if it has really all the required entries with correct LBA addresses, and if not then there must be a problem with the command line flags. Creating a correct disk image file that can be booted from HDD under BIOS and UEFI and from CDROM under BIOS and UEFI as well is a tricky business, there are lot of things that could go wrong (different sector size is just one example). I've tried to solve these with xorriso too, but ended up writing my own tool instead.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Help needed booting El Torito boot sector on real machin
PostPosted: Sat May 08, 2021 1:22 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3122
This is the same configuration used to generate every Linux hybrid ISO, so I see no reason to suspect issues with the boot catalog. The boot catalog is only used for optical media anyway, so it wouldn't cause problems with USB boot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group