Awkward line wrap in Yocto - bash

I'm building an embedded Linux system for ARM architecture using Yocto (thud release).
The image builds and I'm able to flash the board. However, when I connect over serial line, I get this strange line wrapping.
You can see the character h overwriting bash prompt
The line keeps wrapping on the first line. Here is the environment:
guest#:ebox~ # printenv
LANG=C
EDITOR=vi
HZ=100
HUSHLOGIN=FALSE
USER=root
PWD=/home/root
HOME=/home/root
SHELL=/bin/sh
TERM=linux
SHLVL=1
LOGNAME=root
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
PS1=guest#:ebox\w \033[96m# \033[0m
_=/bin/printenv
I looked for solution and the best direction seems to be run with clean environment env -i bash --norc --noprofile
And the env:
bash-4.4# printenv
PWD=/home/root
SHLVL=1
_=/bin/printenv
EDIT: Ok I tried the PS1 prompt by enclosing the unprintable characters in brackets. It worked at that time on the booted system. So I changed the configuration in /etc/profile, built and flashed the system.
Unfortunately it’s not working and I get the same issue - the line wrapping.
Here is the content of the /etc/profile:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
PATH="/usr/local/bin:/usr/bin:/bin"
EDITOR="vi" # needed for packages like cron, git-commit
[ "$TERM" ] || TERM="vt100" # Basic terminal capab. For screen etc.
# Add /sbin & co to $PATH for the root user
[ "$HOME" != "/home/root" ] || PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
# Set the prompt for bash and ash (no other shells known to be in use here)
[ -z "$PS1" ] || PS1="$(cat /etc/device/hwid)#\h:\w \001\033[96m\002# \001\033[0m\002"
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -f $i -a -r $i ]; then
. $i
fi
done
unset i
fi
# Make sure we are on a serial console (i.e. the device used starts with
# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do
# use ssh
case $(tty 2>/dev/null) in
/dev/tty[A-z]*) [ -x /usr/bin/resize ] && /usr/bin/resize >/dev/null;;
esac
export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
umask 022
I also turned on checkwinsize using shopt but didn’t work.
I also include the output of stty (over serial):
speed 115200 baud; line = 0;
-brkint ixoff iutf8
-iexten
And over SSH:
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?;
-brkint ixany iutf8
I connect to the board over serial using screen on Mac. In minicom I get the same issue as do my colleagues on Windows using putty or screen on Linux. Same happens over SSH.
I also checked that the terming package and those files are installed correctly in /etc/terminfo.
EDIT:
I tried to change the size of the shell by using stty cols 100 rows 40 and different sizes but the amount of characters I get on the line stays at 81 followed by carrige return. However if I record the session with script I get the correct amount of characters per line.
Here is my stty -a output:
speed 115200 baud; rows 24; columns 100; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O;
min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff -iuclc -ixany imaxbel
iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho
-extproc
EDIT:
So I tested the behavior on HW and in QEMU. The reported issue is till present in bash on both platforms. However, when I run busybox i don't see such issue only resizing doesn't change the line width and if make the terminal smaller I get on the 80th character new line (in middle of text).
So the problem is probably tight to term being set to fixed size.

Related

Mac Terminal connection to USB connected 3D printer

