[Tutorial] Creating adb script to flash ROM

Is this tutorial Helpful?

  • Yes

    Votes: 3 75.0%
  • No

    Votes: 0 0.0%
  • May be

    Votes: 1 25.0%

  • Total voters
    4
Search This thread

utsavkoju

Senior Member
Nov 4, 2010
150
111
St. John's
Dear all

I know there are numbers of you who want to start developing for our XL. There are numbers of way to flashROM. Either you can flash your ROM via system.img or ROM.zip etc etc. And here are we to explore creating rom via adb script. The earlier two ROM flashing mean require you to have unlocked bootloader but adb script ROM can be flashed on L/UL mobile devices. Lets get started with:

NOTE: The phone needs to be rooted to flash adb script. For your assistance I will attach a ROM template along with this post.

Preparation
  • Please create two folders inside your working folder with name [Your ROM Name] and [Your ROM Name_PC].
  • Copy all your system files/folder inside your [Your ROM Name] folder.
    Please avoid creating folder within folder to avoid confusion. For example: if you are adding ringtones in your ROM consider creating folder inside [Your ROM Name] with name ringtones instead of creating folder structure like media/audio/ringtones.
  • In [Your ROM Name_PC] folder create a folder with name adb and copy adb.exe, AdbWinApi.dll and AdbWinUsbApi.dll inside it from your android sdk. If you are using my template then you can skip this step as i have already included adb folder inside [Your ROM Name_PC]

