Page 1 of 2

GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:08 am
by ClundXIII
Hi all,
finally. I. am. in. this. board.
[offtopic: I created an account with username Clund and email [email protected] ... but freenet simply doesn't recieve any emails from you, so I used my 2nd email ... maybe some Admin can fix this :) ]
I currently got a kernel, that can boot from a floppy (self written bootloader, etc): sf.net/p/imks
(Don't ask me, what it should do later ... I will make a post about that soon and fill my sf wiki ... it should restart parts of itself without rebooting)
This works fine, I can get into 32 bit mode and got some basic libc working. Well, it works in bochs, but not in "RL". I think thats because some wierd floppy behavior or something ... but thats not what I want to fix.

My problem is, that grub simply doesn't accept my kernel. I got the multiboot header set up and everything and it is liked and bless shows me, that it is in the ELF file (little endian ... I hope thats correct) but it still doesnt work ;(

[In attachment you have my complete compiled file ... in case you don't want to run my whole build scripts ;-)]
ooooops, the board wont let me upload it ... you can download it here: http://www.clundxiii.com/myos.elf

Clund(XIII)

(Sorry for my long intro ... I am new in this forum :) )

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:11 am
by Bender
Hi,
What message do you get?
I haven't seen your kernel binary btw.
Is it GRUB 13 Unsupported Format?
Also,
The Bare Bones shows a good example of how to set up a multiboot kernel using GRUB.
-Bender

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:14 am
by ClundXIII
GRUB says "bad magic number"
yea i know this page :P I know this whole site and I used code from this wiki (I hope you don't mind :roll: )
but as you might see with your hex editor ... the magic number is at 0x2000

Clund

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:19 am
by Combuster

Code: Select all

1 .multiboot_header 0000001e  00001000  00001000  00002000  2**12
You put code where it can't go on a real machine, and placed the multiboot header outside the searchable range.

Make sure you use a proper cross-compiler and linker script.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:24 am
by ClundXIII
:mrgreen:
http://sourceforge.net/p/imks/code/ci/m ... nkerscript

Code: Select all

...snip...

    /* First put the multiboot header, as it is required to be put very early
       early in the image or the bootloader won't recognize the file format.
       Next we'll put the .text section. */
    .multiboot_header BLOCK(4K) : ALIGN(4K)
    {
        ./temp/grub-header.o(.multiboot)
        ./temp/grub-header.o(.text)
    }
...snip...
btw http://www.sf.net/p/imks is a link :P (sourceforge)

and my laptop is from '06 (Pentium M) ... I think creating my own cross compiler wont work so nice xD

... what do you mean with out or range :?:

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:47 am
by Bender
what do you mean with out or range
I think he means that GRUB (IIRC) searches for the header within
the first 8K of the kernel binary.
I could be wrong though.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:51 am
by sortie
Hi. Try actually following the instructions at http://wiki.osdev.org/Bare_Bones.

Please note that sourceforge is a pretty crappy project host. Use github or something better. Normally, I wouldn't even visit sourceforge but I feel in a good mood and I'll have a look at your code, prepare for some criticism:

You are not using a cross-compiler! I can see you are on a Linux system, no excuses! You also appear to be passing harmful options like -fno-strict-aliasing (or what it is called). What the ****, are your Makefile replacing your Linux kernel with myos.elf? Note that Linux isn't a multiboot kernel, but uses its own boot protocol. You are loading your kernel at 0x1000 (4 KiB), while Bare Bones tell you to load it at 1 MiB instead. I don't think GRUB can load your kernel that lowly. You also have to use a cross-compiler, no excuses. It looks as if you have taken bits from Bare Bones and butchered it into whatever you have. Your C files are almost more inline assembly than C.

Your directory structure and build system is a bit incomprehensible, I have little idea where to start looking. It doesn't fully help that part of it is in German. Actually, I give up, I have no idea what is going on. Go follow Bare Bones instead of whatever you currently are doing. Perhaps try follow my experimental draft tutorial with an example project structure.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 8:59 am
by ClundXIII
well, that will f*** up my planned memory :mrgreen: but it seems there is no other way ;(
http://sourceforge.net/p/imks/code/ci/m ... y-overview

And, yes, I followed the instructions :P
I will build my cross compiler and everything else, give me 2 hours or so.
But ... that is not why GRUB wont recognize the magic number ... ?

Clund

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 9:04 am
by Combuster
and my laptop is from '06 (Pentium M) ... I think creating my own cross compiler wont work so nice xD

Code: Select all

i386-elf-objdump -s -j .comment myos.elf 

(...)/myos.elf:     file format elf32-i386

Contents of section .comment:
 0000 4743433a 20285562 756e7475 2f4c696e  GCC: (Ubuntu/Lin
 0010 61726f20 342e362e 332d3175 62756e74  aro 4.6.3-1ubunt
 0020 75352920 342e362e 3300               u5) 4.6.3.    
As if using a heavily patched toolchain hasn't already demonstrated not to work :wink:. Regardless of linkerscript, your multiboot header is not the first thing in the file.

Besides, the time it took you to get this question asked would have already built you that crosscompiler.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 9:09 am
by sortie
ClundXIII wrote:And, yes, I followed the instructions :P
Oh, you posted after than I could edit my above post. No, you are not following the instructions of Bare Bones. Please don't lie.

You have multiple problems here. A cross-compiler is just one of them. Linking your kernel at the wrong place is another. I haven't verified, but if your multiboot header is in the wrong place in the file that's a third problem. If you fail to follow instructions, that's a fourth problem. If you are loading your kernel with GRUB as if it was a Linux kernel, that's a fifth problem. :)

Note how Combuster is pointing out that your are using a GCC that came with your distribution and has been altered by your distribution. You have no idea what defaults and other semantics are changed in addition to the compiler thinking it is producing code for a Linux system (rather than a new OS). This is why you want a cross-compiler. Note that you attempting to poorly cover up this mistake by passing bad compiler options you wouldn't need with a cross-compiler.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 9:10 am
by Bender
ClundXIII wrote:well, that will f*** up my planned memory :mrgreen: but it seems there is no other way ;(
http://sourceforge.net/p/imks/code/ci/m ... y-overview

And, yes, I followed the instructions :P
I will build my cross compiler and everything else, give me 2 hours or so.
But ... that is not why GRUB wont recognize the magic number ... ?

Clund
For your info: Loading Kernels below 1MB is the limitation of GRUB not of the multiboot standard.

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 9:34 am
by ClundXIII
okay sorry
hold on everybody ... let me work and please let the shitstorm stop :?
my goal REALLY wasn't to get it working, i just wanted grub to recognize my multiboot header.
What the ****, are your Makefile replacing your Linux kernel with myos.elf?
that was an older linux version that was left ... as I said, I just want the multiboot header to be recognized
I am using an entry via /etc/grub.d/40_custom now :)

Because of the german ... that are very old obsolete parts, that shouldn't be used now. My docs (aka text files) are all english.
Regardless of linkerscript, your multiboot header is not the first thing in the file.
okay, thanks :) how can i change it? should it be like this:
/* Begin putting sections at 1 MiB, a conventional place for kernels to be
loaded at by the bootloader. */
. = 1M;
/* aka 0x100000 */

/* First put the multiboot header, as it is required to be put very early
early in the image or the bootloader won't recognize the file format.
Next we'll put the .text section. */
.multiboot_header BLOCK(4K) : ALIGN(4K)
{
./temp/grub-header.o(.multiboot)
./temp/grub-header.o(.text)
}
I added 1M to all other sections :wink:

And sorry because of my edits, I am sometimes thinking too fast :)

EDIT: here you are: http://sourceforge.net/p/imks/code/ci/4 ... a131b951a/
*gives an virtual coin to Linux Software Foundation for doing this sacrilege*

Clund

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 10:33 am
by ClundXIII
Okay so ...
I am currently downloading the gcc source to compile it (because I have linux I am cloning the repo 8) )
To multiboot and Linux: I didn't know, that Linux is not using the multiboot specification ... I just thought that would be the easiest way to boot a multibot kernel
It looks as if you have taken bits from Bare Bones and butchered it into whatever you have.
:P yes, I had (and still have) a "floppybuilder" woking

