DNP5370

Purpose
Back to User:Mael

The purpose of this webpage is not to explain in details how does linux work, which is already documented everywhere on the web, but to give a small survivor kit to be able to make a new customized image for the µClinux target dnp5370, or to maintain it after a wrong manipulation (erasing of flash memory for example).

As an example, and since my work is on that king of target, I will present the DNP5370 from SSV vendor. This is a powerful and size optimized target, usefull for my other UAV's works, but it has several problems. When it comes from the supplier, the default configuration is made for webserver, and not at all for quick response embedded controlling system: For those 2 reasons, and also to keep an up to dated version of kernel and file system, we need to make a new target.
 * The mutex is too long, when a process takes it the next kernel switch can't happen before 20 ms, even if the process activity goes to "sleep",
 * The use of the old "can4linux" module integrated to the target leads to a dramatic kernel panic, and freezes.

The things I describe here comes from documentation over internet, mainly from the official Blackfin uClinux website. I'll add as much links as possible, but this page is mainly dedicated to dnp5370.

The study is done on the dedicated tool for µClinux applications: Buildroot, which will allow us to build:
 * A new Bootloader to program and start the target,
 * A new kernel, optimized with only the functions we need on our application,
 * A new filesystem where the application and dependencies could already be present.

The data and howto described here comes from many sources, including:
 * : The complete µClinux reference website

Prerequisites
Before we start, we have to get several tools optimized for blackfin. Note that the common tools won't work for a blackfin target, we need to use those that are optimized (and patched) for Blackfin.

So we need :
 * a toolchain, since we build a kernel and tools for a target which is not the host computer. So the generic gcc compiler won't work:
 * a uClibc library, that can be found at the same location that the toolchain. Both are mandatory:
 * a linux kernel distribution, blackfin dedicated:
 * a buildroot tool, a µClinux builder patched for Blackfin target. Note that this one comes with an integrated linux kernel directory in it, that can be used directly:
 * a bootloader, here u-boot:
 * a ftp server

Then you need a computer using linux, a powerful is better since compilation is pretty long. Explanation are based on Ubuntu commands. The installation steps are described in the installation files for each tool, and present no difficulties.

To be able to use all the configuration views, several other small tools are required : sudo apt-get install qt4-dev-tools

sudo apt-get install subversion

sudo apt-get install libncurses5-dev

sudo apt-get install gawk

On a x64 system :

sudo apt-get install lib32z1

Installation
Installation of components is not complicated, but requires rigour.

The toolchain
First we must ensure that we have downloaded both the compiler and libraries: where "xx" is the current value of the tool and library.
 * blackfin-toolchain-20xx
 * blackfin-toolchain-uclibc-full-20xx

Once unpacked, the folder: "/opt/uClinux" is created. The compiler and libraries are unpacked in this folder.

The toolchain can theorically be used anywhere in the filetree, but based on my own experiment it works rather better if copied in the linux folder /opt. Open a terminal in your unpacked folder "/opt" and (ubuntu version): sudo cp -r /opt/uClinux /opt

cd /opt

sudo chmod -r 777 uClinux

Last point, the compiler executables have to be exported (permanently) in the user PATH. The PATH has to be updated for each user.

To do that, in the user folder (/home/username/) edit the ".bashrc" file. At the end of the file add both lines : PATH=$PATH:/opt/uClinux/ /bin:/opt/uClinux//bin export PATH

NB: the .bashrc is a hidden file. The modification is taken into account at next user connection.

The Buildroot
Installation of buildroot is easier. First we unpack the content of the archive anywhere, there are no particular requirements on the buildroot location. The only thing to check is the size available, since the Buildroot folder could grow very quickly (ensure at least 5 Go).

Then, the following commands will be used: make xconfig make busybox-xconfig make linux-xconfig make make help
 * To call the editing window of the distribution using qt librairies:
 * To call the editing window of the busybox using qt librairies:
 * To call the editing window of the kernel using qt librairies:
 * To build everything:
 * To see all other commands (help section of the make command)

!! To avoid the "missing shadow.h" error, it is mandatory to remove the option *** in the busybox menuconfig, at \Login managment. !!

The UBOOT
I use the uBoot compiler, which is the one provided with the target. But this one is too old to be able to use new uClinux images, so a new version of uBoot is also required. Before compiling a new bootloader for the DNP_5370 target, it is mandatory to edit first the file dnp5370.h in the directory : u-boot-2012.07-rc2-2012R2-RC3/include/configs

