AnsweredAssumed Answered

How to format partitions in sdcard image

Question asked by brendanta on Aug 20, 2017
Latest reply on Nov 5, 2017 by brendanta

Hello,

 

I am looking at generating my own IMAGE_FSTYPES=sdcard image. 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:

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})

 

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?  

 

Any help would be greatly appreciated. 

Outcomes