• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[HOWTO] Add /etc/init.d support and enable OTG on boot [ROOT REQUIRED]

Search This thread

tgellen

Member
Jun 23, 2014
35
26
[UPDATE #1] I've added a zip file with the 2 scripts, with UNIX line endings :), as suggested below by @aftvNews . Cheers.
[UPDATE #2] I've added a zip file with the 2 extra scripts to go into /etc/init.d, as requested by @Axecaster . These will need the same ownership and permissions as enableotg. They disable SELinux and set the permissions on the recovery directories. Cheers.

Having had a look around the android image on my Fire TV Stick (v1) [ FireOS 5.2.1.1 @rbox ] I found that a script, which doesn't exist, called /system/bin/factoryadb.sh was being run by /init.build.rc on boot.
I was able to create a simple script to run scripts in /etc/init.d on boot.

UPDATE (05/04/19): Now I've got root access on my FireTV Gen 2 [ FireOS 5.2.6.9 ] I can see the see these instructions will also work, although the OTG enabling is not needed ;)

NOTE: I've only tested this on a 1st generation Fire TV Stick but may work on Fire TV boxes if they also call /system/bin/factoryadb.sh from /init.build.rc

Before you do this please make sure factoryadb.sh is NOT on your FireTV and that it is called from /init.build.rc by connecting to your FireTV via adb and running the following commands

Code:
adb shell
su
grep factoryadb /init.build.rc && ls -l /system/bin/factoryadb.sh

Hopefully this will return

Code:
service factoryadb /system/bin/factoryadb.sh
/system/bin/factoryadb.sh: No such file or directory

Now continue ...

My factoryadb.sh script
Code:
#!/system/bin/sh
#
# Execute all scripts in /etc/init.d

if [ -d /etc/init.d ]
then
    for f in `ls /etc/init.d/* 2>/dev/null`
    do
            if [ -s ${f} ]
            then
                    echo Executing ${f} ... >/dev/kmsg
                    /system/bin/sh ${f}
            fi
    done
fi
NOTE: Make sure this file has UNIX line endings only. Notepad++ has an option to specify UNIX line endings.

I also have a simple script to enable OTG which I called enableotg, again MUST have UNIX line endings.
Code:
#!/system/bin/sh
echo 1 >  /sys/devices/platform/bcmpmu_otg_xceiv/host

Connect to the Fire TV Stick via adb and run the following commands

Code:
adb push factoryadb.sh /sdcard/
adb push enableotg /sdcard/
adb shell

su
mount -o remount,rw /system

mkdir /etc/init.d

cp /sdcard/factoryadb.sh /system/bin/
cp /sdcard/enableotg /etc/init.d/

chown 0:0 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg
chmod 755 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg

mount -o remount,ro /system
reboot

When the FireTV Stick has rebooted then reconnect via adb and run the following commands

Code:
adb shell
su
dmesg | grep -e factoryadb -e Executing -e bcmpmu

You should see something similar to

Code:
<6>[    3.005279] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing started...
<6>[    3.007690] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing successful
<3>[    4.998016] init: Warning!  Service factoryadb needs a SELinux domain defined; please fix!
<4>[    5.573242] Executing /etc/init.d/enableotg ...
<6>[    5.579040] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Switching to Host

All is working and OTG should be working about 5 seconds after leaving the TWRP screen and long before Android has finished booting.
If you have an ethernet dongle attached it should have an IP address before the launcher starts :)

NOTE: The SELinux warning can be safely ignored.

Hope this helps.
 

Attachments

  • aftv-initd-scripts.zip
    516 bytes · Views: 435
  • aftv-extra-scripts.zip
    397 bytes · Views: 319
Last edited:

tgellen

Member
Jun 23, 2014
35
26
Nicely done. Clever using the missing factoryadb.sh to roll your own init.d.

Might be easier for some if you just upload/attach your factoryadb.sh and enableotg files that others can download, so there's no need to worry about proper UNIX line endings.

Doh! Completely missed the section to "Attach Files" when I was writing the post :p
I've now added a zip file with the 2 scripts with UNIX line endings to the post.
Cheers :)
 

SimLynks