The file's content is available inside the link.

To build the release, go in the uboot source and hit : make DNP5370_config

make

The tools
In this chapter I define the tools we will need to access the device. We need :
 * A serial port (U-Boot functions, images download, etc.)
 * A Tftp protocol manager (files download other IP)
 * A Jtag probe, for device backup when everything goes wrong
 * An Ethernet connection, to chek the device after complete programmation.

Using serial port
The programmation of dnp5370 device is performed using the serial RS232 port. To use this port I work with GTKTERM, a serial terminal emulator. To install it, hit : sudo apt-get install gtkterm

Then to use it, hit : sudo gtkterm

It is mandatory to be a SU to use it, since only SU can use USB / serial converter. Then we configure the tool :
 * /dev/ttyUSB0
 * Baudrate 115200
 * Parity : none
 * Bits : 8
 * Stop bit : 1

The tftp protocol
The tftp protocol, using TCP/IP to transfert easily data from a computer to the target, needs to install tftpd : sudo apt-get install tftpd

Then we have to create a configuration file in /etc/xinetd.d/tftp, with the following content : service tftp {    protocol        = udp port           = 69 socket_type    = dgram wait           = yes user           = nobody server         = /usr/sbin/in.tftpd server_args    = /tftpboot disable        = no }

And the tftp folder : sudo mkdir /tftpboot sudo chmod -R 777 /tftpboot sudo chown -R nobody /tftpboot

Then we can restart the configuration file in the xinetd server : sudo /etc/init.d/xinetd reload

And finally strat / restart the xinetd server : sudo /etc/init.d/xinetd start

or in case of failure : sudo /etc/init.d/xinetd restart

JTAG
If something goes wrong during an attempt to replace the u-boot already installed, and you can be sure that something will go wrong, you need to restore the previous configuration. That means basically that you have to load the last working u-boot version you have (normally the one given by SSV in the sk28 kit).


 * How to know that u-boot is dead?
 * The 3 LED flashes together at about 1 Hz, with a 25% on cyclical rate. And when you attempt to communicate with the chip using either IP link or RS232, nothing happens. That means it is dead... But no panic, here is the solution :

The best way to recover it is to use a JTAG emulator, for example gnICE+. For 100 Euros, it is a good investment. No need to install anything, except the toolchain (that you should already have installed on your host). The JTAG use two programs :
 * bfin-gdbproxy : used for debugging purpose,
 * bfin-jtag : used for memory programming

I will describe here how to program memory using the bfin-jtag function on an Ubuntu host with the last available blackfin toolchain installed and exported in the .bashrc file.

First, buy the gnICE+ device (or any JTAG probe that is supported for Blackfin, but the gnICE or gnICE+ from Bluetechnix are the most commonly used). The JTAG device can be connected to the host using a simple USB port (USB 2.0).
 * >Check for the driver installation< **

Then, open a terminal in your tftp directory, where you should have copied all the [u-boot.bin] files that you tried to program on the chip. It is the better place to have all the programs together.

Switch to a root console, since the USB connection will requires admin rights : host> sudo -s password: **** host#

Then open the jtag connection :

host# bfin-jtag -q

This should start the jtag environment:

jtag>

To connect the target, several steps :

jtag> cable gnICE+ jtag> detect jtag> initbus bf53x

The dnp5370 is not available in the target recognized by gnICE+, so we use the generic configuration for bf53x family.

Then the following sequence will copy the u-boot.bin file in the memory of the target.

jtag> detectflash 0x20000000 jtag> endian little jtag> flashmem 0x20000000 u-boot.bin jtag> instruction BYPASS jtag> shift ir jtag> quit

Note that you can also use a path to the file if it is not in the tftpboot directory, or if you have no tftpboot directory:

jtag> flashmem 0x20000000 /somewhere/something.bin

Upload the bootloader
"Well, first step... Erase the boot part and all the chip memory.

You kidding me, right?"

Upload the uImage file (ie the kernel itself)
Once the device started, with the serial emulator, hit  to reach the U-Boot command line. Then, to load the uImage file in the device, we use the command : tftpboot 0x1000000 192.168.0.1:uImage

In this command line, the [0x1000000] address is the address of the file in the device memory. The IP address is the one I use for the computer, since the device default address is 192.168.0.126.