Page 3 of 3

Re: Anyone tried to code their own bootloader ?

Posted: Fri Jul 25, 2008 1:34 am
by Adek336
Masterkiller wrote:I suppose it doesn't load any drivers.
Well it does, you tell grub which files with the directive "module".

Re: Anyone tried to code their own bootloader ?

Posted: Fri Jul 25, 2008 9:36 pm
by Omega
I wrote a crap one. Now I use GRUB :)


> Me too man. . .me too :(

Re:

Posted: Sat Jul 26, 2008 5:42 am
by Brendan
Hi,
zerosum wrote:I wrote a crap one. Now I use GRUB :-)
Omega wrote:Me too man. . .me too :(
I wrote a crappy boot loader, then I wrote a better one, then I wrote an even better one...

Now (IMHO) I use far better quality code than GRUB uses, and I'm supporting features that GRUB couldn't hope to allow. In addition, I'll never need to port GRUB to my (mostly incompatible, "who needs another Unix clone anyway") OS.

However, due to the way my boot stages work it's relatively easy for me to support GRUB as a potential alternative boot environment for legacy systems (e.g. to allow dual booting with Linux from the same partition). This won't be recommended in the official user guide though - I doubt I'll even mention it...


Cheers,

Brendan

Re: Anyone tried to code their own bootloader ?

Posted: Sat Jul 26, 2008 7:04 am
by Adek336
I'm supporting features that GRUB couldn't hope to allow
What are those?

Re: Anyone tried to code their own bootloader ?

Posted: Sat Jul 26, 2008 9:56 am
by Dragon_Hilord
I just recently started coding (back into OSdev, can't stay away :twisted:) my bootloader from scratch because I have a bunch of specific needs for my OS design. The stage1 I'm currently working on is for CD-ROMs (RW is my current choice of media for physical machine testing), which will load a nice portable stage2 that will use simple device drivers to retrieve the rest of the pieces (the first on the list are CD-ROM and then a driver for my ethernet card). I'm aiming to make it nice and modular, but only time will tell how well that goes :lol:.

Re: Anyone tried to code their own bootloader ?

Posted: Mon Jul 28, 2008 5:31 am
by blackcatcoder
@Brendan : Using GRUB doesn't mean that you write a Unix clone, what a small horizont. GRUB is a very good bootloader which gives you the basic features. What follows after GRUB is up to YOU!


I have written my own bootloader too and have to say if you're using GRUB still stick to it, except you need some other features than e820, A20 gate, and so on, but my oppinion is that GRUB hands you all things you need.

Re: Anyone tried to code their own bootloader ?

Posted: Mon Jul 28, 2008 11:19 am
by Korona
blackcatcoder wrote:@Brendan : Using GRUB doesn't mean that you write a Unix clone, what a small horizont. GRUB is a very good bootloader which gives you the basic features. What follows after GRUB is up to YOU!
GRUB can load non-unix operating system but you cannot build GRUB on a non-unix operating system. So if you are using GRUB you'll have to implement or port a unix toolchain in order to compile GRUB on your operating system.

Re: Anyone tried to code their own bootloader ?

Posted: Mon Jul 28, 2008 7:46 pm
by Brendan
Hi,
Korona wrote:
blackcatcoder wrote:@Brendan : Using GRUB doesn't mean that you write a Unix clone, what a small horizont.
GRUB can load non-unix operating system but you cannot build GRUB on a non-unix operating system. So if you are using GRUB you'll have to implement or port a unix toolchain in order to compile GRUB on your operating system.
Precisely - the boot loader is easy to support, but for an OS like mine the boot loader's installer would need to be completely rewritten, and even if I ignore the other issues it's still easier for me to write my own boot loader/s and installer/s than to rewrite GRUB's installer.
blackcatcoder wrote:GRUB is a very good bootloader which gives you the basic features. What follows after GRUB is up to YOU!
For me, what follows after GRUB is switching back to real mode so I can setup a default video mode and do the memory detection myself using BIOS functions (so that I don't need to rely on the relatively dodgy memory detection done by GRUB). For floppies, this means GRUB consumes 104 KB and the only thing I use it for is reading data from disk and enabling A20 - I can do the same with about 1 KB of code, without the need for additional code to return to real mode (IE. for floppies, GRUB costs over 100 times more space than necessary, which leaves less space for my boot image). For hard drives, netboot/PXE, CD-ROM, etc it's not much different - same problem as floppies (but space and time spent loading data isn't as much of an issue).
Adek336 wrote:
I'm supporting features that GRUB couldn't hope to allow
What are those?
My latest code supports redundant floppy images, where the same data is stored on both sides of a 2 sided disk so that the boot loader can read from the second side if there's read errors on the first side. This means that if the floppy has lots of bad sectors, as long as the boot sector itself is readable then my chances of successfully booting are a *lot* better. This also halves the maximum amount of data I can store on the floppy, but if a boot floppy only needs 720 KiB of data it's worth doing IMHO (as floppies are the most unreliable storage media I've ever used).

Previous versions/prototypes for my OS supported "RAM fault tolerance" - during boot (and during run-time) it could check for faulty RAM, and it maintained a "faulty RAM list". Because the boot code dynamically allocated space for everything it can avoid using faulty RAM *after* this is setup (e.g. after the faulty RAM list is parsed and after a basic memory managemer is initialized). The problem here is that there's always some RAM that's used before the "RAM fault tolerance" is setup - a weak spot, or an "Achille's heal" if you like. For GRUB, this weak spot is about 2 MiB or more (depending on the size of the boot image) because GRUB needs to load everything into RAM (including my boot image, etc) *before* the "RAM fault tolerance" is setup. For my own boot loaders the weak spot is only about 16 KiB, because the "RAM fault tolerance" can be setup *before* I load anything else into RAM.

Next, during run-time if the OS detects that a page of RAM is faulty, then it needs to update the "faulty RAM list" on the boot device so that this new faulty RAM isn't used next time the OS boots. For my boot loaders I can make sure that the OS knows where it booted from. For GRUB it's impossible to reliably figure out exactly where the OS booted from - the best I can do is remember that the OS booted from GRUB and display a "can't update faulty RAM list" warning message.

Note: GRUB (or rather, the multi-boot specification) does have a "boot_device" field in the Multiboot information structure. This field is mostly useless, as "BIOS device number 0x00" could be a floppy disk, but it could also be a CD-ROM or flash memory emulating a floppy disk; and "BIOS device number 0x80" could be a hard disk, but it could also be a CD-ROM or flash memory emulating a hard disk, or something else. It's also entirely useless if you boot from network, or anything else that "BIOS Int 0x13" doesn't support.

Lastly, everything I do uses autodetection if possible to minimise headaches for end-users. For example, this includes working out if the computer is headless or not during boot (checking if a VGA card is present) and automatically monitoring all (autodetected) serial ports if the computer is headless, so that if anything goes wrong (and even if nothing goes wrong) an administrator can plug in a dumb terminal at any time (before, during or after boot) to see a full log of what happened during boot. Except for the A20 gate and memory, GRUB won't autodetect anything and needs to be configured manually by end-users and re-installed. As a side issue, I also can't get a full log of what happened during boot (for administrators that plug in a dumb terminal *after* boot) because GRUB's own messages disappear.

Then there's the problem of file systems - I'm too lazy to write patches for GRUB so that it supports my OS's native file system; and even if I did I doubt it'll be included on a default Redhat install...

Basically, for many potential reasons, GRUB lacks adequate integration with the OS and therefore can't be used to provide a smooth/polished result for a "professional" OS project.


Cheers,

Brendan

Re: Anyone tried to code their own bootloader ?

Posted: Tue Jul 29, 2008 1:50 am
by AJ
Blimey, Brendan!

I know you need patience for OS Dev, but you just have more than most! That spin on using both sides of a floppy disk is very nice. I'm now embarrased to say that my custom boot loader (which I was hoping to release to the OSDev community one day) currently does precisely no memory error checking.

I've just seen my TODO list double in size after reading that. :(

Cheers,
Adam

Re: Anyone tried to code their own bootloader ?

Posted: Tue Jul 29, 2008 8:18 pm
by Telgin
AJ wrote:Blimey, Brendan!

I know you need patience for OS Dev, but you just have more than most! That spin on using both sides of a floppy disk is very nice. I'm now embarrased to say that my custom boot loader (which I was hoping to release to the OSDev community one day) currently does precisely no memory error checking.

I've just seen my TODO list double in size after reading that. :(

Cheers,
Adam
You're embarrased over that? You should see my bootloader, I do pretty much none of that caliber stuff in my bootloader. The most sophisticated thing my bootloader does is parse a config file from a disk image with my own filesystem on it. Unfortunately, it is almost all completely hardcoded in this respect... it only supports reading clusters using INT 0x13 and the disk at 0x80. It does support figuring out the cluster size and other details of the filesystem, but that's about it. All it can do so far is set up unreal mode and A20, parse a config file to find the kernel and load it to memory.

I wouldn't even dream of being able to do all of that sort of stuff in my bootloader. Detecting the presence of VGA cards, dumping things to the serial ports, memory ceecking, even detecting the potential boot media are all well beyond what I figure I can easily accomplish in my loader. I'm just happy being able to parse my filesystem and load my kernel!