Senior Member
Sep 30, 2016
69
133
NYC
Awesome job figuring out this was possible! I can confirm the init.d part works just fine on the FireTV-v1 on Rbox v5.2.4.1_r2 (didn't test OTG scripts as I already have a full USB port).

I am going to be adding in your init.d support to my Playing with Fire MOD for the next release.

Now just got to get PS3 / Xbox One controller kernel plugins compiled and working for the Gen1 devices now that init.d works. :good:
 
  • Like
Reactions: puppinoo and Y314K

dony71

Senior Member
Dec 1, 2010
277
14
OTG works for USB pendrive?

I tried this on fire tv stick 1, usb storage does not work.
dmesg shows my Kingston USB pendrive being recognized by kernel,
but registered driver debus_usbdev ?
So I guess kernel doesn't have USB storage driver?

----------------------------------------------------------------------------------------------------
<6>[ 7.267791] usb 3-1: new high speed USB device number 2 using dwc_otg
<6>[ 7.538024] usb 3-1: New USB device found, idVendor=0951, idProduct=1642
<6>[ 7.538116] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
<6>[ 7.538238] usb 3-1: Product: DT 101 G2
<6>[ 7.538330] usb 3-1: Manufacturer: Kingston
<6>[ 7.538482] usb 3-1: SerialNumber: 001CC0EC3509EA50B0000232
<6>[ 47.829345] usbcore: registered new interface driver dbus_usbdev
<3>[ 60.385131] init: Warning! Service adb_usb needs a SELinux domain defined; please fix!
 
Last edited:

sconnyuk

Senior Member
Jul 31, 2011
414
161
Sunderland
Does this enable the use of USB storage ? as ive had this setup for over 6 months now to enable usb pheripal support on boot (with a script booter). If not i guess its still good to do away with the extra apk i had installed to enable my script at boot.
 

Axecaster

Senior Member
Jan 23, 2011
115
13
What does this actually do? My FireTV already can read from usb drives.

Seems mainly for gen 1 sticks to enable usb peripherals. Each boot requires a command to be re-run to recognize usb keyboards, mice, wired networking port, etc. Someone correct me if I'm wrong, but this configuration could in-theory assign multiple scripts to run on boot without extra apps installed.
 

tgellen

Member
Jun 23, 2014
35
26
Seems mainly for gen 1 sticks to enable usb peripherals. Each boot requires a command to be re-run to recognize usb keyboards, mice, wired networking port, etc. Someone correct me if I'm wrong, but this configuration could in-theory assign multiple scripts to run on boot without extra apps installed.

Yes Gen2 sticks and the main FireTV's seem to have OTG already enabled but Gen1 sticks don't.
However even though I've only specified enabling OTG in my initial post, as Axecaster mentioned I do in fact have a number of scripts in /etc/init.d that run on boot.

e.g. Set SELinux to Permissive, set full R/W access on the recovery directories, cleanup some temp files on boot etc

I'm currently checking to see if I can set a static IP on the USB Ethernet adapter I use with my Gen1 stick which will most likely result in a new script in /etc/init.d :)

I also need to investigate the USB storage options more though. Might be the same issue as I'm having with NFS mounts. I can mount an NFS share but currently only root can see it!

Hope this helps.
 

SimLynks

Senior Member
Sep 30, 2016
69
133
NYC
Yes Gen2 sticks and the main FireTV's seem to have OTG already enabled but Gen1 sticks don't.
However even though I've only specified enabling OTG in my initial post, as Axecaster mentioned I do in fact have a number of scripts in /etc/init.d that run on boot.

e.g. Set SELinux to Permissive, set full R/W access on the recovery directories, cleanup some temp files on boot etc

I'm currently checking to see if I can set a static IP on the USB Ethernet adapter I use with my Gen1 stick which will most likely result in a new script in /etc/init.d :)

I also need to investigate the USB storage options more though. Might be the same issue as I'm having with NFS mounts. I can mount an NFS share but currently only root can see it!

Hope this helps.

Have you checked or modified your "persist-usb-config" file yet? If your's has different values than this (from a FireTV-Box) edit it to match mine and see if that helps.

Code:
[email protected]:/ # cat /data/property/persist.sys.usb.config
diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb

As for your NFS shares issue you are going to need to do a Bind Mount to get non-root users able to access the directory. Im using the same bind-mount method to get a bunch of additional GApps installed on the FireTV by binding folders in /data/local/ --> /system/priv-app and using your /etc/init.d/ discovery to launch it automatically on boot.

[email protected]: # mkdir /data/local/nfs && chmod 0755 /data/local/nfs && chown 0:0 /data/local/nfs

init.d startup script:
Code:
#!/system/bin/sh

NFSPATH=/path/to/nfs
NFSDATA=/data/local/nfs

(mount -o bind $NFSPATH $NFSDATA) ; (mount -o remount nosuid,nodev,noexec,reltime,async $NFSPATH)
 

to_b

Member
Dec 30, 2015
22
3
Cologne
Have you checked or modified your "persist-usb-config" file yet? If your's has different values than this (from a FireTV-Box) edit it to match mine and see if that helps.

Result:
Code:
[email protected]:/ # cat /data/property/persist.sys.usb.config
[B]adb[/B][email protected]:/ #

I pulled the file, replaced "adb" with "iag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb", pushed it back and rebooted the device.
Result: ADB is disabled and otg doesn't seem to work (usb flash drive)

Enabling ADB sets the file back to "adb" and after a reboot otg is working again.
 

Y314K

Senior Member
Dec 29, 2008
1,496
488
Samsung Galaxy A32 5G
after installing xposed framework on the fire tv stick this method for otg on boot not longer works.

any solutions?


Hmm. I installed this method after xposed framework. As far as I'm aware, everything seems to be working.
So only setup your scripts after you are done flashing a PreRooted ROM &/or SuperSU &/or XPosed Framework. So in other words only after your done messing with things that mess with /System in TWRP. Or you will have to reset them again.
 
  • Like
Reactions: puppinoo

tgellen

Member
Jun 23, 2014
35
26
Have you checked or modified your "persist-usb-config" file yet? If your's has different values than this (from a FireTV-Box) edit it to match mine and see if that helps.

Code:
[email protected]:/ # cat /data/property/persist.sys.usb.config
diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb

As for your NFS shares issue you are going to need to do a Bind Mount to get non-root users able to access the directory. Im using the same bind-mount method to get a bunch of additional GApps installed on the FireTV by binding folders in /data/local/ --> /system/priv-app and using your /etc/init.d/ discovery to launch it automatically on boot.

[email protected]: # mkdir /data/local/nfs && chmod 0755 /data/local/nfs && chown 0:0 /data/local/nfs

init.d startup script:
Code:
#!/system/bin/sh

NFSPATH=/path/to/nfs
NFSDATA=/data/local/nfs

(mount -o bind $NFSPATH $NFSDATA) ; (mount -o remount nosuid,nodev,noexec,reltime,async $NFSPATH)

Hi SimLynks,
Thanks for your suggestion. The bind mount did make the directory available for the non-root user but unfortunately it's contents were still only visible to the root user :(
I'll keep on trying :)
Cheers.
 

sconnyuk

Senior Member
Jul 31, 2011
414
161
Sunderland
[UPDATE #1] I've added a zip file with the 2 scripts, with UNIX line endings :), as suggested below by AFTVNews. Cheers.
[UPDATE #2] I've added a zip file with the 2 extra scripts to go into /etc/init.d, as requested by Axecaster. These will need the same ownership and permissions as enableotg. They disable SELinux and set the permissions on the recovery directories. Cheers.

Having had a look around the android image on my Fire TV Stick (v1) [FireOS 5.2.1.1 rbox] I found that a script, which doesn't exist, called /system/bin/factoryadb.sh was being run by /init.build.rc on boot.
I was able to create a simple script to run scripts in /etc/init.d on boot.

NOTE: I've only tested this on a 1st generation Fire TV Stick but may work on Fire TV boxes if they also call /system/bin/factoryadb.sh from /init.build.rc

Before you do this please make sure factoryadb.sh is NOT on your FireTV and that it is called from /init.build.rc by connecting to your FireTV via adb and running the following commands

Code:
adb shell
su
grep factoryadb /init.build.rc && ls -l /system/bin/factoryadb.sh

Hopefully this will return

Code:
service factoryadb /system/bin/factoryadb.sh
/system/bin/factoryadb.sh: No such file or directory

Now continue ...

My factoryadb.sh script
Code:
#!/system/bin/sh
#
# Execute all scripts in /etc/init.d

if [ -d /etc/init.d ]
then
    for f in `ls /etc/init.d/* 2>/dev/null`
    do
            if [ -s ${f} ]
            then
                    echo Executing ${f} ... >/dev/kmsg
                    /system/bin/sh ${f}
            fi
    done
fi
NOTE: Make sure this file has UNIX line endings only. Notepad++ has an option to specify UNIX line endings.

I also have a simple script to enable OTG which I called enableotg, again MUST have UNIX line endings.
Code:
#!/system/bin/sh
echo 1 >  /sys/devices/platform/bcmpmu_otg_xceiv/host

Connect to the Fire TV Stick via adb and run the following commands

Code:
adb push factoryadb.sh /sdcard/
adb push enableotg /sdcard/
adb shell

su
mount -o remount,rw /system

mkdir /etc/init.d

cp /sdcard/factoryadb.sh /system/bin/
cp /sdcard/enableotg /etc/init.d/

chown 0:0 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg
chmod 755 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg

mount -o remount,ro /system
reboot

When the FireTV Stick has rebooted then reconnect via adb and run the following commands

Code:
adb shell
su
dmesg | grep -e factoryadb -e Executing -e bcmpmu

You should see something similar to

Code:
<6>[    3.005279] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing started...
<6>[    3.007690] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing successful
<3>[    4.998016] init: Warning!  Service factoryadb needs a SELinux domain defined; please fix!
<4>[    5.573242] Executing /etc/init.d/enableotg ...
<6>[    5.579040] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Switching to Host

All is working and OTG should be working about 5 seconds after leaving the TWRP screen and long before Android has finished booting.
If you have an ethernet dongle attached it should have an IP address before the launcher starts :)

NOTE: The SELinux warning can be safely ignored.

Hope this helps.

Can this be used in some way to enable otg while at the TWRP countdown bar ( as to use keyboard/mouse/airmouse within TWRP), As it's a whole lot easier to use than the ADB mouse, having to plug firestick into laptop/computer if you need to be in recovery, if it is possible it could be easier.
I use the airmouse/keyboard method myself when I go I to recovery but have to use my home made otg cable and swap over usb to computer after running the command to usb dongle for the airmouse (melee F10 pro). After the command has run while plugged into my laptop I unplug the laptop connection and plug in my dongle and I navigate TWRP with my remote.
 

minute

Member
Sep 14, 2009
36
0
It is any chance that we can enable OTG on no-rooted devices of firetv gen 1 ?I have firmware 5.2.6.7 so I think there is no way I can root the device. Thanks!
 

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    [UPDATE #1] I've added a zip file with the 2 scripts, with UNIX line endings :), as suggested below by @aftvNews . Cheers.
    [UPDATE #2] I've added a zip file with the 2 extra scripts to go into /etc/init.d, as requested by @Axecaster . These will need the same ownership and permissions as enableotg. They disable SELinux and set the permissions on the recovery directories. Cheers.

    Having had a look around the android image on my Fire TV Stick (v1) [ FireOS 5.2.1.1 @rbox ] I found that a script, which doesn't exist, called /system/bin/factoryadb.sh was being run by /init.build.rc on boot.
    I was able to create a simple script to run scripts in /etc/init.d on boot.

    UPDATE (05/04/19): Now I've got root access on my FireTV Gen 2 [ FireOS 5.2.6.9 ] I can see the see these instructions will also work, although the OTG enabling is not needed ;)

    NOTE: I've only tested this on a 1st generation Fire TV Stick but may work on Fire TV boxes if they also call /system/bin/factoryadb.sh from /init.build.rc

    Before you do this please make sure factoryadb.sh is NOT on your FireTV and that it is called from /init.build.rc by connecting to your FireTV via adb and running the following commands

    Code:
    adb shell
    su
    grep factoryadb /init.build.rc && ls -l /system/bin/factoryadb.sh

    Hopefully this will return

    Code:
    service factoryadb /system/bin/factoryadb.sh
    /system/bin/factoryadb.sh: No such file or directory

    Now continue ...

    My factoryadb.sh script
    Code:
    #!/system/bin/sh
    #
    # Execute all scripts in /etc/init.d
    
    if [ -d /etc/init.d ]
    then
        for f in `ls /etc/init.d/* 2>/dev/null`
        do
                if [ -s ${f} ]
                then
                        echo Executing ${f} ... >/dev/kmsg
                        /system/bin/sh ${f}
                fi
        done
    fi
    NOTE: Make sure this file has UNIX line endings only. Notepad++ has an option to specify UNIX line endings.

    I also have a simple script to enable OTG which I called enableotg, again MUST have UNIX line endings.
    Code:
    #!/system/bin/sh
    echo 1 >  /sys/devices/platform/bcmpmu_otg_xceiv/host

    Connect to the Fire TV Stick via adb and run the following commands

    Code:
    adb push factoryadb.sh /sdcard/
    adb push enableotg /sdcard/
    adb shell
    
    su
    mount -o remount,rw /system
    
    mkdir /etc/init.d
    
    cp /sdcard/factoryadb.sh /system/bin/
    cp /sdcard/enableotg /etc/init.d/
    
    chown 0:0 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg
    chmod 755 /system/bin/factoryadb.sh /etc/init.d /etc/init.d/enableotg
    
    mount -o remount,ro /system
    reboot

    When the FireTV Stick has rebooted then reconnect via adb and run the following commands

    Code:
    adb shell
    su
    dmesg | grep -e factoryadb -e Executing -e bcmpmu

    You should see something similar to

    Code:
    <6>[    3.005279] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing started...
    <6>[    3.007690] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Probing successful
    <3>[    4.998016] init: Warning!  Service factoryadb needs a SELinux domain defined; please fix!
    <4>[    5.573242] Executing /etc/init.d/enableotg ...
    <6>[    5.579040] bcmpmu_otg_xceiv bcmpmu_otg_xceiv: Switching to Host

    All is working and OTG should be working about 5 seconds after leaving the TWRP screen and long before Android has finished booting.
    If you have an ethernet dongle attached it should have an IP address before the launcher starts :)

    NOTE: The SELinux warning can be safely ignored.

    Hope this helps.
    6
    Nicely done. Clever using the missing factoryadb.sh to roll your own init.d.

    Might be easier for some if you just upload/attach your factoryadb.sh and enableotg files that others can download, so there's no need to worry about proper UNIX line endings.

    Doh! Completely missed the section to "Attach Files" when I was writing the post :p
    I've now added a zip file with the 2 scripts with UNIX line endings to the post.
    Cheers :)
    3
    Seems mainly for gen 1 sticks to enable usb peripherals. Each boot requires a command to be re-run to recognize usb keyboards, mice, wired networking port, etc. Someone correct me if I'm wrong, but this configuration could in-theory assign multiple scripts to run on boot without extra apps installed.

    Yes Gen2 sticks and the main FireTV's seem to have OTG already enabled but Gen1 sticks don't.
    However even though I've only specified enabling OTG in my initial post, as Axecaster mentioned I do in fact have a number of scripts in /etc/init.d that run on boot.

    e.g. Set SELinux to Permissive, set full R/W access on the recovery directories, cleanup some temp files on boot etc

    I'm currently checking to see if I can set a static IP on the USB Ethernet adapter I use with my Gen1 stick which will most likely result in a new script in /etc/init.d :)

    I also need to investigate the USB storage options more though. Might be the same issue as I'm having with NFS mounts. I can mount an NFS share but currently only root can see it!

    Hope this helps.
    2
    Nicely done. Clever using the missing factoryadb.sh to roll your own init.d.

    Might be easier for some if you just upload/attach your factoryadb.sh and enableotg files that others can download, so there's no need to worry about proper UNIX line endings.
    2
    Awesome job figuring out this was possible! I can confirm the init.d part works just fine on the FireTV-v1 on Rbox v5.2.4.1_r2 (didn't test OTG scripts as I already have a full USB port).

    I am going to be adding in your init.d support to my Playing with Fire MOD for the next release.

    Now just got to get PS3 / Xbox One controller kernel plugins compiled and working for the Gen1 devices now that init.d works. :good: