Showing posts with label armhf. Show all posts
Showing posts with label armhf. Show all posts

Headless Hard-float BeagleBone Black - Part 2: Installing LXDE Desktop and Autostart VNC Server

Welcome to Part 2 of my guide on "Headless Hard-float BeagleBone Black". Make sure you did not miss Part 1: Installing Hard-float Ubuntu.

Let's get started. Why do we need to install LXDE Desktop? Well, armhf ubuntu only comes with terminal interface, and for some applications, you need a Desktop GUI. Ubuntu have its default Desktop (Unity), but it's too heavy. You can't fit ubuntu with its desktop on BBB's eMMC. And even on spacious uSD card, the GUI is too slow to provide acceptable user experience. If I remember it right, clean armhf ubuntu takes about 300 MBs, and LXDE takes another 300 MBs, so you will still have more than 1 GB for other stuff (most likely dependencies for development).

Make sure your BBB is updated and upgraded before proceeding:

1
2
sudo apt-get update
sudo apt-get upgrade

Those 2 commands will do the job. Now, to install LXDE, type:

1
sudo apt-get -y install lxde lxde-core lxde-icon-theme

You can skip the "-y" if you want to confirm the installation yourself. After it's done, reboot. If you have a monitor, you can connect it to BBB and you're greeted by LXDE log in screen.

With LXDE install, we will go on and install an autostart VNC server. First, you need x11vnc server:

1
sudo apt-get install x11vnc

Use this command to start VNC server:

1
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lxdm/lxdm-\:0.auth -display :0 -forever

Then use a VNC viewer to connect to your BBB. If you haven't got one, you can try this.

Now, we want to setup your BBB to run that command every time it boots. Luckily, LXDE makes this very easy. Use your favorite text editor to edit /etc/lxdm/LoginReady with root privilege. The easiest way is to use WinSCP, connect to your BBB as root, navigate to that file and open it. You are now editing it on your friendly Windows environment. Just copy and paste the command:

1
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/lxdm/lxdm-\:0.auth -display :0 -forever

at the end of LoginReady and save it.

Some explanations:
  • LXDM's LoginReady is a shell script file, and it will be executed with root privilege when LXDM is ready to show the login window.
  • The flag "-forever" in the VNC server command is to tell the server to not go down. Without that flag, your VNC server will accept the first connection. And when that first client disconnect, the server is shutdown too (just the VNC server, not your whole BBB). 

Headless Hard-float BeagleBone Black - Part 1: Installing Hard-float Ubuntu

Hi everyone! This time, I want to show you how to get a headless hard-float BBB running. These steps are the actual steps that I did to get my BBB working. As usual, if you have any question and/or suggestion, please let me know.

In this post, I will refer your Windows powered desktop/laptop as "Host", and BBB as "Kit". Of course you could use a Linux powered host, but my steps here are for Windows.

What is headless and why? Headless means you run your kit without a monitor, even without mouse and keyboard. Why do we want to do this? The first benefit is that we don't need another monitor, another mouse, and another keyboard. And the most important benefit is that we can use our current mouse and keyboard, to control the kit via a window on out host (as a regular program), which helps multitasking easier.

What is hard-float? Our kit have powerful floating-point capability. In order to fully utilize that power, you need to compile your programs with "float-abi=hard" flag. The Angstrom distribution that comes with the kit DOES support hard-float, but you have to change some settings, see this thread for more details. The easier way to fully utilize hard-float is using armhf-ubuntu. Those images are prepackaged with hardware floating point enabled and are easy to install. One more important benefit of armhf-ubuntu is that libjpeg-turbo is the default libjpeg. You could find more information about libjpeg-turbo and why we want it.

OK, let's get started.

Get an image from here. I used Ubuntu 12.04 LTS image, and you should also use this if you want to install LXDE (more on this on Part 2). You should read the instruction on armhf page too, but I will also give detailed step-by-step to install Ubuntu 12.04 LTS on your kit's eMMC. If you follow armhf's instruction to install to eMMC, you will use your host to install ubuntu to your uSD card, then while running on uSD card, install ubuntu to your eMMC

And now, my steps to directly install ubuntu to your eMMC. You need 7-zip, and SDFormatter.

  • Download "ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img.xz" (~65MB) from armhf
  • Use 7-zip to extract it, you will get "ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img" (~1.78GB)
  • Use SDFormatter to format your uSD card, default settings are good
  • Visit http://elinux.org/BeagleBone_Black_Extracting_eMMC_contents, read it, get the zip, do as instructed there. But change the autorun.sh to:

1
2
3
4
5
#!/bin/sh
echo timer > /sys/class/leds/beaglebone\:green\:usr0/trigger
dd if=/mnt/ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img of=/dev/mmcblk1 bs=10M
sync
echo default-on > /sys/class/leds/beaglebone\:green\:usr0/trigger

  • Copy the extracted image ("ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img") to the root of uSD card
  • Insert uSD card to kit and boot kit up, the script will install ubuntu to your eMMC
  • Once it's done, poweroff the kit (disconnect power), remove uSD card and reconnect power to boot it up
Now you have fresh ubuntu 12.04 installed on your kit. Use PuTTy, connect to your kit, username & password is "ubuntu" (without quotes, of course). The first thing you want to do is setting a root password:

1
sudo passwd

Then update your installation:

1
2
3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get clean

The last command, "sudo apt-get clean" is to delete download cache, to regain precious disk space on your kit.

An updated guide to get hardware-accelerated OpenCV on BeagleBone Black

