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

From DAVE Developer's Wiki
Jump to: navigation, search
(25 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<section begin="History" />
+
<section begin=History/>
 
{| style="border-collapse:collapse; "
 
{| style="border-collapse:collapse; "
! 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" |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"|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" |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"|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:#edf8fb; padding:5px; color:#000000" |{{oldid|14119|2021/07/16}}
 
| 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 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" |{{oldid|16989|2022/03/04}}
 
| 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-MX6-L 3.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/04/27
 
! 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-MX6-L 4.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"|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"|Oct 2020
 +
|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 release
 
|}
 
|}
<section end="History" />
+
<section end=History/>
__FORCETOC__
+
<section begin=Body/>
<section begin="Body" />
 
  
 
==How to create a bootable SD card==
 
==How to create a bootable SD card==
  
{{ImportantMessage|text=The procedure described here was tested with a virtual machine such as the [[Managed_Virtual_Machine_(MVM)|MVM]]. The USB controller of the MVM should be enabled by default. If you are using Linux-based distribution and are having trouble detecting a USB device in virtual machine, please make sure your user belongs to the ''vboxusers'' group.}}
+
{{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-MX6-L/General/Release_Notes|DESK-MX6-L Release Notes]] kit by using a simple bash script. <br>
+
This article shows how to create a bootable microSD for the [[DESK-MX6-L/General/Release_Notes_(DESK-MX6-L)|DESK-MX6-L Release Notes] kit by using a simple bash script. <br>
'''Note:''' Starting from '''DESK-MX6-L 1.0.0''' release the support for the SPL has been introduced in U-Boot. Previous versions of this script will no longer produce a fully functional and bootable microSD card. <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 MVM released with '''DESK-MX6-L 4.0.0''' release with  
+
The procedure has been tested on a Linux PC running Ubuntu LTS (>=''TBD'') distribution with  
*a 32 GB microSD card [1]
+
*a 16 GB microSD card [1]
*a USB SD card reader
+
*the binary files delivered along with the [[Axel_Embedded_Linux_Kit_(XELK)#Downloadable_binary_images|DESKMX6-L ''1.x.x'']].
*the binary files delivered along with the [[DESK-MX6-L/General/Release_Notes#Downloadable_binary_images|DESK-MX6-L 4.0.0]].
+
The resulting card is partitioned as depicted [[Axel_Embedded_Linux_Kit_(XELK)#XELK_microSD_Layout|here]].
The resulting card is partitioned as depicted here below:
 
  
* bootable partition (mmcblk0p1, vfat) containing:
+
The script - named <code>mksd.sh</code> - looks like this:
** binary images (U-Boot and kernel images)
 
* root file system partition (mmcblk0p2, ext3)
 
** root file system binaries and init scripts
 
 
 
The script - named <code>mksd.sh</code> - can be realized with the following code:
 
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
Line 45: Line 33:
 
if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 ]]
 
if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 ]]
 
then
 
then
        echo "$0 Usage:"
+
echo "$0 Usage:"
        echo " $0 <device> <u-boot.img> <SPL> <binaries directory> <rootfs tar.bz2>"
+
echo " $0 <device> <u-boot.img> <SPL> <binaries directory> <rootfs tar.bz2>"
        echo " Example: $0 /dev/sdc u-boot.img SPL binaries/ rootfs.tar.bz2"
+
echo " Example: $0 /dev/sdc u-boot.img SPL binaries/ rootfs.tar.bz2"
        exit
+
exit
 
fi
 
fi
  
 
if [ "$(whoami)" != "root" ]
 
if [ "$(whoami)" != "root" ]
 
then
 
then
        echo "you must be root to run this script!"
+
echo "you must be root to run this script!"
        exit
+
exit
 
fi
 
fi
  
 
if ! [[ -b $1 ]]
 
if ! [[ -b $1 ]]
 
then
 
then
        echo "$1 is not a valid block device!"
+
echo "$1 is not a valid block device!"
        exit
+
exit
 
fi
 
fi
  
 
if ! [[ -e $2 ]]
 
if ! [[ -e $2 ]]
 
then
 
then
        echo "Incorrect u-boot.img location!"
+
echo "Incorrect u-boot.img location!"
        exit
+
exit
 
fi
 
fi
  
 
if ! [[ -e $3 ]]
 
if ! [[ -e $3 ]]
 
then
 
then
        echo "Incorrect SPL location!"
+
echo "Incorrect SPL location!"
        exit
+
exit
 
fi
 
fi
  
 
if ! [[ -d $4 ]]
 
if ! [[ -d $4 ]]
 
then
 
then
        echo "Incorrect Binaries location!"
+
echo "Incorrect Binaries location!"
        exit
+
exit
 
fi
 
fi
  
 
if ! [[ -f $5 ]]
 
if ! [[ -f $5 ]]
 
then
 
then
        echo "Incorrect rootfs location!"
+
echo "Incorrect rootfs location!"
        exit
+
exit
 
fi
 
fi
  
Line 90: Line 78:
 
if [[ "$DRIVE" == *"mmcblk"* ]]
 
if [[ "$DRIVE" == *"mmcblk"* ]]
 
then
 
then
        echo "You're using a mmc device, I need to fix partition names"
+
echo "You're using a mmc device, I need to fix partition names"
        PART="p"
+
PART="p"
 
else
 
else
        PART=""
+
PART=""
 
fi
 
fi
 
UBOOT=$2
 
UBOOT=$2
Line 104: Line 92:
 
if ! [ $ans == 'y' ]
 
if ! [ $ans == 'y' ]
 
then
 
then
        exit
+
exit
 
fi
 
fi
  
Line 122: Line 110:
 
if [ "$?" -eq "0" ]
 
if [ "$?" -eq "0" ]
 
then
 
then
        {
+
{
                echo 40,1380,0x0c,*
+
echo 10,1380,0x0c,*
                echo 1420,,83,-
+
echo 1390,,83,-
        } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
+
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
 
else
 
else
 
{
 
{
     echo 16M,8176M,0x0c,*
+
     echo 10,4086M,0x0c,*
     echo 8192M,,83,-
+
     echo 4096M,,83,-
 
} | sfdisk $DRIVE
 
} | sfdisk $DRIVE
 
fi
 
fi
Line 138: Line 126:
 
echo "[Making filesystems...]"
 
echo "[Making filesystems...]"
 
mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/null
 
mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/null
mkfs.ext3 -F -L ROOTFS "$DRIVE$PART"2 #> /dev/null
+
mkfs.ext3 -L ROOTFS "$DRIVE$PART"2 #> /dev/null
 
 
# wait for the VM to recognize the uSD
 
sleep 60
 
  
 
echo "[Copying files...]"
 
echo "[Copying files...]"
Line 163: Line 148:
  
 
echo "[Done]"
 
echo "[Done]"
 +
 
</pre>
 
</pre>
  
  
Here is an example that shows how to use this script. We use here files delivered with [[DESK-MX6-L/General/Release_Notes#Downloadable_binary_images|DESK-MX6-L 4.0.0]] release. Before invoking the script, the following files has to be renamed in order to make them compatible with the default U-Boot environment variables:
+
Here is an example that shows how to use this script. Let's assume that the binary files were downloaded in the <code>desk</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>
 
* bootscript: <code>boot.scr</code>
* splash image: <code>splash_image.bmp</code>
+
* Linux kernel: <code>uImage</code>
* Linux kernel: <code>desk-mx6-l-4.0.0_uImage</code>
+
* Device tree blob: <code>imx6q-xelk-l-2-0-0.dtb</code>.
* Device tree blob: <code>desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb</code>.
 
 
 
In the case of you don't have some file on MVM, please download it from [https://mirror.dave.eu/desk-mx-l/ mirror.dave.eu].
 
  
We will copy them into <code>~/desk-mx-l/desk</code> directory. Needed binary files can be found on <code>MVM</code> in the following location:
+
This is the list of the binary files that will be used by the script:
 
<pre>
 
<pre>
dvdk@vagrant:~$ ll /tftpboot/desk-mx6-l/
+
dvdk@vagrant:~/desk-mx-l$ ls -la desk
total 11360
+
total 7548
drwxr-xr-x 2 dvdk root   4096 Apr 3 17:57 ./
+
drwxrwxr-x 2 dvdk dvdk   4096 Oct 9 16:22 .
drwxr-xr-x 3 dvdk root   4096 Apr 4 07:16 ../
+
drwxrwxr-x 6 dvdk dvdk    4096 Oct 9 16:22 ..
-rw-r--r-- 1 dvdk root  52247 Apr  3 17:38 desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb
+
-rw-r--r-- 1 dvdk dvdk  53760 Oct 9 16:22 imx6q-sbcx-cb0012.dtb
-rw-r--r-- 1 dvdk root  52560 Apr  3 17:38 desk-mx6-l-4.0.0_imx6dl-sbcx-cb0013.dtb
+
-rw-r--r-- 1 dvdk dvdk  56320 Oct 9 16:22 SPL
-rw-r--r-- 1 dvdk root   52161 Apr 3 17:38 desk-mx6-l-4.0.0_imx6dl-sbcx-cb0018.dtb
+
-rw-r--r-- 1 dvdk dvdk  569864 Oct 9 16:22 u-boot.img
-rw-r--r-- 1 dvdk root  53231 Apr  3 17:38 desk-mx6-l-4.0.0_imx6dl-sbcx-cb0050.dtb
+
-rw-r--r-- 1 dvdk dvdk 7031520 Oct 9 16:22 uImage
-rw-r--r-- 1 dvdk root  52536 Apr  3 17:38 desk-mx6-l-4.0.0_imx6dl-sbcx-cb0055.dtb
+
dvdk@vagrant:~/desk-mx-l$  
-rw-r--r-- 1 dvdk root  48736 Apr  3 17:38 desk-mx6-l-4.0.0_imx6dl-xelk-l.dtb
 
-rw-r--r-- 1 dvdk root  53524 Apr  3 17:38 desk-mx6-l-4.0.0_imx6q-sbcx-cb0012.dtb
 
-rw-r--r-- 1 dvdk root  53833 Apr  3 17:38 desk-mx6-l-4.0.0_imx6q-sbcx-cb0013.dtb
 
-rw-r--r-- 1 dvdk root  50177 Apr  3 17:38 desk-mx6-l-4.0.0_imx6q-xelk-l-2-0-0.dtb
 
-rw-r--r-- 1 dvdk root  50009 Apr  3 17:38 desk-mx6-l-4.0.0_imx6q-xelk-l.dtb
 
-rw-r--r-- 1 dvdk root   56320 Apr 3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_SPL
 
-rw-r--r-- 1 dvdk root  56320 Apr  3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_nand_SPL
 
-rw-r--r-- 1 dvdk root 576288 Apr 3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_nand_u-boot.img
 
-rw-r--r-- 1 dvdk root  56320 Apr  3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_spi_SPL
 
-rw-r--r-- 1 dvdk root  554004 Apr  3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_spi_u-boot.img
 
-rw-r--r-- 1 dvdk root  576000 Apr  3 17:38 desk-mx6-l-4.0.0_mx6qdldesk_u-boot.img
 
-rw-r--r-- 1 dvdk root 8038640 Apr 3 17:38 desk-mx6-l-4.0.0_uImage
 
-rw-r--r-- 1 dvdk root 1152054 Apr  3 17:38 splash_image.bmp
 
dvdk@vagrant:~$ ll ~/desk-mx-l/desk-mx6-l-4.0.0_boot.scr
 
-rw-rw-r-- 1 dvdk dvdk 1556 Apr  3 17:57 /home/dvdk/desk-mx-l/desk-mx6-l-4.0.0_boot.scr
 
dvdk@vagrant:~$ mkdir -p ~/desk-mx-l/desk/
 
dvdk@vagrant:~$ cp /tftpboot/desk-mx6-l/desk-mx6-l-4.0.0_uImage ~/desk-mx-l/desk/desk-mx6-l-4.0.0_uImage
 
dvdk@vagrant:~$ cp /tftpboot/desk-mx6-l/desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb ~/desk-mx-l/desk/desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb
 
dvdk@vagrant:~$ cp ~/desk-mx-l/desk-mx6-l-4.0.0_boot.scr ~/desk-mx-l/desk/boot.scr
 
dvdk@vagrant:~$ cp /tftpboot/desk-mx6-l/splash_image.bmp ~/desk-mx-l/desk/
 
dvdk@vagrant:~$ cp ~/desk-mx-l/rfs/desk-mx6-l-4.0.0_modules.tar.gz ~/desk-mx-l/desk/
 
 
</pre>
 
</pre>
  
 
You can now run the script, by passing the following parameters:
 
You can now run the script, by passing the following parameters:
*Device file of the microSD card (<code>/dev/sdb</code> in the example)
+
*Device file of the microSD card (<code>/dev/sdc</code> in the example)
 
*U-Boot image
 
*U-Boot image
 
*SPL
 
*SPL
*Path of the directory containing the bootscript file, the splash image, the Linux kernel image and the device tree blob files
+
*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).
 
*Archive of the target's root file system (compressed as <code>.tar.bz2</code> file).
 
<pre>
 
<pre>
dvdk@vagrant:~/desk-mx-l$ umount /dev/sdb*
+
dvdk@vagrant:~/desk-mx-l$ ./mksd.sh /dev/sd<x> <u-boot.img> <SPL> desk/ <rfs_filename>
dvdk@vagrant:~/desk-mx-l$ sudo ./desk-mx6-l-4.0.0_mksd.sh /dev/sdb /tftpboot/desk-mx6-l/desk-mx6-l-4.0.0_mx6qdldesk_u-boot.img /tftpboot/desk-mx6-l/desk-mx6-l-4.0.0_mx6qdldesk_SPL ~/desk-mx-l/desk ./rfs/desk-image-qt6-desk-mx6.tar.bz2
+
...
All data on /dev/sdb now will be destroyed! Continue? [y/n]
+
...
y
+
TBD
[Partitioning /dev/sdb...]
+
...
1024+0 records in
+
...
1024+0 records out
+
</pre>
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.228364 s, 4.6 MB/s
 
DISK SIZE - 31914983424 bytes
 
Checking that no-one is using this disk right now ... OK
 
 
 
Disk /dev/sdb: 29.74 GiB, 31914983424 bytes, 62333952 sectors
 
Disk model: Transcend     
 
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 0xeba9791f.
 
/dev/sdb1: 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 21.7 GiB.
 
/dev/sdb3: Done.
 
  
New situation:
 
Disklabel type: dos
 
Disk identifier: 0xeba9791f
 
 
Device    Boot    Start      End  Sectors  Size Id Type
 
/dev/sdb1  *      32768 16777215 16744448    8G  c W95 FAT32 (LBA)
 
/dev/sdb2      16777216 62333951 45556736 21.7G 83 Linux
 
 
The partition table has been altered.
 
Calling ioctl() to re-read partition table.
 
Syncing disks.
 
[Making filesystems...]
 
mkfs.fat 4.1 (2017-01-24)
 
mke2fs 1.45.5 (07-Jan-2020)
 
Creating filesystem with 5694592 4k blocks and 1425408 inodes
 
Filesystem UUID: 2b7edb0e-b75b-4685-87b9-1933bfd0c8f0
 
Superblock backups stored on blocks:
 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 
        4096000
 
 
Allocating group tables: done                           
 
Writing inode tables: done                           
 
Creating journal (32768 blocks): done
 
Writing superblocks and filesystem accounting information: done 
 
 
[Copying files...]
 
'/home/dvdk/desk-mx-l/desk/boot.scr' -> '/mnt/boot.scr'
 
'/home/dvdk/desk-mx-l/desk/desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb' -> '/mnt/desk-mx6-l-4.0.0_imx6dl-sbcx-cb0012.dtb'
 
'/home/dvdk/desk-mx-l/desk/desk-mx6-l-4.0.0_uImage' -> '/mnt/desk-mx6-l-4.0.0_uImage'
 
'/home/dvdk/desk-mx-l/desk/splash_image.bmp' -> '/mnt/splash_image.bmp'
 
[Extracting rfs (this may take a while...)]
 
[Programming SPL]
 
110+0 records in
 
110+0 records out
 
56320 bytes (56 kB, 55 KiB) copied, 0.0340295 s, 1.7 MB/s
 
[Programming u-boot.img]
 
562+1 records in
 
562+1 records out
 
576000 bytes (576 kB, 562 KiB) copied, 0.201931 s, 2.9 MB/s
 
[Done]
 
</pre>
 
  
 
[1] In case you have a different size, you'll need to change the <code>sfdisk</code> parameters accordingly.
 
[1] In case you have a different size, you'll need to change the <code>sfdisk</code> parameters accordingly.
 
===bootscr ===
 
 
Once you got the new binaries compiled from your modified sources, they have to be installed on 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:
 
 
<pre>
 
echo 'bootscript generated with command "mkimage -A ARM -T script -C none -n DESK-MX6 -d bootscript.txt boot.scr"'
 
 
setenv desk_release 'desk-mx6-l-4.0.0'
 
 
if test 0x${cb_configid#} = 0x00000002;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-sbcx.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-sbcx.dtb
 
fi
 
elif test 0x${cb_configid#} = 0x00000003;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-sbcx-cb0003.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-sbcx-cb0003.dtb
 
fi
 
elif test 0x${cb_configid#} = 0x00000012;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-sbcx-cb0012.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-sbcx-cb0012.dtb
 
fi
 
elif test 0x${cb_configid#} = 0x00000013;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-sbcx-cb0013.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-sbcx-cb0013.dtb
 
fi
 
elif test 0x${cb_configid#} = 0x00000077;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-sbcx-cb0077.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-sbcx-cb0077.dtb
 
fi
 
elif test 0x${cb_configid#} = 0x00000001;
 
then
 
if test ${cpu} = 6DL; then
 
setenv fdtfile ${desk_release}_imx6dl-xelk-l.dtb
 
else
 
setenv fdtfile ${desk_release}_imx6q-xelk-l.dtb
 
fi
 
elif test 0x${cb_configid#} = 0xffffffff;
 
then
 
setenv fdtfile ${desk_release}_imx6q-xelk-l-2-0-0.dtb
 
else
 
    echo Invalid CB! Autoreset ...
 
    sleep 30
 
reset
 
fi
 
 
setenv bootfile uImage
 
 
setenv mmc_loadk 'fatload mmc ${mmcdev}:1 ${loadaddr} ${bootfile}'
 
setenv mmc_loadfdt 'fatload mmc ${mmcdev}:1 ${fdtaddr} ${fdtfile}'
 
 
echo Booting DESK-MX6 via mmcboot with ${fdtfile} as device tree
 
 
run mmcboot
 
 
echo mmcboot FAILURE
 
</pre>
 
 
and compile it using:
 
 
<pre>
 
mkimage -A ARM -T script -C none -n DESK-MX6-L -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.
 
 
===Install Module===
 
 
To install kernel modules, follow the steps below.
 
 
<pre>
 
root@desk-mx6:~# sudo mount /dev/mmcblk0p1 /media                   
 
root@desk-mx6:~# tar xvzf /media/desk-mx6-l-4.0.0_modules.tar.gz -C /
 
</pre>
 
 
After installation, run the following command to verify that the installation was successful:
 
 
<pre>
 
root@desk-mx6:~# ls -l /lib/modules/$(uname -r)
 
total 304
 
lrwxrwxrwx 1 541 502    63 Apr  3  2023 build -> /home/jenkins/workspace/workspace/DESK-MX6-L-4.x.x_Linux-kernel
 
drwxr-xr-x 6 541 502  4096 Apr  3  2023 kernel
 
-rw-r--r-- 1 541 502  2812 Apr  3  2023 modules.alias
 
-rw-r--r-- 1 541 502  4926 Apr  3  2023 modules.alias.bin
 
-rw-r--r-- 1 541 502  15368 Apr  3  2023 modules.builtin
 
-rw-r--r-- 1 541 502  35496 Apr  3  2023 modules.builtin.alias.bin
 
-rw-r--r-- 1 541 502  17986 Apr  3  2023 modules.builtin.bin
 
-rw-r--r-- 1 541 502 107589 Apr  3  2023 modules.builtin.modinfo
 
-rw-r--r-- 1 541 502  10767 Apr  3  2023 modules.dep
 
-rw-r--r-- 1 541 502  21773 Apr  3  2023 modules.dep.bin
 
-rw-r--r-- 1 541 502      0 Apr  3  2023 modules.devname
 
-rw-r--r-- 1 541 502  8733 Apr  3  2023 modules.order
 
-rw-r--r-- 1 541 502    85 Apr  3  2023 modules.softdep
 
-rw-r--r-- 1 541 502  16970 Apr  3  2023 modules.symbols
 
-rw-r--r-- 1 541 502  23964 Apr  3  2023 modules.symbols.bin
 
lrwxrwxrwx 1 541 502    63 Apr  3  2023 source -> /home/jenkins/workspace/workspace/DESK-MX6-L-4.x.x_Linux-kernel
 
</pre>
 
 
 
=== Attention !===
 
* <code>/home/dvdk/desk-mx-l/desk-mx6-l-4.0.0_boot.scr</code> has been generated using the images available at the moment of VM creation: please, use the previous indication as an example on how to create a '''proper''' bootscript for your own purposes
 
* <code>/home/dvdk/desk-mx-l/desk-mx6-l-4.0.0_mksd.sh</code> bash script has been validated using a single SD card version: the size of the partitions and the related ''sfdisk'' parameters have to be properly modified according to your own SD card used and to your partitions specification. You can use it an an example to be modified according your use case
 
  
 
----
 
----
  
 
[[Category:AXEL Lite]]
 
[[Category:AXEL Lite]]

Revision as of 14:24, 9 October 2020

History
Version Issue Date Notes
1.0.0 Oct 2020 First DESK 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-MX6-L/General/Release_Notes_(DESK-MX6-L)|DESK-MX6-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 (>=TBD) distribution with

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

The resulting card is partitioned as depicted here.

The script - named mksd.sh - looks like this:

#!/bin/bash

if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 ]]
then
	echo "$0 Usage:"
	echo "	$0 <device> <u-boot.img> <SPL> <binaries directory> <rootfs tar.bz2>"
	echo "	Example: $0 /dev/sdc u-boot.img SPL 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 u-boot.img location!"
	exit
fi

if ! [[ -e $3 ]]
then
	echo "Incorrect SPL location!"
	exit
fi

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

if ! [[ -f $5 ]]
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
UBOOT=$2
SPL=$3
BINARIES=$4
RFS=$5

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 10,1380,0x0c,*
		echo 1390,,83,-
	} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
else
{
    echo 10,4086M,0x0c,*
    echo 4096M,,83,-
} | sfdisk $DRIVE
fi

partprobe


echo "[Making filesystems...]"
mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/null
mkfs.ext3 -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 SPL]"
dd if=$SPL of=$DRIVE bs=512 seek=2 conv=fsync

echo "[Programming u-boot.img]"
dd if=$UBOOT of=$DRIVE bs=1k seek=69 conv=fsync

echo "[Done]"


Here is an example that shows how to use this script. Let's assume that the binary files were downloaded in the desk 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: uImage
  • Device tree blob: imx6q-xelk-l-2-0-0.dtb.

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

dvdk@vagrant:~/desk-mx-l$ ls -la desk
total 7548
drwxrwxr-x 2 dvdk dvdk    4096 Oct  9 16:22 .
drwxrwxr-x 6 dvdk dvdk    4096 Oct  9 16:22 ..
-rw-r--r-- 1 dvdk dvdk   53760 Oct  9 16:22 imx6q-sbcx-cb0012.dtb
-rw-r--r-- 1 dvdk dvdk   56320 Oct  9 16:22 SPL
-rw-r--r-- 1 dvdk dvdk  569864 Oct  9 16:22 u-boot.img
-rw-r--r-- 1 dvdk dvdk 7031520 Oct  9 16:22 uImage
dvdk@vagrant:~/desk-mx-l$ 

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

  • Device file of the microSD card (/dev/sdc in the example)
  • U-Boot image
  • SPL
  • 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$ ./mksd.sh /dev/sd<x> <u-boot.img> <SPL> desk/ <rfs_filename>
...
...
TBD 
...
...


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