Brendan
Brendan

Reputation: 978

How to format partitions for Yocto sdcard image for Variscite iMX6

I am looking at generating my own IMAGE_FSTYPES=sdcard image for a Freescale Variscite VAR-SOM-MX6. I have copied the meta-fsl-arm/classes/image_types_fsl.bbclass class and modified it slightly so that there are three partitions rather than two. I am looking to include a third partition which is formatted as FAT (vfat) so that files can be added onto the sdcard so that they do not sit alongside files in the boot partition or the root file system.

I have made additions to the generate_imx_sdcard() function where I create a new partition:

generate_imx_sdcard () {
# Create partition table
parted -s ${SDCARD} mklabel msdos
parted -s ${SDCARD} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
parted -s ${SDCARD} unit KiB mkpart primary $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE)
# Line below is the new partition I have added
parted -s ${SDCARD} unit KiB mkpart primary fat32 $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE \+ ${THIRD_PARTITION})
parted ${SDCARD} print

I have ensured that the total sdcard side accommodates this by including this, where I add the new partition size ${THIRD_PARTITION} to the total sdcard (device) size:

IMAGE_CMD_sdcard () {
if [ -z "${SDCARD_ROOTFS}" ]; then
    bberror "SDCARD_ROOTFS is undefined. To use sdcard image from Freescale's BSP it needs to be defined."
exit 1
fi
# Align boot partition and calculate total SD card image size
BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
SDCARD_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT} + ${THIRD_PARTITION})

When I bitbake my layer and burn the output sdcard image to an SD card, the partitions are appropriately sized and available however the question/problem that I have is, how do I format this newly created partition?

I understand that a regular method of doing this would be something along the lines of mkfs.vfat -n "Partition Name" /dev/sdd, where I supply a device, however I am unsure how to go about this in Yocto as there is no device identifier, just the ${SDCARD} variable. I understand that if the partition was to be formatted as an ext4 file system then it would be possible to provide offsets to do the formatting however it seems like there is no option to do this if I wanted it formatted as vfat.

Any help would be greatly appreciated.

Upvotes: 3

Views: 3749

Answers (2)

sigmasrb
sigmasrb

Reputation: 11

I am not sure if this is still a relevant thing to you Brendan, but it might help anyone else who comes here looking for help. I managed to format the partition by doing something similar like with the boot, by creating an image file for the third partition like:

SDIMG_THIRD_TYPE ?= "fat" SDIMG_THIRD = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.${SDIMG_THIRD_TYPE}"

And then following it up with

THIRD_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 3 / { print substr($4, 1, length($4 -1)) / 512 /2 }')

mkfs.vfat -n "PART_NAME" -S 512 -C ${SDIMG_THIRD} $THIRD_BLOCKS

Keep in mind that the number 3 in the THIRD_BLOCKS should be the number of your partition in the order (mine was third).

And of course later in the code burning it with dd with something along the lines of:

dd if=${SDIMG_THIRD} of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024 + ${ROOTFS_SIZE} \* 1024) && sync && sync

P.S. You don't necessarily have to set a static size for ROOTFS, this can also be done from the yocto image recipe itself. I just did it for the sake of showing an example. Hope this helps.

Upvotes: 1

BenKwan
BenKwan

Reputation: 197

From my point of view, the way used in image_types_fsl.bbclass to generate a SD card image is little complicated and error-prone if you want to edit it.

I would suggest you to use wic to create your image instead.

Upvotes: 0

Related Questions