Page 1 of 1

Boot Flat Binary kernel Thru GRUB

Posted: Tue Nov 08, 2005 12:00 am
by prajwal
So far i was using my own simple boot loader which use to enable A20
enter Protected Mode and copy my kernel image which is a flat binary file from floppy into memory and jump to Start OS.... so far so fine....

Now i decided to use GRUB to boot the kernel....

Thisi s my Multi Boot Header:-
========================================
_start:
.... few lines of code to jump to Main Function of kernel
....

extern code, bss, end

Align 4
MultiBootHeader:
dd 0x1BADB002
dd 0x00010003
dd -(0x1BADB002 + 0x00010003)
dd MultiBootHeader
dd code
dd bss
dd end
dd _start
===============================================
code, bss and end are defined in the linker script

code is set to 1MB

With this as the first object file i used ld to link other kernel objs generated from gcc
to link and create a Flat Binary (--oformat binary) kernel.bin....

But when i try to boot this using GRUB it throws error saying
Unsupported or Invalid Executable Format

What could be the Issue....

Re: Boot Flat Binary kernel Thru GRUB

Posted: Tue Nov 08, 2005 12:00 am
by carbonBased
I'd take a look at your resultant binary and ensure that the multiboot header is, indeed, there and within correct bounds (within the first 8kb of the binary, and dword aligned).

Otherwise, check through the GRUB sources and see what cases would produce this error message. If more then one, isolate them and retry.

--Jeff

Re: Boot Flat Binary kernel Thru GRUB

Posted: Wed Nov 09, 2005 12:00 am
by prajwal
I'm using BOCHS Emulator...

is it possible to Format the HardDisk Image ifile in ext2 + install GRUB Bootloader on
Hard Disk Image and have my kernel image on HardDisk Image and
Boot using GRUB thru BOCHS from HardDisk Image that BOCHS uses?

Basic nedd is to make the kernel bootable thru GRUB and while doing this i would like
test on BOCHS and then do it on real system....

Re: Boot Flat Binary kernel Thru GRUB

Posted: Wed Nov 09, 2005 12:00 am
by carbonBased
Yes, of course, that's possible. But your choice of emulator and infrastructure is irrelevant if your kernel isn't multiboot compliant (which is what grub is telling you).

Again, I would suggest you investigate your kernel, not your loading process. Open the kernel in a binary editor and ensure the multiboot header is intact, dword aligned, and within the first 8k.

If not, fix this, and retry. If it is, another plan of attack will have to be devised, of course, but I suspect the former case is what you're seeing here.

--Jeff

Re: Boot Flat Binary kernel Thru GRUB

Posted: Thu Nov 10, 2005 12:00 am
by prajwal
Yes, as u suspected there was problem with the MultiBoot Header.... and was fixed;)

I'm using GRUB Bootloader and there are 2 OSs installed on my system...
1) Windows 2000
2) SUSE Linux

Now i made one more entry in GRUB conf for the OS that i'm developing...
On the Real system, it booted fine... no probs ;)

But i want to do this in Emulator BOCHS Environment.... wihich uses a HardDisk
Image file....

How to do this.....

Re: Boot Flat Binary kernel Thru GRUB

Posted: Thu Nov 10, 2005 12:00 am
by carbonBased
The easiest method would be to make your own disk image in Linux.

Assuming your kernel will fit on a 1.44MB floppy, this is the easiest to create (although creating an HD isn't much more difficult, but I presume you'll have to tell BOCHS how many cyl, heads, etc it has. I don't use BOCHS so I don't know how to do this. A floppy, on the other hand, is standardized (mostly) and so BOCHS can assume its geometry).

1. Create the empty disk image:
dd if=/dev/zero of=floppy.img bs=512 count=2880

2. Format it:
mke2fs floppy.img

3. Mount it somewhere using the loopback device:
mount floppy.img /mnt/floppy -o loop

And now you can do as you please with this mounted floppy, as if it were a real floppy (ie, install grub on it, copy your kernel over, etc) and use floppy.img as a disk image to BOCHS.

I've written a tutorial on all of this. It can be found here:
http://neuraldk.org/document.php?grubKernel

Cheers,
Jeff

Re: Boot Flat Binary kernel Thru GRUB

Posted: Fri Nov 11, 2005 12:00 am
by prajwal
Great!....

That os really helpfull