Tuesday, December 23, 2014

pcDuino3 Nano–Problems with the NAND Root File System

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

After connecting the SATA drive I had hoped to move on to setting up the system to recognize the drive and then to use it for the root file system.  However, I ran into a snag…

Some where along the way the root file system in nand had become corrupted.  I subsequently found out that it appeared the corruption occurred when I used apt-get to install the latest updates.  This was a problem because I planned to boot from nand and then copy the root file system from the sd card on to the SATA disk.

Initially I didn’t realize that the problem was with the apt-get so I re-installed the 20141205 kernel and the 20140807 root file system.  Once this was complete I used apt-get to install the latest updates and when the process was complete rebooted and found out I again had a corrupted file system.

At this point I decided to create an image of the root file system on the sd card which was current as of 20141222 and try and reinstall the 20141205 kernel with my 20141222 root file system.  This worked.

Below is the process I used for creating an image of the root file system on the sd card.

Creating an Root File System Image

I did this using a laptop that was running Ubuntu.  The process goes like this:

1. Copy the root file system from the sd card to disk.  First, determine the device for your sd card.  Once you have the device copy the second partition to disk.

ubuntu@ubuntu:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk
├─sda1   8:1    0  14.7G  0 part
├─sda2   8:2    0 118.2G  0 part
├─sda3   8:3    0  97.1G  0 part /
├─sda4   8:4    0     1K  0 part
└─sda5   8:5    0     3G  0 part
sr0     11:0    1  1024M  0 rom
sdb      8:16   1   7.4G  0 disk
├─sdb1   8:17   1    16M  0 part
└─sdb2   8:18   1   7.4G  0 part
ubuntu@ubuntu:~$ sudo dd if=/dev/sdb2 of=file.img
15529984+0 records in
15529984+0 records out
7951351808 bytes (8.0 GB) copied, 505.368 s, 15.7 MB/s

The lsblk command will report all the block structured devices.  In this case we can see that there are two disks sda and sdb and that sda has a partition sda3 that is the root mount point.  Based on this we want sdb2 as sdb1 is the boot partition.

2. Mount and check the image copy.  Using losetup mount the image file and run fsck to make sure it is in good order.  losetup is a nice utility to know about as it allows you to add image files as loopback devices and operate on them.

ubuntu@ubuntu:~$ sudo losetup -f --show file.img
/dev/loop0 ubuntu@ubuntu:~$ sudo e2fsck -fy /dev/loop0
e2fsck 1.42 (29-Nov-2011)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 70827/473280 files (1.3% non-contiguous), 416578/1941248 blocks

3. Resize the file system and the image file.  I was using an 8GB sd card and had expanded the file system to use the whole card.  To speed the update process I wanted to reduce the size of my root file system and the sd image.  To resize the file system I used the resize2fs command and then using dd created a copy of the image file.  As I was done with the loopback device I deleted it.

For the dd command I used a 1K block size and a count that was the same as the K size I had used with resize2fs.

ubutntu@ubuntu:~$ sudo resize2fs -p /dev/loop0 1677721K
resize2fs 1.42 (29-Nov-2011)
Resizing the filesystem on /dev/loop0 to 419430 (4k) blocks.
Begin pass 2 (max = 42302)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 60)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 6053)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0 is now 419430 blocks long.
ubuntu@ubuntu:~$ sudo losetup -d /dev/loop0
ubuntu@ubuntu:~$ dd if=file.img of=file2.img bs=1024 count=1677721
1677721+0 records in
1677721+0 records out
1717986304 bytes (1.7 GB) copied, 86.4562 s, 19.9 MB/s

4. Replace the Image on the Update SD Card.  Insert the second sd card you created in the pcDuino3 Nano – Kernel Upgrade at step 7 that has the 20140807 root file system and update.sh on it.  You will need to delete the old image file pcduino3_ubuntu_20140807.img and replace it with the image you created above.

You could also use a blank vfat formatted sd card with slightly different steps.  As the sd card is blank you would just copy the image file created above to the sd card.

