summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--classes/sdcard_image-rpi.bbclass192
-rwxr-xr-xconf/machine/raspberrypi.conf9
2 files changed, 87 insertions, 114 deletions
diff --git a/classes/sdcard_image-rpi.bbclass b/classes/sdcard_image-rpi.bbclass
index 1ac3e84..af18aab 100644
--- a/classes/sdcard_image-rpi.bbclass
+++ b/classes/sdcard_image-rpi.bbclass
@@ -1,131 +1,97 @@
1inherit image 1#
2 2# Create an image that can by written onto a SD card using dd.
3# Add the fstypes we need 3#
4IMAGE_FSTYPES_append = " tar.bz2 rpi-sdimg" 4# The disk layout used is:
5 5#
6# Ensure required utilities are present 6# 0 - 1M - reserved for other data
7IMAGE_DEPENDS_rpi-sdimg = "genext2fs-native e2fsprogs-native bcm2835-bootfiles bcm2835-kernel-image" 7# 1M - BOOT_SPACE - bootloader and kernel
8 8# BOOT_SPACE - SDIMG_SIZE - rootfs
9# Register this as an avalable type of image. 9#
10IMAGE_TYPES_append = " rpi-sdimg" 10
11 11# Set kernel and boot loader
12# Change this to match your host distro 12IMAGE_BOOTLOADER ?= "bcm2835-bootfiles"
13LOSETUP ?= "/sbin/losetup" 13
14 14# Default to 1.4GiB images
15# Since these need to go in /etc/fstab we can hardcode them 15SDIMG_SIZE ?= "4000"
16# Since the vars are weakly assigned, you can override them from your local.conf 16
17LOOPDEV ?= "/dev/loop1" 17# Boot partition volume id
18LOOPDEV_BOOT ?= "/dev/loop2" 18BOOTDD_VOLUME_ID ?= "${MACHINE}"
19LOOPDEV_FS ?= "/dev/loop3" 19
20 20# Addional space for boot partition
21# Default to 4GiB images 21BOOT_SPACE ?= "20MiB"
22SDIMG_SIZE ?= "444" 22
23 23# Use an ext3 by default as rootfs
24# FS type for rootfs 24SDIMG_ROOTFS_TYPE ?= "ext3"
25ROOTFSTYPE ?= "ext4" 25SDIMG_ROOTFS = "${IMAGE_NAME}.rootfs.${SDIMG_ROOTFS_TYPE}"
26 26
27BOOTPARTNAME ?= "${MACHINE}" 27# Set GPU firmware image to be used
28 28# arm128 : 128M ARM, 128M GPU split
29IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" 29# arm192 : 192M ARM, 64M GPU split
30# arm224 : 224M ARM, 32M GPU split
31RPI_GPU_FIRMWARE ?= "arm192"
32
33IMAGE_DEPENDS_rpi-sdimg = " \
34 parted-native \
35 mtools-native \
36 dosfstools-native \
37 virtual/kernel \
38 ${IMAGE_BOOTLOADER} \
39 "
40
41# SD card image name
42SDIMG = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.rpi-sdimg"
30 43
31# Additional files and/or directories to be copied into the vfat partition from the IMAGE_ROOTFS. 44# Additional files and/or directories to be copied into the vfat partition from the IMAGE_ROOTFS.
32FATPAYLOAD ?= "" 45FATPAYLOAD ?= ""
33 46
34IMAGE_CMD_rpi-sdimg () { 47IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}"
35 SDIMG=${WORKDIR}/sd.img
36
37 # sanity check fstab entry for boot partition mounting
38 if [ "x$(cat /etc/fstab | grep ${LOOPDEV_BOOT} | grep ${WORKDIR}/tmp-mnt-boot | grep user || true)" = "x" ]; then
39 echo "/etc/fstab entries need to be created with the user flag for the loop devices like:"
40 echo "${LOOPDEV_BOOT} ${WORKDIR}/tmp-mnt-boot vfat user 0 0"
41 false
42 fi
43
44 # cleanup loops
45 for loop in ${LOOPDEV} ${LOOPDEV_BOOT} ${LOOPDEV_FS} ; do
46 ${LOSETUP} -d $loop || true
47 done
48
49 # If an SD image is already present, reuse and reformat it
50 if [ ! -e ${SDIMG} ] ; then
51 dd if=/dev/zero of=${SDIMG} bs=$(echo '255 * 63 * 512' | bc) count=${SDIMG_SIZE}
52 fi
53 48
54 ${LOSETUP} ${LOOPDEV} ${SDIMG} 49IMAGE_CMD_rpi-sdimg () {
50 # Initialize sdcard image file
51 dd if=/dev/zero of=${SDIMG} bs=1 count=0 seek=$(expr 1000 \* 1000 \* ${SDIMG_SIZE})
55 52
56 # Create partition table 53 # Create partition table
57 dd if=/dev/zero of=${LOOPDEV} bs=1024 count=1024 54 parted -s ${SDIMG} mklabel msdos
58 SIZE=$(/sbin/fdisk -l ${LOOPDEV} | grep Disk | grep bytes | awk '{print $5}') 55 # Create boot partition and mark it as bootable
59 CYLINDERS=$(echo $SIZE/255/63/512 | bc) 56 parted -s ${SDIMG} mkpart primary fat32 1MiB ${BOOT_SPACE}
60 { 57 parted -s ${SDIMG} set 1 boot on
61 echo ,9,0x0C,* 58 # Create rootfs partition
62 echo ,,,- 59 parted -s ${SDIMG} mkpart primary ext2 ${BOOT_SPACE} 100%
63 } | /sbin/sfdisk -D -H 255 -S 63 -C ${CYLINDERS} ${LOOPDEV} 60 parted ${SDIMG} print
64 61
65 # Prepare loop devices for boot and filesystem partitions 62 # Create a vfat image with boot files
66 BOOT_OFFSET=32256 63 BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }')
67 FS_OFFSET_SECT=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /"|cut -d " " -f 2) 64 mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS
68 FS_OFFSET=$(echo "$FS_OFFSET_SECT * 512" | bc) 65 case "${RPI_GPU_FIRMWARE}" in
69 FS_SIZE_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep Linux | perl -p -i -e "s/\s+/ /g" \ 66 "arm128" | "arm192" | "arm224")
70 |cut -d " " -f 4 | cut -d "+" -f 1) 67 mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/${RPI_GPU_FIRMWARE}_start.elf ::start.elf
71 68 ;;
72 LOOPDEV_BLOCKS=$(/sbin/fdisk -l -u ${LOOPDEV} 2>&1 | grep FAT | perl -p -i -e "s/\s+/ /g"|cut -d " " -f 5) 69 *)
73 LOOPDEV_BYTES=$(echo "$LOOPDEV_BLOCKS * 1024" | bc) 70 bberror "RPI_GPU_FIRMWARE is undefined or value not recongnised. Possible values: arm128, arm192 or arm224."
74 71 exit 1
75 ${LOSETUP} -d ${LOOPDEV} 72 ;;
76 73 esac
77 ${LOSETUP} ${LOOPDEV_BOOT} ${SDIMG} -o ${BOOT_OFFSET}
78
79 /sbin/mkfs.vfat ${LOOPDEV_BOOT} -n ${BOOTPARTNAME} $LOOPDEV_BLOCKS
80
81 # Prepare boot partion. First mount the boot partition, and copy the bootloader and supporting files.
82
83 mkdir -p ${WORKDIR}/tmp-mnt-boot
84 mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot
85 74
86 echo "Copying bootloader and prepended kernel.img into the boot partition" 75 # To do
87 cp -v ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/* ${WORKDIR}/tmp-mnt-boot || true 76 # Copy here a cmdline.txt file generated taking into consideration the partition type
77 # of the rootfs
78 mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/bootcode.bin ::
79 mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/loader.bin ::
80 mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/kernel.img ::
88 81
89 if [ -n ${FATPAYLOAD} ] ; then 82 if [ -n ${FATPAYLOAD} ] ; then
90 echo "Copying payload into VFAT" 83 echo "Copying payload into VFAT"
91 for entry in ${FATPAYLOAD} ; do 84 for entry in ${FATPAYLOAD} ; do
92 # add the || true to stop aborting on vfat issues like not supporting .~lock files 85 # add the || true to stop aborting on vfat issues like not supporting .~lock files
93 cp -av ${IMAGE_ROOTFS}$entry ${WORKDIR}/tmp-mnt-boot || true 86 mcopy -i ${WORKDIR}/boot.img -s -v ${IMAGE_ROOTFS}$entry :: || true
94 done 87 done
95 fi 88 fi
96 89
97 echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${IMAGE_ROOTFS}/etc/image-version-info 90 # Add stamp file
98 91 echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${WORKDIR}/image-version-info
99 cp -v ${IMAGE_ROOTFS}/etc/image-version-info ${WORKDIR}/tmp-mnt-boot || true 92 mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}//image-version-info ::
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 rootfs parition
107 echo "Creating rootfs loopback"
108 ${LOSETUP} ${LOOPDEV_FS} ${SDIMG} -o ${FS_OFFSET}
109
110 FS_NUM_INODES=$(echo $FS_SIZE_BLOCKS / 4 | bc)
111
112 case "${ROOTFSTYPE}" in
113 ext3)
114 genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS}
115 tune2fs -L ${IMAGE_NAME} -j ${LOOPDEV_FS}
116 ;;
117 ext4)
118 genext2fs -z -N $FS_NUM_INODES -b $FS_SIZE_BLOCKS -d ${IMAGE_ROOTFS} ${LOOPDEV_FS}
119 tune2fs -L ${IMAGE_NAME} -j -O extents,uninit_bg,dir_index ${LOOPDEV_FS}
120 ;;
121 *)
122 echo "Please set ROOTFSTYPE to something supported"
123 exit 1
124 ;;
125 esac
126
127 ${LOSETUP} -d ${LOOPDEV_FS} || true
128 93
129 gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz 94 # Burn Partitions
130 rm -f ${WORKDIR}/sd.img 95 dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=1M && sync && sync
96 dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=${BOOT_SPACE} && sync && sync
131} 97}
diff --git a/conf/machine/raspberrypi.conf b/conf/machine/raspberrypi.conf
index 86fd1b8..a64104b 100755
--- a/conf/machine/raspberrypi.conf
+++ b/conf/machine/raspberrypi.conf
@@ -9,7 +9,8 @@ require conf/machine/include/tune-arm1176jzf-s.inc
9 9
10GUI_MACHINE_CLASS = "bigscreen" 10GUI_MACHINE_CLASS = "bigscreen"
11 11
12IMAGE_FSTYPES += "tar.bz2 rpi-sdimg" 12INHERIT += "sdcard_image-rpi"
13IMAGE_FSTYPES += "tar.bz2 ext3 rpi-sdimg"
13 14
14SERIAL_CONSOLE = "115200 ttyAMA0" 15SERIAL_CONSOLE = "115200 ttyAMA0"
15 16
@@ -34,3 +35,9 @@ MACHINE_EXTRA_RRECOMMENDS += " \
34 kernel-modules \ 35 kernel-modules \
35 bcm2835-kernel-image \ 36 bcm2835-kernel-image \
36" 37"
38
39# Set GPU firmware image to be used
40# arm128 : 128M ARM, 128M GPU split
41# arm192 : 192M ARM, 64M GPU split
42# arm224 : 224M ARM, 32M GPU split
43RPI_GPU_FIRMWARE ?= "arm192"