Click here to Skip to main content
15,880,956 members
Articles / DevOps

Auto Login in TI-SDK, Am335x

Rate me:
Please Sign up or sign in to vote.
2.33/5 (3 votes)
18 Mar 2016CPOL1 min read 10.3K  
Auto Login in TI-SDK, Am335x

I have been working with TI-SDK for the past two years and every time I come across some interesting trivia posed by the systems engineers :). One such request was to enable automatic login in tisdk. The idea is to lead the user directly to the command prompt after kernel boot up. I tried several approaches over weeks, and zeroed in on the following simpler approach.

I am going to run through a serious of steps followed to enable auto login in tisdk or embedded linux.

The setup which I used are as follows:

  • Version: TISDK 7.0
  • Hw: AM335x
  • Rootfs: Hosted on Network file system on ubuntu [ which is a guest OS on Vmware]

Firstly, I need a configuration file for setting username and password. I can just hard code in the tool but want to give user the control.

The configuration file looks like:

#cat /etc/autologin.profile

root,root

Then, I wrote a small tool to read the username and password from configuration file and use /bin/login for login to the shell.

C++
// Autologin.c

// GPL, Author: Johnnie J. Alan

#include <unistd.h>
#include <stdio.h>

int main()
{
int nrv = 0;
FILE* fptr = 0;
char user[64];

char pass[64];

// clear buffer
memset(user,’\0′,64);

// open autologin profile file
fptr = fopen("/etc/autologin.profile\0″,"r\0″);

// make sure the file exists and was opened
if (fptr != 0)
{
// the return value from fscanf will be 1 if the autologin profile name is read correctly
nrv = fscanf(fptr,"%s,%s\0",user,pass);
}

// only autologin if the profile name was read successfully,
// otherwise show the regular login prompt
if (nrv > 0)
nrv = execlp("login","login","-f",user,0);
else
nrv = execlp("login","login","\0″,pass,0);

return 0;
}

Note: You can change this according to your needs.

I cross compiled the tool for ARM and placed the compiled tool in /sbin.

arm-linux-gnueabihf-gcc -o autologin autologin.c

Then, I changed the init scripts to reflect the changes, basically setting up getty. My setup uses Uart0 port for console.

The configuration for the console is present in /etc/inittab. The changes which I made are highlighted below.

#Johnnie S:2345:respawn:/sbin/getty 115200 ttyO0
S:2345:once:/etc/init.d/myloginShell

The file myloginShell is just used for my configurations, the idea is to isolate my changes from the defaults.

The contents of myloginShell are as follows:

Bash
#!/bin/sh

# I have removed some of other configuration which is not relevant for this post.

showLogin=1
if [ $showLogin -eq 1 ]; then
while true; do
# This is line which is important. ttyO0 indicates by Uart0 console port

# I am asking getty to use my tool instead of /bin/login which is default.
/sbin/getty -n -l /sbin/autologin 115200 ttyO0
exitCode=$?
if [ "$exitCode" = "129" ]; then
break;
fi
done
else
stty -echo
fi

Viola, you have the setup ready to automatic login.

You can also do the same in inittab itself.

#Johnnie S:2345:respawn:/sbin/getty 115200 ttyO0
S:2345:respawn:/sbin/getty -n -l /sbin/autologin 115200 ttyO0

Thanks for reading this post and happy logging.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United States United States
My passion is working on solutions architecture and software development, using an extensive range of technical knowledge and expertise in protocol and driver development, programming, communication peripherals and software applications. Leading projects with major global clients I have developed strong skills in all stages of the software development lifecycle and project management, and possess strong communication skills for working with stakeholders from different backgrounds to understand requirements, lead development and testing, deliver reporting, training and post-implementation support.

I am ambitious and committed to always providing a professional service, and am proud to have consistently received promotions and awards in reward and recognition programs.

Comments and Discussions

 
-- There are no messages in this forum --