DESK-MX8M-L/Deployment/Standalone boot

From DAVE Developer's Wiki
< DESK-MX8M-L
Revision as of 15:29, 16 February 2022 by U0007 (talk | contribs) (Partitioning)

Jump to: navigation, search
History
Version Issue Date Notes
1.0.0 Feb 2022 First DESK-MX8M-L 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 on 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 of a system microSD card or an NFS server, with threee 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 NAND only
    • in this configuration the whole system will boot without the need of a NOR flash storage, all images and the root file system will be fetched from NAND flash
  • booting with eMMC only
    • in this configuration the whole system will boot without the need of a NOR/NAND flashes storage, all images and the root file system will be fetched from eMMC flash


200px-Emblem-important.svg.png

In the following paragraphs, we will take into account a real case using an embedded eMMC mounted in the ORCA or MITO 8M Mini SOMs

Program boot images into eMMC[edit | edit source]

Boot[edit | edit source]

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

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

Load Boot binary form a tftp server:

u-boot=> run load
Using ethernet@30be0000 device
TFTP from server 192.168.0.13; our IP address is 192.168.0.90
Filename 'desk-mx8m/flash.bin'.
Load address: 0x40480000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ########
         1.8 MiB/s
done
Bytes transferred = 8355840 (7f8000 hex)
u-boot=>

or load Boot binary form an SD card:

Hit ENTER within 1 seconds to stop autoboot
u-boot=> fatload mmc 1:1 ${loadaddr} flash.bin
8355840 bytes read in 373 ms (21.4 MiB/s)
u-boot=>

Program the Boot image on eMMC:

u-boot=> mmc dev 2
switch to partitions #0, OK
mmc2(part 0) is current device
u-boot=> run mmc_update
switch to partitions #0, OK
mmc2(part 0) is current device

MMC write: dev # 2, block # 64, count 16319 ... 16319 blocks written: OK
u-boot=>

Configuring the u-boot environment[edit | edit source]

Once the Boot Image has been correctly programmed, start the system from eMMC in order to configure/program the u-boot environment variables for a correct boot sequence.

kernel image and device tree[edit | edit source]

The following environment variables has to be set (or at least checked) in u-boot; depending on the formatted eMMC partition (FAT32 or ext4), the vars has to be properly modified:

FAT32[edit | edit source]

setenv mmc_loadk 'fatload mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
setenv mmc_loadfdt 'fatload mmc ${mmcdev}:1 ${fdt_addr} ${fdt_file}'
setenv mmc_loadsplash 'fatload mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}'

ext4[edit | edit source]

setenv mmc_loadk 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
setenv mmc_loadfdt 'ext4load mmc ${mmcdev}:1 ${fdt_addr} ${fdt_file}'
setenv mmc_loadsplash 'ext4load mmc ${mmcdev}:1 ${loadaddr} ${splashfile}; cp.b ${loadaddr} ${splashimage} ${filesize}'

Then, u-boot uses the previously listed commands for reading the binary images and starting the Linux file system from the eMMC part 2 (which is reserved for the root-file system storage):

setenv mmcboot 'run mmcargs addcons addmisc; if run mmc_loadk; then if run mmc_loadfdt; then if run configid_fixupfdt; then booti ${loadaddr} - ${fdtaddr}; fi; fi; fi'
setenv mmcargs 'setenv bootargs root=${mmcroot}'
setenv mmcroot '/dev/mmcblk2p2 rootwait rw'

boot vars[edit | edit source]

The following environment variables should be configured for u-boot properly identify the boot files, e.g.

setenv normalboot mmcboot
setenv bootfile Image
setenv fdt_file imx8mp-mito8mplus-cb1001.dtb
setenv splashfile splash_image.bmp

then save the environment and reboot the system to apply the new configuration:

u-boot=> saveenv
Saving Environment to MMC...
Writing to MMC(2)... done
u-boot=> reset

Program root file system into eMMC[edit | edit source]

  • boot the system via SD or NFS as described in the e Booting from NFS
  • eMMC 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:

Partitioning[edit | edit source]

#!/bin/sh

node=$1

# partition size in MB
BOOTLOAD_RESERVE=8
BOOT_SIZE=2048
RFS_SIZE=4096

# 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_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},83,-; echo ${rfs_start},${rfs_size},83,-; } | sfdisk --force ${node}

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

E.g.


root@desk-mx8mp:~# ./emmc_partition.sh /dev/mmcblk2
SD total size: 7457KB
[  238.978157]  mmcblk2: p1 p2 p3
Checking that no-one is using this disk right now ... OK

Disk /dev/mmcblk2: 7.29 GiB, 7820083200 bytes, 15273600 sectors
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: 0xbe0f0cf6

Old situation:

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk2p1         32768   524288   491521  240M  c W95 FAT32 (LBA)
/dev/mmcblk2p2        524289 12058623 11534335  5.5G 83 Linux
/dev/mmcblk2p3      12058624 15273599  3214976  1.5G 83 Linux

>>> Created a new DOS disklabel with disk identifier 0x7b310a69.
/dev/mmcblk2p1: Created a new partition 1 of type 'Linux' and of size 2 GiB.
/dev/mmcblk2p2: Created a new partition 2 of type 'Linux' and of size 4 GiB.
/dev/mmcblk2p3: Done.

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

Device         Boot   Start      End Sectors Size Id Type
/dev/mmcblk2p1        16384  4210687 4194304   2G 83 Linux
/dev/mmcblk2p2      4210688 12599295 8388608   4G 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
[  239.419641]  mmcblk2: p1 p2
Syncing disks.
formatting boot
mke2fs 1.45.3 (14-Jul-2019)
Discarding device blocks: done
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 48ad5de1-5ffe-4ed9-b7e0-bdc05d0b8052
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

formatting rfs
mke2fs 1.45.3 (14-Jul-2019)
Discarding device blocks: done
Creating filesystem with 1048576 4k blocks and 262144 inodes
Filesystem UUID: aacf8195-ddbd-4fdc-a83e-99f57659367e
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@desk-mx8mp:~#
  • create a mount point and mount the first partition
mkdir -p /mnt/emmc
mount /dev/mmcblk2p1 /mnt/emmc
  • copy kernel, dtb and splash_image files from SD card
root@sdvx-lite:~# mount /dev/mmcblk2p1 /mnt/emmc
[  314.432392] EXT4-fs (mmcblk2p1): mounted filesystem with ordered data mode. Opts: (null)
root@desk-mx8mp:~# mkdir -p /mnt/sd
root@desk-mx8mp:~# mount /dev/mmcblk1p1 /mnt/sd
root@desk-mx8mp:~# cp /mnt/sd/* /mnt/emmc/
root@desk-mx8mp:~# umount /mnt/emmc
  • now mount the EXT4 volume in the temporary directory

E.g.:

root@desk-mx8mp:~# mount /dev/mmcblk2p2 /mnt/emmc
[  433.481899] EXT4-fs (mmcblk2p2): mounted filesystem with ordered data mode. Opts: (null)
root@desk-mx8mp:~# cd /mnt/emmc/
root@desk-mx8mp:/mnt/emmc#
  • you can now extract the root file system into that directory
tar xvjf dave-image-devel-desk-mx8mp.tar.bz2
  • finally, you need to cleanly umount and safely reboot or turn off the system.
root@desk-mx8mp:/mnt/emmc# cd
root@desk-mx8mp:~# umount /mnt/emmc
root@desk-mx8mp:~# reboot

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

u-boot=> setenv bootcmd run mmcboot
u-boot=> saveenv