Microchip SAMA5D27-SOM1 based main board for the NW-R platform

Software installation

Compile at91bootstrap

Note

You can download a known working at91bootstrap here. (TODO)

Compile u-boot

You can basically follow https://forum.digikey.com/t/debian-getting-started-with-the-atsama5d27-som1-ek1/13015

Make sure you have the right toolchain:

wget -c https://releases.linaro.org/components/toolchain/binaries/6.5-2018.12/arm-linux-gnueabihf/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf.tar.xz
tar xf gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf.tar.xz
export CC=`pwd`/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

Download and patch u-boot:

git clone -b v2020.04 https://github.com/u-boot/u-boot --depth=1
cd u-boot/
wget -c https://github.com/eewiki/u-boot-patches/raw/master/v2020.04/0001-sama5dX-fixes.patch
patch -p1 < 0001-sama5dX-fixes.patch

Configure and build:

make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} sama5d27_som1_ek_qspiflash_defconfig
make ARCH=arm CROSS_COMPILE=${CC}

TODO: remove network support, EXT4 support, FIT support, EFI support (to make u-boot < 384 K)

Note

You can download a known working u-boot for this board here. (TODO)

Obtain the right device tree

DTB is compiled using Buildroot during the build process. There should be no need to modify it. Download DTB binary blob here (TODO).

Flashing bootloaders

Download and unpack SAM-BA In-system Programmer:

cd /opt
wget https://ww1.microchip.com/downloads/en/DeviceDoc/sam-ba_3.5-linux_x86_64.tar.gz
tar xvzf sam-ba_3.5-linux_x86_64.tar.gz

Make the tool available

export PATH=$PATH:/opt/sam-ba_3.5/

Flash at91bootstrap, u-boot and a device tree blob:

sam-ba -p serial -d sama5d2 -a qspiflash:1:2:25 -c erase
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:25 -c writeboot:at91bootstrap.bin
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:25 -c write:sama5d27-main-nwr2u.dtb:0x4000
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:25 -c write:u-boot.bin:0x10000

Enable booting from QSPI flash, disable others:

sam-ba -p serial -d sama5d2 -a bootconfig -c writecfg:bureg1:QSPI0_DISABLED,SPI0_DISABLED,SPI1_DISABLED,NFC_DISABLED,SDMMC0_DISABLED,SDMMC1_DISABLED,QSPI1_IOSET2,UART_DISABLED,JTAG_IOSET3,EXT_MEM_BOOT
sam-ba -p serial -d sama5d2 -a bootconfig -c writecfg:bscr:valid,bureg1

Note

Those settings are not permanent and require a RTC backup battery to be installed. If you want to make them permanent, use fuses to store the boot configuration.

Test your configuration before making it permanent as it cannot be overwritten later.

sam-ba -p serial -d sama5d2 -a bootconfig \
-c writecfg:fuse:QSPI0_DISABLED,SPI0_DISABLED,SPI1_DISABLED,NFC_DISABLED,SDMMC0_DISABLED,SDMMC1_DISABLED,QSPI1_IOSET2,UART_DISABLED,JTAG_IOSET3,EXT_MEM_BOOTTT

Running debian installer

In order to get a fresh Debian root filesystem, it is best to run the debian installer directly on the board and follow the installation process.

Download and unpack the debian installer from http://ftp.debian.org/debian/dists/stable/main/installer-armhf/current/images/hd-media/, initrd.gz and vmlinuz files are needed. Install u-boot tools first:

apt install u-boot-tools

Convert the init ramdisk to uImage format:

mkimage -n 'Ramdisk Image'  -A arm -O linux -T ramdisk -C gzip -d initrd.gz initrd.uImage

Download ISO netinst image from the debian web. Copy it to a USB stick together with vmlinuz, initrd.uImage and DTB files.

Boot the installer using u-boot:

usb start
fatload usb 0:1 0x21000000 sama5d27-main-nwr2u.dtb
fatload usb 0:1 0x22000000 zImage
fatload usb 0:1 0x23000000 initrd.uImage
bootz 0x22000000 0x23000000 0x21000000

Complete the installation process. You can skip mirror selection if no internet connection is available. You will have to skip bootloader installation as the installer insists on installing Grub.

Running the installed system

Prepare DTB and zImage files, they are the same as required for running the installer. initrd.uImage file obtained by converting from initrd found in the /boot partition of the installed system is required too. Use the same method as above to convert it to uImage.

Flash everything into 32 MB QSPI:

sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c erase
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c writeboot:../at91bootstrap.bin
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c write:../sama5d27-main-nwr2u.dtb:0x4000
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c write:../u-boot.bin:0x10000
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c write:zImage:0x80000
sam-ba -p serial -d sama5d2 -a qspiflash:1:2:10 -c write:initrd.uImage:0x400000

Boot into u-boot and issue the following commands. They load DTB, kernel (max size 3.5 MB) and initrd (max size 28 MB):

env set bootargs "console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p1 rw"
sf probe 0
sf read 0x2100c000 0x4000 0xc000
sf read 0x21080000 0x80000 0x380000
sf read 0x21400000 0x400000 0x1c00000
bootz 0x21080000 0x21400000 0x2100c000

Make the settings permanent:

env set bootargs "console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p1 rw"
env set bootcmd "sf probe 0; sf read 0x2100c000 0x4000 0xc000; sf read 0x21080000 0x80000 0x380000; sf read 0x21400000 0x400000 0x1c00000; bootz 0x21080000 0x21400000 0x2100c000"
env save