Thursday, June 9, 2016

Auto login after reboot for Beaglebone black (BBB)

By default, BBB board has root log in at console.
My board connected a USB WIFI, I don't want to log in to enter root at console.

1) Auto Login
Edit file:
/lib/systemd/system/serial-getty@.service

[Service]
Environment=TERM=vt100
ExecStart=-/sbin/agetty -a root -s %I 115200

2) Start Service
Create file:
/lib/systemd/system/robot.service

[Unit]
Description=Robot
After=syslog.target network.target network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/run.sh

[Install]
WantedBy=multi-user.target

3) Script file
Create file:
/usr/bin/run.sh

#!/bin/sh

cd /home/root
./run_service.sh

4) Service file
/home/root/run_service.sh

#!/bin/sh
cd /sang/driver

insmod rfkill.ko
insmod cfg80211.ko
insmod mac80211.ko
insmod lib80211.ko
insmod rt2x00lib.ko
insmod rt2800lib.ko
insmod rt2x00usb.ko
insmod rt2800usb.ko

#can bus
echo "can bus set up ..."
echo BB-DCAN1 > /sys/devices/bone_capemgr.9/slots
cd /sang
./canconfig can0 bitrate 300000
ifconfig can0 up

echo "PWM setup ..."

cd /sang/driver
insmod pwm_test.ko

echo am33xx_pwm > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P9_31 > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P9_29 > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P8_36 > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P8_34 > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P8_45 > /sys/devices/bone_capemgr.9/slots
echo bone_pwm_P8_46 > /sys/devices/bone_capemgr.9/slots

5)  run /etc/profile after reboot
Edit /etc/profile

cd /home/root
./run_wifi.sh

6) Start WIFI script file
/home/root/run_wifi.sh

#!/bin/sh

killall wpa_supplicant

ip link set wlan0 up
iw dev wlan0 set power_save off

wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
iw dev wlan0 link

ifconfig wlan0 192.168.2.77 up

mount -o nolock 192.168.2.99:/home/bsang /nfs &
mount -o nolock 192.168.2.96:/home/bsang /nfs2 &