To use, from your machine conf or local.conf: * Inherit this class * define IMAGE_FSTYPES = "sdcard" (or sdcard.gz) * fix the u-boot uEnv in order to specify the roots on the /dev/mmcblk0p2
Signed-off-by: Jean-Francois Dagenais <[email protected]> --- README.booting.md | 4 ++ classes/image_types_zynq.bbclass | 105 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 classes/image_types_zynq.bbclass diff --git a/README.booting.md b/README.booting.md index a22ddb7..92c3674 100644 --- a/README.booting.md +++ b/README.booting.md @@ -133,6 +133,10 @@ Loading via SD **(Note: This section only applies to Zynq.)** ### Preparing SD/MMC + +Check out classes/image_types_zynq.bbclass to automatically generate an sdcard +image. (It is untested on zynqmp at this moment.) Otherwise, proceed manually: + Setup the card with the first partition formatted as FAT16. If you intend to boot with the root filesystem located on the SD card, also create a second partition formatted as EXT4. diff --git a/classes/image_types_zynq.bbclass b/classes/image_types_zynq.bbclass new file mode 100644 index 0000000..3ebc24b --- /dev/null +++ b/classes/image_types_zynq.bbclass @@ -0,0 +1,105 @@ +# !!! UNLESS EXPLICITELY MENTIONNED, NUMBERS ARE IN BYTES +# Mind alignments! + +inherit image_types + +IMAGE_BOOTLOADER ?= "u-boot-xlnx" + +# Boot partition volume id +BOOTDD_VOLUME_ID = "ZBOOT" + +# Last byte of the boot partition (30M mark in bytes, MB aligned -1 byte) +BOOT_PART_END = "31457279" + +# Skip the fist 4MB on the card +BOOT_PART_BEGIN = "4194304" + +do_image_sdcard[depends] += "\ + parted-native:do_populate_sysroot \ + dosfstools-native:do_populate_sysroot \ + mtools-native:do_populate_sysroot \ + virtual/kernel:do_deploy \ + ${@d.getVar('IMAGE_BOOTLOADER', True) and d.getVar('IMAGE_BOOTLOADER', True) + ':do_deploy' or ''} \ + ${@d.getVar('INITRD_IMAGE', True) and d.getVar('INITRD_IMAGE', True) + ':do_image_complete' or ''} \ +" + +# The sdcard image file is no longer a ".rootfs", so override this suffix. +# this line fixes symlinks source files: +do_image_sdcard[imgsuffix] = "." +# this line fixes the gz(or others) auto compression stuff +IMAGE_NAME_SUFFIX_sdcard = "" + +# The sdcard requires the ext4 rootfs filesystem to be built before +# using it so we must make this dependency explicit. +IMAGE_TYPEDEP_sdcard += "ext4" + +create_partition_table() { + parted -s ${sdcardFile} mklabel msdos + parted -s --align none ${sdcardFile} mkpart primary fat32 ${BOOT_PART_BEGIN}B ${BOOT_PART_END}B + + local rootfsOffset=$(expr ${BOOT_PART_END} + 1) + parted -s --align none ${sdcardFile} mkpart primary ext2 ${rootfsOffset}B 100% +} + +generate_temp_boot_image() { + # Create boot partition image + bootPartSize=$(expr ${BOOT_PART_END} - ${BOOT_PART_BEGIN} + 1) + + truncate -s $bootPartSize $tempBootImage + echo "bootPartSize: $bootPartSize" + export MTOOLS_SKIP_CHECK=1 + + mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 ${FATSIZE} $tempBootImage + + # conditionnaly copy initrd image + if [ -n "${INITRD_IMAGE}" ]; then + mcopy -i $tempBootImage -s ${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}.cpio.gz.u-boot ::/image-initramfs-${MACHINE}.cpio.gz.u-boot + fi + + # Copy boot files + for fileToWrite in ${IMAGE_BOOT_FILES}; do + if [ ! -e "${DEPLOY_DIR_IMAGE}/${fileToWrite}" ]; then + bbfatal "${DEPLOY_DIR_IMAGE}/${fileToWrite} does not exist." + exit 1 + fi + + mcopy -i $tempBootImage -s ${DEPLOY_DIR_IMAGE}/${fileToWrite} ::/${fileToWrite} + done +} + +write_images_to_partitions() { + # dd in chunks of 1MB + blockSize=1048576 + + bootPartOffset=$(expr ${BOOT_PART_BEGIN} / $blockSize) + + cat $tempBootImage $rootfsImage | dd of=${sdcardFile} conv=notrunc,fsync seek=$bootPartOffset bs=$blockSize +} + +IMAGE_CMD_sdcard () { + # this fabricated rootfs.ext4 name depends on the definition we set in our layer.conf + # see IMAGE_LINK_NAME in there. We can use it since here *_sdcard overrides are in + # effect, so the ".rootfs" part is missing for .sdcard + rootfsImage="${IMGDEPLOYDIR}/${IMAGE_BASENAME}.ext4" + rootfsImage=$(readlink -f ${rootfsImage}) + + if [ ! -e "${rootfsImage}" ]; then + bberror "${rootfsImage} doesn't exist, cannot proceed." + exit 1 + fi + + local rootfsSize=$(du -b --apparent-size $rootfsImage | xargs |cut -d' ' -f1) + sdcardFile="${IMGDEPLOYDIR}/${IMAGE_NAME}.sdcard" + + # Initialize a sparse file + # +1 because the BOOT_PART_END is the last byte occupied, not the size. + local sdCardFileSize=$(expr ${BOOT_PART_END} + 1 + $rootfsSize) + truncate -s $sdCardFileSize ${sdcardFile} + + create_partition_table + + tempBootImage="${WORKDIR}/boot.img" + generate_temp_boot_image + + write_images_to_partitions +} -- 2.1.4 -- _______________________________________________ meta-xilinx mailing list [email protected] https://lists.yoctoproject.org/listinfo/meta-xilinx
