summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorKoen Kooi <koen@dominion.thruhere.net>2011-10-08 00:42:20 +0200
committerKoen Kooi <koen@dominion.thruhere.net>2011-10-08 21:08:03 +0200
commitc26aa8ee7d41543a8e38994a1c584da8eb478512 (patch)
tree4a14111577cc1ce8b4b55f0143eb91a9423dfc2d /classes
parent4ab77fb9195f493c41d3d110903f2ec8234e2fd0 (diff)
downloadmeta-ti-c26aa8ee7d41543a8e38994a1c584da8eb478512.tar.gz
sdcard_image bbclass: make it work with older losetup versions among other things
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Diffstat (limited to 'classes')
-rw-r--r--classes/sdcard_image.bbclass118
1 files changed, 81 insertions, 37 deletions
diff --git a/classes/sdcard_image.bbclass b/classes/sdcard_image.bbclass
index 640c6a4a..7ab565a6 100644
--- a/classes/sdcard_image.bbclass
+++ b/classes/sdcard_image.bbclass
@@ -1,45 +1,62 @@
1inherit image 1inherit image
2 2
3# Add the fstypes we need
4IMAGE_FSTYPES_append = " tar.bz2 sdimg"
5
6# Change this to match your host distro
7LOSETUP ?= "/sbin/losetup"
8
9# Since these need to go in /etc/fstab we can hardcode them
10LOOPDEV ?= "/dev/loop1"
11LOOPDEV_BOOT ?= "/dev/loop2"
12LOOPDEV_FS ?= "/dev/loop3"
13
3IMAGE_CMD_sdimg () { 14IMAGE_CMD_sdimg () {
4 SDIMG=${WORKDIR}/sd.img 15 SDIMG=${WORKDIR}/sd.img
5 16
17 # sanity check fstab entry for boot partition mounting
18 if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then
19 echo "/etc/fstab entries need to be created with the user flag for the loop devices like:"
20 echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot msdos user 0 0"
21 false
22 fi
23
6 # cleanup loops 24 # cleanup loops
7 for loop in $(losetup -j ${SDIMG}); do 25 for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do
8 loop_dev=$(echo $loop|cut -d ":" -f 1) 26 ${LOSETUP} -d $loop || true
9 umount $loop_dev || true
10 losetup -d $loop_dev || true
11 done 27 done
12 28
13 dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=444 29 # If an SD image is already present, reuse and reformat it
14 losetup -f ${SDIMG} 30 if [ ! -e ${SDIMG} ] ; then
15 LOOPDEV=$(losetup -j ${SDIMG} -o 0 | cut -d ":" -f 1) 31 dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=444
32 fi
33
34 ${LOSETUP} ${LOOPDEV} ${SDIMG}
16 35
17 # Create partition table 36 # Create partition table
18 #dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024 37 dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024
19 SIZE=`fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}'` 38 SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}')
20 CYLINDERS=`echo $SIZE/255/63/512 | bc` 39 CYLINDERS=$(echo $SIZE/255/63/512 | bc)
21 { 40 {
22 echo ,9,0x0C,* 41 echo ,9,0x0C,*
23 echo ,,,- 42 echo ,,,-
24 } | sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV} 43 } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV}
25 44
26 # Prepare loop devices for boot and filesystem partitions 45 # Prepare loop devices for boot and filesystem partitions
27 BOOT_OFFSET=32256 46 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) 47 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) 48 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" \ 49 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) 50 |cut -d " " -f 4 | cut -d "+" -f 1)
32 51
33 LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u $LOOPDEV 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5) 52 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) 53 LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc)
35 54
36 losetup -f ${SDIMG} -o ${BOOT_OFFSET} --sizelimit=$LOOPDEV_BYTES 55 ${LOSETUP} -d ${LOOPDEV}
37 56
38 LOOPDEV_BOOT=$(losetup -j ${SDIMG} -o ${BOOT_OFFSET} | cut -d ":" -f 1) 57 ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET}
39 mkfs.msdos ${LOOPDEV_BOOT} -n boot
40 58
41 losetup -f ${SDIMG} -o ${FS_OFFSET} 59 /sbin/mkfs.msdos ${LOOPDEV_BOOT} -n boot $LOOPDEV_BLOCKS
42 LOOPDEV_FS=$(losetup -j ${SDIMG} -o ${FS_OFFSET} | cut -d ":" -f 1)
43 60
44 # Prepare filesystem partition 61 # Prepare filesystem partition
45 # Copy ubi used by flashing scripts 62 # Copy ubi used by flashing scripts
@@ -47,32 +64,59 @@ IMAGE_CMD_sdimg () {
47 echo "Copying UBIFS image to file system" 64 echo "Copying UBIFS image to file system"
48 cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi 65 cp ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ubi ${IMAGE_ROOTFS}/boot/fs.ubi
49 fi 66 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 67
54 # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files 68 # Prepare boot partion. First mount the boot partition, and copy the boot loader and supporting files
55 # from the root filesystem 69 # from the root filesystem
56 70
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 71 mkdir -p ${WORKDIR}/tmp-mnt-boot
65 mount $LOOPDEV_BOOT 72 mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot
66 73
67 echo "Copying bootloaders into the boot partition" 74 echo "Copying bootloaders into the boot partition"
68 cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot 75 if [ -e ${IMAGE_ROOTFS}/boot/MLO ] ; then
69 cp -v ${IMAGE_ROOTFS}/boot/{u-boot.bin,user.txt,uEnv.txt} ${WORKDIR}/tmp-mnt-boot || true 76 cp -v ${IMAGE_ROOTFS}/boot/MLO ${WORKDIR}/tmp-mnt-boot
77 else
78 cp -v ${DEPLOY_DIR_IMAGE}/MLO ${WORKDIR}/tmp-mnt-boot
79 fi
80
81 # Check for u-boot SPL
82 if [ -e ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.img ] ; then
83 suffix=img
84 else
85 suffix=bin
86 fi
87
88 if [ -e ${IMAGE_ROOTFS}/boot/u-boot.$suffix ] ; then
89 cp -v ${IMAGE_ROOTFS}/boot/{u-boot.$suffix,user.txt,uEnv.txt} ${WORKDIR}/tmp-mnt-boot || true
90 else
91 cp -v ${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.$suffix ${WORKDIR}/tmp-mnt-boot/u-boot.$suffix
92 fi
93
94 # Deprecated, u-boot should load it from ext3 instead
95 if [ -e ${IMAGE_ROOTFS}/boot/uImage ] ; then
96 cp -v ${IMAGE_ROOTFS}/boot/uImage ${WORKDIR}/tmp-mnt-boot
97 else
98 cp -v ${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.bin ${WORKDIR}/tmp-mnt-boot/uImage
99 fi
100
101 # Cleanup VFAT mount
102 echo "Cleaning up VFAT mount"
103 umount ${WORKDIR}/tmp-mnt-boot
104 ${LOSETUP} -d ${LOOPDEV_BOOT} || true
105
106 # Prepare ext3 parition
107 echo "Creating ext3 loopback"
108 ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET}
109
110 # should use fdisk info
111 echo "Creating ext3 image"
112 touch ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
113 genext2fs -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
114 tune2fs -L ${IMAGE_NAME} -j ${WORKDIR}/${IMAGE_NAME}.rootfs.ext3
115
116 dd if=${WORKDIR}/${IMAGE_NAME}.rootfs.ext3 of=${LOOPDEV_FS}
70 117
71 # cleanup 118 ${LOSETUP} -d ${LOOPDEV_FS} || true
72 umount ${LOOPDEV_BOOT}
73 /sbin/losetup -d ${LOOPDEV}
74 /sbin/losetup -d ${LOOPDEV_BOOT}
75 /sbin/losetup -d ${LOOPDEV_FS}
76 119
77 gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${PR}.img.gz 120 gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${PR}.img.gz
121 rm -f ${WORKDIR}/sd.img
78} 122}