desc: "Xen-Troops development setup for Renesas RCAR Gen4 hardware"
min_ver: "0.15"

variables:
  YOCTOS_WORK_DIR: "yocto"
  DOM0_BUILD_DIR: "build-dom0"
  DOMD_BUILD_DIR: "build-domd"
  DOMU_BUILD_DIR: "build-domu"
  XT_DOMD_DTB_NAME: "%{SOC_FAMILY}-%{MACHINE}-domd.dtb"
  XT_DOMU_DTB_NAME: "%{SOC_FAMILY}-%{MACHINE}-domu.dtb"
  XT_XEN_DTB_NAME: "%{SOC_FAMILY}-%{MACHINE}-xen.dtb"
  XT_GENERIC_DOMU_TAG: ""
  MACHINE: "s4sk"
  SOC_FAMILY: "r8a779f0"
  XT_DOMD_CONFIG_NAME: "domd-s4sk.cfg"
  XT_DOMU_CONFIG_NAME: "domu-s4sk.cfg"
  XT_KERNEL_BRANCH: "v5.10.41/rcar-5.1.7.rc11.2-xt"
  XT_KERNEL_REV: 555a13f8dd4ab57ada823a9b290f7c19fb29f1d0
common_data:
  # Sources used by all yocto-based domains
  sources: &COMMON_SOURCES
    - type: git
      url: "git://git.yoctoproject.org/poky"
      rev: 232b5533d
    - type: git
      url: "git://git.openembedded.org/meta-openembedded"
      rev: 814eec96c
    - type: git
      url: "git://git.yoctoproject.org/meta-virtualization"
      rev: 180241e
    - type: git
      url: "https://github.com/xen-troops/meta-xt-common.git"
      rev: a36260c04230d24a3819ae26e41f88de459776c9
    - type: git
      url: "https://github.com/renesas-rcar/meta-xt-prod-devel-rcar-gen4.git"
      rev: s4sk-1.2.1

  # Sources to be used in DomD and DomU
  domd_domu_sources: &DOMD_DOMU_SOURCES
    - type: git
      url: https://github.com/renesas-rcar/meta-renesas.git
      rev: 92ddfebae62b78a65ee430d49b710bb16b719bf2

  # Common configuration options for all yocto-based domains
  conf: &COMMON_CONF
    - [SSTATE_DIR, "${TOPDIR}/../../../common_data/sstate"]
    - [DL_DIR, "${TOPDIR}/../../../common_data/downloads"]

    # Skip warning about missing "virtualization" distro feature
    - [SKIP_META_VIRT_SANITY_CHECK, "1"]

    # Use hypervisor console on all guests
    - [SERIAL_CONSOLES, "115200;hvc0"]

    # Remove features that we are not using
    - [DISTRO_FEATURES:remove, "x11 gtk gobject-introspection-data wifi nfc
            bluetooth irda zeroconf 3g sysvinit acl alsa argp pcmcia usbgadget
            usbhost opengl ptest multiarch wayland vulkan sysvinit"]
  # Conf options for domain that are built used renesas layer
  domd_domu_conf: &DOMD_DOMU_CONF
    - [MACHINE, "%{MACHINE}"]
    - [SOC_FAMILY, "%{SOC_FAMILY}"]

    # Add systemd configuration
    - [DISTRO_FEATURES:append, " systemd"]
    - [VIRTUAL-RUNTIME_init_manager, "systemd"]

    # add the static lib to SDK toolchain
    - [SDKIMAGE_FEATURES:append, " staticdev-pkgs"]

    # Add for gstreamer plugins ugly
    - [LICENSE_FLAGS_WHITELIST, "commercial"]

    # Add Capacity Aware migration Strategy (CAS)
    - [MACHINE_FEATURES:append, " cas"]

    # Remove ptest to reduce the build time
    - [DISTRO_FEATURES:remove, "ptest"]

    # Generate ext4 image files
    - [IMAGE_FSTYPES:append, " ext4"]
    - [IMAGE_INSTALL:append, " perf"]

components:
  dom0:
    build-dir: "%{YOCTOS_WORK_DIR}"
    default: true
    sources:
      - *COMMON_SOURCES
    builder:
      type: yocto
      work_dir: "%{DOM0_BUILD_DIR}"
      conf:
        - *COMMON_CONF
        - [MACHINE, "generic-armv8-xt"]
        - [XT_DOM_NAME, "dom0"]
        - [XT_DOMD_CONFIG_NAME, "%{XT_DOMD_CONFIG_NAME}"]
        - [XT_DOMU_CONFIG_NAME, "%{XT_DOMU_CONFIG_NAME}"]
        - [XT_DOMD_DTB_NAME, "%{XT_DOMD_DTB_NAME}"]
        - [XT_DOMU_DTB_NAME, "%{XT_DOMU_DTB_NAME}"]
        - [XT_GUEST_INSTALL, "%{XT_GENERIC_DOMU_TAG} domd"]

        # Disable HWDB which quite huge (around 15MB) and is not required at all
        - [BAD_RECOMMENDATIONS:append, " udev-hwdb"]

        # Enable systemd on dom0
        - [DISTRO_FEATURES:append, " systemd"]
        - [VIRTUAL-RUNTIME_init_manager, "systemd"]

        # Do not install kernel image to rootfs to decrease initrd size
        - ["RDEPENDS:${KERNEL_PACKAGE_NAME}-base", ""]

      layers:
        - "../meta-virtualization"
        - "../meta-openembedded/meta-oe"
        - "../meta-openembedded/meta-filesystems"
        - "../meta-openembedded/meta-python"
        - "../meta-openembedded/meta-networking"
        - "../meta-xt-common/meta-xt-control-domain"
        - "../meta-xt-common/meta-xt-dom0"
        - "../meta-xt-common/meta-xt-domx"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-dom0-gen4"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-domx-gen4"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-prod-devel-rcar-control-gen4"
      build_target: core-image-thin-initramfs
      external_src:
        domd: "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/"
      additional_deps:
        - "%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/Image"
      target_images:
        - "tmp/deploy/images/generic-armv8-xt/Image"
        - "tmp/deploy/images/generic-armv8-xt/uInitramfs"
  domd:
    build-dir: "%{YOCTOS_WORK_DIR}"
    sources:
      - *COMMON_SOURCES
      - *DOMD_DOMU_SOURCES
      - type: git
        url: git://git.yoctoproject.org/meta-selinux
        rev: 46bcf05
    builder:
      type: yocto
      work_dir: "%{DOMD_BUILD_DIR}"
      conf:
        - *COMMON_CONF
        - *DOMD_DOMU_CONF
        - [XT_DOM_NAME, "domd"]
        - [XT_DEVICE_TREES, "%{XT_DOMD_DTB_NAME} %{XT_XEN_DTB_NAME}"]
        - [XT_KERNEL_BRANCH, "%{XT_KERNEL_BRANCH}"]
        - [XT_KERNEL_REV, "%{XT_KERNEL_REV}"]
        - [IMAGE_INSTALL:append, " iperf3"]
        - [IMAGE_INSTALL:append, " smcroute"]
        - [IMAGE_INSTALL:append, " snort"]
        - [EXTRA_IMAGEDEPENDS:append, " boot-script"]

      build_target: rcar-image-minimal
      layers:
        - "../poky/meta"
        - "../poky/meta-poky"
        - "../poky/meta-yocto-bsp"
        - "../meta-virtualization"
        - "../meta-selinux"
        - "../meta-openembedded/meta-oe"
        - "../meta-openembedded/meta-networking"
        - "../meta-openembedded/meta-python"
        - "../meta-openembedded/meta-filesystems"
        - "../meta-renesas/meta-rcar-gateway"
        - "../meta-xt-common/meta-xt-domx"
        - "../meta-xt-common/meta-xt-driver-domain"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-domd-gen4"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-domx-gen4"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-driver-domain-gen4"
      target_images:
        - "tmp/deploy/images/%{MACHINE}/Image"
        - "tmp/deploy/images/%{MACHINE}/rcar-image-minimal-%{MACHINE}.ext4"
        - "tmp/deploy/images/%{MACHINE}/bl31-%{MACHINE}.srec"
        - "tmp/deploy/images/%{MACHINE}/tee-%{MACHINE}.srec"
        - "tmp/deploy/images/%{MACHINE}/u-boot-elf-%{MACHINE}.srec"
        - "tmp/deploy/images/%{MACHINE}/xen-%{MACHINE}.uImage"
        - "tmp/deploy/images/%{MACHINE}/xenpolicy-%{MACHINE}"
        - "tmp/deploy/images/%{MACHINE}/r8a779f0-%{MACHINE}-xen.dtb"
        - "tmp/deploy/images/%{MACHINE}/boot-tftp.uImage"
        - "tmp/deploy/images/%{MACHINE}/boot-emmc.uImage"
  domu:
    build-dir: "%{YOCTOS_WORK_DIR}"
    sources:
      - *COMMON_SOURCES
      - *DOMD_DOMU_SOURCES
    builder:
      type: yocto
      work_dir: "%{DOMU_BUILD_DIR}"
      conf:
        - *COMMON_CONF
        - *DOMD_DOMU_CONF
        - [XT_DOM_NAME, "domu"]
        - [XT_KERNEL_BRANCH, "%{XT_KERNEL_BRANCH}"]
        - [XT_KERNEL_REV, "%{XT_KERNEL_REV}"]
        - [IMAGE_INSTALL:append, " iperf3 "]

      layers:
        - "../meta-openembedded/meta-oe"
        - "../meta-openembedded/meta-filesystems"
        - "../meta-openembedded/meta-python"
        - "../meta-renesas/meta-rcar-gateway"
        - "../meta-xt-common/meta-xt-domu"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-domx-gen4"
        - "../meta-xt-prod-devel-rcar-gen4/meta-xt-domu-gen4"
      build_target: rcar-image-minimal
      target_images:
        - "tmp/deploy/images/%{MACHINE}/Image"
        - "tmp/deploy/images/%{MACHINE}/rcar-image-minimal-%{MACHINE}.ext4"
  boot_artifacts:
    build-dir: "artifacts"
    builder:
      type: archive
      name: "%{MACHINE}-boot-artifacts.tar.bz"
      items:
        - "%{YOCTOS_WORK_DIR}/%{DOM0_BUILD_DIR}/tmp/deploy/images/generic-armv8-xt/Image"
        - "%{YOCTOS_WORK_DIR}/%{DOM0_BUILD_DIR}/tmp/deploy/images/generic-armv8-xt/uInitramfs"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/bl31-%{MACHINE}.srec"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/tee-%{MACHINE}.srec"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/u-boot-elf-%{MACHINE}.srec"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/xen-%{MACHINE}.uImage"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/xenpolicy-%{MACHINE}"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/r8a779f0-%{MACHINE}-xen.dtb"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/boot-emmc.uImage"
        - "%{YOCTOS_WORK_DIR}/%{DOMD_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/boot-tftp.uImage"

images:
  full:
    type: gpt
    desc: "Full SD-card/eMMC image"
    partitions:
      boot:
        gpt_type: 21686148-6449-6E6F-744E-656564454649 # BIOS boot partition (kinda...)
        type: ext4
        size: 128 MiB
        items:
          "Image": "%{YOCTOS_WORK_DIR}/build-dom0/tmp/deploy/images/generic-armv8-xt/Image"
          "uInitramfs": "%{YOCTOS_WORK_DIR}/build-dom0/tmp/deploy/images/generic-armv8-xt/uInitramfs"
          "xen": "%{YOCTOS_WORK_DIR}/build-domd/tmp/deploy/images/%{MACHINE}/xen-%{MACHINE}.uImage"
          "xenpolicy": "%{YOCTOS_WORK_DIR}/build-domd/tmp/deploy/images/%{MACHINE}/xenpolicy-%{MACHINE}"
          "xen.dtb": "%{YOCTOS_WORK_DIR}/build-domd/tmp/deploy/images/%{MACHINE}/%{XT_XEN_DTB_NAME}"
          "boot-emmc.uImage": "%{YOCTOS_WORK_DIR}/build-domd/tmp/deploy/images/%{MACHINE}/boot-emmc.uImage"
      domd_rootfs:
        gpt_type: B921B045-1DF0-41C3-AF44-4C6F280D3FAE # Linux aarch64 root
        type: raw_image
        image_path: "%{YOCTOS_WORK_DIR}/build-domd/tmp/deploy/images/%{MACHINE}/rcar-image-minimal-%{MACHINE}.ext4"

parameters:
  ENABLE_DOMU:
    desc: "Build generic Yocto-based DomU"
    "no":
      default: true
    "yes":
      overrides:
        variables:
          XT_GENERIC_DOMU_TAG: "domu"
        components:
          dom0:
            builder:
              additional_deps:
                - "%{DOMU_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/Image"
              external_src:
                domu: "%{YOCTOS_WORK_DIR}/%{DOMU_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/"
        images:
          full:
            partitions:
              domu-rootfs:
                type: raw_image
                gpt_type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 # Linux filesystem data
                image_path: "%{YOCTOS_WORK_DIR}/%{DOMU_BUILD_DIR}/tmp/deploy/images/%{MACHINE}/rcar-image-minimal-%{MACHINE}.ext4"
