6

I am seeing an issue with my android images where the command adb reboot bootloader simply reboots back the android, instead of going to bootloader mode.

In order to fix the issue, I did some study and find that there are acually two things, adb and adbd and the host and target devices communicate using the TCP protocol over sockets.

So, the interesting thing is commands like adb shell and adb devices are working but not the reboot bootloader. I want to understand what the adbd on receiving the reboot bootloader. Does it change the boor order, sets some flag, changes EFI vars....?

Can you please point to some good links or understanding you can share?

PS : I am working on embedded device environ, similar to raspberry pi...

Naveen
  • 7,944
  • 12
  • 78
  • 165

1 Answers1

10

This is how adb reboot bootloader works on a standard Android device connected via USB (the only transport supported by the standard Android bootloader in the fastboot mode):

  1. adb client sends the reboot bootloader command to the adb server (over TCP)
  2. adb server forwards the reboot bootloader command to the adbd on the device (over USB)
  3. adbd sets the sys.powerctl property to reboot,bootloader
  4. sys.powerctl change triggers the init.rc rule which runs powerctl init's built-in
  5. which does _NR_reboot syscall
  6. which sets the reboot to bootloader flag and reboots the device

On the next power up the bootloader would see the flag and go to the fastboot mode. But only if USB is connected.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • 1
    @InsaneCoder [ADB](https://android.googlesource.com/platform/system/core/+/master/adb/) and [init](https://android.googlesource.com/platform/system/core/+/master/init/) etc. are open-source, so you can see how it works yourself. The kernel sources are a bit harder to dig into, partly because of how much more variation between vendors there is... :-( but mostly they reboot from a `reboot_notifier` handler. What the "bootloader" flag is, also varies greatly, and it's possible it isn't implemented on some ports. – ephemient Feb 10 '17 at 07:50
  • @Alex : Thanks for this valuable info. Can you please tell where can i find this `reboot to bootloader` flag? And is the 4th point incomplete? `built-in` what? – Naveen Feb 10 '17 at 12:15
  • @Alex : Oh wait... I found this http://stackoverflow.com/questions/5472761/how-does-the-bootloader-pick-up-the-command-after-a-restarting-system-with-comm – Naveen Feb 10 '17 at 12:16
  • `powerctl` is an `init` built-in command. and the exact reboot and boot flag setting procedures are SoC specific – Alex P. Feb 10 '17 at 19:26
  • @AlexP. : I searched a lot, but no success. Where is this `reboot to bootloader` flag? I, initially thought it to be `efivars` but when I checked there are no `/sys/firmware/efi/efivars` exported at all. Even on other board, where this `adb reboot bootloader` command is working fine, these variables are not exported in userspace. That means, its implemented differently, to what I was thinking. Can you please give me a direction? – Naveen Feb 22 '17 at 10:40
  • 1
    I can not help you with that. Every SoC vendor handles it differently. This is how Qualcomm does it https://android.googlesource.com/kernel/msm/+/android-msm-bullhead-3.10-marshmallow-dr/drivers/power/reset/msm-poweroff.c – Alex P. Feb 22 '17 at 16:32