I am trying to implement something which requires me to learn this:- How Raspberry pi NOOBS OS boots in recovery mode while holding SHIFT key?
Can anyone help me regarding this?
This is what I have found out after I checked out noobs code as well as reverse engineering it.
recovery.efi is loaded by bootloader. From here kernel is loaded from
recovery.img or some other one for your pi.
Now kernel will load
recovery.rfs to the ram.
recovery.cmdline contains ram0 as root this means kernel will call
sbin/init from ramdisk.
Now init will call
/usr/bin/recovery (an ELF 32bit arm program) its source code is in noobs git.
main.cpp what I felt is that, after it detects recovery partition, it calls bootmenu function. This function once fixed the partition to boot to, will use SYS_reboot system call to reboot to the new OS.
Now I don't know how it does not invoke the bootloader but I know someone with greater understanding than me will post another how it does not literally reboot.
Also note that
recovery.elf is start.elf which will read
autoboot.txt to set boot partition to boot.
I have successfully booted multiple os with this idea.
Below given is a system call can be invoked with c or cpp.
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "1");
Here /dev/mmcblk0p1 will be taken as the boot partition. You can replace that with 2 for /dev/mmcblk0p2 and so on.
NOOBS is actually an Operating System installer and boot manager.
You CAN NOT "boot in recovery mode while holding SHIFT key" - you need to PRESS SHIFT during the brief period it flashes a message.
It is unclear what you are actually asking; it is simple to detect keypress in a program. If you want a more precise answer about how NOOBS does this you will have to study the code (which is readily available).