From 2567ba074cdeee3a9bc4c400cddcc34690b133cf Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Fri, 18 May 2012 22:51:02 +0300 Subject: sdcard_image-rpi.bbclass: Rewrite sdimage creation class - implemented with parted This implementation doesn't use loop mounts, it uses mcopy to copy files to partitions. The partition creation is done with parted. Because of using these tools the IMAGE_DEPENDS was modified accordingly. Added a way of selecting the desired GPU firmware. Because we don't create the rootfs image but we rely on an already created rootfs image, the stamp is available only in the boot partition. By default the class needs an ext3 rootfs image. This is because we don't have yet a way of generating cmdline.txt in order to pass the partition type to the kernel. By default ext3 is mounted so we use this fs type until this will be selectable while generating a cmdline file. Signed-off-by: Andrei Gherzan --- classes/sdcard_image-rpi.bbclass | 194 ++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 113 deletions(-) diff --git a/classes/sdcard_image-rpi.bbclass b/classes/sdcard_image-rpi.bbclass index 1ac3e84..ef27ac6 100644 --- a/classes/sdcard_image-rpi.bbclass +++ b/classes/sdcard_image-rpi.bbclass @@ -1,131 +1,99 @@ -inherit image - -# Add the fstypes we need -IMAGE_FSTYPES_append = " tar.bz2 rpi-sdimg" - -# Ensure required utilities are present -IMAGE_DEPENDS_rpi-sdimg = "genext2fs-native e2fsprogs-native bcm2835-bootfiles bcm2835-kernel-image" - -# Register this as an avalable type of image. -IMAGE_TYPES_append = " rpi-sdimg" - -# 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" - -# Default to 4GiB images -SDIMG_SIZE ?= "444" - -# FS type for rootfs -ROOTFSTYPE ?= "ext4" - -BOOTPARTNAME ?= "${MACHINE}" - -IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" +# +# Create an image that can by written onto a SD card using dd. +# +# The disk layout used is: +# +# 0 - 1M - reserved for other data +# 1M - BOOT_SPACE - bootloader and kernel +# BOOT_SPACE - SDIMG_SIZE - rootfs +# + +inherit image_types + +# Set kernel and boot loader +IMAGE_BOOTLOADER ?= "bcm2835-bootfiles" + +# Default to 1.4GiB images +SDIMG_SIZE ?= "4000" + +# Boot partition volume id +BOOTDD_VOLUME_ID ?= "${MACHINE}" + +# Addional space for boot partition +BOOT_SPACE ?= "20MiB" + +# Use an ext3 by default as rootfs +SDIMG_ROOTFS_TYPE ?= "ext3" +SDIMG_ROOTFS = "${IMAGE_NAME}.rootfs.${SDIMG_ROOTFS_TYPE}" + +# Set GPU firmware image to be used +# arm128 : 128M ARM, 128M GPU split +# arm192 : 192M ARM, 64M GPU split +# arm224 : 224M ARM, 32M GPU split +RPI_GPU_FIRMWARE ?= "arm192" + +IMAGE_DEPENDS_rpi-sdimg = " \ + parted-native \ + mtools-native \ + dosfstools-native \ + virtual/kernel \ + ${IMAGE_BOOTLOADER} \ + " + +# SD card image name +SDIMG = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.rpi-sdimg" # Additional files and/or directories to be copied into the vfat partition from the IMAGE_ROOTFS. FATPAYLOAD ?= "" -IMAGE_CMD_rpi-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 +IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" - ${LOSETUP} ${LOOPDEV} ${SDIMG} +IMAGE_CMD_rpi-sdimg () { + # Initialize sdcard image file + dd if=/dev/zero of=${SDIMG} bs=1 count=0 seek=$(expr 1000 \* 1000 \* ${SDIMG_SIZE}) # 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 boot partion. First mount the boot partition, and copy the bootloader and supporting files. - - mkdir -p ${WORKDIR}/tmp-mnt-boot - mount $LOOPDEV_BOOT ${WORKDIR}/tmp-mnt-boot + parted -s ${SDIMG} mklabel msdos + # Create boot partition and mark it as bootable + parted -s ${SDIMG} mkpart primary fat32 1MiB ${BOOT_SPACE} + parted -s ${SDIMG} set 1 boot on + # Create rootfs partition + parted -s ${SDIMG} mkpart primary ext2 ${BOOT_SPACE} 100% + parted ${SDIMG} print + + # Create a vfat image with boot files + BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }') + mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS + case "${RPI_GPU_FIRMWARE}" in + "arm128" | "arm192" | "arm224") + mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/${RPI_GPU_FIRMWARE}_start.elf ::start.elf + ;; + *) + bberror "RPI_GPU_FIRMWARE is undefined or value not recongnised. Possible values: arm128, arm192 or arm224." + exit 1 + ;; + esac - echo "Copying bootloader and prepended kernel.img into the boot partition" - cp -v ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/* ${WORKDIR}/tmp-mnt-boot || true + # To do + # Copy here a cmdline.txt file generated taking into consideration the partition type + # of the rootfs + mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/bootcode.bin :: + mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/loader.bin :: + mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/kernel.img :: 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 + mcopy -i ${WORKDIR}/boot.img -s -v ${IMAGE_ROOTFS}$entry :: || true done fi - echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${IMAGE_ROOTFS}/etc/image-version-info - - cp -v ${IMAGE_ROOTFS}/etc/image-version-info ${WORKDIR}/tmp-mnt-boot || true - - # 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 + # Add stamp file + echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${WORKDIR}/image-version-info + mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}//image-version-info :: - gzip -c ${WORKDIR}/sd.img > ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}-${IMAGEDATESTAMP}.img.gz - rm -f ${WORKDIR}/sd.img + # Burn Partitions + dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=1M && sync && sync + dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=${BOOT_SPACE} && sync && sync } -- cgit v1.2.3-54-g00ecf From 53eecaf2e9317fe36119865add93503cb819b895 Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Fri, 18 May 2012 22:55:28 +0300 Subject: raspberrypi.conf: Add ext3 to FSTYPE as needed by sd creation tool Signed-off-by: Andrei Gherzan --- conf/machine/raspberrypi.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/machine/raspberrypi.conf b/conf/machine/raspberrypi.conf index 86fd1b8..e089f4f 100755 --- a/conf/machine/raspberrypi.conf +++ b/conf/machine/raspberrypi.conf @@ -9,7 +9,7 @@ require conf/machine/include/tune-arm1176jzf-s.inc GUI_MACHINE_CLASS = "bigscreen" -IMAGE_FSTYPES += "tar.bz2 rpi-sdimg" +IMAGE_FSTYPES += "tar.bz2 ext3 rpi-sdimg" SERIAL_CONSOLE = "115200 ttyAMA0" -- cgit v1.2.3-54-g00ecf From f0d4934ed84a6334944c92184878862de12172c8 Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Mon, 2 Jul 2012 01:01:02 +0300 Subject: raspberrypi.conf: Add variable to set GPU firmware image to be used Signed-off-by: Andrei Gherzan --- conf/machine/raspberrypi.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conf/machine/raspberrypi.conf b/conf/machine/raspberrypi.conf index e089f4f..4508a42 100755 --- a/conf/machine/raspberrypi.conf +++ b/conf/machine/raspberrypi.conf @@ -34,3 +34,9 @@ MACHINE_EXTRA_RRECOMMENDS += " \ kernel-modules \ bcm2835-kernel-image \ " + +# Set GPU firmware image to be used +# arm128 : 128M ARM, 128M GPU split +# arm192 : 192M ARM, 64M GPU split +# arm224 : 224M ARM, 32M GPU split +RPI_GPU_FIRMWARE ?= "arm192" -- cgit v1.2.3-54-g00ecf From a95712d8e7728c5cb5ba750f5d904af110ab0d0c Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Mon, 2 Jul 2012 01:20:36 +0300 Subject: sdcard_image-rpi.bbclass: Change to be usable with any image Instead of being inherited by a specific image recipe, this class can now be inherited globally in the machine configuration, allowing it to be used with any image. This means we can remove "inherit image", and we can also remove the IMAGE_FSTYPES modification since the machine config does this already. Signed-off-by: Paul Eggleton Signed-off-by: Andrei Gherzan --- classes/sdcard_image-rpi.bbclass | 2 -- conf/machine/raspberrypi.conf | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/sdcard_image-rpi.bbclass b/classes/sdcard_image-rpi.bbclass index ef27ac6..af18aab 100644 --- a/classes/sdcard_image-rpi.bbclass +++ b/classes/sdcard_image-rpi.bbclass @@ -8,8 +8,6 @@ # BOOT_SPACE - SDIMG_SIZE - rootfs # -inherit image_types - # Set kernel and boot loader IMAGE_BOOTLOADER ?= "bcm2835-bootfiles" diff --git a/conf/machine/raspberrypi.conf b/conf/machine/raspberrypi.conf index 4508a42..a64104b 100755 --- a/conf/machine/raspberrypi.conf +++ b/conf/machine/raspberrypi.conf @@ -9,6 +9,7 @@ require conf/machine/include/tune-arm1176jzf-s.inc GUI_MACHINE_CLASS = "bigscreen" +INHERIT += "sdcard_image-rpi" IMAGE_FSTYPES += "tar.bz2 ext3 rpi-sdimg" SERIAL_CONSOLE = "115200 ttyAMA0" -- cgit v1.2.3-54-g00ecf