How to make a backup of DVRPTR-NET bootable microSD

How to make a backup of DVRPTR-NET bootable microSD
This article illustrates how to make a backup of your DVRPTR-NET bootable microSD using
an Ubuntu Linux PC.
Unfortunately I didn't find an easy way to do a copy using Windows because DVRPTR-NET
uses an ext filesystems unsupported by Windows. In this case you could use a virtual machine
using SunVirtual Box.
microSD to microSD copy
Insert the master microSD in your Linux PC. Three new folders will appear on your desktop:
?
?
?
kernel
rootfs
data
Remove the target microSD and insert it again. Three new folders will appear on your
desktop:
?
?
?
kernel_
rootfs_
data_
Open a terminal session on your PC and type:
$
$
$
$
$
$
$
sudo
sudo
sudo
sync
sudo
sudo
sudo
cp -rp /media/kernel/. /media/kernel_/.
cp -rp /media/rootfs/. /media/rootfs_/.
cp -rp /media/data/. /media/data_/.
umount /media/kernel_
umount /media/rootfs_
umount /media/data_
microSD to tar file copy
This method is useful if you want to have a snapshot of your microSD contents on your hard
disk to use as master to create new copy.
DG1HT
Insert the master microSD in your Linux PC. Three new folders will appear on your desktop:
?
?
?
kernel
rootfs
data
Open a terminal session and type:
$ cd /media/kernel
$ sudo tar -cvjSf ../kernel.tar.bz2 .
...
$ cd /media/rootfs
$ sudo tar -cvjSf ../rootfs.tar.bz2 .
...
$ cd /media/data
$ sudo tar -cvjSf ../data.tar.bz2 .
...
The options mean:
?
?
?
?
?
-c create a new archive
-v verbosely list files processed
-j filter the archive through bzip2
-S handle sparse files efficiently
-f use archive file or device ARCHIVE
On the /media directory will appear the new three tarbal files:
?
?
?
kernel.tar.bz2
rootfs.tar.bz2
data.tar.bz2
usable as master for the microSD clone.
tar file to microSD copy
Partition and format a new microSD following the instruction on this article:
Be sure that the three new partitions are mounted and visible:
$ ls -al /media
total 170120
drwxr-xr-x 5 root
drwxr-xr-x 22 root
drwxr-xr-x 3 root
-rw-r--r-- 1 root
drwx------ 2 root
-rw-r--r-- 1 root
drwxr-xr-x 21 root
-rw-r--r-- 1 root
root
root
root
root
root
root
root
root
4096
4096
4096
137
16384
1797040
4096
172364479
2011 -08-16
2011 -08-16
2011 -07-13
2011 -08-16
1970 -01-01
2011 -08-16
2010 -09-22
2011 -08-16
12:23
09:12
18:08
12:23
01:00
12:05
16:17
12:09
.
..
data
data.tar.bz2
kernel
kernel.tar.b z2
rootfs
rootfs.tar.bz2
Be sure that kernel, rootfs and data are directory and not files.
Type:
DG1HT
$ cd /media
$ sudo tar -xvjpSf kernel.tar.bz2 -C /media/kernel
...
$ sudo tar -xvjpSf rootfs.tar.bz2 -C /media/rootfs
...
$ sudo tar -xvjpSf data.tar.bz2 -C /media/data
...
$ sync
$ sudo umount /media/kernel
$ sudo umount /media/rootfs
$ sudo umount /media/data
MicroSD partitioning
The bootable microSD currently provided by Acme with Debian preinstalled is organized in 4
partitions:
Format
Label Size
type
Mount point
1 FAT16
kernel 32MB /media/mmc_p1
2 EXT4
3 EXT4
4 SWAP
rootfs 800MB /
data 800MB /media/data
swap 128MB
Description
Linux Kernel image and some optional file used
by the bootloader at startup
Linux root filesystem
User data
Available for memory swap
Brand new microSDs tipically are formatted with a unique big FAT partition so the operation
to do are:
?
?
?
Delete the factory default big FAT partition
Create the four partition requested by the DVRPTR-NET
Copy the file inside the new partitions
Let's see how to do using an Ubuntu Linux PC.
We have to use a Linuc PC because unfortunately on Windows PC it is impossible to manage
the Linux filesystems ext4 e swap using the standard tools.
Insert the microSD memory card in your Linux PC through a card adapter and start a terminal
session.
Type:
$ dmesg
...
[13736.699438]
GB/1.86 GiB)
[13736.700061]
[13736.700067]
[13736.700072]
[13736.702662]
[13736.702671]
[13736.709301]
[13736.709309]
$
sd 15:0:0:0: [sdb] 3911680 512 -byte logical blocks: (2.00
sd 15:0:0:0:
sd 15:0:0:0:
sd 15:0:0:0:
sd 15:0:0:0:
sdb: sdb1
sd 15:0:0:0:
sd 15:0:0:0:
[sdb]
[sdb]
[sdb]
[sdb]
Write Protect is off
Mode Sense: 4b 00 00 08
Assuming drive cache: write through
As suming drive cache: write through
[sdb] Assuming drive cache: write through
[sdb] Attached SCSI removable disk
DG1HT
This indicates that the unique FAT16 partition of microSD is allocated as /dev/sdb1 disk and
mounted on /media/.
It is very important to well understand which is the device allocated for the microSD (in this
case /dev/sdb ) to avoid to erase your main hard disk !!
Install GParted
GParted is a graphical utility to create partition on any memory support like hard-disk, pen
drive and SD cards. To install it use Synaptic (System -> Administration -> Synaptic Package
Manager) and install gparted.
When installed launch it from System -> Administraion -> Gparted menu.
Prepare the microSD
The following operations will destroy all the data contained on microSD so please be sure that
you don't have any useful file on your microSD card.
Select /dev/sdb device checking if the size match with the size of your microSD then the
/dev/sdb1 partition on it and unmount it using right click -> unmount.
Delete it using right click -> delete.
DG1HT
Create a new partition using the command right click -> New with these parameters:
?
?
?
?
New size: 32MB
File system: fat16
Label: kernel
Leave all the other fields at default values
Create a new partition using the command right click -> New with these parameters:
?
New size: 800MB
or more if you intend to install a lot of Linux packages
?
?
?
File system: ext4
Label: rootfs
Leave all the other fields at default values
DG1HT
Create a new partition using the command right click -> New with these parameters:
?
?
?
?
File system: ext4
Free space following: 128MB
Label: data
Leave all the other fields at default values
Create a new partition using the command right click - New with these parameters:
?
?
?
?
?
New size: 128MB
File system: linux-swap
Label: swap
Leave all the other fields at default values
Click on the green sign to apply all the operations and exit from Gparted.
DG1HT
Remove the microSD, wait about 10 sec and insert again. Tree new partitions will be mounted
automatically on:
?
?
?
/media/kernel
/media/rootfs
/media/data
Now proceed to fill these partitions with the contents required by the DVRPTR-NET.
Kernel uImage and rootfs contents
Download the last shapshot from the binary repository then:
Copy the Linux Kernel uImage and parameters files in /media/kernel.
$ cp uImage /media/kernel
$ cp machtype.txt /media/kernel
$ cp cmdline.txt /media/kernel
Untar and copy the rootfs contens in /media/rootfs:
$ sudo tar xvjpSf rootfs.tar.bz2 -C /media/rootfs
Syncronize the microSD contents:
$ sync
Umount all the microSD partition from your PC:
$ sudo umount /media/kernel
$ sudo umount /media/rootfs
$ sudo umount /media/data
Remove the microSD, insert it in your DVRPTR-NET and try to boot it.
DG1HT
How to use the SPI bus
The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard that
operates in full duplex mode. Devices communicate in master/slave mode where the master
device initiates the data frame.
Multiple slave devices are allowed with individual slave select (chip select) lines. Sometimes
SPI is called a "four-wire" serial bus, contrasting with three-, two-, and one-wire serial buses.
Read more on Wikipedia.
This article is a just practical guide for how to use the SPI bus on the DVRPTR-NET. To have
a more in depth idea of how the SPI works under Linux please read the kernel documentation
on:
?
?
Kernel documentation of SPI
Kernel documentation of spidev
The signals required by a SPI bus are distributed on DVRPTR-NET and Daisy-1 connectors
in this way:
Function
DVRPTR-NET pin Daisy-1 pin
Signal
MOSI Master Output Slave Input J7.10
D7.2
MISO Master Input Slave Output J7.9
D7.3
J7.7
D7.4
SCLK Slave Clock
CS0 Chip Select 0
J7.8
D7.5
CS1 Chip Select 1
J7.19
D7.6
CS2 Chip Select 2
N.A.
D7.7
CS3 Chip Select 3
J7.27
D7.8
The signals CS0 to CS3 are called in SPI standards - "SS". With 4 SS signals it is possible to
wire up to 4 SPI slave devices.
Using the SPI from userspace
A driver called spidev is provided by the Linux Kernel to manage the SPI bus from user
space.
This driver is already enabled on the Kernel image provided by Acme on the standard
microSD but you have to register each bus line (from 0 to 3 from each CS line) on this file
board-dvrptr-net.c.
DG1HT
These are the lines to add:
static struct spi_board_info DVRPTR-NETg20_spi_devices[] = {
#if !defined(CONFIG_MMC_AT91)
{
.modalias
= "mtd_dataflash",
.chip_select
= 1,
.max_speed_hz
= 15 * 1000 * 1000,
.bus_num
= 0,
},
#endif
// First line to add
{
.modalias
= "spidev",
.chip_select
= 0,
.max_speed_hz
= 10 * 1000 * 1000,
.bus_num
= 1,
.mode = SPI_MODE_3,
},
{
.modalias
= "spidev",
.chip_select
= 1,
.max_speed_hz
= 10 * 1000 * 1000,
.bus_num
= 1,
.mode = SPI_MODE_3,
},
{
.modalias
= "spidev",
.chip_select
= 2,
.max_speed_hz
= 10 * 1000 * 1000,
.bus_num
= 1,
.mode = SPI_MODE_3,
},
{
.modalias
= "spidev",
.chip_select
= 3,
.max_speed_hz
= 10 * 1000 * 1000,
.bus_num
= 1,
.mode = SPI_MODE_3,
},
// Last line to add
};
To generate a new kernel image and use it on the DVRPTR-NET read this page: [Tag h1 not
found].
The field .mode set the clock signal line polarity and phase. To know more about it read here
and here.
The following symbols should be added to the Kernel config; using the make ARCH=arm
menuconfig you should enable:
CONFIG_SPI_SPIDEV=y
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_ATMEL=y
DG1HT
After a reboot of the DVRPTR-NET with the new image some new devices will appear on
/dev directory:
debarm:/# ls
crw------- 1
crw------- 1
crw------- 1
crw------- 1
/dev/spi*
root root
root root
root root
root root
-l
153,
153,
153,
153,
0
1
2
3
Feb
Feb
Feb
Feb
10
10
10
10
10:51
10:51
10:51
10:51
/dev/spidev1.0
/dev/spidev1.1
/dev/spidev1.2
/dev/spidev1.3
Some final consideration
As stated before the spi mode is an important parameter that should be trimmed according to
your slave device and in accompliance with the modes available here.
Now follow some graphs of the spidev behaviours captured with an oscilloscope.
In the following images the cyan trace is the SCLK signal, the yellow trace is MOSI signal
and at the end the green trace is n-th CS.
Spidev on chipselect 0
The trace below was captured using the following kernel definition:
{
.modalias
= "spidev",
.chip_select
= 0,
.max_speed_hz
= 1000000,
.bus_num
= 1,
.mode = SPI_MODE_3,
},
using the echo spi0 > /dev/spidev1.0 command as spidev writer.
Please note that the training char in the captured image is a carrier return introduced by echo.
DG1HT
Spidev on chipselect 1
The trace below was captured using the following kernel definition:
{
.modalias
= "spidev",
.chip_select
= 1,
.max_speed_hz
= 1000000,
.bus_num
= 1,
.mode = SPI_MODE_1,
},
using the echo test > /dev/spidev1.1 command as spidev writer.
Note that using a mode1 the behaviour of clock signal is different.
Spidev on chipselect 2
The trace below was captured using the following kernel definition:
{
.modalias
= "spidev",
.chip_select
= 2,
.max_speed_hz
= 1000000,
.bus_num
= 1,
.mode = SPI_MODE_3 | SPI_LSB_FIRST,
},
using the echo -n spi2 > /dev/spidev1.2 command as spidev writer.
DG1HT
Note that in this final capture the mode is the binary OR of more than one flag defined inside
spi.h kernel header
The captured traces show also that the byte-ordering is inverted due to SPI_LSB_FIRST flag
and also that only 4 char are sent on the bus due to the -n option of echo command that
supprime the carrier return.
Link utili
?
?
?
Wikipedia definition of SPI bus
Kernel documentation of SPI
Kernel documentation of spidev
How to use the I2C bus
I2C is a multi-master serial single-ended bus invented by Philips that is used to attach lowspeed peripherals to an embedded system. Since the mid 1990s, several competitors (e.g.,
Siemens AG (later Infineon Technologies AG), NEC, Texas Instruments, STMicroelectronics
(formerly SGS-Thomson), Motorola (later Freescale), Intersil, etc.) have brought I2C
products onto the market, which are fully compatible with the NXP (formerly Philips's
semiconductor division) I2C-system.
SMBus, defined by Intel in 1995, is a subset of I2C that defines the protocols more closely.
One purpose of SMBus is to promote robustness and interoperability. Accordingly, modern
I2C systems incorporate policies and rules from SMBus, sometimes supporting both I2C and
SMBus with minimal re-configuration required. (Read more on Wikipedia...).
DG1HT
This article is a just practical guide for to use the I2C bus on the DVRPTR-NET. To have a
more in depth idea of how the I2C works under Linux please read the Linux Kernel
documentation on:
?
Kernel documentation of I2C
Using i2c-tools
The faster way to do the first experiments with this board is by installing and using the i2ctools.
i2c-tools is a package contains a heterogeneous set of I2C tools for Linux such as:
?
?
?
?
?
a bus probing tool
a chip dumper
a register-level access helpers
an EEPROM decoding scripts
...and more
To install i2c-tools on the DVRPTR-NET just type:
debarm:~# apt-get update
debarm:~# apt-get install i2c-tools
Using i2cdetect
i2cdetect is an userspace program to scan an I2C bus for devices. It outputs a table with the
list of detected devices on the specified bus.
?
i2cdetect man page
Example:
debarm:~#
0 1
00:
10: -- -20: 20 -30: -- -40: -- -50: -- -60: -- -70: -- --
i2cdetect -y 0
2 3 4 5 6
-- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --
7
---------
8
--------
9
--------
a
--------
b
--------
c
--------
d
--------
e
--------
f
--------
In this case a device has been detected on address 20 hex.
Using i2cset
i2cset is a small helper program to set registers visible through the I2C bus.
?
i2cset man page
DG1HT
The following simple command writes the byte value 255 to the I2C device at address 20 hex
on the i2c bus 0 (/dev/i2c-0).
debarm:~# i2cset -y 0 0x20 255
If for example you are using a PCF8574 I2C I/O expander this command will set all the GPIO
lines to 1.
import smbus
import time
bus = smbus.SMBus(0)
for a in range(0,256):
bus.write_byte_data(0x20,0x00, a)
time.sleep(0.1)
C example
The following example sends a sequence of values from 0 to 255 to the PCF8574 I2C I/O
expander at address 0x20 in C language.
#include
#include
#include
#include
<stdio.h>
<fcntl.h>
<linux/i2c-dev.h>
<errno.h>
#define I2C_ADDR 0x20
int main (void) {
int value;
int fd;
fd = open("/dev/i2c-0", O_RDWR);
if (fd < 0) {
printf("Error opening file: %s \n", strerror(errno));
return 1;
}
if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0) {
printf("ioctl error: %s\n", strerror(errno));
return 1;
}
for (value=0; value<=255; value++) {
if (write(fd, &value, 1) != 1) {
printf("Error writing file: %s \n", strerror(errno));
}
usleep(100000);
}
return 0;
}
DG1HT
Write internal EEPROM
#include <avr/eeprom.h>
#DG1HT
struct settings_t
{
long time;
int analogVal;
float temp;
char name[50];
} settings;
void setup()
{
Serial.begin(115200);
// Set Struct variable
settings.time=100000;
settings.analogVal=analogRead(0);
settings.temp=23.15;
strcpy(settings.name,"Test EEPROM");
// Write configuration in EEPROM
eeprom_write_block ((const void*)&settings, (void*)0, sizeof(settings));
Serial.println("EEPROM written with this configuration:" );
Serial.print("name: ");
Serial.println(settings.name);
Serial.print("time: ");
Serial.println(settings.time);
Serial.print("analogVal: ");
Serial.println(settings.analogVal);
Serial.print("temp: ");
Serial.println(settings.temp);
}
void loop()
{
}
DG1HT
Read internal EEPROM
#include <avr/eeprom.h>
#DG1HT
struct settings_t
{
long time;
int analogVal;
float temp;
char name[50];
} settings;
void setup()
{
Serial.begin(115200);
// Read stored configuration
eeprom_read_block ((void*)&settings, (void*)0, sizeof(settings));
Serial.println("Read configuration:" );
Serial.print("name: ");
Serial.println(settings.name);
Serial.print("time: ");
Serial.println(settings.time);
Serial.print("analogVal: ");
Serial.println(settings.analogVal);
Serial.print("temp: ");
Serial.println(settings.temp);
}
void loop()
{
}
Related links
?
Wikipedia EEPROM definition
DG1HT
Debug Port Interface (DPI)
DPI is an interface designed to access to the DVRPTR-NET Debug port using a normal USB
port of your PC
DG1HT
DPI is based on the popular FTDI FT232 chip. The relative driver is almost ever already
installed on any PC either Window or Linux. If not get it from http://www.ftdi-chip.com.
To use the DPI you need a terminal emulator program that is an utility that can send and
receive characters via a serial port.
Serial terminal emulator on Windows PC
By default Windows provide an utility called HyperTerminal that is usable with DPI but we
suggest to install a free utility called putty because it can works also as a SSH remote
terminal useful to have access to the DVRPTR-NET command prompt via LAN
Download putty it from this link.
It doesn't need to be installed, just download and run it.
At startup you have to specify:
?
?
?
Connection type: Serial
Serial line: COMx where x is the serial port allocated by the ftdi device driver
Speed: 115200
Save this configuration and press the Open button to continue.
You will reveice a request of login end password from the DVRPTR-NET G20. Use these
credentials:
DG1HT
Login: root
Password: 10011001
DVRPTR-NET:/#
Serial terminal emulator on Linux PC
A simple terminal emulator available on Linux is minicom.
On Ubuntu distribution you can install it using Synaptic or apt-get install by typing:
~$ apt-get install minicom
After installation run it by typing:
~$ minicom
Type CTRL-A followed by O to show the configuration panel. Then select Serial port setup
and access to the serial port configuration.
Se the port as shown below:
Welcome to minicom 2.4
OPTI+----------------------------------------------------------------------+
Comp| A Serial Device
: /dev/ttyUSB0
|
Port| B - Lockfile Location
: /var/lock
|
| C Callin Program
:
|
Pres| D - Callout Program
:
|
| E Bps/Par/Bits
: 115200 8N1
|
| F - Hardware Flow Control : No
|
| G - Software Flow Control : No
|
|
|
|
Change which setting?
|
+----------------------------------------------------------------------+
| Screen and keyboard
|
| Save setup as dfl
|
| Save setup as..
|
| Exit
|
+-------------------------- +
Type ESC the select Save setup as dfl. Then ESC again. Now pressing Enter you could
have access to the DVRPTR-NET login:
Login: root
Password: 10011001
DVRPTR-NET:/#
DG1HT