SAM9X60-EK Evaluation Kit - Booting from NAND Flash Memory

Last modified by Microchip on 2023/11/14 15:19

Prerequisites

Hardware

SAM9X60 Board

For this training topic, you will be using the SAM9X60-EK Evaluation Kit. You will also need two USB Micro-B cables. One cable will connect the Host PC to the target console to view the SAM-BA Monitor log message. The second cable will connect the Host PC to the target USBA port (J7) so that the SAM-BA Host can communicate with the SAM-BA Monitor.

Back to top

Bootable Memory

The SAM9X60-EK Evaluation Kit has a 4 Gb (512 M x 8) NAND Flash memory (U9) (Micron MT29F4G08ABAEA) that may be used for booting an embedded Linux® system.

Board View of SAM9X60-EK Evaluation Kit

You will configure and build bootable files at91bootstrap, u-boot-at91, Flattened Image Tree (FIT) (containing the Linux kernel and device tree), and Root File System (RFS) to be Flashed into U9 using the SAM-BA In-System Programmer (ISP).

Memory Map

Back to top

SAM-BA In-System Programmer

In this section, you will load the SAM-BA Host Application (if you have not already done so) and set up Console and SAM-BA Host to Monitor communications.

Setup SAM9X60-EK Console Serial Communications

To view the SAM-BA Monitor log messages, set up console serial communications following the instructions on the "SAM9X60-EK Evaluation Kit - Console Serial Communicationspage.

You have two choices in connecting to a serial port on the SAM9X60-EK:

  • The first is using a USB cable to connect to the J-LINK-OB port (J22). This method has the added benefit of powering the SAM9X60-EK.
  • The second is using a USB-to-TTL converter to connect to the Universal Asynchronous Receiver Transmitter (UART) Debug port (J24). With this option, to power the SAM9X60-EK, you will need to:
    • Use an external 5 VDC power supply connected to J1 (coaxial power jack), or
    • Use a USB cable connected to the USBA port (J7). As you’ll be connecting a USB cable in Step 3 below (SAM-BA Host to Monitor Communications), this is the easiest method.

USB cable connected to USBA port (J7) and Host to Monitor Communications

Note:

Operation of the J-Link Debugger will be displayed by a green LED (D9).

Serial UART Debut Port

If it is not already installed, install the SAM-BA Host Application.

Note:

SAM-BA ISP should be added to the system PATH variable.

$ export PATH=$PATH:<path_to_sam-ba>

This will enable you to access the SAM-BA ISP from anywhere on your system.


Setup the SAM-BA Host to Monitor Serial Communications

With SAM-BA Monitor on the target, you must have installed the SAM-BA Host on a Linux PC (Step 2 above), and connect a USB Micro-B cable from the host PC to the USBA port (J7) on the SAM9X60-EK as shown in the accompanying figure.

Connected USB Micro-B cable from the host PC to the USBA port (J7) on the SAM9X60-EK

Note:

You may power the SAM9X60-EK one of two ways:

  1. Using an external 5 VDC power supply connected to J1 (coaxial power jack), or
  2. Using a USB cable connect to the USBA port (J7).
Ensure there is no SD memory card inserted in slot J4.

Open Jumper the DISABLE_BOOT (J13).

This will allow booting from the onboard memories (NAND and QSPI Flash).

Press both the DIS_BOOT (SW4) and RESET (SW3) push buttons.
Pressing the DIS_BOOT (SW4) push button disables booting from the onboard memories.

Continue pressing the DIS_BOOT(SW4) while releasing the RESET (SW3) push button.

The SAM9X60-EK will boot to the SAM-BA Monitor and start communications with the SAM-BA Host. Observe ROMBoot on the Console (terminal emulator) indicating the SAM-BA Monitor is running.

Back to top

Erase NAND Flash Memory

In this section, you will erase the contents of the NAND Flash Memory located on the SAM9X60-EK. This is a necessary step before writing data to the NAND Flash Memory.

Erase NAND Flash Memory

Erase the contents of the NAND Flash Memory on the SAM9X60-EK with the following command:

