How to create Geduino SD Card

How to prepare Geduino SD Card


Needed resources:



Needed hardware:


  • an Ubuntu PC (used Ubuntu 14.04 LTS on Parallels VM);
  • an SD Card (used a 4GB SD Card);
  • a Card Reader (used one integrated on Mac).

Step 1 - Prepare SD Card

The SD Card must be prepared before copy resources.

Plug you SD Card on the reader (using Parallels you will be asked the host on which the SD Card must be attached: select Ubuntu VM).

First you have to identify the device corresponding to SD Card. The simplest way is to execute lsblk command from a terminal: list of all existing device will be shown. Now plug you SD Card on the reader (using Parallels you will be asked the host on which the SD Card must be attached: select Ubuntu VM) and repeat the command. A new device will be shown: it is the SD Card! (in my case /dev/sdb);

Start GParted and select the device corresponding to SD Card.

If your SD Card has not a partition table select menu Device -> Create Partition Table. You will asked for the partition table type: select MS-DOS.

Now create a new partition from menu Partition -> New. Use following parameters:

  • free space preceding (MiB): 10;
  • free space following (MiB): 0;
  • align to: MiB;
  • create as: Primary Partition;
  • file system: ext3;
  • label: whatever you want (used UDOO).

Click on Add and confirm you modification.

As result you will have an ext3 partition where put the file system: the 10MB leave free before will be used to flash u-boot.

Step 2 - Prepare file system

Mount the just created partition (used /mnt/sdcard).

Unpack and copy the Ubuntu Core to SD Card using:

sudo tar -xzvpf ubuntu-core-13.04-core-armhf.tar.gz -C /mnt/sdcard

Existing modules and firmwares must be removed before copy the UDOO ones:

sudo rm -R /mnt/sdcard/lib/modules
sudo rm -R /mnt/sdcard/lib/firmware

Unpack the UDOO modules file:

sudo tar -xzvpf modules.tar.gz

and copy modules and firmware on the SD Card:

sudo cp lib/modules /mnt/sdcard/lib/
sudo cp lib/firmware /mnt/sdcard/lib/

Finally copy to UDOO Kernel image:

sudo cp uImage /mnt/sdcard/boot

Step 3 - Flash the u-boot

First unmount your SD Card

sudo umount /dev/sdb

Then copy the u-boot image:

sudo dd if= u-boot-q.imx of=/dev/sdb bs=512 seek=2

Be sure all data are flashed on SD Card using sync command:

sync

Now the SD Card is ready: you can make a test pluggin the SD Card to UDOO and start it. UDOO should start and ask for login.

Step 4 - Create a user

If you start UDOO with the SD Card just prepared you was asked for a login: which credential did you use? As you saw there is not user on this OS so we need to create a new one in order make it work.
Plug the SD Card to your PC and mount it:

sudo mount /dev/sdb /mnt/sdcard

You will need following packages on your PC:

  • binfmt-support;
  • qemu-user-static;
  • debootstrap.

If you have not them install using apt-get

sudo apt-get install binfmt-support qemu-user-static debootstrap

Copy  qemu-arm-static to your SD Card:

cp /usr/bin/qemu-arm-static /mnt/sdcard/usr/bin/

And execute:

sudo chroot /mnt/sdcard

Not you will be able to operate as root of OS on your SD Card. So let’s create user:

adduser udoo
adduser udoo adm
adduser udoo sudo

This will create a user (called udoo, but you can use what you prefer as username). You will also asked for a password and other informations.

During this operation some errors should be shown related to the languages. To fix it use:

sudo apt-get install --reinstall language-pack-en 
sudo locale-gen
sudo dpkg-reconfigure locales

Booting UDOO at this time you will be able to login with just created user. Unfortunately there is not so much you can do since, also basic packages like text editor and network tools, are not installed.

Step 5 - Install basic packages

So plug SD Card to your PC, mount it and use chroot as done before.

Before install other packages some fixes are needed in order to make apt-get works. The Ubuntu Core 13.04 ARMHF use old url in /etc/apt/sources.list. You can fix it using:

