diff options
| -rw-r--r-- | classes/sdcard_image-rpi-xen.bbclass | 120 | ||||
| -rw-r--r-- | conf/distro/include/meta-virt-xen.inc | 3 |
2 files changed, 123 insertions, 0 deletions
diff --git a/classes/sdcard_image-rpi-xen.bbclass b/classes/sdcard_image-rpi-xen.bbclass new file mode 100644 index 00000000..c03520c2 --- /dev/null +++ b/classes/sdcard_image-rpi-xen.bbclass | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | inherit sdcard_image-rpi | ||
| 2 | |||
| 3 | # This image class should be retired and folded into sdcard_image-rpi.bbclass | ||
| 4 | # when it has support for adding binaries to the boot partition that are not | ||
| 5 | # present in the root partition filesystem: ie. the hypervisor (xen) image. | ||
| 6 | |||
| 7 | do_image_rpi_xen_sdimg[depends] = " \ | ||
| 8 | parted-native:do_populate_sysroot \ | ||
| 9 | mtools-native:do_populate_sysroot \ | ||
| 10 | dosfstools-native:do_populate_sysroot \ | ||
| 11 | virtual/kernel:do_deploy \ | ||
| 12 | ${IMAGE_BOOTLOADER}:do_deploy \ | ||
| 13 | rpi-config:do_deploy \ | ||
| 14 | ${@bb.utils.contains('MACHINE_FEATURES', 'armstub', 'armstubs:do_deploy', '' ,d)} \ | ||
| 15 | ${@bb.utils.contains('RPI_USE_U_BOOT', '1', 'u-boot:do_deploy', '',d)} \ | ||
| 16 | ${@bb.utils.contains('RPI_USE_U_BOOT', '1', 'u-boot-default-script:do_deploy', '',d)} \ | ||
| 17 | xen:do_deploy \ | ||
| 18 | " | ||
| 19 | |||
| 20 | do_image_rpi_xen_sdimg[recrdeps] = "do_build" | ||
| 21 | |||
| 22 | IMAGE_TYPEDEP_rpi-xen-sdimg = "${SDIMG_ROOTFS_TYPE}" | ||
| 23 | |||
| 24 | SDIMG = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.rpi-xen-sdimg" | ||
| 25 | |||
| 26 | # Take from: IMAGE_CMD_rpi-sdimg from meta-raspberrypi, current as of: 44d7dd0e | ||
| 27 | # with modification to include the Xen hypervisor binary in the boot partition. | ||
| 28 | IMAGE_CMD_rpi-xen-sdimg () { | ||
| 29 | |||
| 30 | # Align partitions | ||
| 31 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
| 32 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
| 33 | SDIMG_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE) | ||
| 34 | |||
| 35 | echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS $ROOTFS_SIZE KiB" | ||
| 36 | |||
| 37 | # Check if we are building with device tree support | ||
| 38 | DTS="${KERNEL_DEVICETREE}" | ||
| 39 | |||
| 40 | # Initialize sdcard image file | ||
| 41 | dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE} | ||
| 42 | |||
| 43 | # Create partition table | ||
| 44 | parted -s ${SDIMG} mklabel msdos | ||
| 45 | # Create boot partition and mark it as bootable | ||
| 46 | parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) | ||
| 47 | parted -s ${SDIMG} set 1 boot on | ||
| 48 | # Create rootfs partition to the end of disk | ||
| 49 | parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s | ||
| 50 | parted ${SDIMG} print | ||
| 51 | |||
| 52 | # Create a vfat image with boot files | ||
| 53 | BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }') | ||
| 54 | rm -f ${WORKDIR}/boot.img | ||
| 55 | mkfs.vfat -F32 -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS | ||
| 56 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/* ::/ || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/* into boot.img" | ||
| 57 | if [ "${@bb.utils.contains("MACHINE_FEATURES", "armstub", "1", "0", d)}" = "1" ]; then | ||
| 58 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/armstubs/${ARMSTUB} ::/ || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/armstubs/${ARMSTUB} into boot.img" | ||
| 59 | fi | ||
| 60 | if test -n "${DTS}"; then | ||
| 61 | # Copy board device trees to root folder | ||
| 62 | for dtbf in ${@split_overlays(d, True)}; do | ||
| 63 | dtb=`basename $dtbf` | ||
| 64 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/$dtb ::$dtb || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/$dtb into boot.img" | ||
| 65 | done | ||
| 66 | |||
| 67 | # Copy device tree overlays to dedicated folder | ||
| 68 | mmd -i ${WORKDIR}/boot.img overlays | ||
| 69 | for dtbf in ${@split_overlays(d, False)}; do | ||
| 70 | dtb=`basename $dtbf` | ||
| 71 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/$dtb ::overlays/$dtb || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/$dtb into boot.img" | ||
| 72 | done | ||
| 73 | fi | ||
| 74 | if [ "${RPI_USE_U_BOOT}" = "1" ]; then | ||
| 75 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/u-boot.bin ::${SDIMG_KERNELIMAGE} || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/u-boot.bin into boot.img" | ||
| 76 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/boot.scr ::boot.scr || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/boot.scr into boot.img" | ||
| 77 | if [ ! -z "${INITRAMFS_IMAGE}" -a "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then | ||
| 78 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${INITRAMFS_LINK_NAME}.bin ::${KERNEL_IMAGETYPE} || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${INITRAMFS_LINK_NAME}.bin into boot.img" | ||
| 79 | else | ||
| 80 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ::${KERNEL_IMAGETYPE} || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} into boot.img" | ||
| 81 | fi | ||
| 82 | else | ||
| 83 | if [ ! -z "${INITRAMFS_IMAGE}" -a "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then | ||
| 84 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${INITRAMFS_LINK_NAME}.bin ::${SDIMG_KERNELIMAGE} || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${INITRAMFS_LINK_NAME}.bin into boot.img" | ||
| 85 | else | ||
| 86 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ::${SDIMG_KERNELIMAGE} || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} into boot.img" | ||
| 87 | fi | ||
| 88 | fi | ||
| 89 | # -- Begin Xen deploy modification | ||
| 90 | mcopy -v -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/xen-${MACHINE} ::xen || bbfatal "mcopy cannot copy ${DEPLOY_DIR_IMAGE}/xen-${MACHINE} into boot.img" | ||
| 91 | # -- End Xen deploy modification | ||
| 92 | |||
| 93 | if [ -n "${FATPAYLOAD}" ] ; then | ||
| 94 | echo "Copying payload into VFAT" | ||
| 95 | for entry in ${FATPAYLOAD} ; do | ||
| 96 | # use bbwarn instead of bbfatal to stop aborting on vfat issues like not supporting .~lock files | ||
| 97 | mcopy -v -i ${WORKDIR}/boot.img -s ${IMAGE_ROOTFS}$entry :: || bbwarn "mcopy cannot copy ${IMAGE_ROOTFS}$entry into boot.img" | ||
| 98 | done | ||
| 99 | fi | ||
| 100 | |||
| 101 | # Add stamp file | ||
| 102 | echo "${IMAGE_NAME}" > ${WORKDIR}/image-version-info | ||
| 103 | mcopy -v -i ${WORKDIR}/boot.img ${WORKDIR}/image-version-info :: || bbfatal "mcopy cannot copy ${WORKDIR}/image-version-info into boot.img" | ||
| 104 | |||
| 105 | # Deploy vfat partition | ||
| 106 | if [ "${SDIMG_VFAT_DEPLOY}" = "1" ]; then | ||
| 107 | cp ${WORKDIR}/boot.img ${IMGDEPLOYDIR}/${SDIMG_VFAT} | ||
| 108 | ln -sf ${SDIMG_VFAT} ${SDIMG_LINK_VFAT} | ||
| 109 | fi | ||
| 110 | |||
| 111 | # Burn Partitions | ||
| 112 | dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) | ||
| 113 | # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat | ||
| 114 | if echo "${SDIMG_ROOTFS_TYPE}" | egrep -q "*\.xz" | ||
| 115 | then | ||
| 116 | xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) | ||
| 117 | else | ||
| 118 | dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) | ||
| 119 | fi | ||
| 120 | } | ||
diff --git a/conf/distro/include/meta-virt-xen.inc b/conf/distro/include/meta-virt-xen.inc index 2ada83a3..b4a20fe5 100644 --- a/conf/distro/include/meta-virt-xen.inc +++ b/conf/distro/include/meta-virt-xen.inc | |||
| @@ -12,3 +12,6 @@ SERIAL_CONSOLES = "115200;hvc0" | |||
| 12 | # - Xen uses u-boot for configuration and uses the uart | 12 | # - Xen uses u-boot for configuration and uses the uart |
| 13 | RPI_USE_U_BOOT = "1" | 13 | RPI_USE_U_BOOT = "1" |
| 14 | ENABLE_UART = "1" | 14 | ENABLE_UART = "1" |
| 15 | # Build the bootable SD card image | ||
| 16 | IMAGE_CLASSES_append_raspberrypi4-64 = " sdcard_image-rpi-xen" | ||
| 17 | IMAGE_FSTYPES_append_raspberrypi4-64 = " rpi-xen-sdimg" | ||
