USB-A9G20-LPW Software

From CALAO Systems Wiki
Jump to: navigation, search

How to use buildroot

How to build the binaries for the USB-A9G20-LPW from buildroot

  • Download the lastest buildroot release available here
  • Untar and uncompress the buildroot-2012.0x.tar.bz2 package on your host (tar -xvjf buildroot-2012.0x.tar.bz2)
  • Issue cd buildroot-2012.0x
  • Issue make calao_usb_a9g20_lpw_defconfig
  • Issue make 2>&1 | tee build.log to build the binaries for the USB-A9G20-LPW
Note: By default we use the toolchain provided by buildroot. If you want to use an external toolchain you can issue
make menuconfig and go to the Toolchain Menu in order to configure the path and prefix of your toolchain.

How to modify the barebox default config from buildroot

You can modify the default barebox settings by issuing the following command:
  • make barebox-menuconfig
From the menu you can add/remove features and then rebuild barebox by issuing the following command:
  • make
If you want to save your config file your can save by issuing the following command:
  • make savedefconfig

How to modify the linux kernel default config from buildroot

You can modify the default linux kernel settings by issuing the following command:
  • make linux-menuconfig
From the menu you can add/remove features and then re-build the linux kernel by issuing the following command:
  • make
If you want to save your config file your can save by issuing the following command:
  • make savedefconfig

How to install SAM-BA from buildroot

How to add your software application in buildroot

  • More info available at here

How to flash the USB-A9G20-LPW with the SAM-BA utility

  • Download the custom calao sam-ba utility available here
  • Untar and uncompress the sam-ba package on your host.
  • Setup your hardware
  1. Setup the jumper in order to put your USB-A9G20-LPW in "flashing mode"
  2. Plug the USB-A9G20-LPW in your host machine as shown below:
Note: Unlike the USB-A9G20, you don't need to plug in a usb cable in the mini-B USB connector to reflash the USB-A9G20-LPW


  • Issue sam-ba from the command line to start SAM-BA.
Note: Depending on your linux distro you should have to issue the following command in order to create a symlink to
/dev/ttyACM0: ln -s /dev/ttyACM0 /dev/ttyUSB0 
  • From the window below choose the usb-a9g20-lpw board and click on the Connect button.
  • Once sam-ba is loaded you should see the following window
  • Click on the Script File menu and click on Execute
  • Choose the usb-a9g20-lpw.tcl script in the calao directory.
  • When the usb-a9g20-lpw.tcl starts, SAM-BA will ask you to browse your home directory in order to find the at91 bootstrap loader binary.
  • Browse your home directory in order to load the nandflash_usb_a9g20-lpw.bin file.
Note: By default the usb-a9g20-lpw.tcl script will load the binaries from ~/buildroot/output/images/ 
- Nand Flash Mapping Table
NAND Offset Size Reserved for
0x00000 128KB at91bootstrap loader (nandflash_usb_a9g20_lpw.bin)
0x20000 256KB bootloader (barebox.bin)
0xA0000 128KB Device tree blob (usb_a9g20_lpw.dtb)
0xC0000 4MB Linux kernel image (default:zImage)
0x4C0000 120MB UBI rootfs (default:rootfs.ubifs)
  • After a while your board is re-flash
Note: You can edit the usb-a9g20-lpw.tcl script from the Script File menu in order to modify your default binaries directory.

How to use barebox

Introduction

Barebox (formerly known as u-boot-v2) is a bootloader that inherits the best of U-Boot and the Linux kernel: The size and look-and-feel of u-boot, with driver model and lots of design concepts from the kernel.

Start with barebox

Once your USB-A9G20-LPW re-flashed, you can plug in an ethernet cable on the RJ-45 connector and reset your board as shown below:

Then start a terminal program on your host (minicom for instance), setup your serial link with the following parameters: 115200,n,8,1.

In your terminal window you should see something similar to the information displayed below:

If you don't stop the auto countdown, you can notice barebox tries to boot from the network.

  • Issue a ctrl-c from your terminal to stop the network boot stage as it is not probably well configured.

How to install a UBI rootfs from barebox

Prepare the Flash before UBI rootfs install

The /dev/nand0.root partition can be attached to ubi using

  • ubiattach /dev/nand0.rootfs
NOTE: Before attaching the rootfs partition to ubi please erase it with erase /dev/nand0.rootfs

Create a volume on the UBI device

  • ubimkvol /dev/ubi0 root 0

Load a file from a tftp server

Setup a tftp server on your host and copy the UBI rootfs from ~/buildroot/output/images/ to your tftp directory.

Setup your network from barebox:

If you have a dhcp server available on your network you can see the network parameters by issuing the following command:

  • devinfo eth0

If you want to modify for example the serverip you have to issue the following command:

  • eth0.serverip=192.168.1.10

As your network setup is ok, you can load a file from barebox with the command below:

  • tftp zImage zImage

Issue ls and you should see your file in the / directory

Flash the UBI rootfs from barebox