ubuntu@ubuntu:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk
├─sda1   8:1    0  14.7G  0 part
├─sda2   8:2    0 118.2G  0 part
├─sda3   8:3    0  97.1G  0 part /
├─sda4   8:4    0     1K  0 part
└─sda5   8:5    0     3G  0 part
sr0     11:0    1  1024M  0 rom
sdb      8:16   1   1.9G  0 disk
└─sdb1   8:17   1   1.9G  0 part /media/C311-0715
ubuntu@ubuntu:~$ ls -l /media/C311-0715
total 1677760
-rw-r--r-- 1 gjdonaldson gjdonaldson 1717986304 Aug  7 02:58 pcduino3_ubuntu_20140807.img
-rw-r--r-- 1 gjdonaldson gjdonaldson        618 Aug  7 02:58 update.sh
ubuntu@ubuntu:~$ rm /media/C311-0715/pcduino3_ubuntu_20140807.img
ubuntu@ubuntu~$ cp file2.img /media/C311-0715/pcduino3_ubuntu_20141223.img

5. Update the copy of update.sh on the sd card replacing the image file name on line 3 with the name of the image you just copied to the sd card and save the file back to the sd card.

pcduino3_ubuntu_20140807.img –> pcduino3_ubuntu_20141223.img

If you are using the alternative method that started with the blank vfat sd card.  You will need to create a file on it update.sh that contains the lines below with the name of the image file above on line 3 after IMG=.

#!/bin/sh
cd `dirname $0`
IMG=pcduino3_ubuntu_20140807.img

IMG_SIZE=`du -s $IMG  | cut -f1`
BURN_TIME=`expr $IMG_SIZE / 1024 / 3 / 60`
echo -e "\twriting $IMG to nand flash\n"
echo -e "\tit will take about $BURN_TIME minutes to finish..."

time dd if=$IMG of=/dev/nandd bs=4M && sync
if [ $? -eq 0 ]; then
    echo "update finished"
    killall blink_led.sh
    /blink_led.sh 18 1000000 &
    /blink_led.sh 19 1000000 &
else
    echo "write ubuntu to nand failed"
    killall blink_led.sh
    /blink_led.sh 18 100000 &
    /blink_led.sh 19 100000 &
    exit 1
fi

6) Power off your pcDuino3 Nano and put the sd card with the 20141205 kernel update on it into the pcDuino3 Nano’s sd slot and apply power to the pcDuino3 Nano.  If you don’t have an sd card with this on it you can follow the steps in pcDuino3 Nano – Kernel Upgrade to generate the card.

While the kernel is loading LED 4 will flash.  Once the load is complete it will turn off.  When it does turn off the pcDuino3 Nano and remove the sd card.

7) Put it in the sd card we updated in the steps above into the sd card slot of the pcDuino3 Nano and power up the system.  While the Ubuntu files are loading LED 3 will be on and LED 4 will flash.  When the load is finished both LED 3 and LED 4 will blink in unison.

8) Turn off the pcDuino3 Nano, remove the sd card and turn it back on.  It should boot into the updated root file system.

Monday, December 22, 2014

pcDuino3 Nano - Adding a SATA Disk - Connecting the Drive

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

One of the things that drew me to the pcDuino3 Nano as a replacement for my home NAS system was the ability to connect a SATA disk to it.  The pcDuino3 and pcDuino3 Nano both have a SATA host port and a 5v power connector.  The 5v power connector limits you to 2.5” SATA drives.

pcDuino3NanoSATACircle

My original plan was to use a SATA dock to house and power the drive.  However, this didn’t work out as the pcDuino3 Nano has a SATA host port which is a different connector than an eSATA port.  This left me with a problem as I was using a 3.5” SATA drive which requires 12v and 5v and the pcDuino3 Nano only supplies 5v.  I overcame this problem by using a cable with a SATA power connector on one end and a 4 pin molex connector on the other.  This allows a 3.5” SATA drive to be powered from an ATX power supply or anything with a 4 pin molex connector with 12v and 5v. 

In my case I had a power adapter that supplied both voltages and by cutting off the original power connector and replacing it with a 4 pin molex male connector I was able to supply power to the disk drive.  While I was at it I cut off a USB micro b connector from a wall wart and connected that to the 5v lead to power the pcDuino3 Nano.

As shown in the picture below I used an old external USB drive enclosure for the drive.

Setup

After checking all the connections I plugged in the power adapter and booted the pcDuino3 Nano.

Sunday, December 21, 2014

pcDuino3 Nano - Creating a Bootable SD Card from NAND

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

