Compiling kernel module for FTDI USB-Serial on Jetson TX2

I’ve got a nice Jetson TX2 board from NVidia, which suits my goals pretty well, it has plenty of computing power with an onboard GPU for heavy graphics calculatons and CNN/ML processing.

Unfortunately, when I tried to connect my home-made sensor based on FTDI chip, that works perfectly with desktop Linux and other embedded boards, there was no kernel module for this chip, hence I had to compile one myself.

There are plenty of TK1/TX1/TX2 kernel compile guides on the net, but since the versions are different and the software contents change with time, here’s my take.

$ uname -a
Linux tegra-ubuntu 4.4.15-tegra #1 SMP PREEMPT Wed Feb 8 18:06:32 PST 2017 aarch64 aarch64 aarch64 GNU/Linux

First, check the Linux version, if it differs greatly from 4.4.15-tegra I have — take my advices with the grain of salt, maybe install the latest JetPack (mine was JetPack 2.3, I believe). Second, there are files on my system which may or may be not present on yours, beware. This is why I don’t write any “automated” scripts, that will give meaningless error message somewhere in the middle and do nothing.

Next check would be to see if the USB serial support is included in the current kernel or not:

$ zcat /proc/config.gz | grep USB_SERIAL
# CONFIG_USB_SERIAL is not set

In my case it’s not there, and if you grep for “FTDI” — there will be no results at all. A bit disconcertng, but solvable.

System related sources are usually in /usr/src, there might be folders, but in my case there was a single file for the kernel sources: kernel_src.tbz2 — let’s unpack it and copy the current config file there.

$ cd
$ mkdir tmp; cd tmp
$ tar -xjf /usr/src/kernel_src.tbz2
$ cd kernel/kernel-4.4
$ zcat /proc/config.gz >.config

Unpacking might take a minute or two. There will be two folders, “hardware” and “kernel”, go to the latter, then to “kernel-4.4″ and copy the default config there. The easiest way to edit config would be to issue “make menuconfig”, but this requires NCurses library, which is again not installed by default, so we have to do things manually a bit.

Instead of “make menuconfig” we could always use “make config” to resort to the command line, but answering hundreds if not thousands of questions is very tedious and time consuming, so let’s take a shortcut. Use your favourite text editor to open “.config” file and search for “USB_SERIAL” — if you are like me, you’ll find “# CONFIG_USB_SERIAL is not set” and the whole section for various USB serial devices is missing. Replace the line you’ve found with “CONFIG_USB_SERIAL=m”, and save file.

$ make prepare

This command will resurrect the missing section, please, be careful answering to the questions, basically you want to say “Y” to “USB Generic Serial Driver (USB_SERIAL_GENERIC) [N/y/?]“, then once again “m” (not “Y”) to “USB FTDI Single Port Serial Driver (USB_SERIAL_FTDI_SIO) [N/m/?] (NEW)”, the rest of the questions are just answered by pressing “Enter” key:

$ make modules_prepare

Nothing interesting here, just 10-15sec of file compilations.

make M=drivers/usb/serial/

This one actually compiles the kernel modules.

$ ls drivers/usb/serial/*.ko
drivers/usb/serial/ftdi_sio.ko drivers/usb/serial/usbserial.ko

Here are the files, former one is FTDI driver and the latter one is the basic USB Serial support driver the other drivers rely on. Let’s copy ‘em to the proper place (depending on your directory structure you might need or might not need to create the subfolders below:

$ mkdir /lib/modules/4.4.15-tegra/kernel/drivers/usb
$ mkdir /lib/modules/4.4.15-tegra/kernel/drivers/usb/serial
$ sudo cp drivers/usb/serial/*.ko /lib/modules/4.4.15-tegra/kernel/drivers/usb/serial/
$ sudo depmod -a

“depmod” reloads the kernel module list, so next time you insert your device, it will be recognized. Let’s start “tail -f /var/log/syslog” and see what happens there:

[ 4178.392871] usb 1-2: new full-speed USB device number 4 using xhci-tegra
[ 4178.532285] usb 1-2: New USB device found, idVendor=0403, idProduct=6001
[ 4178.539051] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4178.546347] usb 1-2: Product: FT232R USB UART
[ 4178.550947] usb 1-2: Manufacturer: FTDI
[ 4178.554853] usb 1-2: SerialNumber: A4004H1c
[ 4178.560093] xhci-tegra 3530000.xhci: tegra_xhci_mbox_work mailbox command 6
[ 4178.569484] ftdi_sio 1-2:1.0: FTDI USB Serial Device converter detected
[ 4178.576205] usb 1-2: Detected FT232RL
[ 4178.580327] usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB0

Sometimes, there might be an error message, like

[ 4232.645711] ftdi_sio: version magic '4.4.15 SMP preempt ' should be '4.4.15-tegra SMP preempt '

This means that we’ve missed the minor detail during configuration, take a note of “-tegra” suffix after the version number. We have to add it to our configuration file and recompile things again. Open .config file in the text editor, page down to “* General setup” section and change CONFIG_LOCALVERSION=”" to CONFIG_LOCALVERSION=”-tegra” or whatever suffix you find in the error message. Then the usual routine:

$ make clean
$ make prepare
$ make modules_prepare
$ make M=drivers/usb/serial

Copy the “*.ko” files as described above and don’t forget to “sudo depmod -a”.

Insert your FTDI-based device and enjoy!

No Comments

FEN-to-Image chess diagram creator

Needed a few chess diagrams, but screen capturing from chess software does not look good and requires a lot of silly post processing, not to mention time required to put all pieces in order. That’s how a little project of mine was born, FEN-to-Image takes your position in a well known FEN format and returns the beautifully looking diagram with all the pieces.

Board size and layout are configurable, output format now is fixed to .png, but could be anything like .jpg or .gif if someone needs that.

Images are heavily cached, to reduce the load on the server. By my rough calculations it could easily serve about 10-20 hits per second. Not much, but how many chess players are going to use it?

,

No Comments

Raspberry Pi :: heatsink installation

heatsink installed

I was worried about running Raspberry Pi in summer, hot weather is not really friendly with electronics. Worried not enough to put it in 24/7 air-conditioned room, but somewhere around spending $5-8 on heatsink installation, using heatsink kit from ModMyPi.com

The kit comes as three separate radiators, one for the main CPU/memory unit, one for the periferals chip responsible for ethernet and usb, and one really small one — for the power converter, that also gets quite hot.

Installation was a breeze: just attach sticky heat-transfer tape to the bottom of the heatsink, cut to the size and stick the heatsink on the top of the chip. And maybe move around a little, to ensure the perfect fit and there are no air pockets trapped between the tape and chip surface.

The results. I could not notice a very sharp decline in the temperature graph, but still cutting a few degrees off the CPU temperature might prolong the life of the Raspberry Pi for a few more month, if not years. The active cooling system with large fans and radiators might give a somewhat better results, but the price and the noise will definitely be much higher.
temperature graph

,

No Comments

Raspberry Pi :: Monitoring CPU temperature with RRDTOOL

Recently I’ve got wondering about how hot is the processor in my Raspberry Pi, and how this temperature changes throughout the day/night. There’s a beautiful and simple tool for that purpose, called rrdtool, that stores the data (any kind of data) in the round-robin database and creates nice looking graphs.

The installation of rrdtool is pretty straight forward:

sudo apt-get install rrdtool

And here’s the bash script, that runs every five minutes by cron and saves temperature and creates the picture:

#!/bin/bash
#
# update .rrd database with CPU temperature
#
# $Id: update_cputemp 275 2013-05-16 05:20:56Z lenik $

cd /home/lenik

# create database if not exists
[ -f cputemp.rrd ] || {
/usr/bin/rrdtool create cputemp.rrd –step 300 \
DS:cputemp:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \
RRA:AVERAGE:0.5:525600:3200
}

# read the temperature and convert “59234″ into “59.234″ (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`

/usr/bin/rrdtool update cputemp.rrd `date +”%s”`:$TEMPERATURE

/usr/bin/rrdtool graph cputemp.png DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00 –width 800

,

No Comments

Raspberry Pi :: PeerGuardian / Moblock setup

While thinking about connecting the new Raspberry Pi board to the internet, I could not even imagine to do that without any firewalls or filters for incoming traffic. Having a little bit of experience with MoBlock before, I have decided to try the same approach with Raspberry Pi.

Unfortunately, the “moblock” package is not in the official repositories, so I had to build one from the sources. The process is quite easy, but requires a few not very obvious steps.

First, add the repository and get the sources. The following goes into the /etc/apt/sources.list:

deb-src http://moblock-deb.sourceforge.net/debian wheezy main

then install the GPG keys:

gpg –keyserver keyserver.ubuntu.com –recv-keys C0145138
gpg –export –armor C0145138 | sudo apt-key add -

and finally get the sources:

sudo apt-get update
sudo apt-get install fakeroot
sudo apt-get build-dep -y pgl
mkdir ~/peerguardian
cd ~/peerguardian
apt-get source pgl

The build dependecies in the previous step include some X11 and qt4 stuff, which might be required if you run a desktop environment or not, if you run a headless installation, in which case you may free about 65MB (WARNING: you’ll lose your desktop doing this!) using:

sudo apt-get remove x11-common
sudo apt-get autoremove

The build step is very simple:

./autogen.sh
./configure
make
sudo make install

or you may want to replace “./configure” with “./configure –without-qt4 –disable-dbus” in case of headless installation.

Finally, start the PeerGuardian daemon (the first run might take a while, since it’s downloading and unpacking all block lists):

sudo pglcmd start &
tail -f /usr/local/var/log/pgl/pglcmd.log

One last word of warning, the default block list is so strict, it might even disable the blocklist updates and downloads. Don’t be surprised, if you need to issue “sudo pglcmd stop” before being able to download new block lists.

And if everything works fine, you may enable automatic daemon startup using:

update-rc.d pgl defaults

,

No Comments

Raspberry Pi :: got one from RS Components

Raspberry Pi

The Raspberry Pi project has matured enough in the end of the last year to release a new model, with improved schematics and extra memory. I have decided that 512MB is ample enough for my applications and it’s time to try one. Ordered from RS Components, they had about a week or two of back orders, so it took a little while before the nice white package has shown on my doorstep.

The package contents was the board, the transparent plastic enclosure and the power supply. Previous overseas orders taught me to expect a lot of problems with the power supply (the absolute record was the Samsung tablet, that required 3 converter plugs to be able to use it), but this time I was pleasantly surprised to find out several different connectors that accomodate most of the possible power outlets — US, GB and Europe all in one simple package.

Raspbian installation was a breeze — download the image, copy to SD card and off we go. First boot was fast, and though the preinstalled software was a bit limited, I could get almost anything I wanted from the Debian repositories.

Another nice touch — when connected over a HDMI, the board automatically turns on the TV set and changes the input, so I don’t have to search for a remote to see what’s going on. And yeah, it turns TV off during shutdown, that is also very welcome.

No Comments

Nvidia GT 610 drivers for Ubuntu 10.04

Upgraded a video card recently to GeForce GT 610, Ubuntu could not find the proper driver automatically. Had to issue the following commands before rebooting:

sudo apt-add-repository ppa:ubuntu-x-swat/x-updates
sudo apt-get update
sudo apt-get install nvidia-current

No Comments

HOWTO :: Send and receive MMS on Galaxy Nexus / SoftBank

As usual, MMS support in the international version of Galaxy Nexus does not work on SoftBank network as is, and requires a bit of tinkering. We gonna need usual toolset: phone, USB cable, adb, apktool and a text editor. There are a few explanations on the web, but they talk about connecting Nexus to the iPhone APN, so it won’t work if your previous smartphone was not iPhone. Here’s a procedure if you had Android device before.

Copy files from the phone

$ adb pull /system/app/Mms.apk
$ adb pull /system/framework/framework-res.apk

Unpack the framework and Mms.apk

$ apktool if framework-res.apk
$ apktool d Mms.apk

Make changes

The file we are interested in is res/xml/mms_config.xml, you may want to change it directly, but your phone might stop working on some other network, so I prefer another approach. We can create separate file, which will work on SoftBank network only. This new file should be called res/xml-mcc440-mnc20/mms_config.xml, 440 is the country code for Japan, and 20 is SoftBank network. The file contents is the following:

<?xml version=”1.0″ encoding=”utf-8″?>
<mms_config version=”4″>
<bool name=”enabledMMS”>true</bool>
<int name=”maxMessageSize”>307200</int>
<int name=”maxImageHeight”>768</int>
<int name=”maxImageWidth”>1024</int>
<int name=”defaultSMSMessagesPerThread”>500</int>
<int name=”defaultMMSMessagesPerThread”>150</int>
<int name=”minMessageCountPerThread”>10</int>
<int name=”maxMessageCountPerThread”>5000</int>
<string name=”uaProfUrl”>http://www.google.com/oha/rdf/ua-profile-kila.xml</string>
<int name=”recipientLimit”>-1</int>
<int name=”smsToMmsTextThreshold”>4</int>
<bool name=”enableMultipartSMS”>false</bool>
<bool name=”enableSlideDuration”>true</bool>
<int name=”maxMessageTextSize”>-1</int>
<string name=”userAgent”>SoftBank/1.0/X01T/TJ001</string>
</mms_config>

You should not copy/paste the code snipped, just change the bold parts (URL and UserAgent) using your phone file as a boilerplate.

Rebuild .apk

First we run apktool to rebuild the resource files, and then zip contents of build/apk folder and sign the result

$ apktool b Mms
$ cd Mms/build/apk
$ zip Mms.apk *
$ java -jar signapk.jar -w testkey.x509.pem testkey.pk8 Mms{,-signed}.apk

Put results back to the phone

If you phone does not allow pushing files to /system/app, you have to download and use Superboot (see my previous post for details. Otherwise, its as simple as:

$ adb push Mms-signed.apk /system/app/Mms.apk
4760 KB/s (434346 bytes in 0.089s)
$

After reboot, please, don’t forget to input proper APN settings for Open SoftBank.

Downloads

Just in case you don’t like to tinker with Android internals, here’s a ready-to-use download, SBM_Galaxy_Nexus_4.0.2_ICL53F_Mms.apk. This file should be put into your phone as described in “Put results back to the phone” part. It is intended to be used on Android 4.0.2, specifically version ICL53F, and may not work on other versions. As soon as I upgrade to 4.0.4, I will put a new file for download in this topic as well. Well, here’s SBM_Galaxy_Nexus_4.0.4_IMM76I_Mms.apk for version 4.0.4. And also SBM_Galaxy_Nexus_4.1.1_JRO03C_Mms.apk for Jelly Bean 4.1.1.

Final thoughts

There is still one problem left, Mms.apk requires working internet data connection to download MMS contents. As I have remembered from my previous HTC phone, it was possible (on Froyo) to keep data connection off, and Mms application will enable it for a short period of time just to download MMS messages. Unfortunately, this does not work on Galaxy Nexus yet.

, ,

No Comments

HOWTO :: Pull OTA upgrade file from Galaxy Nexus

Recently I’ve got Galaxy Nexus to play with, and as soon as I’ve entered Wi-Fi password, an OTA upgrade came my way. It was very tempting to upgrade immediately, but I’ve decided to pull upgrade file from the device to see what’s inside.

Unfortunately, the phone comes from the factory locked and there’s no way to access system files except unlocking the protection.

Regarding the root access

First we need the root access to be able to access files freely.

I don’t like to permanently root my phone, so I prefer the temporary method, which keeps the phone protected, but gives me the opportunity to access what I need if I really need it (I do not delve into details about how to use adb, hoping you already know that).

Unlock the phone

Reboot into fastboot mode by switching power off, and holding all three buttons (volume up/down and power) until Android logo appears. then issue ‘fastboot oem unlock’ command from your computer. This requires full memory wipe, so be careful and make a backup of any data you care to keep.

Download the superboot

Superboot is the bootoader image, which can turn the phone into a rooted one, but only until the next reboot. Handy and safe.

Reboot into superuser-enabled mode

While still in fastboot mode, the following command will restart the phone with the boot image we have just downloaded.

fastboot boot boot.superboot.img

Wait until the update comes

Since the phone was wiped clear during unlock, we have to wait again for upgrade to come, or request the upgrade check from Settings menu, if you are impatient.

Move upgrade file into the easy to access place

Since adb can not pull system files, we have to move the upgrade file somewhere we can access easily. I chose /sdcard folder for that purpose

adb shell
$ su
# cd /cache
# ls
[... file list skipped ...]
# mv signed-yakju-ICL53F-from-ITL41F.0927b42c.zip /sdcard/

In your case the file name most probably will be different, but it’s quite easy to tell based on size (90MB in my case), which file to copy.

Extract the file from the phone

Finally we can use adb to get the file:

adb pull /sdcard/signed-yakju-ICL53F-from-ITL41F.0927b42c.zip .

, , , ,

No Comments

Auto-Update-Apk :: Automatic Update Deployment for Android Applications

auto-update-apk logo

First, I had an application. And a customer. And another customer. Actually, a few people wanted to use the application, but due to a specific nature of the software it is not intended for Joe Public, and I’m quite reluctant to put it on the Market.

Then comes the problem: I can tell the customer to install the program from a given URL, but how do I deploy updates to the software? Unfortunately, Android Market does not provide update options for non-Market applications.

I’ve spent a few days looking for an automatic update deployment software on the net. Found a few. Most of them are just plain disappointments. So,I’ve decided to spend a weekend to roll my own. Maybe also a disappointment, but at least my own.

Finally, today I’ve published the first version of AutoUpdateAPK service. Due to gruesome death of the service I’ve used before, I was quite pressed for time, so the basic functionality is a bit limited, but is expected to grow rapidly. Especially, because we are going to use this service ourselves quite extensively.

Android code is open-sourced under Apache 2.0 license, so people may freely copy it into their applications and start to deploy updates automatically.

, ,

No Comments