sdcard_image: rewrote to avoid using loopback and mount/unmount
PATCH 1/3 sdcard_image: rewrote to avoid using loopback and mount/unmount
Allow generation by regular users without fancy setup requirements and use of loopback and mount/unmount. Besides, this also includes following improvements:
* use of megabytes when specifying SDIMG_SIZE
* remove restriction of filesystem to rootfs
Images that use this class needs to generate the rootfs filesystem and set ROOTFS variable according.
--- classes/sdcard_image.bbclass | 179 +++++++++++++++--------------------------- 1 files changed, 63 insertions(+), 116 deletions(-)
classes/sdcard_image.bbclass +63 -116
@@ -1,99 +1,43 @@ +# Copyright (C) 2011 O.S. Systems Software LTDA. +# +# Create an image that can by written onto a SD card using dd. +# +# External variables needed: +# ${ROOTFS} - the rootfs image to incorporate + inherit image # Add the fstypes we need -IMAGE_FSTYPES_append = " tar.bz2 sdimg" +IMAGE_FSTYPES += "sdimg" # Ensure required utilities are present -IMAGE_DEPENDS_sdimg = "genext2fs-native e2fsprogs-native" - -# Change this to match your host distro -LOSETUP ?= "/sbin/losetup" - -# Since these need to go in /etc/fstab we can hardcode them -# Since the vars are weakly assigned, you can override them from your local.conf -LOOPDEV ?= "/dev/loop1" -LOOPDEV_BOOT ?= "/dev/loop2" -LOOPDEV_FS ?= "/dev/loop3" +IMAGE_DEPENDS_sdimg = "dosfstools-native parted-native" # Default to 4GiB images -SDIMG_SIZE ?= "444" +SDIMG_SIZE ?= "4000" -# FS type for rootfs -ROOTFSTYPE ?= "ext3" +# Boot partition volume id +BOOTDD_VOLUME_ID_beaglebone = "BEAGLE_BONE" +BOOTDD_VOLUME_ID ?= "${MACHINE}" -BOOTPARTNAME_beaglebone = "BEAGLE_BONE" -BOOTPARTNAME ?= "${MACHINE}" - -IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" +# Addional space for boot partition +BOOTDD_EXTRA_SPACE ?= "16384" # Files and/or directories to be copied into the vfat partition FATPAYLOAD ?= "" IMAGE_CMD_sdimg () { - SDIMG=${WORKDIR}/sd.img - - # sanity check fstab entry for boot partition mounting - if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then - echo "/etc/fstab entries need to be created with the user flag for the loop devices like:" - echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot vfat user 0 0" - false - fi - - # cleanup loops - for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do - ${LOSETUP} -d $loop || true - done - - # If an SD image is already present, reuse and reformat it - if [ ! -e ${SDIMG} ] ; then - dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=${SDIMG_SIZE} - fi - - ${LOSETUP} ${LOOPDEV} ${SDIMG} - - # Create partition table - dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024 - SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}') - CYLINDERS=$(echo $SIZE/255/63/512 | bc) - { - echo ,9,0x0C,* - echo ,,,- - } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV} - - # Prepare loop devices for boot and filesystem partitions - BOOT_OFFSET=32256 - FS_OFFSET_SECT=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /"|cut -d " " -f 2) - FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc) - FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /g" \ - |cut -d " " -f 4 | cut -d "+" -f 1) - - LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5) - LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc) - - ${LOSETUP} -d ${LOOPDEV} - - ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET} - - /sbin/mkfs.vfat ${LOOPDEV_BOOT} -n ${BOOTPARTNAME} $LOOPDEV_BLOCKS - - # Prepare filesystem partition - # Copy ubi used by flashing scripts - if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then - echo "Copying UBIFS image to file system" - cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi - fi + TMP=${WORKDIR}/tmp + SDIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.sdimg - # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files - # from the root filesystem - - mkdir -p ${WORKDIR}/tmp-mnt-boot - mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot + # Prepare boot filesystem + install -d $TMP/boot echo "Copying bootloaders into the boot partition" if [ -e ${IMAGE_ROOTFS}/boot/MLO ] ; then - cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${IMAGE_ROOTFS}/boot/MLO $TMP/boot else - cp -v ${DEPLOY_DIR_IMAGE}/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${DEPLOY_DIR_IMAGE}/MLO $TMP/boot fi # Check for u-boot SPL
@@ -103,54 +47,57 @@ IMAGE_CMD_sdimg () { suffix=bin fi - cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/user.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/uImage ${WORKDIR}/tmp-mnt-boot || true - if [ -e ${IMAGE_ROOTFS}/boot/u-boot.$suffix ] ; then - cp -v ${IMAGE_ROOTFS}/boot/{u-boot.$suffix} ${WORKDIR}/tmp-mnt-boot || true + cp -v ${IMAGE_ROOTFS}/boot/u-boot.$suffix $TMP/boot || true else - cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix ${WORKDIR}/tmp-mnt-boot/u-boot.$suffix + cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix $TMP/boot/u-boot.$suffix + fi + + if [ -e ${IMAGE_ROOTFS}/boot/uImage ]; then + cp -v ${IMAGE_ROOTFS}/boot/uImage $TMP/boot || true + else + cp -v ${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.$suffix $TMP/boot/uImage + fi + + cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt $TMP/boot || true + cp -v ${IMAGE_ROOTFS}/boot/user.txt $TMP/boot || true + + # Copy ubi used by flashing scripts + if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then + echo "Copying UBIFS image to file system" + cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi fi if [ -n ${FATPAYLOAD} ] ; then echo "Copying payload into VFAT" for entry in ${FATPAYLOAD} ; do # add the || true to stop aborting on vfat issues like not supporting .~lock files - cp -av ${IMAGE_ROOTFS}$entry ${WORKDIR}/tmp-mnt-boot || true + cp -av ${IMAGE_ROOTFS}$entry $TMP/boot || true done fi - echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${IMAGE_ROOTFS}/etc/image-version-info - - # Cleanup VFAT mount - echo "Cleaning up VFAT mount" - umount ${WORKDIR}/tmp-mnt-boot - ${LOSETUP} -d ${LOOPDEV_BOOT} || true - - # Prepare rootfs parition - echo "Creating rootfs loopback" - ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET} - - FS_NUM_INODES=$(echo $FS_SIZE_BLOCKS / 4 | bc) - - case "${ROOTFSTYPE}" in - ext3) - genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS} - tune2fs -L ${IMAGE_NAME} -j ${LOOPDEV_FS} - ;; - ext4) - genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS} - tune2fs -L ${IMAGE_NAME} -j -O extents,uninit_bg,dir_index ${LOOPDEV_FS} - ;; - *) - echo "Please set ROOTFSTYPE to something supported" - exit 1 - ;; - esac - - ${LOSETUP} -d ${LOOPDEV_FS} || true - - gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz - rm -f ${WORKDIR}/sd.img + dd if=/dev/zero of=${SDIMG} bs=`expr 1000 \* 1000` count=${SDIMG_SIZE} + + # Create the boot filesystem + BOOT_OFFSET=32256 + BOOT_BLOCKS=`du -bks $TMP/boot | cut -f 1` + BOOT_SIZE=`expr $BOOT_BLOCKS + ${BOOTDD_EXTRA_SPACE}` + mkfs.vfat -n ${BOOTDD_VOLUME_ID} -d $TMP/boot -C $TMP/boot.img $BOOT_SIZE + + # Create partition table + END1=`expr $BOOT_SIZE \* 1024` + END2=`expr $END1 + 512` + parted -s ${SDIMG} mklabel msdos + parted -s ${SDIMG} mkpart primary fat16 ${BOOT_OFFSET}B ${END1}B + parted -s ${SDIMG} mkpart primary ext3 ${END2}B 100% + parted -s ${SDIMG} set 1 boot on + parted ${SDIMG} print + + OFFSET1=`expr $BOOT_OFFSET / 512` + OFFSET2=`expr $END2 / 512` + dd if=$TMP/boot.img of=${SDIMG} conv=notrunc seek=$OFFSET1 bs=512 + dd if=${ROOTFS} of=${SDIMG} conv=notrunc seek=$OFFSET2 bs=512 + + cd ${DEPLOY_DIR_IMAGE} + ln -sf ${IMAGE_NAME}.sdimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.sdimg }
Signature · 1 line
1.7.2.5
PATCH 2/3 ti-hw-bringup-image: adapt to newer sdcard_image class
--- recipes-misc/images/ti-hw-bringup-image.bb | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
recipes-misc/images/ti-hw-bringup-image.bb +3 -0
@@ -38,4 +38,7 @@ IMAGE_LOGIN_MANAGER = "tinylogin shadow" export IMAGE_BASENAME = "TI-hw-bringup" +ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3" +IMAGE_FSTYPES = "ext3" + inherit sdcard_image
Signature · 1 line
1.7.2.5
PATCH 3/3 cloud9-image: adapt to newer sdcard_image class
In reply to Otavio Salvador--- recipes-misc/images/cloud9-image.bb | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
recipes-misc/images/cloud9-image.bb +3 -3
@@ -4,8 +4,6 @@ require ti-hw-bringup-image.bb FATPAYLOAD = "${datadir}/beaglebone-getting-started/*" -ROOTFSTYPE_beaglebone = "ext4" - IMAGE_INSTALL += " \ cloud9 \ task-sdk-target \
@@ -27,5 +25,7 @@ IMAGE_INSTALL += " \ nodejs-dev \ " -export IMAGE_BASENAME = "Cloud9-IDE" +ROOTFS_beaglebone = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext4" +IMAGE_FSTYPES_beaglebone= "ext4" +export IMAGE_BASENAME = "Cloud9-IDE"
Signature · 1 line
1.7.2.5
Otavio,
Quoted 9 lines · Otavio Salvador
Allow generation by regular users without fancy setup requirements and use of loopback and mount/unmount. Besides, this also includes following improvements:
* use of megabytes when specifying
SDIMG_SIZE
* remove restriction of filesystem to rootfsImages that use this class needs to generate the rootfs filesystem and set ROOTFS variable according.
I'm not sure using parted instead of genext2fs is much better, but I haven't tested it yet...
classes/sdcard_image.bbclass line 1
Quoted 11 lines
Signed-off-by Otavio Salvador <[email protected]>--- classes/sdcard_image.bbclass | 179 +++++++++++++++--------------------------- 1 files changed, 63 insertions(+), 116 deletions(-)classes/sdcard_image.bbclass +1
-0@@ -1,99 +1,43 @@ +# Copyright (C) 2011 O.S. Systems Software LTDA.
I don't think you can claim copyright for a derivative work.
Quoted 187 lines
classes/sdcard_image.bbclass +38
-112+# +# Create an image that can by written onto a SD card using dd. +# +# External variables needed: +# ${ROOTFS} - the rootfs image to incorporate + inherit image # Add the fstypes we need -IMAGE_FSTYPES_append = " tar.bz2 sdimg" +IMAGE_FSTYPES += "sdimg" # Ensure required utilities are present -IMAGE_DEPENDS_sdimg = "genext2fs-native e2fsprogs-native" - -# Change this to match your host distro -LOSETUP ?= "/sbin/losetup" - -# Since these need to go in /etc/fstab we can hardcode them -# Since the vars are weakly assigned, you can override them from your local.conf -LOOPDEV ?= "/dev/loop1" -LOOPDEV_BOOT ?= "/dev/loop2" -LOOPDEV_FS ?= "/dev/loop3" +IMAGE_DEPENDS_sdimg = "dosfstools-native parted-native" # Default to 4GiB images -SDIMG_SIZE ?= "444" +SDIMG_SIZE ?= "4000" -# FS type for rootfs -ROOTFSTYPE ?= "ext3" +# Boot partition volume id +BOOTDD_VOLUME_ID_beaglebone = "BEAGLE_BONE" +BOOTDD_VOLUME_ID ?= "${MACHINE}" -BOOTPARTNAME_beaglebone = "BEAGLE_BONE" -BOOTPARTNAME ?= "${MACHINE}" - -IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" +# Addional space for boot partition +BOOTDD_EXTRA_SPACE ?= "16384" # Files and/or directories to be copied into the vfat partition FATPAYLOAD ?= "" IMAGE_CMD_sdimg () { - SDIMG=${WORKDIR}/sd.img - - # sanity check fstab entry for boot partition mounting - if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then - echo "/etc/fstab entries need to be created with the user flag for the loop devices like:" - echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot vfat user 0 0" - false - fi - - # cleanup loops - for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do - ${LOSETUP} -d $loop || true - done - - # If an SD image is already present, reuse and reformat it - if [ ! -e ${SDIMG} ] ; then - dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=${SDIMG_SIZE} - fi - - ${LOSETUP} ${LOOPDEV} ${SDIMG} - - # Create partition table - dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024 - SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}') - CYLINDERS=$(echo $SIZE/255/63/512 | bc) - { - echo ,9,0x0C,* - echo ,,,- - } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV} - - # Prepare loop devices for boot and filesystem partitions - BOOT_OFFSET=32256 - FS_OFFSET_SECT=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /"|cut -d " " -f 2) - FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc) - FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /g" \ - |cut -d " " -f 4 | cut -d "+" -f 1) - - LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5) - LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc) - - ${LOSETUP} -d ${LOOPDEV} - - ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET} - - /sbin/mkfs.vfat ${LOOPDEV_BOOT} -n ${BOOTPARTNAME} $LOOPDEV_BLOCKS - - # Prepare filesystem partition - # Copy ubi used by flashing scripts - if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then - echo "Copying UBIFS image to file system" - cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi - fi + TMP=${WORKDIR}/tmp + SDIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.sdimg - # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files - # from the root filesystem - - mkdir -p ${WORKDIR}/tmp-mnt-boot - mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot + # Prepare boot filesystem + install -d $TMP/boot echo "Copying bootloaders into the boot partition" if [ -e ${IMAGE_ROOTFS}/boot/MLO ] ; then - cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${IMAGE_ROOTFS}/boot/MLO $TMP/boot else - cp -v ${DEPLOY_DIR_IMAGE}/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${DEPLOY_DIR_IMAGE}/MLO $TMP/boot fi # Check for u-boot SPL@@ -103,54 +47,57 @@ IMAGE_CMD_sdimg () { suffix=bin fi - cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/user.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/uImage ${WORKDIR}/tmp-mnt-boot || true - if [ -e ${IMAGE_ROOTFS}/boot/u-boot.$suffix ] ; then - cp -v ${IMAGE_ROOTFS}/boot/{u-boot.$suffix} ${WORKDIR}/tmp-mnt-boot || true + cp -v ${IMAGE_ROOTFS}/boot/u-boot.$suffix $TMP/boot || true else - cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix ${WORKDIR}/tmp-mnt-boot/u-boot.$suffix + cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix $TMP/boot/u-boot.$suffix + fi + + if [ -e ${IMAGE_ROOTFS}/boot/uImage ]; then + cp -v ${IMAGE_ROOTFS}/boot/uImage $TMP/boot || true + else + cp -v ${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.$suffix $TMP/boot/uImage + fi + + cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt $TMP/boot || true + cp -v ${IMAGE_ROOTFS}/boot/user.txt $TMP/boot || true + + # Copy ubi used by flashing scripts + if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then + echo "Copying UBIFS image to file system" + cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi fi if [ -n ${FATPAYLOAD} ] ; then echo "Copying payload into VFAT" for entry in ${FATPAYLOAD} ; do # add the || true to stop aborting on vfat issues like not supporting .~lock files - cp -av ${IMAGE_ROOTFS}$entry ${WORKDIR}/tmp-mnt-boot || true + cp -av ${IMAGE_ROOTFS}$entry $TMP/boot || true done fi - echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${IMAGE_ROOTFS}/etc/image-version-info - - # Cleanup VFAT mount - echo "Cleaning up VFAT mount" - umount ${WORKDIR}/tmp-mnt-boot - ${LOSETUP} -d ${LOOPDEV_BOOT} || true - - # Prepare rootfs parition - echo "Creating rootfs loopback" - ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET} - - FS_NUM_INODES=$(echo $FS_SIZE_BLOCKS / 4 | bc) - - case "${ROOTFSTYPE}" in - ext3) - genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS} - tune2fs -L ${IMAGE_NAME} -j ${LOOPDEV_FS} - ;; - ext4) - genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS} - tune2fs -L ${IMAGE_NAME} -j -O extents,uninit_bg,dir_index ${LOOPDEV_FS} - ;; - *) - echo "Please set ROOTFSTYPE to something supported" - exit 1 - ;; - esac -
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 84
Quoted 10 lines
classes/sdcard_image.bbclass +6
-4- ${LOSETUP} -d ${LOOPDEV_FS} || true - - gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz - rm -f ${WORKDIR}/sd.img + dd if=/dev/zero of=${SDIMG} bs=`expr 1000 \* 1000` count=${SDIMG_SIZE} + + # Create the boot filesystem + BOOT_OFFSET=32256 + BOOT_BLOCKS=`du -bks $TMP/boot | cut -f 1` + BOOT_SIZE=`expr $BOOT_BLOCKS + ${BOOTDD_EXTRA_SPACE}`
Can you please replace backticks?
Quoted 27 lines
classes/sdcard_image.bbclass +18
-0+ mkfs.vfat -n ${BOOTDD_VOLUME_ID} -d $TMP/boot -C $TMP/boot.img $BOOT_SIZE + + # Create partition table + END1=`expr $BOOT_SIZE \* 1024` + END2=`expr $END1 + 512` + parted -s ${SDIMG} mklabel msdos + parted -s ${SDIMG} mkpart primary fat16 ${BOOT_OFFSET}B ${END1}B + parted -s ${SDIMG} mkpart primary ext3 ${END2}B 100% + parted -s ${SDIMG} set 1 boot on + parted ${SDIMG} print + + OFFSET1=`expr $BOOT_OFFSET / 512` + OFFSET2=`expr $END2 / 512` + dd if=$TMP/boot.img of=${SDIMG} conv=notrunc seek=$OFFSET1 bs=512 + dd if=${ROOTFS} of=${SDIMG} conv=notrunc seek=$OFFSET2 bs=512 + + cd ${DEPLOY_DIR_IMAGE} + ln -sf ${IMAGE_NAME}.sdimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.sdimg }Signature · 6 lines
1.7.2.5 _______________________________________________ meta-ti mailing list [email protected] https://lists.yoctoproject.org/listinfo/meta-ti
Quoted 6 lines · Denys Dmytriyenko
Quoted 2 lines
Images that use this class needs to generate the rootfs filesystem and set ROOTFS variable according.
I'm not sure using parted instead of genext2fs is much better, but I haven't
tested it yet...
It avoid a lot of non-obvious math and deep knowledge about device geometry. I prefer this then previous fdisk/sfdisk hacks.
It worked fine for me with beagleboard.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Otavio Salvador <[email protected]>--- classes/sdcard_image.bbclass | 179+++++++++++++++---------------------------
Quoted 2 lines
1 files changed, 63 insertions(+), 116 deletions(-)
Quoted 8 lines
classes/sdcard_image.bbclass line 1
Quoted 6 lines
classes/sdcard_image.bbclass +1
-0@@ -1,99 +1,43 @@ +# Copyright (C) 2011 O.S. Systems Software LTDA.I don't think you can claim copyright for a derivative work.
If you check the diff, it is 79% different but I don't mind too much about it. We can put original one together if it fits better.
Quoted 217 lines
Quoted 10 lines
classes/sdcard_image.bbclass +6
-1+# +# Create an image that can by written onto a SD card using dd. +# +# External variables needed: +# ${ROOTFS} - the rootfs image to incorporate + inherit image # Add the fstypes we need -IMAGE_FSTYPES_append = " tar.bz2 sdimg"classes/sdcard_image.bbclass
Quoted 10 lines
classes/sdcard_image.bbclass +1
-7+IMAGE_FSTYPES += "sdimg" # Ensure required utilities are present -IMAGE_DEPENDS_sdimg = "genext2fs-native e2fsprogs-native" - -# Change this to match your host distro -LOSETUP ?= "/sbin/losetup" - -# Since these need to go in /etc/fstab we can hardcode them -# Since the vars are weakly assigned, you can override them from yourlocal.conf
Quoted 20 lines
classes/sdcard_image.bbclass +6
-10-LOOPDEV ?= "/dev/loop1" -LOOPDEV_BOOT ?= "/dev/loop2" -LOOPDEV_FS ?= "/dev/loop3" +IMAGE_DEPENDS_sdimg = "dosfstools-native parted-native" # Default to 4GiB images -SDIMG_SIZE ?= "444" +SDIMG_SIZE ?= "4000" -# FS type for rootfs -ROOTFSTYPE ?= "ext3" +# Boot partition volume id +BOOTDD_VOLUME_ID_beaglebone = "BEAGLE_BONE" +BOOTDD_VOLUME_ID ?= "${MACHINE}" -BOOTPARTNAME_beaglebone = "BEAGLE_BONE" -BOOTPARTNAME ?= "${MACHINE}" - -IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" +# Addional space for boot partitionclasses/sdcard_image.bbclass
Quoted 10 lines
classes/sdcard_image.bbclass +1
-4+BOOTDD_EXTRA_SPACE ?= "16384" # Files and/or directories to be copied into the vfat partition FATPAYLOAD ?= "" IMAGE_CMD_sdimg () { - SDIMG=${WORKDIR}/sd.img - - # sanity check fstab entry for boot partition mounting - if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then
classes/sdcard_image.bbclass line 37
Quoted 1 line
classes/sdcard_image.bbclass +0
-1- echo "/etc/fstab entries need to be created with the userflag for the loop devices like:"
classes/sdcard_image.bbclass line 38
Quoted 1 line
classes/sdcard_image.bbclass +0
-1- echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot vfat user 00"
classes/sdcard_image.bbclass
Quoted 11 lines
classes/sdcard_image.bbclass +0
-11- false - fi - - # cleanup loops - for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do - ${LOSETUP} -d $loop || true - done - - # If an SD image is already present, reuse and reformat it - if [ ! -e ${SDIMG} ] ; then - dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' |bc) count=${SDIMG_SIZE}
classes/sdcard_image.bbclass
Quoted 7 lines
classes/sdcard_image.bbclass +0
-7- fi - - ${LOSETUP} ${LOOPDEV} ${SDIMG} - - # Create partition table - dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024 - SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk'{print $5}')
classes/sdcard_image.bbclass
Quoted 9 lines
classes/sdcard_image.bbclass +0
-9- CYLINDERS=$(echo $SIZE/255/63/512 | bc) - { - echo ,9,0x0C,* - echo ,,,- - } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV} - - # Prepare loop devices for boot and filesystem partitions - BOOT_OFFSET=32256 - FS_OFFSET_SECT=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux |perl -p -i -e "s/\s+/ /"|cut -d " " -f 2)
classes/sdcard_image.bbclass line 67
Quoted 2 lines
classes/sdcard_image.bbclass +0
-2- FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc) - FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux |perl -p -i -e "s/\s+/ /g" \
classes/sdcard_image.bbclass
Quoted 3 lines
classes/sdcard_image.bbclass +0
-3- |cut -d " " -f 4 | cut -d "+" -f 1) - - LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep FAT |perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5)
classes/sdcard_image.bbclass
Quoted 13 lines
classes/sdcard_image.bbclass +0
-13- LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc) - - ${LOSETUP} -d ${LOOPDEV} - - ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET} - - /sbin/mkfs.vfat ${LOOPDEV_BOOT} -n ${BOOTPARTNAME} $LOOPDEV_BLOCKS - - # Prepare filesystem partition - # Copy ubi used by flashing scripts - if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then - echo "Copying UBIFS image to file system" - cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi${IMAGE_ROOTFS}/boot/fs.ubi
classes/sdcard_image.bbclass
Quoted 5 lines
classes/sdcard_image.bbclass +2
-2- fi + TMP=${WORKDIR}/tmp + SDIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.sdimg - # Prepare boot partion. First mount the boot partition, and copythe boot loader and supporting files
Quoted 18 lines
classes/sdcard_image.bbclass +4
-6- # from the root filesystem - - mkdir -p ${WORKDIR}/tmp-mnt-boot - mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot + # Prepare boot filesystem + install -d $TMP/boot echo "Copying bootloaders into the boot partition" if [ -e ${IMAGE_ROOTFS}/boot/MLO ] ; then - cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${IMAGE_ROOTFS}/boot/MLO $TMP/boot else - cp -v ${DEPLOY_DIR_IMAGE}/MLO ${WORKDIR}/tmp-mnt-boot + cp -v ${DEPLOY_DIR_IMAGE}/MLO $TMP/boot fi # Check for u-boot SPLclasses/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 111
Quoted 9 lines
classes/sdcard_image.bbclass +0
-5@@ -103,54 +47,57 @@ IMAGE_CMD_sdimg () { suffix=bin fi - cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/user.txt ${WORKDIR}/tmp-mnt-boot || true - cp -v ${IMAGE_ROOTFS}/boot/uImage ${WORKDIR}/tmp-mnt-boot || true - if [ -e ${IMAGE_ROOTFS}/boot/u-boot.$suffix ] ; then - cp -v ${IMAGE_ROOTFS}/boot/{u-boot.$suffix}${WORKDIR}/tmp-mnt-boot || true
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 3 lines
classes/sdcard_image.bbclass +1
-1+ cp -v ${IMAGE_ROOTFS}/boot/u-boot.$suffix $TMP/boot || true else - cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix${WORKDIR}/tmp-mnt-boot/u-boot.$suffix
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 53
Quoted 1 line
classes/sdcard_image.bbclass +1
-0+ cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix$TMP/boot/u-boot.$suffix
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 6 lines
classes/sdcard_image.bbclass +6
-0+ fi + + if [ -e ${IMAGE_ROOTFS}/boot/uImage ]; then + cp -v ${IMAGE_ROOTFS}/boot/uImage $TMP/boot || true + else + cp -v ${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.$suffix$TMP/boot/uImage
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 9 lines
classes/sdcard_image.bbclass +9
-0+ fi + + cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt $TMP/boot || true + cp -v ${IMAGE_ROOTFS}/boot/user.txt $TMP/boot || true + + # Copy ubi used by flashing scripts + if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then + echo "Copying UBIFS image to file system" + cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi${IMAGE_ROOTFS}/boot/fs.ubi
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 6 lines
classes/sdcard_image.bbclass +0
-0fi if [ -n ${FATPAYLOAD} ] ; then echo "Copying payload into VFAT" for entry in ${FATPAYLOAD} ; do # add the || true to stop aborting on vfatissues like not supporting .~lock files
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 120
Quoted 1 line
classes/sdcard_image.bbclass +0
-1- cp -av ${IMAGE_ROOTFS}$entry${WORKDIR}/tmp-mnt-boot || true
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 75
Quoted 1 line
classes/sdcard_image.bbclass +1
-0+ cp -av ${IMAGE_ROOTFS}$entry $TMP/boot ||true
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 124
Quoted 4 lines
classes/sdcard_image.bbclass +0
-1done fi - echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" >${IMAGE_ROOTFS}/etc/image-version-info
Quoted 5 lines
classes/sdcard_image.bbclass +0
-5- - # Cleanup VFAT mount - echo "Cleaning up VFAT mount" - umount ${WORKDIR}/tmp-mnt-boot - ${LOSETUP} -d ${LOOPDEV_BOOT} || trueclasses/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 10 lines
classes/sdcard_image.bbclass +0
-10- - # Prepare rootfs parition - echo "Creating rootfs loopback" - ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET} - - FS_NUM_INODES=$(echo $FS_SIZE_BLOCKS / 4 | bc) - - case "${ROOTFSTYPE}" in - ext3) - genext2fs -z -N $FS_NUM_INODES -b$FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS}
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 4 lines
classes/sdcard_image.bbclass +0
-4- tune2fs -L ${IMAGE_NAME} -j ${LOOPDEV_FS} - ;; - ext4) - genext2fs -z -N $FS_NUM_INODES -b$FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS}
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 144
Quoted 1 line
classes/sdcard_image.bbclass +0
-1- tune2fs -L ${IMAGE_NAME} -j -Oextents,uninit_bg,dir_index ${LOOPDEV_FS}
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 3 lines
classes/sdcard_image.bbclass +0
-3- ;; - *) - echo "Please set ROOTFSTYPE to somethingsupported"
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 7 lines
classes/sdcard_image.bbclass +0
-7- exit 1 - ;; - esac - - ${LOSETUP} -d ${LOOPDEV_FS} || true - - gzip -c ${WORKDIR}/sd.img >${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 79
Quoted 2 lines
classes/sdcard_image.bbclass +1
-1- rm -f ${WORKDIR}/sd.img + dd if=/dev/zero of=${SDIMG} bs=`expr 1000 \* 1000`
Quoted 8 lines
count=${SDIMG_SIZE}
classes/sdcard_image.bbclass IMAGE_CMD_sdimg () { · line 84
Quoted 5 lines
classes/sdcard_image.bbclass +5
-0+ + # Create the boot filesystem + BOOT_OFFSET=32256 + BOOT_BLOCKS=`du -bks $TMP/boot | cut -f 1` + BOOT_SIZE=`expr $BOOT_BLOCKS + ${BOOTDD_EXTRA_SPACE}`Can you please replace backticks?
You prefer $(...) form?
Quoted 30 lines
+ mkfs.vfat -n ${BOOTDD_VOLUME_ID} -d $TMP/boot -C $TMP/boot.img
$BOOT_SIZEQuoted 7 lines
classes/sdcard_image.bbclass +7
-0+ + # Create partition table + END1=`expr $BOOT_SIZE \* 1024` + END2=`expr $END1 + 512` + parted -s ${SDIMG} mklabel msdos + parted -s ${SDIMG} mkpart primary fat16 ${BOOT_OFFSET}B ${END1}B + parted -s ${SDIMG} mkpart primary ext3 ${END2}B 100%classes/sdcard_image.bbclass IMAGE_CMD_sdimg () {
Quoted 10 lines
classes/sdcard_image.bbclass +10
-0+ parted -s ${SDIMG} set 1 boot on + parted ${SDIMG} print + + OFFSET1=`expr $BOOT_OFFSET / 512` + OFFSET2=`expr $END2 / 512` + dd if=$TMP/boot.img of=${SDIMG} conv=notrunc seek=$OFFSET1 bs=512 + dd if=${ROOTFS} of=${SDIMG} conv=notrunc seek=$OFFSET2 bs=512 + + cd ${DEPLOY_DIR_IMAGE} + ln -sf ${IMAGE_NAME}.sdimg${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.sdimg
Quoted 9 lines
classes/sdcard_image.bbclass +0
-1} --1.7.2.5
_______________________________________________
meta-ti mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-ti
Signature · 3 lines
Otavio Salvador O.S. Systems E-mail: [email protected] http://www.ossystems.com.br Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br
I need to sit down and run some tests before commenting on it futher, but:
Op 28 nov. 2011, om 21:56 heeft Otavio Salvador het volgende geschreven:
classes/sdcard_image.bbclass line 17
Quoted 4 lines
# Default to 4GiB images
classes/sdcard_image.bbclass +1
-1-SDIMG_SIZE ?= "444" +SDIMG_SIZE ?= "4000"
'444' is ±3400 MB, we need to account for the smallest of SD cards, the one in the factory is ±3700MB, we subtract 10% to be safe. Have a look at the size of e.g. http://dominion.thruhere.net/koen/angstrom/beaglebone/Angstrom-Cloud9-IDE-eglibc-ipk-v2011.11-core-beaglebone-2011.11.16.img.gz
regards,
Koen