The pcDuino family of systems can boot from the onboard NAND storage or from an SD card.  There are reasons for why you may want to boot from and SD card rather than NAND.  One significant reason is that you may need more than 4 GB of storage for the root file system on your system which exceeds the amount of NAND.

One of the very nice value added features that pcDuino provides is a utility that allows you to copy the kernel and operating system files to an SD card which is bootable.  The utility is part of the board-config.sh script which can be run from a terminal window using the sudo board-config.sh command and then following the prompts.

The process also includes instructions for expanding the root file system so that you can access the additional storage capacity of your SD card.

pcDuino3 Nano - Ubuntu Updates

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

Now that we have completed the kernel upgrade the next step is to download and apply Ubuntu upgrades.  You may have caught that the date in the filename of the Ubuntu image was August 7, 2014.  That means that any updates that have been made available for Ubuntu since that time need to be applied to the system.

Ubuntu components are updated on an ongoing basis and this process can be used to update them on your system even if you haven’t updated the kernel.

Note

There is a lot of good information on www.pcduino.com.  On this topic you should check out the blog post Chapter 1: Hardware and Software Introductions of pcDuino.

You will need to be connected to the Internet for this process.

1) From a terminal window (or the console connection if you have one) you type in the sudo apt-get update.  If you get back a long stream of messages connecting to websites and downloading data as shown below that everything is working correctly.

ubuntu@ubuntu:~$ sudo apt-get update
Ign
http://ppa.launchpad.net precise InRelease
Ign
http://ports.ubuntu.com precise InRelease
Ign
http://ports.ubuntu.com precise-security InRelease
Ign
http://ports.ubuntu.com precise-updates InRelease
Hit
http://ppa.launchpad.net precise Release.gpg
Hit
http://ports.ubuntu.com precise Release.gpg
Get:1
http://ports.ubuntu.com precise-security Release.gpg [198 B]
Get:2
http://ports.ubuntu.com precise-updates Release.gpg [198 B]
Hit
http://ppa.launchpad.net precise Release

<messages removed to save space>

Fetched 396 B in 8s (49 B/s)
Reading package lists... Done
W: Conflicting distribution:
http://www.wiimu.com pcduino Release (expected pcduino but got )

The last line you get is warning that one of the repositories isn’t configured correctly this isn’t a fatal error and the process completes.

If you get back a slow stream of message that start with Err you are most likely not connected to the Internet.

ubuntu@ubuntu:~$ sudo apt-get update
Err
http://www.wiimu.com pcduino InRelease

Err http://ppa.launchpad.net precise InRelease

Err http://ports.ubuntu.com precise InRelease

Err http://www.wiimu.com pcduino Release.gpg
  Temporary failure resolving 'www.wiimu.com'
Err
http://ppa.launchpad.net precise Release.gpg
  Temporary failure resolving 'ppa.launchpad.net'
Err
http://ports.ubuntu.com precise-security InRelease

^C

 

Confirming Internet Connectivity

You can confirm Internet connectivity using the ping command as shown below.  If you get a series or replies you are connected to the Internet.

ubuntu@ubuntu:~$ ping -c 5 www.google.com
PING www.google.com (74.125.196.106) 56(84) bytes of data.
64 bytes from yk-in-f106.1e100.net (74.125.196.106): icmp_req=1 ttl=246 time=24.0 ms
64 bytes from yk-in-f106.1e100.net (74.125.196.106): icmp_req=2 ttl=246 time=27.0 ms
64 bytes from yk-in-f106.1e100.net (74.125.196.106): icmp_req=3 ttl=246 time=25.2 ms
64 bytes from yk-in-f106.1e100.net (74.125.196.106): icmp_req=4 ttl=246 time=25.6 ms
64 bytes from yk-in-f106.1e100.net (74.125.196.106): icmp_req=5 ttl=246 time=24.6 ms

--- www.google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 24.003/25.340/27.070/1.039 ms

If the system appears to hang and eventually comes back as follows you do not have Internet connectivity.

ubuntu@ubuntu:~$ ping -c 5 www.google.com
ping: unknown host
www.google.com

 
2) The update phase updates the list of current software from the to your computer but doesn’t apply any of the updates.  The next step sudo apt-get upgrade constructs a list of the packages that need updating and prompts you to confirm that you want to continue.  If you type a return or Y the process will continue.  If you type an n the process will stop without applying any updates.
 

