FORUMS
Remove All Ads from XDA

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

26 posts
Thanks Meter: 22
 
By tgellen, Junior Member on 13th July 2017, 04:58 PM
Post Reply Email Thread
[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.
Attached Files
File Type: zip aftv-initd-scripts.zip - [Click for QR Code] (516 Bytes, 86 views)
File Type: zip aftv-extra-scripts.zip - [Click for QR Code] (397 Bytes, 56 views)
The Following 6 Users Say Thank You to tgellen For This Useful Post: [ View ] Gift tgellen Ad-Free
 
 
13th July 2017, 05:47 PM |#2  
AFTVnews.com's Avatar
Senior Member
Thanks Meter: 339
 
Donate to Me
More
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.
The Following 2 Users Say Thank You to AFTVnews.com For This Useful Post: [ View ] Gift AFTVnews.com Ad-Free
13th July 2017, 06:22 PM |#3  
Member
Thanks Meter: 7
 
More
Worked nicely on one of my gen 1 sticks running 5.2.4.1_r2.
13th July 2017, 08:54 PM |#4  
Senior Member
Thanks Meter: 13
 
More
OTG works for USB pendrive?
14th July 2017, 09:44 AM |#5  
tgellen's Avatar
OP Junior Member
Thanks Meter: 22
 
More
Quote:
Originally Posted by AFTVnews.com

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
I've now added a zip file with the 2 scripts with UNIX line endings to the post.
Cheers
The Following 6 Users Say Thank You to tgellen For This Useful Post: [ View ] Gift tgellen Ad-Free
15th July 2017, 01:36 AM |#6  
SimLynks's Avatar
Member
Flag NYC
Thanks Meter: 107
 
Donate to Me
More
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.
The Following 2 Users Say Thank You to SimLynks For This Useful Post: [ View ] Gift SimLynks Ad-Free
15th July 2017, 10:32 PM |#7  
Senior Member
Thanks Meter: 13
 
More
Quote:
Originally Posted by dony71

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!
16th July 2017, 08:39 PM |#8  
Senior Member
Flag Sunderland
Thanks Meter: 142
 
More
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.
18th July 2017, 02:24 PM |#9  
Member
Thanks Meter: 16
 
More
What does this actually do? My FireTV already can read from usb drives.
18th July 2017, 03:53 PM |#10  
Member
Thanks Meter: 7
 
More
Quote:
Originally Posted by tdfsu

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.
19th July 2017, 09:36 AM |#11  
tgellen's Avatar
OP Junior Member
Thanks Meter: 22
 
More
Quote:
Originally Posted by Axecaster

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.
The Following 3 Users Say Thank You to tgellen For This Useful Post: [ View ] Gift tgellen Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes