first function from kernel

105 views
Skip to first unread message

preetam m.n

unread,
Oct 31, 2011, 7:43:28 AM10/31/11
to android...@googlegroups.com
Hi,

After kernel boots which is the first function in the android file system called and how does kernel know to call the first function of android.

Regards,
Preetam

--
"The great pleasure in life is doing what people say you cannot do"

Yue Zeng

unread,
Oct 31, 2011, 7:57:17 AM10/31/11
to android...@googlegroups.com
u sould read the whole android system code.


preetam m.n

unread,
Oct 31, 2011, 8:07:32 AM10/31/11
to android...@googlegroups.com
Thanks, I have started reading android system code.

I have seen through traces that when in the default boot, the android stack entry is in the file system/core/init/init.c main() function.

I would like to know how does kernel know to call this main function?

Regards,
Preetam

Tim Bird

unread,
Oct 31, 2011, 2:05:56 PM10/31/11
to android...@googlegroups.com, preetam m.n
On 10/31/2011 5:07 AM, preetam m.n wrote:
> Thanks, I have started reading android system code.
>
> I have seen through traces that when in the default boot, the android
> stack entry is in the file system/core/init/init.c main() function.
>
> I would like to know how does kernel know to call this main function?

Normally, the Linux kernel automatically starts a program called 'init', int
the /sbin directory. So most legacy Linux systems have the starting
program placed there: /sbin/init. However, the kernel accepts a command
line variable 'init=<value>' which can be used to specify the starting
program.
In the case of Android, this is set to '/init' (so the full command line
argument is 'init=/init'. This is set by the bootloader. Depending on which
bootloader you are using, you can set this either via the bootloader command
line, or have it read from nvram.

'init' and other kernel command line arguments are documented in the
file: Documentation/kernel_parameters.txt, in the kernel source directory.

The 'main()' function is called by the C initialization code, after the
kernel
starts execution at an address specified in the ELF header for the program.
This is part of the C standard, I believe, but in any case is rather outside
the scope of Android.
-- Tim


preetam m.n

unread,
Oct 31, 2011, 2:35:47 PM10/31/11
to android...@googlegroups.com
Thank you Tim.

Regards,
Preetam

Tim Bird

unread,
Oct 31, 2011, 3:05:04 PM10/31/11
to android...@googlegroups.com, preetam m.n
On 10/31/2011 11:35 AM, preetam m.n wrote:
Thank you Tim.


On Mon, Oct 31, 2011 at 11:35 PM, Tim Bird <tim....@am.sony.com> wrote:
'init' and other kernel command line arguments are documented in the
file: Documentation/kernel_parameters.txt, in the kernel source directory.

One other thing, just for information's sake...

The command line passed to the kernel is printed by
the kernel on startup, and is available in the kernel
log buffer (not to be confused with the Android
system log).  There are usually several other Android-specific
items in the kernel command line.

After a kernel has booted, you can see the kernel
command line, along with other kernel startup messages)
using 'dmesg'.  Here's a sample from my Sony Android
tablet S:

Kernel command line: nvmem=64M@448M mem=1024M@0M vmalloc=192M video=tegrafb console=ttyS0,115200n8 usbcore.old_scheme_first=1 lp0_vec=8192@0x1c404000 odmdata=0x300c0040 androidboot.bootloader=0x00000008 tegraboot=sdmc gpt

(Hmmm.  I just noticed that on this device, it doesn't use the 'init=/init'
argument.  I think it might just symlink /sbin/init to /init, or maybe they've
modified the kernel to default to /init instead of /sbin/init.
You can find the code in the kernel that does the start of the first
program in <kernel_src>/init/main.c in the routine init_post().

Some of the items that you might see in the kernel command line
(specifically some of the items prefixed with 'android')
are not actually parameters to the kernel.

Some of them are set by the bootloader, but used by Android user-space
programs.  If the kernel does not recognize a parameter, it just
ignores it.  The Android system uses this to pass items from the
bootloader to other parts of the system.  The kernel command line
shows up in user space in /proc/cmdline, and some other
android programs look there to find parameters that are used to
control various runtime features.  For example, init looks there
to find out if it should do data collection for bootchart.

This system is a different use for the kernel command line than
I've seen before, and is pretty interesting.
 -- Tim

Sam King

unread,
Oct 31, 2011, 11:05:49 AM10/31/11
to Android Linux Kernel Development
Look for a comment that says "Kernel startup entry point" in head.S

--Sam

On Oct 31, 7:07 am, "preetam m.n" <preeta...@gmail.com> wrote:
> Thanks, I have started reading android system code.
>
> I have seen through traces that when in the default boot, the android stack
> entry is in the file system/core/init/init.c main() function.
>
> I would like to know how does kernel know to call this main function?
>
> Regards,
> Preetam
>
>
>
>
>
>
>
>
>
> On Mon, Oct 31, 2011 at 5:27 PM, Yue Zeng <zenggon...@gmail.com> wrote:
> > u sould read the whole android system code.
>

George Patton

unread,
Oct 31, 2011, 8:09:52 AM10/31/11
to android...@googlegroups.com

I know right

preetam m.n

unread,
Nov 1, 2011, 1:16:30 AM11/1/11
to android...@googlegroups.com
So for instance if i have to boot into recovery in the startup I have to pass recovery path in cmd line of the kernel right?

Tim Bird

unread,
Nov 2, 2011, 11:46:13 AM11/2/11
to android...@googlegroups.com
On 10/31/2011 8:05 AM, Sam King wrote:
> Look for a comment that says "Kernel startup entry point" in head.S
That's the startup entry point for the kernel, not the first
instruction of user-space.
-- Tim

Sam King

unread,
Nov 2, 2011, 1:39:05 PM11/2/11
to Android Linux Kernel Development
Yeah, I know, I misread the question :) I didn't bother following it
up because your posts were right.

--Sam
Reply all
Reply to author
Forward
0 new messages