Clund

Re: GRUB doesn't want to boot my OS

Posted: Tue Mar 04, 2014 11:06 am
by sortie
Hi,

Please don't consider our responses a shitstorm. We are trying to help you, you have committed some unusual beginner mistakes, that's all. :-)

GCC repo? Please don't tell me you are downloading an experimental unstable version of binutils or gcc, which could lead to all sorts trouble. Simply use the latest stable release of binutils and gcc as compressed archives.

Floppies? They are an obsolete technology and quite space limited. If you wish to produce a portable bootable image, try use the Bare Bones method of creating a bootable cdrom image with grub-mkrescue (or any other program that does so).

Re: GRUB doesn't want to boot my OS

Posted: Wed Mar 05, 2014 12:40 am
by ClundXIII
Here I am again :)

binutils fails after a while with "types in conflict for "malloc" (error msg translated)
it happens at:
../../binutils-2.9.1/binutils/../libiberty/cplus-dem.c:3269:8:

god, how I hate german error messages :mrgreen:

do I have to copy these files or are they otional? do I have to copy them from my system libraries? (I installed everything with the package manager)

Code: Select all

mv gmp-x.y.z gcc-x.y.z/gmp
mv mpfr-x.y.z gcc-x.y.z/mpfr
mv mpc-x.y.z gcc-x.y.z/mpc
"make all-gcc" and "make all-target-libgcc" works fine, but when I want to install it (with "make install-gcc"), it wants to create a folder in my root directory: "/libexec" ... I set the path vars correctly :oops:
export:
http://pastebin.com/UJ1mNChJ

EDIT: maybe you want the output:

Code: Select all

simon@simon-audi:~/build-gcc$ make install-gcc
/bin/bash ../gcc-4.8.2/mkinstalldirs  
make[1]: Betrete Verzeichnis '/home/simon/build-gcc/fixincludes'
rm -rf /libexec/gcc/i686-pc-linux-gnu/4.8.2/install-tools
/bin/bash ../../gcc-4.8.2/fixincludes/../mkinstalldirs /libexec/gcc/i686-pc-linux-gnu/4.8.2/install-tools 
mkdir -p -- /libexec/gcc/i686-pc-linux-gnu/4.8.2/install-tools
mkdir: das Verzeichnis »/libexec“ kann nicht angelegt werden: Keine Berechtigung
make[1]: *** [install] Fehler 1
make[1]: Verlasse Verzeichnis '/home/simon/build-gcc/fixincludes'
make: *** [install-fixincludes] Fehler 2
(and yes, I clean it, exported the vars again and everything ... but nothing works :roll: )

Clund