$ sam-ba -p serial -b sam9x60-ek -a nandflash -c erase
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 536870912 bytes.
Page size is 4096 bytes.
Buffer is 8192 bytes (2 pages) at address 0x0030aca0.
NAND header value is 0xc1e04e07.
Supported erase block size: 256KB
Executing command 'erase'
Erased 262144 bytes at address 0x00000000 (0.05%)
Erased 262144 bytes at address 0x00040000 (0.10%)
..
..
Erased 262144 bytes at address 0x1ff80000 (99.95%)
Erased 262144 bytes at address 0x1ffc0000 (100.00%)
Connection closed.

Note:

The default PMECC parameter for the sam9x60ek board is 0xc1e04e07. It is valid for the NAND Flash Memory (U9) onboard the SAM9X60-EK when the SAM-BA command is invoked with the -b sam9x60-ek option.

Note:

Refer to the "Section 12.4.7. Detailed Memory Boot Procedures" and "Section 35. Programmable Multibit Error Correction Code Controller (PMECC)" in the SAM9X60 datasheet for more information.

Build at91bootstrap and Write to NAND Flash Memory

In this section, you will configure and build the second-stage bootloader, at91bootstrap, from source code to boot from NAND Flash Memory and write it to NAND Flash Memory.

For more information, including how to download, see the "at91bootstrap: A Second Stage Bootloader for Microchip Microprocessors" training.

Change directory into the at91bootstrap directory:

$ cd ~~/at91bootstrap

Using a default configuration file, configure at91bootstrap to boot u-boot from NAND Flash Memory:

$ make mrproper
# CLEAN obj and misc files!
# CLEAN configuration files!
# CLEAN binary files!

$ make sam9x60eknf_uboot_defconfig
#
# configuration written to .config
#
#
# make dependencies written to .auto.deps
# See top of this file before playing with this auto-prerequisites!
#

What is the difference between make clean and make mrproper?

  • make clean - Remove most generated files but keep the config and enough build support to build external modules.
  • make mrproper - Remove all generated files + config + various backup files.

Anytime the configuration is changed, you should execute make mrproper.

Default configuration (defconfig) files are provided for the many evaluation kits sold by Microchip. They are located in the ~/at91bootstrap/board/ directory.


Optional: If you would like to verify the NAND Flash Memory settings or make any customizations:

$ make menuconfig

at91bootstrap configuration

Observe that Board Type (sam9X60ek) has been selected.
Highlight Memory selection ---> and press ENTER.

Highlight NAND flash configuration ---> and press ENTER.

You can see the default NAND flash configuration set for SAM9X60-EK.

NAND Flash configuration

You may exit menuconfig by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.


Build at91bootstrap:

$ make

A working cross-toolchain for ARM-based MPU target is required to build at91bootstrap.

​Ensure you set the CROSS_COMPILE=<cross_compiler> and ARCH=arm environment variables.
For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

Another method is to include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

Once the build is complete, the resulting binary files are in the ~/at91bootstrap/binaries/ directory:

$ cd ~~/at91bootstrap/binaries
$ ls
at91bootstrap.bin
boot.bin
sam9x60ek-nandflashboot—uboot-3.9.2.bin
sam9x60ek-nandflashboot—uboot-3.9.2.bin.pmecc
sam9x60ek-nandflashboot-uboot—3.9.2.elf
sam9x60ek-nandflashboot-uboot—3.9.2.map

From the SAM-BA Host command line, write at91bootstrap.bin to NAND Flash Memory starting at location 0x0 using the nandflash applet writeboot command:

$ sam-ba -p serial -b sam9x60-ek -a nandflash -c writeboot:at91bootstrap.bin
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 536870912 bytes.
Page size is 4096 bytes.
Buffer is 8192 bytes (2 pages) at address 0x0030aca0.
NAND header value is 0xc1e04e07.
Supported erase block size: 256KB
Executing command 'write:at91bootstrap.bin'
Appending 3588 bytes of padding to fill the last written page
Wrote 8192 bytes at address 0x00000000 (50%)
Wrote 8192 bytes at address 0x00002000 (100%)
Connection closed.

