DESK-XZ7-L/Deployment/Standalone boot

From DAVE Developer's Wiki
< DESK-XZ7-L
Revision as of 12:27, 21 November 2022 by U0007 (talk | contribs) (Create the SD card partitions)

Jump to: navigation, search
History
ID# Issue Date Notes

17xxx

Q1 2023 DESK-XZ7-L 1.0.0 release


Standalone boot[edit | edit source]

Introduction[edit | edit source]

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


200px-Emblem-important.svg.png

The following programming examples are intended for laboratory usage or for preliminary deployment strategy.

A complete deployment strategy has to be carefully identifiyed taking into account the overall arguments like: boot speed, safe boot, recovery mechanisms, watchdog supervisor, etc.


We'll explain how to program and configure a <SOM> to boot in standalone mode, without the need for a system microSD card or an NFS server, with three options:

  • booting with SD only
    • in this configuration the whole system will boot without the need for a NOR/NAND flashes storage, all images and the root file system will be fetched from the SD card
  • booting with NOR and NAND internal storage
    • in this configuration the primary boot images will be fetched from NOR flash storage, while the root file system will be fetched from NAND flash

Program boot images into SD card[edit | edit source]

The SD card should have at least 2 partition:

  • the first must be an FAT32 partition (type b) with size of at least 64MB
  • the second is a normal linux partition (type 83) of at least 512M with ext3/ext4 filesystem

Create the SD card partitions[edit | edit source]

  • SD device has to be partitioned and properly formatted choosing the file system for each partition
  • an example of SD partitioning script is the following one:
#!/bin/sh

node=$1

# partition size in MB
RESERVED=8
BOOT_ROM_SIZE=128
RFS_SIZE=2048

# create the SDCARD partition
part=""
echo ${node} | grep mmcblk > /dev/null
if [ "$?" -eq "0" ]; then
        part="p"
fi

# print the SD total capacity
total_size=`sfdisk -s ${node}`
total_size=`expr ${total_size} / 1024`
echo SD total size: ${total_size}KB

# calculate partition sizes
boot_start=`expr ${RESERVED} \\* 1024 \\* 1024 / 512`
boot_size=`expr ${BOOT_ROM_SIZE} \\* 1024 \\* 1024 / 512`
rfs_start=`expr ${boot_size} + ${boot_start}`
rfs_size=`expr ${RFS_SIZE} \\* 1024 \\* 1024 / 512`

umount ${node}${part}1 > /dev/null 2>&1
umount ${node}${part}2 > /dev/null 2>&1

# call sfdisk to create partition table
{ echo ${boot_start},${boot_size},0c,-; echo ${rfs_start},${rfs_size},83,-; } | sfdisk --force ${node}

# format the SDCARD partition
echo "formatting boot"
mkfs.vfat -F 32 -n BOOT  ${node}${part}1
echo "formatting rfs"
mkfs.ext4 -F ${node}${part}2 -Lrfs

E.g.

vdk@vagrant:~/desk-xz-l$ sudo ./sdcard-partition.sh /dev/sdc
SD total size: 7580KB
Checking that no-one is using this disk right now ... OK

Disk /dev/sdc: 7.41 GiB, 7948206080 bytes, 15523840 sectors
Disk model: STORAGE DEVICE  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd775a452

Old situation:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1        8192 15523839 15515648  7.4G  b W95 FAT32

>>> Created a new DOS disklabel with disk identifier 0x3f242b9b.
/dev/sdc1: Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 128 MiB.
/dev/sdc2: Created a new partition 2 of type 'Linux' and of size 2 GiB.
Partition #2 contains a ext4 signature.
/dev/sdc3: Done.

New situation:
Disklabel type: dos
Disk identifier: 0x3f242b9b

Device     Boot  Start     End Sectors  Size Id Type
/dev/sdc1        16384  278527  262144  128M  c W95 FAT32 (LBA)
/dev/sdc2       278528 4472831 4194304    2G 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
formatting boot
mkfs.fat 4.1 (2017-01-24)
formatting rfs
mke2fs 1.45.5 (07-Jan-2020)
/dev/sdc2 contains a ext4 file system labelled 'rfs'
        created on Mon Nov 21 13:14:20 2022
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: cc691ca0-1eb4-4ff9-87cc-da74f9e91685
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

dvdk@vagrant:~/desk-xz-l$ 

Then, insert the SD card in the target and boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]

  • create a mount point and mount the first partition
root@bora:~# mkdir -p /mnt/sd
root@bora:~# mount /dev/mmcblk0p1 /mnt/sd
  • copy boot image files
root@bora:~# cp BOOT.BIN /mnt/sd
root@bora:~# cp image.ub /mnt/sd
root@bora:~# cp boot.scr /mnt/sd

Program root file system into SD card[edit | edit source]

Now, you can extract the root file system into that directory

  • mount the ext3/ext4 volume in the temporary directory
root@bora:~# mount /dev/mmcblk0p2 /mnt/sd
[ 1810.899327] EXT4-fs (mmcblk2p2): mounted filesystem with ordered data mode. Opts: (null)
root@bora:~#
root@bora:~# tar xf images/linux/rootfs.tar.gz -C /mnt/sd
  • finally, you need to cleanly umount and safely reboot or turn off the system.
root@bora:~# umount /mnt/sd
root@bora:~# reboot

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

=> setenv bootcmd run mmcboot
=> saveenv

Program boot images into internal storage[edit | edit source]

Program the NOR flash[edit | edit source]

u-Boot[edit | edit source]

Update to the latest u-boot version allows usage of u-boot environment variables available.

=> run load
fit image[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 200000 800000; sf write ${loadaddr} 200000 ${filesize}
spi_updatefdt=sf erase 180000 80000; sf write ${fdtaddr} 180000 ${filesize}
spi_loadk=sf read ${loadaddr} 200000 800000
spi_loadfdt=sf read ${fdtaddr} 180000 80000
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

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

=> setenv bootcmd run spi_nand
=> saveenv

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

  • Boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]
  • 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)


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-ubi partition, which in our case is mtd7, using UBI with:
ubiformat /dev/mtd0
ubiattach -m 0
ubimkvol /dev/ubi0 -N rootfs -m

E.g.

root@bora:~# ubiformat /dev/mtd0
  • 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@bora:~# mkdir -p /mnt/nand
root@bora:~# mount -t ubifs ubi0_0 /mnt/nand
  • you can now extract the root file system into that directory
tar xvjf -C /mnt/nand
  • finally, you need to cleanly umount and detach the MTD partition
umount /mnt/nand/
ubidetach -m 0

E.g.

root@bora:~# umount /mnt/nand/
[ 2446.743091] UBIFS: un-mount UBI device 0, volume 0
[ 2446.749670] UBIFS: background thread "ubifs_bgt0_0" stops
root@bora:~# ubidetach -m 
[ 2450.738153] UBI: detaching mtd7 from ubi0
[ 2450.759527] UBI: mtd7 is detached from ubi0

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

nand_args=setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw ubi.mtd=0