Trying to connect to a Tevo Tornado 3D printer connected to my MacBook Air via a USB cable.
In terminal I identify the USB devcice and try to connect to it using:
> js$ ls /dev/tty* | grep usb
/dev/tty.usbserial-1410
> js$ screen /dev/tty.usbserial-1410
but that yields an unresponsive screen with random looking characters:
If I connect the printer to a Raspberry Pi running OctoPrint software I can look at the terminal output on the Pi's OctoPrint webpage and see the following exchange:
Connecting to: /dev/ttyUSB0
Changing monitoring state from "Offline" to "Opening serial port"
Connected to: Serial<id=0xabb411d0, open=True>(port='/dev/ttyUSB0'
,baudrate=250000, bytesize=8, parity='N', stopbits=1, timeout=10.0
,xonxoff=False, rtscts=False, dsrdtr=False), starting monitor
Changing monitoring state from "Opening serial port" to "Connecting"
Send: N0M110 N0*125
Send: N0 M110 N0*125
Recv: start
Recv: echo:Marlin TORNADO
Send: N0 M110 N0*125
Recv:
...
This lists the baud rate and other connection parameters that allow that software to successfully connect to the printer. Back in terminal, with the printer re-connected directly to the Mac's USB port, I tried to connect by feeding the above information into the screen command like so:
screen /dev/tty.usbserial-14210 250000,cs8,-parenb,-cstopb,-ixoff
I also tried other variations, but they all yield the unresponsive terminal screen above.
Does anyone have any ideas on what I'm doing wrong and how I can connect to this USB device using Terminal on my Mac?
Update, Ran stty on the octopi connected to the printer and got these results:
pi#octopi:~ $ stty < /dev/ttyUSB0 -a
speed 0 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
discard = ^O; min = 0; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany
-imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl
-echoke -flusho -extproc
Update2:
After looking at source code on the OctoPi there is a file called comm.py. It details a process of opening and closing the port while switching parity settings. Apparently this is some kind of common bug/feature??? This is necessary to do for the Python serial library to connect, which I can now do BTW. Here is the code from comm.py which is part of OctoPrint Source:
use_parity_workaround = settings().get(["serial", "useParityWorkaround"])
needs_parity_workaround = get_os() == "linux" and os.path.exists("/etc/debian_version") # See #673
if use_parity_workaround == "always" or (needs_parity_workaround and use_parity_workaround == "detect"):
serial_obj.parity = serial.PARITY_ODD
serial_obj.open()
serial_obj.close()
serial_obj.parity = serial.PARITY_NONE
serial_obj.open()
I still don't know how to get screen to do this disconnect-change parity-connect process though. So maybe screen is not a possibility???

Change back DPI settings in a bash script

I would like to run a program that does not properly support my desired resolution+DPI settings.
Also I want to change my default GTK theme to a lighter one.
What I currently have:
#!/bin/bash
xfconf-query -c xsettings -p /Xft/DPI -s 0
GTK_THEME=/usr/share/themes/Adwaita/gtk-2.0/gtkrc /home/unknown/scripts/ch_resolution.py --output DP-0 --resolution 2560x1440 beersmith3
This sets my DPI settings to 0, changes the gtk-theme, runs a python script that changes my resolution and runs the program, and on program exit changes it back. This is working properly.
Now I want to change back my DPI settings to 136 on program exit
xfconf-query -c xsettings -p /Xft/DPI -s 136
My guess is I need to use a while loop but have no idea how to do it.
ch_resolution.py
#!/usr/bin/env python3
import argparse
import re
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--output', required=True)
parser.add_argument('--resolution', required=True)
parser.add_argument('APP')
args = parser.parse_args()
device_context = '' # track what device's modes we are looking at
modes = [] # keep track of all the devices and modes discovered
current_modes = [] # remember the user's current settings
# Run xrandr and ask it what devices and modes are supported
xrandrinfo = subprocess.Popen('xrandr -q', shell=True, stdout=subprocess.PIPE)
output = xrandrinfo.communicate()[0].decode().split('\n')
for line in output:
# luckily the various data from xrandr are separated by whitespace...
foo = line.split()
# Check to see if the second word in the line indicates a new context
# -- if so, keep track of the context of the device we're seeing
if len(foo) >= 2: # throw out any weirdly formatted lines
if foo[1] == 'disconnected':
# we have a new context, but it should be ignored
device_context = ''
if foo[1] == 'connected':
# we have a new context that we want to test
device_context = foo[0]
elif device_context != '': # we've previously seen a 'connected' dev
# mode names seem to always be of the format [horiz]x[vert]
# (there can be non-mode information inside of a device context!)
if foo[0].find('x') != -1:
modes.append((device_context, foo[0]))
# we also want to remember what the current mode is, which xrandr
# marks with a '*' character, so we can set things back the way
# we found them at the end:
if line.find('*') != -1:
current_modes.append((device_context, foo[0]))
for mode in modes:
if args.output == mode[0] and args.resolution == mode[1]:
cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
subprocess.call(cmd, shell=True)
break
else:
print('Unable to set mode ' + args.resolution + ' for output ' + args.output)
sys.exit(1)
subprocess.call(args.APP, shell=True)
# Put things back the way we found them
for mode in current_modes:
cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
subprocess.call(cmd, shell=True)
edit:
Thanks #AndreLDM for pointing out that I do not need a separate python script to change the resolution, I don't know why I didn't think of that.
I changed it so I don't need the python script and it is working properly now. If I can improve this script please tell me!
#!/bin/bash
xrandr --output DP-0 --mode 2560x1440
xfconf-query -c xsettings -p /Xft/DPI -s 0
GTK_THEME=/usr/share/themes/Adwaita/gtk-2.0/gtkrc beersmith3
if [ $? == 0 ]
then
xrandr --output DP-0 --mode 3840x2160
xfconf-query -c xsettings -p /Xft/DPI -s 136
exit 0
else
xrandr --output DP-0 --mode 3840x2160
xfconf-query -c xsettings -p /Xft/DPI -s 136
exit 1
fi

How to make shortcut beginning of line ( ctrl-a ) work in kali linux?

Distribution: SMP Debian 4.9.6-3kali2 (2017-01-30)
Shell: bash
Program: Terminal emulator
Problem:
Ctrl + a Go to the beginning of the line (Home) is doing a select all
instead .
Ctrl + e Go to the End of the line (End) is working fine.
What I have tried:
stty - change and print terminal line settings
exemple: stty intr "your_new_shortcut"
$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ;
eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt =^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
Solution
The only solution that I found, at this moment is to use the Xfce terminal include in my distro.
The ctrl-a beginning of the line works fine.
The only solution that I found, at this moment is to use the Xfce terminal include in my distro.
The ctrl-a beginning of the line works fine.
I know what you mean, the terminal has the ability to move to the first character and end of line, so why wouldn't the rest of the distro be able to?
I have found a half solution with the text editor named Atom, this is just for source code management. Perhaps if you're using a more advanced source code editor like RubyMine or any of the Jetbrains suites, they'll have a different way to configure them.
For Atom:
Press the hotkey Ctrl-Comma
Navigate to Keybindings
Find the built in link called your keymap file at the beginning of the file.
Copy and paste this into there:'atom-text-editor':
'atom-text-editor':
'ctrl-e': 'editor:move-to-end-of-screen-line'
'atom-workspace atom-text-editor':
'ctrl-a': 'editor:move-to-first-character-of-line'
'ctrl-shift-a': 'core:select-all'
these controls will be more similar to MacOS. Which I assume anyone asking this question will be making the switch over from there...

Seperate keybindings for return, arrow-up, etc.?

I don't understand why return doesn't have it's own key when working with the readline of bash.
Using control+m is the same as using return.
How to create two separate keybindings, one for control+m and another function for return?
The same applies to arrow-up/-down etc. . Printing them quoted shows that they are not a seperate key, but a key sequence, so I can not use that sequence for another function.
If you changed that, you would find it cumbersome to use any terminal application, because all of the POSIX-like systems use "newline" for ending lines. An ASCII carriage return ^M is normally translated into a newline (which happens to be encoded as ASCII line-feed ^J). If you run stty -a on your terminal you may notice something like this:
~ (4) stty -a
speed 38400 baud; 40 rows; 80 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff -ixany -imaxbel -iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
The icrnl says that carriage-return is mapped to newline. So... if you break your return key, you could type control/M or control/J every time you want a newline. Most people prefer just pressing one key for that purpose.

Can't type 'a' symbol in terminal

I got into a strange behaviour of my terminal. Both iTerm and basic terminal on my OS X don't work. I can only type 'A' instead of 'a', but not the 'a' letter. If I try bash --noediting then I can type 'a' but it's very uncomfortable to use. I checked my ~/.bashrc, ~/.bash_profile and did't find anything that seemed strange for me. Could anyone help me?
Any feedback appreciated.
Most likely you've somehow introduced a readline binding for a.
As a first step, try this: (The grep argument is $"a", but you can't type that :) )
bind -p | grep $'"\x61"'
It should print this:
"a": self-insert
If it does, then my guess is wrong, and you'll need to look elsewhere. If it doesn't, then you need to fix it, which you can do like this:
bind $'"\x61"':self-insert
Now you need to find where in your bash start-up files the incorrect bind command is. I'd start by grepping for bind. It may well be in a file sourced from one of those files. Good luck.
You should also check the file ~/.inputrc which is used by the readline library to initialize it's bindings.
If the letter a has been mapped to one of the control characters, you can get some funny effects. Try stty -a, except that you'll probably need to type:
s, t, t, y, , -, Control-V, a
to get the -a to the command. This should show you something like:
speed 9600 baud; 65 rows; 135 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^X; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
except that if my suspicion is correct, one of the cchars values is a.

Resources