ubuntu@ubuntu:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
  libgrip0
The following packages will be upgraded:
  alsa-base alsa-utils apt apt-transport-https apt-utils base-files bash bc
  binutils bsdutils busybox-initramfs ca-certificates chromium-browser

<messages removed to save space>

  xserver-xorg-video-all xserver-xorg-video-nouveau
275 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Need to get 216 MB of archives.
After this operation, 33.8 MB of additional disk space will be used.
Do you want to continue [Y/n]?

Once you continue the system will download all the updates and apply them on your system.  This process can take quite a bit of time.

<messages removed to save space>

Installing new version of config file /etc/pam.d/lightdm-autologin ...

Configuration file `/etc/init/lightdm.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
The default action is to keep your current version.
*** lightdm.conf (Y/I/N/O/D/Z) [default=N] ?
Setting up lightdm-gtk-greeter (1.1.5-0ubuntu1.1) ...
Setting up openjdk-6-jre-lib (6b33-1.13.5-1ubuntu0.12.04) ...

<messages removed to save space>

Installing new version of config file /etc/rsyslog.conf ...
rsyslog stop/waiting
rsyslog start/running, process 12800
Setting up ifupdown (0.7~beta2ubuntu11.1) ...
Installing new version of config file /etc/init/network-interface.conf ...
Setting up network-manager-gnome (0.9.4.1-0ubuntu2.3) ...
Setting up resolvconf (1.63ubuntu16) ...
Installing new version of config file /etc/ppp/ip-down.d/000resolvconf ...
Installing new version of config file /etc/ppp/ip-up.d/000resolvconf ...
Setting up ubuntu-minimal (1.267.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for libgdk-pixbuf2.0-0 ...
Processing triggers for initramfs-tools ...
Processing triggers for resolvconf ...
ubuntu@ubuntu:~$

When you get back to the prompt all the updates have been applied.

Saturday, December 20, 2014

pcDuino3 Nano - Kernel Upgrade

This is the first of a series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

When I booted the fresh out of the box pcDuino3 Nano the kernel it booted from NAND was built on 10-15-2014. A check of the pcDuino3 Nano download page on the LinkSprite website showed that there was a more current version built on 12-5-2014.

I checked the version of the kernel running as shown below:

root@ubuntu:~# uname -a
Linux ubuntu 3.4.79+ #5 SMP PREEMPT Wed Oct 15 14:06:46 CST 2014 armv7l armv7l armv7l GNU/Linux
root@ubuntu:~#

The new kernel resolved the Aurduino-ish IDE corruption issue due to a serial port bug.  I figured before I got started with anything I would upgrade to the latest kernel.

On the pcDuino family of systems there are two methods for upgrading the software running from NAND.

  1. You can use the LiveSuit utility which loads software from a windows computer over usb.
  2. You can use the PhoenixCard utility which writes a specially formatted sd card.  This card is inserted in the system and when it is powered up it loads the new kernel.

I chose to use PhoenixCard. 

Note: I have a USB TTL cable connected to the console pins or the pcDuino3 Nano.  While this isn’t a requirement to complete this process it helps to be able to see the messages as the print.

image

1) The first step was to download the kernel image and the Ubuntu image which is done from the pcDuino3 Nano download page.  You also need to download a copy of PhoenixCard.

The version of PhoenixCard, Phoenix_V309, that is on the pcDuino3 Nano download page was flagged by Norton Internet security as a problem.  As a result I ended up using PhoenixCard_v310_20130618 which I found via Google here: https://drive.google.com/file/d/0B38hUt6ypQXDVTB6cWJXZ3ZGNkE/edit?usp=sharing

Save the files on your system.

image

2) Extract PhoenixCard and run PhoenixCard.exe.

image

3) You will get prompted to allow the program from an unknown publisher to make changes to your system.  You will need to say yes nd you will end up in PhoenixCard 3.10. PhoenixCard does an update check which starts out in Chinese but ends with a window in English.

image

4) Click on the “Img File” button and select “cduino3_nano_a20_kernel_livesuit_20141205.img”. 

image

5) Check to make sure the disk in the disk window is correct and select “Burn”.  After the burn completes you will see the following messages in the Option window. 

  • There is a note on the pcDuino3 Nano download page that says with some internal readers you may be a “Card Preprocess Failed !1012” due to the fact that they cannot write a partition table.
  • I ran into an interesting problem when my sd card’s lock tab ended up in the locked position.  PhoenixCard would say it could format the card but the burn would fail.  If the burn fails check your lock tab.

image

6) Power off your pcDuino3 Nano and take the sd card out of your computer and put it into the pcDuino3 Nano’s sd slot.  Apply power to the pcDuino3 Nano. 

While the kernel is loading LED 4 will flash.  Once the load is complete it will turn off.  When it does turn off the pcDuino3 Nano and remove the sd card.

7) Next you need to extract the Ubuntu files from the archive and write them to an sd card. 

If you use the same sd card you used for the kernel load make sure you reformat the card before you write the ubuntu files to it

You can do this with the PhoenixCard utility or another sd card formatting utility.

image

8) Once the files have been written to the sd card take it out of your system and put it in the sd card slot in the pcDuino3 Nano and power up the system.  While the Ubuntu files are loading LED 3 will be on and LED 4 will flash.  When the load is finished both LED 3 and LED 4 will blink in unison.

9) Turn off the pcDuino3 Nano, remove the sd card and turn it back on.  It should boot into the updated kernel.

root@ubuntu:~# uname -a
Linux ubuntu 3.4.79+ #2 SMP PREEMPT Fri Dec 5 17:23:11 CST 2014 armv7l armv7l armv7l GNU/Linux
root@ubuntu:~#

Friday, December 19, 2014

pcDuino3 Nano

Thanks to the folks at LinkSprite a pcDuino3 Nano recently arrived in my mailbox.  The pcDuino3 is a later generation of the pcDuino which I got in March 2013.  I really enjoyed working with the original pcDuino.  I used it on in a number of projects which are documented in this blog

I found the pcDuino to be a usable computer with easy access to the basic hardware level.  Unlike some other similar systems you can  boot into a windowed environment and get very reasonable performance.

My positive experiences with the first pcDuino led me back to LinkSprite when I started looking for a  a new system to host my home network attach storage system.  The specifications for the pcDuino3 Nano sold me on it and I couldn’t wait to get my hands on one.

What I liked about the pcDuino3 Nano was that it has a decent amount of processing power, a SATA port, GB ethernet and at $39.99 a very attractive price.  Over the next week or so I plan to document my experiences putting this system through its paces and then setting up the NAS system.

pcDuino3Nanov2

The picture above is where I was about 10 minutes after unboxing the pcDuino3 Nano.  I had it plugged into my network and into a monitor with a keyboard, a mouse and a console cable.  I applied power and it booted me into Lubuntu 12.04.

I plan to post updates and tutorials on this project over the next several months.

More to follow…

Sunday, November 30, 2014

RFduino Bluetooth Low Energy Bicycle Speed Sensor

During October and November I worked on a project to build a Bluetooth low energy bicycle speed sensor and interface it with my Android tablet.  The project used a hall effect sensor and magnet to count the rotation of the wheel.  The hall effect sensor was fed into the RFduino which computed the time for a complete rotation of the wheel and then using a BLE notify fed the data to the tablet.

BLESpeedometer

In the picture below the RFduino is at the top of the picture.  The RFduino is covered by a blue and red led.  The blue led is to provide visible status when a device is connected to the speed sensor and the red led cycles on and off as the hall effect sensor is read.  Below the RFduino is an Adafruit CR2032 holder.  To the left of the CR2032 is the connector that the hall effect sensor plugs into and to the right is the on / off switch.

BLESpeedometerClose

On the tablet I developed an app that builds on the Interactive Bicycle Trainer that I developed last winter.  The tablet is fastened on the handle bars and the bike is put on the trainer with the front wheel raised so that the handle bars are able to be turned.  Using the speed sensor a virtual rider on the tablet moves along a roadway at a speed that depends on how fast you pedal.  Leveraging the rotational senor capabilities of the table turning the handle bars allows you to steer the virtual bike to avoid oil slicks that are on the road.

device-2014-12-19-215943

The RFduino sketch and the Android App are on GitHub in the digitalhack/dhRFduino repository.