Active Topics

 


Reply
Thread Tools
Community Council | Posts: 4,920 | Thanked: 12,867 times | Joined on May 2012 @ Southerrn Finland
#1
Last night when I was tinkering with my device I thought about ways to get the thing into single-user mode, as I need to do stuff in the initializing phase. It is not quick to experiment on something when you have to repeatedly boot the box to see the effects.

As N9 lacks both hardware keyboard and serial port it would seem to be difficult to interact with the thing before OS & GUI loading, but fortunately I managed to do it. ( quite propably somebody else has done this before, but what the heck, it works for me )

So I decided to use the USB/IP device which requires just loading of one module to be usable, and I tweaked the sshd default parameters a bit, mounted devpts and launched sshd from preinit and it fires up nicely

Why I call this "almost-single-user-mode", is because with this sshd goes daemon and it is possible to connect to the device repeatedly. Hence it is actually more useful than the traditional serial port single-user mode

Here is the diff for sshd_config;

Code:
~ # 
~ # diff /etc/ssh/sshd_config /root/root_sshd_config 
--- /etc/ssh/sshd_config
+++ /root/root_sshd_config
@@ -2,7 +2,7 @@
 # See the sshd(8) manpage for details
 
 # What ports, IPs and protocols we listen for
-Port 22
+Port 12345
 # Use these options to restrict which interfaces/protocols sshd will bind to
 AddressFamily inet
 #ListenAddress ::
@@ -12,7 +12,7 @@
 HostKey /etc/ssh/ssh_host_rsa_key
 HostKey /etc/ssh/ssh_host_dsa_key
 #Privilege Separation is turned on for security
-UsePrivilegeSeparation yes
+UsePrivilegeSeparation no
 
 # Lifetime and size of ephemeral version 1 server key
 KeyRegenerationInterval 3600
@@ -24,7 +24,7 @@
 
 # Authentication:
 LoginGraceTime 120
-PermitRootLogin no
+PermitRootLogin yes
 StrictModes yes
 
 RSAAuthentication yes
@@ -73,7 +73,7 @@
 # Allow client to pass locale environment variables
 AcceptEnv LANG LC_*
 
-Subsystem sftp /usr/lib/openssh/sftp-server
+#Subsystem sftp /usr/lib/openssh/sftp-server
 
 AllowUsers *@127.0.0.1 *@10.0.0.0/8 *@172.16.0.0/12 *@192.168.0.0/16
 
~ # 
~ #
And here is the bit in /sbin/preinit that does the magic:

Code:
sshd_start()
{
        modprobe g_ether
        sleep 1
        /sbin/ifconfig usb0 192.168.2.15 up

        if [ ! -d /dev/pts ] ; then
                mkdir /dev/pts
        fi
        mount -t devpts devpts -o gid=5,mode=620 /dev/pts

        /usr/sbin/sshd -f /root/root_sshd_config

        text2screen -c -B 0x000000
        text2screen -t "Running SSHD on USB" -s 3 -H center -V center

        while [ "1" -le "2" ]
        do
                sleep 1
        done
}
Of course if you want to have a choice of whether to boot into phone mode or single-user mode, you need some glue logic to implement it (this bit is from sillyboot by coderus, it requires you have evkey installed):

Code:
sshd_query()
{
        modprobe twl4030_keypad
        mknod /tmp/keypadi c 13 68
 
        text2screen -c -B 0x000000
        text2screen -t "Press UP for ssh shell" -s 3 -H center -V center
 
        iii=49
        iLIMIT=1
        iyy=470
        while [ "$iLIMIT" -le $iii ]
        do
                let "iii-=1"
                let "iyy=iyy-10"
                text2screen -t " " -s 1 -x 840 -y $iyy -T 0xffffff -B 0xffffff
                iss=$(/bin/evkey -t 200 -d /tmp/keypadi)
                if [ "x$iss" == "x115" ]; then
                        text2screen -c -B 0x000000
                        text2screen -t "Going to start SSHD" -s 3 -H center -V center
                        sleep 2
                        sshd_start
                        break
                fi
                if [ "x$iss" == "x114" ]; then
                        text2screen -c -B 0x000000
                        text2screen -t "Booting next stage" -s 3 -H center -V center
                        sleep 2
                        boot
                        break
                fi
        done
        if [ "x$iii" == "x0" ]; then
                text2screen -c -B 0x000000
                text2screen -t "Defaulting to booting next stage" -s 3 -H center -V center
                sleep 2
                boot
        fi
}
Few prerequirements, of course you must have root password set to something sensible. And like always, be careful when you tinker with boot chain of embedded devices, it is remarkably easy to brick your phone if you do not know what you are doing

I did not write detailed step-by-step granny guide here on purpose, to make people who would like to try this THINK a bit instead just following orders blindly.

This is to protect newbies from bicking their device (and furthermore, to protect me from their anger if somebody manages to do that) but all the required steps are here for anyone who understands the logic of boot chain.
 

The Following 8 Users Say Thank You to juiceme For This Useful Post:
Posts: 1,067 | Thanked: 2,383 times | Joined on Jan 2012 @ Finland
#2
Originally Posted by juiceme View Post
As N9 lacks both hardware keyboard and serial port it would seem to be difficult to interact with the thing before OS & GUI loading, but fortunately I managed to do it. ( quite propably somebody else has done this before, but what the heck, it works for me )
Well actually N9 does have serial port TX&RX pins on the motherboard that you can connect to (you can see them on service manual schematics). But yes, for most people they are a bit hard to reach and requires quite much work and knowledge to get it working.

But great work, this is a much easier way which doesn't require dismantling of the device
__________________
IRC: jonni@freenode
Sailfish: ¤ Qt5 SailfishTouchExample ¤ Qt5 MultiPointTouchArea Example ¤ ipaddress ¤ stoken ¤ Sailbox (Dropbox client) ¤
Harmattan: ¤ Presence VNC for Harmattan ¤ Live-F1 ¤ BTinput-terminal ¤ BabyLock ¤ BabyLock Trial ¤ QML TextTV ¤
Disclaimer: all my posts in this forum are personal trolling and I never post in any official capacity on behalf of any company.
 

The Following User Says Thank You to rainisto For This Useful Post:
Community Council | Posts: 4,920 | Thanked: 12,867 times | Joined on May 2012 @ Southerrn Finland
#3
Originally Posted by rainisto View Post
Well actually N9 does have serial port TX&RX pins on the motherboard that you can connect to (you can see them on service manual schematics). But yes, for most people they are a bit hard to reach and requires quite much work and knowledge to get it working.
You are correct, it would be a bit tedious to get the serial port leads out from the device and still retain the sleek look of the phone chassis, even as I keep my N9 mostly within its silicone cover

BTW; as I have not seen the schematics of N9; am I correct in assuming that the device does have pins inside for the keyboard interface, in same way as N950 does? If so, then it would be nice to try to connect a real physical keyboard to the device...

Originally Posted by rainisto View Post
But great work, this is a much easier way which doesn't require dismantling of the device
Yes, I found this really useful myself. Actually I was almost sure somebody would comment my post as "naah, thats old tricks, done it before". It is nice if other developers find this trick also useful.
 
Reply


 
Forum Jump


All times are GMT. The time now is 21:21.