Saturday 26 May 2012

How to install Debian on Pandaboard + do basic configuration.


Installing Debian - very easy and fast:

EDIT: Updated for the latest version of rootfs. Some minor changes.
(Thanks to Dr. Ace Jeangle for providing those instructions: http://www.chalk-elec.com/?p=1478 )
(And thanks to Robert Nelson, for creating and providing ARM hard float Debian rootfs. You can visit his site by following this link: http://www.rcn-ee.com .)

Insert your SD card into a card reader of your host PC and run the commands below on your host system, preferably Ubuntu or Debian. (We are using apt-get here.)

WARNING !!! PLEASE ENSURE THAT THE "sdb" DEVICE IS THE ONE OF YOUR SD CARD ! "sda" IS MOST CERTAINLY WRONG ONE TO USE ! IF YOU ARE NOT CAREFUL, YOU CAN WIPE OUT YOUR HARD DRIVE ! PLEASE READ BELOW ABOUT EASY WAYS TO CHECK WHICH ONE IS YOUR CARD

To check the latest rootfs available, visit:
http://rcn-ee.net/deb/rootfs/wheezy/
and update the VERSION variable to that of the newest rootfs
VERSION="2012-11-29"
sudo apt-get install uboot-mkimage wget pv dosfstools btrfs-tools parted
wget http://rcn-ee.net/deb/rootfs/wheezy/debian-wheezy-minimal-armhf-$VERSION.tar.xz
tar xJf debian-wheezy-minimal-armhf-$VERSION.tar.xz
cd debian-wheezy-minimal-armhf-$VERSION/
sudo ./setup_sdcard.sh --mmc /dev/sdb --uboot panda

Use "panda" for PandaBoard Ax (non-ES). Use "panda_es" for PandaBoard ES.
(http://elinux.org/BeagleBoardDebian#Demo_Image)
In my case, the name of my card is "sdc", because I have external USB HDD, which is "sdb". But usually, the card would be "sdb". I use:
sudo ./setup_sdcard.sh --mmc /dev/sdc --uboot panda
You can use the following command to see what is mounted:
df -h
Or you can use:
dmesg
just after you have plugged-in your SD card.
Take a notice of "sdb" or "sdc". Estimate which is your card.

Another OS is installed on the card:

If your card has already got some OS installed on it, we can remove it using "fdisk":
sudo fdisk /dev/sdc
(Change "sdc" to what you have !!!) NOTE: Use "d" option to delete a partition. Each partition has a number (1, 2, etc). Use option "w" to save your changes. (Otherwise your changes will not be saved.)

Video output:

a) If you want to use DVI video output:
Open file uEnv.txt on "boot" partition of the card:
(for e.g.)
nano /media/boot/uEnv.txt
uncomment the line "defaultdisplay=dvi", uncomment "vram=16MB" (if it is commented), uncomment "dvimode=1280x720MR-16@60" and (if you want) change it to suit your display. Some examples (as I don't use DVI) can be found here, by Dr. Ace Jeangle:
http://www.chalk-elec.com/?p=1478

b) If you want to use HDMI video output:
Same as above, except that you leave "dvimode=1280x720MR-16@60" commented in and change "defaultdisplay=dvi" to "defaultdisplay=hdmi".
More to come, when I do a little bit of testing with custom kernel, as with stock kernel, I have stubborn 640x480 60Hz output on my 1080i TV, via HDMI.

Booting process:

Insert your Debian populated SD card into Pandaboard and boot-up the board.
Ok, if your new Debian system is working, on boot you should see the video output being displayed on your monitor or TV. The booting process progresses much faster than on Ubuntu. After a minute or so you should see the login prompt (in Command Line Interface - no GUI).
(From here onwards, all the commands will be executed on our board.)

Login:

So, how do I login ? Well, the default user is "debian" and "temppwd" is its password. The root password is "root". (http://elinux.org/BeagleBoardDebian#Debian_Wheezy_snapshot)

Important security measures:

1 - Change root password ! (IMPORTANT !!!)
Login as root and run:
passwd
then enter and verify your new root password.
2 - Create new user.
Login as root (temporary) OR login as debian and use:
su
(sudo might not work), then run:
adduser YOUR NEW USER NAME
and answer all questions (password, full name, etc).
3 - Add the user to sudoers file. 
(Optional. Will grant the user the ability to use "sudo" command.)
Run:
su
visudo
This will open the /etc/sudoers file. (Visudo is made for this ! Don't think about using nano, vim, etc.)
Look for the following line:
root ALL=(ALL) ALL
and add this line just underneath:
user ALL=(ALL) ALL
changing "user" to your username. Save and exit: Ctrl + o, ENTER, Ctrl + x. Now you can use the "sudo" command. (Btw, "sudo" uses user password, not root password.
4 - Change debian password.
Login as debian or (your username) and run:
 sudo passwd debian
and type in + verify your new debian password. (This is strongly advised, as the default debian password is known and public.)

Set-up Internet connection:

Now, to download packages and etc we need to have an Internet connection. For Panda we have 2 options: Ethernet or WiFi - both work in our Debian Linux !
a) Ethernet: Just connect the cable between your router and the board. It should work straight away - no configurations are needed. Reboot is not necessary.
b) WiFi: Here a little bit of work is needed. But it will work: (This site has really helped me: http://www.howtoforge.com/how-to-connect-to-a-wpa-wifi-using-command-lines-on-debian)
1 - Run "ifconfig -a" if you want to. We do have our WiFi adapter working though. Its name is: wlan0 (We also have wpasupplicant installed - no need to search or install it.)
2 - Create and edit the following file:
su
nano /etc/wpa_supplicant.conf 
Type in the following:
network={
                 ssid="TYPE IN THE NAME OF THE ROUTER HERE"
                 psk="TYPE IN ITS KEY/PASSWORD HERE"
}
Complete the entries. Save and exit: Ctrl + o, ENTER and Ctrl + x .
3 - Run the following command:
wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext
Then, when you see its output, hit ENTER.
4 - Run this last command:
dhclient wlan0
and now you should be connected.
5 - Following the next boot, you will be disconnected. To reconnect, you just repeat step 3 and 4.

Before installing anything:

Update your system. This is required, as you will run into problems if you don't do this:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
Depending on how old is your rootfs, this might take few minutes.

Installing Graphical User Interface:

The easiest way is by using the minimal_lxde_desktop.sh script, provided by Robert Nelson.
(This will give you a working LXDE environment, which I think is the best choice for us.)
cd /boot/uboot/tools/ubuntu
sudo sh minimal_lxde_desktop.sh
Or you can install LXDE with one command line:
sudo apt-get install lxde
If your choice is XFCE, then do:
sudo apt-get install xfce4
LXDE is the easiest option and is the guaranteed one. XFCE didn't work for me last time. GNOME / KDE would take a lot of time to install and are quite heavy (for fbdev in particular).
Installing any of these desktop environments will also cause installation of Xorg (1.12 currently), as well as xserver-xorg-video-fbdev driver, which we will use initially.

Achieving auto-connection (with Wifi):

We have a number of options here. The following are those, which I have tried:
(Choose option "c" if you want boot-up speed-up, but don't want Ethernet.)

a) Install Wicd client:
sudo apt-get install wicd
and answer one configuration question (which users will run wicd). Run the client, find your router, provide your password (in Advanced Settings), click "Automatically connect to this network" box and that's all ! (I don't know for sure, but in my case I had to reboot to get connection. Works perfectly.)

OR

b) Debian has a rc.local start-up script, which we can edit. Open the /etc/rc.local file:
sudo nano /etc/rc.local
and just add the following commands:
wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext
dhclient wlan0
to the end of the script (after all comments), BUT before "exit 0" command. Save and exit. You will be connected each time you boot.

OR

c) This one is the best so far. Edit /etc/network/interfaces file:
sudo nano /etc/network/interfaces
,look for the following:
# WiFi Example
#auto wlan0
#iface wlan0 inet dhcp
#    wpa-ssid "essid"
#    wpa-psk  "password"
,comment out  the last 4 lines quoted here and substitute "essid" with (your router ssid), "password" with (your router password). Now look for:
# The primary network interface
auto eth0
iface eth0 inet dhcp
and comment in the last 2 lines quoted. In the end, the file should look like this:
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0
#iface eth0 inet dhcp
# Example to keep MAC address between reboots
#hwaddress ether DE:AD:BE:EF:CA:FE

# WiFi Example
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid "**********"
    wpa-psk  "**********"
Save and exit. Done.
This actually has a double value for us. 1st - you have a working Wifi, which will be connected at each boot. 2nd - your boot-up time is reduced significantly, as Ethernet is disabled at boot and there is no DHCPDISCOVER loop (which takes about a minute of time). Being in this section means that you don't need Ethernet anyway.

Clock skew and its solution (Important !):

The most annoying problem ... EDIT: Seems to me there are still problems with this, ugh ...
The initial time we have in Debian is .... ugh ... quite far from being accurate - 1st of January, 1970 ! This indicates that the clock was completely reset ... No wonder - Panda, by itself, doesn't have a battery to supply hardware clock.
First, we need to make sure that the timezone is correct. To edit the timezone, we use:
tzselect
and follow the steps. In the end, you will get:
Therefore TZ='TIMEZONE YOU HAVE' will be used.
with you timezone. This is what we need. For example, I got:
Therefore TZ='Europe/Dublin' will be used.
Now, like stated, we will make this change permanent:
cd
nano .profile
Scroll to the bottom of the file, leave an empty space after the last line and add the timezone line:
TZ='TIMEZONE YOU HAVE'; export TZ
Save the file (Ctrl + o, ENTER, Ctrl + x), log out and log in again. Your timezone is set.
Next, we will set the correct time and date. For this task, we will use "date" command:
(Example)
sudo date -s "Jun 1 20:27:00 2012"
The usage is obvious enough. The "-s" flag is used to set the date. Use first 3 characters of each month.
To see the date, use:
sudo date
Now, we wouldn't be able to maintain the correct time via hardware clock. (Unless you have modded your board.) So, we are going to rely on the Internet to sync the clock. Lets use NTP service.1) Install the package:
sudo apt-get install ntp
2) Edit the configuration file (if you want better accuracy):
sudo nano /etc/ntp.conf
Look for the following section:
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
Replace this section by a relevant section of the NTP server you want to use. For e.g. I live in Ireland - so I want a local NTP pool. I have added:
server 0.ie.pool.ntp.org
server 1.europe.pool.ntp.org
server 0.europe.pool.ntp.org
and saved the file.
Look here about which pools to use and how to add them:
http://www.pool.ntp.org/use.html
3) Restart the NTP service:
sudo service ntp restart
Or, if the above command gives you a warning, you can use the combination:
sudo service ntp stop
sudo service ntp start
4) Your NTP service should be set up now and should sync the clock from time to time. Now, if you want to test whether it actually works, run:
sudo ntpq -pn
and you should see something like that:

Note the asterisk (*) (you will probably notice it only after reboot). If you have it, it means that this IP address is being currently used to provide the time for syncing the clock. Initially after reboot, you might notice that the time is set wrong again, but it is only temporally. After few minutes, the clock will be synced. That's all in relation to time.
If your desktop clock (clock applet) shows wrong time, run "sudo date" command to update it.
Note: I know, this paragraph might not sound important, but please, don't skip it. The reason being is that a clock skew will be a source of many annoying problems; such as those warnings you get during "tar" extraction, warnings during kernel configuration, potential errors during compiling, loads of other problems... We don't want them, right ?

Some tweaks:

Turn off SWAP:
SWAP is a form of virtual memory, which is:
- Completely useless for Pandaboard, as SD I/O is hellishly slow !!!
So, check if you have it disabled:
free -m
which should give you this line:
Swap:            0          0          0
meaning swap is disabled. This is how it should be.
If it is not disabled, run this to switch it off:
sudo swapoff -a
which should do the job. That's all.

Disable Ethernet at boot (if it is not needed):
(Skip this section, if you have used option "c" in "Achiving auto-connection (with Wifi)" section)
With Ethernet enabled, what you get is a couple of "DHCPDISCOVER...." lines and about 0.5 - 1 minute of wasted time during boot. If you don't use Ethernet, why wasting time because of it ?
To disable it, edit /etc/network/interfaces file:
sudo nano /etc/network/interfaces
and comment in the following:
auto eth0
iface eth0 inet dhcp
so it will look like:
#auto eth0
#iface eth0 inet dhcp
save and exit. Done !

