summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorJoel A Fernandes <joelagnel@ti.com>2011-09-23 11:32:44 -0500
committerKoen Kooi <koen@dominion.thruhere.net>2011-09-25 16:43:25 +0200
commitfa4d0789fa3b074d963a794c11c48c91cfb2f21d (patch)
tree9f2361c75a53c859f7ce3d20d80dcf285a90a9aa /classes
parent5c553a225d1aa3957cddb7921136ea4b8149b8e6 (diff)
downloadmeta-ti-fa4d0789fa3b074d963a794c11c48c91cfb2f21d.tar.gz
sdcard_image: Helper class to create SD Card images
Tested with 3 different beagleboard image release builds so far For ideas, referenced Narcissus image builder written by Koen Kooi <k-kooi@ti.com> Signed-off-by: Joel A Fernandes <joelagnel@ti.com> Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'classes')
-rw-r--r--classes/sdcard_image.bbclass78
1 files changed, 78 insertions, 0 deletions
diff --git a/classes/sdcard_image.bbclass b/classes/sdcard_image.bbclass
new file mode 100644
index 00000000..b3885df6
--- /dev/null
+++ b/classes/sdcard_image.bbclass
@@ -0,0 +1,78 @@
1inherit image
2
3IMAGE_CMD_sdimg () {
4 SDIMG=${WORKDIR}/sd.img
5
6 # cleanup loops
7 for loop in $(losetup -j ${SDIMG}); do
8 loop_dev=$(echo $loop|cut -d ":" -f 1)
9 umount $loop_dev || true
10 losetup -d $loop_dev || true
11 done
12
13 dd if=/dev/zero of=${SDIMG} bs=4k seek=$(echo '256 * 1024' | bc) count=1
14 losetup -f ${SDIMG}
15 LOOPDEV=$(losetup -j ${SDIMG} -o 0 | cut -d ":" -f 1)
16
17 # Create partition table
18 dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024
19 SIZE=`fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}'`
20 CYLINDERS=`echo $SIZE/255/63/512 | bc`
21 {
22 echo ,9,0x0C,*
23 echo ,,,-
24 } | sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV}
25
26 # Prepare loop devices for boot and filesystem partitions
27 BOOT_OFFSET=32256
28 FS_OFFSET_SECT=$(/sbin/fdisk -l -u $LOOPDEV 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /"|cut -d " " -f 2)
29 FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc)
30 FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u $LOOPDEV 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /g" \
31 |cut -d " " -f 4 | cut -d "+" -f 1)
32
33 LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u $LOOPDEV 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5)
34 LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc)
35
36 losetup -f ${SDIMG} -o ${BOOT_OFFSET} --sizelimit=$LOOPDEV_BYTES
37
38 LOOPDEV_BOOT=$(losetup -j ${SDIMG} -o ${BOOT_OFFSET} | cut -d ":" -f 1)
39 mkfs.msdos ${LOOPDEV_BOOT} -n boot
40
41 losetup -f ${SDIMG} -o ${FS_OFFSET}
42 LOOPDEV_FS=$(losetup -j ${SDIMG} -o ${FS_OFFSET} | cut -d ":" -f 1)
43
44 # Prepare filesystem partition
45 # Copy ubi used by flashing scripts
46 if [ -e ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ] ; then
47 echo "Copying UBIFS image to file system"
48 cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi
49 fi
50 ROOTFS_SIZE="$(du -ks ${IMAGE_ROOTFS} | awk '{print 65536 + $1}')"
51 genext2fs -b ${FS_SIZE_BLOCKS} -d ${IMAGE_ROOTFS} ${LOOPDEV_FS}
52 tune2fs -j ${LOOPDEV_FS}
53
54 # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files
55 # from the root filesystem
56
57 # sanity check fstab entry for boot partition mounting
58 if [ "x$(cat /etc/fstab | grep $LOOPDEV_BOOT | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then
59 echo "/etc/fstab entries need to be created with the user flag for $LOOPDEV_BOOT like:"
60 echo "$LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot msdos user 0 0"
61 false
62 fi
63
64 mkdir -p ${WORKDIR}/tmp-mnt-boot
65 mount $LOOPDEV_BOOT
66
67 echo "Copying bootloaders into the boot partition"
68 cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot
69 cp -v ${IMAGE_ROOTFS}/boot/{u-boot.bin,user.txt,uEnv.txt} ${WORKDIR}/tmp-mnt-boot || true
70
71 # cleanup
72 umount ${LOOPDEV_BOOT}
73 /sbin/losetup -d ${LOOPDEV}
74 /sbin/losetup -d ${LOOPDEV_BOOT}
75 /sbin/losetup -d ${LOOPDEV_FS}
76
77 gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${PR}.img.gz
78}