How to boot linux kernel without bootloader?

What is the best way to share data between Linux Kernel and a bootloader (and vice versa) without any changes in the latter?

  • If any significant information needs to be pass from Linux Kernel to any bootloader (uboot), which methods we can use given by Linux Kernel? Edit: In order to boot from some other partition or device (just like in recovery scenario), I need to pass some information from Linux Kernel (during panic or some event) to guide Bootloader.

  • Answer:

    Most of the mainstream boot loaders(embedded & PC) supports passing Linux kernel boot arguments (internally implemented as ATAG lists). They serve as an easy mechanism to pass information to Linux kernel, for eg: ram size parameters display type boot partition console parameters logging levels these are few of the generic parameters that are defined already For the application mentioned in the question i.e. In order to boot from some other partition or device (just like in recovery scenario), I need to pass some information from Linux Kernel (during panic or some event) to guide Boot loader. It can be approached in various ways. One of the quick and clean method would be to edit the boot loader configuration(it could be file based or stored as an environment in secondary storage - totally depends on the board setup) & change kernel boot argument corresponding to boot partition. For eg: change root=/dev/hda1 to /dev/hda2 or /dev/sdb1 etc. Or if boot loader is having separate arguments for recovery boot(which is obviously better), then change only that configuration if you are working on a particular Linux kernel module, then your module also can define separate boot arguments. For more information check the following links: http://www.tldp.org/HOWTO/BootPrompt-HOWTO-3.html http://www.denx.de/wiki/view/DULG/LinuxKernelArgs http://www.stlinux.com/u-boot/kernel-booting

Vaisakh Sudheesh at Quora Visit the source

Was this solution helpful to you?

Other answers

Passing information from boot loader to kernel is common. But the other way round is not possible unless one changes the way Linux kernel programs the TLBs. Once the boot loader launches the kernel, first thing kernel does is to reprogram the TLBs thus pushing out the boot loader. This is slightly different on x86-based systems as Linux kernel can raise BIOS interrupts (like INT 0x15 to get physical memory layout) to get information from BIOS.  But the other way round is not possible. One way to accomplish it is to contain the boot loader to certain physical memory addresses and to pin the TLBs holding these locations. When kernel starts, it needs to program all other TLB entries and use rest of the memory.  This also requires remapping physical memory used by uboot to kernel. When kernel needs to call a function(or access data structure within boot loader) call with address of the symbol. That means all the symbol tables are somehow exported (one way is to use boot parameters to input a file) to the kernel. This is very cumbersome and fraught with danger of panicing the system.

Anand Bhat

I would keep NOR flash in mind and answer this questions. Lets consider we have 2 RFS partitions on NOR flash and one partition of small size for storing arguments(i will call it as bootflags) e.g. 2KB. We would like to switch RFS partition if there is error in kernel. RAW NOR flash partition is the key partition, you have put your boot flags in that partition. NOR flash gives byte level access so you can set a byte to indicate that RFS 1 is to be used and reset to indicate RFS 2 is to be used. e.g. Now in following boot sequence should happen, Init function of boot loader should read the raw partition flag to check which partition to use as RFS, pseudo code would look like if ( BOOTFLAG eqto 0xff)     "Set rootfs args to RFS1" else if (BOOTFLAG eqto 0xff)     "Set rootfs agrs to RFS2" So now your BOOTFLAG(stored at offset 0 in RAW partition) handles the switching of RFS. From Linux kernel you have to write this flag and switch the RFS partition. Till this point answer is specific to your questions BUT if you are planning to handle kernel PANIC situation, Bootflag writing and switching logic should be in bootloader. And one more thing is you should make system reset when there is kernel panic.(its matter of setting kernel commandline option see uboot bootargs for more details) E.g. Keep 3 flags as follows in RAW NOR partition. 1. RFS_to_use 2. Kernel_boot_Success 3. Retries. So now boot-loader logic is as follows, a. read RFS_to_use flag from NOR RAW partition. b. read kernel_boot_Success flag from NOR RAW partition. c. read Retries flag from NOR RAW partition( initially zero). if (kernel_boot_Success is NOT eqto success)     Retries = Retries + 1 if (Retries gt 3)      if ( RFS_to_use eqto RFS1)              RFS_to_use = RFS2              Set Uboot boot args to boot from RFS2      else              RFS_to_use = RFS1              Set Uboot boot args to boot from RFS1 else      //Try to boot same RFS at-least three times.      kernel_boot_Success = Failed   At kernel side If kernel boots a. Read kernel_boot_Success flag from NOR RAW partition kernel_boot_Success = Success. Now if you have NAND flash this wont work straight away because you can't access NAND at byte level. But there are different ways to handle that situation. Hope it helps!

Ankur Tank

If it is quite recent kernel and u-boot boot loader, one way of passing a lot of information from u-boot to kernel is Device Tree. So in your case I think you can somehow modify the Device Tree from the kernel so it can react accordingly at the next bootup.

Bảo Anh

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.