简体   繁体   中英

How to create C++ executables for flashing ROMs?

I want to create C++ executables to flash ROMs over ADB on android phones, can anyone help me on this? I have a basic knowledge of C++ but cannot understand from where I should start The logic is Initialize header files-->Initialize ADB service-->Start ADB shell-->Flash the .img files using flash_image binary--> ADB reboot

Can anyone give me a simple example for flashing boot image? I m unaware what header files should I include, which compiler should I use. created a new thread as I didn't find anything regarding this

Thank you

adb has nothing to do with flashing ROMs, adb is the debugger interface, which requires system up and running on your phone. And trying to reflash the ROM image with fully running system is like performing a heart surgery without an anaesthetic.

There are two basic ways of reflashing of ROM images correctly:

  1. update.zip
  2. fastboot

The former one is when you copy/download your ROM image as update.zip to the sdcard and then use recovery to update the system. This usually involves users pushing some buttons and powering phone off and on back again. This is the best method, because the update file is already safely stored on the sdcard, can be checked and verified, and the chance of bricking the phone is slim to none.

The second one is when you connect your phone to the PC, switch it to fastboot mode with 'adb reboot bootloader' (or switching off/on and holding some buttons), and then use fastboot to perform ROM update magic. Problem is, when using fastboot you need a very reliable USB connection. Any communication error and the phone is bricked. This is why I don't use and don't recommend fastboot method to reflash ROMs.

If you don't mind bricking your phone using fastboot method, the C++ program would be quite simple.

  1. unpack ROM image somewhere (if you have it packed inside the program)
  2. issue exec() or system() calls to run 'adb reboot bootloader' and then 'fastboot flash*' commands, then, finally 'fastboot reboot'
  3. if you have done everything correctly (catch and process the output of adb and fastboot to check the results), your device will get reflashed and rebooted.

Finally, I'd like to stress again, reflashing ROMs with fastboot is quite dangerous, and I'd recommend to avoid it if possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM