beaglebone am355 u-boot switch bootpart by GPIO - input

I am trying to boot from partition 3 when gpio 48 is in different state.
If I am changing am355x_evm.h as
#define MCO_BOOT "if gpio input 48; then setenv bootpart ${mmcdev}:3; fi;"
and
NANDARGS \
NETARGS \
DFUARGS \
MCO_BOOT \<---- new line
BOOTENV
#endif
Still goes to /dev/mmkblk0p1
If I type in u-boot prompt
if gpio input 48; then setenv bootpart ${mmcdev}:3; fi
reset
also complains about /sbin/init
What I am doing wrong. Thank you.
Same approach works fine on iMX6, See excerpt here.
"xfile=if load mmc 1:1 0x80008000 bootfact; then setenv mmcrootpart 3; else setenv mmcrootpart 2; fi;\0" \
"fact=if gpio input 120; then setenv mmcrootpart 3 ; else run xfile; fi; printenv mmcrootpart;\0" \

I think I found it. I had to set also mmcpart.

Related

How to pass environment variables to a gem5 syscall emulation simulation?

For example, I have a test C program that prints all environment variables:
#include <stdio.h>
#include <stdlib.h>
extern char **environ;
int main(void) {
char **env = environ;
while (*env) {
printf("%s\n", *env);
env++;
}
return EXIT_SUCCESS;
}
GitHub upstream
But when I run it in se.py syscall emulation, it does not print anything, so I'm guessing that gem5 has an empty environment set in syscall emulation by default instead of inheriting the host's.
Tested on gem5 872cb227fdc0b4d60acc7840889d567a6936b6e1.
By doing a quick se.py --help | grep -i env we see:
-e ENV, --env=ENV Initialize workload environment from text file.
and so the following works as expected:
printf 'a=b\nc=d\n' > env.sh
se.py -e env.sh
and the test program prints:
a=b
c=d
Trying to use Bash's <() notation does not work however, gem5 really needs that to be placed in regular file, trying that fails with:
IOError: [Errno 2] No such file or directory: '/dev/fd/63'

Systems programming qemu: unknown keycodes `(unnamed)'

I am trying to run qemu with code that my teacher provided so that we are able to work on our assignment.
This is being run in Ubuntu 18.04
LIBPATH=/usr/lib/gcc/arm-none-eabi/6.3.1/
arm-none-eabi-as -mcpu=arm926ej-s -g ts.s -o ts.o
arm-none-eabi-gcc -c -mcpu=arm926ej-s -g t.c -o t.o
arm-none-eabi-ld -T t.ld ts.o t.o -o t.elf
arm-none-eabi-ld -T t.ld -L $LIBPATH ts.o t.o -o t.elf -lgcc #-lstr
arm-none-eabi-objcopy -O binary t.elf t.bin
rm *.o *.elf
echo ready to go?
read dummy
qemu-system-arm -M realview-pbx-a9 -m 128M -kernel t.bin \
-serial mon:stdio -serial /dev/pts/2 -serial /dev/pts/2 -serial /dev/pts/2
And the numbers in the last line `-serial /dev/pts/#' are from running ps in the terminal and grabbing the number. All of this is in an executable file, and when I run the file the qemu screen does display, but when I press enter again I recieve this error message
unknown keycodes `(unnamed)', please report to qemu-devel#nongnu.org
I cannot seem to find any clear answer on how to solve this problem. I have tried uninstalling and reinstalling qemu a couple of time.
QEMU's "unknown keycodes" message is about key handling in its graphics window, and means that the host keyboard mapping you're using has some odd setup that it doesn't entirely understand. Usually this means that a few keys won't work right in the graphics window, and you can ignore it unless you're actually having a problem with them. The whole keycode system was completely rewritten in a newer version of QEMU, and this message doesn't even exist any more.
If your test program isn't expecting to use the graphical screen, then you can definitely ignore the message (indeed you could turn off the graphics screen entirely with -display none).
The command line options to QEMU you're using for the serial port look really odd -- you seem to be trying to connect multiple serial ports to the same host tty, which I'm pretty sure won't work right. Unless you're actually using serial ports 1 through 3, just drop those and use the serial port 0 that is set up with "-serial mon:stdio".

GNU Screen terminal line settings

I want to use GNU screen to monitor to a serial USB port like this:
$ screen /dev/ttyUSB0 115200
But I need to tweak a few terminal line settings. I have made several attempts but none seem to work. For example, to send NL+CR for a newline character, not just NL, the terminal line setting is onlcr.
Attempt 1 - without any special settings:
$ screen /dev/ttyUSB0 115200
# only sends NL
Attempt 2 - via screen:
$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL
Attempt 3 - via ssty:
$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200
# still only sends NL
Attempt 4 - via both:
$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL
Attempt 5 - in the other order:
$ screen /dev/ttyUSB0 115200,onlcr
# then ctrl+a, ctrl+z to pause the screen session
$ stty -F /dev/ttyUSB0 onlcr
stty: /dev/ttyUSB0: Device or resource busy
In all cases, if I run stty to check the terminal line settings I get this:
Before running screen - note the -onlcr is present:
$ stty -F /dev/ttyUSB0
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo
Changing the stty setting - note the -onlcr has gone:
$ stty -F /dev/ttyUSB0 onlcr
$ stty -F /dev/ttyUSB0
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost
-isig -icanon -echo
After running screen - note the -onlcr is back again:
$ stty -F /dev/ttyUSB0
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo
It's as if screen ignores any stty settings and resets them to it's own defaults. And this the same on both machines I tested it on; Debain 8.7 and macOS Sierra 10.12.4
I have seen posts with other people facing similar problems but none give a definitive answer. Many people end up recommending an alternative to screen like minicom but now I'm interested.
Can stty settings, like onlcr, be used with screen?
I just went through much the same process, only to find out the screen clobbers the stty settings no matter what. One comment here suggests changing the screen source code:
How to toggle CR/LF in gnu screen?
In the end, I was very happy to find a more minimal dumb-terminal program that allows passing stty-style arguments on the command line:
https://github.com/npat-efault/picocom
It also pretty-prints the serial port settings when it starts so you can easily check them.
Packages exist in Debian-derived distros (sudo apt-get install picocom), and for others it seems that compilation is straightforward. One dependency is the linenoise library, which can be disabled.
The way I handled this is to start screen running without any special terminal options using in your case: screen /dev/ttyUSB0 115200, and then leave it running, and switch over to another terminal window and do the stty commands from there.
If you stop screen, I think it locks the device somehow (or else its because you aren't using sudo). Once in the other window you can type the sudo stty -F /dev/ttyUSB0 onlcr and that will change the behavior of the screen session from then on. The problem is that screen is ignoring the setting passed to it and just configuring the tty its own way. You can type sudo stty -F /dev/ttyUSB0 -a to list the settings from another window while screen is running and then alter them as needed. (Note that on the Mac, the -F should be lower case.)
If you only have the one terminal window then it is problematic because putting screen in the background and leaving it running just mixes input and output streams between the shell and screen process.
Another thing you can do if you have two terminal windows open is a low-level fallback hack when nothing is working: In one terminal type cat /dev/ttyUSB0. Then in the other set up the terminal options you want with sudo stty. Then from this same terminal you can send commands via echo "Some text" > /dev/ttyUSB0. You can translate the output of the cat command by piping it through sed or tr. For example cat /dev/ttyUSB0 | tr '\r' '\n' will translate any received carriage returns to line feeds.

Can't activate a USB HID Device on BeagleBoneBlack

Background:
I'm trying to figure out how to use ConfigFS to set up an HID device on BeagleBoneBlack.
I found the following example (www.isticktoit.net/?p=1383) on the web and tried it. The sample runs on a Raspberry Pi Zero. However, the sample does not work on my BBB. The following is the script that I wrote and which is executed as root. The script attempts to define a keyboard hid device.
#!/bin/bash
cd /sys/kernel/config/usb_gadget/
modprobe libcomposite
modprobe usb_f_hid
mkdir -p isticktoit
cd isticktoit
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "Tobias Girstmair" > strings/0x409/manufacturer
echo "iSticktoit.net USB Device" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
# Add functions here
pwd
mkdir -p functions/hid.xyz
echo 1 > functions/hid.xyz/protocol
echo 1 > functions/hid.xyz/subclass
echo 8 > functions/hid.xyz/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.xyz/report_desc
ln -s functions/hid.xyz configs/c.1/
# End functions
ls /sys/class/udc > UDC
The error that I get is "ls: write error: Devicew or resource busy".
I am running Debian Jessie - Linux version 4.4.9-ti-r25
I did an lsmod and libcomposite and usb_f_hid are loaded.
The usb device controller, musb-hdrc-0.auto, is loaded.
Questions:
How can I tell which device is busy?
Where can I find the USB configfs defect bug list for BBB.
Is there a logging file and enabling parameter that would give me a clue as to what is happening?
Thanks for any help
David Glaser
The problem you are likely having with the beaglebone black is the cdc_acm driver. It is difficult to remove (well, not really now that I KNOW how to do it) if you don't know how because the steps aren't just laid out to find anywhere yet. I found this: https://media.defcon.org/DEF%20CON%2023/DEF%20CON%2023%20presentations/DEFCON-23-Phil-Polstra-One-device-to-Pwn-them-all.pdf
which led me to the following solution
#!/usr/bin/env bash
function checkModule(){
MODULE="$1"
if lsmod | grep "$MODULE" &> /dev/null ; then
echo "$MODULE" found.
return 0
else
echo "$MODULE" not found.
return 1
fi
}
if which 'systemctl' | grep "systemctl" &> /dev/null ; then
systemctl stop serial-getty#ttyGS0.service >/dev/null
fi
if checkModule "g_serial" == 0; then
modprobe -r g_serial
fi
if checkModule "usb_f_acm" == 0; then
modprobe -r usb_f_acm
fi
if ! checkModule "libcomposite" == 0; then
modprobe libcomposite
fi
basically, it stops the serial-getty service which allows you to remove the g_serial device and then this allows you to remove usb_f_acm. This in turn removes the libcomposite device, which you actually want to keep. Once this is done, you can likely do all the things you needed to do. I got a nice HID keyboard working this way (well, okay I guess its a KeygleBone Black now)... It is pretty dirt simple once you understand ALL of the pieces, but I'm having a little trouble tearing my device back down. I might not need to eventually, but I'd like to be able to do that and it seems that certain directories cannot be removed (namely the "strings" directories that I've created). This means I can't really fully tear down the device, but maybe I only need to:
echo "" > /sys/kernel/config/usb_gadget/my_gadget/UDC
to actually tear it down. I haven't worked that part out yet. There are also some C libraries, but I've got a bunch of python scripts that I want to use and I don't yet have python wrappers for those. But that probably isn't too much work.
I didn't want to forget to mention, that I tried to throw the above script into rc.local so the beaglebone black I am using would be "HID ready" on boot. There are probably better locations and methods to do this, but I just wanted to use rc.local because the above is a script, rc.local is a script, it should run on boot... But it doesn't... You have to make sure to make rc.local runable ( chmod 755 /etc/rc.local ) as well as modifying the default shell it wants to run (well, it always runs bash, but its method for running bash is the "POSIX" method, and that doesn't seem to work, so you have to force it to run bash in non-POSIX mode with:
#!/usr/bin/bash
Again, there are probably other better methods (I was lazy here and, well, I'm just old school), especially if your device is going to be an IoT device or anything linked to the net, so you might want to consider something else if you need this script to run on boot.
I did stupidly leave out one thing: I made sure the beaglebone black doesn't present its usual "disk" portion as well. I would put the details here, but frankly, those I'd have to track back down. I basically googled around for how to disable the beaglebone black disk. It isn't hard and amounted to me moving some file to another name so it doesn't find the "USB disk" configuration on boot. You can also change a line in the uboot config somewhere I believe, but I didn't really want to do that.
Found the file: /var/local/bb_usb_mass_storage.img
Well, it might be bbg_usb_mass_storage.img if it is a beaglebone green, but I just moved this file so it wouldn't present the mass storage device. That should allow you to do what you want.

How To Use TCMalloc?

Firstly, I want to know how to install TCmalloc in Ubuntu. Then I need a program uses TCmalloc. Then I need a small program to show that TCmalloc is working better than PTmalloc.
I'll provide another answer since there's an easier way to install it than in the other answer:
Ubuntu already has a package for google perf tools: http://packages.ubuntu.com/search?keywords=google-perftools
By installing libgoogle-perftools-dev you should get all that is required for developing tcmalloc applications. As for how to actually use tcmalloc, see the other answer.
Install:
sudo apt-get install google-perftools
Create an application in eclipse or any other code composer
#include <iostream>
#include <unistd.h>
#include <vector>
#include <string>
using namespace std;
class BigNumber
{
public:
BigNumber(int i)
{
cout << "BigNumber(" << i << ")" << endl;
digits = new char[100000];
}
~BigNumber()
{
if (digits != NULL)
delete[] digits;
}
private:
char* digits = NULL;
};
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
vector<BigNumber*> v;
for(int i=0; i< 100; i++)
{
v.push_back(new BigNumber(i));
}
return 0;
}
This code will help you see how memory is leaking
Then add the library to your makefile
-ltcmalloc
when running the application, you want to create a heap file, so you need to add an environment variable HEAPPROFILE=/home/myuser/prefix
and files prefix.0001.heap will be created in the /home/myuser path
Run the application and heap files will be created
Examine heap files
pprof helloworld helloworld.0001.heap --text
Using local file helloworld.
Using local file helloworld.0001.heap.
Total: 9.5 MB
9.5 100.0% 100.0% 9.5 100.0% BigNumber::BigNumber
0.0 0.0% 100.0% 0.0 0.0% __GI__IO_file_doallocate
Easy to see which objects leaked and where were they allocated.
To install TCMalloc:
sudo apt-get install google-perftools
To replace allocators in system-wide manner I edit /etc/environment (or export from /etc/profile, /etc/profile.d/*.sh):
echo "LD_PRELOAD=/usr/lib/libtcmalloc.so.4" | tee -a /etc/environment
To do the same in more narrow scope you can edit ~/.profile, ~/.bashrc, /etc/bashrc, etc.
If you would like to use tcmalloc only just for allocated memory optimization, not for analysis, you can do like this:
sudo apt -y install libgoogle-perftools-dev
cc -O3 -ltcmalloc_minimal -fno-builtin-malloc \
-fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -o main main.c
tcmalloc is in the google perf tool, installation guide could be found here.
The example is included in the google perf tool
see here, section Performance Notes