]> rtime.felk.cvut.cz Git - hercules2020/jailhouse-build.git/blobdiff - build/Makefile
deb: Do not start jailhouse automatically
[hercules2020/jailhouse-build.git] / build / Makefile
index a6b0e52ad687246b2d2e9fe45950a663f72b0e1a..169d90ffc912e390cc1345e54a32a85364ccaeed 100644 (file)
-all: buildroot/images/rootfs.cpio.uboot linux-4.4/vmlinux
+all: buildroot/images/rootfs.cpio.uboot kernel-4.4/vmlinux
 
-buildroot/images/rootfs.cpio.uboot: rootfs-overlay/lib/firmware/jailhouse.bin rootfs-overlay/lib/modules/4.4.38+/kernel
-       $(MAKE) -C buildroot
+NPROC:=$(shell nproc)
 
-rootfs-overlay/lib/firmware/jailhouse.bin: linux-4.4/vmlinux
-rootfs-overlay/lib/firmware/jailhouse.bin: ../jailhouse/include/jailhouse/config.h
-rootfs-overlay/lib/firmware/jailhouse.bin: $(addprefix ../jailhouse/,$(shell cd ../jailhouse && git ls-files))
-       $(MAKE) -C ../jailhouse install KDIR=$(CURDIR)/linux-4.4 ARCH=arm64 DESTDIR=$(CURDIR)/rootfs-overlay
-       mkdir -p rootfs-overlay/jailhouse/configs/ rootfs-overlay/jailhouse/demos/
+# TX2 U-Boot does not support FIT images
+image.fit: buildroot/images/rootfs.cpio.uboot kernel-4.4/vmlinux
+       mkimage -f auto -d kernel-4.4/arch/arm64/boot/Image -i buildroot/images/rootfs.cpio.uboot -b kernel-4.4/arch/arm64/boot/dts/tegra186-quill-p3310-1000-c03-00-base.dtb image.fit
+
+buildroot/images/rootfs.cpio.uboot: ./buildroot/.config
+buildroot/images/rootfs.cpio.uboot: rootfs-overlay/lib/firmware/jailhouse.bin
+buildroot/images/rootfs.cpio.uboot: modules_install
+buildroot/images/rootfs.cpio.uboot: $(shell find rootfs-overlay)
+buildroot/images/rootfs.cpio.uboot: rootfs-overlay/bin/prem-test
+       $(MAKE) -j1 -C buildroot ROOTFS_CPIO_COMPRESS_CMD="gzip --fast -c"
+
+rootfs-overlay/bin/prem-test: ../test/prem-test
+       install -D $< $@
+
+rootfs-overlay/lib/firmware/jailhouse.bin: ../jailhouse/hypervisor/jailhouse.bin
+rootfs-overlay/lib/firmware/jailhouse.bin: $(wildcard ../jailhouse/configs/arm64/*.cell)
+       $(MAKE) jailhouse-install
+
+jailhouse: ../jailhouse/hypervisor/jailhouse.bin
+
+DESTDIR=$(CURDIR)/rootfs-overlay
+
+jailhouse-install: FORCE
+       $(MAKE) -C ../jailhouse -j$(NPROC) install KDIR=$(CURDIR)/kernel-4.4 ARCH=arm64 DESTDIR=$(abspath $(DESTDIR)) prefix=/usr
+       mkdir -p $(DESTDIR)/jailhouse/configs/ $(DESTDIR)/jailhouse/demos/
 #      cp ../jailhouse/inmates/demos/arm64/my-demo.bin rootfs-overlay/jailhouse/demos/
-       cp ../jailhouse/configs/arm64/jetson-tx2.cell rootfs-overlay/jailhouse/configs/
-       cp ../jailhouse/configs/arm64/jetson-tx2-demo.cell rootfs-overlay/jailhouse/configs/
+       cp ../jailhouse/configs/arm64/jetson-tx2.cell $(DESTDIR)/jailhouse/configs/
+       cp ../jailhouse/configs/arm64/jetson-tx2-demo.cell $(DESTDIR)/jailhouse/demos/
+
+# Add something like this to ~/.ssh/config for
+# jailhouse-install-remote to work out of the box:
+#
+#    Host tx2
+#      Hostname 192.168.1.54
+INSTALL_HOST ?= root@tx2
+
+jailhouse-install-remote: JAILHOUSE_DESTDIR=jailhouse-install
+jailhouse-install-remote: jailhouse-install
+       rsync -rlptD jailhouse-install/ $(INSTALL_HOST):/
+       rsync -rlptD rootfs-overlay/lib/modules/ $(INSTALL_HOST):/lib/modules
+
+../jailhouse/hypervisor/jailhouse.bin: ../jailhouse/include/jailhouse/config.h
+../jailhouse/hypervisor/jailhouse.bin: kernel-4.4/vmlinux
+../jailhouse/hypervisor/jailhouse.bin: $(addprefix ../jailhouse/,$(shell cd ../jailhouse && git ls-files))
+       $(MAKE) -C ../jailhouse -j$(NPROC) KDIR=$(CURDIR)/kernel-4.4 ARCH=arm64 prefix=/usr
 
 ../jailhouse/include/jailhouse/config.h: Makefile
        rm -f $@.tmp
        echo '#define CONFIG_TRACE_ERROR             1' >> $@.tmp
        echo '#define CONFIG_ARM_GIC_V2              1' >> $@.tmp
        echo '#define CONFIG_MACH_JETSON_TX2         1' >> $@.tmp
-       mv $@.tmp $@
+       mv --update $@.tmp $@
+
+kernel-4.4/vmlinux:
+       $(MAKE) -C $(@D) -j$(NPROC)
 
-rootfs-overlay/lib/modules/4.4.38+/kernel: linux-4.4/vmlinux
-       $(MAKE) -C linux-4.4 modules_install INSTALL_MOD_PATH=$(CURDIR)/rootfs-overlay
+linux_install: kernel-4.4/vmlinux
+       install -m644 -D kernel-4.4/arch/arm64/boot/Image $(DESTDIR)/boot/Image-prem
 
-linux-4.4/vmlinux:
-       $(MAKE) -C $(@D)
+modules_install: kernel-4.4/vmlinux
+       $(MAKE) -C kernel-4.4 -j$(NPROC)  modules_install INSTALL_MOD_PATH=$(DESTDIR)
+
+.PHONY: FORCE
+
+../test/prem-test: FORCE
+       $(MAKE) -C ../test
 
 clean:
-       rm buildroot/images/rootfs.cpio.uboot linux-4.4/vmlinux
+       rm -rf buildroot/images/rootfs.cpio.uboot kernel-4.4/vmlinux buildroot/target `find buildroot/ -name .stamp_target_installed` jailhouse-install
+
+deploy: ../test/prem-test
+#deploy: ../jailhouse/hypervisor/jailhouse.bin
+       scp ../test/prem-test tx2:/bin
+#      scp ../jailhouse/hypervisor/jailhouse.bin tx2:/lib/firmware
+       ssh tx2 'sh /etc/init.d/S20jailhouse.sh stop && sh /etc/init.d/S20jailhouse.sh start'
+
+deb: DESTDIR=$(CURDIR)/_install.deb
+deb: jailhouse-install linux_install modules_install DEBIAN_DIR
+       $(file >$(DESTDIR)/DEBIAN/control,$(deb_control))
+       $(file >$(DESTDIR)/DEBIAN/postinst,$(deb_postinst))
+       $(file >$(DESTDIR)/DEBIAN/prerm,$(deb_prerm))
+       chmod +x $(DESTDIR)/DEBIAN/postinst $(DESTDIR)/DEBIAN/prerm
+       rm -f _install.deb/lib/modules/*/source _install.deb/lib/modules/*/build
+       install -D ./rootfs-overlay/etc/init.d/S20jailhouse.sh $(DESTDIR)/etc/init.d/jailhouse
+       install -m644 -D ./rootfs-overlay/etc/systemd/system/jailhouse.service $(DESTDIR)/lib/systemd/system/jailhouse.service
+       #install -d $(DESTDIR)/lib/systemd/system/multi-user.target.wants/
+       #ln -sf ../jailhouse.service $(DESTDIR)/lib/systemd/system/multi-user.target.wants/jailhouse.service
+# Note: --root-owner-group requires dpkg version 1.19.0+
+       dpkg-deb --root-owner-group --build $(DESTDIR) .
+
+DEBIAN_DIR:
+       install -d $(DESTDIR)/DEBIAN
+
+
+define deb_control
+Package: jailhouse
+Essential: no
+Priority: optional
+Section: admin
+Maintainer: Michal Sojka <michal.sojka@cvut.cz>
+Architecture: arm64
+Version: $(shell git describe --always --dirty)
+Description: Jailhouse hypervisor and the Linux kernel for the HERCULES project.
+endef
+
+define deb_postinst
+#!/bin/sh
+set -e
+if ! grep -q Image-prem /boot/extlinux/extlinux.conf; then
+cat >>/boot/extlinux/extlinux.conf <<'EOF'
+LABEL prem
+      MENU LABEL prem kernel and jailhouse
+      LINUX /boot/Image-prem
+      APPEND $${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 mem=7808M vmalloc=512M jailhouse
+EOF
+fi
+endef
+
+define deb_prerm
+#!/bin/sh
+set -e
+if grep -q Image-prem /boot/extlinux/extlinux.conf; then
+       . # TODO
+fi
+endef