Acqua technical documentation

Write on NAND memory with SAM-BA

Microchip SAM-BA is a software that provides an open set of tools for in-system programming of internal and external memories connected to Microchip 32-MCUs and MPUs. This article illustrates how to use it to transfer the at91bootstrap bootloader on NAND memory mounted on the Acqua SOM

In this article is used the command line version of SAM-BA version 3.5 that support the latest generations of Microchip MPUs.

Installing SAM-BA

Download the package from Microchip site:

mkdir acqua

Uncompress the tar.gz file:

tar xvf sam-ba_3.5-linux_x86_64.tar.gz

Move inside the new directory created by tar

cd sam-ba_3.5

Using SAM-BA

SAM-BA comunicates with MCU via the USB client port of Acqua. It can be used only when on the MPU is running RomBOOT. When the CPU is running Linux it is impossible to use SAM-BA to access the NAND memory.

RomBOOT is the first piece of code that runs on the SAMA5D3x MCU at startup. It is burned directly by the Microchip factory inside the ROM MPU.

At startup RomBOOT looks for a bootable code from any possible supported external memory, if nothing is available, it waits for any serial commands incoming from the USB device port or from the serial debug port. This is the way used by SAM-BA to talk with RomBOOT.

In case you want to program the NAND memory it is enought to remove the MicroSD from Acqua SOM and turn on the board.

Type this command on your Linux PC:

Bus 003 Device 076: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader

and a new serial device is available with the name /dev/ttyACM0:

[1123395.428292] cdc_acm 3-9:1.0: ttyACM0: USB ACM device
[1123404.688098] usb 3-9: USB disconnect, device number 74
[1126710.259644] usb 3-9: new high-speed USB device number 76 using xhci_hcd
[1126710.408128] usb 3-9: New USB device found, idVendor=03eb, idProduct=6124, bcdDevice= 1.10
[1126710.408135] usb 3-9: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[1126710.411176] cdc_acm 3-9:1.0: ttyACM0: USB ACM device   ...

ls -al /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 dic  6 18:02 /dev/ttyACM0

Examples to use SAM-BA from command line

Erase the whole NANDFLASH

sudo ./sam-ba -p usb -b sama5d3-xplained -a nandflash -c erase

Write the bootloader

sudo ./sam-ba -p usb -b sama5d3-xplained -a nandflash -c writeboot:at91bootstrap.bin

When a bootloader is loaded inside the NANDFLASH to have access again to the NANDFLASH via SAM-BA close the BOOT pin of Berta Board to GND to avoid that At91bootstrap starts.

Write to memory from a file

-c write:<filename>:[<addr>]

Examples: write and verify at91bootstrap.bin at begin of NANDFLASH

sudo ./sam-ba -p usb -b sama5d3-xplained -a nandflash -c write:at91bootstrap.bin   
sudo ./sam-ba -p usb -b sama5d3-xplained -a nandflash -c verify:at91bootstrap.bin

Read memory to file

Read the whole NANDFLASH content and save in in a file called firmware.bin

sudo ./sam-ba -p usb -b sama5d3-xplained -a nandflash -c read:firmware.bin 

The general format of -c read command is:

-c read:<filename>:[<addr>]:[<length>]

for example:

-c read:firmware.bin              read all to firmware.bin
-c read:firmware.bin:0x1000       read from 0x1000 to end into firmware.bin
-c read:firmware.bin:0x1000:1024  read 1024 bytes from 0x1000 into firmware.bin
-c read:firmware.bin::1024        read 1024 bytes from start of memory into firmware.bin

Verify memory from a file

-c verify:<filename>:[<addr>]


verify:firmware.bin         verify that start of memory matches firmware.bin
verify:firmware.bin:0x1000  verify that memory at offset 0x1000 matches firmware.bin

To generate different size sample files use these examples:

dd bs=1K count=64  < /dev/urandom > test64KB.bin
dd bs=1M count=16  < /dev/urandom > test16MB.bin
dd bs=1M count=64  < /dev/urandom > test64MB.bin
dd bs=1M count=128 < /dev/urandom > test128MB.bin
dd bs=1M count=256 < /dev/urandom > test256MB.bin

Using SAM-BA with QML script files

SAM-BA can execute scripts written in QML to do automaticaly complex functions.

With the following QML script for example it is possible to write and verify at91bootloader on the NANDFLASH.

import SAMBA 3.5
import SAMBA.Connection.Serial 3.5
import SAMBA.Device.SAMA5D3 3.5

SerialConnection {
    device: SAMA5D3Xplained {

    onConnectionOpened: {
        // initialize Low-Level applet

        // initialize NAND flash applet

        // erase all memory
        applet.erase(0, applet.memorySize)

        // write file
        applet.write(0x000000, "at91bootstrap.bin", true)

        // verify file
        applet.verify(0x00000, "at91bootstrap.bin", true)

save it in a file called for example mytest.qml then lauch it by typing:

sudo ./sam-ba -x mytest.qml


Sergio Tanzilli
Systems designer, webmaster of and founder of Acme Systems srl

Personal email:
Web pages: ---
Github repositories: ---
Telegram group dedicated to the Acme Systems boards:

Acqua technical documentation