sudo sed -i 's@ports.ubuntu.com/ubuntu-ports@old-releases.ubuntu.com/ubuntu@g' etc/apt/sources.list

After that open etc/apt/sources.list file and enable all repos removing the comment char (#).

Probably you will also need a DNS server:

echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null

Now you are ready to install other packages:

apt-get update
apt-get install sudo nano net-tools openssh-server isc-dhcp-client
apt-get install inetutils-* wpasupplicant avahi-autoipd inetutils-ping ntp

ntp package added in order to synch Udoo clock with Ubuntu NTP servers 

This task can take really long time execute from chroot. In order to speed up you can download those packages (and other dependencies), plug your SD Card on UDOO, start it and install the downloaded packages.

To download packages and their dependencies use:

apt-get clean
apt-get update
apt-get install —download-only sudo nano net-tools openssh-server isc-dhcp-client
apt-get install —download-only inetutils-* wpasupplicant avahi-autoipd inetutils-ping

and type:

exit

to exit chroot, so use sync to flush all data and unmount the sdcard. Plug SD Card to UDOO and boot it. Login with username and password then install downloaded packages:

sudo dpkg -i /var/cache/apt/archives/*deb

All downloaded packages will be installed. Execute

apt-get clean

to clean the apt cache.


Step 6 - Final configurations

Finally some configuration must be done. I performed those tasks from UDOO itself but you can also use chroot on your PC. First set up network configuration editing /etc/network/interfaces:

sudo nano /etc/network/interfaces

And add following line for eth0:

auto eth0
iface eth0 inet dhcp

Now you can start networking using:

sudo ifup eth0

Check you network using:

ping <SOME_KNOW_HOST>

Now only hostname must be setup. Open /etc/hostname file:

sudo nano /etc/hostname

and put your hostname into the file (overwrite existing one). Not open /etc/hosts file:

sudo nano /etc/hosts

and add following line:

127.0.0.1 <HOSTNAME> localhost

and save.

In order to make your wifi network working following packages must be downloaded:

sudo apt-get install wireless-tools wpasupplicant

and add following lines to /etc/network/interfaces file:

iface wlan0 inet dhcp

and for WPA protected network:

wpa-ssid <YOUR_SSID>
wpa-psk <YOUR_KEY>

or for free access network:

wireless-essid <YOUR_SSID>

Before turn on you wifi connection you need to install the firmware for network card. Expand the UDOObuntu file system archive into a temporary folder:

sudo tar -xzvpf UDOObuntu_FS_v1.0.tar.gz temp

Now copy the firmwares to your SD card:

cp temp/lib/firmware/rt*.bin /lib/firmware

Now you can activate you wifi connection using:

sudo ifup wlan0

Congratulation, your system in now ready to be connected to the network and download and install packages!

Step 7 - Installing ROS

Before installing ROS we need to add ROS repositories to /etc/apt/sources.list. Open /etc/apt/sources.list file using nano:

sudo nano /etc/apt/sources.list

enable universe, restricted and multiverse repos uncommenting relative lines and add following lines:


UPDATE:
http://packages.ros.org is no longer available. Use http://packages.namniart.com/repos/ros instead.

Furthermore you need to download and add ROS repo key:

wget http://packages.ros.org/ros.key
sudo apt-key add ros.key

UPDATE:
http://packages.ros.org is no longer available. Get key from http://packages.namniart.com/repos/namniart.key instead

Update apt database using:

sudo apt-get update

Now you can install ROS packages. In order to have a minimal installation use:

sudo apt get install make ros-hydro-ros ros-hydro-roscpp ros-hydro-roslaunch ros-hydro-rostopic

NB: Make is needed for build packages but is not included on Ubuntu core and is not dependencies of ROS packages.

Package python-rosdep should be automatically installed. If not do it using:

sudo apt-get install python-rosdep

Now initialize rosdep using:

sudo rosdep init
rosdep update

(This last command still result in an error on my installation. I was not able to fix it but it seems this does not affect other tasks)

Finally ROS environment must be set up. In order to do it automatically when terminal is open add following lint to ~/.bashrc:

source /opt/ros/hydro/setup.bash

Now reboot your system and type:

roscore

if roscore is started you have a running ROS on your UDOO!


Step 8 - Make a copy image of your SD Card


If you want to sleep quietly I suggest you to make a backup copy of your SD Card. To do that plug your SD Card on PC and unmount it using:

sudo umount /dev/sdb

Now create the image using:

sudo dd if=/dev/sdb of=~/sdcard-backup.img

Appendix A - Troubleshooting


catkin_make show warning “Clock skew detected”


During ROS package build you should have following warning raised by make:

make: warning: Clock skew detected. Your build may be incomplete.

That message is usually an indication that some of your files have modification times later than the current system time. Since make decides which files to compile when performing an incremental build by checking if a source files has been modified more recently than its object file, this situation can cause unnecessary files to be built, or worse, necessary files to not be built.

However, if you are building from scratch (not doing an incremental build) you can likely ignore this warning without consequence.

Pesmission denied accessing /dev/ttymxc3

The serial port user between iMX6 and SAMx3 is /dev/ttymxc3. Accessing this port with normal user will cause permission access error. To fix it execute:

sudo chmod 777 /dev/ttymxc3

rosserial_arduino HelloWorld example is not working

This happen due to a bug on rosserial_arduino package that result in a warning during compiling. It is also a warning but a the end the sketch will not works.

This bug was fixed on hydro git repo but the binary packages does not contains it. In order to fix it you can install rosserial by source.

Move to your repo directory and download sources from git:

git clone https://github.com/ros-drivers/rosserial.git

If certificate problem occurs downloading from git (this can happens since UDOO lose date and time at restart) set following environment variable:

export GIT_SSL_NO_VERIFY=1

To make this permanent use

git config --global http.sslverify false

instead.

Then build and install this package:

catkin_make
catkin_make install
source <ws>/install/setup.bash

After that you can remove rosserial sources from you workspace if not needed. I found also some bugs on generated ros_lib. It should be fixed commenting out following lines on ArduinoHardware.h:

//#if defined(USBCON) and !(defined(USE_USBCON))
      /* Leonardo support */
//      iostream = &Serial1;
//#else
      iostream = &Serial;
//#endif
      baud_ = 57600;

Run rosserial server

The rosserial server has same limitation in comparison to rosserial_python but, since it is a c++ implementation, has better performance.

Start it using:

rosrun rosserial_python serial_node.py _port:=/dev/ttymxc3

Change keyboard layout

To change the keyboard layout first you have to install following packages

sudo apt-get install console-data

after that use

sudo dpkg-reconfigure console-data

Install X server and Java JRE

To install X server:

sudo apt-get install xorg

To install Java JRE

sudo apt-get install default-jre

Change boot sequence

Change boot sequence can be useful in order to start, on different tty, different process at boot time. For this purpose different users must be created for any process to be started. For ex:

  • ros user, to start ros;
  • ui user, to start user interface;
  • ….
The boot procedure will automatically login ros user on tty1, ui user on tty etc. The login sequence of each user will launch its own process.

To create a new user (for ex. ros):

sudo adduser ros

To auto login a user on a tty (for ex. ros on tty1) open /etc/init/tty1.conf file:

sudo nano /etc/init/tty1.conf

And replace line:

exec /sbin/getty -8 38400 tty1

with:

exec /bin/login -f ros < /dev/tty1 > /dev/tty1 2>&1

Now ros user will be automatically login at boot. To change its boot sequence open /home/ros/.bashrc:

nano /home/ros/.bashrc

This bash file is execute after user login. Add at the end of this file the command to start your process, for ex.:

source /opt/ros/hydro/setup.bash
roscore

If needed you can also modify the logout sequence modifying /home/ros/.bash_logout

nano /home/ros/.bash_logout

To start X server use:

xinit

If you want to execute command when X server start (for ex. start  a Java UI application) create .xinitrc file in /home/ros

nano /home/ros/.xinitrc

Command on this file will be execute when X server is started by ros user. For ex.:

java -jar java-ui.jar




Nessun commento:

Posta un commento

Nota. Solo i membri di questo blog possono postare un commento.