For more information on the SAM-BA Applet nandflash command, see the "SAM-BA ISP - Applets: Program External NAND Flash Memory" page.

The result is at91bootstrap.bin is stored in the NAND Flash Memory starting at address 0x0.

NAND Memory Map at91bootstrap

Build u-boot-at91 and Write to NAND Flash Memory

In this section, you will configure and build the third-stage bootloader, u-boot-at91, from source code to boot from NAND Flash Memory and write it to NAND Flash Memory.

Note:

u-boot-at91 is maintained by Microchip Technology Inc. and hosted on GitHub.

Note:

For more information about the third-stage bootloader see the "Das U-Boot – The Universal Boot Loader" page.

Change directory to your working directory containing the u-boot-at91:

$ cd ~/u-boot-at91

Using a default configuration file, configure u-boot-at91 for NAND Flash Memory:​

$ make sam9x60ek_nandflash_defconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written .config
#

Optional: If you would like to verify settings for booting from NAND Flash Memory or make any customizations, type:

$ make menuconfig

U-Boot screen showing configuration

Highlight Boot media > and press ENTER.

[*] Support for booting from NAND flash ---> has been selected.

You may exit menuconfig by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.


Build u-boot-at91:​

$ make

Alert!

A working cross-toolchain for an Arm-based MPU target is required to build u-boot-at91.

Alert!

Ensure you set the CROSS_COMPILE=<cross_compiler> and ARCH=arm environment variables.

For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

Another method is to include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

Once the build is complete, the resulting binary file u-boot.bin is in the u-boot-at91 directory.


From the SAM-BA Host command line, write u-boot.bin to NAND Flash Memory starting at location 0x40000 using the applet -a nandflash -c write command:​

$ sam-ba -p serial -b sam9x60-ek -a nandflash -c write:u-boot.bin:0x40000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 536870912 bytes.
Page size is 4096 bytes.
Buffer is 8192 bytes (2 pages) at address 0x0030aca0.
NAND header value is 0xc1e04e07.
Supported erase block size: 256KB
Executing command 'write:u-boot.bin:0x40000'
Appending 2794 bytes of padding to fill the last written page
Wrote 8192 bytes at address 0x00040000 (1.41%)
Wrote 8192 bytes at address 0x00042000 (2.82%)


Wrote 8192 bytes at address 0x000ca000 (98.59%)
Wrote 8192 bytes at address 0x000cc000 (100%)
Connection closed.

The result is u-boot.bin is stored on the NAND Flash Memory starting at address 0x40000.

Memory Map


Back to top

Create u-boot-env.bin and Write to NAND Flash Memory

Configuration of U-Boot is performed using environment variables. They are stored in binary format, generally, on the same boot memory (mass storage) that U-Boot is stored.

In this section, you will create a U-Boot environment binary file by first creating a text file. The text file is then converted to binary format using a utility program, mkenvimage. Finally, you will write the file to NAND Flash Memory using the SAM-BA In-System Programmer (ISP).

Note:

More information on U-Boot Environment Variables can be found in the U-Boot documentation "Environment Variables" section.

Using your favorite text editor, create a text file with the following information. Name the text file u-boot-env.txt.

baudrate=115200
bootargs=console=ttyS0,115200 mtdparts=atmel_nand:256k(bootstrap)ro,768k(uboot)ro,256k(env_redundant),256k(env),6656k(itb)ro,
-(rootfs) rootfstype=ubifs ubi.mtd=11 root=ubi0:rootfs rw atmel.pm_modes=standby,ulp0
bootcmd=nand read 0x24000000 0x00180000 0x49b46c; bootm 0x24000000#kernel_dtb
bootdelay=1
stderr=serial
stdin=serial
stdout=serial

The bootargs line tells U-Boot:

  • The console= device and baud
  • The root= location of the root filesystem and permissions
  • The rootfstype= root filesystem type

The bootcmd= line tells U-Boot to load the sam9x60ek.itb file from address 0x00180000 of NAND Flash memory to external DDR2 SDRAM starting at address 0x24000000.


Convert the text file u-boot-env.txt into a binary file u-boot-env.bin using the utility program mkenvimage.

$ mkenvimage -s 0x20000 -o u-boot-env.bin u-boot-env.txt

Note:

The mkenvimage utility program generates a valid binary environment image from a text file. It is part of the U-Boot software package. See directory ../u-boot-at91/tools/.

Note:

The -s option allows you to specify the size of the image to create. It must match the size of the Flash area reserved for the U-Boot environment.


From the SAM-BA Host command line, write u-boot-env.bin to NAND Flash Memory starting at location 0x140000 using the applet -a nandflash -c write command:

The result is u-boot environment is stored in the NAND Flash Memory starting at address 0x40000.

NAND Flash Memory starting at address 0x40000.


Back to top

Build the Linux® Kernel Image and Device Tree Blob (DTB)

In this section, you will configure the Linux kernel and device tree for the SAM9X60-EK evaluation kit using the default configuration and build files. In the next section, you will use these files to create a Flattened Image Tree (FIT) image and write it to NAND Flash Memory.

Note:

linux-at91 is maintained by Microchip Technology Inc. and hosted on GitHub.

Change the directory to your working directory containing the linux-at91 source code:

​$ cd ~/linux-at91

Using default configuration files, configure the Linux kernel using the following command:​

$ make ARCH=arm at91_dt_defconfig

HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer/lex.o
HOSTCC scripts/kconfig/parser.tab.o
HOSTCC scripts/kconfig/preprocess.o
HOSTCC scripts/kconfig/symbol.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#

Optional: If you would like to verify settings or make customization changes type:​

$ make menuconfig

U-Boot Screen showing Configuration

 

You may exit menuconfig by repeatedly typing "ESC-ESC" until it closes. Do not save any changes.


Build linux-at91:​

$ make ARCH=arm

Alert!

A working cross-toolchain for an Arm-based MPU target is required to build linux-at91.

Alert!

Ensure you set the CROSS_COMPILE=<cross_compiler> and ARCH=arm environment variables.

For example, if your cross-compiler executable is arm-linux-gcc then CROSS_COMPILE=<path_to>/arm-linux-

Another method is to include these as command variables. For example:

$ make ARCH=arm CROSS_COMPILE=<path_to>/<cross_compiler>

Once the build is complete, the resulting binary files are created:

/arch/arm/boot/zImage
/arch/arm/boot/dts/at91-sam9x60ek.dtb

Back to top

Create Flattened Image Tree (FIT) and Write to NAND Flash Memory

In this section, you will create a Flattened Image Tree (FIT). The FIT image allows for more flexibility in handling images of various types and enhances the integrity protection of images with stronger checksums. An Image Source (*.its) file and a set of data files are used as input. An Image Tree Blob (*.itb) file is generated as the output. Finally, you will write the FIT image to NAND Flash Memory.

Git clone the Device Tree Overlay files from the Linux4SAM repository:​

$ git clone git://github.com/linux4sam/dt-overlay-at91.git

Change directory to your working directory containing the dt-overlay-at91:​

$ cd ~/dt-overlay-at91

Open Makefile with your favorite editor and verify that the KERNEL_DIR is pointing to your linux-at91 directory:

CC?=$(CROSS_COMPILE)gcc
DTC_OPTIONS?=-@
DTC_OPTIONS += -Wno-unit_address_vs_reg -Wno-graph_child_address -Wno_pwms_property
KERNEL_DIR?=../linux-at91 <--- Ensure pointing to your linux-at91 directory
KERNEL_BUILD_DIR?=$(KERNEL_DIR)
DTC?=$(KERNEL_BUILD_DIR)/scripts/dtc/dtc

Or you can set the KERNEL_DIR environment variable:
$ export KERNEL_DIR=path
$ echo $KERNEL_DIR


Build the *.itb image file:

$ make sam9x60ek.itb

Once the build is complete, the resulting image file sam9x60ek.itb is located in the dt-overlay-at91 directory.


Write Image Tree Blob (ITB) to NAND Flash Memory using the following command:​

$ sam-ba -p serial -b sam9x60-ek -a nandflash -c write:sam9x60ek.itb:0x180000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 536870912 bytes.
Page size is 4096 bytes.
Buffer is 8192 bytes (2 pages) at address 0x0030aca0.
NAND header value is 0xc1e04e07.
Supported erase block size: 256KB
Executing command 'write:sam9x60ek.itb:0x180000'
Wrote 8192 bytes at address 0x00180000 (0.17%)
Wrote 8192 bytes at address 0x00142000 (0.34%)


Wrote 8192 bytes at address 0x0015c000 (99.83%)
Wrote 8192 bytes at address 0x0015e000 (100%)
Connection closed.

The result is the Flattened Image Tree (FIT) is stored in the NAND Flash Memory starting at address 0x180000.

Flattened Image Tree (FIT) stored in the NAND Flash Memory starting at address 0x180000.


Back to top

Prepare a Root File System (ROOTFS) for NAND Flash Memory

In this section, you will download a demonstration image from the Linux4SAM website to use the ROOTFS on the image. You will Flash the image to NAND Flash Memory.

 

Download the SAM9X60-EK demonstration package from the Linux4SAM website.

Note:

The latest demonstration images for the SAM9X60-EK are available on the Linux4SAM website. There you will find the demonstration package for NAND Flash Memory.

Download and extract the linux4sam-poky-sam9x60ek-headless-2020.04.zip file.


Flash the RootFS image to NAND Flash Memory.

Once you have the package extracted, you will use the microchip-headless-image-sam9x60ek.ubi file. This is the RootFS in the Unsorted Block Image File System (UBIFS) format.

Write to NAND Flash Memory using the following command:​

$ sam-ba -p serial -b sam9x60-ek -a nandflash -c write:microchip-headless-image-sam9x60ek.ubi:0x800000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 536870912 bytes.
Page size is 4096 bytes.
Buffer is 8192 bytes (2 pages) at address 0x0030aca0.
NAND header value is 0xc1e04e07.
Supported erase block size: 256KB
Executing command 'write:microchip-headless-image-sam9x60ek.ubi:0x800000'
Wrote 8192 bytes at address 0x00800000 (0.01%)
Wrote 8192 bytes at address 0x00802000 (0.01%)


Wrote 8192 bytes at address 0x0015c000 (99.83%)
Wrote 8192 bytes at address 0x0015e000 (100%)
Connection closed.

The result is the Root File System is stored in the NAND Flash Memory starting at address 0x800000.

Root File System stored in the NAND Flash Memory starting at address 0x800000


Back to top

Boot from NAND Flash Memory


Check that you have Console Serial Communications established.

Review STEP 1 of the SAM-BA In-System Programmer section above.


Check that jumper the DIS_BOOT (J13) is open.

This will allow booting from the onboard memories (NAND and QSPI Flash).


Press the RESET button SW3 (nRST).

The boot log will be displayed in the terminal emulator. In the end, the command line will prompt the user to log in. Login as ‘root’. There is no password required to log in.

Boot Log
Proper operation of the image will be indicated by a flashing blue RGB LED (LD1).

If Console Serial Communications is connected to J22, the operation of the onboard J-Link Debugger will be indicated by a flashing green LED (D9).

Congratulations! You have created an embedded Linux system that boots from NAND Flash memory.

Back to top

Summary

In this training topic, you configured and built the second-stage bootloader at91bootstap, the third-stage bootloader u-boot-at91, Linux kernel, and device tree. You created a Flattened Image Tree (FIT) containing the Linux kernel and device tree. You prepared a Root File System (RootFS) in the UBIFS format from a Linux4SAM demonstration image. Each of these you individually wrote to NAND Flash Memory. The result is an embedded Linux system that boots from NAND Flash Memory.

Back to top

Learn More

Back to top