If you're interested in BBB and OpenCV, you must have known Michael Darling's guide. Seriously, if you have not read it, go read it please to understand the hard works that people have done to make our life with BBB much much easier. These two blog posts about BBB and OpenCV are also very interesting [1] & [2].

That guide is dated to September 24, 2013. Since then, many things have changed, and fortunately, things are much easier now. I will point out steps that need to be changed from the guide (due to links changes, sources changes, ...). I will also include some steps that I hope will make things easier new comers.

My steps assume that your main operating system is Windows.

This is is intended to be used side by side with Michael Darling's guide. Michael Darling wrote a really excellent guide, I just want to update and add some steps.

You have to install Ubuntu onto your BBB. Go to here, I recommend getting Ubuntu Precise 12.04. I also recommend flash it directly to your eMMC, as your eMMC is much faster than any uSD card. You can do that by:
  1. Download ubuntu-precise-12.04.3-armhf-3.8.13-bone30.img.xz to your desktop
  2. Extract it (you need 7-zip, it's a free and very powerful archive manager)
  3. Copy it to the root of your uSD card
  4. Go to here, download it, and do as instructed to perform flashing
We need to install dependencies, tons of them. Make an "install.sh" file with the following content is the easiest and most automatic way to do so:

1
2
3
4
5
6
7
sudo apt-get -y install build-essential checkinstall cmake cmake-curses-gui pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
sudo apt-get -y install libgtk2.0-dev

And one tip for you, doing "sudo apt-get clean" after installing packages will clean the download cache and free up disk space (it can free 200-400MB, which matters much on BBB).

Recently, libjpeg-turbo have been choose to be default libjpeg-dev package for armhf distro, so you don't have to built it from source like in the guide.

I highly recommend doing this step. Building OpenCV on a single core ARM board takes 3-4 hours and will make your little ARM CPU hot as hell. Setting up distcc and configure OpenCV correctly, we can build it in 15 minutes, and BBB CPU is not even warm.

About the compiler, you can use the one in the guide, version 4.8-2013.08 or use the updated here.

The new commands for installing distcc are:

1
2
3
4
wget https://distcc.googlecode.com/files/distcc-3.1.tar.bz2
tar xjf distcc-3.1.tar.bz2
cd distcc-3.1
./configure --with-gtk --disable-Werrormakesudo make install

Get a USB flash drive, and use MiniTool Partition Wizard Home Edition (free) to format it to Ext2. Remember to give it a name when doing so, the name must contain no space, for example "myusb". Plug it in your BBB.

The new commands for building OpenCV:

1
2
3
4
5
6
7
8
su
cd /media/myusb
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.8/opencv-2.4.8.zip
unzip opencv-2.4.8.zip
cd opencd-2.4.8
mkdir build
cd build
cmake -D CMAKE_C_FLAGS='-O3 -mfpu=neon -mfloat-abi=hard' -D CMAKE_CXX_FLAGS='-O3 -mfpu=neon -mfloat-abi=hard' -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DENABLE_VFPV3=ON -DENABLE_NEON=ON ..

We need to disable some part of the build to speed it up:

1
ccmake .

Remember the dot "." after ccmake command. Check to make sure that ENABLE_NEON and ENABLE_VFPV3 are ON. Now we disable BUILD_PERF_TESTS, BUILD_TESTS, and ENABLE_PRECOMPILED_HEADERS. Some explanations:

  • ENABLE_NEON and ENABLE_VFPV3: to enable hardware acceleration
  • BUILD_PERF_TESTS and BUILD_TESTS: set these 2 to OFF to disable the building of these 2 test suites of OpenCV. Why do we want to not build the tests? Building these tests takes lots lots of time, and I'm sure that you don't have enough patient to run those tests. There is an individual executable for each module of OpenCV, and I tried running the test for opencv_core myself just to see me interrupted the test after waiting for ~20 minutes.
  • ENABLE_PRECOMPILED_HEADERS: by theory, using precompiled headers speed up compilation. But that's not in this case. Our BBB CPU will have to compile those headers alone, as distcc can't do this. And doing this takes BBB CPU lots of time. The precompiled headers in this case will only speed up compilation on host machine, which is already powerful. Less work for BBB = faster overall compilation :).

Follow the on-screen instructions, press "c" to reconfigure and then "g" to regenerate. Finally, we can begin compilation:

1
make -j6

The "-jX" after make command allow parallelization, set X to the number of jobs your host allow.

My distcc host is a virtual machine running Ubuntu 12.04. My desktop is powered by an AMD Phenom II X4 and 4GB RAM so I give my virtual Ubuntu 3 cores and 1.5GB RAM. Therefore the number of jobs is 6. My setup built OpenCV in just 15 minutes.

Some final notes:

  • Environmental variables in Unix systems are only temporary, they got wiped out after reboot or even on session exit. So if you plan to keep using distcc, you will have to edit the ".profile" file in your home folder. Just paste the export commands at the end of that file. The variables will be created every time you log in using that username.
  • Don't forget to tell your system where to look for OpenCV runtime libraries. Edit /etc/ld.so.conf and add "/usr/local/lib" and the end of it. Then run "sudo ldconfig".
  • The easiest way to edit those files from Windows is using WinSCP (free). Using WinSCP, you just need to navigate to the needed file, double click it, a text editor will open it up, and when you save, WinSCP will put the updated version in the right place. Nice and clean. Log in as your username to edit the ".profile" file, and as root to edit /etc/ld.so.conf.

This "guide" lacks lots of stuffs. That's my intention, so you have to read this guide in combination with Michael Darling's one.

Feel free to leave suggestions and/or questions :).

Update: Watch the Final test run of my Thesis on YouTube