The UBI volume can then be flashed with the command below:

  • tftp rootfs.ubifs /dev/ubi0.root

Save your network settings

From the barebox command line you can save your network settings by editing the config file in /env directory:

  • edit env/config
 env/config                <ctrl-d>: Save and quit <ctrl-c>: quit 
#!/bin/sh

# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
ip=dhcp-barebox
dhcp_vendor_id=barebox-usb-a9g20

# or set your networking parameters here
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
#eth0.serverip=a.b.c.d

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nand
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=nand
# can be either 'nfs', 'tftp', 'nor', 'nand' or empty
oftree_loc=none

Uncomment and setup your network parameters as below:

# or set your networking parameters here
eth0.ipaddr=192.168.1.100
eth0.netmask=255.255.255.0
eth0.gateway=192.168.1.10
eth0.serverip=192.168.1.10

Save your config file by issuing Ctrl-d

Now to save your config issue the following command :

  • saveenv

Modify the default boot sequence

By default barebox tries to boot from the network.Once you have flashed your kernel and your root filesystem in the Nand Flash memory you can boot from the NAND Flash.

Below the steps required to modify the default boot sequence (Boot from Nand Flash).

  • Stop the autoboot from your terminal

  • Edit the config file by issuing the following command edit env/config
 env/config                <ctrl-d>: Save and quit <ctrl-c>: quit 
#!/bin/sh
# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
# ip=dhcp-barebox
dhcp_vendor_id=barebox-usb-a9g20

# or set your networking parameters here
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
#eth0.serverip=a.b.c.d

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nfs
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=net
# can be either 'nfs', 'tftp', 'nor', 'nand' or empty
oftree_loc=none

# can be either 'jffs2' or 'ubifs'
rootfs_type=ubifs
  • replace ip by none & modify the kernel_loc, rootfs_loc by nand as shown below:

# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
# ip=dhcp-barebox
ip=none
dhcp_vendor_id=barebox-usb-a9g20

# or set your networking parameters here
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
#eth0.serverip=a.b.c.d

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nand
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=nand
# can be either 'nfs', 'tftp', 'nor', 'nand' or empty
oftree_loc=nand

# can be either 'jffs2' or 'ubifs'
rootfs_type=ubifs
rootfsimage=root.$rootfs_type

kernelimage=zImage
#kernelimage=uImage
#kernelimage=Image
#kernelimage=Image.lzo

Save your config file by issuing Ctrl-d

Note: If you built a linux kernel with DT, you should specify where your DT blob is located with oftree_loc

Now to save your config issue the following command :

  • saveenv

Issue reset in order to check your default boot sequence

  • reset

How to use the dfu

DFU for Device Firmware upgrade can be used to download and upload barebox, linux kernel and the rootfs to the USB-A9G20-LPW connected over USB.

Let's assume that you want to upgrade your kernel image from barebox.

  • Plug the USB-A9G20-LPW in your host machine as shown below:
  • During the boot, press the user push button of the USB-A9G20-LPW in order to start the DFU automatically.

Note: You can also start the dfu from the barebox command line by issuing the following command:dfu ${dfu_config} -P ${product_id} -V ${vendor_id}

  • Now from your host you can start dfu-util

Note: dfu-util can be installed on your host from buildroot or by downloading the package here.

  • From your host open a terminal window and issue the following command:
  • $sudo dfu-util -l (if you have installed dfu-util from buildroot issue cd ~/buildroot/output/host/usr/bin/ and then sudo ./dfu-util -l)
  • You should see the upgradable partition list
barebox@Calao USB-A9G20:/                                                                                                                
# dfu ${dfu_config} -P ${product_id} -V ${vendor_id}                                                                                     
dfu: register alt0(barebox) with device /dev/nand0.barebox.bb                                                                            
dfu: register alt1(kernel) with device /dev/nand0.kernel.bb                                                                              
dfu: register alt2(rootfs) with device /dev/nand0.rootfs.bb

Let's assume that you want to reflash your linux kernel

  • Issue the following command:

$sudo ./dfu-util -d 4321:1234 -a kernel -R -D ~/buildroot/output/images/zImage

$ sudo ./dfu-util -d 4321:1234 -a kernel -R -D ~/buildroot/output/images/zImage 
dfu-util 0.6

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY

Filter on vendor = 0x4321 product = 0x1234
Opening DFU capable USB device... ID 4321:1234
Run-time device DFU version 0100
Claiming USB DFU Runtime Interface...
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB...
Opening DFU USB Device...
Found Runtime: [4321:1234] devnum=0, cfg=1, intf=0, alt=1, name="kernel"
Claiming USB DFU Interface...
Setting Alternate Setting #1 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0100
Device returned transfer size 4096
No valid DFU suffix signature
Warning: File has no DFU suffix
bytes_per_hash=42475
Copying data from PC to DFU device
Starting download: [##################################################] finished!
state(2) = dfuIDLE, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode

Let's assume that you want to reflash your rootfs

  • Issue the following command:

$sudo ./dfu-util -d 4321:1234 -a rootfs -R -D ~/buildroot/output/images/rootfs.ubi

sudo ./dfu-util -d 4321:1234 -a rootfs -R -D ~/buildroot/output/images/rootfs.ubi
dfu-util 0.6

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2012 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY

Filter on vendor = 0x4321 product = 0x1234
Opening DFU capable USB device... ID 4321:1234
Run-time device DFU version 0100
Claiming USB DFU Runtime Interface...
Determining device status: state = appIDLE, status = 0
Device really in Runtime Mode, send DFU detach request...
Resetting USB...
Opening DFU USB Device...
Found Runtime: [4321:1234] devnum=0, cfg=1, intf=0, alt=2, name="rootfs"
Claiming USB DFU Interface...
Setting Alternate Setting #2 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0100
Device returned transfer size 4096
No valid DFU suffix signature
Warning: File has no DFU suffix
bytes_per_hash=62914
Copying data from PC to DFU device
Starting download: [##################################################] finished!
state(2) = dfuIDLE, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode
 Note: The rootfs.ubi is an image of the UBI rootfs and can be built from buildroot 

How to boot from nfs

When you are setting up your rootfs for your target, it can be interesting to use nfs.

Indeed when your ethernet is functional on your target you can easily mount a rootfs available on your host.

First setup an nfs server on your host. You will find a lot of interesting information about how to install an nfs server on your preferred linux distro in your documentation. Below the Howto for Ubuntu:

  • How to setup an NFS server here.

From your freshly reflashed USB-A9G20-LPW you should see the following trace:

# Clocks: CPU 180 MHz, master 90 MHz, main 12.000 MHz
registered netconsole as cs4
atmel_nand: Use On Flash BBT
NAND device: Manufacturer ID: 0x2c, Chip ID: 0xda (Micron NAND 256MiB 3,3V 8-bit)
Bad block table found at page 131008, version 0x01
Bad block table found at page 130944, version 0x01
nand_read_bbt: Bad block at 0x00860000
atmel_mci@mci0: registered as mci0
at91_udc@at91_udc0: at91_udc version 3 May 2006
Malloc space: 0x23b00000 -> 0x23efffff (size  4 MB)
Stack space : 0x23af8000 -> 0x23b00000 (size 32 kB)
envfs: wrong magic on /dev/env0
no valid environment found on /dev/env0. Using default environment
running /env/bin/init...
No USB Device cable plugged, normal boot

Hit any key to stop autoboot:  0
warning: No MAC address set. Using random address DA:2A:78:27:2E:52
phy0: Link is up - 100/Full
DHCP client bound to address 192.168.1.18

Filename './zImage'.
NFS failed: Interrupted system call

barebox@Calao USB-A9G20:/

Edit the env/config file by issuing the command below:

  • edit env/config

Replace ip=dhcp by ip= and if you don't have a dhcp server available on your network, you can setup the following variables:

  • eth0.ipaddr
  • eth0.serverip
  • eth0.netmask
  • eth0.gateway
  • eth0.ethaddr
#!/bin/sh

# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
#ip=dhcp-barebox
#dhcp_vendor_id=barebox-usb-a9g20
ip=
nfsroot=/home/user/nfs

# or set your networking parameters here
eth0.ipaddr=192.168.1.100
#eth0.netmask=255.255.255.0
#eth0.gateway=192.168.1.10
eth0.serverip=192.168.1.10

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=tftp
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=net
# can be either 'nfs', 'tftp', 'nor', 'nand' or empty
oftree_loc=none

# can be either 'jffs2' or 'ubifs'
rootfs_type=ubifs
rootfsimage=root.$rootfs_type

kernelimage=zImage
#kernelimage=uImage
#kernelimage=Image
#kernelimage=Image.lzo

nand_device=atmel_nand
nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
rootfs_mtdblock_nand=6

autoboot_timeout=3


bootargs="console=ttyS0,115200"

# set a fancy prompt (if support is compiled in)
PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m\n# "
# 

As you can notice above in the config file, the kernel image will be downloaded from the tftp server installed on your host. If you have flashed a kernel in the nand flash memory you can replace kernel_loc=tftp by kernel_loc=nand to check if everything is ok.

You can now save your file with ctrl-d and saveenv and reset your board.

 By default the path for nfs is .In the example above it has been replaced by /home/user/nfs 

You will find a lot of interesting information about how to install an tftp server on your preferred linux distro documentation.

Below the Howto for Ubuntu:

  • How to setup a tftp server here.

How to download a file from the serial port

If you want to download a file through the serial port you can issue the following command on your target:

  • loadb -f filename -c

From your host you can use for instance C-Kermit and issue the command below in order to send a file to your USB-A9G20-LPW:

~$ kermit
?SET SPEED has no effect without prior SET LINE
C-Kermit 8.0.211, 10 Apr 2004, for Linux
 Copyright (C) 1985, 2004,
  Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
Linux Kermit> send filename

Note: You should configure kermit by editing the kermrc file located in /etc/kermit/

Misc