Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | #!/bin/sh |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 2 | ############################################################################### |
| 3 | # This script is used to automatically set up the serial console(s) on startup. |
| 4 | # The variable SERIAL_CONSOLES can be set in meta/conf/machine/*.conf. |
| 5 | # Script enhancement has been done based on Bug YOCTO #10844. |
| 6 | # Most of the information is retrieved from /proc virtual filesystem containing |
| 7 | # all the runtime system information (eg. system memory, device mount, etc). |
| 8 | ############################################################################### |
| 9 | |
| 10 | # Get active serial filename. |
| 11 | active_serial=$(grep "serial" /proc/tty/drivers | cut -d/ -f1 | sed "s/ *$//") |
| 12 | |
| 13 | # Rephrase input parameter from ttyS target index (ttyS1, ttyS2, ttyAMA0, etc). |
| 14 | runtime_tty=$(echo $2 | grep -oh '[0-9]') |
| 15 | |
| 16 | # Backup $IFS. |
| 17 | DEFAULT_IFS=$IFS |
| 18 | # Customize Internal Field Separator. |
| 19 | IFS="$(printf '\n\t')" |
| 20 | |
| 21 | for line in $active_serial; do |
| 22 | # Check we have the file containing current active serial target index. |
| 23 | if [ -e "/proc/tty/driver/$line" ] |
| 24 | then |
| 25 | # Remove all unknown entries and discard the first line (desc). |
| 26 | activetty=$(grep -v "unknown" "/proc/tty/driver/$line" \ |
| 27 | | tail -n +2 | grep -oh "^\s*\S*[0-9]") |
| 28 | for active in $activetty; do |
| 29 | # If indexes do match then enable the serial console. |
| 30 | if [ $active -eq $runtime_tty ] |
| 31 | then |
| 32 | if [ -c /dev/$2 ] |
| 33 | then |
| 34 | /sbin/getty -L $1 $2 $3 |
| 35 | fi |
| 36 | break |
| 37 | fi |
| 38 | done |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | # Restore $IFS. |
| 43 | IFS=$DEFAULT_IFS |