OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 7:01 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 8:18 am 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
I'm trying to build a simple linux hello world kernel that will boot with GRUB2. To this end I have isolated the files linux-5.10.1/arch/x86/boot/header.S linux-5.10.1/arch/x86/boot/main.c and linux-5.10.1/arch/x86/boot/setup.ld as a good starting point. After doing a complete make on the linux kernel source I removed header.o and main.o to see what make would do to remake and link these files. Here's what I got:

Code:
make
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  DESCEND  objtool
  DESCEND  bpf/resolve_btfids
  CHK     include/generated/compile.h
  CHK     kernel/kheaders_data.tar.xz
  AS      arch/x86/boot/header.o
  CC      arch/x86/boot/main.o
  LD      arch/x86/boot/setup.elf
  OBJCOPY arch/x86/boot/setup.bin
  BUILD   arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready  (#2)


Does anybody know how I can force make to give better output so that I can get the actual full gcc commands to build and link these files?


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 10:33 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1604
"make V=1" makes it show the full command. "make help" displays a help text that would have told you that.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 12:18 pm 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
Thanks, that did the trick.


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 3:02 pm 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
I managed to build a bootable linux image that boots with GRUB2. However, when I modify main.c to print a Hello linux world message I just get a blank screen for some reason. The good news is it seems to be booting both in legacy and UEFI mode just no output to screen.


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 3:04 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Is the system in graphical mode?

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 22, 2020 3:16 pm 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
:oops:

Not sure. How would I know that?


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Thu Dec 24, 2020 11:30 pm 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
Here is my grub.cfg file

Code:
set timeout=15
set default=0 # Set the default menu entry

menuentry "MYOS" {
   linux /boot/kernel-file 
}


So I don't think it's booting in graphical mode. There must be some other reason why I'm not getting any output to screen.


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Fri Dec 25, 2020 7:15 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
On EFI, it is definitley booting into graphical mode. On BIOS, it may not, but your linux bootstrap code may be putting it in graphical mode. Personally, I would recommend following the Bare Bones tutorial on the Wiki, and using Multiboot 1, then changing to Multiboot 2 later.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Fri Dec 25, 2020 7:39 am 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
What kind of code could be putting it in graphical mode? What am I looking for?


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Sun Dec 27, 2020 1:22 am 
Offline
Member
Member

Joined: Wed Dec 09, 2020 11:32 am
Posts: 49
I thought I found the code that sets graphical mode. There is a function set_mode in video-mode.c which is called by set_video in video.c which is called by main in main.c. I commented out the call and I still get a blank screen.

I then commented out all the function calls in main (just in case) and put a while loop which prints out my message continuously. My new main function looks like this:

Code:
void main(void)
{
        while (1) {
                printf("Hello linux world\n");
        }
}


Still getting a blank screen.


Top
 Profile  
 
 Post subject: Re: linux hello world kernel with GRUB2
PostPosted: Tue Dec 29, 2020 10:09 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
IMO it is better just to write it from scratch. If you are not extremely familliar with Linux, its best not to copy it :) .

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 88 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