1 inherit image
3 # Add the fstypes we need
4 IMAGE_FSTYPES_append = " tar.bz2 sdimg"
6 # Change this to match your host distro
7 LOSETUP ?= "/sbin/losetup"
9 # Since these need to go in /etc/fstab we can hardcode them
10 # Since the vars are weakly assigned, you can override them from your local.conf
11 LOOPDEV ?= "/dev/loop1"
12 LOOPDEV_BOOT ?= "/dev/loop2"
13 LOOPDEV_FS ?= "/dev/loop3"
15 # Default to 4GiB images
16 SDIMG_SIZE ?= "444"
18 BOOTPARTNAME_beaglebone = "BEAGLE_BONE"
19 BOOTPARTNAME ?= "${MACHINE}"
21 IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}"
23 # Files and/or directories to be copied into the vfat partition
24 FATPAYLOAD ?= ""
26 IMAGE_CMD_sdimg () {
27 SDIMG=${WORKDIR}/sd.img
29 # sanity check fstab entry for boot partition mounting
30 if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then
31 echo "/etc/fstab entries need to be created with the user flag for the loop devices like:"
32 echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot msdos user 0 0"
33 false
34 fi
36 # cleanup loops
37 for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do
38 ${LOSETUP} -d $loop || true
39 done
41 # If an SD image is already present, reuse and reformat it
42 if [ ! -e ${SDIMG} ] ; then
43 dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=${SDIMG_SIZE}
44 fi
46 ${LOSETUP} ${LOOPDEV} ${SDIMG}
48 # Create partition table
49 dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024
50 SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}')
51 CYLINDERS=$(echo $SIZE/255/63/512 | bc)
52 {
53 echo ,9,0x0C,*
54 echo ,,,-
55 } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV}
57 # Prepare loop devices for boot and filesystem partitions
58 BOOT_OFFSET=32256
59 FS_OFFSET_SECT=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /"|cut -d " " -f 2)
60 FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc)
61 FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /g" \
62 |cut -d " " -f 4 | cut -d "+" -f 1)
64 LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5)
65 LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc)
67 ${LOSETUP} -d ${LOOPDEV}
69 ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET}
71 /sbin/mkfs.msdos ${LOOPDEV_BOOT} -n ${BOOTPARTNAME} $LOOPDEV_BLOCKS
73 # Prepare filesystem partition
74 # Copy ubi used by flashing scripts
75 if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then
76 echo "Copying UBIFS image to file system"
77 cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi
78 fi
80 # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files
81 # from the root filesystem
83 mkdir -p ${WORKDIR}/tmp-mnt-boot
84 mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot
86 echo "Copying bootloaders into the boot partition"
87 if [ -e ${IMAGE_ROOTFS}/boot/MLO ] ; then
88 cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot
89 else
90 cp -v ${DEPLOY_DIR_IMAGE}/MLO ${WORKDIR}/tmp-mnt-boot
91 fi
93 # Check for u-boot SPL
94 if [ -e ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.img ] ; then
95 suffix=img
96 else
97 suffix=bin
98 fi
100 cp -v ${IMAGE_ROOTFS}/boot/uEnv.txt ${WORKDIR}/tmp-mnt-boot || true
101 cp -v ${IMAGE_ROOTFS}/boot/user.txt ${WORKDIR}/tmp-mnt-boot || true
103 if [ -e ${IMAGE_ROOTFS}/boot/u-boot.$suffix ] ; then
104 cp -v ${IMAGE_ROOTFS}/boot/{u-boot.$suffix} ${WORKDIR}/tmp-mnt-boot || true
105 else
106 cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix ${WORKDIR}/tmp-mnt-boot/u-boot.$suffix
107 fi
109 if [ -n ${FATPAYLOAD} ] ; then
110 echo "Copying payload into VFAT"
111 for entry in ${FATPAYLOAD} ; do
112 cp -av $entry ${WORKDIR}/tmp-mnt-boot
113 done
114 fi
116 # Cleanup VFAT mount
117 echo "Cleaning up VFAT mount"
118 umount ${WORKDIR}/tmp-mnt-boot
119 ${LOSETUP} -d ${LOOPDEV_BOOT} || true
121 # Prepare ext3 parition
122 echo "Creating ext3 loopback"
123 ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET}
125 # should use fdisk info
126 echo "Creating ext3 image"
127 touch ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
128 # lots of small files, so use 8k per inode, not 64k
129 genext2fs -i 8192 -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
130 tune2fs -L ${IMAGE_NAME} -j ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
132 dd if=${WORKDIR}/${IMAGE_NAME}.rootfs.ext3 of=${LOOPDEV_FS}
134 ${LOSETUP} -d ${LOOPDEV_FS} || true
136 gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz
137 rm -f ${WORKDIR}/sd.img
138 }