Difference between revisions of "DESK-MX8M-L/Development/How to create a bootable microSD card"

From DAVE Developer's Wiki
Jump to: navigation, search
(7 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
!colspan="4" style="width:100%; text-align:left"; border-bottom:solid 2px #ededed"|History
 
!colspan="4" style="width:100%; text-align:left"; border-bottom:solid 2px #ededed"|History
 
|-  
 
|-  
|-
+
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Version
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Issue Date
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Issue Date
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
 
|-
 
|-
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|{{oldid|16139|2022/02/17}}
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|1.0.0
 +
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Feb 2022
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|First DESK-MX8M-L release
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|First DESK-MX8M-L release
 
|-
 
|-
| style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |{{oldid|17546|2023/02/24}}
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|2.0.0
| style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |DESK-MX8M-L-2.0.0 release
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Feb 2023
|-
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|DESK-MX8M-L-2.0.0 release
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |2023/08/23
 
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |DESK-MX8M-L-4.0.0 release
 
 
|-
 
|-
 
|}
 
|}
Line 23: Line 22:
 
==How to create a bootable SD card==
 
==How to create a bootable SD card==
  
This article shows how to (re)create the bootable SD card, from the binary images produced by the DESK-MX-L Yocto build, using a standard SD image flasher like [https://etcher.balena.io/ balenaEtcher]
+
{{ImportantMessage|text=The procedure described here was tested with a physical machine. In case of a virtual machine such as the [[Managed_Virtual_Machine_(MVM)|MVM]], it might not work properly. Also, it is worth remembering that USB controller of the MVM is disabled by default. See also [[MVM_FAQs#Q:_How_to_use_the_USB_devices_connected_to_the_host_machine.3F|this section]].}}
 +
 
 +
 
 +
This article shows how to create a bootable microSD for the [[DESK-MX8M-L/General/Release_Notes_(DESK-MX8M-L)|DESK-MX8M-L Release Notes] kit by using a simple bash script. <br>
 +
'''Note:''' Starting from this release the support for the SPL has been introduced in Uboot. Previous versions of this script will no longer produce a fully functional and bootable microSD card. <br>
 +
 +
The procedure has been tested on a Linux PC running Ubuntu LTS (>=16.04) distribution with
 +
*a 16 GB microSD card [1]
 +
*the binary files delivered along with the [[DESK-MX8M-L/General/Release_Notes#Downloadable_binary_images|DESKMX8M-L 2.0.0]].
 +
The resulting card is partitioned as depicted [[ORCA_SOM/ORCA_Evaluation_Kit/Getting_started/Unboxing#microSD_Layout|here]].
 +
 
 +
The script - named <code>mksd.sh</code> - can be realized with the following code:
 +
<pre>
 +
#!/bin/bash
 +
 
 +
if [[ -z $1 || -z $2 || -z $3 || -z $4 ]]
 +
then
 +
echo "$0 Usage:"
 +
echo " $0 <device> <flash.bin> <binaries directory> <rootfs tar.bz2>"
 +
echo " Example: $0 /dev/sdc flash.bin binaries/ rootfs.tar.bz2"
 +
exit
 +
fi
 +
 
 +
if [ "$(whoami)" != "root" ]
 +
then
 +
echo "you must be root to run this script!"
 +
exit
 +
fi
 +
 
 +
if ! [[ -b $1 ]]
 +
then
 +
echo "$1 is not a valid block device!"
 +
exit
 +
fi
 +
 
 +
if ! [[ -e $2 ]]
 +
then
 +
echo "Incorrect flash.bin location!"
 +
exit
 +
fi
 +
 
 +
if ! [[ -d $3 ]]
 +
then
 +
echo "Incorrect Binaries location!"
 +
exit
 +
fi
 +
 
 +
if ! [[ -f $4 ]]
 +
then
 +
echo "Incorrect rootfs location!"
 +
exit
 +
fi
 +
 
 +
DRIVE=$1
 +
if [[ "$DRIVE" == *"mmcblk"* ]]
 +
then
 +
echo "You're using a mmc device, I need to fix partition names"
 +
PART="p"
 +
else
 +
PART=""
 +
fi
 +
BOOT=$2
 +
BINARIES=$3
 +
RFS=$4
 +
 
 +
echo "All data on "$DRIVE" now will be destroyed! Continue? [y/n]"
 +
read ans
 +
if ! [ $ans == 'y' ]
 +
then
 +
exit
 +
fi
 +
 
 +
echo "[Partitioning $1...]"
 +
 
 +
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
 +
 
 +
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
 +
 
 +
echo DISK SIZE - $SIZE bytes
 +
 
 +
CYLINDERS=`echo $SIZE/255/63/512 | bc`
 +
 
 +
# check if we're running an old (e.g. 2.20.x) or new (e.g. 2.24.x) sfdisk
 +
sfdisk --help | grep -- -H
 +
 
 +
if [ "$?" -eq "0" ]
 +
then
 +
{
 +
echo 40,1380,0x0c,*
 +
echo 1420,,83,-
 +
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
 +
else
 +
{
 +
    echo 16M,8176M,0x0c,*
 +
    echo 8192M,,83,-
 +
} | sfdisk $DRIVE
 +
fi
 +
 
 +
partprobe
 +
 
 +
 
 +
echo "[Making filesystems...]"
 +
mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/null
 +
mkfs.ext3 -F -L ROOTFS "$DRIVE$PART"2 #> /dev/null
 +
 
 +
echo "[Copying files...]"
 +
 
 +
binaries_dir=${BINARIES%/}
 +
mount "$DRIVE$PART"1 /mnt
 +
cp -av --no-preserve=ownership $binaries_dir/* /mnt/
 +
umount "$DRIVE$PART"1
 +
 
 +
echo "[Extracting rfs (this may take a while...)]"
 +
mount "$DRIVE$PART"2 /mnt
 +
tar jxf $RFS -C /mnt > /dev/null
 +
chmod 755 /mnt
 +
umount "$DRIVE$PART"2
 +
 
 +
echo "[Programming flash.bin]"
 +
dd if=$BOOT of=$DRIVE bs=1k seek=32 conv=fsync
 +
 
 +
echo "[Done]"
 +
</pre>
 +
Attention, if you are making a uSD for MITO 8M Mini SOM, then the last line must be modified with <code>dd if=$BOOT of=$DRIVE bs=1k seek=33</code>
 +
Here is an example that shows how to use this script. Let's assume that the binary files were downloaded in the <code>sdcard</code> subdirectory of the working directory. Before invoking the script, the following files has to be renamed in order to make them compatible with the default U-Boot environment variables:
 +
* bootscript: <code>boot.scr</code>
 +
* Linux kernel: <code>Image</code>
 +
* Device tree blob: <code>imx8mp-mito8mplus-cb1008.dtb</code> or <code>imx8mm-mito8mmini.dtb</code>
 +
 
 +
This is the list of the binary files that will be used by the script:
 +
 
 +
<pre class="workstation-terminal">
 +
dvdk@vagrant:~/desk-mx-l/sdcard$ ls -laR
 +
.:
 +
total 734040
 +
drwxrwxr-x 3 dvdk dvdk      4096 Feb 16 09:41 .
 +
drwxr-xr-x 7 dvdk dvdk      4096 Feb 16 09:21 ..
 +
drwxrwxr-x 2 dvdk dvdk      4096 Feb 16 09:41 binaries
 +
-rwxrwxr-x 1 dvdk dvdk 743273295 Feb 16 09:34 dave-image-devel-desk-mx8mp.tar.bz2
 +
-rw-r--r-- 1 root root  1304608 Feb 16 09:32 flash.bin
 +
-rwxrwxr-x 1 dvdk dvdk      1908 Feb 16 09:22 mksd.sh
 +
 
 +
./binaries:
 +
total 27604
 +
drwxrwxr-x 2 dvdk dvdk    4096 Feb 16 09:41 .
 +
drwxrwxr-x 3 dvdk dvdk    4096 Feb 16 09:41 ..
 +
-rw-rw-r-- 1 dvdk dvdk      695 Feb 16 09:41 boot.scr
 +
-rw-r--r-- 1 dvdk dvdk 28150272 Feb 16 09:35 Image
 +
-rw-r--r-- 1 dvdk dvdk    40521 Feb 16 09:35 imx8mm-mito8mmini.dtb
 +
-rw-r--r-- 1 dvdk dvdk    58111 Feb 16 09:35 imx8mp-mito8mplus-cb1008.dtb
 +
dvdk@vagrant:~/desk-mx-l/sdcard$
 +
</pre>
 +
You can now run the script, by passing the following parameters:
 +
*Device file of the microSD card (<code>/dev/sdb</code> in the example)
 +
*Boot image
 +
*Path of the directory containing the bootscript file, the Linux kernel image, and the device tree blob files
 +
*Archive of the target's root file system (compressed as <code>.tar.bz2</code> file).
 +
<pre class="workstation-terminal">
 +
dvdk@vagrant:~/desk-mx-l/sdcard$ sudo ./mksd.sh /dev/sdb flash.bin binaries/ dave-image-devel-desk-mx8mp.tar.bz2
 +
All data on /dev/sdb now will be destroyed! Continue? [y/n]
 +
y
 +
[Partitioning /dev/sdb...]
 +
1024+0 records in
 +
1024+0 records out
 +
1048576 bytes (1.0 MB, 1.0 MiB) copied, 3.03198 s, 346 kB/s
 +
DISK SIZE - 15931539456 bytes
 +
Checking that no-one is using this disk right now ... OK
 +
 
 +
Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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
 +
 
 +
>>> Created a new DOS disklabel with disk identifier 0xcd2d3b4e.
 +
Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 8 GiB.
 +
/dev/sdb2: Created a new partition 2 of type 'Linux' and of size 6.9 GiB.
 +
/dev/sdb3:
 +
New situation:
 +
 
 +
Device    Boot    Start      End  Sectors  Size Id Type
 +
/dev/sdb1  *      32768 16777215 16744448    8G  c W95 FAT32 (LBA)
 +
/dev/sdb2      16777216 31116287 14339072  6.9G 83 Linux
  
The process is relatively straightforward: it consists of writing the WIC file of interest generated by Yocto onto the SD card.  
+
The partition table has been altered.
The following instruction explains how to use ''balenaEtcher'' on a Windows host. The procedure is similar when working with a Linux host.
+
Calling ioctl() to re-read partition table.
* download the desired binary image to flash (<code>*.wic</code> or <code>*.wic.bz2</code>) from the [https://mirror.dave.eu/desk-mx-l/ mirror binary server] selecting the proper [[DESK-MX8M-L | DESK-MX8M-L]] release
+
Syncing disks.
**among the binaries made available in the [[mirror:desk-mp1-l/| mirror]] there are several <code>*.wic.bz2</code> files for the available releases. In particular, there is the <code>dave-image-devel-desk-mx8mp.wic.bz2</code> (for ORCA) or <code>dave-image-devel-desk-mx8mm.wic.bz2</code> (for MITO8M Mini) files. This image is the one used to program the microSD card delivered along with the evaluation kit.
+
[Making filesystems...]
* connect the microSD card to the PC Host
+
mkfs.fat 3.0.28 (2015-05-16)
* open balenaEtcher tool
+
mke2fs 1.42.13 (17-May-2015)
* once the tool is open:
+
Creating filesystem with 1792384 4k blocks and 448800 inodes
** select the binary to flash by clicking on "Flash from file"
+
Filesystem UUID: ce8daece-3f58-4b43-bd11-7bafd10bba73
** select the microSD to flash by clicking on "Select target"
+
Superblock backups stored on blocks:
** flash the uSD by clicking o "Flash".
+
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
  
{| class="wikitable" style="text-align: center"
+
Allocating group tables: done                           
|[[File:DESK-MP1-L-1.0.0 balenaEtcher unpack.png|center|thumb|200x200px|Unpacking]]
+
Writing inode tables: done                           
|[[File:DESK-MP1-L-1.0.0 balenaEtcher flash.png|center|thumb|200x200px|Flashing]]
+
Creating journal (32768 blocks): done
|[[File:DESK-MP1-L-1.0.0 balenaEtcher valid.png|center|thumb|200x200px|Validating]]
+
Writing superblocks and filesystem accounting information: done
|}
+
 
 +
[Copying files...]
 +
'binaries/boot.scr' -> '/mnt/boot.scr'
 +
'binaries/Image' -> '/mnt/Image'
 +
'binaries/imx8mm-mito8mmini.dtb' -> '/mnt/imx8mm-mito8mmini.dtb'
 +
'binaries/imx8mp-mito8mplus-cb1008.dtb' -> '/mnt/imx8mp-mito8mplus-cb1008.dtb'
 +
[Extracting rfs (this may take a while...)]
 +
[Programming flash.bin]
 +
1274+0 records in
 +
1274+0 records out
 +
1304608 bytes (1.3 MB, 1.3 MiB) copied, 4.1375 s, 344 kB/s
 +
[Done]
 +
dvdk@vagrant:~/desk-mx-l/sdcard$
 +
</pre>
 +
 
 +
[1] In case you have a different size, you'll need to change the <code>sfdisk</code> parameters accordingly.
 +
 
 +
===boot.scr ===
 +
 
 +
Once you got the new binaries compiled from your modified sources, they have to be installed on the first SD partition preserving the original file names used into <i>boot.scr</i> u-boot bootscript.
 +
 
 +
Here below there is an example on how to create a <code>boot.scr</code> file from the '''bootscript.txt''' for booting from SD card:
 +
 
 +
* for [[ORCA SOM | ORCA SOM]]
 +
<pre>
 +
echo 'bootscript generated with command "mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr"'
 +
 
 +
setenv fdtfile imx8mp-mito8mplus-cb1008.dtb
 +
setenv bootfile Image
 +
setenv mmc_loadk 'fatload mmc ${sd_dev}:1 ${loadaddr} ${bootfile}'
 +
setenv mmc_loadfdt 'fatload mmc ${sd_dev}:1 ${fdt_addr} ${fdtfile}'
 +
setenv mmcboot 'run mmc_loadk; run mmc_loadfdt; run bootk'
 +
setenv bootargs 'console=ttymxc1,115200 earlycon=ec_imx6q,0x30890000,115200 root=/dev/mmcblk1p2'
 +
setenv bootk 'booti ${loadaddr} - ${fdt_addr}'
 +
 
 +
echo Booting DESK-MX8M via mmcboot with ${fdtfile} as device tree
 +
 
 +
run mmcboot
 +
 
 +
echo mmcboot FAILURE
 +
</pre>
 +
 
 +
* for [[MITO 8M Mini SOM | MITO 8M Mini SOM]]
 +
<pre>
 +
echo 'bootscript generated with command "mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr"'
 +
 
 +
setenv fdtfile imx8mm-mito8mmini.dtb
 +
setenv bootfile Image
 +
setenv mmc_loadk 'fatload mmc ${sd_dev}:1 ${loadaddr} ${bootfile}'
 +
setenv mmc_loadfdt 'fatload mmc ${sd_dev}:1 ${fdt_addr} ${fdtfile}'
 +
setenv mmcboot 'run mmc_loadk; run mmc_loadfdt; run bootk'
 +
setenv bootargs 'console=ttymxc1,115200 earlycon=ec_imx6q,0x30890000,115200 root=/dev/mmcblk1p2'
 +
setenv bootk 'booti ${loadaddr} - ${fdt_addr}'
  
=== SD card structure ===
+
echo Booting DESK-MX8M via mmcboot with ${fdtfile} as device tree
The created SD card has the following structure:
 
* raw sectors for the bootloader storage: tipically this is a 8MB raw part where storing the bootloader binaries (like <code>imx8mp_flash.bin</code>) for the bootrom startup
 
* <code>FAT32</code> first partition: this will be mapped to the <code>/dev/mmcblk1p1</code> device in Linux
 
** usually this partition contains the Linux kernel binary and the device tree blob
 
** the splash screen image is stored in this partition too for a splash image showing during U-Boot startup
 
* <code>ext4</code> second partition: this will be mapped to the <code>/dev/mmcblk1p2</code> device in Linux
 
** this partition contains the Linux ''root file system''
 
  
=== Creating the SD card from binary artifacts ===
+
run mmcboot
  
Even if the overall binary artifacts have been created by the Yocto build, it is highly discouraged to manually create the SD card starting from them.
+
echo mmcboot FAILURE
 +
</pre>
  
The Yocto build take care about the overall binary consistance (like kernel modules and so on) avoiding to mistmatch different version.
+
and compile it using:
  
Moreover, the SD card is intended to be used during the development process and not for the production phase (where other deployment specifications and details have to be taken into account).
+
<pre>
 +
mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr
 +
</pre>
  
 +
Then copy the ''boot.scr'' into the <code><binaries_dir></code> directories used by the script to create the SD card.
  
 
----
 
----
  
 
[[Category:ORCA]] [[Category:MITO 8M Mini]]
 
[[Category:ORCA]] [[Category:MITO 8M Mini]]

Revision as of 11:57, 14 February 2023

History
Version Issue Date Notes
1.0.0 Feb 2022 First DESK-MX8M-L release
2.0.0 Feb 2023 DESK-MX8M-L-2.0.0 release



How to create a bootable SD card[edit | edit source]

200px-Emblem-important.svg.png

The procedure described here was tested with a physical machine. In case of a virtual machine such as the MVM, it might not work properly. Also, it is worth remembering that USB controller of the MVM is disabled by default. See also this section.


This article shows how to create a bootable microSD for the [[DESK-MX8M-L/General/Release_Notes_(DESK-MX8M-L)|DESK-MX8M-L Release Notes] kit by using a simple bash script.
Note: Starting from this release the support for the SPL has been introduced in Uboot. Previous versions of this script will no longer produce a fully functional and bootable microSD card.

The procedure has been tested on a Linux PC running Ubuntu LTS (>=16.04) distribution with

  • a 16 GB microSD card [1]
  • the binary files delivered along with the DESKMX8M-L 2.0.0.

The resulting card is partitioned as depicted here.

The script - named mksd.sh - can be realized with the following code:

#!/bin/bash

if [[ -z $1 || -z $2 || -z $3 || -z $4 ]]
then
	echo "$0 Usage:"
	echo "	$0 <device> <flash.bin> <binaries directory> <rootfs tar.bz2>"
	echo "	Example: $0 /dev/sdc flash.bin binaries/ rootfs.tar.bz2"
	exit
fi

if [ "$(whoami)" != "root" ]
then
	echo "you must be root to run this script!"
	exit
fi

if ! [[ -b $1 ]]
then
	echo "$1 is not a valid block device!"
	exit
fi

if ! [[ -e $2 ]]
then
	echo "Incorrect flash.bin location!"
	exit
fi

if ! [[ -d $3 ]]
then
	echo "Incorrect Binaries location!"
	exit
fi

if ! [[ -f $4 ]]
then
	echo "Incorrect rootfs location!"
	exit
fi

DRIVE=$1
if [[ "$DRIVE" == *"mmcblk"* ]]
then
	echo "You're using a mmc device, I need to fix partition names"
	PART="p"
else
	PART=""
fi
BOOT=$2
BINARIES=$3
RFS=$4

echo "All data on "$DRIVE" now will be destroyed! Continue? [y/n]"
read ans
if ! [ $ans == 'y' ]
then
	exit
fi

echo "[Partitioning $1...]"

dd if=/dev/zero of=$DRIVE bs=1024 count=1024

SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`

echo DISK SIZE - $SIZE bytes

CYLINDERS=`echo $SIZE/255/63/512 | bc`

# check if we're running an old (e.g. 2.20.x) or new (e.g. 2.24.x) sfdisk
sfdisk --help | grep -- -H

if [ "$?" -eq "0" ]
then
	{
		echo 40,1380,0x0c,*
		echo 1420,,83,-
	} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
else
{
    echo 16M,8176M,0x0c,*
    echo 8192M,,83,-
} | sfdisk $DRIVE
fi

partprobe


echo "[Making filesystems...]"
mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/null
mkfs.ext3 -F -L ROOTFS "$DRIVE$PART"2 #> /dev/null

echo "[Copying files...]"

binaries_dir=${BINARIES%/}
mount "$DRIVE$PART"1 /mnt
cp -av --no-preserve=ownership $binaries_dir/* /mnt/
umount "$DRIVE$PART"1

echo "[Extracting rfs (this may take a while...)]"
mount "$DRIVE$PART"2 /mnt
tar jxf $RFS -C /mnt > /dev/null
chmod 755 /mnt
umount "$DRIVE$PART"2

echo "[Programming flash.bin]"
dd if=$BOOT of=$DRIVE bs=1k seek=32 conv=fsync

echo "[Done]"

Attention, if you are making a uSD for MITO 8M Mini SOM, then the last line must be modified with dd if=$BOOT of=$DRIVE bs=1k seek=33 Here is an example that shows how to use this script. Let's assume that the binary files were downloaded in the sdcard subdirectory of the working directory. Before invoking the script, the following files has to be renamed in order to make them compatible with the default U-Boot environment variables:

  • bootscript: boot.scr
  • Linux kernel: Image
  • Device tree blob: imx8mp-mito8mplus-cb1008.dtb or imx8mm-mito8mmini.dtb

This is the list of the binary files that will be used by the script:

dvdk@vagrant:~/desk-mx-l/sdcard$ ls -laR
.:
total 734040
drwxrwxr-x 3 dvdk dvdk      4096 Feb 16 09:41 .
drwxr-xr-x 7 dvdk dvdk      4096 Feb 16 09:21 ..
drwxrwxr-x 2 dvdk dvdk      4096 Feb 16 09:41 binaries
-rwxrwxr-x 1 dvdk dvdk 743273295 Feb 16 09:34 dave-image-devel-desk-mx8mp.tar.bz2
-rw-r--r-- 1 root root   1304608 Feb 16 09:32 flash.bin
-rwxrwxr-x 1 dvdk dvdk      1908 Feb 16 09:22 mksd.sh

./binaries:
total 27604
drwxrwxr-x 2 dvdk dvdk     4096 Feb 16 09:41 .
drwxrwxr-x 3 dvdk dvdk     4096 Feb 16 09:41 ..
-rw-rw-r-- 1 dvdk dvdk      695 Feb 16 09:41 boot.scr
-rw-r--r-- 1 dvdk dvdk 28150272 Feb 16 09:35 Image
-rw-r--r-- 1 dvdk dvdk    40521 Feb 16 09:35 imx8mm-mito8mmini.dtb
-rw-r--r-- 1 dvdk dvdk    58111 Feb 16 09:35 imx8mp-mito8mplus-cb1008.dtb
dvdk@vagrant:~/desk-mx-l/sdcard$ 

You can now run the script, by passing the following parameters:

  • Device file of the microSD card (/dev/sdb in the example)
  • Boot image
  • Path of the directory containing the bootscript file, the Linux kernel image, and the device tree blob files
  • Archive of the target's root file system (compressed as .tar.bz2 file).
dvdk@vagrant:~/desk-mx-l/sdcard$ sudo ./mksd.sh /dev/sdb flash.bin binaries/ dave-image-devel-desk-mx8mp.tar.bz2
All data on /dev/sdb now will be destroyed! Continue? [y/n]
y
[Partitioning /dev/sdb...]
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 3.03198 s, 346 kB/s
DISK SIZE - 15931539456 bytes
Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 31116288 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

>>> Created a new DOS disklabel with disk identifier 0xcd2d3b4e.
Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 8 GiB.
/dev/sdb2: Created a new partition 2 of type 'Linux' and of size 6.9 GiB.
/dev/sdb3: 
New situation:

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sdb1  *       32768 16777215 16744448    8G  c W95 FAT32 (LBA)
/dev/sdb2       16777216 31116287 14339072  6.9G 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[Making filesystems...]
mkfs.fat 3.0.28 (2015-05-16)
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1792384 4k blocks and 448800 inodes
Filesystem UUID: ce8daece-3f58-4b43-bd11-7bafd10bba73
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

[Copying files...]
'binaries/boot.scr' -> '/mnt/boot.scr'
'binaries/Image' -> '/mnt/Image'
'binaries/imx8mm-mito8mmini.dtb' -> '/mnt/imx8mm-mito8mmini.dtb'
'binaries/imx8mp-mito8mplus-cb1008.dtb' -> '/mnt/imx8mp-mito8mplus-cb1008.dtb'
[Extracting rfs (this may take a while...)]
[Programming flash.bin]
1274+0 records in
1274+0 records out
1304608 bytes (1.3 MB, 1.3 MiB) copied, 4.1375 s, 344 kB/s
[Done]
dvdk@vagrant:~/desk-mx-l/sdcard$ 

[1] In case you have a different size, you'll need to change the sfdisk parameters accordingly.

boot.scr[edit | edit source]

Once you got the new binaries compiled from your modified sources, they have to be installed on the first SD partition preserving the original file names used into boot.scr u-boot bootscript.

Here below there is an example on how to create a boot.scr file from the bootscript.txt for booting from SD card:

echo 'bootscript generated with command "mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr"'

setenv fdtfile imx8mp-mito8mplus-cb1008.dtb
setenv bootfile Image
setenv mmc_loadk 'fatload mmc ${sd_dev}:1 ${loadaddr} ${bootfile}'
setenv mmc_loadfdt 'fatload mmc ${sd_dev}:1 ${fdt_addr} ${fdtfile}'
setenv mmcboot 'run mmc_loadk; run mmc_loadfdt; run bootk'
setenv bootargs 'console=ttymxc1,115200 earlycon=ec_imx6q,0x30890000,115200 root=/dev/mmcblk1p2'
setenv bootk 'booti ${loadaddr} - ${fdt_addr}'

echo Booting DESK-MX8M via mmcboot with ${fdtfile} as device tree

run mmcboot

echo mmcboot FAILURE
echo 'bootscript generated with command "mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr"'

setenv fdtfile imx8mm-mito8mmini.dtb
setenv bootfile Image
setenv mmc_loadk 'fatload mmc ${sd_dev}:1 ${loadaddr} ${bootfile}'
setenv mmc_loadfdt 'fatload mmc ${sd_dev}:1 ${fdt_addr} ${fdtfile}'
setenv mmcboot 'run mmc_loadk; run mmc_loadfdt; run bootk'
setenv bootargs 'console=ttymxc1,115200 earlycon=ec_imx6q,0x30890000,115200 root=/dev/mmcblk1p2'
setenv bootk 'booti ${loadaddr} - ${fdt_addr}'

echo Booting DESK-MX8M via mmcboot with ${fdtfile} as device tree

run mmcboot

echo mmcboot FAILURE

and compile it using:

mkimage -A ARM -T script -C none -n DESK-MX8M -d bootscript.txt boot.scr

Then copy the boot.scr into the <binaries_dir> directories used by the script to create the SD card.