Friday 17 June 2016

Ubuntu Precise 12.04 on Pandaboard - Configuration

This guide describes how to install and configure Ubuntu Precise on OMAP4 Pandaboard with working HDMI out (ES should be similar)

(I have put code below)

What do you need:

- Panda-board + power supply
- Linux host (You can use Windows with Cygwin as an alternative: https://www.cygwin.com)
- Host computer with SD card reader (or separate)
- SD card: 8BG+ ( MIN = 4GB), Class 10 preferably (fastest)
- Wifi / Ethernet connection
- Minicom
- HDMI / DVI supported TV / monitor
- Serial cable (optional, I am not a developer)

SD Card:

First, make sure you have >4GB SD card to make your life easier. If you use 4GB card for e.g., there is very high chance resizing will fail .. And you will have to do it manually. Thus, ideally you should use SD card 8 GB or bigger. Also, I recommend faster class.

Prepare SD card:

Download pre-built image (OMAP4 ARMv7 hardfloat)
http://cdimage.ubuntu.com/releases/12.04/release/ubuntu-12.04-preinstalled-desktop-armhf+omap4.img.gz
Uncompress gzip archive
Make sure you know which device your SD card stands for, in most cases it would be sdc or sdd (sda is definitely wrong ... don't wipe your hard drive !) Use sudo fdisk -l to check !
Transfer the image with dd command - takes some time and sync
Now your card is ready !
sudo fdisk -l
cd $HOME
wget http://cdimage.ubuntu.com/releases/12.04/release/ubuntu-12.04-preinstalled-desktop-armhf+omap4.img.gz
gunzip ubuntu-12.04-preinstalled-desktop-armhf+omap4.img.gz
sudo dd bs=4M if=ubuntu-12.04-preinstalled-desktop-armhf+omap4.img of=/dev/sdX
sudo sync


Boot up your board:

You should get HDMI image immediately more or less. LEDs should be lit and working.
You should be informed that the filesystem is being re-sized - if it fails, you would need to do it manually on your host computer (e.g. with GParted).
Then, it should reboot and commence installation - follow on-screen instructions (input your router details to make use of Wifi).


Install add-ons and do basic configuration:

Follow step-by-step - otherwise you will run into problems:
1) A) (Update) Before anything else, update your repos in: /etc/apt/sources.list
and uncomment any unused repositories, including precise-backports, but make sure there are no duplicates.
-   B) Alternatively, you can use Software Properties application:
software-properties-gtk
(If you run into duplicate warnings: http://askubuntu.com/questions/120621/how-to-fix-duplicate-sources-list-entry)
2) Add OMAP PPA (Guide for installation of add-ons: https://groups.google.com/forum/#!topic/pandaboard/vKunvhMNV8k
3) Update sources and upgrade software.
4) Install drivers.
5) Change bootargs ! Follow this link for more info: https://groups.google.com/forum/#!msg/pandaboard/7DLabw7amBg/ofeX-SOsdw4J
Change this:
vram=40M mem=456M@0x80000000 mem=512M@0xA0000000
to this:
 mem=1G@0x80000000

in your /boot/boot.script
ro elevator=noop console=ttyO2,115200n8 mem=1G@0x80000000 root=<UUID or LABEL root> fixrtc splash
(Recommended bootargs according to Xavier)
6) Force bootloader update.
7) Tweak ALSA as advised (not sure why).
8) Disable hardware cursor option ! It cause GUI crashes if not disabled. Edit  /usr/share/X11/xorg.conf.d/99-omap.conf and add this line to Device section:
Option "HWcursor" "false"
9) Re-boot.
10) Re-install pvr-omap4-dkms (it causes constant error messages otherwise). You can check if the GPU module is loaded with lsmod.
If the board doesn't boot the first 10 times, press Enter for e.g. to end this.
sudo nano /etc/apt/sources.list

sudo add-apt-repository ppa:tiomap-dev/release
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ubuntu-omap4-extras
sudo nano /boot/boot.script
sudo /usr/sbin/flash-kernel --update-bootloader
sudo /usr/bin/alsaucm -c Panda set _verb HiFi
sudo nano /usr/share/X11/xorg.conf.d/99-omap.conf
sudo reboot
sudo apt-get install --reinstall pvr-omap4-dkms && sudo reboot
Optional:
Use GParted to change your SD card label - this will make it much easier to make sure the rootfs are always found, even after backing up / restoring image. For example, if you change the label to PANDA, add this bootarg:
root=LABEL="PANDA"

Optional:
Disable SWAP, if you are using a SD card. This is strongly advised, as you will be trashing your SD card, not to mention slowing down your system (I/O of Pandaboard SD card is quite slow). Follow these commands to disable it completely (you can confirm that SWAP is not being used with top):
sudo swapoff -a
sudo nano /etc/fstab
sudo rm /SWAP.swap
(Remove SWAP entry from fstab)



(Update) Optional: Update TI PPA software

You can update some of OMAP stuff by getting packages from TI Trunk PPA, which is more up to date. It includes updated GPU drivers, among other things.
(You don't need to remove Release PPA)

1) Add ppa:tiomap-dev/omap-trunk repository
2) Run apt-get update, followed by dist-upgrade
3) Again, make sure xorg configuration has Hardware Cursor disabled !
4) Force boot-loader update !
 