Disable screensaver in LXDE:
Screensaver is useless in our case. It is an extra load for CPU, as we do not have OpenGL drivers (and will probably never have). We would be able to install GLES / GLES2 drivers, but they are most likely not used by screensaver. So, lets disable it.
For LXDE:
Open /etc/xdg/lxsession/LXDE/autostart file:
sudo nano /etc/xdg/lxsession/LXDE/autostart
and remove "screensaver" line. Save and exit.

My comments about what I have so far: 

- The system is fast. Certainly much faster than Ubuntu. It boots quicker (edit: at least with original kernel) and is much more responsive.
- EDIT: But SD I/O is still slow :(
- The rootfs partition is Ext4 !
- Both USB keyboard and USB mouse work normally.
- Ethernet is working fine.
- WiFi is working. Firmware is installed.
- HDMI out works. With GUI, I get 640 x 480 picture at 60 Hz on my 720p HDMI TV (with default kernel). Fbdev driver is being used by default. Primitive, I know. But this is only temporary. Later, I will try to install GPU drivers. But first, I need to choose the right version of kernel and install it. (GPU drivers are heavily dependent on the version of the kernel you use.) Of course, you should be able to somehow change you resolution, by modifying your uEnv.txt file. Also, you can install the omapfb driver, which is for OMAP DSS (also uses NEON extension) - it doesn't use SGX though. The omapfb driver will be faster than fbdev driver.
- Sound doesn't work - no soundcard is found. We should be able to solve this ...
- I don't know whether Bluetooth works or not. However, according to some comments on http://www.chalk-elec.com/?p=1478 , it should work.
- Obviously no 2d/3d hardware acceleration yet. I will try to install the drivers ...EDIT: 2d/3d in progress ...
- No hardware video decoding yet. This will probably take a lot of time to set up ...
- Edit: Clock skew problem solved. Took a lot of time !
- A lot more to come. I will try to get as much working staff as I can on this awesome board !

Why did I choose Debian in the first place:

1 - Heard it was much faster than Ubuntu.
2 - Debian uses .deb packages, like Ubuntu, and also shares a lot in common with it. Installing packaged drivers should work ... Of course some changes will be needed.
Actually, after I have done a little bit of reading, I understood that: INSTALLING UBUNTU PACKAGES ON DEBIAN IS NOT A GOOD IDEA AND CAN CAUSE A LOT OF PROBLEMS LATER ON. So, I am going to build everything from source.
3 - I just wanted to see what is Debian like ! (I have already tried Ubuntu, Angstrom, YDL and Fedora.)

What's next ?

Lets build Ubuntu kernel ! This way, we would be able to install SGX drivers and hardware decoders/encoders.
http://alastordmcblog.blogspot.com/2012/05/debian-on-pandaboard-building-ubuntu.html





9 comments:

  1. where do I get the setup_sdcard.sh I read every where on the internet and everyone talking about the script file but, I can not find it.
    thanks,

    ReplyDelete
    Replies
    1. As far as I remember, the file should be in "debian-wheezy-minimal-armhf-2012-03-29/" directory, after running first cd command.

      Delete
  2. it is very helpful, but I have some question. I use the HDMI, and I don't know how to change the resolution ratio,can you help me ?

    ReplyDelete
    Replies
    1. Sorry for late reply, was quite busy and didn't boot up panda until recently. But I don't really know, because I didn't want to play with resolution until I have working SGX drivers, accelerated 2d/3d and xvideo. I will try to get this working ...
      Maybe you can play with values in "uEnv.txt" ? There is dvimode, so hdmimode might be possible to use...

      Delete
    2. Can I disable the screen saver in Ubuntu?

      Delete
    3. Yep, you can and probably should. Screensaver uses OpenGL binaries, we use OpenGLES. So screensaver by itself will use CPU for rendering, unless they have added support for GLES1/2 ... Disabling screensaver is easy, but depends what GUI you use.

      Delete
  3. Thanks, very useful recipe. I'm using debian with pandaboard.

    Nevertheless I'm tring to get the same for a Sabre lite board (embest, using ./setup_sdcard.sh --mmc /dev/sdc --uboot mx6qsabrelite). Despite I have a SD card flashed, I don't know how to launch debian SD sw from sabre bootloader, any Idea?

    ReplyDelete
  4. Well, after completing this https://wiki.linaro.org/Boards/MX6QSabreLite, the bootloader works better but some files are missing:

    Running bootscript from mmc ...
    ## Executing script at 10800000
    boot.scr -> uEnv.txt wrapper...
    Loading file "uEnv.txt" from mmc device 0:1 (xxa1)
    1009 bytes read
    Loading file "uImage" from mmc device 0:1 (xxa1)
    ** File not found uImage
    Loading file "uInitrd" from mmc device 0:1 (xxa1)
    ** File not found uInitrd
    Loading file "/dtbs/imx6q-sabrelite.dtb" from mmc device 0:1 (xxa1)
    ** File not found /dtbs/imx6q-sabrelite.dtb
    Booting from mmc ...

    If I looking at /dtbs/ I can't found imcq-sabrelite.dtb. Nevertheless in your script i can find:

    mx6qsabrelite)
    SYSTEM="mx6qsabrelite"
    (...)
    dtb_file="imx6q-sabrelite.dtb"
    need_dtbs=1
    My board is from embest.

    Any Idea?

    ReplyDelete
    Replies
    1. Sorry, I don't get time to boot my board even on weekends now ... Dental student

      Delete