Difference between revisions of "DESK-XZ7-L/Deployment/Standalone boot"

From DAVE Developer's Wiki
Jump to: navigation, search
Line 30: Line 30:
 
** 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
 
** 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
  
=== Program boot images into NOR flash ===
+
=== Program boot images into internal storage ===
 
+
==== Program the NOR flash ====
====u-Boot====
+
=====u-Boot=====
  
 
Update to the latest u-boot version allows usage of u-boot environment variables available.
 
Update to the latest u-boot version allows usage of u-boot environment variables available.
Line 40: Line 40:
 
</pre>
 
</pre>
  
====fit image ====
+
=====fit image =====
 
 
 
We assume that the following environment variables are present in u-boot:
 
We assume that the following environment variables are present in u-boot:
  
Line 74: Line 73:
 
</pre>
 
</pre>
  
=== Program root file system into NAND flash ===
+
==== Program root file system into NAND flash ====
 
 
 
* Boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]
 
* 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 [[Memory Tecnology Device (MTD)|MTD]] partitions can be dumped with <code>/proc/mtd</code> (the partition's name should be self-explanatory)
 
* 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 [[Memory Tecnology Device (MTD)|MTD]] partitions can be dumped with <code>/proc/mtd</code> (the partition's name should be self-explanatory)
Line 85: Line 83:
 
* Format and initialize ''nand-ubi'' partition, which in our case is <code>mtd7</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:
 
* Format and initialize ''nand-ubi'' partition, which in our case is <code>mtd7</code>, using [[Memory Tecnology Device (MTD)#UBI|UBI]] with:
 
<pre>
 
<pre>
ubiformat /dev/mtd7
+
ubiformat /dev/mtd0
ubiattach -m 7
+
ubiattach -m 0
 
ubimkvol /dev/ubi0 -N rootfs -m
 
ubimkvol /dev/ubi0 -N rootfs -m
 
</pre>
 
</pre>
Line 93: Line 91:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# ubiformat /dev/mtd0
+
root@bora:~# ubiformat /dev/mtd0
 
</pre>
 
</pre>
 
* Now mount the UBI volume using [[Memory Tecnology Device (MTD)#UBIFS|UBIFS]] in a temporary directory
 
* Now mount the UBI volume using [[Memory Tecnology Device (MTD)#UBIFS|UBIFS]] in a temporary directory
Line 104: Line 102:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# mkdir -p /mnt/nand
+
root@bora:~# mkdir -p /mnt/nand
root@sdvx-lite:~# mount -t ubifs ubi0_0 /mnt/nand
+
root@bora:~# mount -t ubifs ubi0_0 /mnt/nand
[ 1810.301461] UBIFS: default file-system created
 
[ 1810.308952] UBIFS: background thread "ubifs_bgt0_0" started, PID 717
 
[ 1810.452274] UBIFS: mounted UBI device 0, volume 0, name "rootfs"
 
[ 1810.459421] UBIFS: LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
 
[ 1810.469398] UBIFS: FS size: 992698368 bytes (946 MiB, 7818 LEBs), journal size 33521664 bytes (31 MiB, 264 LEBs)
 
[ 1810.480976] UBIFS: reserved for root: 4952683 bytes (4836 KiB)
 
[ 1810.487210] UBIFS: media format: w4/r0 (latest is w4/r0), UUID 99D0F3C6-5955-4B30-9E2D-72202281BD30, small LPT model
 
 
</pre>
 
</pre>
 
* you can now extract the root file system into that directory
 
* you can now extract the root file system into that directory
Line 123: Line 114:
 
<pre>
 
<pre>
 
umount /mnt/nand/
 
umount /mnt/nand/
ubidetach -m 7
+
ubidetach -m 0
 
</pre>
 
</pre>
  
Line 129: Line 120:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# umount /mnt/nand/
+
root@bora:~# umount /mnt/nand/
 
[ 2446.743091] UBIFS: un-mount UBI device 0, volume 0
 
[ 2446.743091] UBIFS: un-mount UBI device 0, volume 0
 
[ 2446.749670] UBIFS: background thread "ubifs_bgt0_0" stops
 
[ 2446.749670] UBIFS: background thread "ubifs_bgt0_0" stops
root@sdvx-lite:~# ubidetach -m  
+
root@bora:~# ubidetach -m  
 
[ 2450.738153] UBI: detaching mtd7 from ubi0
 
[ 2450.738153] UBI: detaching mtd7 from ubi0
 
[ 2450.759527] UBI: mtd7 is detached from ubi0
 
[ 2450.759527] UBI: mtd7 is detached from ubi0
Line 142: Line 133:
  
 
<pre>
 
<pre>
nand_args=setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw ubi.mtd=7
+
nand_args=setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw ubi.mtd=0
 
</pre>
 
</pre>
  
Line 161: Line 152:
 
</pre>
 
</pre>
  
====fit image====
+
==== Create the SD card partitions ====
 
 
We assume that the following environment variables are present in u-boot:
 
 
 
<pre>
 
mmc_loadk=fatload mmc ${mmcdev}:1 ${loadaddr} ${bootfile}
 
mmc_loadfdt=fatload mmc ${mmcdev}:1 ${fdtaddr} ${fdtfile}
 
mmc_loadsplash=fatload mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}
 
mmcboot=run mmcargs addcons addmisc; if run mmc_loadk; then if run mmc_loadfdt; then if run configid_fixupfdt; then bootm ${loadaddr} - ${fdtaddr}; fi; fi; fi
 
</pre>
 
 
 
Using an SD card or an eMMC device assumes that <code>bootfile</code>, <code>fdtfile</code> and <code>splashfile</code> are stored into fist MMC device partition.
 
 
 
Then, u-boot uses the previous listed commands for reading the binary images and starting the linux bootstrap from the ''MMC part 2'' (which is reserved for the root-file system storage).
 
 
 
The following u-boot environment variables are present for this purposes:
 
<pre>
 
mmcargs=setenv bootargs root=${mmcroot}
 
mmcroot=/dev/mmcblk2p2 rootwait rw
 
</pre>
 
 
 
==== boot vars ====
 
 
 
The following environment variables should be configured for u-boot properly reading the boot files from the first SD card partition, e.g.
 
 
 
<pre class="workstation-terminal">
 
=> setenv normalboot mmcboot
 
=> setenv bootfile
 
</pre>
 
 
 
then save the environment and reboot the system to apply the new configuration:
 
 
 
<pre class="workstation-terminal">
 
=> saveenv
 
Saving Environment to MMC...
 
Writing to MMC(2)... done
 
=> reset
 
</pre>
 
 
 
=== Program root file system into SD card ===
 
 
 
 
* Boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]
 
* Boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]
* eMMC device has to be partitioned and properly formatted choosing the <code>file system</code> for each partition
+
* SD device has to be partitioned and properly formatted choosing the <code>file system</code> for each partition
 
* an example of SD partitioning script is the following one:
 
* an example of SD partitioning script is the following one:
  
==== FAT32 partition ====
 
 
<pre>
 
<pre>
 
#!/bin/sh
 
#!/bin/sh
Line 251: Line 201:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# ./sdcard-partition.sh /dev/mmcblk2
+
root@bora:~# ./sdcard-partition.sh /dev/mmcblk2
 
SD total size: 3776KB
 
SD total size: 3776KB
 
[ 1341.905014]  mmcblk2: p1 p2
 
[ 1341.905014]  mmcblk2: p1 p2
Line 299: Line 249:
 
Writing superblocks and filesystem accounting information: done
 
Writing superblocks and filesystem accounting information: done
  
root@sdvx-lite:~#
+
root@bora:~#  
 
</pre>
 
</pre>
  
 
* create a mount point and mount the first partition  
 
* create a mount point and mount the first partition  
 
<pre>
 
<pre>
mkdir -p /mnt/emmc
+
root@bora:~# mkdir -p /mnt/sd
mount /dev/mmcblk2p1 /mnt/emmc
+
root@bora:~# mount /dev/mmcblk0p1 /mnt/sd
 
</pre>
 
</pre>
  
Line 311: Line 261:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# mount /dev/mmcblk0p2 /mnt/sd
+
root@bora:~# cp images/linux/BOOT.BIN /mnt/sd
root@sdvx-lite:~# cd /mnt/emmc
+
root@bora:~# cp images/linux/image.ub /mnt/sd
root@sdvx-lite:/mnt/emmc# cp /tftpboot/xxxxx .
+
root@bora:~# cp images/linux/boot.scr /mnt/sd
root@sdvx-lite:/mnt/emmc# cd
 
root@sdvx-lite:~# umount /mnt/emmc
 
 
</pre>
 
</pre>
  
* now mount the EXT4 volume in the temporary directory
+
==== Program root file system into SD card ====
 +
Now, you can extract the root file system into that directory
  
E.g.:
+
* mount the <code>ext3/ext4</code> volume in the temporary directory
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:~# mount /dev/mmcblk2p2 /mnt/emmc
+
root@bora:~# mount /dev/mmcblk0p2 /mnt/sd
 
[ 1810.899327] EXT4-fs (mmcblk2p2): mounted filesystem with ordered data mode. Opts: (null)
 
[ 1810.899327] EXT4-fs (mmcblk2p2): mounted filesystem with ordered data mode. Opts: (null)
root@sdvx-lite:~# cd /mnt/emmc
+
root@bora:~#
root@sdvx-lite:/mnt/emmc#  
 
 
</pre>
 
</pre>
  
* you can now extract the root file system into that directory
+
<pre class="workstation-terminal">
 
+
root@bora:~# tar xf images/linux/rootfs.tar.gz -C /mnt/sd
<pre>
 
tar xvjf sdvx-1.0.1_image-devel-sdvx-lite.tar.bz2
 
 
</pre>
 
</pre>
  
Line 338: Line 284:
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
root@sdvx-lite:/mnt/emmc# cd
+
root@bora:/mnt/sd# cd
root@sdvx-lite:~# umount /mnt/emmc
+
root@bora:~# umount /mnt/sd
root@sdvx-lite:~# reboot
+
root@bora:~# reboot
 
</pre>
 
</pre>
  
Line 350: Line 296:
 
</pre>
 
</pre>
  
==== ext4 partition ====
 
For using an <b>ext4</b> partition also for boot files, it is possibile to change the formatting script:
 
 
{ echo ${boot_start},${boot_size},'''83''',-; echo ${rfs_start},${rfs_size},83,-; } | sfdisk --force ${node}
 
 
and formatting the first partition using ''mkfs.ext4''
 
 
mkfs.ext4 -F ${node}${part}1 -Lboot
 
 
then, the u-boot <code>environment</code> has to be properly configured:
 
 
<pre class="workstation-terminal">
 
=> setenv mmc_loadk 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
 
=> setenv mmc_loadfdt 'ext4load mmc ${mmcdev}:1 ${fdtaddr} ${fdtfile}'
 
=> setenv mmc_loadsplash 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}'
 
=> saveenv
 
</pre>
 
  
 
----
 
----
  
 
[[Category:BORA]]
 
[[Category:BORA]]

Revision as of 09:53, 21 November 2022

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 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
  • 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

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

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

u-Boot[edit | edit source]

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

mmc_update=mmc dev; setexpr blocks ${filesize} / 0x200; setexpr blocks ${blocks} + 1; mmc write ${loadaddr} 2 ${blocks}

Load u-boot binary form a tftp server:

=> run load
=> run mmc_update

Create the SD card partitions[edit | edit source]

  • Boot the system via SD or NFS as described in the e [[(<KIT>)#Quick_start_guide|Quick start guide]]
  • 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
BOOTLOAD_RESERVE=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 ${BOOTLOAD_RESERVE} \\* 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.

root@bora:~# ./sdcard-partition.sh /dev/mmcblk2
SD total size: 3776KB
[ 1341.905014]  mmcblk2: p1 p2
Checking that no-one is using this disk right now ... OK

Disk /dev/mmcblk2: 3.7 GiB, 3959422976 bytes, 7733248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical):[ 1341.922729]  mmcblk2: p1 p2
 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa77eb3f0

Old situation:

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk2p1        2048  264191  262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk2p2      264192 4458495 4194304    2G 83 Linux

>>> Created a new DOS disklabel with disk identifier 0xcce0c36f.
Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 128 MiB.
/dev/mmcblk2p2: Created a new partition 2 of type 'Linux' and of size 2 GiB.
/dev/mmcblk2p3:
New situation:

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk2p1       16384  278527  262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk2p2      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 3.0.28 (2015-05-16)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
formatting rfs
mke2fs 1.43-WIP (18-May-2015)
Discarding device blocks: done
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 9a685543-1af2-4e39-83f3-b8a32248c021
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

root@bora:~# 
  • 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 images/linux/BOOT.BIN /mnt/sd
root@bora:~# cp images/linux/image.ub /mnt/sd
root@bora:~# cp images/linux/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:/mnt/sd# cd
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