sudo add-apt-repository ppa:tiomap-dev/omap-trunk
sudo apt-get update
sudo apt-get dist-upgrade
sudo nano /usr/share/X11/xorg.conf.d/99-omap.conf
sudo /usr/sbin/flash-kernel --update-bootloader


(Update) Optional: Disable ondemand CPU frequency scaling:

(Thanks to Trevor Robinson)

Note: Doesn't seem to solve the issue for me, but quoted to be successful by some users. Also, setting performance governor will surely increase the incidence of overheating by logic. If the freeze is due to overheating, this may make the problem worse ... 
sudo update-rc.d ondemand disable
sudo apt-get -y install cpufrequtils
sudo echo 'ENABLE="true"
GOVERNOR="performance"
MAX_SPEED="0"
MIN_SPEED="0"' > /etc/default/cpufrequtils
sudo cpufreq-set -r -g performance
This disables ondemand and forces Ubuntu to switch to performance mode

Install a light Desktop Environment:

This can be LXDE or XFCE4 for example:
sudo apt-get install lxde
or
sudo apt-get install xfce4
Both are quite light. LXDE is probably lighter, but XFCE has nice customization of panels and workspace, which can help offset over-scan issue you might have on TV screen for e.g.
If you want full desktop version with all the features, you can install xubuntu-desktop or lubuntu-desktop respectively.
Important: Do not use XFCE4 Settings / Display !! You will end up with no image if you switch resolution. Instead, install ARandr.
There is also Enlightenment.
For those interested in GLES2 accelerated window manager, have a look here:
https://userbase.kde.org/KWin
Its a KDE Window Manager, but can be bundled with any DE with some tweaks. Here is a nice guide by Will Foster about using KWin with XFCE4:
https://hobo.house/2015/08/14/using-kwin-with-xfce/
Now, I have tried that by adding: kwin_gles --replace to auto-sessions in XFCE, which does the trick. However, I haven't noticed any difference ...

Problems after update

1) HDMI blanking

There is a weird issue of HDMI screen going black on some hardware ... Well, I have the symptoms. It happens in particular stages:
After splash screen and before login
When login crashes
When I move mouse (!)
When going from Shell console back to GUI
To recover:
Disconnect and reconnect your HDMI cable - you should get back to login screen
We need to turn-off hardware cursor (how can such small thing as mouse pointer have an effect ??): create xorg.conf and edit it turning off hardware cursor.
After reboot, everything works fine ! Unity 2D is advised

2) Freezes / lock-ups / turn-offs

Strange random boot-up freezes: sometimes it gets stuck on splash loading screen, sometimes after ... LEDs may or may not blink, may stop blinking after splash ... Well, really weird. So I have to to do a full reset - disconnecting power supply and pressing reset button.
Apparently, odemand governor is a culprit: http://askubuntu.com/questions/201981/pandaboard-crash-on-startup-or-freeze-after-minutes and https://bugs.launchpad.net/ubuntu/+source/linux-ti-omap4/+bug/971091. I don't think it has anything to do with overheating, at least not for Panda at 1GHz.
The solution should be to disable odemand. But that didn't solve the problem completely... Freezes happen during installation of software or browsing, as well as watching movies.
This may be related to overheating.
Make sure you fully disconnect the board: remove power supply and eject SD card, only then re-insert and boot up. Otherwise, it can continue to freeze each few minutes.
Update: Nice topic discussing the issue on Pandaboard ES: https://groups.google.com/forum/#!topic/pandaboard/sZtIzLs1LaM

3) Limited resolutions on HDMI

It seems not all TV resolutions are available in Xrandr. After trying Ubuntu 12.10, I have noticed that I have much more resolutions there than on 12.04 (it was not very useful system though). I couldn't find any solution so far, apart from accepting ... Oh, Xrandr --newmode doesn't work, at least for me. I have followed this Ubuntu guide: https://wiki.ubuntu.com/X/Config/Resolution#Adding_undetected_resolutions


How to back up the system to host computer:

Insert your SD card and don't mount it.
Use dd to write an image from it and compress with gzip, for e.g. (sudo fdisk -l to confirm your card just in case):
sudo fdisk -l
cd $HOME
sudo dd bs=4M if=/dev/sdX of=Pandaboard-8GB.img
gzip Pandaboard-8GB.img
This allows us to create our own image of Ubuntu on Panda and restore if we mess up ...
(Be warned that dd and gzip can take a long time to finish)


Status:

- GPU 2d / 3d acceleration is working, video scaling, etc; use es2gears to check (Unity 2d or and other desktop environment is preferred)
- Hardware video acceleration is working via Gstreamer (Totem and XBMC are supported and work quite well), however:
* Not all formats are supported in Totem - MKVs are sideshow :( ... Use MP4s preferably
* XBMC supports more containers ! :) At least MKVs. 720p works like a charm, 1080p is a little bit sluggish. Sometimes shattering occurs in some videos and supplied XBMC doesn't seem to support subtitles ...
- Audio over HDMI / speakers works fine
- Wifi works fine
- SD card speed is somewhat slow (known issue)
- Bluetooth doesn't work (will never work, not with stock kernel)
- System is not stable (see above)