65.9K
CodeProject 正在变化。 阅读更多。
Home

TI-SDK 中的自动登录,Am335x

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (3投票s)

2016年3月12日

CPOL

1分钟阅读

viewsIcon

10874

TI-SDK 中的自动登录,Am335x

过去两年我一直在使用 TI-SDK,每次系统工程师提出一些有趣的难题时 :)。 其中一个请求是在 tisdk 中启用自动登录。 想法是在内核启动后直接将用户引导到命令行提示符。 我尝试了几个星期,最终确定了以下更简单的方法。

我将介绍一系列步骤,用于在 tisdk 或嵌入式 Linux 中启用自动登录。

我使用的设置如下

  • 版本:TISDK 7.0
  • 硬件:AM335x
  • 根文件系统:托管在 Ubuntu 上的网络文件系统上 [Ubuntu 是 Vmware 上的客户操作系统]

首先,我需要一个配置文件来设置用户名和密码。 我可以直接在工具中硬编码,但希望给用户控制权。

配置文件如下

#cat /etc/autologin.profile

root,root

然后,我编写了一个小型工具来从配置文件中读取用户名和密码,并使用 /bin/login 登录到 shell。

// 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;
}

注意:您可以根据需要更改此设置。

我为 ARM 交叉编译了该工具,并将编译后的工具放置在 /sbin 中。

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

然后,我更改了 init 脚本以反映更改,基本上设置了 getty。 我的设置使用 Uart0 端口作为控制台。

控制台的配置位于 /etc/inittab 中。 我所做的更改如下突出显示。

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

文件 myloginShell 只是用于我的配置,目的是将我的更改与默认设置隔离。

myloginShell 的内容如下

#!/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

瞧,您已经准备好自动登录了。

您也可以在 inittab 本身中执行相同的操作。

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

感谢您阅读这篇文章,祝您记录愉快。

© . All rights reserved.