> 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
On Mon, Oct 31, 2011 at 11:35 PM, Tim Bird <tim.b...@am.sony.com> wrote: > 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
> On Mon, Oct 31, 2011 at 11:35 PM, Tim Bird <tim.b...@am.sony.com > <mailto:tim.b...@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:
(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
> 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.
> > On Mon, Oct 31, 2011 at 7:43 PM, preetam m.n <preeta...@gmail.com> wrote:
> >> 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"
> 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.
>> On Mon, Oct 31, 2011 at 7:43 PM, preetam m.n <preeta...@gmail.com> wrote:
>>> 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"
On Mon, Oct 31, 2011 at 5:39 PM, George Patton <patton7...@gmail.com> wrote: > I know right > On Oct 31, 2011 5: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.
>>> On Mon, Oct 31, 2011 at 7:43 PM, preetam m.n <preeta...@gmail.com>wrote:
>>>> 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"