Standalone boot (DIVELK)

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box
Diva-am335x-overview.png Applies to Diva

History[edit | edit source]

Version Date DIVELK version Notes

3.0.0

June 2017 DIVELK 3.0.0
4.0.0 April 2018 DIVELK 4.0.0

Introduction[edit | edit source]

This document has been written and tested with the software/hardware combination described in the history table above. However it contains general concept that can be adapted on any DAVE Embedded Systems' Linux platform.

We'll explain how to program and configure a to boot in standalone mode, without the need of a system microSD card or a NFS server, with two options:

  • booting with NOR + NAND
    • U-Boot will fetch Linux kernel binary images (kernel + device tree) from on-board NOR flash memory, while later the OS will mount the root file system from a NAND partition.
  • booting with NAND only
    • in this configuration the whole system will boot without the need of a NOR storage, all images and the root file system will be fetch from NAND.

Update u-boot NOR[edit | edit source]

tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_MLO.byteswap
sf probe 0:0; sf erase 0x0 0x40000; sf write ${loadaddr} 0x0 0x40000
tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_u-boot.img
sf probe 0:0; sf erase 0x40000 0x100000; sf write ${loadaddr} 0x40000 0x100000
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_MLO.byteswap
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/divelk-4.0.0_diva_spiboot_MLO.byteswap'.
Load address: 0x82000000
Loading: #############
         1.3 MiB/s
done
Bytes transferred = 65868 (1014c hex)

=> sf probe 0:0; sf erase 0x0 0x40000; sf write ${loadaddr} 0x0 0x40000
SF: Detected s25fl256s_64k with page size 256 Bytes, erase size 64 KiB, total 32 MiB
SF: 262144 bytes @ 0x0 Erased: OK
device 0 offset 0x0, size 0x40000
SF: 262144 bytes @ 0x0 Written: OK

=> tftp ${loadaddr} diva/divelk-4.0.0_diva_spiboot_u-boot.img
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/divelk-4.0.0_diva_spiboot_u-boot.img'.
Load address: 0x82000000
Loading: #################################################################
         #########################################
         1.3 MiB/s
done
Bytes transferred = 540424 (83f08 hex)

=> sf probe 0:0; sf erase 0x40000 0x100000; sf write ${loadaddr} 0x40000 0x100000
SF: Detected s25fl256s_64k with page size 256 Bytes, erase size 64 KiB, total 32 MiB
SF: 1048576 bytes @ 0x40000 Erased: OK
device 0 offset 0x40000, size 0x100000
SF: 1048576 bytes @ 0x40000 Written: OK

Note: Adjust the SYSBOOT pins to enable boot from spi.

Update u-boot NAND[edit | edit source]

tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_MLO
nand erase.part nand-spl; nand write ${loadaddr} nand-spl ${filesize}
tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_u-boot.img
nand erase.part nand-uboot; nand write ${loadaddr} nand-uboot ${filesize}
=> tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_MLO
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/divelk-4.0.0_diva_nandboot_MLO'.
Load address: 0x82000000
Loading: #############
         825.2 KiB/s
done
Bytes transferred = 61716 (f114 hex)
=> nand erase.part nand-spl; nand write ${loadaddr} nand-spl ${filesize}

NAND erase.part: device 0 offset 0x0, size 0x20000
Erasing at 0x0 -- 100% complete.
OK

NAND write: device 0 offset 0x0, size 0xf114
 61716 bytes written: OK

=> tftp ${loadaddr} diva/divelk-4.0.0_diva_nandboot_u-boot.img
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/divelk-4.0.0_diva_nandboot_u-boot.img'.
Load address: 0x82000000
Loading: #################################################################
         #########################################
         1 MiB/s
done
Bytes transferred = 539856 (83cd0 hex)

=> nand erase.part nand-uboot; nand write ${loadaddr} nand-uboot ${filesize}

NAND erase.part: device 0 offset 0x80000, size 0x1e0000
Erasing at 0x240000 -- 100% complete.
OK

NAND write: device 0 offset 0x80000, size 0x83cd0
 539856 bytes written: OK

Note: Adjust the SYSBOOT pins to enable boot from nand.

Program root file system in NAND flash[edit | edit source]

This is a common step for both booting options.

  • Boot the system via SD or NFS
  • By default, the NAND is already partitioned to allow booting from NAND-only (see next section) and, thus, some partitions are reserved for U-boot and kernel images. Here we won't modify this default configuration. The MTD partitions can be dumped with /proc/mtd (the partition's name should be self-explanatory)
root@diva:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "spi-MLO"
mtd1: 00100000 00010000 "spi-uboot"
mtd2: 00040000 00010000 "spi-env1"
mtd3: 00040000 00010000 "spi-env2"
mtd4: 00040000 00010000 "spi-fdt"
mtd5: 00600000 00010000 "spi-kernel"
mtd6: 00400000 00010000 "spi-splash"
mtd7: 01400000 00010000 "spi-free"
mtd8: 00020000 00020000 "nand-spl"
mtd9: 00020000 00020000 "nand-spl.backup1"
mtd10: 00020000 00020000 "nand-spl.backup2"
mtd11: 00020000 00020000 "nand-spl.backup3"
mtd12: 001e0000 00020000 "nand-uboot"
mtd13: 00020000 00020000 "nand-uboot-env"
mtd14: 00020000 00020000 "nand-uboot-env.backup1"
mtd15: 00020000 00020000 "nand-fdt"
mtd16: 00600000 00020000 "nand-kernel"
mtd17: 00400000 00020000 "nand-splash"
mtd18: 3f340000 00020000 "nand-filesystem"


200px-Emblem-important.svg.png

Please note that MTD partition index may change depending of flash device availability, flash device size, u-boot environment variables or kernel device driver load order. Always take care of looking inside /proc/mtd to match your specific layout


  • Format and initialize nand-filesystem partition, which in our case is mtd18, using UBI with:
ubiformat /dev/mtd18
ubiattach -m 18
ubimkvol /dev/ubi0 -N rootfs -m

E.g.

root@diva:~# ubiformat /dev/mtd18
ubiformat: mtd18 (nand), size 1060372480 bytes (1011.2 MiB), 8090 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 8089 -- 100 % complete  6 % complete  
ubiformat: 8089 eraseblocks have valid erase counter, mean value is 1
ubiformat: 1 bad eraseblocks found, numbers: 2991
ubiformat: formatting eraseblock 8089 -- 100 % complete  
root@diva:~# 
root@diva:~# ubiattach -m 18
[  932.829348] ubi0: attaching mtd18
[  935.304512] ubi0: scanning is finished
[  935.334456] ubi0: attached mtd18 (name "nand-filesystem", size 1011 MiB)
[  935.341934] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[  935.353377] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[  935.362897] ubi0: VID header offset: 512 (aligned 512), data offset: 2048
[  935.372570] ubi0: good PEBs: 8089, bad PEBs: 1, corrupted PEBs: 0
[  935.381808] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[  935.391863] ubi0: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 1786346429
[  935.403777] ubi0: available PEBs: 7926, total reserved PEBs: 163, PEBs reserved for bad PEB handling: 159
[  935.416248] ubi0: background thread "ubi_bgt0d" started, PID 1025
UBI device number 0, total 8089 LEBs (1043675136 bytes, 995.3 MiB), available 7926 LEBs (1022644224 bytes, 975.3 MiB), LEB size 129024 byte)
root@axel-lite:~# ubimkvol /dev/ubi0 -N rootfs -m
Set volume size to 1022644224
Volume ID 0, size 7926 LEBs (1022644224 bytes, 975.3 MiB), LEB size 129024 bytes (126.0 KiB), dynamic, name "rootfs", alignment 1
root@diva:~#
  • Now mount the UBI volume using UBIFS in a temporary directory
mkdir -p /mnt/nand
mount -t ubifs ubi0_0 /mnt/nand

E.g.:

root@diva:~# mkdir -p /mnt/nand
root@diva:~# mount -t ubifs ubi0_0 /mnt/nand
[ 1048.356596] UBIFS (ubi0:0): default file-system created
[ 1048.371923] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1033
[ 1048.436268] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
[ 1048.443769] UBIFS (ubi0:0): LEB size: 129024 bytes (126 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 1048.459787] UBIFS (ubi0:0): FS size: 1020321792 bytes (973 MiB, 7908 LEBs), journal size 33546240 bytes (31 MiB, 260 LEBs)
[ 1048.477979] UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
[ 1048.484678] UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 506C48EC-890F-476F-BD40-56141C521278, small LPT model
root@diva:~#
  • you can now extract the root file system into that directory
tar xvJf divelk-4.0.0_divelk-image-matrix.tar.xz -C /mnt/nand
  • finally, you need to cleanly umount and detach the MTD partition
umount /mnt/nand/
ubidetach -m 18

E.g.

root@diva:~# umount /mnt/nand/
[ 1137.013852] UBIFS (ubi0:0): un-mount UBI device 0
[ 1137.027471] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" stops
root@diva:~# ubidetach -m 18
[ 1144.283392] ubi0: detaching mtd18
[ 1144.311866] ubi0: mtd18 is detached
root@diva:~# 

You can now safely reboot or turn off the system.

In U-Boot environment check the following variable, which must contain the same MTD partition number used above

nandargs=setenv bootargs ubi.mtd=nand-filesystem root=ubi0:rootfs rootfstype=ubifs rw rootwait=1

Program boot images[edit | edit source]

NOR flash[edit | edit source]

We assume that the following environment variables are present in u-boot:

loadk=tftpboot ${loadaddr} ${serverip}:${bootfile}
loadfdt=tftpboot ${fdtaddr} ${serverip}:${fdtfile}
spi_updatek=sf erase 0x200000 0x600000; sf write ${loadaddr} 0x200000 ${filesize}
spi_updatefdt=sf erase 0x1C0000 0x40000; sf write ${fdtaddr} 0x1C0000 ${filesize}
spi_loadk=sf read ${loadaddr} 0x200000 0x600000
spi_loadfdt=sf read ${fdtaddr} 0x1C0000 0x40000
spi_nand=sf probe; run spi_loadk spi_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi
  • Update the bootfile and fdtfile environment variables to fit the filename as found inside the TFTP server.
  • Program kernel and device tree on NOR flash with the following U-Boot command
sf probe; run loadk spi_updatek loadfdt spi_updatefdt

E.g.:

=> sf probe; run loadk spi_updatek loadfdt spi_updatefdt
SF: Detected s25fl256s_64k with page size 256 Bytes, erase size 64 KiB, total 32 MiB
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/uImage'.
Load address: 0x82000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################################################
         1022.5 KiB/s
done
Bytes transferred = 4593552 (461790 hex)
SF: 6291456 bytes @ 0x200000 Erased: OK
device 0 offset 0x200000, size 0x461790
SF: 4593552 bytes @ 0x200000 Written: OK
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/am335x-sbcd.dtb'.
Load address: 0x88000000
Loading: #########
         598.6 KiB/s
done
Bytes transferred = 44754 (aed2 hex)
SF: 262144 bytes @ 0x1c0000 Erased: OK
device 0 offset 0x1c0000, size 0xaed2
SF: 44754 bytes @ 0x1c0000 Written: OK


Reboot the system and configure U-Boot to apply the new configuration

=> setenv bootcmd run spi_nand
=> saveenv

NAND flash[edit | edit source]

We assume that the following environment variables are present in u-boot:

nand_updatek=nand erase.part nand-kernel; nand write ${loadaddr} nand-kernel ${filesize}
nand_updatefdt=nand erase.part nand-fdt; nand write ${fdtaddr} nand-fdt ${filesize}

nand_loadk=nand read ${loadaddr} nand-kernel
nand_loadfdt=nand read ${fdtaddr} nand-fdt
nand_nand=run nand_loadk nand_loadfdt nandargs addcons addmisc; if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi


  • Update the bootfile and fdtfile environment variables to fit the filename as found inside the TFTP server.
  • Program kernel and device tree on NAND flash with the following U-Boot command
run loadk nand_updatek loadfdt nand_updatefdt

E.g.:

=> run loadk nand_updatek loadfdt nand_updatefdt
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/uImage'.
Load address: 0x82000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #####################################################
         1010.7 KiB/s
done
Bytes transferred = 4593552 (461790 hex)

NAND erase.part: device 0 offset 0x2c0000, size 0x600000
Erasing at 0x8a0000 -- 100% complete.
OK

NAND write: device 0 offset 0x2c0000, size 0x461790
 4593552 bytes written: OK
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 192.168.0.82; our IP address is 192.168.0.83
Filename 'diva/am335x-sbcd.dtb'.
Load address: 0x88000000
Loading: #########
         682.6 KiB/s
done
Bytes transferred = 44754 (aed2 hex)

NAND erase.part: device 0 offset 0x2a0000, size 0x20000
Erasing at 0x2a0000 -- 100% complete.
OK

NAND write: device 0 offset 0x2a0000, size 0xaed2
 44754 bytes written: OK


Reboot the system and configure U-Boot to apply the new configuration

=> setenv bootcmd run nand_nand
=> saveenv