Template:Yocto Create Bootable SD: Difference between revisions

From Variscite Wiki
No edit summary
 
(50 intermediate revisions by 5 users not shown)
Line 1: Line 1:
= Create a bootable SD card =
= Create a bootable SD card =
 
{{#ifexpr:{{#varexists:DEBIAN_NAME}} | {{#vardefine:OS_TYPE|Debian}} | {{#vardefine:OS_TYPE|yocto}} }}
== SD card structure ==
{{#vardefine:SHELL_PROMPT|{{#if:{{#var:BUILD_YOCTO_IN_DOCKER_CONTAINER}}|vari@yocto-{{#var:DOCKER_CONTAINER_INFO}}:/workdir/{{#var:BUILD_FOLDER_ENV}}$|{{#var:BUILD_FOLDER}}/{{#var:BUILD_FOLDER_ENV}}$}}}}
== SD Card Structure ==
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
This is the structure of our Recovery/Extended SD card:<br>
This is the structure of our default SD card programmed from Yocto images:<br>
  Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors                                                                                               
  Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors                                                                                               
  Disk model: MassStorageClass                                                                                                                                 
  Disk model: MassStorageClass                                                                                                                                 
Line 16: Line 17:
<br>
<br>
* At the beginning of the card is 8 MiB of reserved area for the partition table and bootloader.
* At the beginning of the card is 8 MiB of reserved area for the partition table and bootloader.
* The first and only SD card partition begins at offset 16384 (of 512 byte sectors) which is due to the reserved area explained above. This partition is an ext4 partition that contains the complete root filesystem (including kernel image and device tree files under /boot).<br>
* The first and only SD card partition begins at offset 16,384 (of 512 byte sectors) which is due to the reserved area explained above. This partition is an ext4 partition that contains the complete root filesystem (including kernel image and device tree files under /boot).<br>
|
|
This is the structure of our Recovery/Extended SD card:<br>
This is the structure of our Recovery/Extended SD card:<br>
Line 28: Line 29:
}}
}}
<br>
<br>
{{Note|'''Note:''' The last unallocated area is not used. It is there so that the rootfs will fit on any 8 GB SD card, as not all 8 GB SD cards are really the same size. Please see [[#Create an extended SD card|creating an extended SD card]] for steps on how to maximize SD card usage by the rootfs.}}
{{Note|'''Note:''' This partition includes an unallocated area to ensure compatibility with all 8 GB SD cards, as their actual sizes may vary. For instructions on optimizing the usage of your SD card's capacity, refer to the section [[#Extending the SD Card Size|Extending the SD Card Size]].}}


==Yocto pre-built bootable SD card==
==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>
The Yocto build products contains many files as explained in the [[#Build_Results | Build Results section]]. For example, {{#var:DEFAULT_IMAGE_BB_NAME|fsl-image-gui}}-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}}, depending on your build. This is a complete and bootable image ready to be flashed directly to an SD card.<br>


Example usage:
Example usage:
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
{{#switch: {{#var:SOC_SERIES}} | imx8 | imx9=
{{#ifexpr:{{#varexists:DEBIAN_NAME|0|1}}| <!-- if not Debian -->
  <br>
  <br>
  $ sudo umount /dev/sdX*
  {{#var:SHELL_PROMPT}} 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)
  # 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
  {{#var:SHELL_PROMPT}} {{#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}}|
  {{#if:{{#var:YOCTO_SUPPORT_CHROMIUM}}|
  Or
  Or
  # For fsl-image-gui-chromium image (GUI-XWAYLAND & GUI-WAYLAND)
  # 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
  {{#var:SHELL_PROMPT}} {{#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
  Or
  # For fsl-image-qt{{#var:QT_VER}} image (Qt{{#var:QT_VER}}-XWAYLAND & Qt{{#var:QT_VER}}-WAYLAND)
  # 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
  {{#var:SHELL_PROMPT}} {{#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*
$ cd {{#var:BUILD_FOLDER}}/build_debian_xwayland
$ {{#var:UNZIP}} tmp/deploy/images/{{#var:MACHINE_NAME}}/var-image-debian-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT|sdcard.gz}} <nowiki>|</nowiki> sudo dd of=/dev/sdX bs=1M conv=fsync
}}
|
|
  <br>
  <br>
Line 84: Line 86:
{{Note|'''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|'''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|'''Note:''' 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 the section on [[#Create an extended SD card|creating an extended SD card]]}}
{{Note|'''Note:''' 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 the section on [[#Extending the SD Card Size|Extending the SD Card Size]].}}


== Yocto Recovery Image ==
== Yocto Recovery Image ==
Beginning in Yocto Langdale, Variscite has released a new recovery Yocto image recipe called “var-recovery-image.This image is used to create a bootable SD card that contains another target image to be programmed to the eMMC. See the [[#Yocto_Recovery_SD|Yocto Recovery SD]] article on specifics of installing a recovery image.<br>
Beginning in Yocto Langdale, Variscite has released a new recovery Yocto image recipe called "var-recovery-image." This image is used to create a bootable SD card that contains another target image to be programmed to the eMMC. See the {{Varlink2|{{#var:OS_TYPE}} Recovery SD card|{{#var:RELEASE_LINK}}}} or the more manual {{Varlink|Yocto NAND Flash Burning|{{#var:RELEASE_LINK}}|Installing Yocto to the SOM's internal storage}} articles for specifics of installing a recovery image.<br>
<br>
<br>
Usage:<br><br>
Usage:<br><br>
To create a recovery image, simply run the following from your Yocto environment:
To create a recovery image, simply run the following from your Yocto environment:
<br>
<br>
  $ bitbake var-recovery-image
  {{#var:SHELL_PROMPT}} bitbake var-recovery-image


This will produce an output relative to the build folder of "./tmp/deploy/images/{{#var:MACHINE_NAME}}/var-recovery-image-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}}" that can be flashed to the SD card. By default, this image boots fsl-image-gui and contains a fsl-image-gui target image to be programmed to eMMC.<br>
This will produce an output relative to the build folder of "./tmp/deploy/images/{{#var:MACHINE_NAME}}/var-recovery-image-{{#var:MACHINE_NAME}}.{{#var:SDCARD_IMG_EXT}}" that can be flashed to the SD card. By default, this image boots fsl-image-gui and contains a fsl-image-gui target image to be programmed to eMMC.<br>
Line 98: Line 100:
You can also specify a different target eMMC image to be embedded in the recovery image by setting VAR_RECOVERY_TARGET_ROOTFS via the command line during build:<br>
You can also specify a different target eMMC image to be embedded in the recovery image by setting VAR_RECOVERY_TARGET_ROOTFS via the command line during build:<br>
i.e.
i.e.
  $ VAR_RECOVERY_TARGET_ROOTFS="<desired-emmc-image-recipe>" bitbake var-recovery-image
  {{#var:SHELL_PROMPT}} VAR_RECOVERY_TARGET_ROOTFS="<desired-emmc-image-recipe>" bitbake var-recovery-image
<br>
<br>
Or alternatively, by setting this variable in local.conf:
Or alternatively, by setting this variable in local.conf:
  VAR_RECOVERY_TARGET_ROOTFS = "<desired-emmc-image-recipe>"  
  {{#var:SHELL_PROMPT}} VAR_RECOVERY_TARGET_ROOTFS = "<desired-emmc-image-recipe>"  
<br>
<br>
Additionally, the file name of the recovery image output can be modified by setting something like the following in local.conf:
Additionally, the file name of the recovery image output can be modified by setting something like the following in local.conf:
  VAR_RECOVERY_SD_NAME = “my-recovery-image”
 
Would produce a recovery image relative to the build folder of "./tmp/deploy/images/{{#var:MACHINE_NAME}}/my-recovery-image.{{#var:SDCARD_IMG_EXT}}"<br>
  {{#var:SHELL_PROMPT}} echo 'VAR_RECOVERY_SD_NAME = "{{#var:RECOVERY_BASE_NAME}}"' >> conf/local.conf
 
Would produce a recovery image relative to the build folder of "./tmp/deploy/images/{{#var:MACHINE_NAME}}/{{#var:RECOVERY_BASE_NAME}}.{{#var:SDCARD_IMG_EXT}}"<br>
<br>
<br>
{{Note|'''Note:''' Please see the [{{#var:META_VARISCITE_SDK_GIT}}/blob/{{#var:META_VARISCITE_SDK_BRANCH}}/recipes-core/images/var-recovery-image.bb var-recovery-image recipe source] for advanced usages of the recovery image.}}
{{Note|'''Note:''' Please see the [{{#var:META_VARISCITE_SDK_GIT}}/blob/{{#var:META_VARISCITE_SDK_BRANCH}}/recipes-core/images/var-recovery-image.bb var-recovery-image recipe source] for advanced usages of the recovery image.}}


== Extending the SD Card Size ==
== Extending the SD Card Size ==
Flashing the default .{{#var:SDCARD_IMG_EXT}} images from Yocto results in a rootfs that does not utilize the entire SD card if the card is > 8 GB. This section explains how the SD card can be extended on the build host after flashing.<br>
Flashing the default .{{#var:SDCARD_IMG_EXT}} images from Yocto results in a rootfs that does not utilize the entire SD card. This section explains how the SD card can be extended on the build host after flashing.<br>
<br>
<br>
Procedure:<br>
Procedure:<br>
Line 116: Line 120:
Begin with an SD card on which you have previously flashed a Yocto .{{#var:SDCARD_IMG_EXT}} image. Ensure the SD card is inserted and the device present (i.e. /dev/sda, /dev/mmcblk0, etc.)<br>
Begin with an SD card on which you have previously flashed a Yocto .{{#var:SDCARD_IMG_EXT}} image. Ensure the SD card is inserted and the device present (i.e. /dev/sda, /dev/mmcblk0, etc.)<br>
{{Note|'''Note:''' Below replace /dev/sdX with your actual device (i.e. /dev/sda)}}
{{Note|'''Note:''' Below replace /dev/sdX with your actual device (i.e. /dev/sda)}}
Start by running fdisk as below and typing "p" and enter to print current partitions. You should see a layout similar to below but numbers may differ depending on card sizes. Note that the partition starts at 16384 (bytes offset 16384*512) which is to account for the boot content explained above.
Start by running fdisk as below and typing "p" and enter to print current partitions. You should see a layout similar to below but numbers may differ depending on card sizes. Note that the partition starts at 16,384 (bytes offset 16384*512) which is to account for the boot content explained above.
  $ sudo fdisk /dev/sdX
  $ sudo fdisk /dev/sdX
   
   
Line 136: Line 140:
  /dev/sdX1      16384 15165439 15149056  7.2G 83 Linux
  /dev/sdX1      16384 15165439 15149056  7.2G 83 Linux


Next we will run the following sequence of commands followed by enter with each step explained with a "-" to the right. Each command/input should be followed by enter:<br>
Next, run the following sequence of commands followed by enter with each step explained with a "-" to the right. Each command/input should be followed by enter:<br>
* d - Delete current partition (1).<br>
* d - Delete current partition (1).<br>
* n - Create a new parition.<br>
* n - Create a new parition.<br>
Line 188: Line 192:
  Syncing disks.
  Syncing disks.
<br>
<br>
Finally, we will need to resize the file system on the disk to fill the now larger partition. Do that as follows:
Finally, the file system needs to be resized on the disk to fill the now larger partition. Do that as follows:
  $ sudo e2fsck -f /dev/sdX1                                                     
  $ sudo e2fsck -f /dev/sdX1                                                     
  e2fsck 1.46.5 (30-Dec-2021)                                                                                                                                 
  e2fsck 1.46.5 (30-Dec-2021)                                                                                                                                 
Line 203: Line 207:
  Resizing the filesystem on /dev/sdX1 to 15589888 (4k) blocks.                                                                                               
  Resizing the filesystem on /dev/sdX1 to 15589888 (4k) blocks.                                                                                               
  The filesystem on /dev/sdX1 is now 15589888 (4k) blocks long.
  The filesystem on /dev/sdX1 is now 15589888 (4k) blocks long.
$ sync
<br>
<br>
Again, numbers and output should differ slightly depending on your card.<br>
Again, numbers and output should differ slightly depending on your card.<br>
<br>
<br>
Your rootfs image should now fill the entire SD card and is ready to boot.
Your rootfs image should now fill the entire SD card and is ready to boot.

Latest revision as of 16:30, 4 November 2024

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: This partition includes an unallocated area to ensure compatibility with all 8 GB SD cards, as their actual sizes may vary. For instructions on optimizing the usage of your SD card's capacity, refer to the section Extending the SD Card Size.

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 and bootable image ready 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: 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 the section on Extending the SD Card Size.

Yocto Recovery Image

Beginning in Yocto Langdale, Variscite has released a new recovery Yocto image recipe called "var-recovery-image." This image is used to create a bootable SD card that contains another target image to be programmed to the eMMC. See the yocto Recovery SD card or the more manual Installing Yocto to the SOM's internal storage articles for specifics of installing a recovery image.

Usage:

To create a recovery image, simply run the following from your Yocto environment:

/$ bitbake var-recovery-image

This will produce an output relative to the build folder of "./tmp/deploy/images//var-recovery-image-." that can be flashed to the SD card. By default, this image boots fsl-image-gui and contains a fsl-image-gui target image to be programmed to eMMC.

You can also specify a different target eMMC image to be embedded in the recovery image by setting VAR_RECOVERY_TARGET_ROOTFS via the command line during build:
i.e.

/$ VAR_RECOVERY_TARGET_ROOTFS="<desired-emmc-image-recipe>" bitbake var-recovery-image


Or alternatively, by setting this variable in local.conf:

/$ VAR_RECOVERY_TARGET_ROOTFS = "<desired-emmc-image-recipe>" 


Additionally, the file name of the recovery image output can be modified by setting something like the following in local.conf:

/$ echo 'VAR_RECOVERY_SD_NAME = ""' >> conf/local.conf

Would produce a recovery image relative to the build folder of "./tmp/deploy/images//."

Note: Please see the [/blob//recipes-core/images/var-recovery-image.bb var-recovery-image recipe source] for advanced usages of the recovery image.

Extending the SD Card Size

Flashing the default . images from Yocto results in a rootfs that does not utilize the entire SD card. This section explains how the SD card can be extended on the build host after flashing.

Procedure:

Begin with an SD card on which you have previously flashed a Yocto . image. Ensure the SD card is inserted and the device present (i.e. /dev/sda, /dev/mmcblk0, etc.)

Note: Below replace /dev/sdX with your actual device (i.e. /dev/sda)

Start by running fdisk as below and typing "p" and enter to print current partitions. You should see a layout similar to below but numbers may differ depending on card sizes. Note that the partition starts at 16,384 (bytes offset 16384*512) which is to account for the boot content explained above.

$ sudo fdisk /dev/sdX

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors                                                                                              
Disk model: MassStorageClass                                                                                                                                
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: 0x5ebf1617                                                                                                                                 
                                                                                                                                                           
Device     Boot Start      End  Sectors  Size Id Type                                                                                                       
/dev/sdX1       16384 15165439 15149056  7.2G 83 Linux

Next, run the following sequence of commands followed by enter with each step explained with a "-" to the right. Each command/input should be followed by enter:

  • d - Delete current partition (1).
  • n - Create a new parition.
  • - Empty, hit enter only which will leave default response p for primary partition.
  • - Empty, hit enter only which will leave default response 1 for first partition.
  • 16384 - Enter 16384 to begin partition past bootloader section.
  • - Empty, hit enter only which will leave last sector as default which should choose ending size of the SD card.
  • N - Answers no to not remove the ext4 signature on the disk
  • p - Print output and verify before we write. We should see the starting offset the same and the end expanded to fill the SD card.
  • w - Write output to disk


See the full log of the above sequence below:

Command (m for help): d                                                                                                                                     
Selected partition 1                                                                                                                                        
Partition 1 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-124735487, default 2048): 16384
Last sector, +/-sectors or +/-size{K,M,G,T,P} (16384-124735487, default 124735487): 

Created a new partition 1 of type 'Linux' and of size 59.5 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors
Disk model: MassStorageClass
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
identifier: 0x5ebf1617

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdX1       16384 124735487 124719104 59.5G 83 Linux

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


Finally, the file system needs to be resized on the disk to fill the now larger partition. Do that as follows:

$ sudo e2fsck -f /dev/sdX1                                                    
e2fsck 1.46.5 (30-Dec-2021)                                                                                                                                 
root: recovering journal                                                                                                                                    
Pass 1: Checking inodes, blocks, and sizes                                                                                                                  
Pass 2: Checking directory structure                                                                                                                        
Pass 3: Checking directory connectivity                                                                                                                     
Pass 4: Checking reference counts                                                                                                                           
Pass 5: Checking group summary information                                                                                                                  
root: 43155/947488 files (0.1% non-contiguous), 674097/1893632 blocks

$ sudo resize2fs /dev/sdX1                                                    
resize2fs 1.46.5 (30-Dec-2021)                                                                                                                              
Resizing the filesystem on /dev/sdX1 to 15589888 (4k) blocks.                                                                                               
The filesystem on /dev/sdX1 is now 15589888 (4k) blocks long.

$ sync


Again, numbers and output should differ slightly depending on your card.

Your rootfs image should now fill the entire SD card and is ready to boot.