Scripting ADB Flasher
1. Create a new text file and rename it as Setup.bat. Remember to remove .txt extension and replace it with .bat extension.
  • Right Click on Setup.bat and click Edit. The file will open in notepad.
    2. Copy Following lines of Code and paste it in your Setup.bat file.
    HTML:
     [user=279333]@ECHO[/user] off
    TITLE [YOUR ROM NAME] by [Dev_Name] [Version 1.0]
    COLOR 70
    mode con:cols=100 lines=40
    ECHO.
    Pause 
    ECHO Waiting For Device.....
    
    
     [user=302893]@adb[/user]\adb wait-for-device
    
     [user=302893]@adb[/user]\adb shell "su -c 'stop'"
    ECHO Getting System access.....
     [user=302893]@adb[/user]\adb shell "su -c 'mount -o rw,remount /system/ /system/'"
    This will mount system folder with read write privilege.
    3. Before flashing your apks and other stuff you need to make sure you remove corresponding stuffs from the system. I have listed generic folders inside the code below please add/delete lines as per your application preferences.
    HTML:
    ECHO Removing system files
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/app/*.odex'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/app/*.apk'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/fonts/*.ttf'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.jar'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.apk'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.odex'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/ringtones/*.ogg'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/alarms/*.ogg'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/notifications/*.ogg'"
     [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/ui/*.ogg'"
    ECHO System files removed successfully!
    ECHO.

    4. Copy each and every content of each folder you want to flash in corresponding folders of the system. Below is the sample code please consider adding/deleting as per your preferences.
    HTML:
    ECHO COPYING FILES.....
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/framework/* /system/framework/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/app/* /system/app/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/fonts/* /system/fonts/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/media/* /system/media/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/ringtones/* /system/media/audio/ringtones/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/alarms/* /system/media/audio/alarms/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/notifications/* /system/media/audio/notifications/'"
     [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/ui/* /system/media/audio/ui/'"

    5. After you have copied all your files/folders into the system you need to add permission in case of framework and apps and any other folders requiring special permission. Below is the sample code please consider adding/deleting as per your preferences.
    HTML:
    ECHO SETTING PERMISSION.....
     [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/framework/*.jar'"
     [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/framework/*.jar'"
     [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/framework/*.apk'"
     [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/framework/*.apk'"
     [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/app/*.apk'"
     [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/app/*.apk'"

    6. We are almost done now. Please consider copying following codes and adding them at the end of your script to remount system as read-only and rebooting the mobile device.
    HTML:
    ECHO.
    ECHO                         --------------------------------------------------------
    ECHO                ----------ROM INSTALLED SUCCESSFULLY------------
    ECHO                         --------------------------------------------------------
    ECHO.
     [user=302893]@adb[/user]\adb shell "su -c 'mount -o ro,remount /system/ /system/'"
    ECHO Rebooting System
     [user=302893]@adb[/user]\adb reboot
    ECHO.
    ECHO Please be patient till device reboot!
    ECHO.
    ECHO.
    ECHO                         --------------------------------------------------------
    ECHO                     -----------------------THANK YOU------------------------
    ECHO                         --------------------------------------------------------
    ECHO.
    pause

    7. Now zip both [Your ROM Name] and [Your ROM Name_PC] folders and upload them to the file sharing sites of your convenience.

    If all goes well you will have a superb ROM to share here at XDA. Please find the attached template along with this post.

    If you like this tutorial please press thanx at the bottom of the post.

    Have a happy time porting.

    CREDITS will be highly appreciated.
 

Attachments

  • template.zip
    173.5 KB · Views: 121
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    Dear all

    I know there are numbers of you who want to start developing for our XL. There are numbers of way to flashROM. Either you can flash your ROM via system.img or ROM.zip etc etc. And here are we to explore creating rom via adb script. The earlier two ROM flashing mean require you to have unlocked bootloader but adb script ROM can be flashed on L/UL mobile devices. Lets get started with:

    NOTE: The phone needs to be rooted to flash adb script. For your assistance I will attach a ROM template along with this post.

    Preparation
    • Please create two folders inside your working folder with name [Your ROM Name] and [Your ROM Name_PC].
    • Copy all your system files/folder inside your [Your ROM Name] folder.
      Please avoid creating folder within folder to avoid confusion. For example: if you are adding ringtones in your ROM consider creating folder inside [Your ROM Name] with name ringtones instead of creating folder structure like media/audio/ringtones.
    • In [Your ROM Name_PC] folder create a folder with name adb and copy adb.exe, AdbWinApi.dll and AdbWinUsbApi.dll inside it from your android sdk. If you are using my template then you can skip this step as i have already included adb folder inside [Your ROM Name_PC]

    Scripting ADB Flasher
    1. Create a new text file and rename it as Setup.bat. Remember to remove .txt extension and replace it with .bat extension.
    • Right Click on Setup.bat and click Edit. The file will open in notepad.
      2. Copy Following lines of Code and paste it in your Setup.bat file.
      HTML:
       [user=279333]@ECHO[/user] off
      TITLE [YOUR ROM NAME] by [Dev_Name] [Version 1.0]
      COLOR 70
      mode con:cols=100 lines=40
      ECHO.
      Pause 
      ECHO Waiting For Device.....
      
      
       [user=302893]@adb[/user]\adb wait-for-device
      
       [user=302893]@adb[/user]\adb shell "su -c 'stop'"
      ECHO Getting System access.....
       [user=302893]@adb[/user]\adb shell "su -c 'mount -o rw,remount /system/ /system/'"
      This will mount system folder with read write privilege.
      3. Before flashing your apks and other stuff you need to make sure you remove corresponding stuffs from the system. I have listed generic folders inside the code below please add/delete lines as per your application preferences.
      HTML:
      ECHO Removing system files
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/app/*.odex'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/app/*.apk'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/fonts/*.ttf'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.jar'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.apk'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/framework/*.odex'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/ringtones/*.ogg'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/alarms/*.ogg'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/notifications/*.ogg'"
       [user=302893]@adb[/user]\adb shell "su -c 'rm /system/media/audio/ui/*.ogg'"
      ECHO System files removed successfully!
      ECHO.

      4. Copy each and every content of each folder you want to flash in corresponding folders of the system. Below is the sample code please consider adding/deleting as per your preferences.
      HTML:
      ECHO COPYING FILES.....
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/framework/* /system/framework/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/app/* /system/app/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/fonts/* /system/fonts/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/media/* /system/media/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/ringtones/* /system/media/audio/ringtones/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/alarms/* /system/media/audio/alarms/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/notifications/* /system/media/audio/notifications/'"
       [user=302893]@adb[/user]\adb shell "su -c 'cp /sdcard/[Your ROM Name]/ui/* /system/media/audio/ui/'"

      5. After you have copied all your files/folders into the system you need to add permission in case of framework and apps and any other folders requiring special permission. Below is the sample code please consider adding/deleting as per your preferences.
      HTML:
      ECHO SETTING PERMISSION.....
       [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/framework/*.jar'"
       [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/framework/*.jar'"
       [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/framework/*.apk'"
       [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/framework/*.apk'"
       [user=302893]@adb[/user]\adb shell "su -c 'chown 0.0 /system/app/*.apk'"
       [user=302893]@adb[/user]\adb shell "su -c 'chmod 0644 /system/app/*.apk'"

      6. We are almost done now. Please consider copying following codes and adding them at the end of your script to remount system as read-only and rebooting the mobile device.
      HTML:
      ECHO.
      ECHO                         --------------------------------------------------------
      ECHO                ----------ROM INSTALLED SUCCESSFULLY------------
      ECHO                         --------------------------------------------------------
      ECHO.
       [user=302893]@adb[/user]\adb shell "su -c 'mount -o ro,remount /system/ /system/'"
      ECHO Rebooting System
       [user=302893]@adb[/user]\adb reboot
      ECHO.
      ECHO Please be patient till device reboot!
      ECHO.
      ECHO.
      ECHO                         --------------------------------------------------------
      ECHO                     -----------------------THANK YOU------------------------
      ECHO                         --------------------------------------------------------
      ECHO.
      pause

      7. Now zip both [Your ROM Name] and [Your ROM Name_PC] folders and upload them to the file sharing sites of your convenience.

      If all goes well you will have a superb ROM to share here at XDA. Please find the attached template along with this post.

      If you like this tutorial please press thanx at the bottom of the post.

      Have a happy time porting.

      CREDITS will be highly appreciated.