High reliable boot up for SAMA5D3x-CM

1. Overview
This article shows you how to build a high reliable boot up for SAMA5D3x-CM. The set of patches adds redundant booting of U-BOOT and Kernel. Additionally 8-bit ECC is used for at91bootstrap, U-BOOT, Kernel image and RootFS. The UBIFS bitflip_threshold is set to 6. This means that if there are 6,7 or 8 bit flips per 512 bytes block, then the NAND page is marked for scrubbing.

2. Prerequisites

- a CPU Module SAMA5D3x-CM
- a Base board SAMA5D3x-MB
- A host machine running Linux for building

3. MTDs partitions
Because of the additionally images, the following MTD partitions are used:

0x00000000 0x00040000 At91 bootstrap
0x00040000 0x00080000 U-Boot
0x000C0000 0x00080000 U-Boot Redundant image 1
0x00140000 0x00080000 U-Boot Redundant image 2
0x001C0000 0x000C0000 U-Boot environments
0x001C0000 0x00040000 env
0x00200000 0x00040000 env redundant
0x00240000 0x00040000 reserved for env redundant second
0x00300000 0x00600000 kernel
0x00980000 0x00600000 kernel Redundant
0x00f80000 - rootfs

4. Toolchain: download, unpack, set CROSS_COMPILE
The toolchain is this example will be installed in /opt/cross

$ cd /opt/
$ sudo mkdir cross
$ cd cross

$ sudo wget
$ sudo tar xvfj gcc-arm-none-eabi-4_9-2015q1.tar.bz2
$ export CROSS_COMPILE=/opt/cross/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-

5. Patches: download, unpack

$ mkdir -p ~/work
$ cd ~/work
$ wget
$ tar xfvz sama5d3x-redundant.tar.gz

6. AT91Bootstrap: download, patch, build

$ cd ~/work/sama5d3x-redundant/at91bootstrap
$ git clone git://
$ cd at91bootstrap
$ git checkout -b v3.8.1 v3.8.1
$ git am ../patches/0001-add-support-for-redundant-booting-of-U-BOOT.patch
$ git am ../patches/0002-use-8-bit-PMECC.patch
$ make sama5d3xeknf_uboot_defconfig
$ make
$ cp binaries/sama5d3xek-nandflashboot-uboot-3.8.1.bin ../../bin/boot.bin


7. U-Boot: download, patch, build, pad to 512KB, add CRC32 at end of file

$ cd ~/work/sama5d3x-redundant/u-boot-at91
$ git clone git://
$ cd u-boot-at91
$ git checkout origin/u-boot-2015.01-at91 -b u-boot-2015.01-at91
$ git am ../patches/0001-add-support-for-redundant-booting-of-Linux-Kernel.patch
$ git am ../patches/0002-use-8-bit-PMECC.patch
$ make sama5d3xek_nandflash_defconfig
$ make

Pad the U-BOOT image with zeros to 512KiB and add at the end 32-bit CRC32:

$ ../../bin/padfile u-boot.bin

$ cp u-boot.bin ../../bin/
$ sudo cp tools/mkimage /usr/bin/


8. Linux Kernel: download, patch, build
This set of patches uses the new, FIT (Flattened Image Tree) format which allows more flexibility in handling various images and also enhances integrity protection.

$ cd ~/work/sama5d3x-redundant/linux-at91
$ git clone git://
$ cd linux-at91
$ git remote add linux4sam git://
$ git remote update linux4sam
$ git checkout origin/linux-3.18-at91 -b linux-3.18-at91
$ git am ../patches/0001-add-sources-for-U-Boot-FIT-images.patch
$ git am ../patches/0002-no-need-of-PDAx-dtbs-in-Ronetix-products.patch
$ git am ../patches/0003-adjast-NAND-MTD-partitions-with-redundant-multi-imag.patch
$ git am ../patches/0004-use-8bits-for-NAND-PMECC.patch

$ export ARCH=arm
$ make mrproper
$ make sama5_defconfig
$ make -j 8
$ make uImage
$ make sama5d3{1,3,4,5,6}ek.dtb
$ dtc() {
${PWD}/scripts/dtc/dtc "$@"
$ export -f dtc
$ mkimage -f ./arch/arm/boot/dts/sama5d3xek.its sama5d3xek.itb
$ cp sama5d3xek.itb ../../bin

9. Root File system - Buildroot

$ mkdir -p ~/work/sama5d3x-redundant/buildroot
$ cd ~/work/sama5d3x-redundant/buildroot
$ git clone git://
$ cd buildroot-at91
$ git checkout master
$ make sama5d3_defconfig
$ make
$ cp output/images/rootfs.ubi ../../bin


10. Program images with SAM-BA
Register to ATMEL site and get SAM-BA v2.15

$ cd /opt
$ sudo unzip

$cd ~/work/sama5d3x-redundant/bin

Check that all necessary images are here:

$ ls
boot.bin ; at91bootstrap bootloader ; bash script which calls d3x.tcl to program all images
padfile ; bash script used to pad u-boot.bin to 512KiB and to add CRC32
rootfs.ubi ; Buildroot RootFS image
sama5d3xek.itb ; Linux kernel FIT image
u-boot.bin ; U-BOOT bootloader

Start programming:

$ ./

11. Program images with PEEDI
PEEDI have to be configured to use the Ronetix configuration file for SAMA5Dx3-CM: atsama5d3.cfg

Note: PEEDI supports 8-bit PMECC programming since firmware v16.x.x.

Copy the images from "~/work/sama5d3x-redundant/bin" to the TFTBOOT directory and modify the paths in atsama5d3.cfg.
When PEEDI successfully connects to the board, then just enter the following command to program bootstrap, two redundant U_BOOT images , two redundant Linux kernel images and root filesystem at once:

sama5d3x> run $prog

Alternatively, single images can be programmed using:
sama5d3x> flash set 0 ; select bootstrap flash section
sama5d3x> flash erase ; erase the whole NAND Flash
sama5d3x> flash program ; program the bootstrap image using 8-bit ECC and add 52x32-bit header
sama5d3x> flash set 1 ; select U-BOOT flash section
sama5d3x> flash program ; program U-BOOT image using 8-bit ECC

Additional information can be found here: