Template:Yocto Create Bootable SD: Difference between revisions

From Variscite Wiki
(Created page with "= Create a bootable SD card = test")
 
Line 1: Line 1:
= Create a bootable SD card =
= Create a bootable SD card =


test
== SD card structure ==
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
This is the structure of our Recovery/Extended SD card:<br>
[[File:SD_card_part_mx8m.png]]<br><br>
 
 
The SD card is divided into 2 sections as shown in the picture above:<br>
* The first unallocated 8MiB section reserved for U-Boot. It can be replaced using the dd command as described in the {{Varlink2|Yocto Build U-Boot|{{#var:RELEASE_LINK}}}} section.<br>
* The first partition is an ext4 partition that contains the complete root filesystem (including kernel image and device tree files under /boot).<br><br>
|
This is the structure of our Recovery/Extended SD card:<br>
[[File:SD_card_part_v50.png|SD card partitions]]<br><br>
 
 
The SD card is divided into 3 sections as shown in the picture above:<br>
* The first unallocated 4MiB are saved space for U-Boot. It can be replaced using the dd command as described in the {{Varlink2|Yocto Build U-Boot|{{#var:RELEASE_LINK}}}} section.<br>
* The first partition is a fat16 partition used for the device tree files and the kernel image file. You can copy them as described in the {{Varlink2|Yocto Build Linux|{{#var:RELEASE_LINK}}}} section.<br>
* The second partition is an ext4 partition that contains the complete root filesystem (including the kernel modules).<br><br>
}}
 
Note:<br>
The last unallocated area is not used. It is there so that the rootfs will fit on any 4GB SD card, as not all 4GB SD cards are really the same size. If you want, you can use a program such as GParted to resize the roofs partition and make it end at the end of your specific SD card (of course, you can also use SD cards with much bigger capacity than 4GB, and then it makes more sense to resize the partition).<br>
Also, if you create the extended SD card yourself by following the [[#Create_an_extended_SD_card | Create an extended SD card]] section below, and you use the '-a' option, the rootfs partition will end at the end of your specific SD card automatically.<br>
 
==Yocto pre-built bootable SD card==
 
The Yocto build products contains many files as explained in the [[#Build_Results | Build Results section]]. For example, fsl-image-gui-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}}, depending on your build. This is a complete image to be flashed directly to an SD card.<br>
 
Example usage:
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
<br>
$ sudo umount /dev/sdX*
 
# For GUI-XWAYLAND & Qt{{#var:QT_VER}}-XWAYLAND
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_XWAYLAND}}
Or
# For GUI-WAYLAND & Qt{{#var:QT_VER}}-WAYLAND
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_WAYLAND}}
# For fsl-image-gui image (GUI-XWAYLAND & GUI-WAYLAND)
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-gui-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT|sdcard.gz}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M conv=fsync
{{#if:{{#var:YOCTO_SUPPORT_CHROMIUM}}|
Or
# For fsl-image-gui-chromium image (GUI-XWAYLAND & GUI-WAYLAND)
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-gui-chromium-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT|sdcard.gz}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M conv=fsync
|}}
Or
# For fsl-image-qt{{#var:QT_VER}} image (Qt{{#var:QT_VER}}-XWAYLAND & Qt{{#var:QT_VER}}-WAYLAND)
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-qt{{#var:QT_VER}}-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT|sdcard.gz}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M conv=fsync
|
<br>
$ sudo umount /dev/sdX*
 
# For GUI-X11 & Qt{{#var:QT_VER}}-X11
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_X11}}
Or
# For Qt{{#var:QT_VER}}-FB
$ cd {{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_FB}}
# For fsl-image-gui image (GUI-X11)
{{#ifeq: {{#var:SDCARD_IMG_EXT}} | wic.gz |
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-gui-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M && sync
|
$ sudo dd if=tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-gui-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}} of=/dev/sdX bs=1M && sync
}}
Or
# For fsl-image-qt{{#var:QT_VER}} image (Qt{{#var:QT_VER}}-X11 & Qt{{#var:QT_VER}}-FB)
{{#ifeq: {{#var:SDCARD_IMG_EXT}} | wic.gz |
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-qt{{#var:QT_VER}}-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M && sync
|
$ sudo dd if=tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-qt{{#var:QT_VER}}-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}} of=/dev/sdX bs=1M && sync
}}
}}
 
Replace sdX with the right device name. This can be obtained by "dmesg" command on your host Linux PC, after the SD card reader is inserted.
 
* <span style="color:red">Note:</span> Booting your system from an SD card requires pressing the boot-select button, or switching the relevant DIP switch to "Boot from SD card", according to the relevant start-up guide of your system<br><br>
 
 
{{Note|'''Note:''' Please note that if using any of the native .{{#var:SDCARD_IMG_EXT}} images output from Yocto, these will only have a default partition size of slightly less than 8 GB in order to fit on most SD cards. In order to maximize all usable space on the SD card, please see 5.4 Create an extended SD card.}}
 
== Create an extended SD card ==
Variscite provides the var-create-yocto-sdcard.sh script which creates our recovery SD card - an SD card based on the fsl-image-gui filesystem, which also contain the scripts and relevant binaries for installation to the internal storage of the SOM.<br>
Later, you will be able to follow either the more automatic {{Varlink2|Yocto Recovery SD card|{{#var:RELEASE_LINK}}}} guide or the more manual {{Varlink|Yocto NAND Flash Burning|{{#var:RELEASE_LINK}}|Installing Yocto to the SOM's internal storage}} guide.<br><br>
 
Note:<br>
This is essentially the same as our pre-built Recovery SD image, with the following main differences:<br>
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX6 |
* The Android recovery (Android-eMMC) is only present on the pre-built SD image, and not on the SD card built from the Yocto script.<br>
}}
* The pre-built image's rootfs partition size is 3700MiB, which is also the default size when using the script, but the script also has an option to set the rootfs partition size to fill the whole free space of the used SD card. Anyway, you can always resize the partition later with an external tool such as gparted.<br>
Naturally, the pre-built image is more straight forward and easier to use, while the script method is easier to customize.<br><br>
 
Usage:<br>
* Follow the [[#Setup and build Yocto|Setup and build Yocto]] guide, and bitbake fsl-image-gui.
* Plug-in the SD card to your Linux Host PC, run dmesg and see which device is added (i.e. /dev/sdX or /dev/mmcblkX)
 
$ cd {{#var:BUILD_FOLDER}}
$ sudo MACHINE={{#var:MACHINE_NAME}} sources/{{#var:META_VARISCITE_SDK}}/scripts/var_mk_yocto_sdcard/var-create-yocto-sdcard.sh <options> /dev/sdX
(Replace /dev/sdX with your actual device)
 
options:
  -h            Display help message
  -s            Only show partition sizes to be written, without actually write them
  -a            Automatically set the rootfs partition size to fill the SD card
  -r            Select alternative rootfs for recovery images (default: {{#var:BUILD_FOLDER_X11}}/tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-gui-{{#var:MACHINE_NAME}}.*)
 
If you don't use the '-a' option, a default rootfs size of 3700MiB will be used
The '-r' option allows you to create a bootable SD card with an alternative image for the installation to NAND flash or eMMC.
Example: "-r tmp/deploy/images/{{#var:MACHINE_NAME}}/fsl-image-qt{{#var:QT_VER}}-{{#var:MACHINE_NAME}}" -- selected the "Qt{{#var:QT_VER}} image with X11" recovery image
 
=== Create an extended SD card image using a loop device ===
It is also possible to use the var-create-yocto-sdcard.sh script to create an extended SD card image, while using a loop device instead of attaching a real SD card.<br>
<br>
Create an empty file using the following command:
$ dd if=/dev/zero of={{#var:MACHINE_NAME}}-extended-sd.img bs=1M count=7420
 
The above command creates a 7420MiB file representing the SD card.<br>
<br>
Attach the first available loop device to this file:
$ sudo losetup -Pf {{#var:MACHINE_NAME}}-extended-sd.img
 
To find the actual loop device being used, run:
$ losetup -a | grep {{#var:MACHINE_NAME}}-extended-sd.img
 
Write the content to the loop device to generate the SD card image:
$ sudo MACHINE={{#var:MACHINE_NAME}} sources/{{#var:META_VARISCITE_SDK}}/scripts/var_mk_yocto_sdcard/var-create-yocto-sdcard.sh <options> /dev/loopX
(Replace /dev/loopX with your actual loop device, e.g. /dev/loop0)<br><br>
 
Detach the loop device from the file:
$ sudo losetup -d /dev/loopX
 
To compress the SD card image file use the following command:
$ gzip -9 {{#var:MACHINE_NAME}}-extended-sd.img
 
To write the SD card image to a real SD card device use the following command:
$ zcat {{#var:MACHINE_NAME}}-extended-sd.img.gz | sudo dd of=/dev/sdX bs=1M && sync
(Replace /dev/sdX with your actual SD device, e.g. /dev/sdb)

Revision as of 18:09, 14 July 2023

Create a bootable SD card

SD card structure

This is the structure of our Recovery/Extended SD card:
SD card partitions


The SD card is divided into 3 sections as shown in the picture above:

  • The first unallocated 4MiB are saved space for U-Boot. It can be replaced using the dd command as described in the Yocto Build U-Boot section.
  • The first partition is a fat16 partition used for the device tree files and the kernel image file. You can copy them as described in the Yocto Build Linux section.
  • The second partition is an ext4 partition that contains the complete root filesystem (including the kernel modules).

Note:
The last unallocated area is not used. It is there so that the rootfs will fit on any 4GB SD card, as not all 4GB SD cards are really the same size. If you want, you can use a program such as GParted to resize the roofs partition and make it end at the end of your specific SD card (of course, you can also use SD cards with much bigger capacity than 4GB, and then it makes more sense to resize the partition).
Also, if you create the extended SD card yourself by following the Create an extended SD card section below, and you use the '-a' option, the rootfs partition will end at the end of your specific SD card automatically.

Yocto pre-built bootable SD card

The Yocto build products contains many files as explained in the Build Results section. For example, fsl-image-gui-., depending on your build. This is a complete image to be flashed directly to an SD card.

Example usage:

$ sudo umount /dev/sdX*
# For GUI-X11 & Qt-X11
$ cd /
Or
# For Qt-FB
$ cd /

# For fsl-image-gui image (GUI-X11)
$ sudo dd if=tmp/deploy/images//fsl-image-gui-. of=/dev/sdX bs=1M && sync
Or
# For fsl-image-qt image (Qt-X11 & Qt-FB)
$ sudo dd if=tmp/deploy/images//fsl-image-qt-. of=/dev/sdX bs=1M && sync

Replace sdX with the right device name. This can be obtained by "dmesg" command on your host Linux PC, after the SD card reader is inserted.

  • Note: Booting your system from an SD card requires pressing the boot-select button, or switching the relevant DIP switch to "Boot from SD card", according to the relevant start-up guide of your system


Note: Please note that if using any of the native . images output from Yocto, these will only have a default partition size of slightly less than 8 GB in order to fit on most SD cards. In order to maximize all usable space on the SD card, please see 5.4 Create an extended SD card.

Create an extended SD card

Variscite provides the var-create-yocto-sdcard.sh script which creates our recovery SD card - an SD card based on the fsl-image-gui filesystem, which also contain the scripts and relevant binaries for installation to the internal storage of the SOM.
Later, you will be able to follow either the more automatic Yocto Recovery SD card guide or the more manual Installing Yocto to the SOM's internal storage guide.

Note:
This is essentially the same as our pre-built Recovery SD image, with the following main differences:

  • The pre-built image's rootfs partition size is 3700MiB, which is also the default size when using the script, but the script also has an option to set the rootfs partition size to fill the whole free space of the used SD card. Anyway, you can always resize the partition later with an external tool such as gparted.

Naturally, the pre-built image is more straight forward and easier to use, while the script method is easier to customize.

Usage:

  • Follow the Setup and build Yocto guide, and bitbake fsl-image-gui.
  • Plug-in the SD card to your Linux Host PC, run dmesg and see which device is added (i.e. /dev/sdX or /dev/mmcblkX)
$ cd 
$ sudo MACHINE= sources//scripts/var_mk_yocto_sdcard/var-create-yocto-sdcard.sh <options> /dev/sdX
(Replace /dev/sdX with your actual device)
options:
 -h            Display help message
 -s            Only show partition sizes to be written, without actually write them
 -a            Automatically set the rootfs partition size to fill the SD card
 -r            Select alternative rootfs for recovery images (default: /tmp/deploy/images//fsl-image-gui-.*)
If you don't use the '-a' option, a default rootfs size of 3700MiB will be used
The '-r' option allows you to create a bootable SD card with an alternative image for the installation to NAND flash or eMMC.
Example: "-r tmp/deploy/images//fsl-image-qt-" -- selected the "Qt image with X11" recovery image

Create an extended SD card image using a loop device

It is also possible to use the var-create-yocto-sdcard.sh script to create an extended SD card image, while using a loop device instead of attaching a real SD card.

Create an empty file using the following command:

$ dd if=/dev/zero of=-extended-sd.img bs=1M count=7420

The above command creates a 7420MiB file representing the SD card.

Attach the first available loop device to this file:

$ sudo losetup -Pf -extended-sd.img

To find the actual loop device being used, run:

$ losetup -a | grep -extended-sd.img

Write the content to the loop device to generate the SD card image:

$ sudo MACHINE= sources//scripts/var_mk_yocto_sdcard/var-create-yocto-sdcard.sh <options> /dev/loopX

(Replace /dev/loopX with your actual loop device, e.g. /dev/loop0)

Detach the loop device from the file:

$ sudo losetup -d /dev/loopX

To compress the SD card image file use the following command:

$ gzip -9 -extended-sd.img

To write the SD card image to a real SD card device use the following command:

$ zcat -extended-sd.img.gz | sudo dd of=/dev/sdX bs=1M && sync

(Replace /dev/sdX with your actual SD device, e.g. /dev/sdb)